ssd202d-badblock-坏块检测

这边文章讲述的是坏快检测功能

思路:

1.第一次烧录固件会实现跳坏块,但是后续使用会导致坏块的产生;

于是我在uboot环境变量添加了两个变量来控制坏快

lb_badnum = //坏块个数

lb_badoff = //坏块所在位置

2.第一次开机会根据lb_badnum是否存在判断,如果不存在则保存上面坏块信息,跳过坏块功能

3.第二次开机之后会获取环境变量lb_badnum和lb_badoff;

3.1.然后检测实际坏块数,进行对比,如果有新增坏块, 则判断新坏块产生的所在分区;

3.2.然后判断所在分区坏块大小加上固件大小后是否超出划分的分区空间;

3.3.执行对应的分区还原;

commit 0ae66e0a3d1366aa90b4661b86203345f4ae02bd (HEAD -> master)
Author: longmin <1938049502@qq.com>
Date:   Tue Dec 10 16:44:44 2024 +0800add cmd_lbbad.c support bad block detection functiondiff --git a/boot/common/Kconfig b/boot/common/Kconfig
index 516a279af..11cb2c30a 100755
--- a/boot/common/Kconfig
+++ b/boot/common/Kconfig
@@ -365,4 +365,10 @@ config XZconfig MZbool "MZ"config SILENT_CONSOLE
-       bool "SILENT_CONSOLE"
\ No newline at end of file
+       bool "SILENT_CONSOLE"
+
+config CMD_LBBAD
+       bool "LBBAD"
+       help
+         This enables the command CONFIG_CMD_LBBAD power on detection of bad
+         blocks.
\ No newline at end of file
diff --git a/boot/common/Makefile b/boot/common/Makefile
index 85ba0bffd..0d54285f5 100755
--- a/boot/common/Makefile
+++ b/boot/common/Makefile
@@ -344,4 +344,5 @@ endifobj-$(CONFIG_CMD_LBCHK) += cmd_lbchk.oobj-$(CONFIG_CMD_LBFDT) += cmd_lbfdt.o
+obj-$(CONFIG_CMD_LBBAD) += cmd_lbbad.oobj-y += cmd_sar.o
diff --git a/boot/common/autoboot.c b/boot/common/autoboot.c
index 60f7b2291..927dcd18a 100755
--- a/boot/common/autoboot.c
+++ b/boot/common/autoboot.c
@@ -585,6 +585,10 @@ void autoboot_command(const char *s)boot:debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
+#if defined (CONFIG_CMD_LBBAD)
+      extern int run_lbbadblock(void);
+      run_lbbadblock();    /* bad block inspection */
+#endif#if defined (CONFIG_CMD_LBCHK) && defined (LONBON_CHECK_RUNCMD)extern int run_lbcheck(int cmd);run_lbcheck(LONBON_CHECK_RUNCMD);
diff --git a/boot/common/cmd_lbbad.c b/boot/common/cmd_lbbad.c
new file mode 100755
index 000000000..5bfa4890c
--- /dev/null
+++ b/boot/common/cmd_lbbad.c
@@ -0,0 +1,503 @@
+#include <common.h>^M
+#include <command.h>^M
+#include <malloc.h>^M
+#include <nand.h>^M
+#include <u-boot/md5.h>^M
+#include <asm/io.h>^M
+#include <spi.h>^M
+#include <spi_flash.h>^M
+#if (1 == CONFIG_LONBON_LED) || (1 == LONBON_CMD_CHECK_2BTN_FOR_RESTORE)^M
+#include "../drivers/mstar/gpio/infinity2m/gpio.h"^M
+#include "../drivers/mstar/gpio/drvGPIO.h"^M
+#endif^M
+^M
+//#define LB_DEBUG^M
+^M
+#ifdef LB_DEBUG^M
+#define LBCHK_DEBUG(msg...)            printf(msg)^M
+#else^M
+#define LBCHK_DEBUG(msg...)            do{}while(0)^M
+#endif^M
+^M
+typedef int BOOL;^M
+^M
+#ifndef FALSE^M
+#define FALSE  0^M
+#endif^M
+^M
+#ifndef TRUE^M
+#define TRUE   1^M
+#endif^M
+^M
+#ifdef CONFIG_YAFFS2^M
+extern void cmd_yaffs_devconfig(char *mp, int flash_dev, int start_block, int end_block);^M
+extern void cmd_yaffs_mount(char *mp);^M
+extern void cmd_yaffs_umount(char *mp);^M
+extern void cmd_yaffs_mread_file(char *fn, char *addr);^M
+#endif^M
+^M
+#define BADBLOCK_MAX 200^M
+^M
+extern int lb_nand_get_badblock_number(ulong *badblock_list);^M
+extern int lbcmd_get_imagename_by_cmd(char* imgname, unsigned char cmd);^M
+extern int lonbon_get_partitions(const char *part_name, uint *part_offset, uint *part_size);^M
+extern int lonbon_get_partitions_name(uint *off, char *part_name, uint *part_offset, uint *part_size);^M
+extern int lb_nand_flash_partition_baseAddr(const char *part_name, uint *part_offset, uint *part_size);^M
+^M
+typedef struct {^M
+       int uboot;^M
+       int kernel;^M
+       int rootfs;^M
+       int backup;^M
+       int ro;^M
+       int rw;^M
+       int ipl;^M
+       int ipl_cust;^M
+       int logo;^M
+       int factory;^M
+       int lbcmd;^M
+       int lbflash;^M
+       int lbcfg;^M
+       int env;^M
+       int key_cust;^M
+} lb_bad_partition_t;^M
+^M
+int lonbon_set_badnum(int number)^M
+{^M
+       unsigned char  badnum[2];^M
+    if(number >= 0) {^M
+               memset(badnum,0,2);^M
+               badnum[0] = number + 0x30;^M
+               setenv("lb_badnum", (const char *)badnum);^M
+               run_command("saveenv", 0);^M
+               return 0;^M
+    }^M
+       return -1;^M
+}^M
+^M
+int lonbon_get_badnum(void)^M
+{^M
+       char * lb_badnum = getenv("lb_badnum");^M
+       unsigned char  badnum[2];^M
+^M
+    if(lb_badnum) {^M
+               badnum[0] = *lb_badnum - 0x30;^M
+               printf("old bad_block number= %d\n",badnum[0]);^M
+               return badnum[0];^M
+    }else{^M
+               printf("%s lb_badnum=null\n", __func__);^M
+               return -1;^M
+       }^M
+       return 0;^M
+}^M
+^M
+int lonbon_number_exist(int all_number, ulong *badblock_list, ulong number){^M
+       int i;^M
+       for(i=0; i < all_number; i++)^M
+       {^M
+               if(*(badblock_list+i) == number)^M
+               {^M
+                       return i;^M
+               }^M
+       }^M
+       return -1;^M
+}^M
+^M
+int lonbon_new_badblock(int all_number, ulong *badblock_list, int env_number, ulong *old_badblock_list,ulong *add_badblock_list)^M
+{^M
+       int i, j, k = 0;^M
+       bool flag;^M
+       for (i=0; i < all_number; i++){^M
+               flag = false;^M
+               for (j=0; j < all_number; j++){^M
+               if( badblock_list[i] == old_badblock_list[j] )^M
+               flag = true;^M
+               }^M
+^M
+               if(flag == false){^M
+               *(add_badblock_list + k) = badblock_list[i];^M
+               k++;^M
+               }^M
+^M
+       }^M
+^M
+       return 0;^M
+}^M
+^M
+^M
+int lonbon_get_bad_offset(int all_number, ulong *badblock_list, int number)^M
+{^M
+       int i;^M
+       char *lb_badoff = getenv("lb_badoff");^M
+       char badb_offset[1024]= {0};^M
+       ulong old_badb_list[all_number];^M
+       ulong *old_badblock_list = &old_badb_list[0];^M
+       ulong add_badb_list[all_number];^M
+       ulong *add_badblock_list = &add_badb_list[0];^M
+       char *lb_bad_off;^M
+       ulong num;^M
+^M
+       if(all_number == 0){^M
+       printf("%s not badblock_list\n", __func__);^M
+       return 0;^M
+       }^M
+^M
+       if(lb_badoff){^M
+               strcpy(badb_offset,lb_badoff);^M
+               lb_bad_off = strtok(badb_offset, "-");^M
+               num = simple_strtol(lb_bad_off, NULL, 16);^M
+               old_badb_list[0] = num;^M
+               for(i=1; i < all_number;i++ ){^M
+               lb_bad_off = strtok(NULL ,"-");^M
+               num = simple_strtol(lb_bad_off, NULL, 16);^M
+               old_badb_list[i] = num;^M
+               }^M
+       }^M
+       /* determine the partition location of the new bad block */^M
+       lonbon_new_badblock(all_number, badblock_list, number, old_badblock_list, add_badblock_list);^M
+       for(i=0; i < all_number; i++){^M
+       *(badblock_list + i) = 0;^M
+       }^M
+       for(i=0; i<number;i++){^M
+       *(badblock_list + i) = add_badb_list[i];^M
+       }^M
+^M
+       return 1;^M
+}^M
+^M
+int lonbon_set_bad_offset(int number, ulong *badblock_list)^M
+{^M
+       int i;^M
+       char commandline[10] = {0};^M
+       char badb_addr[1024]= {'0'};^M
+       if(number >= 0) {^M
+               if(number > 0) {^M
+                       for(i=0;i<number;i++){^M
+                       sprintf(commandline,"%08lx-", *(badblock_list+i));^M
+                       strcat(badb_addr,commandline);^M
+                       }^M
+               }^M
+               printf("lonbon_set_bad_offset badblock_list:%s\n",badb_addr);^M
+               setenv("lb_badoff", (const char *)badb_addr);^M
+               run_command("saveenv", 0);^M
+               return number;^M
+       }^M
+       return 0;^M
+}^M
+^M
+int lonbon_set_partitions(lb_bad_partition_t *lb_part, char *part_name)^M
+{^M
+       //printf("%s %s \n",__func__,part_name);^M
+       if(strcmp(part_name, "UBOOT0") == 0||strcmp(part_name, "UBOOT1") == 0){^M
+       lb_part->uboot += 1;^M
+       }else if(strcmp(part_name, "rootfs") == 0){^M
+       lb_part->rootfs  += 1;^M
+       }else if(strcmp(part_name, "KERNEL") == 0||strcmp(part_name, "RECOVERY") == 0){^M
+       lb_part->kernel  += 1;^M
+       }else if(strcmp(part_name, "backup") == 0){^M
+       lb_part->backup  += 1;^M
+       }else if(strcmp(part_name, "ro") == 0){^M
+       lb_part->ro  += 1;^M
+       }else if(strcmp(part_name, "rw") == 0){^M
+       lb_part->rw  += 1;^M
+       }else if(strcmp(part_name, "IPL0") == 0||strcmp(part_name, "IPL1") == 0){^M
+       lb_part->ipl  += 1;^M
+       }else if(strcmp(part_name, "IPL_CUST0") == 0||strcmp(part_name, "IPL_CUST1") == 0){^M
+       lb_part->ipl_cust  += 1;^M
+       }else if(strcmp(part_name, "LOGO") == 0){^M
+       lb_part->logo  += 1;^M
+       }else if(strcmp(part_name, "factory") == 0){^M
+       lb_part->factory  += 1;^M
+       }else if(strcmp(part_name, "lbcmd") == 0){^M
+       lb_part->lbcmd  += 1;;^M
+       }else if(strcmp(part_name, "lbflash") == 0||strcmp(part_name, "lbflash2") == 0){^M
+       lb_part->lbflash  += 1;^M
+       }else if(strcmp(part_name, "lbcfg") == 0||strcmp(part_name, "lbcfg2") == 0){^M
+       lb_part->lbcfg  += 1;^M
+       }else if(strcmp(part_name, "ENV") == 0||strcmp(part_name, "ENV1") == 0){^M
+       lb_part->env  += 1;^M
+       }else if(strcmp(part_name, "KEY_CUST") == 0){^M
+       lb_part->key_cust  += 1;^M
+       }else{^M
+       return -1;^M
+       }^M
+^M
+       return 0;^M
+}^M
+^M
+void lonbon_printf_bad(int num){^M
+^M
+       switch (num)^M
+       {^M
+               case 0: printf("\n");^M
+                               printf("##############################################################################\n");^M
+                               printf("##############################################################################\n");^M
+                               printf("############################ bad block list:##################################\n");^M
+                               break;^M
+               case 1: printf("\nstart all bad block list:\n");^M
+                               break;^M
+               case 2: printf("\n");^M
+                               printf("add bad block:\n");^M
+                               printf("\n");^M
+                               break;^M
+               case 3: printf("\n");^M
+                               printf("##############################################################################\n");^M
+                               printf("##############################################################################\n");^M
+                               printf("\n");^M
+                               break;^M
+       }^M
+^M
+}^M
+^M
+uint lonbon_get_pattition_firmware_size(char *fileName){^M
+               char *mntpoint = "/factory";^M
+               uint part_offset;^M
+               uint part_size;^M
+               int start_block;^M
+               int end_block;^M
+^M
+               char filename[100] = {0};^M
+               unsigned long addr= 0x21000000;^M
+               lb_nand_flash_partition_baseAddr("factory", &part_offset, &part_size);^M
+               if(!part_offset || !part_size) {^M
+                       printf("#ERROR: No factory partition is found\n");^M
+                       return -1;^M
+               }^M
+^M
+               start_block = part_offset/(128*1024); /* Nand flash block size is 128 KB */^M
+               end_block = (part_offset+part_size)/(128*1024)-1;^M
+^M
+               cmd_yaffs_devconfig(mntpoint,0,start_block,end_block);^M
+               cmd_yaffs_mount(mntpoint);^M
+               sprintf(filename, "%s/%s", mntpoint, fileName);^M
+               cmd_yaffs_mread_file(filename, (char *)addr);^M
+               char *str_env = getenv("filesize");^M
+               ulong filesize = simple_strtoul(str_env, NULL, 16);^M
+               size_t blocksize = nand_info[0].erasesize;^M
+               ulong wsize=(filesize/blocksize+1)*blocksize;^M
+               cmd_yaffs_umount(mntpoint);^M
+               printf("longbon  filename=%s  str_env=%s filesize=%lx wsize=%lx \n",filename,str_env,filesize,wsize);^M
+       return wsize;^M
+^M
+}^M
+^M
+int lonbon_pattition_firmware_size(unsigned char cmd, char *part_name, int bad_number)^M
+{^M
+       char firmware_name[32] = {0};^M
+       char *firmware_part_name = &firmware_name[0];^M
+       uint part_offset, part_size;^M
+       ulong firmware_size, firmware_size_bad;^M
+       size_t blocksize = nand_info[0].erasesize;^M
+^M
+       /* get firmware name */^M
+       lbcmd_get_imagename_by_cmd(firmware_part_name, cmd);^M
+       /* get firmware size */^M
+       firmware_size = lonbon_get_pattition_firmware_size(firmware_part_name);^M
+       /* the size after adding the bad block */^M
+       firmware_size_bad = firmware_size +( blocksize * bad_number);^M
+       /* get partitions total size */^M
+       lonbon_get_partitions(part_name, &part_offset, &part_size);^M
+^M
+       /* partitions total size > firmware size add bad block size */^M
+       if( part_size > firmware_size_bad)^M
+       {^M
+       printf("\nlonbon %s is OK! part_size=%x firmware_size_bad=%lx \n",__func__,part_size,firmware_size_bad);^M
+       return 1;^M
+       }^M
+       else {^M
+       printf("\nlonbon %s error!! part_size=%x firmware_size_bad=%lx \n",__func__,part_size,firmware_size_bad);^M
+       return -1;^M
+       }^M
+       return 0;^M
+}^M
+^M
+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
+^M
+       int i, ret, flags = 0;^M
+       char write[20] = {' '};^M
+       char *write_t = &write[0];^M
+       char part_name[10] = {'0'};^M
+       char *part_name_t = &part_name[0];^M
+       ulong *badblock_list = bad_list;^M
+       char commandline[30] = {0};^M
+       uint lbflash_offset = 0,lbflash_size = 0;^M
+^M
+       if(new_number > 0){^M
+       lonbon_printf_bad(1);^M
+       }^M
+       for(i=0; i< number; i++){^M
+               memset(part_name,0,sizeof(part_name));^M
+               lonbon_get_partitions_name((uint *) *(badblock_list+i), part_name_t, &lbflash_offset, &lbflash_size);^M
+               printf("bad[%d]=0x%08lx name=%s off=0x%08x size=0x%08x end=0x%08x \n",^M
+                       i, *(badblock_list+i), part_name_t, lbflash_offset, lbflash_size ,(lbflash_offset +lbflash_size -1) );^M
+       }^M
+       if(new_number > 0){^M
+       lonbon_printf_bad(2);^M
+               for(i=0; i< new_number; i++){^M
+               printf(" 0x%08lx \n", *(new_bad_list + i));^M
+               }^M
+       }^M
+       if(lb_bad_partition->factory > 0){^M
+       printf("\n warn factory partition are bad blocks !!!\n\n");^M
+       }^M
+       if(lb_bad_partition->uboot > 0){^M
+       printf("\n warn uboot partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(1,"uboot",lb_bad_partition->uboot);^M
+               if(ret > 0){^M
+               strcat(write,"1 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!uboot insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+       if(lb_bad_partition->kernel > 0){^M
+       printf("\n warn kernel partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(2,"kernel",lb_bad_partition->kernel);^M
+               if(ret > 0){^M
+               strcat(write,"2 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!kernel insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+       if(lb_bad_partition->rootfs > 0){^M
+       printf("\n warn rootfs partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(3,"rootfs",lb_bad_partition->rootfs);^M
+               if(ret > 0){^M
+               strcat(write,"3 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!rootfs insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+       if(lb_bad_partition->backup > 0){^M
+       printf("\n warn backup partition are bad blocks !!!\n\n");^M
+       }^M
+       if(lb_bad_partition->ro > 0){^M
+       printf("\n warn ro partition are bad blocks !!!\n\n");^M
+       }^M
+       if(lb_bad_partition->rw > 0){^M
+       printf("\n warn rw partition are bad blocks !!!\n\n");^M
+       }^M
+       if(lb_bad_partition->ipl > 0){^M
+       printf("\n warn ipl partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(6,"ipl",lb_bad_partition->ipl);^M
+               if(ret > 0){^M
+               strcat(write,"6 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!ipl insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+       if(lb_bad_partition->ipl_cust > 0){^M
+       printf("\n warn ipl_cust partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(7,"ipl",lb_bad_partition->ipl_cust);^M
+               if(ret > 0){^M
+               strcat(write,"7 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!ipl_cust insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+       if(lb_bad_partition->logo > 0){^M
+       printf("\n warn logo partition are bad blocks !!!\n\n");^M
+       ret = lonbon_pattition_firmware_size(8,"logo",lb_bad_partition->logo);^M
+               if(ret > 0){^M
+               //run_command("lbupgrade write 8", 0);^M
+               strcat(write,"8 ");^M
+               flags++;^M
+               }else{^M
+               printf("\n%s error!!!logo insufficient partition space !!!\n",__func__ );^M
+               }^M
+       }^M
+^M
+       if (flags > 0){^M
+       sprintf(commandline,"lbupgrade write %s", write_t);^M
+       printf("\nlonbon %s run_command: %s !!!\n", __func__ , commandline);^M
+       run_command(commandline, 0);^M
+       }^M
+^M
+       lonbon_printf_bad(3);^M
+^M
+}^M
+^M
+/* bad block inspection */^M
+int run_lbbadblock(void) ^M
+{^M
+       lb_bad_partition_t lb_bad_partition ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};^M
+       lb_bad_partition_t *lb_bad_partition_r = &lb_bad_partition;^M
+       int ret, i;^M
+       char part_name[10] = {'0'};^M
+       char *part_name_t = &part_name[0];^M
+       uint lbflash_offset = 0,lbflash_size = 0;^M
+       ulong badblock_list[BADBLOCK_MAX];^M
+       ulong *list_badblock = &badblock_list[0];^M
+       int badblock_number , lb_badnum;^M
+       bool new_badblock = false;^M
+^M
+       lonbon_printf_bad(0);^M
+       memset(badblock_list,0,sizeof(badblock_list));^M
+       badblock_number = lb_nand_get_badblock_number(list_badblock);^M
+       ulong bad_list[badblock_number];^M
+       ulong *bad_list_t = &bad_list[0];^M
+^M
+       for( i = 0; i < badblock_number; i++){^M
+       bad_list[i] = badblock_list[i];^M
+       }^M
+^M
+       if(badblock_number < 0){^M
+               printf("error! get badblock number failed! :%d\n",badblock_number);^M
+               return badblock_number;^M
+       }else{^M
+               printf("bad badblock  number: %d\n",badblock_number);^M
+       }^M
+^M
+       lb_badnum = lonbon_get_badnum();/* get lb_badnum */^M
+       if(lb_badnum < 0){ /* the first burning is not processed */^M
+^M
+               ret = lonbon_set_badnum(badblock_number);/* directly save the number of burned blocks */^M
+               if(ret < 0){^M
+               printf("error %s badblock_number=null\n",__func__);^M
+               }^M
+               printf("lonbon %s init badblock\n",__func__);^M
+               ret = lonbon_set_bad_offset(badblock_number, list_badblock);/* save bad block address*/^M
+               lonbon_printf_bad(3);^M
+               return 0;^M
+^M
+       }else{   /* after the second boot, go here */^M
+               if(badblock_number == lb_badnum){ /* equal means there are no bad blocks */^M
+                       printf("lonbon %s not new badblock\n",__func__);^M
+^M
+               }else{                            /* unequal means there are bad blocks */^M
+                       printf("%s new badblock number= %d\n",__func__, badblock_number - lb_badnum);^M
+                       ret = lonbon_set_badnum(badblock_number);^M
+                       if(ret < 0){^M
+                       printf("error %s badblock_number=null\n",__func__);^M
+                       }else{^M
+                       new_badblock = true; /* mark the newly added bad block symbol */^M
+                       }^M
+               }^M
+       }^M
+^M
+       if(new_badblock == true ){/* there are new bad blocks added */^M
+               /* Get env bad block address */^M
+               ret = lonbon_get_bad_offset(badblock_number, list_badblock ,badblock_number - lb_badnum);^M
+^M
+               for(i=0; i< badblock_number - lb_badnum; i++){^M
+                       memset(part_name,0,sizeof(part_name));^M
+                       lonbon_get_partitions_name((uint *) badblock_list[i], part_name_t, &lbflash_offset, &lbflash_size);^M
+                       ret = lonbon_set_partitions(lb_bad_partition_r, part_name_t);^M
+               }^M
+               printf("%s new_badblock=true\n",__func__);^M
+^M
+       }^M
+^M
+       lonbon_printf_bad_block(lb_bad_partition_r, badblock_number, bad_list_t, badblock_number - lb_badnum, list_badblock);^M
+^M
+       if(new_badblock == true){/* if a new bad block is added, restart and enter restore mode */^M
+               ret = lonbon_set_bad_offset(badblock_number, bad_list_t);/* save bad block address */^M
+               new_badblock = false;^M
+               run_command("reset", 0);^M
+       }^M
+       return 0;^M
+}^M
diff --git a/boot/common/cmd_mtdparts.c b/boot/common/cmd_mtdparts.c
index f6940a6f2..172750152 100755
--- a/boot/common/cmd_mtdparts.c
+++ b/boot/common/cmd_mtdparts.c
@@ -1331,6 +1331,63 @@ int lonbon_get_partitions(const char *part_name, uint *part_offset, uint *part_s}return -1;}
+
+int lonbon_strcpy_name(char *part_name,char *name)
+{
+       char str[10];
+       int len,i;
+               strcpy(str,name);
+               len = strlen(str);
+               for(i=0; i < len; i++){
+                       *(part_name+i) = str[i];
+               }
+       return 0;
+}
+/**
+* obtain the partition name of the address by passing it through.
+*/
+
+int lonbon_get_partitions_name(uint *off, char *part_name, uint *part_offset, uint *part_size)
+{
+       struct list_head *dentry, *pentry;
+       struct part_info *part;
+       struct mtd_device *dev;
+       int part_num;
+       uint *part_offset_closure;
+
+       if (!part_name) {
+               printf("the part name is empty\n");
+               //return -1;
+       }
+
+       if (list_empty(&devices)) {
+               printf("the partitions list is empty\n");
+               return -1;
+       }
+
+       if (mtdparts_init() != 0)
+               return -1;
+
+       list_for_each(dentry, &devices) {
+               dev = list_entry(dentry, struct mtd_device, link);
+               part_num = 0;
+               list_for_each(pentry, &dev->parts) {
+                       part = list_entry(pentry, struct part_info, link);
+                       //printf("%2d:%s 0x%08llx 0x%08llx\n",part_num, part->name, part->size,part->offset);
+                       part_offset_closure = part->offset + part->size;
+                       if(part_offset_closure > off){
+
+                                       lonbon_strcpy_name(part_name,part->name);
+                                       *part_offset = part->offset;
+                                       *part_size   = part->size;
+                                       return 0;
+                               }
+                               part_num++;
+               }
+       }
+       return -1;
+}
+#endif/*** Format and print out a partition list for each device from global device
diff --git a/boot/common/cmd_nand.c b/boot/common/cmd_nand.c
index 64b0bd26b..022696de3 100755
--- a/boot/common/cmd_nand.c
+++ b/boot/common/cmd_nand.c
@@ -718,10 +718,14 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])nand = &nand_info[dev];if (strcmp(cmd, "bad") == 0) {
-               printf("\nDevice %d bad blocks:\n", dev);
+               int j = 0;
+               //printf("\nDevice %d bad blocks:\n", dev);for (off = 0; off < nand->size; off += nand->erasesize)
-                       if (nand_block_isbad(nand, off))
+                       if (nand_block_isbad(nand, off)){printf("  %08llx\n", (unsigned long long)off);
+                               j++;
+                       }
+               printf("bad number %d blocks:\n", j);return 0;}@@ -1466,6 +1470,31 @@ static int lb_nand_erase(uint start_addr, uint part_size, uint length)return 0;}
+#define BADBLOCK_MAX 200
+int lb_nand_get_badblock_number(ulong *badblock_list)
+{
+       int j = 0;
+       ulong off,badblock_addr[BADBLOCK_MAX];
+       nand_info_t *nand = &nand_info[0];
+       char commandline[16];
+       char badb_addr[1024];
+       memset(badblock_addr,0,sizeof(badblock_addr));
+       memset(commandline,0,sizeof(commandline));
+       memset(badb_addr,0,sizeof(badb_addr));
+       printf("\n");
+       for (off = 0; off < nand->size; off += nand->erasesize)
+               if (nand_block_isbad(nand, off)){
+                       //printf("lonbon bad blocks  %08llx\n", (unsigned long long)off);
+                       badblock_addr[j] = off;
+                       j++;
+               }
+       printf("\n");
+       for(int i = 0; i < j; i++){
+       //printf("\nlonbon %08lx\n", badblock_addr[i]);
+       badblock_list[i] = badblock_addr[i];
+       }
+       return j;
+}int lb_nand_flash_partition_baseAddr(const char *part_name, uint *part_offset, uint *part_size){
@@ -1492,7 +1521,7 @@ int lb_nand_flash_partition_read(const char *part_name,char* buff,const int lengreturn -1;}-    ret=lb_nand_read(lbflash_offset,lbflash_size, length>lbflash_size?lbflash_size:len,(void *) buff);
+    ret = lb_nand_read(lbflash_offset,lbflash_size, length>lbflash_size?lbflash_size:len,(void *) buff);//_print_hex_string(buff,length); //TEST ONLYreturn ret;}
diff --git a/boot/include/configs/infinity2m.h b/boot/include/configs/infinity2m.h
index c5d5d8ea1..19a44747b 100755
--- a/boot/include/configs/infinity2m.h
+++ b/boot/include/configs/infinity2m.h
@@ -39,6 +39,7 @@#define LONBONVOIP#ifdef LONBONVOIP#define CONFIG_CMD_LBCHK
+#define CONFIG_CMD_LBBAD#define CONFIG_LB_MD5#define CONFIG_IDENT_STRING     " LonBon Technology "#define LONBONVOIP_REALM       "voip.lonbon.com"

========================================================================

第一次开机

 第二次开机

第N次开机后产生新坏块

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/488854.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

泷羽Sec-Burp Suite自动刷漏洞-解放双手

声明&#xff01; 学习视频来自B站up主 **泷羽sec** 有兴趣的师傅可以关注一下&#xff0c;如涉及侵权马上删除文章&#xff0c;笔记只是方便各位师傅的学习和探讨&#xff0c;文章所提到的网站以及内容&#xff0c;只做学习交流&#xff0c;其他均与本人以及泷羽sec团队无关&a…

Java多线程与线程池技术详解(九)

面对苦难的态度&#xff1a;《病隙碎笔》“不断的苦难才是不断地需要信心的原因&#xff0c;这是信心的原则&#xff0c;不可稍有更动。” 孤独与心灵的成长&#xff1a;《我与地坛》“孤独的心必是充盈的心&#xff0c;充盈得要流溢出来要冲涌出去&#xff0c;便渴望有人呼应他…

以太网链路详情

文章目录 1、交换机1、常见的概念1、冲突域2、广播域3、以太网卡1、以太网卡帧 4、mac地址1、mac地址表示2、mac地址分类3、mac地址转换为二进制 2、交换机的工作原理1、mac地址表2、交换机三种数据帧处理行为3、为什么会泛洪4、转发5、丢弃 3、mac表怎么获得4、同网段数据通信…

IDEA 2024 版本配置热部署

在实际开发过程中&#xff0c;每次修改代码就得将项目重启&#xff0c;重新部署&#xff0c;对于一些大型应用来说&#xff0c;重启时间需要花费大量的时间成本。对于一个后端开发者来说&#xff0c;重启过程确实很难受啊 采用下面三步骤可以完成 1.在IDEA中settings中搜索Debb…

阿里云 云产品流转(实现设备与小程序交互)

一、准备工作 1、设备接入平台 创建两个设备接入到对应产品中&#xff0c;具体可以参考这里&#xff08;点击跳转&#xff09;。 二、云产品流转设置 在物联网平台下-->消息转发-->云产品流转->数据源 1、数据源 数据源-->创建数据源-->填写信息-->确定&…

单目深度估计模型 lite-mono 测试

lite-mono 使用工业数据集kitti 进行训练&#xff0c;目的使用单目摄像头实现物体深度预测&#xff0c;关于kitti数据集的介绍和下载参考 &#xff08;二&#xff09;一文带你了解KITTI数据集-CSDN博客文章浏览阅读2.7w次&#xff0c;点赞64次&#xff0c;收藏294次。文章介绍…

.Net 多线程、异步、性能优化应用与心得

文章目录 概要多线程Thread方式创建线程:Task方式创建线程[C#5.0引入]&#xff08;推荐使用&#xff09;:线程池方式创建线程&#xff1a; 异步异步方法异步IO操作异步数据库操作异步Web请求取消异步ValueTask[C# 7.0引入]ValueTask<TResult> 和 Task 性能优化懒加载对象…

qt-C++语法笔记之mapToGlobal将组件(控件)中的本地坐标系(局部坐标)映射到全局坐标系

qt-C语法笔记之mapToGlobal将组件&#xff08;控件&#xff09;中的本地坐标系&#xff08;局部坐标&#xff09;映射到全局坐标系 code review! 文章目录 qt-C语法笔记之mapToGlobal将组件&#xff08;控件&#xff09;中的本地坐标系&#xff08;局部坐标&#xff09;映射到…

python爬虫--小白篇【爬取B站视频】

目录 一、任务分析 二、网页分析 三、任务实现 一、任务分析 将B站视频爬取并保存到本地&#xff0c;经过分析可知可以分为四个步骤&#xff0c;分别是&#xff1a; 爬取视频页的网页源代码&#xff1b;提取视频和音频的播放地址&#xff1b;下载并保存视频和音频&#x…

UniScene:Video、LiDAR 和Occupancy全面SOTA

论文: https://arxiv.org/pdf/2412.05435 项目页面&#xff1a;https://arlo0o.github.io/uniscene/ 0. 摘要 生成高保真度、可控制且带有标注的训练数据对于自动驾驶至关重要。现有方法通常直接从粗糙的场景布局生成单一形式的数据&#xff0c;这不仅无法输出多样化下游任务…

Ubuntu22.04搭建FTP服务器保姆级教程

在网络环境中&#xff0c;文件传输是一项至关重要的任务。FTP&#xff08;文件传输协议&#xff09;是一种基于客户端/服务器模式的协议&#xff0c;广泛用于在互联网上传输文件。Ubuntu作为一款流行的Linux发行版&#xff0c;因其稳定性和易用性而广受开发者和系统管理员的喜爱…

【银河麒麟高级服务器操作系统】修改容器中journal服务日志存储位置无效—分析及解决方案

了解更多银河麒麟操作系统全新产品&#xff0c;请点击访问 麒麟软件产品专区&#xff1a;https://product.kylinos.cn 开发者专区&#xff1a;https://developer.kylinos.cn 文档中心&#xff1a;https://documentkylinos.cn 服务器环境以及配置 【机型】 整机类型/架构&am…

React 第十六节 useCallback 使用详解注意事项

useCallback 概述 1、useCallback 是在React 中多次渲染缓存函数的 Hook&#xff0c;返回一个函数的 memoized的值&#xff1b; 2、如果多次传入的依赖项不变&#xff0c;那么多次定义的时候&#xff0c;返回的值是相同的,防止频繁触发更新&#xff1b; 3、多应用在 父组件为函…

二十七、Tomcat专题总结与拓展

文章目录 一、Tomcat设计思路总结1、Tomcat整体架构2、Tomcat设计思路 二、Tomcat源码设计精髓三、拓展&#xff1a;SpringBoot整合Tomcat源码分析四、拓展&#xff1a;SpringBoot整合Undertow实战1、Undertow概述2、SpringBoot集成Undertow2.1、引入依赖2.2、application.prop…

[游戏开发] Unity中使用FlatBuffer

什么是FlatBuffer 官网&#xff1a; GitHub - google/flatbuffers: FlatBuffers: Memory Efficient Serialization LibraryFlatBuffers: Memory Efficient Serialization Library - google/flatbuffershttps://github.com/google/flatbuffers 为什么用FloatBuffer&#xff0c…

【JAVA】旅游行业中大数据的使用

一、应用场景 数据采集与整合&#xff1a;全面收集旅游数据&#xff0c;如客流量、游客满意度等&#xff0c;整合形成统一数据集&#xff0c;为后续分析提供便利。 舆情监测与分析&#xff1a;实时监测旅游目的地的舆情信息&#xff0c;运用NLP算法进行智能处理&#xff0c;及…

android studio创建虚拟机注意事项

emulator 启动模拟器的时候&#xff0c;可以用 AVD 界面&#xff0c;也可以用命令行启动&#xff0c;但命令行启 动的时候要注意&#xff0c;系统有两个 emulator.exe &#xff0c;建议使用 emulator 目录下的那个&#xff01;&#xff01; 创建类型为google APIs的虚拟机可从…

全面解析租赁小程序的功能与优势

内容概要 租赁小程序正在逐渐改变人与物之间的互动方式。通过这些小程序&#xff0c;用户不仅可以轻松找到所需的租赁商品&#xff0c;还能够享受无缝的操作体验。为了给大家一个清晰的了解&#xff0c;下面我们将重点介绍几个核心功能。 建议&#xff1a;在选择租赁小程序时&…

JCR一区牛顿-拉夫逊优化算法+分解对比!VMD-NRBO-Transformer-BiLSTM多变量时序光伏功率预测

JCR一区牛顿-拉夫逊优化算法分解对比&#xff01;VMD-NRBO-Transformer-BiLSTM多变量时序光伏功率预测 目录 JCR一区牛顿-拉夫逊优化算法分解对比&#xff01;VMD-NRBO-Transformer-BiLSTM多变量时序光伏功率预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.中科院…

用二维图像渲染3D场景视频

✨✨ 欢迎大家来访Srlua的博文&#xff08;づ&#xffe3;3&#xffe3;&#xff09;づ╭❤&#xff5e;✨✨ &#x1f31f;&#x1f31f; 欢迎各位亲爱的读者&#xff0c;感谢你们抽出宝贵的时间来阅读我的文章。 我是Srlua小谢&#xff0c;在这里我会分享我的知识和经验。&am…