由于这块网卡芯片的应用很广泛,在linux下的移植的文档相当多,我们要做的也就是只是稍作改以便适合我们的自己的系统。 昨天的进展比较快,把内核弄好了。整个移植过程参考了网上一些同行的笔记。在网上找到了网卡的驱动程序文件,cs8900.h与cs8900.c这两个。 先说一下我的编译环境:
linux系统:ubuntu8.04
编译器版本:arm-linux-3.4.1 glibc-2.2.3
目前网上的移植主要有两种思路,一种是在drivers/net/arm目录下进行相关文件的添加与修改、另一种是在drivers/net下进行相关的文件的添加与修改。我用的是第一种:
下面是整个过程:
1、
将cs8900.h与cs8900.c拷贝到drivers/net/arm目录下。
2、
修改drivers/net/arm目录下的Makefile,以使其对网卡程序进行编译
emacs Makefile
在后面加上这一句:obj-$(CONFIG_ARM_CS8900) += cs8900.o
3、
为网卡驱动程序中用到的一些宏定义添加一个头文件:
打开目录include/asm-arm/arch-s3c2410/
新建文件smdk2410.h
加入以下内容:
#ifndef _INCLUDE_SMDK2410_H_
#define _INCLUDE_SMDK2410_H_
#include <linux/config.h>
#define pSMDK2410_ETH_IO __phys_to_pfn(0x19000000)
#define vSMDK2410_ETH_IO 0xE0000000
#define SMDK2410_ETH_IRQ IRQ_EINT9
#endif // _INCLUDE_SMDK2410_H_
注意红色部分,我原来是用#define pSMDK2410_ETH_IO 0x19000000这样的一句代替它,但是编译通过后网络不通,串口显示是了错误:
Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)
Unable to handle kernel paging request at virtual address e000030a
pgd = c0004000
[e000030a] *pgd=00000000
Internal error: Oops: 805 [#1]
Modules linked in:
CPU: 0
PC is at cs8900_probe+0x10c/0x304
LR is at 0xe0000300
pc : [<c00183d0>] lr : [<e0000300>] Not tainted
sp : c02cbf60 ip : c01ca51c fp : c02cbf84
r10: 00000000 r9 : 00000000 r8 : 00000000
r7 : 00000002 r6 : 00000000 r5 : c01d5e3c r4 : c021d2b8
r3 : e000030a r2 : 00000000 r1 : c3ceea80 r0 : e000030a
Flags: NzCv IRQs on FIQs on Mode SVC_32 Segment kernel
Control: 717F Table: 30004000 DAC: 00000017
Process swapper (pid: 1, stack limit = 0xc02ca198)
Stack: (0xc02cbf60 to 0xc02cc000)
bf60: c02cbfa4 c02cbf70 c01d5e3c 00000000 00000000 c001c2d8 c02cbfa4 c02cbf88
bf80: c01391fc c00182d4 c01d5e3c 00000000 c01d5e3c 00000000 c02cbfbc c02cbfa8
bfa0: c0139544 c013912c c01d5e3c c02ca000 c02cbfd0 c02cbfc0 c00185ec c01394ec
bfc0: c001c278 c02cbff4 c02cbfd4 c001f0f4 c00185d8 00000001 00000000 00000000
bfe0: 00000000 00000000 00000000 c02cbff8 c0038084 c001f068 0000006f 5f6f6962
Backtrace:
[<c00182c4>] (cs8900_probe+0x0/0x304) from [<c01391fc>] (register_netdevice+0xe)
r7 = C001C2D8 r6 = 00000000 r5 = 00000000 r4 = C01D5E3C
[<c013911c>] (register_netdevice+0x0/0x3c0) from [<c0139544>] (register_netdev+)
r6 = 00000000 r5 = C01D5E3C r4 = 00000000
[<c01394dc>] (register_netdev+0x0/0x7c) from [<c00185ec>] (cs8900_init+0x24/0x3)
r5 = C02CA000 r4 = C01D5E3C
[<c00185c8>] (cs8900_init+0x0/0x30) from [<c001f0f4>] (init+0x9c/0x220)
r4 = C001C278
[<c001f058>] (init+0x0/0x220) from [<c0038084>] (do_exit+0x0/0x714)
r7 = 00000000 r6 = 00000000 r5 = 00000000 r4 = 00000000
Code: e28e000a e3500201 e1a03000 328334f2 (e1c360b0)
<0>Kernel panic - not syncing: Attempted to kill init!
应该是虚拟地址问题。
4、
为cs8900a芯片增加物理地址到虚拟地址的映射并把刚才建的头文件加进来:
打开/arch/arm/mach-s3c2410/mach-smdk2410.c
在smdk2410_iodesc[]数组内加入
{vSMDK2410_ETH_IO, pSMDK2410_ETH_IO, SZ_1M, MT_DEVICE}
加入之后的内容应该是:
static struct map_desc smdk2410_iodesc[] __initdata = {
/* nothing here yet */
/* Map the ethernet controller CS8900A */ {vSMDK2410_ETH_IO, pSMDK2410_ETH_IO, SZ_1M, MT_DEVICE}
};
加入刚才的头文件,不加头文件过来将显示几个宏定的变量没有定义,编译通不过。
打开/arch/arm/mach-s3c2410/mach-smdk2410.c
在开始处加入:
#include <asm-arm/arch-s3c2410/smdk2410.h>/* ++ */
5、
在配置选项中加入配置CS8900的选项
打开drivers/net/arm/Kconfig文件,在后面加入:
Config ARM_CS8900
tristate "CS8900 support"
depends on NET_ETHERNET && ARM && ARCH_SMDK2410
help
Support for CS8900A chipset based Ethernet cards. If you have a network (Ethernet) card of this type, say Y and read the Ethernet-HOWTO, available from as well as .
To compile this driver as a module, choose M here and read
. The module will be
called cs8900.o.
(后面这些帮助信息你自己随便加了,无所谓的,这个我也是抄网上的)
6、
进行配置
make menuconfig
出现配置界面进行配置:
选中如下的选项:
Device drivers ---->
Network device support --->
Ethernet (10 or 100 Mbit)----->
CS8900 Support
7、保存,进行编译。
make zImage
8、生成uImage通过tftp下载。
启动后挂载NFS文件系统后进行ping测试:
PING 202.198.137.100 (202.198.137.100): 56 data bytes
64 bytes from 202.198.137.100: seq=0 ttl=64 time=1.504 ms
64 bytes from 202.198.137.100: seq=1 ttl=64 time=1.194 ms
64 bytes from 202.198.137.100: seq=2 ttl=64 time=1.043 ms
64 bytes from 202.198.137.100: seq=3 ttl=64 time=1.025 ms
移植完成,表明成功。