Skip to content

Conversation

@zhaoxingyu12
Copy link
Contributor

@zhaoxingyu12 zhaoxingyu12 commented Jan 19, 2026

Note: Please adhere to Contributing Guidelines.

Summary

Optimize mtdconfig related modules

  1. change filename mtd_config_fs to mtd_config_nvs
  2. change kconfig MTD_CONFIG_FAIL_SAFE to MTD_CONFIG_NVS
  3. other changes related to the name MTD_CONFIG_FAIL_SAFE

Impact

KV read and write functions

Testing

testcases
`
int print_list(void)
{
int fd = open("/dev/nvs", O_RDONLY);

uint8_t buf[255];
struct config_data_s data;
int ret;

data.configdata = buf;
data.len = 255;
ret = ioctl(fd, CFGDIOC_FIRSTCONFIG, &data);
if (ret < 0)
    return ret;

#ifdef CONFIG_MTD_CONFIG_NAMED
syslog(0, "######## key=%s, value=%s", data.name, data.configdata);
#else
syslog(0, "######## id=%d, instance=%d, value=%s", data.id, data.instance, data.configdata);
#endif

while (1) {
    data.configdata = buf;
    data.len = 255;
    ret = ioctl(fd, CFGDIOC_NEXTCONFIG, &data);
    if (ret < 0) {
        ret = -errno;

        /* ENOENT is expected when there are no more entries */

        if (ret == -ENOENT)
            ret = 0;

        break;
    }

#ifdef CONFIG_MTD_CONFIG_NAMED
syslog(0, "######## key=%s, value=%s", data.name, data.configdata);
#else
syslog(0, "######## id=%d, instance=%d, value=%s", data.id, data.instance, data.configdata);
#endif
}

close(fd);
return ret;

}

void test(void)
{
uint64_t filling_id = 0;
struct config_data_s data;
int ret;

int fd = open("/dev/nvs", O_RDWR);
while (1)
  {
  
  uint8_t wr_buf[50] = {0};
  uint8_t wr_buf1[50] = {0};
  snprintf(wr_buf, sizeof(wr_buf), "v----------------------------%llx", filling_id);

#ifdef CONFIG_MTD_CONFIG_NAMED
char rd_buf[10] = {0};

  snprintf(rd_buf, sizeof(rd_buf), "k%llx", filling_id);  
  strlcpy(data.name, rd_buf, sizeof(data.name));

#else
data.id = (uint16_t)filling_id;
data.instance = (int)filling_id + 1;
#endif
data.configdata = wr_buf;
data.len = sizeof(wr_buf);
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);

   if (ret != 0)
     {
       return;
     }

  data.configdata = wr_buf1;
  ret = ioctl(fd, CFGDIOC_GETCONFIG, &data);

   if (ret < 0)
     {
       assert(0);
     }

   if (memcmp(wr_buf, wr_buf1, sizeof(wr_buf)) != 0)
     {
       assert(0);
     }

   filling_id++;
  }
close(fd);

}

int main(int argc, FAR char *argv[])
{
test();
print_list();
return 0;
}
`

