分类: 嵌入式
2010-10-17 22:00:06
基于S
在mini2440上移植DM9000E网卡的参考步骤如下:
一、看电路图
在mini2440开发板上移植好Linux-
1、DM9000E挂接到S
S
2、总线位宽16,用到nWAIT信号
3、DM9000E收到完整的数据包,通过中断引脚通知S
二、网卡驱动程序修改
修改内核中网卡驱动程序时需要先结合所使用的内核,先查看当前内核是否支持该网卡,如果不支持需要查找支持该网卡的驱动程序进行修改。我用的是Linux-
The driver supports three DM9000 variants, the DM9000E which is the first chip supported as well as the newer DM |
一些低版本的内核(比如linux-
1、修改DM9000平台设备
修改/arch/arm/plat-s3c24xx/common-smdk.c文件
(1)、添加要包含的头文件
#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE) #include #endif |
(2)、添加DM9000的平台设备结构
#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE) /*DM9000*/ static struct resource s [0] = { .start = S .end = S .flags = IORESOURCE_MEM, }, [1] = { .start = S .end = S .flags = IORESOURCE_MEM, }, [2] = { .start = IRQ_EINT7, .end = IRQ_EINT7, .flags = IORESOURCE_IRQ, } }; static struct dm9000_plat_data s .flags = DM9000_PLATF_16BITONLY, }; static struct platform_device s .name = "dm9000", .id = 0, .num_resources = ARRAY_SIZE(s .resource = s .dev = { .platform_data = &s } }; #endif |
(3)、将DM9000平台设备加入内核设备列表中
/* devices we initialise */ static struct platform_device __initdata *smdk_devs[] = { &s &smdk_led4, &smdk_led5, &smdk_led6, &smdk_led7, #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE) &s #endif }; |
2、修改drivers/net/dm9000.c
dm9000.c中包含dm9000_probe函数,该函数完成DM9000设备的枚举,dm9000_probe函数的介绍在《嵌入式Linux应用开发完全手册》一书中详细介绍。
(1)、添加必要的头文件
#if defined(CONFIG_ARCH_S #include #endif |
在《嵌入式Linux应用开发完全手册》一书中上面的#include
(2)、在dm9000_probe中设置存储器使BANK4可用,设置默认MAC地址(也可以在根文件系统启动脚本设置),添加的代码如下:
/* * Search DM9000 board, allocate space and register it */ static int __devinit dm9000_probe(struct platform_device *pdev) { … #if defined(CONFIG_ARCH_S unsigned int oldval_bwscon; //用来保存BWSCON寄存器的值 unsigned int oldval_bankcon4; //用来保存S #endif … #if defined (CONFIG_ARCH_S //设置BANK4:总线宽度为16,使能nWAIT oldval_bwscon = *((volatile unsigned int *)S *((volatile unsigned int *)S | S //设置BANK4的时间参数 oldval_bankcon4 = *((volatile unsigned int *)S *((volatile unsigned int *)S #endif … if (!is_valid_ether_addr(ndev->dev_addr)) dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " "set using ifconfig\n", ndev->name); #if defined(CONFIG_ARCH_S printk("Now use the default MAC address:08:90:90:90:90:90\n"); ndev->dev_addr[0] = 0x08; ndev->dev_addr[1] = 0x90; ndev->dev_addr[2] = 0x90; ndev->dev_addr[3] = 0x90; ndev->dev_addr[4] = 0x90; ndev->dev_addr[5] = 0x90; #endif … out: printk("%s:not found (%d).\n",CARDNAME,ret); #if defined(CONFIG_ARCH_S *((volatile unsigned int *)S *((volatile unsigned int *)S #endif |
(3)、指定注册中断时的触发方式
dm9000_open(struct net_device *dev) { … irqflags |= IRQF_SHARED; #if defined (CONFIG_ARCH_S if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED|IRQF_TRIGGER_RISING,dev->name,dev)) #else if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED,dev->name,dev)) #endif //if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev)) return -EAGAIN; … } |
三、在内核中增加对网卡DM9000的配置
在内核目录下执行“make menuconfig”命令进行如下的配置:
Device Drivers---> [*]Network device support---> [*]Ethernet(10 or 100Mbit)---> <*>DM9000 support [*]Networking support---> Networking options---> <*>TCP/IP networking <*>IP:kernel leel autoconfiguration //增加对nfs的支持 File systems---> [*]Networking File Systems---> <*>NFS client support [*]NFS client support for NFS version 3 [*]NFS client support for the NFSv3 ACL protocol extension [*]Boot file system on NFS [*]NFS server support |
四、修改根文件系统启动脚本rcS
在根文件etc/init.d/rcS文件中添加如下:
echo "network interface" /sbin/ifconfig lo 127.0.0.1 /sbin/ifconfig eth0 192.168.1.230 up route add default gw 192.168.1.1 |
五、测试和修改
至此,将修改过的内核和根文件系统下载到mini2440开发板,启动时出现如下信息:
----------munt all---------------- network interface dm9000 dm9000.0: WARNING: no IRQ resource flags set. eth0: link up, 10Mbps, half-duplex, lpa 0x0021 *********************************************** ****************Studying ARM********************* Kernel version:linux- Student:Feng dong rui Date:2009.07.15 *********************************************** Please press Enter to activate this console. [MrFeng]# |
1、测试
Please press Enter to activate this console. [MrFeng]#ifconfig -a eth0 Link encap:Ethernet HWaddr 10:23:45:67:89:AB inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1506 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:101460 (99.0 KiB) TX bytes:0 (0.0 B) Interrupt:51 Base address:0x8000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:504 (504.0 B) TX bytes:504 (504.0 B) [MrFeng]#ping 127.0.0.1 64 bytes from 127.0.0.1: seq="0" ttl="64" time="1".004 ms 64 bytes from 127.0.0.1: seq="1" ttl="64" time="0".518 ms 64 bytes from 127.0.0.1: seq="2" ttl="64" time="0".436 ms ^C --- 127.0.0.1 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.436/0.652/1.004 ms [MrFeng]#ping 192.168.1.103 64 bytes from 192.168.1.103: seq="0" ttl="64" time="2".098 ms 64 bytes from 192.168.1.103: seq="1" ttl="64" time="1".342 ms 64 bytes from 192.168.1.103: seq="2" ttl="64" time="0".823 ms ^C --- 192.168.1.103 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.823/1.421/2.098 ms //挂载网络文件系统 [MrFeng]#mount -t nfs -o nolock 192.168.1.103:/opt/nfs /mnt [MrFeng]#ls /mnt pic.jpg [MrFeng]#umount /mnt [MrFeng]#ls /mnt [MrFeng]# |
注:在挂载网络文件系统时先要在Linux系统下设置共享目录才能在从开发板挂载该目录,这里已经在虚拟机下Redhat9.0系统中的/opt下设置了共享目录nfs,虚拟机的ip为192.168.1.103,故通过mount -t nfs -o nolock 192.168.1.103:/opt/nfs /mnt命令挂载。
2、曾经出现的问题
(1)、ping不同局域网内其它主机,ping自己也有时会出现如下问题:
[ 44/0x r4:c [ Exception stack(0xc2e2bd98 to 0xc2e2bde0) bd80: 00000000 fb000000 bda0: 00000001 bdc0: c39bfc r7:00000080 r6:00000010 r5:f4000000 r4:ffffffff [ [ [ [ ) r5:00000000 r4:c382b800 [ /0x708) r7:bed9ba88 r6:c39fdf00 r5:00000000 r4:ffffff9d [ [ [ r7:00000003 r6:00008914 r5:ffffffe7 r4:c2d [ r6:00000000 r5:bed9ba88 r4:c2d [ r7:00000036 r6:00008914 r5:fffffff7 r4:c2d [ r6:00000000 r5:00159dec r4:00159d |
出现这个问题的原因是我没将中断的触发方式按照默认的,没有改成上面修改的。
(2)、挂载不了网络文件系统
可能的原因:检查内核的配置中是否选中对NFS的支持,Linux主机是否能连通局域网并设置了共享目录,硬件的链接是否良好。还有就是Linux主机的防火墙是否关闭,nfs服务是否已经开启。
六、参考资料
在学习的过程中,参考了韦东山写的《嵌入式Linux应用开发完全手册》一书,该书我觉得虽然没有把很多东西讲得很详细,嵌入式Linux的书也不可能在一本书上讲得详细,但我每想做什么就不自觉的翻阅它,对我来说非常具有参考价值。另外就是网上的一些热心网友的博客、帖子上的内容给了我很多参考,结合“百家之长”解决问题,网上的资料很多,不一一列举。