歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> U-boot中用tftp命令直接燒寫到flash中

U-boot中用tftp命令直接燒寫到flash中

日期:2017/3/1 10:00:24   编辑:Linux編程

一年前,學習使用u-boot時候用它的Yaffs功能燒寫一個96M的Yaffs鏡像,結果在tftp到內存中一半卡死。細分析原因是內存一共64M,你要把一個96M的鏡像下載到內存中去。那不得撐死。網上找不到答案,就覺得是自己發現一個大的bug,但是又不會移植。就向當時用的u-boot的原創Tekkmannaja發郵件求助。他很仔細的答復了,並指出了解決了解決方案。我一邊激動一邊無奈。激動的是大牛回信了,無奈的是我根本就沒有移植成功過u-boot,看他的說的頭頭是道。可我還是無從下手。當時就這樣放到那了。

時隔一年,再來看這個問題,再翻開他回的郵件,這次看感覺清晰一點了。這次再不做出來點啥。可真是說不過去了。主要是tftp接收到數據後,如果地址是flash中的就燒到flash中去。這樣就沒有大小限制了。除非鏡像比flash還大,那誰都沒有辦法。


主要看的是net/tftp.c中的CONFIG_SYS_DIRECT_FLASH_TFTP宏之間的內容。仔細看看了,在板級配置文件中加上這個宏之後,這個宏裡邊的內容執行不執行就靠地址來地址范圍來判斷的。那就加上這個宏直接下載到0地址處看會怎麼樣。測試的三次終於可以,這個只是測試燒寫到NorFlash,重點是NandFlash。還要更改CONFIG_SYS_DIRECT_FLASH_TFTP宏之間的內容為NandFlash寫入。


SMDK2440 # tftp 0 6Ubootnand.bin
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:01:02:03:04:05
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.229; our IP address is 192.168.1.230
Filename '6Ubootnand.bin'.
Load address: 0x0
Loading: T #Can't write to protected Flash sectors
SMDK2440 # protect off all
Un-Protect Flash Bank # 1
SMDK2440 # tftp 0 6Ubootnand.bin
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:01:02:03:04:05
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.229; our IP address is 192.168.1.230
Filename '6Ubootnand.bin'.
Load address: 0x0
Loading: T #Flash not Erased
T SMDK2440 # erase 0 3ffff
Erasing sector 0 ... ok.
Erasing sector 1 ... ok.
Erasing sector 2 ... ok.
Erasing sector 3 ... ok.
Erasing sector 4 ... ok.
Erasing sector 5 ... ok.
Erasing sector 6 ... ok.
Erased 7 sectors
SMDK2440 # tftp 0 6Ubootnand.bin
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:01:02:03:04:05
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.229; our IP address is 192.168.1.230
Filename '6Ubootnand.bin'.
Load address: 0x0
Loading: T #T ######T ###
done
Bytes transferred = 146292 (23b74 hex)
SMDK2440 # OKstage_on: going to jump o start_armboot....


U-Boot 2009.11 ( 3月 11 2013 - 10:13:31)


DRAM: 64 MB
Flash: 2 MB
NAND: 256 MiB
*** Warning - bad CRC, using default environment


In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
SMDK2440 #


後記:NandFlash中主要根文件系統需要這樣燒寫,其它都不需要。這樣的話,這裡還要改成nand.yaffs中裡邊的燒寫函數了。有點復雜,但是這次一定要做出來。以下是u-boot裡邊對這個宏的解釋。
- CONFIG_SYS_DIRECT_FLASH_TFTP:


Enable TFTP transfers directly to flash memory;
without this option such a download has to be
performed in two steps: (1) download to RAM, and (2)
copy from RAM to flash.


The two-step approach is usually more reliable, since
you can check if the download worked before you erase
the flash, but in some situations (when system RAM is
too limited to allow for a temporary copy of the
downloaded image) this option may be very useful.

U-Boot源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

Copyright © Linux教程網 All Rights Reserved