Linux开发环境在pxa270平台上的搭建(1)——u-boot移植

时间:2022-05-11 17:27:14

最近接手一个基于pxa270平台的pda项目,开发相关驱动,由于种种原因,接手的时候两最基本的开发环境都没有,所以本人虽为菜鸟,也只好硬着头皮把环境一步一步搭好,幸好经过一个月的拼搏,终于基本完毕,现将大致过程记录如下,以作备用,如有不对之处,望请各位大神指正!


一.基本开发环境的搭建

接手项目的时候,就给我一块开发板,一台电脑,电脑别说linux了,连xp都没给装,当然我所在是个很小的公司,肯定是用不了常用的linux服务器+xp客户端的开发模式,只有采用vmware + ubuntu的开发模式。坑爹的是连个xp都不给我装,也太狠了,非得让我从零开始。

1.装好xp。相信来这个网站的是个正常人都会。

2.装vmware,装好vmware后再装ubuntu,我用的是ubuntu10.10。这个弄好的话,大概一上午就过去了。

3.下午开始配置ubuntu,大概的配置也就这几个:

(1).tftp服务,用于后面的下载bootloader,内核镜像。

(2).nfs服务,这个到建立网络文件系统的时候就必须得用了。

(3),samba服务,用于xp和ubuntu之间的文件传输,及其方便,我一般将其映射为网络驱动器。

上面这些服务和系统安装,在百度和google一搜一大把的文章,这里就不再详细记录了。


二.u-boot-1.3.0移植

硬件平台:优龙yle270开发板

mcu:intel pxa270

sdram:samsung  k4s561632c * 2  2片16位数据位宽的sdram组合成64M的SDRAM

flash:intel  E28f128j3 * 2 2片intel 16位数据位宽norflash组合成32M norflash

eth:dm9000


软件:u-boot-1.3.0源码包

    交叉工具链版本为:3.3.2


优龙也提供一套bootloader,是在ads环境下开发的,比较臃肿,而且不方便用于调试内核,遂决定一直一个比较熟悉的bootloader,不过有优龙的源码提供支持,虽然以前没接触过intel pxa270芯片,但是移植过程也并不复杂,但在bootloader对dm9000的支持上倒是花了不少时间。下面简述移植过程以及遇到的问题和解决的方法,有不当之处希望各位大神指出,小弟一定改正。

1.由于时间比较久了,具体的移植细节记得不大清楚,不过可以参考网上这篇帖子,写得比较详细,我这里主要记述遇到的问题以及解决的方法。

具体移植步骤:http://pine721.blog.163.com/blog/static/1774710220080301491617/


2.移植过程中遇到的问题


(1),串口无输出,这个问题可能是每个移植u-boot的菜鸟遇到的一个棘手的问题,不过解决了这个问题就相当与解决u-boot移植的一半,也会给菜鸟以信心,进行下面的工作。

其实这个问题,主要有两方面的原因造成:一是:没有正确的初始化sdram。二是:没有正确的配置gpio口。修改这两个配置需要根据硬件的相关参数来修改,当然我手头有优龙的源码就方便多了,利用linux的强大的搜索命令grep,基本就把对应的参数搞定,不用看那恼人的datasheet了,不过要是没有源码的支持,仔细查看datasheet,顺着这两条思路,解决问题应该也只是时间问题。


下面列出我的参数清单:

修改文件为:include/configs/yle270.h,其中yle270.h由xsbase270.h复制得到

/*gpio 的配置*/
#define CFG_GPSR0_VAL 0x00008408//0x00018004
#define CFG_GPSR1_VAL 0x004FAB82//0x004F0080
#define CFG_GPSR2_VAL 0x0021C000//0x13EFC000
#define CFG_GPSR3_VAL 0x00020000//0x0006E032


#define CFG_GPCR0_VAL 0x00010810//0x084AFE1A
#define CFG_GPCR1_VAL 0x00000000//0x003003F2
#define CFG_GPCR2_VAL 0x00000000//0x0C014000
#define CFG_GPCR3_VAL 0x00000000//0x00000C00


#define CFG_GPDR0_VAL 0xC0A18DFC//0xCBC3BFFC
#define CFG_GPDR1_VAL 0xFCDFAB83//0x00FFABF3
#define CFG_GPDR2_VAL 0x02E1FFFF//0x1EEFFC00
#define CFG_GPDR3_VAL 0x00021B81//0x0187EC32


#define CFG_GAFR0_L_VAL 0x82000000//0x84400000
#define CFG_GAFR0_U_VAL 0xA5E54018//0xA51A8010


