分类: 嵌入式
2009-12-23 22:38:14
一、开发平台
· 主 机:VMWare--Fedora 8
· 开发板:utu2440--64MB Nand / linux-
· 编译器:arm-linux-gcc-
二、移植步骤
在移植好内核和根文件系统的基础上,进行DM9000网卡驱动的移植。utu2440开发板上中断线为EINT9, CS连接到2440的nGCS3, INDEX和DATA端口地址分别为0x18000000和0x18000004。以下是移植步骤:
1. 添加内核配置选项
# cd linux-
# make menuconfig,选中以下配置选项:
Device Drivers --->
[*] Network device support --->
[*] Ethernet (10 or 100Mbit) --->
<*> DM9000 support
2. 添加dm9000的platform_device
# vi arch/arm/plat-s3c24xx/devs.c // add as following:
#include
static struct resource dm9000_resource[] = {
[0]= {
.start = 0x18000000,
.end = 0x18000003,
.flags = IORESOURCE_MEM,
},
[1]={
.start = 0x18000004,
.end = 0x18000007,
.flags = IORESOURCE_MEM,
},
[2]={
.start = IRQ_EINT9,
.end = IRQ_EINT9,
.flags = IORESOURCE_IRQ,
}
};
static struct dm9000_plat_data dm9000_platdata ={
.flags = DM9000_PLATF_16BITONLY,// work in 16bit mode
};
struct platform_device dm9000_device = {
.name = "dm9000",
.id = -1,
.num_resources = 3,
.resource = dm9000_resource,
.dev = {
.platform_data = &dm9000_platdata,
}
};
EXPORT_SYMBOL(dm9000_device);
# vi arch/arm/plat-s3c/include/plat/devs.h // add as following:
extern struct platform_device dm9000_device;
3. 将dm9000_device添加到平台设备列表中
# vi arch/arm/mach-s3c2440/mach-smdk2440.c
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&dm9000_device, /* add dm9000 */
};
4. OK,经过上述努力,dm9000设备已经成功注册进入驱动核心。下面进入driver/net/dm9000.c中,还需要做两方面的工作:设置芯片MAC地址,使能dm9000的中断.
根据2440资料。有几个地方需要设置:
1)设置GPGCON 使GPG1功能设置为EINT9 。
这可以用函数实现:s3c2410_gpio_cfgpin(S3C2410_GPG1, S3C2410_GPF3_EINT9);
2)外部中断EXTINT1 位设 置中断 触发方式
代码修改:
在dm9000.c的开始添加如下定义:
#include
static void *extint1,*intmsk;
#define EINTMASK (0x560000a4) //外部中断屏蔽
#define EXTINT1 (0x5600008c) //外部中断方式
#define INTMSK (0x4A000008) //中断屏蔽
在dm9000_probe函数中,register_netdev之前添加如下:
char net_mac_addr[] = {0x00, 0x6c, 0x69, 0x75, 0x67, 0x7A};
for (i = 0; i < 6; i++) {
ndev->dev_addr[i] = net_mac_addr[i];
}
extint1=ioremap_nocache(EXTINT1,0x0000004);
intmsk=ioremap_nocache(INTMSK,4);
s3c2410_gpio_cfgpin(S3C2410_GPG1, S3C2410_GPG1_EINT9);
writel(readl(extint1)|0x40,extint1);
writel(readl(intmsk)&0xfff1,intmsk);
iounmap(intmsk);
iounmap(extint1);
至此,移植过程结束. 编译内核,并在rootfs脚本中设置IP, 下载到开发板后重启,开发板和主机之间已能ping通。
[root@liuzg]\$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:6C:69:75:67:7A
inet addr:192.168.1.168 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4384 errors:0 dropped:0 overruns:0 frame:0
TX packets:1740 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5794116 (5.5 MiB) TX bytes:280444 (273.8 KiB)
Interrupt:53 Base address:0xe000
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:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
[root@liuzg]\$ ping 192.168.1.100
64 bytes from 192.168.1.100: seq=0 ttl=128 time=4.612 ms
64 bytes from 192.168.1.100: seq=1 ttl=128 time=0.956 ms
64 bytes from 192.168.1.100: seq=2 ttl=128 time=0.937 ms
64 bytes from 192.168.1.100: seq=3 ttl=128 time=0.950 ms
64 bytes from 192.168.1.100: seq=4 ttl=128 time=0.944 ms
^C
--- 192.168.1.100 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.937/1.679/4.612 ms
参考资料:
[1] http://blog.mcuol.com/User/lvembededsys/Article/6856_1.htm