This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit d12cf1cb753801a89532f0c90d865de3a1e09be4 Author: jingfei <jing...@xiaomi.com> AuthorDate: Thu Jul 10 22:53:57 2025 +0800 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 <jing...@xiaomi.com> --- .../arm/s32k3xx/mr-canhubk3/src/s32k3xx_bringup.c | 44 ++++++---------------- boards/arm/sama5/sama5d4-ek/Kconfig | 21 +++-------- .../sama5/sama5d4-ek/configs/at25boot/defconfig | 1 - boards/arm/sama5/sama5d4-ek/src/at25_main.c | 4 +- boards/arm/sama5/sama5d4-ek/src/sam_at25.c | 41 ++++---------------- boards/arm/sama5/sama5d4-ek/src/sam_usbmsc.c | 4 +- boards/arm/sama5/sama5d4-ek/src/sama5d4-ek.h | 19 ++-------- boards/arm/samv7/common/src/sam_progmem.c | 27 +++---------- boards/arm/samv7/samv71-xult/src/sam_bringup.c | 29 +++----------- .../stm32l4/stm32l476vg-disco/src/stm32_bringup.c | 26 +++---------- .../common/src/esp32c3_board_spiflash.c | 19 ++-------- .../risc-v/esp32c6/common/src/esp_board_spiflash.c | 20 ++-------- .../xtensa/esp32/common/src/esp32_board_spiflash.c | 19 +--------- boards/z80/ez80/z20x/Kconfig | 15 +------- boards/z80/ez80/z20x/src/ez80_w25.c | 29 ++------------ boards/z80/ez80/z20x/src/w25_main.c | 10 ++--- boards/z80/ez80/z20x/src/z20x.h | 3 +- 17 files changed, 67 insertions(+), 264 deletions(-) diff --git a/boards/arm/s32k3xx/mr-canhubk3/src/s32k3xx_bringup.c b/boards/arm/s32k3xx/mr-canhubk3/src/s32k3xx_bringup.c index d309eefb00e..9a62ba1bd08 100644 --- a/boards/arm/s32k3xx/mr-canhubk3/src/s32k3xx_bringup.c +++ b/boards/arm/s32k3xx/mr-canhubk3/src/s32k3xx_bringup.c @@ -88,12 +88,11 @@ struct mtd_dev_s *g_mtd_fs; int s32k3xx_bringup(void) { int ret = OK; -#if defined(CONFIG_BCH) || defined(HAVE_MX25L_LITTLEFS) +#if defined(HAVE_MX25L_LITTLEFS) char blockdev[32]; -# if !defined(HAVE_MX25L_LITTLEFS) && !defined(HAVE_MX25L_NXFFS) - char chardev[32]; -# endif /* !HAVE_MX25L_LITTLEFS && !HAVE_MX25L_NXFFS */ -#endif /* CONFIG_BCH || HAVE_MX25L_LITTLEFS */ +#elif defined(HAVE_MX25L_CHARDEV) + char mtddev[32]; +#endif /* HAVE_MX25L_LITTLEFS */ #ifdef CONFIG_S32K3XX_LPSPI /* Initialize SPI driver */ @@ -285,38 +284,17 @@ int s32k3xx_bringup(void) } # else /* if defined(HAVE_MX25L_CHARDEV) */ - /* Use the FTL layer to wrap the MTD driver as a block driver */ + /* Use the minor number to create device paths */ - ret = ftl_initialize(MX25L_MTD_MINOR, g_mtd_fs); - if (ret < 0) - { - _err("ftl_initialize() failed: %d\n", ret); - } -# ifdef CONFIG_BCH - else - { - _info("ftl_initialize() successful\n"); - - /* Use the minor number to create device paths */ + snprintf(mtddev, sizeof(mtddev), "/dev/mtd%d", MX25L_MTD_MINOR); - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", - MX25L_MTD_MINOR); - snprintf(chardev, sizeof(chardev), "/dev/mtd%d", - MX25L_MTD_MINOR); + /* Register the MTD driver */ - /* Now create a character device on the block device */ - - ret = bchdev_register(blockdev, chardev, false); - if (ret < 0) - { - _err("bchdev_register %s failed: %d\n", chardev, ret); - } - else - { - _info("bchdev_register %s successful\n", chardev); - } + ret = register_mtddriver(mtddev, g_mtd_fs, 0755, NULL); + if (ret < 0) + { + _err("register_mtddriver for %s failed: %d\n", mtddev, ret); } -# endif /* CONFIG_BCH */ # endif } } diff --git a/boards/arm/sama5/sama5d4-ek/Kconfig b/boards/arm/sama5/sama5d4-ek/Kconfig index 351b9ebc1a8..13fb229e86a 100644 --- a/boards/arm/sama5/sama5d4-ek/Kconfig +++ b/boards/arm/sama5/sama5d4-ek/Kconfig @@ -157,24 +157,15 @@ config SAMA5D4EK_AT25_BLOCKMOUNT choice prompt "AT25 serial FLASH configuration" - default SAMA5D4EK_AT25_FTL + default SAMA5D4EK_AT25_MTD depends on SAMA5D4EK_AT25_BLOCKMOUNT -config SAMA5D4EK_AT25_FTL - bool "Create AT25 Serial FLASH block driver" +config SAMA5D4EK_AT25_MTD + bool "Create AT25 Serial FLASH MTD driver" ---help--- - Create the MTD driver for the AT25 and "wrap" the AT25 as a standard - block driver that could then, for example, be mounted using FAT or - any other file system. Any file system may be used, but there will - be no wear-leveling. - -config SAMA5D4EK_AT25_CHARDEV - bool "Create AT25 Serial FLASH character driver" - ---help--- - Create the MTD driver for the AT25 and "wrap" the AT25 as a standard - character driver that could then, for example, via simple open, close, - read, write file system operations. There will be no wear-leveling - in this configuration. + Create the MTD driver for the AT25 that could then, for example, + be mounted using FAT or any other file system. Any file system may be + used, but there will be no wear-leveling. config SAMA5D4EK_AT25_NXFFS bool "Create AT25 serial FLASH NXFFS file system" diff --git a/boards/arm/sama5/sama5d4-ek/configs/at25boot/defconfig b/boards/arm/sama5/sama5d4-ek/configs/at25boot/defconfig index e2ea1fc2e98..590bfa8115a 100644 --- a/boards/arm/sama5/sama5d4-ek/configs/at25boot/defconfig +++ b/boards/arm/sama5/sama5d4-ek/configs/at25boot/defconfig @@ -39,7 +39,6 @@ CONFIG_RAW_BINARY=y CONFIG_RR_INTERVAL=200 CONFIG_SAMA5D4EK_528MHZ=y CONFIG_SAMA5D4EK_AT25_BLOCKMOUNT=y -CONFIG_SAMA5D4EK_AT25_CHARDEV=y CONFIG_SAMA5D4EK_AT25_MAIN=y CONFIG_SAMA5_DDRCS=y CONFIG_SAMA5_DDRCS_LPDDR2=y diff --git a/boards/arm/sama5/sama5d4-ek/src/at25_main.c b/boards/arm/sama5/sama5d4-ek/src/at25_main.c index 475ac806bfe..61dd7757ad2 100644 --- a/boards/arm/sama5/sama5d4-ek/src/at25_main.c +++ b/boards/arm/sama5/sama5d4-ek/src/at25_main.c @@ -55,8 +55,8 @@ # error CONFIG_SAMA5D4EK_AT25_BLOCKMOUNT must be selected #endif -#ifndef CONFIG_SAMA5D4EK_AT25_CHARDEV -# error CONFIG_SAMA5D4EK_AT25_CHARDEV must be selected +#ifndef CONFIG_SAMA5D4EK_AT25_MTD +# error CONFIG_SAMA5D4EK_AT25_MTD must be selected #endif #ifdef CONFIG_BOOT_SDRAM_DATA diff --git a/boards/arm/sama5/sama5d4-ek/src/sam_at25.c b/boards/arm/sama5/sama5d4-ek/src/sam_at25.c index 6d96d353707..15c12e07ac5 100644 --- a/boards/arm/sama5/sama5d4-ek/src/sam_at25.c +++ b/boards/arm/sama5/sama5d4-ek/src/sam_at25.c @@ -62,11 +62,8 @@ int sam_at25_automount(int minor) { struct spi_dev_s *spi; struct mtd_dev_s *mtd; -#ifdef CONFIG_SAMA5D4EK_AT25_CHARDEV -#if defined(CONFIG_BCH) - char blockdev[18]; - char chardev[12]; -#endif /* defined(CONFIG_BCH) */ +#ifdef CONFIG_SAMA5D4EK_AT25_MTD + char mtddev[12]; #endif static bool initialized = false; int ret; @@ -94,43 +91,19 @@ int sam_at25_automount(int minor) return -ENODEV; } -#if defined(CONFIG_SAMA5D4EK_AT25_FTL) - /* And finally, use the FTL layer to wrap the MTD driver as a block - * driver. - */ - - ret = ftl_initialize(minor, mtd); - if (ret < 0) - { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); - return ret; - } - -#elif defined(CONFIG_SAMA5D4EK_AT25_CHARDEV) - /* Use the FTL layer to wrap the MTD driver as a block driver */ - - ret = ftl_initialize(minor, mtd); - if (ret < 0) - { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); - return ret; - } - -#if defined(CONFIG_BCH) +#if defined(CONFIG_SAMA5D4EK_AT25_MTD) /* Use the minor number to create device paths */ - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", minor); - snprintf(chardev, sizeof(chardev), "/dev/mtd%d", minor); + snprintf(mtddev, sizeof(mtddev), "/dev/mtd%d", minor); - /* Now create a character device on the block device */ + /* Register the MTD driver */ - ret = bchdev_register(blockdev, chardev, false); + ret = register_mtddriver(mtddev, mtd, 0755, NULL); if (ret < 0) { - ferr("ERROR: bchdev_register %s failed: %d\n", chardev, ret); + ferr("register_mtddriver %s failed: %d\n", mtddev, ret); return ret; } -#endif /* defined(CONFIG_BCH) */ #elif defined(CONFIG_SAMA5D4EK_AT25_NXFFS) /* Initialize to provide NXFFS on the MTD interface */ diff --git a/boards/arm/sama5/sama5d4-ek/src/sam_usbmsc.c b/boards/arm/sama5/sama5d4-ek/src/sam_usbmsc.c index e6fdc915bfa..16fe2e2f7dc 100644 --- a/boards/arm/sama5/sama5d4-ek/src/sam_usbmsc.c +++ b/boards/arm/sama5/sama5d4-ek/src/sam_usbmsc.c @@ -46,8 +46,8 @@ # error AT25 Serial FLASH not supported #endif -#ifndef CONFIG_SAMA5D4EK_AT25_FTL -# error AT25 FTL support required (CONFIG_SAMA5D4EK_AT25_FTL) +#ifndef CONFIG_SAMA5D4EK_AT25_MTD +# error AT25 MTD support required (CONFIG_SAMA5D4EK_AT25_MTD) # undef HAVE_AT25 #endif diff --git a/boards/arm/sama5/sama5d4-ek/src/sama5d4-ek.h b/boards/arm/sama5/sama5d4-ek/src/sama5d4-ek.h index 591451da254..d5a379f3604 100644 --- a/boards/arm/sama5/sama5d4-ek/src/sama5d4-ek.h +++ b/boards/arm/sama5/sama5d4-ek/src/sama5d4-ek.h @@ -152,25 +152,12 @@ # undef CONFIG_SAMA5D4EK_AT25_NXFFS #endif -#if !defined(CONFIG_SAMA5D4EK_AT25_FTL) && !defined(CONFIG_SAMA5D4EK_AT25_CHARDEV) && \ - !defined(CONFIG_SAMA5D4EK_AT25_NXFFS) +#if !defined(CONFIG_SAMA5D4EK_AT25_MTD) && !defined(CONFIG_SAMA5D4EK_AT25_NXFFS) # undef HAVE_AT25 #endif -#if defined(CONFIG_SAMA5D4EK_AT25_FTL) && defined(CONFIG_SAMA5D4EK_AT25_CHARDEV) -# warning Both CONFIG_SAMA5D4EK_AT25_CHARDEV and CONFIG_SAMA5D4EK_AT25_FTL are set -# warning Ignoring CONFIG_SAMA5D4EK_AT25_FTL -# undef CONFIG_SAMA5D4EK_AT25_FTL -#endif - -#if defined(CONFIG_SAMA5D4EK_AT25_FTL) && defined(CONFIG_SAMA5D4EK_AT25_NXFFS) -# warning Both CONFIG_SAMA5D4EK_AT25_FTL and CONFIG_SAMA5D4EK_AT25_NXFFS are set -# warning Ignoring CONFIG_SAMA5D4EK_AT25_NXFFS -# undef CONFIG_SAMA5D4EK_AT25_NXFFS -#endif - -#if defined(CONFIG_SAMA5D4EK_AT25_CHARDEV) && defined(CONFIG_SAMA5D4EK_AT25_NXFFS) -# warning Both CONFIG_SAMA5D4EK_AT25_CHARDEV and CONFIG_SAMA5D4EK_AT25_NXFFS are set +#if defined(CONFIG_SAMA5D4EK_AT25_MTD) && defined(CONFIG_SAMA5D4EK_AT25_NXFFS) +# warning Both CONFIG_SAMA5D4EK_AT25_MTD and CONFIG_SAMA5D4EK_AT25_NXFFS are set # warning Ignoring CONFIG_SAMA5D4EK_AT25_NXFFS # undef CONFIG_SAMA5D4EK_AT25_NXFFS #endif diff --git a/boards/arm/samv7/common/src/sam_progmem.c b/boards/arm/samv7/common/src/sam_progmem.c index eaab00c4ffa..77832c2224a 100644 --- a/boards/arm/samv7/common/src/sam_progmem.c +++ b/boards/arm/samv7/common/src/sam_progmem.c @@ -66,40 +66,25 @@ static int sam_progmem_register_driver(int minor, struct mtd_dev_s *mtd, const char *devpath) { -#ifdef CONFIG_BCH - char blockdev[18]; - char chardev[12]; -#endif + char mtddev[12]; int ret = OK; - /* Use the FTL layer to wrap the MTD driver as a block driver */ - - ret = ftl_initialize(minor, mtd); - if (ret < 0) - { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); - return ret; - } - -#ifdef CONFIG_BCH /* Use the minor number to create device paths */ - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", minor); if (devpath == NULL) { - snprintf(chardev, sizeof(chardev), "/dev/mtd%d", minor); - devpath = chardev; + snprintf(mtddev, sizeof(mtddev), "/dev/mtd%d", minor); + devpath = mtddev; } - /* Now create a character device on the block device */ + /* Register the MTD driver */ - ret = bchdev_register(blockdev, devpath, false); + ret = register_mtddriver(devpath, mtd, 0755, NULL); if (ret < 0) { - ferr("ERROR: bchdev_register %s failed: %d\n", devpath, ret); + ferr("ERROR: register_mtddriver %s failed: %d\n", devpath, ret); return ret; } -#endif return ret; } diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c b/boards/arm/samv7/samv71-xult/src/sam_bringup.c index 06e32bc0889..7053c515799 100644 --- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c +++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c @@ -218,10 +218,7 @@ int sam_bringup(void) struct i2c_master_s *i2c; #endif #if defined(HAVE_S25FL1_CHARDEV) -#if defined(CONFIG_BCH) - char blockdev[18]; - char chardev[12]; -#endif /* defined(CONFIG_BCH) */ + char mtddev[12]; #endif int ret; @@ -457,33 +454,19 @@ int sam_bringup(void) } #else /* if defined(HAVE_S25FL1_CHARDEV) */ - /* Use the FTL layer to wrap the MTD driver as a block driver */ - - ret = ftl_initialize(S25FL1_MTD_MINOR, mtd); - if (ret < 0) - { - syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n", - ret); - return ret; - } - -#if defined(CONFIG_BCH) /* Use the minor number to create device paths */ - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", - S25FL1_MTD_MINOR); - snprintf(chardev, sizeof(chardev), "/dev/mtd%d", S25FL1_MTD_MINOR); + snprintf(mtddev, sizeof(mtddev), "/dev/mtd%d", S25FL1_MTD_MINOR); - /* Now create a character device on the block device */ + /* Register the MTD driver */ - ret = bchdev_register(blockdev, chardev, false); + ret = register_mtddriver(mtddev, mtd, 0755, NULL); if (ret < 0) { - syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n", - chardev, ret); + syslog(LOG_ERR, "ERROR: register_mtddriver %s failed: %d\n", + mtddev, ret); return ret; } -#endif /* defined(CONFIG_BCH) */ #endif } #endif diff --git a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_bringup.c b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_bringup.c index cc2e99112f1..0246af3fa9b 100644 --- a/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_bringup.c +++ b/boards/arm/stm32l4/stm32l476vg-disco/src/stm32_bringup.c @@ -106,10 +106,7 @@ int stm32_bringup(void) struct mtd_dev_s *mtd_temp; #endif #if defined(HAVE_N25QXXX_CHARDEV) -#if defined(CONFIG_BCH) - char blockdev[18]; - char chardev[12]; -#endif /* defined(CONFIG_BCH) */ + char mtddev[12]; #endif int ret = OK; @@ -231,31 +228,18 @@ int stm32_bringup(void) } #else /* if defined(HAVE_N25QXXX_CHARDEV) */ - /* Use the FTL layer to wrap the MTD driver as a block driver */ - - ret = ftl_initialize(N25QXXX_MTD_MINOR, g_mtd_fs); - if (ret < 0) - { - _err("ERROR: Failed to initialize the FTL layer: %d\n", ret); - return ret; - } - -#if defined(CONFIG_BCH) /* Use the minor number to create device paths */ - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", - N25QXXX_MTD_MINOR); - snprintf(chardev, sizeof(chardev), "/dev/mtd%d", N25QXXX_MTD_MINOR); + snprintf(mtddev, sizeof(mtddev), "/dev/mtd%d", N25QXXX_MTD_MINOR); - /* Now create a character device on the block device */ + /* Register the MTD driver */ - ret = bchdev_register(blockdev, chardev, false); + ret = register_mtddriver(mtddev, g_mtd_fs, 0755, NULL); if (ret < 0) { - _err("ERROR: bchdev_register %s failed: %d\n", chardev, ret); + _err("ERROR: register_mtddriver %s failed: %d\n", mtddev, ret); return ret; } -#endif /* defined(CONFIG_BCH) */ #endif } #endif diff --git a/boards/risc-v/esp32c3-legacy/common/src/esp32c3_board_spiflash.c b/boards/risc-v/esp32c3-legacy/common/src/esp32c3_board_spiflash.c index abe945fbce5..d3d05d2c02d 100644 --- a/boards/risc-v/esp32c3-legacy/common/src/esp32c3_board_spiflash.c +++ b/boards/risc-v/esp32c3-legacy/common/src/esp32c3_board_spiflash.c @@ -138,9 +138,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) @@ -149,23 +146,13 @@ static int init_ota_partitions(void) mtd = esp32c3_spiflash_alloc_mtdpart(part->offset, part->size, OTA_ENCRYPT); - ret = ftl_initialize(i, mtd); - if (ret < 0) - { - ferr("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); + ret = register_mtddriver(part->devpath, mtd, 0755, NULL); if (ret < 0) { - ferr("ERROR: bchdev_register %s failed: %d\n", part->devpath, ret); + ferr("ERROR: register_mtddriver %s failed: %d\n", + part->devpath, ret); return ret; } -#endif } return ret; diff --git a/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c b/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c index cbd7bf6d8e0..c12abc3aa82 100644 --- a/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c +++ b/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c @@ -125,32 +125,18 @@ static int init_ota_partitions(void) int ret = OK; int i; -#ifdef CONFIG_BCH - char blockdev[18]; -#endif - for (i = 0; i < nitems(g_ota_partition_table); ++i) { const struct ota_partition_s *part = &g_ota_partition_table[i]; mtd = esp_spiflash_alloc_mtdpart(part->offset, part->size); - ret = ftl_initialize(i, mtd); + ret = register_mtddriver(part->devpath, mtd, 0755, NULL); if (ret < 0) { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); + ferr("ERROR: register_mtddriver %s failed: %d\n", + part->devpath, ret); return ret; } - -#ifdef CONFIG_BCH - snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", i); - - ret = bchdev_register(blockdev, part->devpath, false); - if (ret < 0) - { - ferr("ERROR: bchdev_register %s failed: %d\n", part->devpath, ret); - return ret; - } -#endif } return ret; diff --git a/boards/xtensa/esp32/common/src/esp32_board_spiflash.c b/boards/xtensa/esp32/common/src/esp32_board_spiflash.c index 54683343a07..60b9179426d 100644 --- a/boards/xtensa/esp32/common/src/esp32_board_spiflash.c +++ b/boards/xtensa/esp32/common/src/esp32_board_spiflash.c @@ -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); - 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); + ret = register_mtddriver(part->devpath, mtd, 0755, NULL); 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; diff --git a/boards/z80/ez80/z20x/Kconfig b/boards/z80/ez80/z20x/Kconfig index 3277cec34e8..9cff4920599 100644 --- a/boards/z80/ez80/z20x/Kconfig +++ b/boards/z80/ez80/z20x/Kconfig @@ -68,22 +68,11 @@ config Z20X_W25_PROGSIZE this program must run from SRAM, there would be no purpose int making this size any larger than the size of the internal SRAM. -choice - prompt "Winbond W25 Usage" - default Z20X_W25_CHARDEV - depends on EZ80_SPI && MTD_W25 - config Z20X_W25_CHARDEV bool "Character device" + depends on EZ80_SPI && MTD_W25 select BCH - -config Z20X_W25_BLOCKDEV - bool "Block device" - -config Z20X_W25_MTDDEV - bool "MTD device" - -endchoice + default y config Z20X_W25_MINOR int "W25 device minor number" diff --git a/boards/z80/ez80/z20x/src/ez80_w25.c b/boards/z80/ez80/z20x/src/ez80_w25.c index 218c290f2e7..fa01f1da49e 100644 --- a/boards/z80/ez80/z20x/src/ez80_w25.c +++ b/boards/z80/ez80/z20x/src/ez80_w25.c @@ -74,37 +74,14 @@ int ez80_w25_initialize(int minor) return -ENODEV; } -#if defined(CONFIG_Z20X_W25_BLOCKDEV) - /* Use the FTL layer to wrap the MTD driver as a block driver. */ + /* Register the MTD driver */ - ret = ftl_initialize(minor, mtd); + ret = register_mtddriver(W25_DEV, mtd, 0755, NULL); if (ret < 0) { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); + ferr("ERROR: register_mtddriver %s failed: %d\n", W25_DEV, ret); return ret; } -#elif defined(CONFIG_Z20X_W25_CHARDEV) - /* Use the FTL layer to wrap the MTD driver as a block driver */ - - ret = ftl_initialize(minor, mtd); - if (ret < 0) - { - ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); - return ret; - } - -#if defined(CONFIG_BCH) - /* Create a character device on the block device */ - - ret = bchdev_register(W25_BLOCKDEV, W25_CHARDEV, false); - if (ret < 0) - { - ferr("ERROR: bchdev_register %s failed: %d\n", W25_CHARDEV, ret); - return ret; - } -#endif /* defined(CONFIG_BCH) */ -#endif - return OK; } diff --git a/boards/z80/ez80/z20x/src/w25_main.c b/boards/z80/ez80/z20x/src/w25_main.c index 392521db73f..e54565c55d4 100644 --- a/boards/z80/ez80/z20x/src/w25_main.c +++ b/boards/z80/ez80/z20x/src/w25_main.c @@ -103,11 +103,11 @@ static int w25_read_hex(FAR uint24_t *len) /* Open the W25 device for writing */ - fd = open(W25_CHARDEV, O_WRONLY); + fd = open(W25_DEV, O_WRONLY); if (fd < 0) { ret = -errno; - fprintf(stderr, "ERROR: Failed to open %s: %d\n", W25_CHARDEV, ret); + fprintf(stderr, "ERROR: Failed to open %s: %d\n", W25_DEV, ret); return ret; } @@ -206,11 +206,11 @@ static int w25_write_binary(FAR const struct prog_header_s *hdr) /* Open the W25 device for writing */ - fd = open(W25_CHARDEV, O_WRONLY); + fd = open(W25_DEV, O_WRONLY); if (fd < 0) { ret = -errno; - fprintf(stderr, "ERROR: Failed to open %s: %d\n", W25_CHARDEV, ret); + fprintf(stderr, "ERROR: Failed to open %s: %d\n", W25_DEV, ret); return ret; } @@ -290,7 +290,7 @@ static int w25_read_binary(FAR struct prog_header_s *hdr) /* Open the W25 device for reading */ - fd = open(W25_CHARDEV, O_RDONLY); + fd = open(W25_DEV, O_RDONLY); if (fd < 0) { ret = -errno; diff --git a/boards/z80/ez80/z20x/src/z20x.h b/boards/z80/ez80/z20x/src/z20x.h index 3b9c8e255eb..8c7c1ae83e5 100644 --- a/boards/z80/ez80/z20x/src/z20x.h +++ b/boards/z80/ez80/z20x/src/z20x.h @@ -154,8 +154,7 @@ extern uint8_t _progend[]; #define __STR(s) #s #define __XSTR(s) __STR(s) -#define W25_CHARDEV "/dev/mtd" __XSTR(CONFIG_Z20X_W25_MINOR) -#define W25_BLOCKDEV "/dev/mtdblock" __XSTR(CONFIG_Z20X_W25_MINOR) +#define W25_DEV "/dev/mtd" __XSTR(CONFIG_Z20X_W25_MINOR) /**************************************************************************** * Public Function Prototypes