作者:reille
本博客网址:http://blog.csdn.net/reille/
开发环境:主机:Window XP SP2;linux:VMware7.01+ubuntu9.10;目标板:扬创utu2440-F开发板
交叉编译器:arm-linux-3.4.1
更多请关注:http://velep.com/
本CS8900网卡驱动移植是基于之前内核版本的,实际上是从扬创开发板附送光盘上拷贝下来的CS8900源文件移植而来。
移植好的CS8900网卡驱动在扬创ubu2440-F开发板上已验证通过,可从网址下载到:http://download.csdn.net/source/3342114
CS8900网卡驱动移植到基于linux2.6.30内核版本的S3C2440中,主要关注其中几点:
1. 基于旧的CS8900网卡驱动;
2. CS8900网卡驱动的BSP信息构造;
2. 头文件的变化;
3. linux2.6.30的struct net_device有变化,主要是没有了priv这个成员变量;
1. 在drivers/net/arm/ 目录下添加 cs8900.c,cs8900.h两个文件。
如果是你自己重新移植的话,这两文件可从网上搜索或从我的博客资源上下载:http://download.csdn.net/source/3342941;如果使用本人移植好的驱动(可以省略一些步骤),在我的博客资源下载:http://download.csdn.net/source/3342114
2. 修改drivers/net/arm/目录下的Kconfig文件,在最后添加如下内容:
config ARM_CS8900 tristate "CS8900 support" depends on ARM || BLACKFIN || MIPS help support for cs8900 chipset based Ethernet cards , if you have a network card of this type
3. 修改drivers/net/arm/Makefile文件,添加:
obj-$(CONFIG_ARM_CS8900) += cs8900.o
4. 编译配置内核,进入配置菜单,添加CS8900驱动到内核:
# make menuconfig
Device Drivers --->
[*] Network device support --->
[*] Ethernet (10 or 100Mbit) --->
<*> CS8900 support
5. 添加BSP关于CS8900网卡驱动信息:
如果是移植到2410,则打开arch/arm/mach-s3c2410/mach-smdk2410.c文件;如果是移植到2440,则打开arch/arm/mach-s3c2440/mach-smdk2440.c。本人使用自己创建的BSP文件,即arch/arm/mach-s3c2440/mach-reille2440.c,在static struct map_desc smdk2410_iodesc[] __initdata (对2410而言)或static struct map_desc smdk2440_iodesc[] __initdata(对2440而言)最后添加:
,{ // support cs8900|added by guoyirong 2011.06.04 .virtual = vSMDK2410_ETH_IO, // virtural addr that will be remapped .pfn = __phys_to_pfn(S3C2410_CS3 + (1<<24)), .length = SZ_1M, .type = MT_DEVICE, }
6. 修改arch/arm/mach-s3c2410/include/mach/map.h文件,在最后添加:
/* CS8900 */ #define pSMDK2410_ETH_IO __phys_to_pfn(0x19000000) #define vSMDK2410_ETH_IO 0xE0000000 #define SMDK2410_ETH_IRQ IRQ_EINT9
7. 编译内核:
如果是使用我移植好的CS8900驱动,则不会有问题,如果是使用从网上下载或从我博客资源上下载的未移植好的C8900驱动,则编译时会出现很多错误,包括头文件、宏定义、priv成员等错误,如下所示:
drivers/net/arm/cs8900.c:56:26: asm/hardware.h: No such file or directory
drivers/net/arm/cs8900.c:71:30: asm/arch/bit-map.h: No such file or directory
drivers/net/arm/cs8900.c:72:31: asm/arch/regs-mem.h: No such file or directory
drivers/net/arm/cs8900.c:96: error: unknown field `init' specified in initializer
drivers/net/arm/cs8900.c:97: warning: missing braces around initializer
drivers/net/arm/cs8900.c:97: warning: (near initialization for `cs8900_dev.name')
drivers/net/arm/cs8900.c:97: warning: initialization makes integer from pointer without a cast
drivers/net/arm/cs8900.c:97: error: initializer element is not computable at load time
drivers/net/arm/cs8900.c:97: error: (near initialization for `cs8900_dev.name[0]')
drivers/net/arm/cs8900.c:97: error: initializer element is not constant
drivers/net/arm/cs8900.c:97: error: (near initialization for `cs8900_dev.name')
drivers/net/arm/cs8900.c:117: error: variable `cs8900_eeprom_fops' has initializer but incomplete type
drivers/net/arm/cs8900.c:118: error: unknown field `owner' specified in initializer
drivers/net/arm/cs8900.c:118: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:118: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c:119: error: unknown field `open' specified in initializer
drivers/net/arm/cs8900.c:119: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:119: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c:120: error: unknown field `release' specified in initializer
drivers/net/arm/cs8900.c:120: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:120: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c:121: error: unknown field `llseek' specified in initializer
drivers/net/arm/cs8900.c:121: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:121: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c:122: error: unknown field `read' specified in initializer
drivers/net/arm/cs8900.c:122: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:122: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c:123: error: unknown field `write' specified in initializer
drivers/net/arm/cs8900.c:123: warning: excess elements in struct initializer
drivers/net/arm/cs8900.c:123: warning: (near initialization for `cs8900_eeprom_fops')
drivers/net/arm/cs8900.c: In function `cs8900_receive':
drivers/net/arm/cs8900.c:343: error: structure has no member named `priv'
drivers/net/arm/cs8900.c: In function `cs8900_send_start':
drivers/net/arm/cs8900.c:382: error: structure has no member named `priv'
drivers/net/arm/cs8900.c: In function `cs8900_interrupt':
drivers/net/arm/cs8900.c:434: error: structure has no member named `priv'
drivers/net/arm/cs8900.c:439: error: structure has no member named `priv'
drivers/net/arm/cs8900.c: In function `cs8900_transmit_timeout':
drivers/net/arm/cs8900.c:496: error: structure has no member named `priv'
drivers/net/arm/cs8900.c: In function `cs8900_start':
drivers/net/arm/cs8900.c:508: error: implicit declaration of function `set_irq_type'
drivers/net/arm/cs8900.c:508: error: `IRQT_RISING' undeclared (first use in this function)
drivers/net/arm/cs8900.c:508: error: (Each undeclared identifier is reported only once
drivers/net/arm/cs8900.c:508: error: for each function it appears in.)
drivers/net/arm/cs8900.c:523: warning: passing arg 2 of `request_irq' from incompatible pointer type
drivers/net/arm/cs8900.c: In function `cs8900_get_stats':
drivers/net/arm/cs8900.c:580: error: structure has no member named `priv'
drivers/net/arm/cs8900.c: In function `cs8900_eeprom':
drivers/net/arm/cs8900.c:599: error: structure has no member named `priv'
drivers/net/arm/cs8900.c:618: error: implicit declaration of function `register_chrdev'
drivers/net/arm/cs8900.c: In function `cs8900_eeprom_fllseek':
drivers/net/arm/cs8900.c:674: error: dereferencing pointer to incomplete type
drivers/net/arm/cs8900.c:686: error: dereferencing pointer to incomplete type
drivers/net/arm/cs8900.c: In function `cs8900_probe':
drivers/net/arm/cs8900.c:778: error: `S3C2410_BWSCON' undeclared (first use in this function)
drivers/net/arm/cs8900.c:779: error: `S3C2410_BANKCON3' undeclared (first use in this function)
drivers/net/arm/cs8900.c:807: error: structure has no member named `priv'
drivers/net/arm/cs8900.c:811: error: implicit declaration of function `SET_MODULE_OWNER'
drivers/net/arm/cs8900.c: In function `cs8900_cleanup':
drivers/net/arm/cs8900.c:916: error: structure has no member named `priv'
drivers/net/arm/cs8900.c:919: error: implicit declaration of function `unregister_chrdev'
drivers/net/arm/cs8900.c: In function `cs8900_probe':
drivers/net/arm/cs8900.c:778: warning: statement with no effect
drivers/net/arm/cs8900.c:779: warning: statement with no effect
drivers/net/arm/cs8900.c: At top level:
drivers/net/arm/cs8900.c:117: error: storage size of `cs8900_eeprom_fops' isn't known
make[3]: *** [drivers/net/arm/cs8900.o] Error 1
make[2]: *** [drivers/net/arm] Error 2
make[1]: *** [drivers/net] Error 2
make: *** [drivers] Error 2
————————————————————————————————————————————————————————————
上述错误如下处理:
1) 把#include <asm/hardware.h> 、#include "asm/arch/bit-map.h"和#include <asm/arch/regs-mem.h>屏蔽掉,同时增加如下头文件:
#include <mach/hardware.h> #include <mach/regs-mem.h> #include <mach/regs-irq.h>
2) netdevice.h 中struct net_device结构体又添上了:void *priv;
3) 把#include <linux/irq.h>文件包含,同时在CS8900.c文件中定义如下宏:
#define IRQT_RISING IRQ_TYPE_EDGE_RISING
把823行屏蔽掉。
4)对于错误:drivers/net/arm/cs8900.c:96: error: unknown field `init' specified in initializer
这个错误不知道怎么解决,我是把那行屏蔽掉了,同时把它改为在cs8900_init()函数中进行初始化。
按上述处理后,启动时会出现错误:操作了空指针,这是由于cs8900.c中静态定义了cs8900_dev但没有分配私有成员空间的缘故。
因此,改用alloc_etherdev()函数分配cs8900_dev就可以了。
具体的可以对比本人移植前后的的cs8900.c的源代码。
http://blog.csdn.net/guolele2010/archive/2011/04/08/6309589.aspx
http://blog.163.com/kmustchenb@126/blog/static/110905765200988765547/
http://blog.163.com/kmustchenb@126/blog/static/1109057652009887734131/
http://blog.ednchina.com/xiong_gang_whut/240010/message.aspx