U-boot-2014.04移植到MINI2440(6) DM9000网卡移植

时间:2021-04-20 19:30:48

MINI2440上有一个DM9000网卡,关于这部分的驱动其实是比较复杂的,但是u-boot对其支持比较好,我们在移植的时候只需要修改少量的代码。这部分的代码主要在u-boot/drivers/net/下以及mini2440.h。

 

一.修改mini2440.h

首先看drivers/net/Makefile,打开,第18行:

obj-$(CONFIG_DESIGNWARE_ETH) += designware.o

obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o

obj-$(CONFIG_DNET) += dnet.o

红色部分的意思是,如果我们定义了CONFIG_DRIVER_DM9000,那么就将其编译进内核,否则不编译进去。因为第一步,我们在mini2440.h里去掉了CS8900的定义,所以这时候切到mini2440.h,添加进去这一行:

#define CONFIG_DRIVER_DM9000

根据友善之臂提供的移植好的u-boot2010,打开include/configs/smdk2440a.h相当于我们这里的mini2440.h,关于dm9000的配置还有如下:

#define CONFIG_NET_MULTI         1

#define CONFIG_NET_RETRY_COUNT              20

#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_USE_16BIT         1

#define CONFIG_DM9000_NO_SROM         1

#undef CONFIG_DM9000_DEBUG

这里我们把红色部分都添加进去:

#define CONFIG_DM9000_BASE           0x20000300

#define DM9000_IO                    CONFIG_DM9000_BASE

#define DM9000_DATA                     (CONFIG_DM9000_BASE+4)

#define CONFIG_DM9000_NO_SROM         1

 

打开第一步关闭的#defineCONFIG_CMD_PING宏。

 

二.修改mini2440.c

进入board/mini2440/mini2440,打开mini2440.c文件。之所以要修改这个文件,是因为在编译的时候会报错,提示:

Net:No ethernet found.

同样,追踪错误,grep“Net:”* -nR,还是在/arch/arm/lib/board.c下面,打开查看,第662行:

       puts("Net:   ");

       eth_initialize(gd->bd);

追踪eth_initialize函数,在net/eth.c下面,第296行:

      if(board_eth_init != __def_eth_init) {

             if(board_eth_init(bis) < 0)

                    printf("BoardNet Initialization Failed\n");

      }else if (cpu_eth_init != __def_eth_init) {

             if(cpu_eth_init(bis) < 0)

                    printf("CPUNet Initialization Failed\n");

      }else

             printf("NetInitialization Skipped\n");

 

      if(!eth_devices) {

             puts("Noethernet found.\n");

             bootstage_error(BOOTSTAGE_ID_NET_ETH_START);

       追踪board_eth_init,在board/mini2440/mini2440/mini2440.c下,第118行:

#ifdef CONFIG_CMD_NET

int board_eth_init(bd_t *bis)

{

    intrc = 0;

#ifdef CONFIG_CS8900

    rc= cs8900_initialize(0, CONFIG_CS8900_BASE);

#endif

    returnrc;

}

#endif

       显然这里是rc传回去了cs8900_initlize的值,我们这里将其修改为DM9000的部分。

    #ifdefCONFIG_CMD_NET

int board_eth_init(bd_t *bis)

{

    intrc = 0;

#ifdef CONFIG_DRIVER_DM9000

    rc=dm9000_initialize(bis);

#endif

    returnrc;

}

#endif

 

.屏蔽could not establish link

       在drivers/net/dm9000x.c下,第376行:

              if (i == 10000) {

                     printf("could notestablish link\n");

                     return 0;

              }

将其注释掉,如下:

if 0 

i = 0;

       while(!(dm9000_phy_read(1) & 0x20)) {   /*autonegation complete bit */

              udelay(1000);

              i++;

              if(i == 10000) {

                     printf("couldnot establish link\n");

                     return0;

              }

       }

endif

 

编译下载,输出如下信息:

U-Boot 2014.04 (Aug 25 2015 - 09:16:10)

 

CPUID: 32440001

FCLK:      400MHz

HCLK:      100MHz

PCLK:       50MHz

DRAM:  64 MiB

WARNING: Caches not enabled

Flash: fwc addr 00000000 cmd f0 00f0 16bit x 16 bit

fwc addr 0000aaaa cmd aa 00aa 16bit x 16 bit

fwc addr 00005554 cmd 55 0055 16bit x 16 bit

fwc addr 0000aaaa cmd 90 0090 16bit x 16 bit

fwc addr 00000000 cmd f0 00f0 16bit x 16 bit

JEDEC PROBE: ID 1 2249 0

Found JEDEC Flash: AMD AM29LV160DB,migrated by Deep_l_zh

unlock address index 1

unlock addresses are 0x555/0x2aa

erase_region_count = 1 erase_region_size = 16384

erase_region_count = 2 erase_region_size = 8192

erase_region_count = 1 erase_region_size = 32768

erase_region_count = 31 erase_region_size = 65536

2 MiB

*** Warning - bad CRC, using default environment

 

In:    serial

Out:   serial

Err:   serial

Net:  dm9000

可以看到已经识别到了我们的网卡,printenv查看现在的环境变量:

MINI2440 Deep_l_zh # printenv

baudrate=115200

bootdelay=5

ethact=dm9000

ipaddr=10.0.0.110

netmask=255.255.255.0

serverip=10.0.0.1

stderr=serial

stdin=serial

stdout=serial

Environment size: 160/65532 bytes

 

下面设置环境变量,来ping通主机:

MINI2440 Deep_l_zh # setenv ethaddr 08:08:11:18:12:27

MINI2440 Deep_l_zh # setenv ipaddr 192.168.1.226

MINI2440 Deep_l_zh # setenv serverip 192.168.1.122

MINI2440 Deep_l_zh # setenv gatewayip 192.168.1.1

MINI2440 Deep_l_zh # printenv

baudrate=115200

bootdelay=5

ethact=dm9000

ethaddr=08:08:11:18:12:27

gatewayip=192.168.1.1

ipaddr=192.168.1.226

netmask=255.255.255.0

serverip=192.168.1.122

stderr=serial

stdin=serial

stdout=serial

 

Environment size: 220/65532 bytes

MINI2440 Deep_l_zh # ping192.168.1.122

dm9000 i/o: 0x20000300, id: 0x90000a46

DM9000: running in 16 bit mode

MAC: 08:08:11:18:12:27

operating at 100M full duplex mode

Using dm9000 device

host 192.168.1.122 is alive

      

       测试下载:

       MINI2440 Deep_l_zh # tftp 0x30008000 u-boot.bin

dm9000 i/o: 0x20000300, id: 0x90000a46

DM9000: running in 16 bit mode

MAC: 08:08:11:18:12:27

operating at 100M full duplexmode

Using dm9000 device

TFTP from server 192.168.1.122;our IP address is 192.168.1.226

Filename 'u-boot.bin'.

Load address: 0x30008000

Loading: T ##############

         36.1 KiB/s

done

Bytes transferred = 191528 (2ec28 hex)

       网卡移植完毕,不过这部分没有对dm9000的驱动代码做细致分析,这个留到以后写驱动帖子的时候分析,现在分析尽量和u-boot本身有关的部分。以上内容如有错误的地方还请指出,大家共同进步。