分类: 嵌入式
2010-08-13 22:22:49
嵌入式学习入门 http://blog.chinaunix.net/u3/117680/showart.php?id=2300212
修改arch/arm/mach-s3c2440/mach-smdk2440.c 160行
Platform_device结构体中,加入:
&s3c_device_dm9000,
修改arch/arm/plat-s3c24xx/devs.c 在最前面38行加入:
#include
/*DM9000*/
static struct resource s3c_dm9000_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_EINT18, /*use eint18 GPG10*/
.end = IRQ_EINT18,
.flags = IORESOURCE_IRQ,
}
};
static struct dm9000_plat_data s3c_dm9000_platdata = {
.flags = DM9000_PLATF_16BITONLY,
};
static struct platform_device s3c_device_dm9000 = {
.name = "dm9000",
.id = 0,
.num_resources = ARRAY_SIZE(s3c_dm9000_resource),
.resource = s3c_dm9000_resource,
.dev = {
.platform_data = &s3c_dm9000_platdata,
}
};
EXPORT_SYMBOL(s3c_device_dm9000);
在arch/arm/plat-s3c/include/plat/devs.h中加入一行:
extern struct platform_device s3c_device_dm9000;
下面修改dm9000.c源码,在drivers/net/dm9000.c中
1. 添加头文件,在第43行加入:
#if defined(CONFIG_ARCH_S3C2410)
#include
#endif
2. 指定注册时的中断触发方式,在第1019行加入:
static int dm9000_open(struct net_device *dev)
{
…………
irqflags |= IRQF_SHARED;
#if defined (CONFIG_ARCH_S3C2410)
if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED|IRQF_TRIGGER_RISING,dev->name,dev))
#else
if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED,dev->name,dev))
#endif
//if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev))
return -EAGAIN;
…………
}
3. 设置BANK4, 设置MAC地址,在1215行,dm9000_probe函数中加入:
int ret = 0;
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
/* Init network device */
ndev = alloc_etherdev(sizeof(struct board_info));
if (!ndev) {
dev_err(&pdev->dev, "could not allocate device.\n");
return -ENOMEM;
}
在1231行加入:
SET_NETDEV_DEV(ndev, &pdev->dev);
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_BWSCON_ST4;
*((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
#endif
在1390行加入:
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: 08:90:90:90:90:90 ");
mac_src = "www.txmcu.com";
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
platform_set_drvdata(pdev, ndev);
ret = register_netdev(ndev);
if (ret == 0)
printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n",
ndev->name, dm9000_type_to_char(db->type),
db->io_addr, db->io_data, ndev->irq,
ndev->dev_addr, mac_src);
return 0;
out:
#if defined(CONFIG_ARCH_S3C2410) /* 加上这些 */
*(volatile unsigned int *)S3C2410_BWSCON = oldval_bwscon;
*(volatile unsigned int *)S3C2410_BANKCON4 = oldval_bankcon4;
#endif
配置内核,支持网卡:
Device Drivers --->
[*] Network device support --->
[*] Ethernet(10 or 100 Mbit) --->
<*> DM9000 support
(4) DM9000 maximum debug level
编译时出现一个奇怪的错误:
arch/arm/plat-s3c24xx/devs.c:63: error: static declaration of 's3c_device_dm9000' follows non-static declaration
arch/arm/plat-s3c/include/plat/devs.h:27: error: previous declaration of 's3c_device_dm9000' was here
s3c_device_dm9000首先在devs.c中定义,在devs.h中声明,在mach-s3c2440.c中使用,看了好几遍代码,应该没什么问题。查不到什么原因,我觉得是跟编译器有关,在devs.c中做了一下修改,问题解决,编译时只出现一个warning
把devs.c中的这句:
static struct platform_device s3c_device_dm9000 = {
的static改成extern,就可以了
启动时输出:
dm9000 Ethernet Driver, V1.31
Now use the default MAC address: 08:90:90:90:90:90
eth0: dm9000e at c881c000,c8820004 IRQ 62 MAC: 08:90:90:90:90:90
在文件系统中添加网络配置文件,使系统在开机过程中自动完成对网卡的配置
1)在文件系统/etc/net.conf文件中添加内容
|
2)在文件系统/sbin/目录下新建一个可执行的脚本文件net_config,注意文件的权限(可执行)
|
3)在文件系统/etc/init.d/rcS文件中添加网络配置语句
|
8. 在文件系统中添加完上述网卡配置信息后重新编译文件系统下载到开发板,系统上电启动后就会对网卡自动配置,并执行#ifconfig命令可以看到网卡的配置信息
9. 测试与主机的通信,开发板的IP地址可以在/etc/net.conf中修改