l 移植u-boot之修改代码支持DM9000网卡-3.5

时间:2021-10-01 02:23:37
修改UBOOT支持DM9000网卡

1.在源码里,搜索是否支持DM9000

book@book-desktop:/work/system/u-boot-2012.04.01$ ls drivers/net/dm9000* -l
-rw-r--r-- 1 book book 17149 2012-04-25 21:22 drivers/net/dm9000x.c
-rw-r--r-- 1 book book  3538 2012-04-25 21:22 drivers/net/dm9000x.h

2.找到该目录下的Makefile,看看如果将dm9000x.c编译进内核,需要配置什么宏?

所以在配置文件里面,必须定义这个宏: CONFIG_DRIVER_DM9000 , 除掉cs8900
COBJS-$(CONFIG_BFIN_MAC) += bfin_mac.o
COBJS-$(CONFIG_CALXEDA_XGMAC) += calxedaxgmac.o
COBJS-$(CONFIG_CS8900) += cs8900.o
COBJS-$(CONFIG_TULIP) += dc2114x.o
COBJS-$(CONFIG_DESIGNWARE_ETH) += designware.o
COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.o
COBJS-$(CONFIG_DNET) += dnet.o
COBJS-$(CONFIG_E1000) += e1000.o


3.修改代码

     需要修改两部分:
        A. 设置内存控制器
        B. 确定访问地址 
l 移植u-boot之修改代码支持DM9000网卡-3.5

DM9000是内存类设备,对于访问这类设备,需要知道:
(1)位宽
(2)访问地址


3.1 设置访问地址

l 移植u-boot之修改代码支持DM9000网卡-3.5l 移植u-boot之修改代码支持DM9000网卡-3.5


这里:
        (1)片选引脚nGCS4接到了DM9000,从手册知道访问地址0x20000000-0x28000000时,将会使能片选信号nGCS4;
        (2)2440地址线LADDR2接到了DM9000的CMD引脚,进行控制访问;

配置文件需要修改: include/configs/smdk2440.h
#if 0
#define CONFIG_CS8900        /* we have a CS8900 on-board */
#define CONFIG_CS8900_BASE    0x19000300
#define CONFIG_CS8900_BUS16    /* the Linux driver does accesses as shorts */
#else
// 这里增加对DM9000的定义
#define CONFIG_DRIVER_DM9000            
#define CONFIG_DM9000_BASE  0x20000000    // 定义基地址 0x20000000
#define DM9000_IO           CONFIG_DM9000_BASE
#define DM9000_DATA         (CONFIG_DM9000_BASE + 4)   // LADDR2相当于bit2引脚 bit2 = 4;
#endif



3.2 设置内存控制器

在u-boot代码第一阶段的时候,实现了SDRAM的初始化,在lowlevel_init.S中实现:
SMRDATA:
    .long 0x22011110     //BWSCON          设置位宽
    .long 0x00000700     //BANKCON0
    .long 0x00000700     //BANKCON1
    .long 0x00000700     //BANKCON2
    .long 0x00000700     //BANKCON3  
    
    //.long 0x00000700     //BANKCON4 修改为下面的代码:
    .long 0x00000740     //BANKCON4        设置控制时序
    
    .long 0x00000700     //BANKCON5
    .long 0x00018005     //BANKCON6
    .long 0x00018005     //BANKCON7
    .long 0x008C04F4     // REFRESH
    .long 0x000000B1     //BANKSIZE
    .long 0x00000030     //MRSRB6
    .long 0x00000030     //MRSRB7

查找2440手册:
l 移植u-boot之修改代码支持DM9000网卡-3.5

1. 设置位宽:
bit[17:16] = 01,设置为16-bit位宽

l 移植u-boot之修改代码支持DM9000网卡-3.5

2. 设置时序
    一般设置默认的就可以了。
    这里设置 bit[7:6] = 01, 设置:.long 0x00000740     //BANKCON4     

