linux内核:2.6.39
参考文档:http://blog.sina.com.cn/s/blog_63ac1cef0100ute3.html
1) 添加网卡驱动的平台数据信息,包括:网卡的资源(地址资源、数据资源以及中断号等)、数据位数、网卡名称等。编辑文件arch/arm/plat-s3c24xx/devs.c,具体添加内容如下:
在文件开头添加:
38行: #include
//在引用头文件处添加dm9000.h头文件,该文件包含S3C2410_CS4等定义
在最后添加:
-
/* DM9000AEP 10/100 ethernet controller */
-
#define MACH_MY2440_DM9K_BASE (S3C2410_CS4 + 0x300)
-
-
static struct resource my2440_dm9k_resource[] = {
-
[0] = {
-
.start = MACH_MY2440_DM9K_BASE,
-
.end = MACH_MY2440_DM9K_BASE + 3,
-
.flags = IORESOURCE_MEM
-
},
-
[1] = {
-
.start = MACH_MY2440_DM9K_BASE + 4,
-
.end = MACH_MY2440_DM9K_BASE + 7,
-
.flags = IORESOURCE_MEM
-
},
-
[2] = {
-
.start = IRQ_EINT7,
-
.end = IRQ_EINT7,
-
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
-
}
-
};
-
-
/*
-
* * The DM9000 has no eeprom, and it's MAC address is set by
-
* * the bootloader before starting the kernel.
-
* */
-
static struct dm9000_plat_data my2440_dm9k_pdata = {
-
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
-
};
-
-
struct platform_device my2440_device_eth = {
-
.name = "dm9000",
-
.id = -1,
-
.num_resources = ARRAY_SIZE(my2440_dm9k_resource),
-
.resource = my2440_dm9k_resource,
-
.dev = {
-
.platform_data = &my2440_dm9k_pdata,
-
},
-
};
-
-
EXPORT_SYMBOL(my2440_device_eth);
2) 导出my2440_device_eth变量。编辑arch/arm/plat-samsung/include/plat/devs.h文件,具体添加内容如下:
-
extern struct platform_device my2440_device_eth;
3) 添加my2440_device_eth到平台设备数组。编辑arch/arm/mach-s3c2440/mach-my2440.c文件,具体添加内容如下:
-
static struct platform_device *my2440_devices[] __initdata = {
-
&s3c_device_ohci,
-
&s3c_device_lcd,
-
&s3c_device_wdt,
-
&s3c_device_i2c0,
-
&s3c_device_iis,
-
//lisi
-
&s3c_device_nand,
-
&s3c_device_rtc,
-
&my2440_device_eth,
-
};
4)修改/drivers/net/dm9000.c文件。由于在common-smdk.c中设置了dm9000使用的系统资源是CS4,因此需要根据dm9000的芯片手册来设置BWSCON和BANKCON4寄存器。另外由于dm9000网卡中断信号为上升沿,因此需要在网卡注册中断前设置中断信号为上升沿有效。具体修改内容如下:
(1)添加处理s3c2440寄存器头文件,红色为增加部分的代码。
-
#include <asm/delay.h>
-
#include <asm/irq.h>
-
#include <asm/io.h>
-
-
#if defined(CONFIG_ARCH_S3C2410)
-
#include <mach/regs-mem.h>
-
#endif
(2) dm9000_open()函数中添加对中断类型的处理
-
if (netif_msg_ifup(db))
-
dev_dbg(db->dev, "enabling %s\n", dev->name);
-
-
/* If there is no IRQ type specified, default to something that
-
* may work, and tell the user that this is a problem */
-
-
#ifdef CONFIG_ARCH_S3C2410
-
irqflags = IRQF_SHARED | IRQF_TRIGGER_RISING;
-
#else
-
if (irqflags == IRQF_TRIGGER_NONE)
-
dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
-
-
irqflags |= IRQF_SHARED;
-
#endif
-
-
if (request_irq(dev->irq, dm9000_interrupt, irqflags, dev->name, dev))
-
return -EAGAIN;
(3)dm9000_probe()函数中添加对BWSCON和BANKCON4寄存器的处理,具体的数值请查阅s3c2440A芯片手册
-
static int __devinit
-
dm9000_probe(struct platform_device *pdev)
-
{
-
struct dm9000_plat_data *pdata = pdev->dev.platform_data;
-
struct board_info *db; /* Point a board information structure */
-
struct net_device *ndev;
-
const unsigned char *mac_src;
-
int ret = 0;
-
int iosize;
-
int i;
-
u32 id_val;
-
-
#if defined(CONFIG_ARCH_S3C2410)
-
unsigned int oldval_bwscon;
-
unsigned int oldval_bankcon4;
-
#endif
-
-
/* Init network device */
-
ndev = alloc_etherdev(sizeof(struct board_info));
-
if (!ndev) {
-
dev_err(&pdev->dev, "could not allocate device.\n");
-
return -ENOMEM;
-
}
-
-
SET_NETDEV_DEV(ndev, &pdev->dev);
-
-
#if defined(CONFIG_ARCH_S3C2410)
-
oldval_bwscon = *((volatile unsigned int *)S3C2410_BWSCON);
-
*((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) |
-
S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
-
oldval_bankcon4 = *((volatile unsigned int *)S3C2410_BANKCON4);
-
*((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
-
#endif
-
-
dev_dbg(&pdev->dev, "dm9000_probe()\n");
-
out:
-
dev_err(db->dev, "not found (%d).\n", ret);
-
-
#if defined(CONFIG_ARCH_S3C2410)
-
*((volatile unsigned int *)S3C2410_BWSCON) = oldval_bwscon;
-
*((volatile unsigned int *)S3C2410_BANKCON4) = oldval_bankcon4;
-
#endif
-
-
dm9000_release_board(pdev, db);
-
free_netdev(ndev);
-
-
return ret;
由于s3c2440不能很好的从eeprom中读取网卡的MAC地址,因此需要在probe函数中手动设置网卡的MAC地址,即:在设置网卡MAC地址出屏蔽掉原来代码,手动添加自己的MAC
-
#ifdef CONFIG_ARCH_S3C2410
-
mac_src = "handy";
-
ndev->dev_addr[0] = 0x01;
-
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);
-
}
-
#endif
5)编译并配置内核
[*] Networking support --->
Networking options --->
<*> Unix domain sockets
[*] TCP/IP networking
[*] IP:kernel level autoconfiguration
[*] IP:DHCP support
[*] Devices Drivers --->
[*] Network device support --->
[*] Ethernet(10 or 100Mbit) --->
<*> DM9000 support
6)DM9000网卡的配置
1.修改文件系统的“/etc/init.d/rcS”,添加如下所示内容:
ifconfig lo 127.0.0.1 //设置本地回环设备IP地址
net_set& //调用网络配置文件
2.在文件系统的/sbin目录下新建一个可执行文件“net_set”,其内容如下:
#!/bin/sh
echo Try to bring eth0 interface up ...>/dev/tq2440_serial0
if [ -f /etc/net.conf ];then
source /etc/net.conf
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
echo ifconfig eth0 hw ether $MAC > /dev/tq2440_serial0
ifconfig eth0 $IPADDR netmask $NETMASK up
echo ifconfig eth0 $IPADDR netmask $NETMASK up >
/dev/tq2440_serial0
route add default gw $GATEWAY
echo add default gw $GATEWAY > /dev/tq2440_serial0
else
ifconfig eth0 hw ether 10:23:45:67:89:ab
ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up
route add default gw 192.128.1.2
echo ifconfig eth0 hw ether 10:23:45:67:89:ab >
/dev/tq2440_serial0
echo ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up>
/dev/tq2440_serial0
echo route add default gw 192.128.1.2 >/dev/tq2440_serial0
fi
echo Done > /dev/tq2440_serial0
3.然后在文件系统的/etc目录下新建“net.conf”文件用于存放网络配置信息
IPADDR=192.168.1.6
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
MAC=10:23:45:67:89:ab
当要修改网卡的IP地址时,只需要修改“/etc/net.conf”文件的内容后,执行一下net_set命令即可
然后,重新制作根文件系统,烧到开发板。
阅读(1361) | 评论(0) | 转发(0) |