您的位置:首页 > 其它

U-Boot1.1.6移植DM9000网卡

2016-05-23 16:37 465 查看
[align=left]原文链接 http://www.100ask.org/bbs/forum.php?mod=viewthread&tid=3655&extra=&highlight=DM9000&page=1[/align]
根据书《嵌入式Linux应用开发完全手册》移植网卡驱动,对于Jz2440开发板好像并不适用,Jz2440开发板使用的是DM9000网卡,已经不是书上讲的CS8900网卡了。DM9000网卡与CS8900网卡接口方式不一样,经过几天的折腾,终于移植成功,现将笔记整理如下。

一、移植环境

1.u-boot版本1.1.6

2.开发板Jz2440(ARM9
S3C2440

NAND K9F2G08

SDRAM K4S561632 * 2

网卡 DM9000)

3.Linux: ubuntu 9.10

二、移植思路

查看u-boot-1.1.6源码发现,u-boot中已经包含dm9000的驱动文件dm9000x.c,所以我们只需要设置u-boot支持网卡就行。总体思路主要完成以下几件事情:

1.设置存储控制器,也就是设置S3C2440的BANK以使用DM9000;

2.配置u-boot使用DM9000网卡;

3.设置IP、serverIP等。

三、设置存储控制器

根据Jz2440开发板的原理图可知,DM9000网卡 使用的是BANK4,如图3.1所示。



图3.1 DM9000原理图

由图可知,DM9000网卡使用的片选信号是nGCS
4,也就说明DM9000使用了BANK4。修改lowlevel_init.S(路径:board/smdk2410/lowlevel_init.S)。

/* BWSCON */

#define DW8 (0x0)

#define DW16 (0x1)

#define DW32 (0x2)

#define WAIT (0x1<<2)

#define UBLB (0x1<<3)

#define B1_BWSCON (DW32)

#define B2_BWSCON (DW16)

#if 0

#define B3_BWSCON (DW16 + WAIT + UBLB)

#endif

#define B3_BWSCON (DW16 + UBLB)

#define B4_BWSCON (DW16 + WAIT + UBLB)

#define B5_BWSCON (DW16)

#define B6_BWSCON (DW32)

#define B7_BWSCON (DW32)

修改前BANK3外接的CS8900网卡,将BANK3注释掉,修改数据宽度为16位,设置BANK4数据宽度16位,使用WAIT和nBE信号。

#define B4_Tacs 0x0 /*0clk */

#define B4_Tcos 0x3 /*4clk */

#define B4_Tacc 0x7 /* 14clk */

#define B4_Tcoh 0x1 /*1clk */

#define B4_Tah 0x3 /*4clk */

#define B4_Tacp 0x6 /*6clk */

#define B4_PMC 0x0 /* normal */

根据DM9000数据手册设置时序,具体见DM9000数据手册。

四、配置u-boot使用DM9000网卡

修改配置文件smdk2410.h(路径:include/configs/smdk2410.h)。

/** Hardware drivers*/

#if 0

#define CONFIG_DRIVER_CS8900 1

/* we have a CS8900 on-board */

#define CS8900_BASE 0x19000300

#define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */

#endif

#define CONFIG_DRIVER_DM9000 1 /* we have a DM9000 on-board */

#define CONFIG_DM9000_USE_16BIT 1

#define CONFIG_DM9000_BASE 0x20000000

#define DM9000_DATA 0x20000004

#define DM9000_IO 0x20000000

注释掉CS8900的信息,添加DM9000的配置信息。

宏定义CONFIG_DRIVER_DM9000为1表示配置使用DM9000网卡,u-boot编译时会将DM9000相关的驱动编译进去。其中0x20000000是DM9000的基址(BANK4),由于DM9000只有一条地址线CMD(LADDR2,见图3.1)用于区别是数据还是地址(CMD为低时数据总线上传输的是地址信号,CMD为高时传输的是数据信号),所以DM9000_DATA为0x20000004,DM9000_IO为0x20000000。

五、设置IP、serverIP

在配置文件smdk2410.h(路径:include/configs/smdk2410.h)中根据实际情况修改开发板的IP地址,serverIP。

修改前:

#define CONFIG_NETMASK 255.255.255.0

#define CONFIG_IPADDR 10.0.0.110

#define CONFIG_SERVERIP 10.0.0.1

修改后:

#define CONFIG_NETMASK 255.255.255.0

#define CONFIG_IPADDR 192.168.1.6

#define CONFIG_SERVERIP 192.168.1.2

我的PC和开发板使用路由器相连,PC
IP地址为192.168.1.2,开发板设置为192.168.1.6,保证在同一个网段就行。

增加ping命令:

#define CONFIG_COMMANDS \

(CONFIG_CMD_DFL| \

CFG_CMD_CACHE| \

/*CFG_CMD_NAND|*/ \

/*CFG_CMD_EEPROM |*/ \

/*CFG_CMD_I2C|*/ \

/*CFG_CMD_USB|*/ \

FG_CMD_REGINFO| \

CFG_CMD_PING| \

CFG_CMD_DATE| \

CFG_CMD_ELF)