l 移植u-boot之修改代码支持DM9000网卡-3.5


修改到这里,发现编译,烧写进板子,还是发现DM9000不成功。
为什么呢,跟踪源代码中网卡初始化流程:
    eth_initialize
        board_eth_init
            cs8900_initialize

3.3 增加对DM9000的初始化

这里发现在文件中:\board\samsung\smdk2440\Smdk2410.c 并没有对进行DM9000初始化操作
#ifdef CONFIG_CMD_NET
int board_eth_init(bd_t *bis)
{
    int rc = 0;
#ifdef CONFIG_CS8900
    rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
#endif

// 这里增加对DM9000的初始化
#ifdef CONFIG_DRIVER_DM9000
    rc = dm9000_initialize(bis);
#endif

    return rc;
}
#endif

重新编译,烧写进板子,发现DM9000成功移植。
启动板子打印信息如下:
U-Boot 2012.04.01 (Dec 06 2016 - 09:11:18)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: flash_size: 0kb                // 从NAND启动,检测不到NOR的大小,因为从NAND启动,
                                              // cpu看到的0地址对应的是内部的SRAM,看不到NOR,所以打印为0.
NAND:  256 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
SMDK2410 # 


4. 测试

4.1 ping通linux虚拟机

打印默认参数

SMDK2410 # print
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

4.2 测试是否能ping通

首先设置板子的IP地址:set ipaddr 192.168.1.50
虚拟机的IP地址:  192.168.1.19

SMDK2410 # set ipaddr 192.168.1.50
SMDK2410 # ping 192.168.1.19      
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:00:00:00:00:00
could not establish link
*** ERROR: `ethaddr' not set
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:00:00:00:00:00
could not establish link
ping failed; host 192.168.1.19 is not alive

错误提示:表示没有设置ethaddr。
重启开发板:
    重新设置ipaddr,ethaddr。

        set ipaddr 192.168.1.50
        set ethaddr 00:0c:29:2f:4e:70
SMDK2410 # set ipaddr 192.168.1.50
SMDK2410 # set ethaddr 00:0c:29:2f:4e:70
SMDK2410 # ping 192.168.1.19
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
host 192.168.1.19 is alive
SMDK2410 # 

表示能够ping通了。

4.3 利用网络命令进行传输文件

2.1 在windows下打开tftp,windows的IP地址为:192.168.1.100
l 移植u-boot之修改代码支持DM9000网卡-3.5

2.2 传输文件到板子,输入命令,将uImage文件下载到内存0x30000000处。
tftp 30000000 uImage

注意:这之前要设置服务器IP(也就是传输文件过来的服务器的IP地址
set serverip 192.168.1.100
SMDK2410 # tftp 30000000 uImage
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 10.0.0.1; our IP address is 192.168.1.50
Filename 'uImage'.
Load address: 0x30000000
Loading: ## Warning: gatewayip needed but not set
T ## Warning: gatewayip needed but not set
## Warning: gatewayip needed but not set
T ## Warning: gatewayip needed but not set
T ## Warning: gatewayip needed but not set
## Warning: gatewayip needed but not set
T ## Warning: gatewayip needed but not set

Abort
SMDK2410 # set serverip  192.168.1.100


然后启动内核:
SMDK2410 # tftp 30000000 uImage      
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.17
Filename 'uImage'.
Load address: 0x30000000
Loading: #################################################################
         #############################################################
done
Bytes transferred = 1848720 (1c3590 hex)
SMDK2410 # bootm 30000000
## Booting kernel from Legacy Image at 30000000 ...
   Image Name:   Linux-2.6.22.6
   Created:      2016-07-11   9:28:04 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1848656 Bytes = 1.8 MiB
   Load Address: 30008000
   Entry Point:  30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux...................................................................................................................... done, booting the kernel.
Linux version 2.6.22.6 (book@book-desktop) (gcc version 3.4.5) #1 Mon Jul 11 17:27:56 CST 2016
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on