test result
[ 3.724800] [core0] ######## key=k28, value=v----------------------------28
[ 3.725400] [core0] ######## key=k27, value=v----------------------------27
[ 3.726000] [core0] ######## key=k26, value=v----------------------------26
[ 3.726600] [core0] ######## key=k25, value=v----------------------------25
[ 3.727100] [core0] ######## key=k24, value=v----------------------------24
[ 3.727700] [core0] ######## key=k23, value=v----------------------------23
[ 3.728300] [core0] ######## key=k22, value=v----------------------------22
[ 3.728800] [core0] ######## key=k21, value=v----------------------------21
[ 3.729400] [core0] ######## key=k20, value=v----------------------------20
[ 3.729900] [core0] ######## key=k1f, value=v----------------------------1f
[ 3.730500] [core0] ######## key=k1e, value=v----------------------------1e
[ 3.731200] [core0] ######## key=k1d, value=v----------------------------1d
[ 3.731800] [core0] ######## key=k1c, value=v----------------------------1c
[ 3.732500] [core0] ######## key=k1b, value=v----------------------------1b
[ 3.733100] [core0] ######## key=k1a, value=v----------------------------1a
[ 3.733700] [core0] ######## key=k19, value=v----------------------------19
[ 3.734300] [core0] ######## key=k18, value=v----------------------------18
[ 3.734800] [core0] ######## key=k17, value=v----------------------------17
[ 3.735400] [core0] ######## key=k16, value=v----------------------------16
[ 3.736100] [core0] ######## key=k15, value=v----------------------------15
[ 3.736700] [core0] ######## key=k14, value=v----------------------------14
[ 3.737300] [core0] ######## key=k13, value=v----------------------------13
[ 3.737700] [core0] ######## key=k12, value=v----------------------------12
[ 3.738200] [core0] ######## key=k11, value=v----------------------------11
[ 3.738700] [core0] ######## key=k10, value=v----------------------------10
[ 3.739100] [core0] ######## key=kf, value=v----------------------------f
[ 3.739600] [core0] ######## key=ke, value=v----------------------------e
[ 3.740100] [core0] ######## key=kd, value=v----------------------------d
[ 3.740600] [core0] ######## key=kc, value=v----------------------------c
[ 3.741100] [core0] ######## key=kb, value=v----------------------------b
[ 3.741700] [core0] ######## key=ka, value=v----------------------------a
[ 3.742100] [core0] ######## key=k9, value=v----------------------------9
[ 3.742600] [core0] ######## key=k8, value=v----------------------------8
[ 3.743100] [core0] ######## key=k7, value=v----------------------------7
[ 3.743500] [core0] ######## key=k6, value=v----------------------------6
[ 3.744000] [core0] ######## key=k5, value=v----------------------------5
[ 3.744500] [core0] ######## key=k4, value=v----------------------------4
[ 3.744900] [core0] ######## key=k3, value=v----------------------------3
[ 3.745400] [core0] ######## key=k2, value=v----------------------------2
[ 3.746000] [core0] ######## key=k1, value=v----------------------------1
[ 3.747300] [core0] ######## key=k0, value=v----------------------------0
[ 3.748300] [core0] ######## key=k29, value=v----------------------------29
[ 3.748700] [core0] ######## key=k2a, value=v----------------------------2a
[ 3.749300] [core0] ######## key=k2b, value=v----------------------------2b
[ 3.749800] [core0] ######## key=k2c, value=v----------------------------2c
[ 3.750300] [core0] ######## key=k2d, value=v----------------------------2d
[ 3.751000] [core0] ######## key=k2e, value=v----------------------------2e
[ 3.751600] [core0] ######## key=k2f, value=v----------------------------2f
[ 3.752200] [core0] ######## key=k30, value=v----------------------------30
[ 3.752700] [core0] ######## key=k31, value=v----------------------------31
[ 3.753300] [core0] ######## key=k32, value=v----------------------------32
[ 3.753800] [core0] ######## key=k33, value=v----------------------------33
[ 3.754300] [core0] ######## key=k34, value=v----------------------------34
[ 3.754900] [core0] ######## key=k35, value=v----------------------------35
[ 3.755400] [core0] ######## key=k36, value=v----------------------------36
[ 3.756100] [core0] ######## key=k37, value=v----------------------------37
[ 3.756600] [core0] ######## key=k38, value=v----------------------------38
[ 3.757200] [core0] ######## key=k39, value=v----------------------------39
[ 3.757700] [core0] ######## key=k3a, value=v----------------------------3a
[ 3.758200] [core0] ######## key=k3b, value=v----------------------------3b
[ 3.758800] [core0] ######## key=k3c, value=v----------------------------3c
[ 3.759300] [core0] ######## key=k3d, value=v----------------------------3d
[ 3.759800] [core0] ######## key=k3e, value=v----------------------------3e
[ 3.760300] [core0] ######## key=k3f, value=v----------------------------3f
[ 3.761100] [core0] ######## key=k40, value=v----------------------------40
[ 3.761700] [core0] ######## key=k41, value=v----------------------------41
[ 3.762200] [core0] ######## key=k42, value=v----------------------------42
[ 3.762700] [core0] ######## key=k43, value=v----------------------------43
[ 3.763200] [core0] ######## key=k44, value=v----------------------------44
[ 3.763800] [core0] ######## key=k45, value=v----------------------------45
[ 3.764300] [core0] ######## key=k46, value=v----------------------------46
[ 3.764800] [core0] ######## key=k47, value=v----------------------------47
[ 3.765400] [core0] ######## key=k48, value=v----------------------------48
[ 3.766000] [core0] ######## key=k49, value=v----------------------------49
[ 3.766600] [core0] ######## key=k4a, value=v----------------------------4a
[ 3.767100] [core0] ######## key=k4b, value=v----------------------------4b
[ 3.767600] [core0] ######## key=k4c, value=v----------------------------4c
[ 3.768200] [core0] ######## key=k4d, value=v----------------------------4d
[ 3.768800] [core0] ######## key=k4e, value=v----------------------------4e
[ 3.769300] [core0] ######## key=k4f, value=v----------------------------4f
[ 3.769900] [core0] ######## key=k50, value=v----------------------------50
[ 3.771100] [core0] ######## key=k51, value=v----------------------------51