#define CFG_GAFR1_L_VAL 0x999A955A//0x699A955A
#define CFG_GAFR1_U_VAL 0xAAA5A0AA//0x0005A0AA


#define CFG_GAFR2_L_VAL 0xAAAAAAAA//0x40000000
#define CFG_GAFR2_U_VAL 0x55F0A402//0x0109A400


#define CFG_GAFR3_L_VAL 0x540A950C//0x54000000
#define CFG_GAFR3_U_VAL 0x00001591//0x00001409

注释之前的值是从优龙的源码中搜索得到,后面的值为u-boot原始值,经过上述修改之后,将得到的u-boot.bin利用优龙提供的bootloader下载到   sdram运行,(需要打开#define CONFIG_SKIP_LOWLEVEL_INIT 1 这个宏,避免重新初始化gpio和sdram)串口能正确输出,正高兴的把它烧到flash里面,却一点反应也没有,郁闷归郁闷,仔细思考,觉得是应为利用优龙的bootloader下载到sdram的话,此时gpio和sdram已经被正确初始化,所以窗口有输出,如果把#define CONFIG_SKIP_LOWLEVEL_INIT 1打开,让u-boot再重新初始化一遍gpio和sdram,即使你下载到sdram,肯定也是运行不了的,原因已经明了,动手开始干。


 再添加初始化sdram的值:

 /*内存控制寄存器的设置*/
/*现代sdram*/

同样是修改include/configs/yle270.h


#define CFG_MSC0_VAL  0x23F2B8F2  /* 0x48000008 */
#define CFG_MSC1_VAL  0x0000CCD1  /* 0x4800000C */
#define CFG_MSC2_VAL  0x0000B884  /* 0x48000010 */这个值关系到我们的网卡
#define CFG_MDCNFG_VAL  0x00000AC8  /* 0x48000000 */
#define CFG_MDREFR_VAL  0x0000001E  /* 0x48000004 */
#define CFG_MDMRS_VAL  0x00000000  /* 0x48000040 */


#define CFG_FLYCNFG_VAL  0x00010001  
#define CFG_SXCNFG_VAL  0x40044004  /* 0x4800001C */

将这些值改完后,重新编译,烧到flash当中,该死的串口终于可以正确的输出了,心情是相当的好。


(2)、无法保存环境变量到flash当中

不好意思没有将错误信息记录下来,不过大概意思是“不正确的边界”,当时把把错误信息放到google上搜索,基本上就确定了原因,其实也可以查看源代码,是因为norflash 需要一整个一整个扇区的擦除才行,我在配置中给的扇区大小不对,导致无法写入flash。一片E28f128j3的大小为     128K,两片组合后应该为256K,将配置改正之后的值为:

       #define CFG_ENV_SIZE        0x20000 /* Total Size of Environment        */
      #define CFG_ENV_SECT_SIZE   0x40000 /* Total Size of Environment Sector */此处原为0x20000

   此处修改完毕之后,重新编译,烧到flash当中,已能正确写入flash,这个问题解决还比较顺利,下面的问题可是耗费我大把的时间。

    (3)、网卡DM9000无法传输数据

   将网卡驱动编译到u-boot里面去以后,将u-boot.bin下载到sdram中,发现网卡还不能正确接收数据,其间各种错误,记不清了,使劲的问google,有人给出答案,    u-boot的dm9000驱动有问题,抱着试一试的心态,将其替换,还真的可以了,实在是太感谢google和那些前辈大牛了!现在将代买贴出:

#include <common.h>
#include <command.h>
#include <net.h>
#include <asm/io.h>

#ifdef CONFIG_DRIVER_DM9000

#include "dm9000x.h"

/* Board/System/Debug information/definition ---------------- */

#define DM9801_NOISE_FLOOR 0x08
#define DM9802_NOISE_FLOOR 0x05

/* #define CONFIG_DM9000_DEBUG */

#ifdef CONFIG_DM9000_DEBUG
#define DM9000_DBG(fmt,args...) printf(fmt ,##args)
#else /* */
#define DM9000_DBG(fmt,args...)
#endif /* */
enum DM9000_PHY_mode { DM9000_10MHD = 0, DM9000_100MHD =
1, DM9000_10MFD = 4, DM9000_100MFD = 5, DM9000_AUTO =
8, DM9000_1M_HPNA = 0x10
};
enum DM9000_NIC_TYPE { FASTETHER_NIC = 0, HOMERUN_NIC = 1, LONGRUN_NIC = 2
};

/* Structure/enum declaration ------------------------------- */
typedef struct board_info {
u32 runt_length_counter; /* counter: RX length < 64byte */
u32 long_length_counter; /* counter: RX length > 1514byte */
u32 reset_counter; /* counter: RESET */
u32 reset_tx_timeout; /* RESET caused by TX Timeout */
u32 reset_rx_status; /* RESET caused by RX Statsus wrong */
u16 tx_pkt_cnt;
u16 queue_start_addr;
u16 dbug_cnt;
u8 phy_addr;
u8 device_wait_reset; /* device state */
u8 nic_type; /* NIC type */
unsigned char srom[128];
} board_info_t;
board_info_t dmfe_info;

/* For module input parameter */
//static int media_mode = DM9000_AUTO; /* weiyan,use full duplex mode */
static int media_mode = DM9000_100MFD;
static u8 nfloor = 0;

/* function declaration ------------------------------------- */
int eth_init(bd_t * bd);
int eth_send(volatile void *, int);
int eth_rx(void);
void eth_halt(void);
void eth_halt_true(void);
static int dm9000_probe(void);
static u16 phy_read(int);
static void phy_write(int, u16);
u16 read_srom_word(int);
static u8 DM9000_ior(int);
static void DM9000_iow(int reg, u8 value);

/* DM9000 network board routine ---------------------------- */

#define DM9000_outb(d,r) ( *(volatile u8 *)r = d )
#define DM9000_outw(d,r) ( *(volatile u16 *)r = d )
#define DM9000_outl(d,r) ( *(volatile u32 *)r = d )
#define DM9000_inb(r) (*(volatile u8 *)r)
#define DM9000_inw(r) (*(volatile u16 *)r)
#define DM9000_inl(r) (*(volatile u32 *)r)

#ifdef CONFIG_DM9000_DEBUG
static void
dump_regs(void)
{
DM9000_DBG("\n");
DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0));
DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1));
DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2));
DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3));
DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5));
DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6));
// DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(ISR));
DM9000_DBG("\n");
}
#endif /* */

