From 273222c06ea4b96b7e2ab8cfa18a8538ea0140b5 Mon Sep 17 00:00:00 2001 From: zhaoxingyu1 Date: Tue, 29 Apr 2025 10:22:05 +0800 Subject: [PATCH] mtdconfig: modify mtdconfig kconfig change filename mtd/mtd_config_fs.c to mtd/mtd_config_nvs.c and optimize the configuration related to mtdconfig Signed-off-by: zhaoxingyu1 --- boards/arm/stm32wl5/nucleo-wl55jc/Kconfig | 8 ++--- .../nucleo-wl55jc/configs/demo/defconfig | 1 + .../configs/nvcfgdata/defconfig | 1 - drivers/mtd/CMakeLists.txt | 4 +-- drivers/mtd/Kconfig | 33 +++++++++++-------- drivers/mtd/Make.defs | 4 +-- .../mtd/{mtd_config_fs.c => mtd_config_nvs.c} | 2 +- 7 files changed, 30 insertions(+), 23 deletions(-) rename drivers/mtd/{mtd_config_fs.c => mtd_config_nvs.c} (99%) diff --git a/boards/arm/stm32wl5/nucleo-wl55jc/Kconfig b/boards/arm/stm32wl5/nucleo-wl55jc/Kconfig index bc565d72d9c..6fbb8b4cb12 100644 --- a/boards/arm/stm32wl5/nucleo-wl55jc/Kconfig +++ b/boards/arm/stm32wl5/nucleo-wl55jc/Kconfig @@ -271,7 +271,7 @@ config ARCH_BOARD_FLASH_PART1_FS_SMARTFS is absolute minimum (so a 16KiB!). config ARCH_BOARD_FLASH_PART1_FS_MTDCONFIG - select MTD_CONFIG + depends on !MTD_CONFIG_NONE bool "mtdconfig" ---help--- Purpose build filesystem to hold application's configuration. @@ -319,7 +319,7 @@ config ARCH_BOARD_FLASH_PART2_FS_SMARTFS bool "smartfs" config ARCH_BOARD_FLASH_PART2_FS_MTDCONFIG - select MTD_CONFIG + depends on !MTD_CONFIG_NONE bool "mtdconfig" endchoice # Filesystem of user partition 2 @@ -362,7 +362,7 @@ config ARCH_BOARD_FLASH_PART3_FS_SMARTFS bool "smartfs" config ARCH_BOARD_FLASH_PART3_FS_MTDCONFIG - select MTD_CONFIG + depends on !MTD_CONFIG_NONE bool "mtdconfig" endchoice # Filesystem of user partition 3 @@ -405,7 +405,7 @@ config ARCH_BOARD_FLASH_PART4_FS_SMARTFS bool "smartfs" config ARCH_BOARD_FLASH_PART4_FS_MTDCONFIG - select MTD_CONFIG + depends on !MTD_CONFIG_NONE bool "mtdconfig" endchoice # Filesystem of user partition 4 diff --git a/boards/arm/stm32wl5/nucleo-wl55jc/configs/demo/defconfig b/boards/arm/stm32wl5/nucleo-wl55jc/configs/demo/defconfig index ba1b1efb255..38f878be55e 100644 --- a/boards/arm/stm32wl5/nucleo-wl55jc/configs/demo/defconfig +++ b/boards/arm/stm32wl5/nucleo-wl55jc/configs/demo/defconfig @@ -40,6 +40,7 @@ CONFIG_INPUT=y CONFIG_INPUT_BUTTONS=y CONFIG_INPUT_BUTTONS_LOWER=y CONFIG_LPUART1_SERIAL_CONSOLE=y +CONFIG_MTD_CONFIG=y CONFIG_MTD_CONFIG_NAMED=y CONFIG_MTD_SMART_SECTOR_SIZE=2048 CONFIG_NSH_ARCHINIT=y diff --git a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig index 50a8d39cde1..306f4f2fcb8 100644 --- a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig +++ b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig @@ -31,7 +31,6 @@ CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_PERROR_STDOUT=y CONFIG_LIBC_STRERROR=y CONFIG_MTD_CONFIG=y -CONFIG_MTD_CONFIG_FAIL_SAFE=y CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/drivers/mtd/CMakeLists.txt b/drivers/mtd/CMakeLists.txt index e1c128fa446..aef546411ef 100644 --- a/drivers/mtd/CMakeLists.txt +++ b/drivers/mtd/CMakeLists.txt @@ -23,8 +23,8 @@ if(CONFIG_MTD) set(SRCS ftl.c) - if(CONFIG_MTD_CONFIG_FAIL_SAFE) - list(APPEND SRCS mtd_config_fs.c) + if(CONFIG_MTD_CONFIG_NVS) + list(APPEND SRCS mtd_config_nvs.c) elseif(CONFIG_MTD_CONFIG) list(APPEND SRCS mtd_config.c) endif() diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index a10ff88157c..6c0a9066118 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -142,14 +142,29 @@ if MTD_PROGMEM endif #MTD_PROGMEM +choice + prompt "Select MTD config solution" + default MTD_CONFIG_NONE + config MTD_CONFIG bool "Enable Dev Config (MTD based) device" - default n ---help--- Provides a /dev/config device for saving / restoring application configuration data to a standard MTD device or partition. -if MTD_CONFIG +config MTD_CONFIG_NVS + bool "NVS" + ---help--- + NVS is a lightweight KV storage mechanism which supports classical + on-chip NorFlash, it implements basic KV write, read, and delete + functions, and supports power down protection. + +config MTD_CONFIG_NONE + bool "None MTD config" + +endchoice + +if !MTD_CONFIG_NONE config MTD_CONFIG_RAM_CONSOLIDATE bool "Always use RAM consolidation method (work in progress)" @@ -186,30 +201,22 @@ config MTD_CONFIG_NAME_LEN ---help--- Sets the maximum length of config item names. -config MTD_CONFIG_FAIL_SAFE - bool "Enable Fail Safe MTD Config" - default n - ---help--- - Enable the new storage layout to support the resilient to power loss. - This replaces the drivers/mtd/mtd_config, which - is resilient to power loss. - config MTD_CONFIG_BLOCKSIZE_MULTIPLE int "Set NVS blocksize multiple" default 1 - depends on MTD_CONFIG_FAIL_SAFE + depends on MTD_CONFIG_NVS ---help--- The size of a multiple of blocksize compared to erasize config MTD_CONFIG_CACHE_SIZE int "Non-volatile Storage lookup cache size" default 0 - depends on MTD_CONFIG_FAIL_SAFE + depends on MTD_CONFIG_NVS help Number of entries in Non-volatile Storage lookup cache. It is recommended that it be a power of 2. -endif # MTD_CONFIG +endif comment "MTD Device Drivers" diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs index ccf74e60736..4dc3f37c6b2 100644 --- a/drivers/mtd/Make.defs +++ b/drivers/mtd/Make.defs @@ -31,8 +31,8 @@ ifeq ($(CONFIG_MTD),y) CSRCS += ftl.c -ifeq ($(CONFIG_MTD_CONFIG_FAIL_SAFE),y) -CSRCS += mtd_config_fs.c +ifeq ($(CONFIG_MTD_CONFIG_NVS),y) +CSRCS += mtd_config_nvs.c else ifeq ($(CONFIG_MTD_CONFIG),y) CSRCS += mtd_config.c endif diff --git a/drivers/mtd/mtd_config_fs.c b/drivers/mtd/mtd_config_nvs.c similarity index 99% rename from drivers/mtd/mtd_config_fs.c rename to drivers/mtd/mtd_config_nvs.c index e19821f2f0e..adf66be7721 100644 --- a/drivers/mtd/mtd_config_fs.c +++ b/drivers/mtd/mtd_config_nvs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/mtd/mtd_config_fs.c + * drivers/mtd/mtd_config_nvs.c * * SPDX-License-Identifier: Apache-2.0 * SPDX-FileCopyrightText: 2018 Laczen