@github-actions github-actions bot added Area: Drivers Drivers issues Area: File System File System issues Board: arm Board: risc-v Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Jan 19, 2026
@Laczen
Copy link
Contributor

Laczen commented Jan 19, 2026

@zhaoxingyu12 does NuttX have the possibility to distinguish between devices that require erase and devices that don't? Even for devices that do not require erase the benefits of zms over nvs (emulating a erase by writing 0xff) is very limited. I am unsure that the addition of zms (with associated maintenance) can be justified.

@zhaoxingyu12 zhaoxingyu12 reopened this Jan 20, 2026
@zhaoxingyu12 zhaoxingyu12 changed the title add zms module for RRAM storage device Optimization of mtdconfig module Jan 20, 2026
@github-actions github-actions bot added the Size: M The size of the change in this PR is medium label Jan 20, 2026
@xiaoxiang781216
Copy link
Contributor

@zhaoxingyu12 does NuttX have the possibility to distinguish between devices that require erase and devices that don't? Even for devices that do not require erase the benefits of zms over nvs (emulating a erase by writing 0xff) is very limited. I am unsure that the addition of zms (with associated maintenance) can be justified.

@Laczen you can check whether mtd driver implement mtd_dev_s::erase.

@Laczen
Copy link
Contributor

Laczen commented Jan 20, 2026

@zhaoxingyu12 does NuttX have the possibility to distinguish between devices that require erase and devices that don't? Even for devices that do not require erase the benefits of zms over nvs (emulating a erase by writing 0xff) is very limited. I am unsure that the addition of zms (with associated maintenance) can be justified.

@Laczen you can check whether mtd driver implement mtd_dev_s::erase.

@xiaoxiang781216 this could be done, but this might break other drivers. E.g. the rwbuffer directly calls the underlying mtd_erase method.

@jerpelea jerpelea changed the title Optimization of mtdconfig module drivers/mtd: Optimization of mtdconfig module Jan 20, 2026
@xiaoxiang781216
Copy link
Contributor

@zhaoxingyu12 does NuttX have the possibility to distinguish between devices that require erase and devices that don't? Even for devices that do not require erase the benefits of zms over nvs (emulating a erase by writing 0xff) is very limited. I am unsure that the addition of zms (with associated maintenance) can be justified.

@Laczen you can check whether mtd driver implement mtd_dev_s::erase.

@xiaoxiang781216 this could be done, but this might break other drivers. E.g. the rwbuffer directly calls the underlying mtd_erase method.

