首先找到dm9000目录下的makefile,可以看到一般有两种网卡,cs8900和dm9000,我们用的是dm9000,所以先对头文件进行设置
#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
#define CONFIG_DRIVER_DM9000
#endif
然后重新编译,可以看到如下错误:
dm9000x.c: In function 'dm9000_outblk_8bit':
dm9000x.c:156: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c:156: error: (Each undeclared identifier is reported only once
dm9000x.c:156: error: for each function it appears in.)
dm9000x.c: In function 'dm9000_outblk_16bit':
dm9000x.c:165: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_outblk_32bit':
dm9000x.c:173: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_inblk_8bit':
dm9000x.c:180: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_inblk_16bit':
dm9000x.c:189: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_inblk_32bit':
dm9000x.c:197: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_rx_status_32bit':
dm9000x.c:204: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c:206: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_rx_status_16bit':
dm9000x.c:213: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c:215: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_rx_status_8bit':
dm9000x.c:221: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c:224: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_probe':
dm9000x.c:243: error: 'CONFIG_DM9000_BASE' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_send':
dm9000x.c:420: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c: In function 'dm9000_rx':
dm9000x.c:484: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'DM9000_ior':
dm9000x.c:574: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c:575: error: 'DM9000_DATA' undeclared (first use in this function)
dm9000x.c: In function 'DM9000_iow':
dm9000x.c:584: error: 'DM9000_IO' undeclared (first use in this function)
dm9000x.c:585: error: 'DM9000_DATA' undeclared (first use in this function)
/home/book/Par_Uboot/mk_uboot/u-boot-2012.04.01/config.mk:312: recipe for target 'dm9000x.o' failed
make[1]: *** [dm9000x.o] Error 1
make[1]: Leaving directory '/home/book/Par_Uboot/mk_uboot/u-boot-2012.04.01/drivers/net'
Makefile:485: recipe for target 'drivers/net/libnet.o' failed
在所有文件张搜索DM9000_DATA,可以看到使用dm9000时还得定义一些其他的东西,先复制过来
#define CONFIG_DRIVER_DM9000
#define CONFIG_DM9000_NO_SROM
#define CONFIG_DM9000_BASE 0x20100000
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE + 2)
这里的基地址是根据不同的开发板的内存分布会有不同的值,所以分析2440的内存分布来确定上面宏定义的值:
dm9000是有nGCS4来选取的,所以当内存控制器发出的地址在0x20000000 和 0x28000000之间就会选中DM9000,这时候的基地址是0x20000000,然后根据cmd引脚确定data的地址
#define CONFIG_DRIVER_DM9000
#define CONFIG_DM9000_NO_SROM
#define CONFIG_DM9000_BASE 0x20000000
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (CONFIG_DM9000_BASE + 4)
然后查看原来的内存设置,确定是否需要修改
SMRDATA:
.long 0x22011110 //BWSCON
.long 0x00000700 //BANKCON0
.long 0x00000700 //BANKCON1
.long 0x00000700 //BANKCON2
.long 0x00000700 //BANKCON3
.long 0x00000740 //BANKCON4
.long 0x00000700 //BANKCON5
.long 0x00018005 //BANKCON6
.long 0x00018005 //BANKCON7
.long 0x008C04F4 // REFRESH
.long 0x000000B1 //BANKSIZE
.long 0x00000030 //MRSRB6
.long 0x00000030 //MRSRB7
改完内存重启后仍然发现无法找到网卡:
然后看网卡原来的初始化函数,以确定问题,下面是原来的网卡初始化流程:
eth_initialize(gd->bd); //board.c
rc = cs8900_initialize(0, CONFIG_CS8900_BASE); //smdk2410.c
从这里可以看到原来的初始化函数是初始化cs8900的,所以现在需要改成dm9000,uboot下搜索的目录dm9000的初始化函数,借鉴别的单板是怎么设置dm9000的
book@www.100ask.org:~/Par_Uboot/mk_uboot/u-boot-2012.04.01$ grep "dm9000_initialize" * -nR
board/atmel/at91sam9261ek/at91sam9261ek.c:277: return dm9000_initialize(bis);
board/altera/nios2-generic/nios2-generic.c:79: rc += dm9000_initialize(bis);
board/scb9328/scb9328.c:66: return dm9000_initialize(bis);
board/ronetix/pm9261/pm9261.c:280: return dm9000_initialize(bis);
从而去修改2440的网卡初始化
int board_eth_init(bd_t *bis)
{
int rc = 0;
#ifdef CONFIG_CS8900
rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
#endif
#ifdef CONFIG_DRIVER_DM9000
rc = dm9000_initialize(bis);
#endif
return rc;
}
烧写运行
U-Boot 2012.04.01 (Sep 24 2019 - 15:31:45)
CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: fwc addr (null) 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 (null) cmd f0 00f0 16bit x 16 bit
JEDEC PROBE: ID c2 2249 0
2 MiB
NAND: 256 MiB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: dm9000
设置ip。测试网卡功能
set ipaddr 192.168.2.5 设置单板ip
set serverip 192.168.2.2 设置服务器ip
set ethaddr 00:0c:29:6c:b9:36 设置网卡mac
tftp 30000000 uImage_3.5 下载内核进行测试
更改的文件:
smdk2440/smdk2410.c
lowlevel_init.S
smdk2440.h