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_badbloc