邮箱:zhuimengcanyang@163.com 痴爱嵌入式技术的蜗牛
分类: 嵌入式
2016-12-14 20:59:31
启动内核后,输入ifconfig命令,没有反应。
NET: Registered protocol family 17
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
ALSA device list:
No soundcards found.
VFS: Mounted root (jffs2 filesystem) on device 31:3.
Freeing init memory: 164K
ifconfig: SIOCSIFADDR: No such device
Please press Enter to activate this console.
/ #
/ # ifconfig
/ # ifconfig eth0
ifconfig: eth0: error fetching interface information: Device not found
/ #
linux-3.4.2\drivers\net\ethernet\davicom\dm9000.c
看代码,DM9000是注册了一个平台设备驱动。
static struct platform_driver dm9000_driver = {
.driver = {
.name = "dm9000",
.owner = THIS_MODULE,
.pm = &dm9000_drv_pm_ops,
},
.probe = dm9000_probe,
.remove = __devexit_p(dm9000_drv_remove),
};
static int __init
dm9000_init(void)
{
printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);
return platform_driver_register(&dm9000_driver);
}
所以,搜索driver的名字"dm9000",发现在mini2440开发板中,注册了该设备。
linux-3.4.2\arch\arm\mach-s3c24xx\mach-mini2440.c
static struct platform_device mini2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
.resource = mini2440_dm9k_resource,
.dev = {
.platform_data = &mini2440_dm9k_pdata,
},
};
阅读mini2440中相关的dm9000注册流程:
static void __init mini2440_init(void)
platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
platform_device_register(devs[i]); // 在这个devs[i]数组中,有DM9000设备:mini2440_device_eth 这一项
static struct platform_device mini2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
.resource = mini2440_dm9k_resource,
.dev = {
.platform_data = &mini2440_dm9k_pdata,
},
};
相关定义:
/* DM9000AEP 10/100 ethernet controller */
static struct resource mini2440_dm9k_resource[] = {
[0] = {
.start = MACH_MINI2440_DM9K_BASE,
.end = MACH_MINI2440_DM9K_BASE + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = MACH_MINI2440_DM9K_BASE + 4,
.end = MACH_MINI2440_DM9K_BASE + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};
/*
* The DM9000 has no eeprom, and it's MAC address is set by
* the bootloader before starting the kernel.
*/
static struct dm9000_plat_data mini2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
仿照mini2440的做法,在linux-3.4.2\arch\arm\mach-s3c24xx\mach-smdk2440.c 添加下面的代码:
#define MACH_SMDK2440_DM9K_BASE (S3C2410_CS4 + 0x300)
/* DM9000AEP 10/100 ethernet controller */
static struct resource smdk2440_dm9k_resource[] = {
[0] = {
.start = MACH_SMDK2440_DM9K_BASE,
.end = MACH_SMDK2440_DM9K_BASE + 3,
.flags = IORESOURCE_MEM
},
[1] = {
.start = MACH_SMDK2440_DM9K_BASE + 4,
.end = MACH_SMDK2440_DM9K_BASE + 7,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
}
};
/*
* The DM9000 has no eeprom, and it's MAC address is set by
* the bootloader before starting the kernel.
*/
static struct dm9000_plat_data smdk2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
static struct platform_device smdk2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(smdk2440_dm9k_resource),
.resource = smdk2440_dm9k_resource,
.dev = {
.platform_data = &smdk2440_dm9k_pdata,
},
};
最后,在设备的数组中加入dm9000这个设备:
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&smdk2440_device_eth, /* add DM9000 */
};
tftp 30000000 uImage_net; bootm 30000000
看打印信息,看到网卡已经配置成功,且已经启动了。
.......
ALSA device list:
No soundcards found.
jffs2: Empty flash at 0x00b18fd8 ends at 0x00b19000
VFS: Mounted root (jffs2 filesystem) on device 31:3.
Freeing init memory: 116K
dm9000 dm9000: eth0: link down
dm9000 dm9000: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
Please press Enter to activate this console.
/ #
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2F:4E:70
inet addr:192.168.1.17 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:51 Base address:0x2300
/ #
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2F:4E:70
inet addr:192.168.1.17 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:51 Base address:0x2300
/ # ifconfig eth0 192.168.1.17
/ # mount -t nfs -o nolock,vers=2 192.168.1.240:/work/nfs_root /mnt
/ # cd /mnt
/mnt # ls
first_fs fs_mini_mdev fs_qtopia.tar.bz2
first_fs.jffs2 fs_mini_mdev.jffs2 fs_qtopia.yaffs2
first_fs.yaffs2 fs_mini_mdev.tar.bz2 fs_qtopia_ts.yaffs2
fs_mini fs_mini_mdev.yaffs2 fs_xwindow.tar.bz2
fs_mini.jffs2 fs_mini_mdev_new my_fs
fs_mini.tar.bz2 fs_mini_mdev_new.tar.bz2 my_fs.jffs2
fs_mini.yaffs2 fs_qtopia.jffs2 my_fs.yaffs2
cp dm9000.h dm9dev9000c.c /work/system/linux-3.4.2/drivers/net/ethernet/davicom/
vi /work/system/linux-3.4.2/drivers/net/ethernet/davicom/Makefile
#obj-$(CONFIG_DM9000) += dm9000.o
修改为:
obj-$(CONFIG_DM9000) += dm9dev9000c.o
1. 移植内核做好的DM9000驱动程序,可以仿照内核中已经实现的代码,进行复制,修改,编译,直到可以使得DM9000可以工作。
2. 移植厂家做好的驱动程序,可以将驱动程序加入内核一起编译。