From 36db071233f728519a0891e60d3bddc948832325 Mon Sep 17 00:00:00 2001 From: Wanderingss <1624155937@qq.com> Date: Sun, 20 Sep 2026 04:39:41 +0800 Subject: [PATCH] =?UTF-8?q?FTL=E8=AF=8A=E6=96=AD=EF=BC=9Aresume=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E9=80=90=E6=8E=A2=E6=B5=8B=E6=8E=A2=E9=92=88=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=88page=5Fread/ECC/magic/epoch/BBT=E5=85=A8?= =?UTF-8?q?=E8=BE=93=E5=85=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Drivers/BSP/GD5F2GQ5UE/nand_ftl.c | 40 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Drivers/BSP/GD5F2GQ5UE/nand_ftl.c b/Drivers/BSP/GD5F2GQ5UE/nand_ftl.c index 995f811a..f7ed20f7 100644 --- a/Drivers/BSP/GD5F2GQ5UE/nand_ftl.c +++ b/Drivers/BSP/GD5F2GQ5UE/nand_ftl.c @@ -52,6 +52,9 @@ static uint8_t s_copy_buf[FTL_PAGE_SIZE]; /* 初始化状态 */ static uint8_t s_initialized; +/* resume 搜索探针日志窗口(诊断:逐探测记录判定输入) */ +static uint8_t s_probe_log; + /* ======================== 私有函数声明 ======================== */ static int ftl_flush_cache(void); @@ -94,7 +97,12 @@ static int ftl_read_page(dhara_sector_t lpn) { int dhara_nand_is_bad(const struct dhara_nand *n, dhara_block_t b) { (void)n; - return gd5f2gq5ue_is_block_bad(ftl_phy_block(b)); + const int bad = gd5f2gq5ue_is_block_bad(ftl_phy_block(b)); + if (s_probe_log) { + DBG_INFO("probe blk %lu: bbt_bad=%u", (unsigned long)b, + (unsigned int)bad); + } + return bad; } void dhara_nand_mark_bad(const struct dhara_nand *n, dhara_block_t b) { @@ -187,18 +195,42 @@ int dhara_nand_is_free(const struct dhara_nand *n, dhara_page_t p) { int dhara_nand_read(const struct dhara_nand *n, dhara_page_t p, size_t offset, size_t length, uint8_t *data, dhara_error_t *err) { (void)n; uint32_t phy_pg = ftl_phy_page(p); + int rret; + int eret; - if (gd5f_page_read(phy_pg) != GD5F_OK) { + if ((rret = gd5f_page_read(phy_pg)) != GD5F_OK) { + if (s_probe_log) { + DBG_INFO("probe pg %lu blk %lu: page_read=%d", + (unsigned long)phy_pg, (unsigned long)(p >> 6), + rret); + } dhara_set_error(err, DHARA_E_ECC); return -1; } - if (gd5f_check_ecc() != GD5F_OK) { + if ((eret = gd5f_check_ecc()) != GD5F_OK) { + if (s_probe_log) { + DBG_INFO("probe pg %lu blk %lu: ecc=%d", + (unsigned long)phy_pg, (unsigned long)(p >> 6), + eret); + } dhara_set_error(err, DHARA_E_ECC); return -1; } gd5f_read_from_cache((uint16_t)offset, data, length); + + if (s_probe_log && offset == 0 && length == FTL_PAGE_SIZE) { + /* 组末页(组内偏移 15)= checkpoint 页:记录 magic/epoch 判定 */ + if ((p & 63u) == 15u) { + const uint8_t *m = data; + DBG_INFO("probe pg %lu blk %lu chk: magic=%u epoch=%u", + (unsigned long)phy_pg, (unsigned long)(p >> 6), + (unsigned int)((m[0] == 'D' && m[1] == 'h' && + m[2] == 'a') ? 1 : 0), + (unsigned int)m[3]); + } + } return 0; } @@ -248,6 +280,7 @@ DSTATUS disk_initialize(BYTE pdrv) { { dhara_error_t err; + s_probe_log = 1; if (dhara_map_resume(&s_map, &err) < 0) { DBG_INFO("No valid map found, creating fresh (err=%d)", err); dhara_map_clear(&s_map); @@ -255,6 +288,7 @@ DSTATUS disk_initialize(BYTE pdrv) { DBG_INFO("Map resumed: %lu/%lu sectors used", dhara_map_size(&s_map), dhara_map_capacity(&s_map)); } + s_probe_log = 0; } s_initialized = 1;