在这一篇中,我们首先让开发板对CS8900或者DM9000X网卡的支持,然后再分析实现u-boot怎样来引导Linux内核启动。因为测试u-boot引导内核我们要用到网络下载功能。
7)u-boot对CS8900或者DM9000X网卡的支持。 u-boot-2009.08版本已经对CS8900和DM9000X网卡有比较完善的代码支持(代码在drivers/net/目录下),而且在S3C24XX系列中默认对CS8900网卡进行配置使用。只是在个别地方要根据开发板的具体网卡片选进行设置,就可以对S3C24XX系列中CS8900网卡的支持使用。代码如下:
- #vim include/configs/yyq2440.h
- /*
- * Hardware drivers
- */
- #define CONFIG_DRIVER_CS8900 1 /* we have a CS8900 on-board */
- #define CS8900_BASE 0x19000300 //注意:对不同的开发板就是要修改这个片选地址参数,这个参数值就看开发板上网卡的片选引脚是接到ARM芯片存储控制器的哪个Bank上
- #define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */
现在修改对我们开发板上DM9000X网卡的支持。 首先,我们看看drivers/net/目录下有关DM9000的代码,发现dm9000x.h中对CONFIG_DRIVER_DM9000宏的依赖,dm9000x.c中对CONFIG_DM9000_BASE宏、DM9000_IO宏、DM9000_DATA等宏的依赖,所以我们修改代码如下:
- #vim include/configs/yyq2440.h
- /* * Hardware drivers */ 屏蔽掉u-boot默认对CS8900网卡的支持
- //#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 */
- //添加u-boot对DM9000X网卡的支持
- #define CONFIG_DRIVER_DM9000 1
- #define CONFIG_NET_MULTI 1
- #define CONFIG_DM9000_NO_SROM 1
- #define CONFIG_DM9000_BASE 0x20000000 //网卡片选地址
- #define DM9000_IO CONFIG_DM9000_BASE
- #define DM9000_DATA (CONFIG_DM9000_BASE + 4) //网卡数据地址
- #define CONFIG_DM9000_USE 16BIT 1
- 注意:
- u-boot-2009.08 可以自动检测DM9000网卡的位数,根据开发板原理图可知网卡的数据位为16位,并且网卡位于CPU的BANK4上
- //给u-boot加上ping命令,用来测试网络通不通
- #define CONFIG_CMD_PING
- //恢复被注释掉的网卡MAC地址和修改你合适的开发板IP地址
- #define CONFIG_ETHADDR 08:00:3e:26:0a:5b //开发板MAC地址
- #define CONFIG_NETMASK 255.255.255.0
- #define CONFIG_IPADDR 192.168.7.1 //开发板IP地址
- #define CONFIG_SERVERIP 192.168.1.11
添加板载DM9000网卡初始化代码,如下:
- #vim board/samsung/yyq2440/yyq2440.c
- #include <net.h>
- #include <netdev.h>
- #ifdef CONFIG_DRIVER_DM9000
- int board_eth_init(bd_t *bis)
- {
- return dm9000_initialize(bis);
- }
- #endif
修改MD9000网卡驱动代码,如下:
- #vim drivers/net/dm9000x.c
- static int dm9000_init(struct eth_device *dev, bd_t *bd)
- {
- ............
-
- i = 0;
- while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
- udelay(1000);
- i++;
- if (i == 10000) {
- //printf("could not establish link ");
- //return 0;
- //把上面改为break;不然使用网卡的时候会报“could not establish link”的错误
- break;
- }
- }
- .............
- }
然后重新编译u-boot,下载到Nand中从Nand启动,查看启动信息和环境变量可以得知,u-boot已经可以识别了dm9000。
- U-Boot 2009.08 ( 2月 28 2011 - 20:48:30)
- DRAM: 64 MB
- Flash: 512 kB
- NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
- 128 MiB
- In: serial
- Out: serial
- Err: serial
- Net: dm9000
- [yyq2440] #
并使用ping命令测试网卡,操作如下:
- [yyq2440] # printenv
- bootdelay=3
- baudrate=115200
- ethaddr=08:00:3e:26:0a:5b
- ipaddr=192.168.7.1
- serverip=192.168.7.11
- netmask=255.255.255.0
- stdin=serial
- stdout=serial
- stderr=serial
- ethact=dm9000
-
- Environment size: 175/131068 bytes
- [yyq2440] # ping 192.168.7.11
- dm9000 i/o: 0x20000000, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at 100M full duplex mode
- Using dm9000 device
- ping failed; host 192.168.7.11 is not alive
- [yyq2440] #
可以看到,启动信息里面显示了Net:dm9000,printenv查看的环境变量也和include/configs/yyq2440.h中设置的一致。但是现在有个问题就是ping不能通过。
经过一段时间在网上搜索,原来有很多人都碰到了这种情况。出现问题的地方可能是DM9000网卡驱动中关闭网卡的地方,如是就试着修改代码如下:
- #gedit drivers/net/dm9000x.c //屏蔽掉dm9000_halt函数中的内容
- /*
- Stop the interface.
- The interface is stopped when it is brought.
- */
- static void dm9000_halt(struct eth_device *netdev)
- {
- //DM9000_DBG("%sn", __func__);
- ///* RESET devie */
- //phy_write(0, 0x8000); /* PHY RESET */
- //DM9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */
- //DM9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */
- //DM9000_iow(DM9000_RCR, 0x00); /* Disable RX */
- }
结果,只是第一次ping不通,以后都是可以ping通的(据网友们说这是正常的),如下图:
- U-Boot 2009.08 ( 2月 28 2011 - 20:57:16)
- DRAM: 64 MB
- Flash: 512 kB
- NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
- 128 MiB
- In: serial
- Out: serial
- Err: serial
- Net: dm9000
- [yyq2440] #
- [yyq2440] # ping 192.168.7.11
- dm9000 i/o: 0x20000000, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at 100M full duplex mode
- Using dm9000 device
- ping failed; host 192.168.7.11 is not alive
- [yyq2440] # ping 192.168.7.11
- dm9000 i/o: 0x20000000, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at 100M full duplex mode
- Using dm9000 device
- ping failed; host 192.168.7.11 is alive
好了,现在只剩下一个问题了,就是使用tftp进行下载。关于tftp服务器在Linux中的安装和配置,这里我就不讲了,在网上搜一下很多的。然而,在tftp下载时又遇到了问题。我先试着下载一个小文件hello.bin,没有问题。但是尝试下载2M大小的zImage的时候i,总是出现传送不完整又重新传送的现象,不断的循环,如下图:
- [yyq2440] # tftp 0x30008000 hello.bin
- dm9000 i/o: 0x20000300, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at unknown: 0 mode
- Using dm9000 device
- TFTP from server 192.168.1.101; our IP address is 192.168.1.100
- Filename 'hello.bin'.
- Load address: 0x30008000
- Loading: #
- done
- Bytes transferred = 514 (202 hex)
- [yyq2440] # tftp 0x30800000 zImage
- dm9000 i/o: 0x20000300, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at unknown: 0 mode
- Using dm9000 device
- TFTP from server 192.168.1.101; our IP address is 192.168.1.100
- Filename 'zImage'.
- Load address: 0x30800000
- Loading: T T T ###T T T T T T T
- Retry count exceeded; starting again
- dm9000 i/o: 0x20000300, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at unknown: 0 mode
- Using dm9000 device
- TFTP from server 192.168.1.101; our IP address is 192.168.1.100
- Filename 'zImage'.
- Loading: T ##T T T T T T T T T
- Retry count exceeded; starting again
- ^C
- Abort
- [yyq2440 ] #
经过一段时间的努力,困惑好久的tftp问题现在终于搞定啦,心情真是爽啊!!首先分析上面图中的现象,在下载过程中断断续续就说明是可以下载的,只是由于某种原因使网络出现超时从而重新下载,那我想出现这种情况的最大的可能性就是u-boot中对网络的延时设置;我就跟踪u-boot中的代码,结果发现真的是这个原因。解决办法就是修改tftp网络源码中关于超时的值。
- #vim net/tftp.c
- #define TIMEOUT 5000UL
- #ifndef CONFIG_NET_RETRY_COUNT
- # define TIMEOUNT_COUNT 10
- #else
- # define TIMEOUNT_COUNT(CONFIG_NET_RETRY_COUNT * 2)
- #endif
因为没有定义CONFIG_NET_RETRY_COUNT这个宏,所以改为:
- #vim net/tftp.c
- #define TIMEOUT 13000UL
- #ifndef CONFIG_NET_RETRY_COUNT
- # define TIMEOUNT_COUNT 25
- #else
- # define TIMEOUNT_COUNT(CONFIG_NET_RETRY_COUNT * 2)
- #endif
最后重新编译烧写到开发板,并用tftp下载zImage,虽然还是有超时的时候,不过最后还是能够下载完整个文件。花了好几天时间终于把问题解决完了。大功告成!!心里有些许激动。嘿嘿。
- U-Boot 2009.08 ( 2月 28 2011 - 21:27:46)
- DRAM: 64 MB
- Flash: 512 kB
- NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
- 128 MiB
- In: serial
- Out: serial
- Err: serial
- Net: dm9000
- [yyq2440] # tftp 0x30008000 zImage
- dm9000 i/o: 0x20000300, id: 0x90000a46
- DM9000: running in 16 bit mode
- MAC: 08:00:3e:26:0a:5b
- operating at 100M full duplex mode
- Using dm9000 device
- TFTP from server 192.168.7.11; our IP address is 192.168.7.1
- Filename 'zImage'.
- Load address: 0x30008000
- Loading: T T T T T #########################T #T ###################
- ###T T ####T #################T ######################T ### ###T T
- ######
- done
- Bytes transferred = 2026844 (1eed5c hex)
- [yyq2440] #
2011-02-28
|