XiaomiRouter自學之路(05-U-boot配置編譯燒錄)
上一章節已經將遠程和本地的U-boot服務器都搭建完成了,現在我們要開始真正的編譯我們所clone的U-boot是否能正常,燒錄進去是否能帶動板子呢?
1.在配置編譯之前,我們需要把編譯器gcc先安裝好,在網上下載MTK的SDK,如MediaTek_ApSoC_SDK_4320_20150414.tar.bz2,解壓后將里面的buildroot-gcc342.tar.bz2復制到/opt/目錄下進行解壓即可,如下:
linye@ly:~/XiaomiRouter$ tar -jxvf MediaTek_ApSoC_SDK_4320_20150414.tar.bz2
linye@ly:~/XiaomiRouter$ cd RT288x_SDK/toolchain/
linye@ly:~/XiaomiRouter/RT288x_SDK/toolchain$ cp buildroot-gcc342.tar.bz2 /opt/
linye@ly:~/XiaomiRouter/RT288x_SDK/toolchain$ cd /opt/
linye@ly:/opt$ tar -jxvf buildroot-gcc342.tar.bz2
對于環境的搭建不同版本的Ubuntu可能會有不同,遇到問題時自己到網絡上找下解決方案,gcc解壓到/opt/目錄后,U-boot在make時會自動查找gcc所在的位置,所以我們只需要解壓即可。
2.通過make menuconfig
進行配置U-boot,會出現GUI配置頁面,我們進行如下選擇
對選項進行解析下,
- Chip Type(ASIC):application-specific integrated circuit專用集成電路
- Chip ID(MT7620):主芯片型號
- Flash Type(SPI):小米mini路由器使用的是16M的SPI Flash
- DRAM Type(DDR2):使用的是NT5TU64M16芯片,參看官方手冊為1Gb、16bits的DDR2,所以下面兩個選項為DDR Component(1024Mb)和DDR Width(16bits)
- Ram/Rom version(ROM):SPI Flash為ROM
- CPU PLL source(CONF):與PLL_MULTI_RATIO conf(29)和PLL_DIV_RATIO conf(2)共同來決定CPU的是在頻率,PLL source一共有三種模式AUX0/AUX1/CONF,有興趣的可以去追查下代碼,到后面會在/tools/mkimage.c里面調用以下信息進行PLL選擇
#if defined (CPLL_FROM_480MHZ)
cpu_pll = ntohs(1<<11);
#elif defined (CPLL_FROM_XTAL)
cpu_pll = ntohs(1<<12);
#else
cpu_pll = ntohs((CPLL_MULTI_RATIO_CFG<<8)|(CPLL_DIV_RATIO_CFG<<6)|(CPLL_SSC_CFG<<0));
#endif
寄存器的介紹可以查看MT7620_ProgrammingGuide的33頁CPLL_CFG0寄存器。
- 其他幾個配置項暫時不知道怎么用,后面明白時進行更新。
3.配置后通過make
命令進行編譯,編譯完成會出現如下錯誤
fsdata.c:314: error: parse error before ',' token
make[1]: *** [fs.o] Error 1
make[1]: Leaving directory `/home/linye/XiaomiRouter/U-boot/httpd'
make: *** [httpd/libhttpd.a] Error 2
4.錯誤提示httpd/fsdata.c的314行有誤,我們打開該文件看下,可以很清楚的看到多了一個逗號,去掉即可,再執行make
進行編譯,如下信息及編譯成功
===============<<IMPORTANT>>==================
Notes:Uboot firmware is uboot.bin NOT uboot.img
================================================
./tools/mkimage -A mips -T standalone -C none \
-a 0xBC000000 -e 0xbc000000 \
-n "SPI Flash Image" \
-r DDR -s 16 -t 128 -u 32 \
-y 0xFF -z 0xFF -w 0xFF -d uboot.bin uboot.img
Image Name: SPI Flas
Created: Fri Feb 10 14:03:16 2017
Image Type: MIPS Linux Standalone Program (uncompressed)
Data Size: 124804 Bytes = 121.88 kB = 0.12 MB
Load Address: 0xBC000000
Entry Point: 0xBC000000
DRAM Parameter: 2b (Parm0=0 Parm1=0)
5.在目錄下會生成uboot.bin文件,將這個文件cp到window,使用SPI燒錄器進行燒錄,然后將flash重新裝回插座口上電。如果一切都正常的話,console應該會出現類似下面的亂碼
榾鎬榾鎬f駘?烚瀈??驤唦`?驤唦`?驤唦`??榾鎬榾鎬f駘?烚?
6.觀察到能打印信息但是亂碼,應該是波特率有問題,所以嘗試著更改下secureCRT的波特率,可以得到當波特率為57600時,可以正常打印如下信息:
U-Boot 1.1.3 (Feb 9 2017 - 05:56:34)
Board: Ralink APSoC DRAM: 128 MB
GPIO#44 updated GPIOMODE register: 001a311c -> 001ab11c
MT7620 Ai-BR100 gpio init : WPS / RESET pin
relocate_code Pointer at: 87fb0000
enable ephy clock...done. rf reg 29 = 5
SSC disabled.
spi_wait_nsec: 29
spi device id: ef 40 14 0 0 (40140000)
Warning: un-recognized chip ID, please update bootloader!
raspi_read: from:20000 len:1000
*** Warning - bad CRC, using default environment
============================================
CleanWRT u-boot_mt7620 Version: 0.0.0.1
--------------------------------------------
ASIC 7620_MP (Port5<->None)
DRAM component: 1024 Mbits DDR, width 16
DRAM bus: 16 bit
Total memory: 128 MBytes
Flash component: SPI Flash
Date:Feb 9 2017 Time:05:56:34
============================================
icache: sets:512, ways:4, linesz:32 ,total:65536
dcache: sets:256, ways:4, linesz:32 ,total:32768
##### The CPU freq = 580 MHZ ####
estimate memory size =128 Mbytes
Press press WPS button for more than 2 seconds to run web failsafe mode
WPS button is pressed for: 0 second(s)
Catution: WPS button wasn't pressed or not long enough!
Continuing normal boot...
Please choose the operation:
0: System Load Linux then write to Flash via Serial.
1: Load system code to SDRAM via TFTP.
2: Load system code then write to Flash via TFTP.
3: Boot system code via Flash (default).
4: Entr boot command line interface.
7: Load Boot Loader code then write to Flash via Serial.
8: System Load UBoot to SDRAM via TFTP.
9: Load Boot Loader code then write to Flash via TFTP.
3
7.在倒計時的時候直接按Enter鍵發現不是進入命令行,使用的是默認選項3,直接bootm,但又沒有內核,所以卡住
3: System Boot system code via Flash.
## Booting image at bc040000 ...
raspi_read: from:40000 len:40
Bad Magic Number,FFFFFFFF
8.觀察提示可以輸入4則進入命令行模式,進行操作,可以自己試下
You choosed 4
0
raspi_read: from:30028 len:6
4: System Enter Boot Command Line Interface.
U-Boot 1.1.3 (Feb 9 2017 - 05:56:34)
MT7620 #
MT7620 # pri
bootcmd=tftp
bootdelay=5
baudrate=57600
ethaddr="24:0A:64:FE:47:BB"
ipaddr=192.168.128.1
serverip=192.168.128.32
stdin=serial
stdout=serial
stderr=serial
Environment size: 154/4092 bytes
MT7620 #
9.輸入9則進入TFTP更新模式,當選擇9后,會提示你是否確認擦出Uboot進行tftp更新,然后就是設置ip,輸入uboot的名稱,把網址的ip地址設置為192.168.128.32,將Tfthd32打開,并定位到uboot.bin所放的位置,設置完成后按Enter鍵即可,如果一切設置正常則會出現如下過程。
Warning!! Erase Boot Loader in Flash then burn new one. Are you sure?(Y/N)
Please Input new ones /or Ctrl-C to discard
Input device IP (192.168.128.1) ==:192.168.128.1
Input server IP (192.168.128.32) ==:192.168.128.32
Input Uboot filename () ==:uboot.bin
netboot_common, argc= 3
NetTxPacket = 0x87FE6C40
KSEG1ADDR(NetTxPacket) = 0xA7FE6C40
NetLoop,call eth_halt !
NetLoop,call eth_init !
Trying Eth0 (10/100-M)
Waitting for RX_DMA_BUSY status Start... done
ETH_STATE_ACTIVE!!
TFTP from server 192.168.128.32; our IP address is 192.168.128.1
Filename 'uboot.bin'.
TIMEOUT_COUNT=10,Load address: 0x80100000
Loading: Got ARP REPLY, set server/gtwy eth addr (00:0c:07:14:05:2d)
Got it
#########################
done
Bytes transferred = 124164 (1e504 hex)
NetBootFileXferSize= 0001e504
raspi_erase_write: offs:0, count:1e504
raspi_erase: offs:0 len:10000
.
raspi_write: 80100000 to:0 len:10000
.
raspi_read: from:0 len:10000
raspi_read: from:10000 len:10000
raspi_erase: offs:10000 len:10000
.
raspi_write: 87f711f0 to:10000 len:10000
.
raspi_read: from:10000 len:10000
Done!
U-Boot 1.1.3 (Feb 10 2017 - 21:39:25)
可以觀察到tftp服務器檢測到網絡正常并uboot.bin存在時,就會將uboot.bin上傳到0x80100000地址,然后將spi flash里面原本的uboot擦除掉,把新的uboot寫進去后重啟。
U-boot配置編譯燒錄的分析就到這邊,有感悟時會持續會更新。
注:以上內容都是本人在學習過程積累的一些心得,難免會有參考到其他文章的一些知識,如有侵權,請及時通知我,我將及時刪除或標注內容出處,如有錯誤之處也請指出,進行探討學習。文章只是起一個引導作用,詳細的數據解析內容還請查看XiaomiRouter相關教程,感謝您的查閱。