详情请进入 湖南阳光电子学校 已关注:人 咨询电话:0731-85579057 微信号:yp941688, yp94168
1,主机环境:VMare下CentOS 5.5 ,1G内存。
2,集成开发环境:Elipse IDE
3,编译编译环境:arm-linux-gcc v4.4.3,arm-none-eabi-gcc v4.5.1。
4,开发板:mini2440,2M nor flash,128M nand flash。
5,u-boot版本:u-boot-2009.08
6,参考文章:
?id=2105215
?uid=23787856&do=blog&id=115382
u-boot-2009.08版本已经对CS8900、RTL8019和DM9000X等网卡有比较完善的代码支持(代码在drivers/net/目录下),而且在S3C24XX系列中默认对CS8900网卡进行配置使用。而mini2440开发板使用的则是DM9000网卡芯片,所以只需在开发板上添加对DM9000的支持即可。还有一点,以前的 U-boot 对于网络延时部分有问题,需要修改许多地方。但是现在的U-boot 网络
部分已经基本不需要怎么修改了,只有在DM9000 的驱动和NFS 的TIMEOUT 参数上需要稍微修改一下。
4.1,DM9000驱动代码修改
【1】修改static int dm9000_init函数中部分代码,如果不修改这一部分,在使用网卡的时候会报“could not establish link”的错误。
打开/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 0 //default to link MII interface
i = 0;
while (!(phy_read(1) & 0x20)) {/* autonegation complete bit */
udelay(1000);
i++;
if (i == 1650) {
//printf("could not establish linkn");
//return 0;
break;
}
}
#endif
【2】对于NFS,增加了延时,否则会出现“*** ERROR: Cannot mount”的错误。
打开/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)的初始化函数
打开board/samsung/mini2440/mini2440.c,定位到194行附近,文件末尾处,修改如下:
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】添加串口 Xmodem 传输协议(可不修改)
对于使用串口传输数据到内存的操作,有可能会用到Xmodem协议。但是原本的kermit协议传输就挺好用的,速度也比较快,所以可添加此功能。
打开/common/cmd_load.c,定位到37行,修改如下:
#if defined(CONFIG_CMD_LOADB)
#if defined(ENABLE_CMD_LOADB_X)
static ulong load_serial_xmodem (ulong offset);
#endif
static ulong load_serial_ymodem (ulong offset);
#endif
然后再定位到480行附近,修改如下:
if (load_baudrate != current_baudrate) {
printf ("## Switch baudrate to %d bps and press ENTER ...n",
load_baudrate);
udelay(50000);
gd->baudrate = load_baudrate;
serial_setbrg ();
udelay(50000);
for (;;) {
if (getc() == 'r')
break;
}
}
#if defined(ENABLE_CMD_LOADB_X)
if (strcmp(argv[0],"loadx")==0) {
printf ("## Ready for binary (xmodem) download "
"to 0x%08lX at %d bps...n",
offset,
load_baudrate);
addr = load_serial_xmodem (offset);
} else if (strcmp(argv[0],"loady")==0) {
#else
if (strcmp(argv[0],"loady")==0) {
#endif
printf ("## Ready for binary (ymodem) download "
"to 0x%08lX at %d bps...n",
offset,
load_baudrate);
addr = load_serial_ymodem (offset);
再定位到998行附近,修改如下:
static int getcxmodem(void) {
if (tstc())
return (getc());
return -1;
}
#if defined(ENABLE_CMD_LOADB_X)
static ulong load_serial_xmodem (ulong offset)
{
int size;
char buf[32];
int err;
int res;
connection_info_t info;
char xmodemBuf[1024];
ulong store_addr = ~0;
ulong addr = 0;
size = 0;
info.mode = xyzModem_xmodem;
res = xyzModem_stream_open (&info, &err);
if (!res) {
while ((res =
xyzModem_stream_read (xmodemBuf, 1024, &err)) > 0) {
store_addr = addr + offset;
size += res;
addr += res;
#ifndef CFG_NO_FLASH
if (addr2info (store_addr)) {
int rc;
rc = flash_write ((char *) xmodemBuf,
store_addr, res);
if (rc != 0) {
flash_perror (rc);
return (~0);
}
} else
#endif
{
memcpy ((char *) (store_addr), xmodemBuf,
res);
}
}
} else {
printf ("%sn", xyzModem_error (err));
}
xyzModem_stream_close (&err);
xyzModem_stream_terminate (false, &getcxmodem);
flush_cache (offset, size);
printf ("## Total Size = 0x%08x = %d Bytesn", size, size);
sprintf (buf, "%X", size);
setenv ("filesize", buf);
return offset;
}
#endif
static ulong load_serial_ymodem (ulong offset)
再定位到1169行,修改如下:
#if defined(CONFIG_CMD_LOADB)
U_BOOT_CMD(
loadb, 3, 0,do_load_serial_bin,
"load binary file over serial line (kermit mode)",
"[ off ] [ baud ]n"
" - load binary file over serial line"
" with offset 'off' and baudrate 'baud'"
);
#if defined(ENABLE_CMD_LOADB_X)
U_BOOT_CMD(
loadx, 3, 0, do_load_serial_bin,
"load binary file over serial line (xmodem mode)",
"[ off ] [ baud ]n"
" - load binary file over serial line"
" with offset 'off' and baudrate 'baud'"
);
#endif
U_BOOT_CMD(
loady, 3, 0,do_load_serial_bin,
"load binary file over serial line (ymodem mode)",
"[ off ] [ baud ]n"
" - load binary file over serial line"
" with offset 'off' and baudrate 'baud'"
);
【5】修改配置文件,在mini2440.h中加入相关定义
打开/include/configs/mini2440.h,定位到60行附近,修改如下:
/*
* Hardware drivers
*/
#if 0
#define CONFIG_DRIVER_CS89001/* we have a CS8900 on-board */
#define CS8900_BASE0x19000300
#define CS8900_BUS161 /* the Linux driver does accesses as shorts */
#endif
#define CONFIG_NET_MULTI1
#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_SROM1
//#define CONFIG_DM9000_USE_16BIT
#undef CONFIG_DM9000_DEBUG
注意:
u-boot-2009.08 可以自动检测DM9000网卡的位数,根据开发板原理图可知网卡的数据位为16位,并且网卡位
于CPU的BANK4上,所以只需在 board/samsung/mini2440/lowlevel_init.S中设置 #define B4_BWSCON (DW16) 即
可,不需要此处的 #define CONFIG_DM9000_USE_16BIT 1
给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_JFFS2 /* JFFS2 Support*/
#define CONFIG_CMD_PING /*ping command support*/
恢复被注释掉的网卡MAC地址和修改你合适的开发板IP地址以及内核启动参数:
#define CONFIG_BOOTDELAY3
#define CONFIG_ETHADDR08:00:3e:26:0a:5b
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR10.1.0.129
#define CONFIG_SERVERIP10.1.0.128
#define CONFIG_GATEWAYIP10.1.0.1
#define CONFIG_OVERWRITE_ETHADDR_ONCE
/*#define CONFIG_BOOTFILE"elinos-lart" */
定位到139行附近,加入使能串口传输数据到内存的操作:
#define ENABLE_CMD_LOADB_X1 //使能串口传输数据到内存的操作
#if defined(CONFIG_CMD_KGDB)
#define CONFIG_KGDB_BAUDRATE115200/* speed to run kgdb serial port */
/* what's this ? it's not used anywhere */
#define CONFIG_KGDB_SER_INDEX1/* which serial port to use */
#endif
【6】为u-boot增加命令自动补全和历史记录功能
此功能如同shell里面自动补全和历史记录功能,用起来非常方便。
打开/include/configs/mini2440.h,定位到109附近,加入宏定义:
#define CONFIG_CMD_ASKENV
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DATE
#define CONFIG_CMD_ELF
#define CONFIG_AUTO_COMPLETE /*command auto complete*/
#define CONFIG_CMDLINE_EDITING /*command history record*/
#define CONFIG_CMD_NAND
#define CONFIG_CMD_JFFS2 /* JFFS2 Support*/
#define CONFIG_CMD_PING /*ping command support*/
4.2,重新编译u-boot,下载到Nand中从Nand启动,查看启动信息和环境变量并使用ping命令测试网卡,操作如下:
Enter your selection: a
USB host is connected. Waiting a download.