U-boot用tftp命令直接烧写到NandFlash V2.0
2013-03-12 22:09
337 查看
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:数据长度,为2048
buffer: 数据位置 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 是运行成功截图。
图1
图2
没解决的问题:
1.但是是烧写102k的会出现超时:Retry count exceeded; starting again 。不过应该是tftp延时参数的问题了。一次能计79次。说明能80k烧写。(如图3)
2.计数的全局变量没有函数去给它清零,如果开机时tftp再次,这个全局变量会还会是上次tftp时候计数的值。要在tftp这个命令的执行函数里边清零这个全局变量。(如图4)
图3
图4
重点参考:《以1024收,以2048存的算法》 http://bbs.csdn.net/topics/390389188
/****************************************************
版本: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:数据长度,为2048
buffer: 数据位置 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 是运行成功截图。
图1
图2
没解决的问题:
1.但是是烧写102k的会出现超时:Retry count exceeded; starting again 。不过应该是tftp延时参数的问题了。一次能计79次。说明能80k烧写。(如图3)
2.计数的全局变量没有函数去给它清零,如果开机时tftp再次,这个全局变量会还会是上次tftp时候计数的值。要在tftp这个命令的执行函数里边清零这个全局变量。(如图4)
图3
图4
重点参考:《以1024收,以2048存的算法》 http://bbs.csdn.net/topics/390389188
相关文章推荐
- U-boot用tftp命令直接烧写到NandFlash V1.0
- U-boot中用tftp命令直接烧写到flash中
- U-boot用tftp命令直接烧写到NandFlash V3.0
- 追踪uboot下tftp命令的代码执行过程
- 移植u-boot1.1.4支持操作nandFlash的nand erase命令
- u-boot命令介绍及烧写程序实例
- DM8168 ccs5.4 烧写u-boot到nandflash
- 用uboot 烧写uboot linux内核 文件系统到nandflash的 过程以及bootm go命令启动与区别
- uboot烧写命令--yaffs、jiffs和ubifs
- 用tftp的方式在u_boot下 烧写uImage内核
- u-boot配置、编译、烧写、命令使用
- u-boot命令介绍及烧写
- 如何用nfs命令烧写内核和文件系统(网络下载文件到nandflash)(未完)
- u-boot命令介绍及烧写程序实例
- u-boot命令介绍及烧写程序实例(备忘)
- Linux_Bootloader_u-boot命令介绍及烧写程序实例
- 如何用nfs命令烧写内核和文件系统(网络下载文件到nandflash)(未完)
- 用uboot 烧写uboot linux内核 文件系统到nandflash的 过程以及bootm go命令启动与区别
- 使用u-boot的tftp下载功能烧写程序到Nand Flash ——韦东山嵌入式Linux学习笔记09
- JZ2440如何烧写裸板程序,在 Linux 下使用 dnw 和 u-boot 烧写系统 和 用Tftp 下载