分类: LINUX
2011-08-17 17:31:41
上接:《3 添加nand flash支持》
http://blog.chinaunix.net/space.php?uid=24473044&do=blog&id=2208595
4 添加DM9000支持(续)
参考说明:
(1)本文参考了singleboy:
(2)参考了Tekkaman Ninja的blog文章,http://blog.chinaunix.net/space.php?uid=20543672&do=blog&cuid=2085154
(3)参考了黄刚的blog:http://blogold.chinaunix.net:80/u3/101649/showart.php?id=2276917
向上述作者表示感谢!一、移植环境说明
1,主机环境:VMWare下RHEL5;
2,编译器:arm-linux-gcc v4.4.3;
3,开发板:mini2440,2M nor flash,256M nand flash(自改,原64M),NEC屏;
4,u-boot版本:u-boot-2009.08。
二、移植任务描述
为开发板添加网络功能。
三、移植步骤
u-boot-2009.08版本已经对CS8900、RTL8019和DM9000X等网卡有比较完善的代码支持(代码在drivers/net/目录下),而且在S3C24XX系列中默认对CS8900网卡进行配置使用。而mini2440开发板使用的则是DM9000网卡芯片,所以只需在开发板上添加对DM9000的支持即可。还有一点,以前的 U-boot 对于网络延时部分有问题,需要修改许多地方。但是现在的U-boot 网络部分已经基本不需要怎么修改了,只有在DM9000 的驱动和NFS 的TIMEOUT 参数上需要稍微修改一下。
DM9000驱动代码修改
【1】修改static int dm9000_init函数中部分代码,如果不修改这一部分,在使用网卡的时候会报“could not establish link”的错误。
gedit drivers/net/dm9000x.c,定位到378行,修改如下:
/* Activate DM9000 */
/* RX enable */
DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
/* Enable TX/RX interrupt mask */
DM9000_iow(DM9000_IMR, IMR_PAR);
i = 0;
while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
udelay(1000);
i++;
if (i == 1000) {
//printf("could not establish link\n");
//return 0;
break;
}
}
geit drivers/net/dm9000x.c,定位到377行,修改如下:
/* Activate DM9000 */
/* RX enable */
DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
/* Enable TX/RX interrupt mask */
DM9000_iow(DM9000_IMR, IMR_PAR);
#if 1 //internet delay loop
i = 0;
while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
udelay(1000);
i++;
if (i == 3000) {
printf("could not establish link\n");
return 0;
//break;
}
}
#endif
Tekkaman 定位到374行
# if 1
/* see what we've got */
lnk = phy_read(17) >> 12;
printf("operating at ");
switch (lnk) {
case 1:
printf("10M half duplex ");
break;
case 2:
printf("10M full duplex ");
break;
case 4:
printf("100M half duplex ");
break;
case 8:
printf("100M full duplex ");
break;
default:
printf("unknown: %d ", lnk);
break;
}
printf("mode\n");
#endif
return 0;
}
)
【2】对于NFS,增加了延时,否则会出现“*** ERROR: Cannot mount”的错误。
gedit net/nfs.c,定位到36行,修改如下:
#if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_NFS)
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
#define NFS_RETRY_COUNT 30
#define NFS_TIMEOUT (CONFIG_SYS_HZ/1000*2000UL) //2000UL
【3】添加网卡芯片(DM9000)的初始化函数
gedit board/gy/mini2440/mini2440.c,定位到165行附近,文件末尾处,修改如下:
int dram_init (void)
{
gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
return 0;
}
extern int dm9000_initialize(bd_t *bis);//implicit declaration of function 'dm9000_initialize'
#ifdef CONFIG_DRIVER_DM9000
int board_eth_init(bd_t *bis)
{
return dm9000_initialize(bis);
}
#endif
【4】修改配置文件,在mini2440.h中加入相关定义
gedit include/configs/mini2440.h,定位到60行附近,修改如下:
/*
* Hardware drivers
*/
#if 0
#define CONFIG_DRIVER_CS8900 1 /* we have a CS8900 on-board */
#define CS8900_BASE 0x19000300
#define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */
#endif
#define CONFIG_NET_MULTI 1
#define CONFIG_DRIVER_DM9000 1
#define CONFIG_DM9000_BASE 0x20000300 //网卡片选地址
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE+4) //网卡数据地址
#define CONFIG_DM9000_NO_SROM 1
#define CONFIG_DM9000_USE_16BIT 1
#undef CONFIG_DM9000_DEBUG
112行,给u-boot加上ping命令,用来测试网络通不通
/*
* Command line configuration.
*/
#include
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DATE
#define CONFIG_CMD_ELF
#define CONFIG_CMD_NAND
#define CONFIG_CMD_PING /*ping command support*/
恢复被注释掉的网卡MAC地址和修改你合适的开发板IP地址以及内核启动参数:
#define CONFIG_BOOTDELAY 1
#define CONFIG_ETHADDR 01:02:03:04:05:06
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 222.197.173.10
#define CONFIG_SERVERIP 222.197.173.99
#define CONFIG_GATEWAYIP 222.197.173.1
#define CONFIG_OVERWRITE_ETHADDR_ONCE
/*#define CONFIG_BOOTFILE "elinos-lart" */
重新编译u-boot,下载到Nand中从Nand启动,查看启动信息和环境变量并使用ping命令测试网卡,操作如下:
nand 方式上电重启后:
U-Boot 2009.08 (Aug 04 2011 - 10:51:37)
modified by gy (robinfit01@163.com)
Love pore and Linux forever!!!
DRAM: 64 MB
Flash: 2 MB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
[mini2440] #
ping测试:
[mini2440] #ping 222.197.173.99
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:00:00:00:00:00
operating at 100M full duplex mode
*** ERROR: `ethaddr' not set
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:00:00:00:00:00
operating at 100M full duplex mode
ping failed; host 222.197.173.99 is not alive
需要设定IP地址和MAC地址
[mini2440] #setenv ipaddr 222.197.173.10
[mini2440] #setenv serverip 222.197.173.99
[mini2440] #setenv setenv ethaddr 01:02:03:04:05:06
[mini2440] #saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x4000000000002 -- 0% complete.
Writing to Nand... done
[mini2440] #
然后再进行ping测试:
[mini2440] #ping 222.197.173.99
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 01:02:03:04:05:06
operating at 100M full duplex mode
Using dm9000 device
ping failed; host 10.1.0.128 is not alive
[mini2440] #
重启一下后问题解决:
U-Boot 2009.08 (Aug 04 2011 - 10:51:37)
modified by gy (robinfit01@163.com)
Love pore and Linux forever!!!
DRAM: 64 MB
Flash: 2 MB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
[mini2440] # printenv
bootdelay=3
baudrate=115200
netmask=255.255.255.0
ethact=dm9000
ethaddr=01:02:03:04:05:06
ipaddr=222.197.173.10
serverip=222.197.173.99
stdin=serial
stdout=serial
stderr=serial
Environment size: 177/131068 bytes
[mini2440] # ping 222.197.173.99
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 01:02:03:04:05:06
operating at 100M full duplex mode
Using dm9000 device
host 222.197.173.99 is alive
[mini2440] #
接下来添加yaffs2文件系统的支持(未完待续)。