All places already add the check, I think. @zhaoxingyu12 please confirm this.

guohao15 and others added 2 commits January 20, 2026 17:47
improve the speed of finding the target ate

Signed-off-by: guohao15 <guohao15@xiaomi.com>
change filename  mtd/mtd_config_fs.c to mtd/mtd_config_nvs.c
and optimize the configuration related to mtdconfig

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
guohao15 and others added 3 commits January 20, 2026 17:47
For nvs test in qemu

Signed-off-by: guohao15 <guohao15@xiaomi.com>
The structure of mtd_config in Kconfig has changed.

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
…y_path api

mtd_config/mtd_config_nvs should all support
mtdconfig_register_by_path/mtdconfig_unregister_by_path api

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
For the MTD_CONFIG configuration item in
drivers/mtd/Kconfig has changed.

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
@xiaoxiang781216
Copy link
Contributor

@zhaoxingyu12 please fix the following error:

====================================================================================
Configuration/Tool: esp32c3-legacy-devkit/nvcfgdata
2026-01-20 13:56:42
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
  [1/1] Normalize esp32c3-legacy-devkit/nvcfgdata
46d45
< CONFIG_SYSTEM_CFGDATA=y
48d46
< CONFIG_TESTING_MTD_CONFIG_FAIL_SAFE=y
Saving the new configuration file
HEAD detached at pull/18024/merge
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig

@michallenc
Copy link
Contributor

Shouldn't this be marked as breaking because of MTD_CONFIG_FAIL_SAFE removal?

@zhaoxingyu12
Copy link
Contributor Author

zhaoxingyu12 commented Jan 20, 2026

@zhaoxingyu12 please fix the following error:

====================================================================================
Configuration/Tool: esp32c3-legacy-devkit/nvcfgdata
2026-01-20 13:56:42
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
  [1/1] Normalize esp32c3-legacy-devkit/nvcfgdata
46d45
< CONFIG_SYSTEM_CFGDATA=y
48d46
< CONFIG_TESTING_MTD_CONFIG_FAIL_SAFE=y
Saving the new configuration file
HEAD detached at pull/18024/merge
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig

Does it mean to remove these two configs in boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/configs/nvcfgdata/defconfig?
CONFIG_SYSTEM_CFGDATA=y
CONFIG_TESTING_MTD_CONFIG_FAIL_SAFE=y

i think #18024 and apache/nuttx-apps#3344 compiling together can fix it . but i dont know how to put the nuttx and nuttx-apps cict together

@zhaoxingyu12
Copy link
Contributor Author

@zhaoxingyu12 does NuttX have the possibility to distinguish between devices that require erase and devices that don't? Even for devices that do not require erase the benefits of zms over nvs (emulating a erase by writing 0xff) is very limited. I am unsure that the addition of zms (with associated maintenance) can be justified.

@Laczen you can check whether mtd driver implement mtd_dev_s::erase.

@xiaoxiang781216 this could be done, but this might break other drivers. E.g. the rwbuffer directly calls the underlying mtd_erase method.

All places already add the check, I think. @zhaoxingyu12 please confirm this.

@xiaoxiang781216 @Laczen It is currently only used in mtd_partition, and has (part->child.erase = mtd->erase ? part_erase : NULL; ) check in mtd_partition.
I will fully check other drivers.

@xiaoxiang781216
Copy link
Contributor

@zhaoxingyu12 please fix:

====================================================================================
Configuration/Tool: esp32c3-legacy-devkit/nvcfgdata
2026-01-20 13:56:42
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
  [1/1] Normalize esp32c3-legacy-devkit/nvcfgdata
46d45
< CONFIG_SYSTEM_CFGDATA=y
48d46
< CONFIG_TESTING_MTD_CONFIG_FAIL_SAFE=y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Area: File System File System issues Board: arm Board: risc-v Size: M The size of the change in this PR is medium Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants