一、移植环境
1. 内核源码版本: linux-2.6.31.1
2. 交叉编译器版本: arm-linux-gcc 4.3.3
3. Linux环境:redhat enterprise 5.5 (2.6.18-194.el5)
4. 开发板:TQ2440
二、移植过程
说明:我将linux内核源码解压在redhat enterprise 5.5的/opt目录下,下面所有对文件的修改都是linux-2.6.31.1源代码中的文件。移植之前,内核,文件系统的移植都已经完成。
1. 修改arch/arm/mach-s3c2440/mach-smdk2440.c文件,在platform_device结构体中增加下面1行
&s3c_device_dm9000, /* DM9000 */
2.
修改arch/arm/mach-s3c2440/mach-smdk2440.c,增加如下内容:
-
#include <linux/dm9000.h>
-
static struct resource s3c_dm9k_resource[] = {
-
[0] = {
-
.start = S3C2410_CS4,
-
.end = S3C2410_CS4 + 3,
-
.flags = IORESOURCE_MEM,
-
},
-
-
[1] = {
-
.start = S3C2410_CS4 + 4,
-
.end = S3C2410_CS4 + 4 + 3,
-
.flags = IORESOURCE_MEM,
-
},
-
-
[2] = {
-
.start = IRQ_EINT7,
-
.end = IRQ_EINT7,
-
.flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
-
},
-
};
-
-
static struct dm9000_plat_data s3c_dm9k_platdata = {
-
.flags = DM9000_PLATF_16BITONLY,
-
};
-
-
struct platform_device s3c_device_dm9000 = {
-
.name = "dm9000",
-
.id = 0,
-
.num_resources = ARRAY_SIZE(s3c_dm9k_resource),
-
.resource = s3c_dm9k_resource,
-
.dev = {
-
.platform_data = &s3c_dm9k_platdata,
-
},
-
};
4. 修改drivers/net/dm9000.c文件,
(1) #include "dm9000.h"后增加头文件
-
#if defined(CONFIG_ARCH_S3C2410)
-
#include <mach/regs-mem.h>
-
#endif
(2) 在dm9000_probe接口中
int iosize;
int i;
u32 id_val;
增加:
-
#if defined(CONFIG_ARCH_S3C2410)
-
unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
-
unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;
-
#endif
dev_dbg(&pdev->dev, "dm9000_probe()\n");
后增加
-
#if defined(CONFIG_ARCH_S3C2410)
-
*((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_B
-
WSCON_ST4;
-
*((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
-
#endif
db->mii.mdio_write = dm9000_phy_write;
后修改代码:
-
#if defined(CONFIG_ARCH_S3C2410)
-
printk("Now use the default MAC address: 08:90:90:90:90:90\n");
-
mac_src = "S3C2440";
-
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;
-
#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
out:
后增加代码
-
#if defined(CONFIG_ARCH_S3C2410)
-
*(volatile unsigned int *)S3C2410_BWSCON = oldval_bwscon;
-
*(volatile unsigned int *)S3C2410_BANKCON4 = oldval_bankcon4;
-
#endif
5. 以上4步完成后,即完成了对dm9000驱动的添加
6. 配置内核,支持网卡:
shell中运行make menuconfig,找到Device Drivers项
Device Drivers --->
[*] Network device support --->
[*] Ethernet (10 or 100Mbit) --->
<*> DM9000 support
(4) DM9000 maximum debug level
配置完成后,保存退出。
7. 重新编译内核,运行:
make zImage
编译完成后会在arch/arm/boot/目录下生成zImage文件,这个文件就是编译好的内核文件,
烧到开发板nand flash中就可以了。
8. 配置系统启动时启用网卡(这里要启动开发板,登录开发板linux系统后,对系统内的/etc/init.d/rcS文件进行修改)
由于之前在移植buybox时,没有对网络进行配置,所以在移植完
dm9000后,在系统启动脚本增加开发板IP地址配置,这里简单的在/etc/init.d/rcS脚本中添加网络配置。
编辑/etc/init.d/rcS文件,添加下面内容:
/sbin/ifconfig lo 127.0.0.1 up
/sbin/ifconfig eth0 192.168.1.8 netmask 255.255.255.0 up
/sbin/route add default gw 192.168.1.1 eth0
保存,退出。
9. 重启开发板,启动时输出:
dm9000 Ethernet Driver, V1.31
Now use the default MAC address: 08:90:90:90:90:90
eth0: dm9000e at c4810300,c4814304 IRQ 51 MAC: 08:90:90:90:90:90 (MY2440)
连接好计算机与开发板之间的网线,如果开发板网卡灯亮起来,说明已经连接好了。
从计算机ping开发板,就可以了。
阅读(2337) | 评论(0) | 转发(1) |