请先登录
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
一.修改mt7620.dtsi,去掉默认的bootargs,kernel_menuconfig取消buildin的command line
二.kernel_menuconfig加入scsi驱动,USB Storage,Ext4文件系统,设置USB驱动有个关键的地方,要打开:
<*> Generic EHCI driver for a platform device
三.set bootargs root=8:2 rootdelay=5 rootfstype=ext4 rw console=ttyS0,57600注意:rootdelay很关键
四.完全关闭MTD驱动,需要修改两处:
1.从MTD中获取MAC地址
代码位于drivers/of/of_net.c
- int of_get_mac_address_mtd(struct device_node *np, void *mac)
- {
- struct device_node *mtd_np = NULL;
- size_t retlen;
- int size, ret;
- struct mtd_info *mtd;
- const char *part;
- const __be32 *list;
- phandle phandle;
-
- list = of_get_property(np, "mtd-mac-address", &size);
- if (!list || (size != (2 * sizeof(*list))))
- return -ENOENT;
-
- phandle = be32_to_cpup(list++);
- if (phandle)
- mtd_np = of_find_node_by_phandle(phandle);
-
- if (!mtd_np)
- return -ENOENT;
-
- part = of_get_property(mtd_np, "label", NULL);
- if (!part)
- part = mtd_np->name;
-
- mtd = get_mtd_device_nm(part);
- if (IS_ERR(mtd))
- return PTR_ERR(mtd);
-
- ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, (u_char *) mac);
- put_mtd_device(mtd);
-
- return ret;
- }
复制代码 其中MTD中的mac地址位置定义在WRTNode.dts文件中
- ethernet@10100000 {
- mtd-mac-address = <&factory 0x4>;
- ralink,port-map = "wllll";
- };
复制代码 factory区(mtdblock3)内容如下:
我们可以看到,factory偏移4的mac地址是00:0C:43:76:20:A0
由于关闭了MTD驱动,现在的思路:通过bootargs来传递mac地址。
修改of_net.c代码为:
- #ifdef CONFIG_MTD
- int of_get_mac_address_mtd(struct device_node *np, void *mac)
- {
- // 原始代码,从factory偏移4中获取mac地址
- }
- #else // #not define CONFIG_MTD
- // manfeel , mod to support cmdline mac address
- char mac_addr[ETH_ALEN];
- static int __init eth_addr_setup(char *str)
- {
- int i;
-
- if(str == NULL)
- return 0;
- for(i = 0; i < ETH_ALEN; i++)
- mac_addr[i] = simple_strtol(&str[i*3], (char **)NULL, 16);
- return 1;
- }
-
- /* Get MAC address from kernel boot parameter eth=AA:BB:CC:DD:EE:FF */
- __setup("eth=", eth_addr_setup);
-
- int of_get_mac_address_mtd(struct device_node *np, void *mac)
- {
- int i;
- for(i = 0; i < ETH_ALEN; i++)
- ((u_char *) mac)[i] = mac_addr[i];
-
- return 1;
- }
- #endif
复制代码 于是,bootargs变成了:root=8:2 rootdelay=5 rootfstype=ext4 rw eth=${ethaddr} console=ttyS0,57600
2.从MTD中获取wifi参数
由于WRTNode使用了lintel编译好的ko格式的wifi驱动,无法修改。所以找到了“大茶园丁”大侠的代码,感谢他;)
“大茶”采取的是kernelPackage的方式,故rt2860的代码位于:build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/rt2860v2-r2714
读取MTD中的wifi配置的代码位于:rt2860v2/os/linux/rt_flash.c中,修改如下:
- #include <linux/module.h>
- #include <linux/types.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/version.h>
- #include <linux/err.h>
- #include <linux/slab.h>
- #include <linux/delay.h>
- #include <linux/sched.h>
- #include <linux/backing-dev.h>
- #include <linux/compat.h>
- #include <linux/mount.h>
-
- //#include <linux/mtd/mtd.h>
- //#include <linux/mtd/map.h>
- //#include <linux/mtd/concat.h>
- //#include <linux/mtd/partitions.h>
-
-
-
-
-
- #include <linux/fs.h>
- #include <linux/string.h>
- #include <linux/mm.h>
- #include <linux/syscalls.h>
- #include <asm/unistd.h>
- #include <asm/uaccess.h>
-
- #define MY_FILE "/etc/config/eeprom"
-
-
-
- struct proc_dir_entry *procRegDir;
- /*
- * Flash API: ra_mtd_read, ra_mtd_write
- * Arguments:
- * - num: specific the mtd number
- * - to/from: the offset to read from or written to
- * - len: length
- * - buf: data to be read/written
- * Returns:
- * - return -errno if failed
- * - return the number of bytes read/written if successed
- */
- int ra_mtd_write_nm(char *name, loff_t to, size_t len, const u_char *buf)
- {
- int ret = -1;
- pr_info("NOT implement : mtd_write to %X len = %X\n", to , len);
- return ret;
- }
-
- int ra_mtd_read_nm(char *name, loff_t from, size_t len, u_char *buf)
- {
- int ret;
- size_t rdlen = 0;
- struct mtd_info *mtd;
- pr_info("<=-=- mtd_read(%s,in file!) from %d len = %d\n", name, from , len);
-
- pr_info("begin to read factory file\n");
-
- struct file *file = NULL;
-
- mm_segment_t old_fs;
-
- if(file == NULL)
- file = filp_open(MY_FILE, O_RDWR, 0644);
- if (IS_ERR(file)) {
- printk("error occured while opening file %s, exiting...\n", MY_FILE);
- return 0;
- }
-
- old_fs = get_fs();
- set_fs(KERNEL_DS);
-
- file->f_pos = from;
- rdlen = file->f_op->read(file, (char *)buf, len == 0 ? 0x400 : len, &file->f_pos);
- set_fs(old_fs);
- filp_close(file, NULL);
- file = NULL;
- ret = 1;
-
- pr_info("mtd_read rdlen = %X\n",rdlen);
- if (rdlen != len)
- printk("warning: ra_mtd_read_nm: rdlen is not equal to len\n");
-
-
- return ret;
- }
-
- EXPORT_SYMBOL(ra_mtd_write_nm);
- EXPORT_SYMBOL(ra_mtd_read_nm);
- EXPORT_SYMBOL(procRegDir);
-
- MODULE_AUTHOR("Manfeel <manfeel@foxmail.com>");
- MODULE_DESCRIPTION("Ralink APSoC Flash Map");
- MODULE_LICENSE("GPL");
复制代码 内核驱动中读取/etc/config/eeprom文件的方式来实现,不符合kernel工作组的规范。后期想改成module parameter的方式,在insmod中,将eeprom内容通过数组参数的方式传递到内核驱动。
|