drivers/fs:Always use register_mtddriver() to register the MTD device.

We have adjusted the registration method for MTD devices
in nuttx/boards, replacing the previous approach using
ftl_initialize() and bchdev_register() with
register_mtddriver().

When registering MTD devices via register_mtddriver(),
FTL and BCH wrappers will be added during the open() process:

1. Character Device Mode:
   When accessing the MTD device node via the open() interface,
   the device will be automatically converted to a character
   device. Both FTL and BCH wrappers will be implicitly added,
   provided that BCH support is enabled in the configuration.

2. Block Device Mode:
   When accessing the MTD device node via open_blockdriver(),
   the device will be treated as a block device, with only
   the FTL wrapper automatically applied.

Due to the automatic wrapping of MTD devices during the
open() process, the legacy registration methods
ftl_initialize() and bchdev_register() are no longer
required for MTD device registration for user code and should
be used only internally within fs and driver code.

Signed-off-by: jingfei <jingfei@xiaomi.com>
This commit is contained in:
jingfei
2025-07-10 22:53:57 +08:00
committed by Xiang Xiao
parent a754b73e4c
commit d12cf1cb75
17 changed files with 67 additions and 264 deletions
@@ -119,9 +119,6 @@ static const struct ota_partition_s g_ota_partition_table[] =
static int init_ota_partitions(void)
{
struct mtd_dev_s *mtd;
#ifdef CONFIG_BCH
char blockdev[18];
#endif
int ret = OK;
for (int i = 0; i < nitems(g_ota_partition_table); ++i)
@@ -130,25 +127,13 @@ static int init_ota_partitions(void)
mtd = esp32_spiflash_alloc_mtdpart(part->offset, part->size,
OTA_ENCRYPT);
ret = ftl_initialize(i, mtd);
ret = register_mtddriver(part->devpath, mtd, 0755, NULL);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n",
ret);
return ret;
}
#ifdef CONFIG_BCH
snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", i);
ret = bchdev_register(blockdev, part->devpath, false);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n",
syslog(LOG_ERR, "register_mtddriver %s failed: %d\n",
part->devpath, ret);
return ret;
}
#endif
}
return ret;