仿照CMD命令格式,我们使用CFG_CMD_PING增加对ping的支持。

六、遇到问题vs解决方案

以上任务完成,在u-boot根目录下编译,编译成功!

使用OpenJtag将编译完成的u-boot.bin烧入开发板运行。u-boot启动后,使用print命令查看u-boot的参数:

Jz2440 # print

bootdelay=3

baudrate=115200

ethaddr=08:00:3e:26:0a:5b

ipaddr=192.168.1.6

serverip=192.168.1.2

netmask=255.255.255.0

stdin=serial

stdout=serial

stderr=serial

看到开发板的IP、serverIP已经修改成功。我们使用ping命令ping一下PC
192.168.1.2。

Jz2440 # ping 192.168.1.2

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

MAC: 50:50:50:50:50:50

could not establish link

ping failed; host 192.168.1.2 is not alive

host is not alive ,ping不通,看来存在问题!

上网搜索了很久,网上的都是教你屏蔽这一段代码,屏蔽那一段代码,然后就可以了,都没有详细的分析,看不大明白。后来,通过研究高版本的u-boot,发现了问题所在。

打开高版本u-boot,u-boot-1.3.4中的dm9000x.c,可以看到如下更新说明:

06/03/2008 Remy Bohmer <linux@bohmer.net>

-Fixed the driver to work with DM9000A.

发现DM9000驱动在后续版本中更新了,老版本的(u-boot-1.1.6)对DM9000支持可能存在问题。

发现了问题,马上更新试试看,复制u-boot-1.3.4中的dm9000x.c到u-boot-1.1.6中,覆盖掉原来的dm9000x.c,然后编译。

出现了错误!

drivers/dm9000x.c:480: undefined reference to `is_zero_ether_addr'

/drivers/dm9000x.c:480: undefined reference to `is_multicast_ether_addr'

make: *** [u-boot] Error 1

很明显,缺少两个函数定义。网上搜索也没有找到,干脆对u-boot-1.3.4建立SourceInsight工程搜索这两个函数。发现这两个函数都存在于net.h中(路径:include/net.h)。

复制这两个函数,到自己的u-boot(目前为u-boot-1.1.6)的net.h中(路径:include/net.h)

/*

*

* is_zero_ether_addr - Determine if give Ethernet address is all zeros.

* @addr: Pointer to a six-byte array containing the Ethernet address

*

* Return true if the address is all zeroes.

*/

static inline int is_zero_ether_addr(const u8 *addr)

{

return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);

}

/*

*

* is_multicast_ether_addr - Determine if the Ethernet address is a multicast.

* @addr: Pointer to a six-byte array containing the Ethernet address

*

* Return true if the address is a multicast address.

* By definition the broadcast address is also a multicast address.

*/

static inline int is_multicast_ether_addr(const u8 *addr)

{

return (0x01 & addr[0]);

}

然后编译,通过!

烧写到开发板,ping主机192.168.1.2:

Jz2440 # ping 192.168.1.2

ERROR: resetting DM9000 -> not responding

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

DM9000: running in 16 bit mode

MAC: 08:00:3e:26:0a:5b

could not establish link

host 192.168.1.2 is alive

“host 192.168.1.2 is alive”, ping通了,DM9000移植OK!

七、网络测试

1.测试tftp

通过tftp传输一个程序到内存中运行试试看。在主机上打开tftp软件,将leds.bin(运行地址在0x30000000)放在tftp软件目录中,在u-boot界面,输入命令:

Jz2440 # tftp 0x30000000 leds.bin

ERROR: resetting DM9000 -> not responding

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

DM9000: running in 16 bit mode

MAC: 08:00:3e:26:0a:5b

could not establish link

TFTP from server 192.168.1.2; our IP address is 192.168.1.6

Filename 'leds.bin'.

Load address: 0x30000000

Loading: #

done

Bytes transferred = 168 (a8 hex)

传输成功,在u-boot界面使用go命令运行程序

Jz2440 # go 0x30000000

## Starting application at 0x30000000 ...

可以看到Jz2440开发板上led已经在循环闪烁了。

2.测试nfs

由于虚拟机Linux上开启了nfs服务,虚拟机Linux
IP为192.168.1.3,需要先更改serverIP。

Jz2440 # setenv serverip 192.168.1.3

Jz2440 # saveenv

然后将leds.bin放在nfs目录,/work/nfs_root/,在u-boot界面使用nfs传输文件

Jz2440 # nfs 0x30000000 192.168.1.3:/work/nfs_root/leds.bin

ERROR: resetting DM9000 -> not responding

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

DM9000: running in 16 bit mode

MAC: 08:00:3e:26:0a:5b

could not establish link

File transfer via NFS from server 192.168.1.3; our IP address is 192.168.1.6

Filename '/work/nfs_root/leds.bin'.

Load address: 0x30000000

Loading: #

done

Bytes transferred = 168 (a8 hex)

传输成功,在u-boot界面使用go命令运行程序

Jz2440 # go 0x30000000

## Starting application at 0x30000000 ...

可以看到Jz2440开发板上led已经在循环闪烁了。

至此,DM9000网卡移植成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: