读书人

U-boot用tftp下令直接烧写到NandFlash

发布时间: 2013-03-21 10:08:17 作者: rapoo

U-boot用tftp命令直接烧写到NandFlash V2.0

U-boot用tftp命令直接烧写到NandFlash V2.0

/****************************************************
版本:v2.0功能:可以实现小于1024的字节的写入了。大于1024的也可以了。不足:就是下边的“没解决的问题”*****************************************************/1、定义一块tftp_nand_buffer[2048];2、每次store_block调用的时候,首先从tftp_nand_buffer[(tftp_nand_counter & 1) << 10]开始拷贝数据;3、nand_write_skip_bad(nand, off, &length, buffer);
nand_write_skip_bad:nand :off  :写入flash的位置(off + ((tftp_nand_counter-1)*1024)) //里边的off为0.length:数据长度,为2048buffer: 数据位置 tftp_nand_buffer
改动如下:
--- 6Ubootnand/net/tftp.c 2013-03-10 20:45:12.448500276 +0800+++ 7UbootTftp/net/tftp.c 2013-03-12 21:05:20.092097048 +0800@@ -9,6 +9,11 @@ #include <net.h> #include "tftp.h" #include "bootp.h"+#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP+#include <nand.h>+static ulong tftp_nand_counter = 0;+static u_char tftp_nand_buffer[2048];+#endif #if defined(CONFIG_CMD_NET) @@ -131,7 +136,11 @@ ulong newsize = offset + len; #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP int i, rc = 0;-+ int data_end_flag = 0;+ nand_info_t *nand;+ loff_t off = 0;+ size_t length;+ u_char *buffer; for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; i++) { /* start address in flash? */ if (flash_info[i].flash_id == FLASH_UNKNOWN)@@ -142,19 +151,37 @@ } } - if (rc) { /* Flash is destination for this packet */- rc = flash_write ((char *)src, (ulong)(load_addr+offset), len);+ nand = &nand_info[nand_curr_device];+ off = 0x0;+ length = 2048;+ memcpy((uchar *)(tftp_nand_buffer+((tftp_nand_counter & 1) << 10)), (uchar *)src, 1024);+ buffer = (u_char *)tftp_nand_buffer;+ printf("\nlen = %d, tftp_nand_counter = %d\n", len, tftp_nand_counter);+ if(len < 1024)+ {+ data_end_flag = 1; //不足1k的。+ if (0 == tftp_nand_counter)
+ tftp_nand_counter = 1;
+ //buffer = (u_char *)src;+ }+ if ( rc && ( data_end_flag || (0 != (tftp_nand_counter & 1))) ) { /* Flash is destination for this packet */+ rc = nand_write_skip_bad(nand, (off + ((tftp_nand_counter-1)*1024)), &length, buffer);+ printf("\nhaha\n"); if (rc) { flash_perror (rc); NetState = NETLOOP_FAIL; return; }+ } else #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */ { (void)memcpy((void *)(load_addr + offset), src, len); }++#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP+ tftp_nand_counter ++;+#endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */+ #ifdef CONFIG_MCAST_TFTP if (Multicast) ext2_set_bit(block, Bitmap);
另外在板级配置文件中smdk2440.h中:
/* * tftp 烧写到flash中 */#define CONFIG_SYS_DIRECT_FLASH_TFTP 1#define CONFIG_TFTP_BLOCKSIZE 1024
代码修改完。
然后tftp了一个led.bin(<1k)的,OK了。tftp了一个vboot.bin (3k<size<4k)也OK了。这说明大体没有问题了。(如图1)图2 是运行成功截图。
U-boot用tftp下令直接烧写到NandFlash V2.0
图1U-boot用tftp下令直接烧写到NandFlash V2.0
图2
没解决的问题:
1.但是是烧写102k的会出现超时:Retry count exceeded; starting again 。不过应该是tftp延时参数的问题了。一次能计79次。说明能80k烧写。(如图3)2.计数的全局变量没有函数去给它清零,如果开机时tftp再次,这个全局变量会还会是上次tftp时候计数的值。要在tftp这个命令的执行函数里边清零这个全局变量。(如图4)U-boot用tftp下令直接烧写到NandFlash V2.0
图3U-boot用tftp下令直接烧写到NandFlash V2.0
图4


重点参考:《以1024收,以2048存的算法》 http://bbs.csdn.net/topics/390389188




读书人网 >Flash

热点推荐