/*
Search DM9000 board, allocate space and register it
*/
int
dm9000_probe(void)
{
u32 id_val;
id_val = DM9000_ior(DM9000_VIDL);
id_val |= DM9000_ior(DM9000_VIDH) << 8;
id_val |= DM9000_ior(DM9000_PIDL) << 16;
id_val |= DM9000_ior(DM9000_PIDH) << 24;
if (id_val == DM9000_ID) {
printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
id_val);
return 0;
} else {
printf("dm9000 not found at 0x%08x id: 0x%08x\n",
CONFIG_DM9000_BASE, id_val);
return -1;
}
}

/* Set PHY operationg mode
*/
static void
set_PHY_mode(void)
{
u16 phy_reg4 = 0x01e1, phy_reg0 = 0x1000;
if (!(media_mode & DM9000_AUTO)) {
switch (media_mode) {
case DM9000_10MHD:
phy_reg4 = 0x21;
phy_reg0 = 0x0000;
break;
case DM9000_10MFD:
phy_reg4 = 0x41;
phy_reg0 = 0x1100;
break;
case DM9000_100MHD:
phy_reg4 = 0x81;
phy_reg0 = 0x2000;
break;
case DM9000_100MFD:
phy_reg4 = 0x101;
phy_reg0 = 0x3100;
break;
}
phy_write(4, phy_reg4); /* Set PHY media mode */
phy_write(0, phy_reg0); /* Tmp */
}
DM9000_iow(DM9000_GPCR, 0x01); /* Let GPIO0 output */
DM9000_iow(DM9000_GPR, 0x00); /* Enable PHY */
}

/*
Init HomeRun DM9801
*/
static void
program_dm9801(u16 HPNA_rev)
{
__u16 reg16, reg17, reg24, reg25;
if (!nfloor)
nfloor = DM9801_NOISE_FLOOR;
reg16 = phy_read(16);
reg17 = phy_read(17);
reg24 = phy_read(24);
reg25 = phy_read(25);
switch (HPNA_rev) {
case 0xb900: /* DM9801 E3 */
reg16 |= 0x1000;
reg25 = ((reg24 + nfloor) & 0x00ff) | 0xf000;
break;
case 0xb901: /* DM9801 E4 */
reg25 = ((reg24 + nfloor) & 0x00ff) | 0xc200;
reg17 = (reg17 & 0xfff0) + nfloor + 3;
break;
case 0xb902: /* DM9801 E5 */
case 0xb903: /* DM9801 E6 */
default:
reg16 |= 0x1000;
reg25 = ((reg24 + nfloor - 3) & 0x00ff) | 0xc200;
reg17 = (reg17 & 0xfff0) + nfloor;
}
phy_write(16, reg16);
phy_write(17, reg17);
phy_write(25, reg25);
}

