Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3170396
  • 博文数量: 685
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5303
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-19 14:17
个人简介

文章分类

全部博文(685)

文章存档

2015年(116)

2014年(569)

分类: 嵌入式

2014-08-15 15:13:36

原文地址:http://liu1227787871.blog.163.com/blog/static/205363197201272611483434/

一、参考mach-mini2440.c文件,在mach-smdk2440.c文件里面添加如下内容:
#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 smdk2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(smdk2440_dm9k_resource),
.resource = smdk2440_dm9k_resource,
.dev = {
.platform_data = &smdk2440_dm9k_pdata,
},
};

二、在mach-smdk2440.c文件的smdk2440_devices里添加:&smdk2440_device_eth,
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&smdk2440_device_eth,  //新加
};

三、mach-smdk2440.c文件里添加头文件:#include

四、实验:
用新内核启动开发板
ping 192.168.183.128   :可以ping通
mount -t nfs -o nolock,vers=2 192.168.183.128:/home/share /mnt   :也是成功的!

五、优化
如果想使用较新版本的dm9000.c文件,我们需要修改厂家提供的dm9000.c文件,之前我们在dm9000驱动的时候曾经将厂家提供的网卡驱动修改好了,包括Makefile、dm9dev9000c.c两个文件。先见Makefile文件的内核目录改成:dm9dev9000c.c。之后编译!
我们的任务就是修改错误!
39行:注释掉头文件:#include
302行:添加头文件:#include
358行:注释掉: SET_MODULE_OWNER(dev);
409、410行:注释掉,并替换为:db = netdev_priv(dev);
                                                         memset(db, 0, sizeof(struct board_info));
并将所有的:board_info_t *db = (board_info_t *)dev->priv;
替换为:
board_info_t *db =   netdev_priv(dev) ;

将所有的:db = (board_info_t *)dev->priv;
替换为:db = netdev_priv(dev);

重新编译,并修改错误:
426行:在419行左右添加:dev->netdev_ops = &dm9k_netdev_ops;
并在dm9dev9000c.c文件里面添加如下代码:
static const struct net_device_ops dm9k_netdev_ops = {
.ndo_open = dmfe_open,
.ndo_stop = dmfe_stop,
.ndo_start_xmit = dmfe_start_xmit,
.ndo_tx_timeout = dmfe_timeout,
.ndo_set_rx_mode = dm9000_hash_table,
.ndo_do_ioctl = dmfe_do_ioctl,
.ndo_get_stats      =  &dmfe_get_stats,
.ndo_change_mtu = eth_change_mtu,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = eth_mac_addr,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = dm9000_poll_controller,
#endif
};

并将下列代码注释掉:
dev->open  = &dmfe_open;
dev->hard_start_xmit  = &dmfe_start_xmit;
dev->tx_timeout = dmfe_timeout;
dev->stop  = &dmfe_stop;
dev->set_multicast_list = &dm9000_hash_table;
dev->do_ioctl  = &dmfe_do_ioctl;
dev->get_stats  = &dmfe_get_stats;

重新编译,并修改错误:
1400行:将dm9000_hash_table函数替换成如下代码:

static void
dm9000_hash_table_unlocked(struct net_device *dev)
{
board_info_t *db = netdev_priv(dev);
struct netdev_hw_addr *ha;
int i, oft;
u32 hash_val;
u16 hash_table[4];
u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN;

dm9000_dbg(db, 1, "entering %s\n", __func__);

for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
iow(db, oft, dev->dev_addr[i]);

/* Clear Hash Table */
for (i = 0; i < 4; i++)
hash_table[i] = 0x0;

/* broadcast address */
hash_table[3] = 0x8000;

if (dev->flags & IFF_PROMISC)
rcr |= RCR_PRMSC;

if (dev->flags & IFF_ALLMULTI)
rcr |= RCR_ALL;

/* the multicast address in Hash Table : 64 bits */
netdev_for_each_mc_addr(ha, dev) {
hash_val = ether_crc_le(6, ha->addr) & 0x3f;
hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
}

/* Write the hash table to MAC MD table */
for (i = 0, oft = DM9000_MAR; i < 4; i++) {
iow(db, oft++, hash_table[i]);
iow(db, oft++, hash_table[i] >> 8);
}

iow(db, DM9000_RCR, rcr);
}

static void
dm9000_hash_table(struct net_device *dev)
{
board_info_t *db = netdev_priv(dev);
unsigned long flags;

spin_lock_irqsave(&db->lock, flags);
dm9000_hash_table_unlocked(dev);
spin_unlock_irqrestore(&db->lock, flags);
}

重新编译:
1405行:缺少头文件dm9000.h,我们可以将内核自带的dm9000.h拷贝过来,并在:dm9dev9000c.c文件里添加头文件:#include “dm9000.h”

重新编译:
1408行:将下列代码注释掉:
.get_rx_csum = dmfe_get_rx_csum,
.set_rx_csum = dmfe_set_rx_csum,
.get_tx_csum = dmfe_get_tx_csum,
.set_tx_csum = dmfe_set_tx_csum,

        error: implicit declaration of function 'dm9000_dbg'

没有错误了,我们需要将dm9dev9000c.c编译进内核,方法如下:
1、cp dm9dev9000c.c /home/share/jz2440/source/kernel/linux-3.4.2/drivers/net/ethernet/davicom/
2、cd /home/share/jz2440/source/kernel/linux-3.4.2/drivers/net/ethernet/davicom/
      vi Makefile
将:obj-$(CONFIG_DM9000) += dm9000.o
修改为:obj-$(CONFIG_DM9000) += dm9dev9000c.o
cd /home/share/jz2440/source/kernel/linux-3.4.2
make uImage
使用新内核:
nfs 30000000 192.168.183.128:/home/share/jz2440/source/kernel/linux-3.4.2/arch/arm/boot/uImage
bootm 30000000
ping 192.168.183.128   :可以ping通
mount -t nfs -o nolock,vers=2 192.168.183.128:/home/share /mnt   :也是成功的!

六、使用nfs文件系统
set bootargs console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.183.128:/home/share/jz2440/source/other/fs_mini_mdev_new ip=192.168.183.127:192.168.183.128:192.168.183.225:225.225.225.0::eth0:off
nfs 30000000 192.168.183.128:/home/share/jz2440/source/kernel/linux-3.4.2/arch/arm/boot/uImage
bootm 30000000
成功!!!

最后我们可以将: 
*bankcon4 = (1<<8)|(1<<6);
//*bankcon4 = (7<<8)|(1<<6);  
改为:
//*bankcon4 = (1<<8)|(1<<6);
*bankcon4 = (7<<8)|(1<<6);  
速度会快一点点!

七、制作补丁
cd linux-3.4.2
cp .config config.ko
make distclean
cd ..
mv linux-3.4.2 linux-3.4.2_lht
tar xvf linux-3.4.2.tar.bz2
diff -urN  linux-3.4.2  linux-3.4.2_lht >  linux-3.4.2_lht.patch

八、使用补丁
cd linux-3.4.2
patch -p1 < ../linux-3.4.2_lht.patch
cp ../config.ok .
cp config.ok .config
make uImage


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