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.bindm9000 i/o: 0x20000000, id: 0x90000a46DM9000: running in 16 bit modeMAC: 00:01:02:03:04:05operating at 100M full duplex modeUsing dm9000 deviceTFTP from server 192.168.1.229; our IP address is 192.168.1.230Filename '6Ubootnand.bin'.Load address: 0x0Loading: T #Can't write to protected Flash sectorsSMDK2440 # protect off allUn-Protect Flash Bank # 1SMDK2440 # tftp 0 6Ubootnand.bindm9000 i/o: 0x20000000, id: 0x90000a46DM9000: running in 16 bit modeMAC: 00:01:02:03:04:05operating at 100M full duplex modeUsing dm9000 deviceTFTP from server 192.168.1.229; our IP address is 192.168.1.230Filename '6Ubootnand.bin'.Load address: 0x0Loading: T #Flash not ErasedT SMDK2440 # erase 0 3ffffErasing 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 sectorsSMDK2440 # tftp 0 6Ubootnand.bindm9000 i/o: 0x20000000, id: 0x90000a46DM9000: running in 16 bit modeMAC: 00:01:02:03:04:05operating at 100M full duplex modeUsing dm9000 deviceTFTP from server 192.168.1.229; our IP address is 192.168.1.230Filename '6Ubootnand.bin'.Load address: 0x0Loading: T #T ######T ###doneBytes 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 MBFlash: 2 MBNAND: 256 MiB*** Warning - bad CRC, using default environment
In: serialOut: serialErr: serialNet: dm9000Hit any key to stop autoboot: 0SMDK2440 #
后记: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 beperformed in two steps: (1) download to RAM, and (2)copy from RAM to flash.
The two-step approach is usually more reliable, sinceyou can check if the download worked before you erasethe flash, but in some situations (when system RAM istoo limited to allow for a temporary copy of thedownloaded image) this option may be very useful.