U-boot中用tftp命令直接烧写到flash中


一年前,学习使用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源代码下载地址

相关内容