移植uboot第七步:支持DM9000
寫在前面:
我的博客已遷移至自建服務器:博客傳送門,CSDN博客暫時停止,如有機器學習方面的興趣,歡迎來看一看。
此外目前我在gitHub上準備一些李航的《統計學習方法》的實現算法,目標將書內算法全部手打實現,歡迎參觀并打星。GitHib傳送門
正文
一. 在Uboot中搜索DM9000,可以找到dm9000x.c,說明uboot是可以支持dm9000的。該文件的路徑為:drivers\net\Dm9000x.c,找到net目錄下的Makefile
COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.odm9000x是否編譯取決于宏CONFIG_DRIVER_DM9000,同樣,uboot原先默認的網卡是cs8900,它的宏取決于CONFIG_CS8900。進入smdk2440.h對宏進行配置
#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 */把原先的8900的宏取消,添加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) make[1]: *** [dm9000x.o] Error 1 make[1]: Leaving directory `/work/system/u-boot-2012.04.01/drivers/net' make: *** [drivers/net/libnet.o] Error 2找打第一個錯誤,是說DM9000_DATA未定義。在linux中uboot的文件夾內搜索這個宏,看看別人怎么使用的
book@book-desktop:/work/system/u-boot-2012.04.01$ grep "DM9000_DATA" * -nR結果如下:
drivers/net/dm9000x.c:156: DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); drivers/net/dm9000x.c:165: DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); drivers/net/dm9000x.c:173: DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA); drivers/net/dm9000x.c:180: ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA); drivers/net/dm9000x.c:189: ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA); drivers/net/dm9000x.c:197: ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA); drivers/net/dm9000x.c:206: tmpdata = DM9000_inl(DM9000_DATA); drivers/net/dm9000x.c:215: *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA)); drivers/net/dm9000x.c:216: *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA)); drivers/net/dm9000x.c:224: __le16_to_cpu(DM9000_inb(DM9000_DATA) + drivers/net/dm9000x.c:225: (DM9000_inb(DM9000_DATA) << 8)); drivers/net/dm9000x.c:227: __le16_to_cpu(DM9000_inb(DM9000_DATA) + drivers/net/dm9000x.c:228: (DM9000_inb(DM9000_DATA) << 8)); drivers/net/dm9000x.c:484: rxbyte = DM9000_inb(DM9000_DATA) & 0x03; drivers/net/dm9000x.c:575: return DM9000_inb(DM9000_DATA); drivers/net/dm9000x.c:585: DM9000_outb(value, DM9000_DATA); include/configs/trizepsiv.h:303:#define DM9000_DATA (CONFIG_DM9000_BASE+0x8004) include/configs/scb9328.h:249:#define DM9000_DATA (CONFIG_DM9000_BASE+4) include/configs/pm9261.h:258:#define DM9000_DATA (CONFIG_DM9000_BASE + 4) include/configs/M5253DEMO.h:95:# define DM9000_DATA (CONFIG_DM9000_BASE + 4) include/configs/devkit8000.h:81:#define DM9000_DATA (CONFIG_DM9000_BASE + 0x400) include/configs/ip04.h:78:#define DM9000_DATA (CONFIG_DM9000_BASE + 2) include/configs/colibri_pxa270.h:84:#define DM9000_DATA (CONFIG_DM9000_BASE + 4) include/configs/davinci_dm355evm.h:56:#define DM9000_DATA (CONFIG_DM9000_BASE + 2) include/configs/at91sam9261ek.h:159:#define DM9000_DATA (CONFIG_DM9000_BASE + 4) include/configs/vpac270.h:113:#define DM9000_DATA (CONFIG_DM9000_BASE + 4) include/configs/davinci_dm355leopard.h:55:#define DM9000_DATA (CONFIG_DM9000_BASE + 16)隨便找了一個文件進入看看(后面的+Num是打開以后定位到該文件的某行)
vi include/configs/vpac270.h +113結果如下:
#define CONFIG_DM9000_BASE 0x08000300 /* CS2 */ #define DM9000_IO (CONFIG_DM9000_BASE) #define DM9000_DATA (CONFIG_DM9000_BASE + 4)所以我也把它直接這樣加我的我文件里了
#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 #define CONFIG_DM9000_BASE 0x20000000 //這三個是新加的 #define DM9000_IO CONFIG_DM9000_BASE //這三個是新加的 #define DM9000_DATA (CONFIG_DM9000_BASE + 4) //這三個是新加的 #endif網卡屬于內存設備,它的片選由寫入的地址范圍決定,我的dm9000根據硬件接線,如果寫入的地址在0x20000000到0x30000000,它會被選中,所以其中CONFIG_DM9000_BASE值改為0x20000000,DM9000_DATA是命令數據引腳,我的是bit2,1時為數據,用十進制表示是4,所以值修改為(CONFIG_DM9000_BASE + 4)
三,編譯,燒寫,運行
U-Boot 2012.04.01 (Aug 13 2016 - 17:00:33)CPUID: 32440001 FCLK: 400 MHz HCLK: 100 MHz PCLK: 50 MHz DRAM: 64 MiB WARNING: Caches not enabled Flash: 2 MiB NAND: 256 MiB *** Warning - bad CRC, using default environmentIn: serial Out: serial Err: serial Net: No ethernet found. SMDK2410 #沒有檢測到網卡,還是有問題。網卡那塊重頭檢查一遍
start.S cpu_init_crit lowlevel_init先檢查了一遍寄存器位寬和時間參數有沒有正確,我最后沒有做修改。
start.S board_init_r eth_initialize board_eth_init在這個函數中發現了問題
#ifdef CONFIG_CMD_NET int board_eth_init(bd_t *bis) {int rc = 0; #ifdef CONFIG_CS8900rc = cs8900_initialize(0, CONFIG_CS8900_BASE); #endifreturn rc; } #endif網卡的初始化,只宏定義了8900,現在宏沒有定義,程序里面什么都沒執行,9000沒有進行初始化,進入dm9000x.c,看看有沒有提供初始化函數。
int dm9000_initialize(bd_t *bis)找到了函數,在board_eth_init中添加進去
#ifdef CONFIG_DRIVER_DM9000rc = dm9000_initialize(bis); #endif只要定義了dm9000,就執行9000的初始化,如果定義了8900,就初始化8900。
四. 編譯,燒寫
U-Boot 2012.04.01 (Aug 13 2016 - 17:38:05)CPUID: 32440001 FCLK: 400 MHz HCLK: 100 MHz PCLK: 50 MHz DRAM: 64 MiB WARNING: Caches not enabled Flash: 2 MiB NAND: 256 MiB *** Warning - bad CRC, using default environmentIn: serial Out: serial Err: serial Net: dm9000 SMDK2410 #已經檢測到dm9000了,設置一下ip地址,地址隨便設的,然后試試ping一下
SMDK2410 # set ipaddr 192.168.1.120 SMDK2410 # ping 192.168.1.119 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.119 is not alive出現了錯誤,ethaddr還沒有設置,mac地址copy的lunix虛擬機的mac,mac不能自己隨便寫,它有自己的格式。
SMDK2410 # set ethaddr 00:0c:29:d3:fe:1d再次ping
SMDK2410 # ping 192.168.1.119 ERROR: resetting DM9000 -> not responding dm9000 i/o: 0x20000000, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 00:0c:29:d3:fe:1d could not establish link Using dm9000 device host 192.168.1.119 is alive成功了,試著用網絡下載內核試試,在winPC端打開tftp服務器,文件地址寫為包含內核的文件地址,在板子上設置服務器ip
set serverip 192.168.1.119這個ip一定要和tftp服務器上顯示的ip一樣,向板子輸入命令等待傳輸
tftp 30000000 uImage燒寫完成了,啟動內核
SMDK2410 # bootm 30000000之后內核正常啟動,但在啟動過程中依然報了一些錯,這些在之后解決
總結
以上是生活随笔為你收集整理的移植uboot第七步:支持DM9000的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移植uboot第六步:支持NANDFla
- 下一篇: 移植uboot第八步:裁剪、修改默认参数