/*
Init LongRun DM9802
*/
static void
program_dm9802(void)
{
__u16 reg25;
if (!nfloor)
nfloor = DM9802_NOISE_FLOOR;
reg25 = phy_read(25);
reg25 = (reg25 & 0xff00) + nfloor;
phy_write(25, reg25);
}

/* Identify NIC type
*/
static void
identify_nic(void)
{
struct board_info *db = &dmfe_info; /* Point a board information structure */
u16 phy_reg3;
DM9000_iow(DM9000_NCR, NCR_EXT_PHY);
phy_reg3 = phy_read(3);
switch (phy_reg3 & 0xfff0) {
case 0xb900:
if (phy_read(31) == 0x4404) {
db->nic_type = HOMERUN_NIC;
program_dm9801(phy_reg3);
DM9000_DBG("found homerun NIC\n");
} else {
db->nic_type = LONGRUN_NIC;
DM9000_DBG("found longrun NIC\n");
program_dm9802();
}
break;
default:
db->nic_type = FASTETHER_NIC;
break;
}
DM9000_iow(DM9000_NCR, 0);
}

/* General Purpose dm9000 reset routine */
static void
dm9000_reset(void)
{
DM9000_DBG("resetting\n");
// DM9000_iow(DM9000_NCR, NCR_RST);
// udelay(500);
DM9000_iow(DM9000_NCR, NCR_RST);
udelay(1000);
}

/* Initilize dm9000 board
*/
int
eth_init(bd_t * bd)
{
eth_init_true(bd);
}

int eth_init_true(bd_t * bd)
{
int i, oft, lnk;

DM9000_DBG("eth_init()\n");

// eth_halt_true();
/* RESET device */
dm9000_reset();
dm9000_probe();

/* NIC Type: FASTETHER, HOMERUN, LONGRUN */
// identify_nic();

/* GPIO0 on pre-activate PHY */
DM9000_iow(DM9000_GPR, 0x00); /*REG_1F bit0 activate phyxcer */

/* copy from set_PHY_mode, do not set phy mode */
DM9000_iow(DM9000_GPCR, 0x01); /* Let GPIO0 output */
DM9000_iow(DM9000_GPR, 0x00); /* Enable PHY */
/* Set PHY */
// set_PHY_mode();

/* Program operating register */
// DM9000_iow(DM9000_NCR, 0x0); /* only intern phy supported by now */
/* cut from Linux, weiyan */

DM9000_iow(DM9000_TCR, 0); /* TX Polling clear */
DM9000_iow(DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */
DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); /* Flow Control : High/Low Water */
DM9000_iow(DM9000_FCR, 0x0); /* SH FIXME: This looks strange! Flow Control */
DM9000_iow(DM9000_SMCR, 0); /* Special Mode */
DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); /* clear TX status */
DM9000_iow(DM9000_ISR, 0x0f); /* Clear interrupt status */

/* Set Node address */
// for (i = 0; i < 6; i++)
// ((u16 *) bd->bi_enetaddr)[i] = read_srom_word(i);

if (is_zero_ether_addr(bd->bi_enetaddr) ||
is_multicast_ether_addr(bd->bi_enetaddr)) {
/* try reading from environment */
u8 i;
char *s, *e;
s = getenv ("ethaddr");
for (i = 0; i < 6; ++i) {
bd->bi_enetaddr[i] = s ?
simple_strtoul (s, &e, 16) : 0;
if (s)
s = (*e) ? e + 1 : e;
}
}

printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", bd->bi_enetaddr[0],
bd->bi_enetaddr[1], bd->bi_enetaddr[2], bd->bi_enetaddr[3],
bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
for (i = 0, oft = 0x10; i < 6; i++, oft++)
DM9000_iow(oft, bd->bi_enetaddr[i]);
for (i = 0, oft = 0x16; i < 8; i++, oft++)
DM9000_iow(oft, 0xff);

/* read back mac, just to be sure */
for (i = 0, oft = 0x10; i < 6; i++, oft++)
DM9000_DBG("%02x:", DM9000_ior(oft));
DM9000_DBG("\n");

/* Activate DM9000 */
DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); /* RX enable */
DM9000_iow(DM9000_IMR, IMR_PAR); /* Enable TX/RX interrupt mask */
#if 0 //weibing
i = 0;
while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
udelay(1000);
i++;
if (i == 10000) {
printf("could not establish link\n");
return 0;
}
}
#endif
#if 0
/* 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
printf("operating at 100M full duplex mode\n");
return 0;
}

/*
Hardware start transmission.
Send a packet to media from the upper layer.
*/
int
eth_send(volatile void *packet, int length)
{
char *data_ptr;
u32 tmplen, i;
int tmo;
DM9000_DBG("eth_send: length: %d\n", length);
for (i = 0; i < length; i++) {
if (i % 8 == 0)
DM9000_DBG("\nSend: 02x: ", i);
DM9000_DBG("%02x ", ((unsigned char *) packet)[i]);
} DM9000_DBG("\n");

/* Move data to DM9000 TX RAM */
data_ptr = (char *) packet;
DM9000_outb(DM9000_MWCMD, DM9000_IO);

#ifdef CONFIG_DM9000_USE_8BIT
/* Byte mode */
for (i = 0; i < length; i++)
DM9000_outb((data_ptr[i] & 0xff), DM9000_DATA);

#endif /* */
#ifdef CONFIG_DM9000_USE_16BIT
tmplen = (length + 1) / 2;
for (i = 0; i < tmplen; i++)
DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);

#endif /* */
#ifdef CONFIG_DM9000_USE_32BIT
tmplen = (length + 3) / 4;
for (i = 0; i < tmplen; i++)
DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);

#endif /* */

/* Set TX length to DM9000 */
DM9000_iow(DM9000_TXPLL, length & 0xff);
DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);

/* Issue TX polling command */
DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */

/* wait for end of transmission */
tmo = get_timer(0) + 5 * CFG_HZ;
while (DM9000_ior(DM9000_TCR) & TCR_TXREQ) {
if (get_timer(0) >= tmo) {
printf("transmission timeout\n");
break;
}
}
DM9000_DBG("transmit done\n\n");
return 0;
}

/*
Stop the interface.
The interface is stopped when it is brought.
*/
void eth_halt(void){}

void
eth_halt_true(void)
{
#if 1 //weibing
DM9000_DBG("eth_halt\n");

/* 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
}

/*
Received a packet and pass to upper layer
*/
int
eth_rx(void)
{
u8 rxbyte, *rdptr = (u8 *) NetRxPackets[0];
u16 RxStatus, RxLen = 0;
u32 tmplen, i;
#ifdef CONFIG_DM9000_USE_32BIT
u32 tmpdata;
#endif

/* Check packet ready or not */
//weibing
DM9000_ior(DM9000_MRRH);
DM9000_ior(DM9000_MRRL); //must add this two read,weiyan
DM9000_ior(DM9000_MRCMDX); /* Dummy read */
rxbyte = DM9000_inb(DM9000_DATA); /* Got most updated data */

if (rxbyte == 0)
return 0;

/* Status check: this byte must be 0 or 1 */
if (rxbyte > 1) {
DM9000_iow(DM9000_RCR, 0x00); /* Stop Device */
DM9000_iow(DM9000_ISR, 0x80); /* Stop INT request */
DM9000_DBG("rx status check: %d\n", rxbyte);
return;
}
DM9000_DBG("receiving packet\n");

/* A packet ready now & Get status/length */
DM9000_outb(DM9000_MRCMD, DM9000_IO);

#ifdef CONFIG_DM9000_USE_8BIT
RxStatus = DM9000_inb(DM9000_DATA) + (DM9000_inb(DM9000_DATA) << 8);
RxLen = DM9000_inb(DM9000_DATA) + (DM9000_inb(DM9000_DATA) << 8);

#endif /* */
#ifdef CONFIG_DM9000_USE_16BIT
RxStatus = DM9000_inw(DM9000_DATA);
RxLen = DM9000_inw(DM9000_DATA);

#endif /* */
#ifdef CONFIG_DM9000_USE_32BIT
tmpdata = DM9000_inl(DM9000_DATA);
RxStatus = tmpdata;
RxLen = tmpdata >> 16;

#endif /* */
DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);

/* Move data from DM9000 */
/* Read received packet from RX SRAM */
#ifdef CONFIG_DM9000_USE_8BIT
for (i = 0; i < RxLen; i++)
rdptr[i] = DM9000_inb(DM9000_DATA);

#endif /* */
#ifdef CONFIG_DM9000_USE_16BIT
tmplen = (RxLen + 1) / 2;
for (i = 0; i < tmplen; i++)
((u16 *) rdptr)[i] = DM9000_inw(DM9000_DATA);
/* printf("length:%d\n", RxLen);
for (i = 0; i < RxLen+1; i++)
if(rdptr[i]>='0' && rdptr[i]<='9' || rdptr[i]>='a' && rdptr[i]<='f')
printf("i:%3d %c ",i, rdptr[i]);
printf("\n");
*/
#endif /* */
#ifdef CONFIG_DM9000_USE_32BIT
tmplen = (RxLen + 3) / 4;
for (i = 0; i < tmplen; i++)
((u32 *) rdptr)[i] = DM9000_inl(DM9000_DATA);

#endif /* */
if ((RxStatus & 0xbf00) || (RxLen < 0x40)
|| (RxLen > DM9000_PKT_MAX)) {
if (RxStatus & 0x100) {
printf("rx fifo error\n");
}
if (RxStatus & 0x200) {
printf("rx crc error\n");
}
if (RxStatus & 0x8000) {
printf("rx length error\n");
}
if (RxLen > DM9000_PKT_MAX) {
printf("rx length too big\n");
dm9000_reset();
}
} else {
/* Pass to upper layer */
DM9000_DBG("passing packet to upper layer\n");
NetReceive(NetRxPackets[0], RxLen);
return RxLen;
}
return 0;
}

/*
Read a word data from SROM
*/
u16
read_srom_word(int offset)
{
DM9000_iow(DM9000_EPAR, offset);
DM9000_iow(DM9000_EPCR, 0x4);
udelay(8000);
DM9000_iow(DM9000_EPCR, 0x0);
return (DM9000_ior(DM9000_EPDRL) + (DM9000_ior(DM9000_EPDRH) << 8));
}

void
write_srom_word(int offset, u16 val)
{
DM9000_iow(DM9000_EPAR, offset);
DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
DM9000_iow(DM9000_EPDRL, (val & 0xff));
DM9000_iow(DM9000_EPCR, 0x12);
udelay(8000);
DM9000_iow(DM9000_EPCR, 0);
}


/*
Read a byte from I/O port
*/
static u8
DM9000_ior(int reg)
{
DM9000_outb(reg, DM9000_IO);
return DM9000_inb(DM9000_DATA);
}

/*
Write a byte to I/O port
*/
static void
DM9000_iow(int reg, u8 value)
{
DM9000_outb(reg, DM9000_IO);
DM9000_outb(value, DM9000_DATA);
}

/*
Read a word from phyxcer
*/
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(100); /* Wait read complete */ //weiyan
udelay(1000); /* 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(%d): %d\n", reg, val);
return val;
}

/*
Write a word to phyxcer
*/
static void
phy_write(int reg, u16 value)
{
/* Fill the phyxcer register into REG_0C */
DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);

/* Fill the written data into REG_0D & REG_0E */
DM9000_iow(DM9000_EPDRL, (value & 0xff));
DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */
// udelay(500); /* Wait write complete */ //weiyan
udelay(1000); /* Wait write complete */
DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */
DM9000_DBG("phy_write(reg:%d, value:%d)\n", reg, value);
}
#endif /* CONFIG_DRIVER_DM9000 *

本以为就此结束,可是我高兴的太早了,将改好dm9000驱动的 u-boot编译烧到flash之后,发现竟然连网卡都初始化不了,当时死的心都有,我折腾这么久还是不能用,哎!不过叹气归叹气,问题还是要解决啊,想来想去,用优龙的bootloader下载到sdram里能用,到了flash里就是不行,那应该还是初始化的问题,思路对了,解决问题只是个时间问题,又用了一个下午的时间,发现:dm9000挂在ncs4上,应该正确的配置msc2的值为0xfff99139,但是上面的值却不是这一个,这是优龙后来在他自己的dm9000驱动改过来的,重新初始化了一遍msc2,和最开始的值不同。没办法,人家的代码,人家想怎么写就怎么写,想想还是u-boot的 代码规范一点,不过后续版本就不敢恭维了。

将上面的#define CFG_MSC2_VAL  红色部分的值改过来之后,u-boot基本正常了。至此,u-boot移植完毕。


  由于时间较久,很多细节都没有列出,希望大家原谅,这里只提供解决问题的大致思路,如果思路对了,相信解决问题只是时间问题。