u-boot-2009.08在mini2440上的移植(四)---增加DM9000驅(qū)動
移植環(huán)境
1,主機環(huán)境:VMare下CentOS 5.5 ,1G內(nèi)存。
2,集成開發(fā)環(huán)境:Elipse IDE
3,編譯編譯環(huán)境:arm-linux-gcc v4.4.3,arm-none-eabi-gcc v4.5.1。
4,開發(fā)板:mini2440,2M nor flash,128M nand flash。
5,u-boot版本:u-boot-2009.08
6,參考文章:
http://blogold.chinaunix.net/u3/101649/showart.php?id=2105215
http://blog.chinaunix.net/space.php?uid=23787856&do=blog&id=115382
http://blogimg.chinaunix.net/blog/upfile2/100811115954.pdf
u-boot-2009.08版本已經(jīng)對CS8900、RTL8019和DM9000X等網(wǎng)卡有比較完善的代碼支持(代碼在drivers/net/目錄下),而且在S3C24XX系列中默認(rèn)對CS8900網(wǎng)卡進行配置使用。而mini2440開發(fā)板使用的則是DM9000網(wǎng)卡芯片,所以只需在開發(fā)板上添加對DM9000的支持即可。還有一點,以前的 U-boot 對于網(wǎng)絡(luò)延時部分有問題,需要修改許多地方。但是現(xiàn)在的U-boot 網(wǎng)絡(luò)
部分已經(jīng)基本不需要怎么修改了,只有在DM9000 的驅(qū)動和NFS 的TIMEOUT 參數(shù)上需要稍微修改一下。
4.1,DM9000驅(qū)動代碼修改
【1】修改static int dm9000_init函數(shù)中部分代碼,如果不修改這一部分,在使用網(wǎng)卡的時候會報“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,增加了延時,否則會出現(xiàn)“*** 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】添加網(wǎng)卡芯片(DM9000)的初始化函數(shù)
打開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 傳輸協(xié)議(可不修改)
對于使用串口傳輸數(shù)據(jù)到內(nèi)存的操作,有可能會用到Xmodem協(xié)議。但是原本的kermit協(xié)議傳輸就挺好用的,速度也比較快,所以可添加此功能。
打開/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中加入相關(guān)定義
打開/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 //網(wǎng)卡片選地址
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE+4) //網(wǎng)卡數(shù)據(jù)地址
#define CONFIG_DM9000_NO_SROM1
//#define CONFIG_DM9000_USE_16BIT
#undef CONFIG_DM9000_DEBUG
注意:
u-boot-2009.08 可以自動檢測DM9000網(wǎng)卡的位數(shù),根據(jù)開發(fā)板原理圖可知網(wǎng)卡的數(shù)據(jù)位為16位,并且網(wǎng)卡位
于CPU的BANK4上,所以只需在 board/samsung/mini2440/lowlevel_init.S中設(shè)置 #define B4_BWSCON (DW16) 即
可,不需要此處的 #define CONFIG_DM9000_USE_16BIT 1
給u-boot加上ping命令,用來測試網(wǎng)絡(luò)通不通
/*
* 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*/
恢復(fù)被注釋掉的網(wǎng)卡MAC地址和修改你合適的開發(fā)板IP地址以及內(nèi)核啟動參數(shù):
#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行附近,加入使能串口傳輸數(shù)據(jù)到內(nèi)存的操作:
#define ENABLE_CMD_LOADB_X1 //使能串口傳輸數(shù)據(jù)到內(nèi)存的操作
#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啟動,查看啟動信息和環(huán)境變量并使用ping命令測試網(wǎng)卡,操作如下:
Enter your selection: a
USB host is connected. Waiting a download.