michallenc commented on code in PR #19018:
URL: https://github.com/apache/nuttx/pull/19018#discussion_r3413772296
##########
drivers/mtd/Kconfig:
##########
@@ -50,6 +50,15 @@ config FTL_READAHEAD
default n
depends on DRVR_READAHEAD
+config FTL_BBM
+ bool "Enable bad block management in the FTL layer"
+ default y if MTD_NAND
Review Comment:
But mtd_partition defines `markbad` and `isbad` unconditionally, see
https://github.com/apache/nuttx/blob/master/drivers/mtd/mtd_partition.c#L909.
So `DEBUGASSERT(mtd->isbad == NULL && mtd->markbad == NULL);` will ALWAYS
assert unless you enable `CONFIG_FTL_BBM`. I use W25Q and GD25 nor flashes
without bad block management, but I still had to enable `CONFIG_FTL_BBM` to
avoid the assertion.
The logic for `CONFIG_MTD_PARTITION` is the same as for `MTD_NAND`. The
other option is to change the logic in `mtd_partition` and assign markbad and
isbad only if the underlying flash really supports them, something like this
```diff
diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c
index 7de1c64db3..a00d609454 100644
--- a/drivers/mtd/mtd_partition.c
+++ b/drivers/mtd/mtd_partition.c
@@ -906,8 +906,8 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s
*mtd,
part->child.bwrite = part_bwrite;
part->child.read = mtd->read ? part_read : NULL;
part->child.ioctl = part_ioctl;
- part->child.isbad = part_isbad;
- part->child.markbad = part_markbad;
+ part->child.isbad = mtd->isbad ? part_isbad : NULL;
+ part->child.markbad = mtd->markbad ? part_markbad : NULL;
#ifdef CONFIG_MTD_BYTE_WRITE
part->child.write = mtd->write ? part_write : NULL;
#endif
```
That would be the better approach it seems.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]