在这一篇中,我们首先让开发板对CS8900或者DM9000X网卡的支持,然后再分析实现u-boot怎样来引导Linux内核启动。因为测试u-boot引导内核我们要用到网络下载功能。
7)u-boot对CS8900或者DM9000X网卡的支持。
u-boot-2009.08版本已经对CS8900和DM9000X网卡有比较完善的代码支持(代码在drivers/net/目录下),而且在S3C24XX系列中默认对CS8900网卡进行配置使用。只是在个别地方要根据开发板的具体网卡片选进行设置,就可以对S3C24XX系列中CS8900网卡的支持使用。代码如下:
现在修改对我们开发板上DM9000X网卡的支持。
首先,我们看看drivers/net/目录下有关DM9000的代码,发现dm9000x.h中对CONFIG_DRIVER_DM9000宏的依赖,dm9000x.c中对CONFIG_DM9000_BASE宏、DM9000_IO宏、DM9000_DATA等宏的依赖,所以我们修改代码如下:
#gedit include/configs/my2440.h
#define CONFIG_BOOTDELAY 3 /*#define CONFIG_BOOTARGS "root=ramfs devfs=mount console=ttySA0,9600" */ #define CONFIG_ETHADDR 08:00:3e:26:0a:5b #define CONFIG_NETMASK 255.255.255.0 #define CONFIG_IPADDR 192.168.0.119 #define CONFIG_SERVERIP 192.168.0.111 #define CONFIG_GATEWAYIP 192.168.0.1 #define CONFIG_OVERWRITE_ETHADDR_ONCE /*#define CONFIG_BOOTFILE "elinos-lart" */ /*#define CONFIG_BOOTCOMMAND "tftp; bootm" */ /* * 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 0x20000300 #define DM9000_IO CONFIG_DM9000_BASE #define DM9000_DATA (CONFIG_DM9000_BASE + 4) #define DM9000_IO CONFIG_DM9000_BASE //#define CONFIG_DM9000_USE_16BIT 1 注意: u-boot-2009.08 可以自动检测DM9000网卡的位数,根据开发板原理图可知网卡的数据位为16位,并且网卡位于CPU的BANK4上,所以只需在 board/samsung/my2440/lowlevel_init.S中设置 #define B4_BWSCON (DW16) 即可,不需要此处的 #define CONFIG_DM9000_USE_16BIT 1 #undef CONFIG_DM9000_DEBUG //给u-boot加上ping命令,用来测试网络通不通 #define CONFIG_CMD_PING
添加板载DM9000网卡初始化代码,如下:
#gedit board/samsung/my2440/my2440.c
#include <net.h> #include <netdev.h> #ifdef CONFIG_DRIVER_DM9000 extern int dm9000_initialize(bd_t *bis); int board_eth_init(bd_t *bis) { return dm9000_initialize(bis); } #endif
修改MD9000网卡驱动代码,如下:
#gedit drivers/net/dm9000x.c // 需要三处修改,以下三处可能顺序不对,读者自行校正
#if 1 i = 0; while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */ udelay(1000); i++; if (i == 3000) { printf("could not establish link\n"); return 0; } } #endif 。。。。。。 。。。。。。 /* Stop the interface. The interface is stopped when it is brought. */ static void dm9000_halt(struct eth_device *netdev) { #if 0 DM9000_DBG("%s\n", __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 */ #endif } 。。。。。。 。。。。。。 /* Read a word from phyxcer */ // phy_read 函数中只修改了 带/* Wait read complete */标注的一行 static u16 phy_read(int reg) { u16 val; /* Fill the phyxcer register into REG_0C */ DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ udelay(1000); //udelay(100); /* Wait read complete */ DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */ DM9000_DBG("phy_read(0x%x): 0x%x\n", reg, val); return val; }
net/nfs.c
#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
此博文是两篇博文的合体:
http://www.embeddedlinux.org.cn/html/jishuzixun/201303/16-2496.html
http://www.linuxidc.com/Linux/2011-05/35982p4.htm
注:移植网卡这一块,经常碰到的问题是,不能ping通主机,本人也遇到了,参考以上两篇文章后,当以XP(自己的家用电脑),为主机时,可以ping通,以WIN7(公司电脑,防火墙受管理员控制,自己改不了设置)为主机时,不能ping通,最后判断,网卡移植没问题,问题是:公司电脑防火墙的问题。
最后,发个能ping通的画面
网卡搞定后,就可以下载了
直接上图吧:
上图,成功将1.bin文件下载到NAND FLASH的0x60000位置上