s3c2440中U-boot移植时执行cp.b提示:Flash not Erased【转】
本文转载自:https://blog.csdn.net/baiyang139/article/details/79054415
在源码中搜索Flash not Erased,在common/flash.c中flash_perror()函数为错误打印函数
void flash_perror (int err)
{
switch(err) {
caseERR_OK:
break;
caseERR_TIMOUT:
puts("Timeout writing to Flash\n");
break;
caseERR_NOT_ERASED:
puts("Flash not Erased\n");
break;
caseERR_PROTECTED:
puts("Can't write to protected Flash sectors\n");
break;
caseERR_INVAL:
puts("Outside available Flash\n");
break;
caseERR_ALIGN:
puts("Start and/or end address not on sector boundary\n");
break;
caseERR_UNKNOWN_FLASH_VENDOR:
puts("Unknown Vendor of Flash\n");
break;
caseERR_UNKNOWN_FLASH_TYPE:
puts("Unknown Type of Flash\n");
break;
caseERR_PROG_ERROR:
puts("General Flash Programming Error\n");
break;
default:
printf("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, err);
break;
}
}
在common/cmd_mem.c文件中查找cp命令,锁定do_mem_cp函数
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag,int argc, char * const argv[])
{
ulong addr, dest, count;
int size;
if(argc != 4)
returnCMD_RET_USAGE;
/*Check for size specification.
*/
if((size = cmd_get_data_size(argv[0], 4)) < 0)
return1;
addr= simple_strtoul(argv[1], NULL, 16);
addr+= base_address;
dest= simple_strtoul(argv[2], NULL, 16);
dest+= base_address;
count= simple_strtoul(argv[3], NULL, 16);
if(count == 0) {
puts("Zero length ???\n");
return1;
}
#ifndef CONFIG_SYS_NO_FLASH
/*check if we are copying to Flash */
if( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
&& (!addr_dataflash(dest))
#endif
) {
intrc;
puts("Copy to Flash... ");
rc = flash_write ((char *)addr,dest, count*size);
if (rc != 0) {
flash_perror(rc);
return(1);
}
puts("done\n");
return 0;
}
#endif
#ifdef CONFIG_HAS_DATAFLASH
/*Check if we are copying from RAM or Flash to DataFlash */
if(addr_dataflash(dest) && !addr_dataflash(addr)){
intrc;
puts("Copy to DataFlash... ");
rc= write_dataflash (dest, addr, count*size);
if(rc != 1) {
dataflash_perror(rc);
return(1);
}
puts("done\n");
return0;
}
/*Check if we are copying from DataFlash to RAM */
if(addr_dataflash(addr) && !addr_dataflash(dest)
#ifndef CONFIG_SYS_NO_FLASH
&& (addr2info(dest) == NULL)
#endif
){
intrc;
rc= read_dataflash(addr, count * size, (char *) dest);
if(rc != 1) {
dataflash_perror(rc);
return(1);
}
return0;
}
if(addr_dataflash(addr) && addr_dataflash(dest)){
puts("Unsupported combination of source/destination.\n\r");
return1;
}
#endif
#ifdef CONFIG_BLACKFIN
/*See if we're copying to/from L1 inst */
if(addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
memcpy((void*)dest, (void *)addr, count * size);
return0;
}
#endif
while(count-- > 0) {
if(size == 4)
*((ulong *)dest) = *((ulong *)addr);
elseif (size == 2)
*((ushort*)dest) = *((ushort *)addr);
else
*((u_char*)dest) = *((u_char *)addr);
addr+= size;
dest+= size;
/*reset watchdog from time to time */
if((count % (64 << 10)) == 0)
WATCHDOG_RESET();
}
return0;
}
从该函数
rc = flash_write ((char *)addr,dest, count*size);
if (rc != 0) {
flash_perror(rc);
return(1);
}
puts("done\n");
return 0;
部分可以得知flash_write函数返回值不为0,继续查找flash_write()函数。
在common/flash.c中查找到了flash_write()函数
/*-----------------------------------------------------------------------
*Copy memory to flash.
*Make sure all target addresses are within Flash bounds,
*and no protected sectors are hit.
*Returns:
*ERR_OK 0 - OK
*ERR_TIMOUT 1 - write timeout
*ERR_NOT_ERASED 2 - Flash not erased
*ERR_PROTECTED 4 - target range includesprotected sectors
*ERR_INVAL 8 - target address not inFlash memory
*ERR_ALIGN 16 - target address notaligned on boundary
* (only some targetsrequire alignment)
*/
int
flash_write (char *src, ulong addr, ulongcnt)
{
#ifdef CONFIG_SPD823TS
return(ERR_TIMOUT); /* any other error codesare possible as well */
#else
inti;
ulong end = addr + cnt - 1;
flash_info_t*info_first = addr2info (addr);
flash_info_t*info_last = addr2info (end );
flash_info_t*info;
if(cnt == 0) {
return(ERR_OK);
}
if(!info_first || !info_last) {
return(ERR_INVAL);
}
for(info = info_first; info <= info_last; ++info) {
ulongb_end = info->start[0] + info->size; /*bank end addr */
shorts_end = info->sector_count - 1;
for(i=0; i<info->sector_count; ++i) {
ulonge_addr = (i == s_end) ? b_end : info->start[i + 1];
if((end >= info->start[i]) && (addr < e_addr) &&
(info->protect[i] != 0) ) {
return(ERR_PROTECTED);
}
}
}
/*finally write data to flash */
for (info = info_first; info<= info_last && cnt>0; ++info) {
ulong len;
len =info->start[0] + info->size - addr;
if (len >cnt)
len =cnt;
if ((i =write_buff(info, (uchar *)src, addr, len)) != 0) {
return(i);
}
cnt -= len;
addr += len;
src += len;
}
return(ERR_OK);
#endif /* CONFIG_SPD823TS */
}
/*-----------------------------------------------------------------------
*/
从return可知
for (info = info_first; info <= info_last && cnt>0;++info) {
ulong len;
len =info->start[0] + info->size - addr;
if (len >cnt)
len =cnt;
if ((i =write_buff(info, (uchar *)src, addr, len)) != 0) {
return(i);
}
write_buff()函数的返回值应该为2,继续看write_buff()
在driver/mtd/cfi_flash.c中找到了该函数。
* 1 - write timeout
1277 * 2 - Flash not erased
1278 */
1279 int write_buff (flash_info_t * info,uchar * src, ulong addr, ulong cnt)
1280 {
1281 ulong wp;
1282 uchar *p;
1283 int aln;
1284 cfiword_t cword;
1285 int i, rc;
1286 #ifdefCONFIG_SYS_FLASH_USE_BUFFER_WRITE
1287 int buffered_size;
1288 #endif
1289 #ifdef CONFIG_FLASH_SHOW_PROGRESS
1290 int digit = CONFIG_FLASH_SHOW_PROGRESS;
1291 int scale = 0;
1292 int dots = 0;
1293
1294 /*
1295 * Suppress if there are fewer thanCONFIG_FLASH_SHOW_PROGRESS writ es.
1296 */
1297 if (cnt >= CONFIG_FLASH_SHOW_PROGRESS) {
1298 scale = (int)((cnt +CONFIG_FLASH_SHOW_PROGRESS - 1) /
1299 CONFIG_FLASH_SHOW_PROGRESS);
1300 }
1301 #endif
1302
1303 /* get lower aligned address */
1304 wp = (addr & ~(info->portwidth - 1));
1305
1306 /* handle unaligned start */
1307 if ((aln = addr - wp) != 0) {
1308 cword.l = 0;
1309 p = (uchar *)wp;
1310 for (i = 0; i < aln; ++i)
1311 flash_add_byte (info,&cword, flash_read8(p + i));
1312
1313 for (; (i <info->portwidth) && (cnt > 0); i++) {
1314 flash_add_byte (info,&cword, *src++);
1315 cnt--;
1316 }
1317 for (; (cnt == 0) &&(i < info->portwidth); ++i)
1318 flash_add_byte (info,&cword, flash_read8(p + i));
1319
1320 rc = flash_write_cfiword(info, wp, cword);
1321 printf("rc=%d cfi_flash.c(line:1321)\n",rc);
1322 if (rc != 0)
1323 return rc;
1324
1325 wp += i;
1326 FLASH_SHOW_PROGRESS(scale,dots, digit, i);
1327 }
1328
1329 /* handle the aligned part */
1330 #ifdefCONFIG_SYS_FLASH_USE_BUFFER_WRITE
1331 buffered_size = (info->portwidth / info->chipwidth);
1332 buffered_size *= info->buffer_size;
1333 while (cnt >= info->portwidth) {
1334 /* prohibit buffer write whenbuffer_size is 1 */
1335 if (info->buffer_size == 1){
1336 cword.l = 0;
1337 for (i = 0; i <info->portwidth; i++)
1338 flash_add_byte(info, &cword, *src++);
1339 if ((rc =flash_write_cfiword (info, wp, cword)) != 0)
1340 return rc;
1341 wp +=info->portwidth;
1342 cnt -=info->portwidth;
1343 continue;
1344 }
1345
1346 /* write buffer until nextbuffered_size aligned boundary * /
1347 i = buffered_size - (wp %buffered_size);
1348 if (i > cnt)
1349 i = cnt;
1350 if ((rc =flash_write_cfibuffer (info, wp, src, i)) != ERR_ OK)
1351 return rc;
1352 i -= i &(info->portwidth - 1);
1353 wp += i;
1354 src += i;
1355 cnt -= i;
1356 FLASH_SHOW_PROGRESS(scale,dots, digit, i);
1357 }
1358 #else
1359 while (cnt >= info->portwidth) {
1360 cword.l = 0;
1361 for (i = 0; i <info->portwidth; i++) {
1362 flash_add_byte (info,&cword, *src++);
1363 }
1364 if ((rc = flash_write_cfiword(info, wp, cword)) != 0)
1365 {
1366 printf("rc=%d cfi_flash.c(line:1366)\n",rc);
1367 return rc;
1368 }
1369 wp += info->portwidth;
1370 cnt -= info->portwidth;
1371 FLASH_SHOW_PROGRESS(scale,dots, digit, info->portwidth);
1372 }
1373 #endif /*CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
1374
1375 if (cnt == 0) {
1376 return (0);
1377 }
1378
1379 /*
1380 * handle unaligned tail bytes
1381 */
1382 cword.l = 0;
1383 p = (uchar *)wp;
1384 for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) {
1385 flash_add_byte (info, &cword,*src++);
1386 --cnt;
1387 }
1388 for (; i < info->portwidth; ++i)
1389 flash_add_byte (info,&cword, flash_read8(p + i));
1390
1391 rc= flash_write_cfiword (info, wp, cword);
1392 printf("rc=%d\ncfi_flash.c(line:1392)\n",rc);
1393 return rc;
1394 }
暂时不能找到rc=2,是在那一部分产生的,通过插入printf()函数查找。可以确定为1366行产生的。
1364 if ((rc = flash_write_cfiword(info, wp, cword)) != 0)
1365 {
1366 printf("rc=%d cfi_flash.c(line:1366)\n",rc);
1367 return rc;
1368 }
继续查看flash_write_cfiword()函数,driver/mtd/cfi_flash.c内779行,
static int flash_write_cfiword(flash_info_t * info, ulong dest,
cfiword_tcword)
{
void*dstaddr = (void *)dest;
intflag;
flash_sect_tsect = 0;
charsect_found = 0;
/* Check if Flash is(sufficiently) erased */
switch(info->portwidth) {
case FLASH_CFI_8BIT:
flag =((flash_read8(dstaddr) & cword.c) == cword.c);
break;
case FLASH_CFI_16BIT:
flag =((flash_read16(dstaddr) & cword.w) == cword.w);
break;
case FLASH_CFI_32BIT:
flag =((flash_read32(dstaddr) & cword.l) == cword.l);
break;
case FLASH_CFI_64BIT:
flag =((flash_read64(dstaddr) & cword.ll) == cword.ll);
break;
default:
flag = 0;
break;
}
if (!flag)
returnERR_NOT_ERASED;
/*Disable interrupts which might cause a timeout here */
flag= disable_interrupts ();
switch(info->vendor) {
caseCFI_CMDSET_INTEL_PROG_REGIONS:
caseCFI_CMDSET_INTEL_EXTENDED:
caseCFI_CMDSET_INTEL_STANDARD:
flash_write_cmd(info, 0, 0, FLASH_CMD_CLEAR_STATUS);
flash_write_cmd(info, 0, 0, FLASH_CMD_WRITE);
break;
caseCFI_CMDSET_AMD_EXTENDED:
caseCFI_CMDSET_AMD_STANDARD:
sect= find_sector(info, dest);
flash_unlock_seq(info, sect);
flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_WRITE);
sect_found= 1;
break;
#ifdef CONFIG_FLASH_CFI_LEGACY
caseCFI_CMDSET_AMD_LEGACY:
sect= find_sector(info, dest);
flash_unlock_seq(info, 0);
flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_WRITE);
sect_found= 1;
break;
#endif
}
switch(info->portwidth) {
caseFLASH_CFI_8BIT:
flash_write8(cword.c,dstaddr);
break;
caseFLASH_CFI_16BIT:
flash_write16(cword.w,dstaddr);
break;
caseFLASH_CFI_32BIT:
flash_write32(cword.l,dstaddr);
break;
caseFLASH_CFI_64BIT:
flash_write64(cword.ll,dstaddr);
break;
}
/*re-enable interrupts if necessary */
if(flag)
enable_interrupts();
if(!sect_found)
sect= find_sector (info, dest);
if(use_flash_status_poll(info))
returnflash_status_poll(info, &cword, dstaddr,
info->write_tout, "write");
else
returnflash_full_status_check(info, sect,
info->write_tout, "write");
}
重点注意
/* Check if Flash is(sufficiently) erased */
switch(info->portwidth) {
case FLASH_CFI_8BIT:
flag =((flash_read8(dstaddr) & cword.c) == cword.c);
break;
case FLASH_CFI_16BIT:
flag =((flash_read16(dstaddr) & cword.w) == cword.w);
break;
case FLASH_CFI_32BIT:
flag =((flash_read32(dstaddr) & cword.l) == cword.l);
break;
case FLASH_CFI_64BIT:
flag =((flash_read64(dstaddr) & cword.ll) == cword.ll);
break;
default:
flag = 0;
break;
}
if (!flag)
returnERR_NOT_ERASED;
这部分可以判断flag=0,info->portwidth的设置有问题,添加printf函数:
/* Check if Flash is (sufficiently) erased*/
printf("info->portwidth =%d cfi_flash.c(line:787)\n",info->portwidth);
switch (info->portwidth) {
caseFLASH_CFI_8BIT:
flag= ((flash_read8(dstaddr) & cword.c) == cword.c);
break;
caseFLASH_CFI_16BIT:
flag= ((flash_read16(dstaddr) & cword.w) == cword.w);
break;
caseFLASH_CFI_32BIT:
flag= ((flash_read32(dstaddr) & cword.l) == cword.l);
break;
caseFLASH_CFI_64BIT:
flag= ((flash_read64(dstaddr) & cword.ll) == cword.ll);
break;
default:
flag= 0;
break;
}
if(!flag)
returnERR_NOT_ERASED;
编译运行结果:
说明info->portwidth=2,与include/flash.h文件中设置一致
case FLASH_CFI_16BIT:
flag= ((flash_read16(dstaddr) & cword.w) == cword.w);
break;
说明flash_read16函数的返回值为2,继续查找,发现flash_read16分别在两个函数中定义:board/micronas/vct/ebi_nor_flash.c和board/freescale/p1022ds/diu.c两个文件。
查看两个文件夹发现没有.o文件生成,说明这个程序编译过程没有执行flash_read16函数,
查看board/micronas/vct/Makefile文件:
需要打开CONFIG_VCT_NOR的宏定义,于是在smdk2440.h中添加:
#define ONFIG_VCT_NOR
编译下载后,cp.b能正常执行。
---------------------
本文来自 baiyang139 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/baiyang139/article/details/79054415?utm_source=copy
s3c2440中U-boot移植时执行cp.b提示:Flash not Erased【转】的更多相关文章
- python:当文件中出现特定字符串时执行robot用例
#coding:utf-8 import os import datetime import time def execute_rpt_db_full_effe_cainiao_city(): fla ...
- Ubuntu Server 上在安装Nginx时执行./confgiure后提示:C compiler cc is not found
场景 Ubuntu Server 16.04 LTS上怎样安装下载安装Nginx并启动: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detai ...
- Entity Framework 6 Recipes 2nd Edition(12-1)译 -> 当SaveChanges( ) 被调用时执行你的代码
第12章定制EF 在本章的小节里,定制实体对象和EF处理的一些功能.这些小节将涵盖很多”幕后”的事情,能让你的代码更加统一解决一些事情,比如用一个业务规则中心统一地为实体执行验证. 本章开始的小节,将 ...
- spring boot 项目在启动时执行指定sql文件
参考博客: https://www.jianshu.com/p/88125f1cf91c 1. 启动时执行 当有在项目启动时先执行指定的sql语句的需求时,可以在resources文件夹下添加需要执行 ...
- 执行cp命令时提示cp: 略过目录
执行cp命令时提示cp: 略过目录 加入-r之后成功拷贝 在网上search了一下CP命令的用法: CP命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,同MSDOS下的copy命令一样, ...
- SpringMVC中如何在网站启动、结束时执行代码(详细,确保可用)
在一个网站启动.结束时,我们经常有些操作是需要执行的. 熟悉Asp.net的朋友,使用Global.asax很容易就搞定,在其中有Application_Start和Application_E ...
- Quartz.net 定时任务在IIS中未按时执行
IIS 垃圾回收机制下解决Quartz.net 的不执行问题 IIS中涉及了垃圾回收机制,quartz.net 在ASP.NET 项目中可以实现线程监控定时执行任务,但是在IIS7.5机一下版本中涉及 ...
- 让docker中的mysql启动时自动执行sql文件
本文提要 本文目的不仅仅是创建一个MySQL的镜像,而是在其基础上再实现启动过程中自动导入数据及数据库用户的权限设置,并且在新创建出来的容器里自动启动MySQL服务接受外部连接,主要是通过Docker ...
- C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation
C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation 后台添加以下方法:/// <summa ...
随机推荐
- 【Twitter接口】网站嵌入推特信息
提示:要 翻 墙 的,墙内的去玩新浪微博吧 方法 1 打开链接: https://publish.twitter.com ,输入链接.在下边选择时间表格式 复制这段代码.粘贴到你的网站,就可以使 ...
- android框架---->下沉文字Titanic的使用
Titanic is a simple illusion obtained by applying an animated translation on the TextView TextPaint ...
- 深刻理解 React (一) ——JSX和虚拟DOM
版权声明:本文由左明原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/155 来源:腾云阁 https://www.qclou ...
- Android 简单案例:可移动的View
CrossCompatibility.rar 1. VersionedGestureDetector.java import android.content.Context; import andro ...
- hdu4976 A simple greedy problem.
A simple greedy problem. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- 纯HTML自动刷新页面或重定向(http-equiv属性的refresh)
refresh 属性值 -- 刷新与跳转(重定向)页面 refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址 refresh示例一:5秒之后刷 ...
- OC开发_Storyboard——多线程、UIScrollView
一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...
- 详解Go语言中的屏蔽现象
在刚开始学习Go语言的过程中,难免会遇到一些问题,尤其是从其他语言转向Go开发的人员,面对语法及其内部实现的差异,在使用Go开发时也避免不了会踩"坑".本文主要针对Go设计中的屏蔽 ...
- Scikit Learn安装教程
Windows下安装scikit-learn 准备工作 Python (>= 2.6 or >= 3.3), Numpy (>= 1.6.1) Scipy (>= 0.9), ...
- log4j.properties配置详解与实例(转载)
转自:http://blog.sina.com.cn/s/blog_5ed94d710101go3u.html 最近使用log4j写log时候发现网上的写的都是千篇一律,写的好的嘛不全,写的全一点的嘛 ...