ssd202d-badblock-坏块检测

打印 上一主题 下一主题

主题 846|帖子 846|积分 2538

这边文章报告的是坏快检测功能
思路:
1.第一次烧录固件会实现跳坏块,但是后续使用会导致坏块的产生;
于是我在uboot情况变量添加了两个变量来控制坏快
lb_badnum = //坏块个数
lb_badoff = //坏块所在位置

2.第一次开时机根据lb_badnum是否存在判断,如果不存在则生存上面坏块信息,跳过坏块功能
3.第二次开机之后会获取情况变量lb_badnum和lb_badoff;
3.1.然后检测现实坏块数,举行对比,如果有新增坏块, 则判断新坏块产生的所在分区;
3.2.然后判断所在分区坏块大小加上固件大小后是否超出分别的分区空间;
3.3.执行对应的分区还原;


  1. commit 0ae66e0a3d1366aa90b4661b86203345f4ae02bd (HEAD -> master)
  2. Author: longmin <1938049502@qq.com>
  3. Date:   Tue Dec 10 16:44:44 2024 +0800
  4.     add cmd_lbbad.c support bad block detection function
  5. diff --git a/boot/common/Kconfig b/boot/common/Kconfig
  6. index 516a279af..11cb2c30a 100755
  7. --- a/boot/common/Kconfig
  8. +++ b/boot/common/Kconfig
  9. @@ -365,4 +365,10 @@ config XZ
  10. config MZ
  11.         bool "MZ"
  12. config SILENT_CONSOLE
  13. -       bool "SILENT_CONSOLE"
  14. \ No newline at end of file
  15. +       bool "SILENT_CONSOLE"
  16. +
  17. +config CMD_LBBAD
  18. +       bool "LBBAD"
  19. +       help
  20. +         This enables the command CONFIG_CMD_LBBAD power on detection of bad
  21. +         blocks.
  22. \ No newline at end of file
  23. diff --git a/boot/common/Makefile b/boot/common/Makefile
  24. index 85ba0bffd..0d54285f5 100755
  25. --- a/boot/common/Makefile
  26. +++ b/boot/common/Makefile
  27. @@ -344,4 +344,5 @@ endif
  28. obj-$(CONFIG_CMD_LBCHK) += cmd_lbchk.o
  29. obj-$(CONFIG_CMD_LBFDT) += cmd_lbfdt.o
  30. +obj-$(CONFIG_CMD_LBBAD) += cmd_lbbad.o
  31. obj-y += cmd_sar.o
  32. diff --git a/boot/common/autoboot.c b/boot/common/autoboot.c
  33. index 60f7b2291..927dcd18a 100755
  34. --- a/boot/common/autoboot.c
  35. +++ b/boot/common/autoboot.c
  36. @@ -585,6 +585,10 @@ void autoboot_command(const char *s)
  37. boot:
  38.         debug("### main_loop: bootcmd="%s"\n", s ? s : "<UNDEFINED>");
  39. +#if defined (CONFIG_CMD_LBBAD)
  40. +      extern int run_lbbadblock(void);
  41. +      run_lbbadblock();    /* bad block inspection */
  42. +#endif
  43. #if defined (CONFIG_CMD_LBCHK) && defined (LONBON_CHECK_RUNCMD)
  44.        extern int run_lbcheck(int cmd);
  45.        run_lbcheck(LONBON_CHECK_RUNCMD);
  46. diff --git a/boot/common/cmd_lbbad.c b/boot/common/cmd_lbbad.c
  47. new file mode 100755
  48. index 000000000..5bfa4890c
  49. --- /dev/null
  50. +++ b/boot/common/cmd_lbbad.c
  51. @@ -0,0 +1,503 @@
  52. +#include <common.h>^M
  53. +#include <command.h>^M
  54. +#include <malloc.h>^M
  55. +#include <nand.h>^M
  56. +#include <u-boot/md5.h>^M
  57. +#include <asm/io.h>^M
  58. +#include <spi.h>^M
  59. +#include <spi_flash.h>^M
  60. +#if (1 == CONFIG_LONBON_LED) || (1 == LONBON_CMD_CHECK_2BTN_FOR_RESTORE)^M
  61. +#include "../drivers/mstar/gpio/infinity2m/gpio.h"^M
  62. +#include "../drivers/mstar/gpio/drvGPIO.h"^M
  63. +#endif^M
  64. +^M
  65. +//#define LB_DEBUG^M
  66. +^M
  67. +#ifdef LB_DEBUG^M
  68. +#define LBCHK_DEBUG(msg...)            printf(msg)^M
  69. +#else^M
  70. +#define LBCHK_DEBUG(msg...)            do{}while(0)^M
  71. +#endif^M
  72. +^M
  73. +typedef int BOOL;^M
  74. +^M
  75. +#ifndef FALSE^M
  76. +#define FALSE  0^M
  77. +#endif^M
  78. +^M
  79. +#ifndef TRUE^M
  80. +#define TRUE   1^M
  81. +#endif^M
  82. +^M
  83. +#ifdef CONFIG_YAFFS2^M
  84. +extern void cmd_yaffs_devconfig(char *mp, int flash_dev, int start_block, int end_block);^M
  85. +extern void cmd_yaffs_mount(char *mp);^M
  86. +extern void cmd_yaffs_umount(char *mp);^M
  87. +extern void cmd_yaffs_mread_file(char *fn, char *addr);^M
  88. +#endif^M
  89. +^M
  90. +#define BADBLOCK_MAX 200^M
  91. +^M
  92. +extern int lb_nand_get_badblock_number(ulong *badblock_list);^M
  93. +extern int lbcmd_get_imagename_by_cmd(char* imgname, unsigned char cmd);^M
  94. +extern int lonbon_get_partitions(const char *part_name, uint *part_offset, uint *part_size);^M
  95. +extern int lonbon_get_partitions_name(uint *off, char *part_name, uint *part_offset, uint *part_size);^M
  96. +extern int lb_nand_flash_partition_baseAddr(const char *part_name, uint *part_offset, uint *part_size);^M
  97. +^M
  98. +typedef struct {^M
  99. +       int uboot;^M
  100. +       int kernel;^M
  101. +       int rootfs;^M
  102. +       int backup;^M
  103. +       int ro;^M
  104. +       int rw;^M
  105. +       int ipl;^M
  106. +       int ipl_cust;^M
  107. +       int logo;^M
  108. +       int factory;^M
  109. +       int lbcmd;^M
  110. +       int lbflash;^M
  111. +       int lbcfg;^M
  112. +       int env;^M
  113. +       int key_cust;^M
  114. +} lb_bad_partition_t;^M
  115. +^M
  116. +int lonbon_set_badnum(int number)^M
  117. +{^M
  118. +       unsigned char  badnum[2];^M
  119. +    if(number >= 0) {^M
  120. +               memset(badnum,0,2);^M
  121. +               badnum[0] = number + 0x30;^M
  122. +               setenv("lb_badnum", (const char *)badnum);^M
  123. +               run_command("saveenv", 0);^M
  124. +               return 0;^M
  125. +    }^M
  126. +       return -1;^M
  127. +}^M
  128. +^M
  129. +int lonbon_get_badnum(void)^M
  130. +{^M
  131. +       char * lb_badnum = getenv("lb_badnum");^M
  132. +       unsigned char  badnum[2];^M
  133. +^M
  134. +    if(lb_badnum) {^M
  135. +               badnum[0] = *lb_badnum - 0x30;^M
  136. +               printf("old bad_block number= %d\n",badnum[0]);^M
  137. +               return badnum[0];^M
  138. +    }else{^M
  139. +               printf("%s lb_badnum=null\n", __func__);^M
  140. +               return -1;^M
  141. +       }^M
  142. +       return 0;^M
  143. +}^M
  144. +^M
  145. +int lonbon_number_exist(int all_number, ulong *badblock_list, ulong number){^M
  146. +       int i;^M
  147. +       for(i=0; i < all_number; i++)^M
  148. +       {^M
  149. +               if(*(badblock_list+i) == number)^M
  150. +               {^M
  151. +                       return i;^M
  152. +               }^M
  153. +       }^M
  154. +       return -1;^M
  155. +}^M
  156. +^M
  157. +int lonbon_new_badblock(int all_number, ulong *badblock_list, int env_number, ulong *old_badblock_list,ulong *add_badblock_list)^M
  158. +{^M
  159. +       int i, j, k = 0;^M
  160. +       bool flag;^M
  161. +       for (i=0; i < all_number; i++){^M
  162. +               flag = false;^M
  163. +               for (j=0; j < all_number; j++){^M
  164. +               if( badblock_list[i] == old_badblock_list[j] )^M
  165. +               flag = true;^M
  166. +               }^M
  167. +^M
  168. +               if(flag == false){^M
  169. +               *(add_badblock_list + k) = badblock_list[i];^M
  170. +               k++;^M
  171. +               }^M
  172. +^M
  173. +       }^M
  174. +^M
  175. +       return 0;^M
  176. +}^M
  177. +^M
  178. +^M
  179. +int lonbon_get_bad_offset(int all_number, ulong *badblock_list, int number)^M
  180. +{^M
  181. +       int i;^M
  182. +       char *lb_badoff = getenv("lb_badoff");^M
  183. +       char badb_offset[1024]= {0};^M
  184. +       ulong old_badb_list[all_number];^M
  185. +       ulong *old_badblock_list = &old_badb_list[0];^M
  186. +       ulong add_badb_list[all_number];^M
  187. +       ulong *add_badblock_list = &add_badb_list[0];^M
  188. +       char *lb_bad_off;^M
  189. +       ulong num;^M
  190. +^M
  191. +       if(all_number == 0){^M
  192. +       printf("%s not badblock_list\n", __func__);^M
  193. +       return 0;^M
  194. +       }^M
  195. +^M
  196. +       if(lb_badoff){^M
  197. +               strcpy(badb_offset,lb_badoff);^M
  198. +               lb_bad_off = strtok(badb_offset, "-");^M
  199. +               num = simple_strtol(lb_bad_off, NULL, 16);^M
  200. +               old_badb_list[0] = num;^M
  201. +               for(i=1; i < all_number;i++ ){^M
  202. +               lb_bad_off = strtok(NULL ,"-");^M
  203. +               num = simple_strtol(lb_bad_off, NULL, 16);^M
  204. +               old_badb_list[i] = num;^M
  205. +               }^M
  206. +       }^M
  207. +       /* determine the partition location of the new bad block */^M
  208. +       lonbon_new_badblock(all_number, badblock_list, number, old_badblock_list, add_badblock_list);^M
  209. +       for(i=0; i < all_number; i++){^M
  210. +       *(badblock_list + i) = 0;^M
  211. +       }^M
  212. +       for(i=0; i<number;i++){^M
  213. +       *(badblock_list + i) = add_badb_list[i];^M
  214. +       }^M
  215. +^M
  216. +       return 1;^M
  217. +}^M
  218. +^M
  219. +int lonbon_set_bad_offset(int number, ulong *badblock_list)^M
  220. +{^M
  221. +       int i;^M
  222. +       char commandline[10] = {0};^M
  223. +       char badb_addr[1024]= {'0'};^M
  224. +       if(number >= 0) {^M
  225. +               if(number > 0) {^M
  226. +                       for(i=0;i<number;i++){^M
  227. +                       sprintf(commandline,"%08lx-", *(badblock_list+i));^M
  228. +                       strcat(badb_addr,commandline);^M
  229. +                       }^M
  230. +               }^M
  231. +               printf("lonbon_set_bad_offset badblock_list:%s\n",badb_addr);^M
  232. +               setenv("lb_badoff", (const char *)badb_addr);^M
  233. +               run_command("saveenv", 0);^M
  234. +               return number;^M
  235. +       }^M
  236. +       return 0;^M
  237. +}^M
  238. +^M
  239. +int lonbon_set_partitions(lb_bad_partition_t *lb_part, char *part_name)^M
  240. +{^M
  241. +       //printf("%s %s \n",__func__,part_name);^M
  242. +       if(strcmp(part_name, "UBOOT0") == 0||strcmp(part_name, "UBOOT1") == 0){^M
  243. +       lb_part->uboot += 1;^M
  244. +       }else if(strcmp(part_name, "rootfs") == 0){^M
  245. +       lb_part->rootfs  += 1;^M
  246. +       }else if(strcmp(part_name, "KERNEL") == 0||strcmp(part_name, "RECOVERY") == 0){^M
  247. +       lb_part->kernel  += 1;^M
  248. +       }else if(strcmp(part_name, "backup") == 0){^M
  249. +       lb_part->backup  += 1;^M
  250. +       }else if(strcmp(part_name, "ro") == 0){^M
  251. +       lb_part->ro  += 1;^M
  252. +       }else if(strcmp(part_name, "rw") == 0){^M
  253. +       lb_part->rw  += 1;^M
  254. +       }else if(strcmp(part_name, "IPL0") == 0||strcmp(part_name, "IPL1") == 0){^M
  255. +       lb_part->ipl  += 1;^M
  256. +       }else if(strcmp(part_name, "IPL_CUST0") == 0||strcmp(part_name, "IPL_CUST1") == 0){^M
  257. +       lb_part->ipl_cust  += 1;^M
  258. +       }else if(strcmp(part_name, "LOGO") == 0){^M
  259. +       lb_part->logo  += 1;^M
  260. +       }else if(strcmp(part_name, "factory") == 0){^M
  261. +       lb_part->factory  += 1;^M
  262. +       }else if(strcmp(part_name, "lbcmd") == 0){^M
  263. +       lb_part->lbcmd  += 1;;^M
  264. +       }else if(strcmp(part_name, "lbflash") == 0||strcmp(part_name, "lbflash2") == 0){^M
  265. +       lb_part->lbflash  += 1;^M
  266. +       }else if(strcmp(part_name, "lbcfg") == 0||strcmp(part_name, "lbcfg2") == 0){^M
  267. +       lb_part->lbcfg  += 1;^M
  268. +       }else if(strcmp(part_name, "ENV") == 0||strcmp(part_name, "ENV1") == 0){^M
  269. +       lb_part->env  += 1;^M
  270. +       }else if(strcmp(part_name, "KEY_CUST") == 0){^M
  271. +       lb_part->key_cust  += 1;^M
  272. +       }else{^M
  273. +       return -1;^M
  274. +       }^M
  275. +^M
  276. +       return 0;^M
  277. +}^M
  278. +^M
  279. +void lonbon_printf_bad(int num){^M
  280. +^M
  281. +       switch (num)^M
  282. +       {^M
  283. +               case 0: printf("\n");^M
  284. +                               printf("##############################################################################\n");^M
  285. +                               printf("##############################################################################\n");^M
  286. +                               printf("############################ bad block list:##################################\n");^M
  287. +                               break;^M
  288. +               case 1: printf("\nstart all bad block list:\n");^M
  289. +                               break;^M
  290. +               case 2: printf("\n");^M
  291. +                               printf("add bad block:\n");^M
  292. +                               printf("\n");^M
  293. +                               break;^M
  294. +               case 3: printf("\n");^M
  295. +                               printf("##############################################################################\n");^M
  296. +                               printf("##############################################################################\n");^M
  297. +                               printf("\n");^M
  298. +                               break;^M
  299. +       }^M
  300. +^M
  301. +}^M
  302. +^M
  303. +uint lonbon_get_pattition_firmware_size(char *fileName){^M
  304. +               char *mntpoint = "/factory";^M
  305. +               uint part_offset;^M
  306. +               uint part_size;^M
  307. +               int start_block;^M
  308. +               int end_block;^M
  309. +^M
  310. +               char filename[100] = {0};^M
  311. +               unsigned long addr= 0x21000000;^M
  312. +               lb_nand_flash_partition_baseAddr("factory", &part_offset, &part_size);^M
  313. +               if(!part_offset || !part_size) {^M
  314. +                       printf("#ERROR: No factory partition is found\n");^M
  315. +                       return -1;^M
  316. +               }^M
  317. +^M
  318. +               start_block = part_offset/(128*1024); /* Nand flash block size is 128 KB */^M
  319. +               end_block = (part_offset+part_size)/(128*1024)-1;^M
  320. +^M
  321. +               cmd_yaffs_devconfig(mntpoint,0,start_block,end_block);^M
  322. +               cmd_yaffs_mount(mntpoint);^M
  323. +               sprintf(filename, "%s/%s", mntpoint, fileName);^M
  324. +               cmd_yaffs_mread_file(filename, (char *)addr);^M
  325. +               char *str_env = getenv("filesize");^M
  326. +               ulong filesize = simple_strtoul(str_env, NULL, 16);^M
  327. +               size_t blocksize = nand_info[0].erasesize;^M
  328. +               ulong wsize=(filesize/blocksize+1)*blocksize;^M
  329. +               cmd_yaffs_umount(mntpoint);^M
  330. +               printf("longbon  filename=%s  str_env=%s filesize=%lx wsize=%lx \n",filename,str_env,filesize,wsize);^M
  331. +       return wsize;^M
  332. +^M
  333. +}^M
  334. +^M
  335. +int lonbon_pattition_firmware_size(unsigned char cmd, char *part_name, int bad_number)^M
  336. +{^M
  337. +       char firmware_name[32] = {0};^M
  338. +       char *firmware_part_name = &firmware_name[0];^M
  339. +       uint part_offset, part_size;^M
  340. +       ulong firmware_size, firmware_size_bad;^M
  341. +       size_t blocksize = nand_info[0].erasesize;^M
  342. +^M
  343. +       /* get firmware name */^M
  344. +       lbcmd_get_imagename_by_cmd(firmware_part_name, cmd);^M
  345. +       /* get firmware size */^M
  346. +       firmware_size = lonbon_get_pattition_firmware_size(firmware_part_name);^M
  347. +       /* the size after adding the bad block */^M
  348. +       firmware_size_bad = firmware_size +( blocksize * bad_number);^M
  349. +       /* get partitions total size */^M
  350. +       lonbon_get_partitions(part_name, &part_offset, &part_size);^M
  351. +^M
  352. +       /* partitions total size > firmware size add bad block size */^M
  353. +       if( part_size > firmware_size_bad)^M
  354. +       {^M
  355. +       printf("\nlonbon %s is OK! part_size=%x firmware_size_bad=%lx \n",__func__,part_size,firmware_size_bad);^M
  356. +       return 1;^M
  357. +       }^M
  358. +       else {^M
  359. +       printf("\nlonbon %s error!! part_size=%x firmware_size_bad=%lx \n",__func__,part_size,firmware_size_bad);^M
  360. +       return -1;^M
  361. +       }^M
  362. +       return 0;^M
  363. +}^M
  364. +^M
  365. +void lonbon_printf_bad_block(lb_bad_partition_t *lb_bad_partition, int number, ulong *bad_list, int new_number, ulong *new_bad_list){^M
  366. +^M
  367. +       int i, ret, flags = 0;^M
  368. +       char write[20] = {' '};^M
  369. +       char *write_t = &write[0];^M
  370. +       char part_name[10] = {'0'};^M
  371. +       char *part_name_t = &part_name[0];^M
  372. +       ulong *badblock_list = bad_list;^M
  373. +       char commandline[30] = {0};^M
  374. +       uint lbflash_offset = 0,lbflash_size = 0;^M
  375. +^M
  376. +       if(new_number > 0){^M
  377. +       lonbon_printf_bad(1);^M
  378. +       }^M
  379. +       for(i=0; i< number; i++){^M
  380. +               memset(part_name,0,sizeof(part_name));^M
  381. +               lonbon_get_partitions_name((uint *) *(badblock_list+i), part_name_t, &lbflash_offset, &lbflash_size);^M
  382. +               printf("bad[%d]=0x%08lx name=%s off=0x%08x size=0x%08x end=0x%08x \n",^M
  383. +                       i, *(badblock_list+i), part_name_t, lbflash_offset, lbflash_size ,(lbflash_offset +lbflash_size -1) );^M
  384. +       }^M
  385. +       if(new_number > 0){^M
  386. +       lonbon_printf_bad(2);^M
  387. +               for(i=0; i< new_number; i++){^M
  388. +               printf(" 0x%08lx \n", *(new_bad_list + i));^M
  389. +               }^M
  390. +       }^M
  391. +       if(lb_bad_partition->factory > 0){^M
  392. +       printf("\n warn factory partition are bad blocks !!!\n\n");^M
  393. +       }^M
  394. +       if(lb_bad_partition->uboot > 0){^M
  395. +       printf("\n warn uboot partition are bad blocks !!!\n\n");^M
  396. +       ret = lonbon_pattition_firmware_size(1,"uboot",lb_bad_partition->uboot);^M
  397. +               if(ret > 0){^M
  398. +               strcat(write,"1 ");^M
  399. +               flags++;^M
  400. +               }else{^M
  401. +               printf("\n%s error!!!uboot insufficient partition space !!!\n",__func__ );^M
  402. +               }^M
  403. +       }^M
  404. +       if(lb_bad_partition->kernel > 0){^M
  405. +       printf("\n warn kernel partition are bad blocks !!!\n\n");^M
  406. +       ret = lonbon_pattition_firmware_size(2,"kernel",lb_bad_partition->kernel);^M
  407. +               if(ret > 0){^M
  408. +               strcat(write,"2 ");^M
  409. +               flags++;^M
  410. +               }else{^M
  411. +               printf("\n%s error!!!kernel insufficient partition space !!!\n",__func__ );^M
  412. +               }^M
  413. +       }^M
  414. +       if(lb_bad_partition->rootfs > 0){^M
  415. +       printf("\n warn rootfs partition are bad blocks !!!\n\n");^M
  416. +       ret = lonbon_pattition_firmware_size(3,"rootfs",lb_bad_partition->rootfs);^M
  417. +               if(ret > 0){^M
  418. +               strcat(write,"3 ");^M
  419. +               flags++;^M
  420. +               }else{^M
  421. +               printf("\n%s error!!!rootfs insufficient partition space !!!\n",__func__ );^M
  422. +               }^M
  423. +       }^M
  424. +       if(lb_bad_partition->backup > 0){^M
  425. +       printf("\n warn backup partition are bad blocks !!!\n\n");^M
  426. +       }^M
  427. +       if(lb_bad_partition->ro > 0){^M
  428. +       printf("\n warn ro partition are bad blocks !!!\n\n");^M
  429. +       }^M
  430. +       if(lb_bad_partition->rw > 0){^M
  431. +       printf("\n warn rw partition are bad blocks !!!\n\n");^M
  432. +       }^M
  433. +       if(lb_bad_partition->ipl > 0){^M
  434. +       printf("\n warn ipl partition are bad blocks !!!\n\n");^M
  435. +       ret = lonbon_pattition_firmware_size(6,"ipl",lb_bad_partition->ipl);^M
  436. +               if(ret > 0){^M
  437. +               strcat(write,"6 ");^M
  438. +               flags++;^M
  439. +               }else{^M
  440. +               printf("\n%s error!!!ipl insufficient partition space !!!\n",__func__ );^M
  441. +               }^M
  442. +       }^M
  443. +       if(lb_bad_partition->ipl_cust > 0){^M
  444. +       printf("\n warn ipl_cust partition are bad blocks !!!\n\n");^M
  445. +       ret = lonbon_pattition_firmware_size(7,"ipl",lb_bad_partition->ipl_cust);^M
  446. +               if(ret > 0){^M
  447. +               strcat(write,"7 ");^M
  448. +               flags++;^M
  449. +               }else{^M
  450. +               printf("\n%s error!!!ipl_cust insufficient partition space !!!\n",__func__ );^M
  451. +               }^M
  452. +       }^M
  453. +       if(lb_bad_partition->logo > 0){^M
  454. +       printf("\n warn logo partition are bad blocks !!!\n\n");^M
  455. +       ret = lonbon_pattition_firmware_size(8,"logo",lb_bad_partition->logo);^M
  456. +               if(ret > 0){^M
  457. +               //run_command("lbupgrade write 8", 0);^M
  458. +               strcat(write,"8 ");^M
  459. +               flags++;^M
  460. +               }else{^M
  461. +               printf("\n%s error!!!logo insufficient partition space !!!\n",__func__ );^M
  462. +               }^M
  463. +       }^M
  464. +^M
  465. +       if (flags > 0){^M
  466. +       sprintf(commandline,"lbupgrade write %s", write_t);^M
  467. +       printf("\nlonbon %s run_command: %s !!!\n", __func__ , commandline);^M
  468. +       run_command(commandline, 0);^M
  469. +       }^M
  470. +^M
  471. +       lonbon_printf_bad(3);^M
  472. +^M
  473. +}^M
  474. +^M
  475. +/* bad block inspection */^M
  476. +int run_lbbadblock(void) ^M
  477. +{^M
  478. +       lb_bad_partition_t lb_bad_partition ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};^M
  479. +       lb_bad_partition_t *lb_bad_partition_r = &lb_bad_partition;^M
  480. +       int ret, i;^M
  481. +       char part_name[10] = {'0'};^M
  482. +       char *part_name_t = &part_name[0];^M
  483. +       uint lbflash_offset = 0,lbflash_size = 0;^M
  484. +       ulong badblock_list[BADBLOCK_MAX];^M
  485. +       ulong *list_badblock = &badblock_list[0];^M
  486. +       int badblock_number , lb_badnum;^M
  487. +       bool new_badblock = false;^M
  488. +^M
  489. +       lonbon_printf_bad(0);^M
  490. +       memset(badblock_list,0,sizeof(badblock_list));^M
  491. +       badblock_number = lb_nand_get_badblock_number(list_badblock);^M
  492. +       ulong bad_list[badblock_number];^M
  493. +       ulong *bad_list_t = &bad_list[0];^M
  494. +^M
  495. +       for( i = 0; i < badblock_number; i++){^M
  496. +       bad_list[i] = badblock_list[i];^M
  497. +       }^M
  498. +^M
  499. +       if(badblock_number < 0){^M
  500. +               printf("error! get badblock number failed! :%d\n",badblock_number);^M
  501. +               return badblock_number;^M
  502. +       }else{^M
  503. +               printf("bad badblock  number: %d\n",badblock_number);^M
  504. +       }^M
  505. +^M
  506. +       lb_badnum = lonbon_get_badnum();/* get lb_badnum */^M
  507. +       if(lb_badnum < 0){ /* the first burning is not processed */^M
  508. +^M
  509. +               ret = lonbon_set_badnum(badblock_number);/* directly save the number of burned blocks */^M
  510. +               if(ret < 0){^M
  511. +               printf("error %s badblock_number=null\n",__func__);^M
  512. +               }^M
  513. +               printf("lonbon %s init badblock\n",__func__);^M
  514. +               ret = lonbon_set_bad_offset(badblock_number, list_badblock);/* save bad block address*/^M
  515. +               lonbon_printf_bad(3);^M
  516. +               return 0;^M
  517. +^M
  518. +       }else{   /* after the second boot, go here */^M
  519. +               if(badblock_number == lb_badnum){ /* equal means there are no bad blocks */^M
  520. +                       printf("lonbon %s not new badblock\n",__func__);^M
  521. +^M
  522. +               }else{                            /* unequal means there are bad blocks */^M
  523. +                       printf("%s new badblock number= %d\n",__func__, badblock_number - lb_badnum);^M
  524. +                       ret = lonbon_set_badnum(badblock_number);^M
  525. +                       if(ret < 0){^M
  526. +                       printf("error %s badblock_number=null\n",__func__);^M
  527. +                       }else{^M
  528. +                       new_badblock = true; /* mark the newly added bad block symbol */^M
  529. +                       }^M
  530. +               }^M
  531. +       }^M
  532. +^M
  533. +       if(new_badblock == true ){/* there are new bad blocks added */^M
  534. +               /* Get env bad block address */^M
  535. +               ret = lonbon_get_bad_offset(badblock_number, list_badblock ,badblock_number - lb_badnum);^M
  536. +^M
  537. +               for(i=0; i< badblock_number - lb_badnum; i++){^M
  538. +                       memset(part_name,0,sizeof(part_name));^M
  539. +                       lonbon_get_partitions_name((uint *) badblock_list[i], part_name_t, &lbflash_offset, &lbflash_size);^M
  540. +                       ret = lonbon_set_partitions(lb_bad_partition_r, part_name_t);^M
  541. +               }^M
  542. +               printf("%s new_badblock=true\n",__func__);^M
  543. +^M
  544. +       }^M
  545. +^M
  546. +       lonbon_printf_bad_block(lb_bad_partition_r, badblock_number, bad_list_t, badblock_number - lb_badnum, list_badblock);^M
  547. +^M
  548. +       if(new_badblock == true){/* if a new bad block is added, restart and enter restore mode */^M
  549. +               ret = lonbon_set_bad_offset(badblock_number, bad_list_t);/* save bad block address */^M
  550. +               new_badblock = false;^M
  551. +               run_command("reset", 0);^M
  552. +       }^M
  553. +       return 0;^M
  554. +}^M
  555. diff --git a/boot/common/cmd_mtdparts.c b/boot/common/cmd_mtdparts.c
  556. index f6940a6f2..172750152 100755
  557. --- a/boot/common/cmd_mtdparts.c
  558. +++ b/boot/common/cmd_mtdparts.c
  559. @@ -1331,6 +1331,63 @@ int lonbon_get_partitions(const char *part_name, uint *part_offset, uint *part_s
  560.      }
  561.      return -1;
  562. }
  563. +
  564. +int lonbon_strcpy_name(char *part_name,char *name)
  565. +{
  566. +       char str[10];
  567. +       int len,i;
  568. +               strcpy(str,name);
  569. +               len = strlen(str);
  570. +               for(i=0; i < len; i++){
  571. +                       *(part_name+i) = str[i];
  572. +               }
  573. +       return 0;
  574. +}
  575. +/**
  576. +* obtain the partition name of the address by passing it through.
  577. +*/
  578. +
  579. +int lonbon_get_partitions_name(uint *off, char *part_name, uint *part_offset, uint *part_size)
  580. +{
  581. +       struct list_head *dentry, *pentry;
  582. +       struct part_info *part;
  583. +       struct mtd_device *dev;
  584. +       int part_num;
  585. +       uint *part_offset_closure;
  586. +
  587. +       if (!part_name) {
  588. +               printf("the part name is empty\n");
  589. +               //return -1;
  590. +       }
  591. +
  592. +       if (list_empty(&devices)) {
  593. +               printf("the partitions list is empty\n");
  594. +               return -1;
  595. +       }
  596. +
  597. +       if (mtdparts_init() != 0)
  598. +               return -1;
  599. +
  600. +       list_for_each(dentry, &devices) {
  601. +               dev = list_entry(dentry, struct mtd_device, link);
  602. +               part_num = 0;
  603. +               list_for_each(pentry, &dev->parts) {
  604. +                       part = list_entry(pentry, struct part_info, link);
  605. +                       //printf("%2d:%s 0x%08llx 0x%08llx\n",part_num, part->name, part->size,part->offset);
  606. +                       part_offset_closure = part->offset + part->size;
  607. +                       if(part_offset_closure > off){
  608. +
  609. +                                       lonbon_strcpy_name(part_name,part->name);
  610. +                                       *part_offset = part->offset;
  611. +                                       *part_size   = part->size;
  612. +                                       return 0;
  613. +                               }
  614. +                               part_num++;
  615. +               }
  616. +       }
  617. +       return -1;
  618. +}
  619. +
  620. #endif
  621. /**
  622.   * Format and print out a partition list for each device from global device
  623. diff --git a/boot/common/cmd_nand.c b/boot/common/cmd_nand.c
  624. index 64b0bd26b..022696de3 100755
  625. --- a/boot/common/cmd_nand.c
  626. +++ b/boot/common/cmd_nand.c
  627. @@ -718,10 +718,14 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  628.         nand = &nand_info[dev];
  629.         if (strcmp(cmd, "bad") == 0) {
  630. -               printf("\nDevice %d bad blocks:\n", dev);
  631. +               int j = 0;
  632. +               //printf("\nDevice %d bad blocks:\n", dev);
  633.                 for (off = 0; off < nand->size; off += nand->erasesize)
  634. -                       if (nand_block_isbad(nand, off))
  635. +                       if (nand_block_isbad(nand, off)){
  636.                                 printf("  %08llx\n", (unsigned long long)off);
  637. +                               j++;
  638. +                       }
  639. +               printf("bad number %d blocks:\n", j);
  640.                 return 0;
  641.         }
  642. @@ -1466,6 +1470,31 @@ static int lb_nand_erase(uint start_addr, uint part_size, uint length)
  643.      return 0;
  644. }
  645. +#define BADBLOCK_MAX 200
  646. +int lb_nand_get_badblock_number(ulong *badblock_list)
  647. +{
  648. +       int j = 0;
  649. +       ulong off,badblock_addr[BADBLOCK_MAX];
  650. +       nand_info_t *nand = &nand_info[0];
  651. +       char commandline[16];
  652. +       char badb_addr[1024];
  653. +       memset(badblock_addr,0,sizeof(badblock_addr));
  654. +       memset(commandline,0,sizeof(commandline));
  655. +       memset(badb_addr,0,sizeof(badb_addr));
  656. +       printf("\n");
  657. +       for (off = 0; off < nand->size; off += nand->erasesize)
  658. +               if (nand_block_isbad(nand, off)){
  659. +                       //printf("lonbon bad blocks  %08llx\n", (unsigned long long)off);
  660. +                       badblock_addr[j] = off;
  661. +                       j++;
  662. +               }
  663. +       printf("\n");
  664. +       for(int i = 0; i < j; i++){
  665. +       //printf("\nlonbon %08lx\n", badblock_addr[i]);
  666. +       badblock_list[i] = badblock_addr[i];
  667. +       }
  668. +       return j;
  669. +}
  670. int lb_nand_flash_partition_baseAddr(const char *part_name, uint *part_offset, uint *part_size)
  671. {
  672. @@ -1492,7 +1521,7 @@ int lb_nand_flash_partition_read(const char *part_name,char* buff,const int leng
  673.          return -1;
  674.         }
  675. -    ret=lb_nand_read(lbflash_offset,lbflash_size, length>lbflash_size?lbflash_size:len,(void *) buff);
  676. +    ret = lb_nand_read(lbflash_offset,lbflash_size, length>lbflash_size?lbflash_size:len,(void *) buff);
  677.      //_print_hex_string(buff,length); //TEST ONLY
  678.      return ret;
  679. }
  680. diff --git a/boot/include/configs/infinity2m.h b/boot/include/configs/infinity2m.h
  681. index c5d5d8ea1..19a44747b 100755
  682. --- a/boot/include/configs/infinity2m.h
  683. +++ b/boot/include/configs/infinity2m.h
  684. @@ -39,6 +39,7 @@
  685. #define LONBONVOIP
  686. #ifdef LONBONVOIP
  687. #define CONFIG_CMD_LBCHK
  688. +#define CONFIG_CMD_LBBAD
  689. #define CONFIG_LB_MD5
  690. #define CONFIG_IDENT_STRING     " LonBon Technology "
  691. #define LONBONVOIP_REALM       "voip.lonbon.com"
复制代码
========================================================================
第一次开机

 第二次开机

第N次开机后产生新坏块






免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

忿忿的泥巴坨

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表