http://hi.baidu.com/andio/item/f6072b29d9e3bdf850fd8785
这里我们主要阐述DM9000的驱动在TQ2440+linux2.6.32下的移植,分俩部分,一是驱动移植,一是测试程序
硬件平台:TQ2440,DM9000EP
内核 : linux2.6.32
编译工具: codesource出品 arm-linux-none-gnueabi-4.3.3
文件系统: busybox1.1.11+yaffs
在此推荐一个文档:http://singleboy.blog.163.com/blog/static/5490019420115141426387/ mini2440的,在移植过程中参考了此文,鸣谢
一、DM9000驱动移植
主要修改俩个文件,一是mach-smdk2440.c,一是dm9000.c
1.1 mach-smdk2440.c
#vi arch/arm/mach-s3c2440/mach-smdk2440.c
修改mach-smdk2440.c,在其中添加如下红色所示的代码,注意gcc中#include是可以随处摆放的的,
因此只需要把如下红色代码copy 就可以了
/*
DM9000
*/
#include <linux/dm9000.h>
#define MACH_SMDK2440_DM9K_BASE (S3C2410_CS4 + 0x300)
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,
}
};
static struct dm9000_plat_data smdk2440_dm9k_pdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};
static struct platform_device s3c_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(smdk2440_dm9k_resource),
.resource = smdk2440_dm9k_resource,
.dev = {
.platform_data = &smdk2440_dm9k_pdata,
},
};
//如上代码置于smdk2440_devices[] 数组前
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_eth
};
1.2 dm9000.c
#vi driver/net/dm9000.c
在头文件处添加如下红色的代码
#include "dm9000.h"
#if defined(CONFIG_ARCH_S3C2410)
#include <mach/regs-mem.h>
#endif
修改static int __devinit dm9000_probe(struct platform_device *pdev)函数如下所示,
该函数大概位置1276行,需要修改的大概位置为1460行
db->mii.reg_num_mask = 0x1f;
db->mii.force_media = 0;
db->mii.full_duplex = 0;
db->mii.dev = ndev;
db->mii.mdio_read = dm9000_phy_read;
db->mii.mdio_write = dm9000_phy_write;
#if defined(CONFIG_ARCH_S3C2410)
printk("Now use the default MAC address: 10:23:45:67:89:ab\n");
mac_src = "tq2440";
ndev->dev_addr[0] = 0x10;
ndev->dev_addr[1] = 0x23;
ndev->dev_addr[2] = 0x45;
ndev->dev_addr[3] = 0x67;
ndev->dev_addr[4] = 0x89;
ndev->dev_addr[5] = 0xab;
#else
mac_src = "eeprom";
/* try reading the node address from the attached EEPROM */
for (i = 0; i < 6; i += 2)
dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
mac_src = "platform data";
memcpy(ndev->dev_addr, pdata->dev_addr, 6);
}
if (!is_valid_ether_addr(ndev->dev_addr)) {
/* try reading from mac */
mac_src = "chip";
for (i = 0; i < 6; i++)
ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
}
if (!is_valid_ether_addr(ndev->dev_addr))
dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
"set using ifconfig\n", ndev->name);
#endif
如上代码效果如图
修改dm9000_init(void)函数如下所示,大概位置1590行
static int __init
dm9000_init(void)
{
#if defined(CONFIG_ARCH_S3C2410)
unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;
*((volatile unsigned int *)S3C2410_BWSCON) =
(oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
*((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
#endif
printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);
return platform_driver_register(&dm9000_driver);
}
二、编译和测试
2.1 编译
编译选项Device Drivers --->Network device support ---> Ethernet (10 or 100Mbit) --->,
<*>DM9000 Surport,在此不做阐述
2.2 测试
编写如下测试文件
#vi net_set
ifconfig eth0 hw ether 10:23:45:67:89:ab
#ifconfig eth0 板子的ip地址 netmask 子网掩码 up
ifconfig eth0 172.18.25.15 netmask 255.255.255.0 up
#route add default gw 网关
route add default gw 172.18.25.254
#如下显示的是调试信息,可以不要
echo ifconfig eth0 hw ether 10:23:45:67:89:ab >/dev/console
echo ifconfig eth0 172.18.25.15 netmask255.255.255.0 up >/dev/console
echo route add default gw 172.18.25.254 >/dev/console
存放改文件到
/etc/init.d/net_set
#chmod +x net_set
运行之,即可以看到如下信息
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1,
继续测试,输入ping命令,拼局域网的一个主机172.18.25.9
#ping 172.18.25.9
PING 172.18.25.9 (172.18.25.9): 56 data bytes
64 bytes from 172.18.25.9: seq=0 ttl=64 time=2.128 ms
64 bytes from 172.18.25.9: seq=1 ttl=64 time=0.934 ms
64 bytes from 172.18.25.9: seq=2 ttl=64 time=0.939 ms
64 bytes from 172.18.25.9: seq=3 ttl=64 time=0.937 ms
64 bytes from 172.18.25.9: seq=4 ttl=64 time=0.867 ms
64 bytes from 172.18.25.9: seq=5 ttl=64 time=0.938 ms
64 bytes from 172.18.25.9: seq=6 ttl=64 time=0.942 ms
..............
说明移植成功
2.3 实现自启动net_set
修改inittab可以实现该功能
#vi /etc/inittab
在其中添加如下代码
::sysinit:/etc/init.d/net_set
即可