Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7723746
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

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


系统启动后,可能会出现这个错误:
ifconfig: SIOCSIFFLAGS: Cannot assign requested address
原因是MAC地址没有设置或没有设置对,在启动脚本中加上:
ifconfig eth0 down
ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX 􀃅MAC地址,随便设
ifconfig eth0 up
一般问题可以解决,如果还提示有错,再改一下MAC地址

 

在文件系统中添加网络配置文件,使系统在开机过程中自动完成对网卡的配置

   1)在文件系统/etc/net.conf文件中添加内容

IPADDR=192.168.1.105
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
MAC=10:23:45:67:89:ab

   2)在文件系统/sbin/目录下新建一个可执行的脚本文件net_config,注意文件的权限(可执行)

#!/bin/sh
echo Try to bring eth0 interface up ...>/dev/s3c2410_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/s3c2410_serial0
    ifconfig eth0 $IPADDR netmask $NETMASK up
    echo ifconfig eth0 $IPADDR netmask $NETMASK up >/dev/s3c2410_serial0
    route add default gw $GATEWAY
    echo add default gw $GATEWAY >/dev/s3c2410_serial0
else
    ifconfig eth0 hw ether 10:23:45:67:89:ab
    ifconfig eth0 192.168.1.105 netmask 255.255.255.0 up
    route add default gw 192.168.1.1
    echo ifconfig eth0 hw ether 10:23:45:67:89:ab >/dev/s3c2410_serial0
    echo ifconfig eth0 192.168.1.105 netmask 255.255.255.0 up >/dev/s3c2410_serial0
    echo route add default gw 192.168.1.1 >/dev/s3c2410_serial0
fi
echo Done > /dev/s3c2410_serial0

   3)在文件系统/etc/init.d/rcS文件中添加网络配置语句

/sbin/ifconfig lo 127.0.0.1     #设置本地回环设备的IP地址
net_config&                     #执行上面的net_config文件对网卡进行设置

8. 在文件系统中添加完上述网卡配置信息后重新编译文件系统下载到开发板,系统上电启动后就会对网卡自动配置,并执行#ifconfig命令可以看到网卡的配置信息

9. 测试与主机的通信,开发板的IP地址可以在/etc/net.conf中修改


 

 

  

阅读(1941) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~