mkfs全程erase/prog逐条追踪窗口(proglog/eraselog):定位绑定页内容被改写的元凶

This commit is contained in:
2026-09-20 11:20:46 +08:00
parent 66fc48cd98
commit 32283de45b
3 changed files with 40 additions and 0 deletions
+37
View File
@@ -56,6 +56,20 @@ static uint8_t s_initialized;
static uint8_t s_probe_log;
/* L0 卷健康探针窗口(诊断:记录 FAT 读的 LPN 绑定 → 物理页路径) */
static uint8_t s_tree_probe_log;
/* 写路径全量追踪窗口(诊断:mkfs 期间每个 erase/prog 逐条记录) */
static uint8_t s_prog_log;
/*
* 函数功能:打开/关闭写路径全量追踪窗口(erase/prog 逐条日志)
* 入口参数:on - 1 打开,0 关闭
* 返回值:无
* 限定条件:无
* 函数说明:定位"绑定页内容被谁改写/擦除":记录每次 erase 的目标块与
* 每次 prog 的目标页+数据前 4 字节+校验结果。
*/
void nand_ftl_set_prog_log(uint8_t on) {
s_prog_log = on;
}
/*
* 函数功能:打开/关闭 L0 卷健康探针日志窗口
@@ -137,6 +151,10 @@ void dhara_nand_mark_bad(const struct dhara_nand *n, dhara_block_t b) {
int dhara_nand_erase(const struct dhara_nand *n, dhara_block_t b, dhara_error_t *err) {
(void)n;
int ret = gd5f_block_erase(ftl_phy_block(b));
if (s_prog_log) {
DBG_INFO("eraselog blk %lu ret %d",
(unsigned long)ftl_phy_block(b), ret);
}
if (ret == GD5F_ERASE_FAIL || ret != GD5F_OK) {
dhara_nand_mark_bad(n, b);
dhara_set_error(err, DHARA_E_BAD_BLOCK);
@@ -165,6 +183,10 @@ int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p, const uint8_t *d
ret = gd5f_program_exec(phy_pg);
if (ret == GD5F_PROGRAM_FAIL || ret != GD5F_OK) {
if (s_prog_log) {
DBG_INFO("proglog pg %lu exec ret %d",
(unsigned long)phy_pg, ret);
}
dhara_nand_mark_bad(n, p >> n->log2_ppb);
dhara_set_error(err, DHARA_E_BAD_BLOCK);
return -1;
@@ -193,6 +215,14 @@ int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p, const uint8_t *d
gd5f_read_from_cache(0, s_copy_buf, FTL_PAGE_SIZE);
if (memcmp(s_copy_buf, data, FTL_PAGE_SIZE) != 0) {
if (s_prog_log) {
DBG_INFO("proglog pg %lu verify mismatch d=%02X%02X%02X%02X r=%02X%02X%02X%02X",
(unsigned long)phy_pg,
(unsigned int)data[0], (unsigned int)data[1],
(unsigned int)data[2], (unsigned int)data[3],
(unsigned int)s_copy_buf[0], (unsigned int)s_copy_buf[1],
(unsigned int)s_copy_buf[2], (unsigned int)s_copy_buf[3]);
}
dhara_nand_mark_bad(n, p >> n->log2_ppb);
dhara_set_error(err, DHARA_E_BAD_BLOCK);
DBG_ERROR("program verify: data mismatch, blk %lu",
@@ -200,6 +230,13 @@ int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p, const uint8_t *d
return -1;
}
if (s_prog_log) {
DBG_INFO("proglog pg %lu ok d=%02X%02X%02X%02X",
(unsigned long)phy_pg,
(unsigned int)data[0], (unsigned int)data[1],
(unsigned int)data[2], (unsigned int)data[3]);
}
return 0;
}
+1
View File
@@ -17,6 +17,7 @@ void nand_ftl_scan_checks(void);
void nand_ftl_set_tree_probe(uint8_t on);
void nand_ftl_raw_persist_test(void);
void nand_ftl_dump_binding(uint32_t lpn, const char *tag);
void nand_ftl_set_prog_log(uint8_t on);
#ifdef __cplusplus
}