xiaoxiang781216 commented on code in PR #6829: URL: https://github.com/apache/incubator-nuttx/pull/6829#discussion_r945041497
########## include/nuttx/mtd/configdata.h: ########## @@ -120,6 +120,27 @@ extern "C" struct mtd_dev_s; int mtdconfig_register(FAR struct mtd_dev_s *mtd); +/**************************************************************************** + * Name: mtdnvs_register + * + * Description: + * This function binds an instance of an MTD device to the /dev/config + * device. + * + * When this function is called, the MTD device pass in should already + * be initialized appropriately to access the physical device or partition. + * + * Input Parameters: + * mtd - Pointer to the MTD device to bind with the /dev/config device + * + * Returned Value: + * Zero on success; a negated errno value on failure. + + * + ****************************************************************************/ + +int mtdnvs_register(FAR struct mtd_dev_s *mtd); Review Comment: let's use the same register function mtdconfig_register? ########## boards/risc-v/esp32c3/esp32c3-devkit/Kconfig: ########## @@ -109,6 +109,10 @@ choice ESP32C3_SPIFLASH_FS bool "LittleFS" select FS_LITTLEFS + config ESP32C3_SPIFLASH_NVCFGDATA Review Comment: ```suggestion config ESP32C3_SPIFLASH_MTD_CONFIG ``` ########## drivers/mtd/mtd_nvs.c: ########## @@ -0,0 +1,2244 @@ +/**************************************************************************** + * drivers/mtd/mtd_nvs.c Review Comment: mtd_config_fs.c ########## drivers/mtd/Make.defs: ########## @@ -29,6 +29,10 @@ ifeq ($(CONFIG_MTD),y) CSRCS += ftl.c mtd_config.c +ifeq ($(CONFIG_MTD_NVS),y) +CSRCS += mtd_nvs.c +endif Review Comment: ifeq ($(CONFIG_MTD_NVS),y) CSRCS += mtd_nvs.c else if($(CONFIG_MTD_CONFIG),y) CSRCS += mtd_config.c endif ########## drivers/mtd/Kconfig: ########## @@ -192,6 +192,15 @@ config MTD_CONFIG_NAME_LEN ---help--- Sets the maximum length of config item names. +config MTD_NVS + bool "Enable Dev Non-volatile storage (MTD based) device" Review Comment: config MTD_CONFIG_FAIL_SAFE bool "Enable Fail Safe" ---help--- Enable the new storage layout to support the resilient to power loss. ########## drivers/mtd/Kconfig: ########## @@ -192,6 +192,15 @@ config MTD_CONFIG_NAME_LEN ---help--- Sets the maximum length of config item names. +config MTD_NVS + bool "Enable Dev Non-volatile storage (MTD based) device" + default n + depends on MTD_CONFIG_NAMED Review Comment: let's support no named case too ########## drivers/mtd/mtd_nvs.h: ########## @@ -0,0 +1,102 @@ +/**************************************************************************** + * drivers/mtd/mtd_nvs.h Review Comment: could merge mtd_nvs.h into mtd_nvs.c, since all info is the internal detail which doesn't need share with other party. ########## drivers/mtd/mtd_nvs.h: ########## @@ -0,0 +1,102 @@ +/**************************************************************************** + * drivers/mtd/mtd_nvs.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MTD_MTD_NVS_H +#define __DRIVERS_MTD_MTD_NVS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <nuttx/compiler.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* MASKS AND SHIFT FOR ADDRESSES + * an address in nvs is an uint32_t where: + * high 2 bytes represent the sector number + * low 2 bytes represent the offset in a sector + */ +#define ADDR_SECT_MASK 0xFFFF0000 +#define ADDR_SECT_SHIFT 16 +#define ADDR_OFFS_MASK 0x0000FFFF + +/* Status return values */ + +#define NVS_STATUS_NOSPACE 1 + +#define NVS_BLOCK_SIZE 32 + +/** + * @brief Non-volatile Storage File system structure + * + * @param offset File system offset in flash + * @param ate_wra: Allocation table entry write address. Addresses are stored + * as uint32_t: high 2 bytes are sector, low 2 bytes are offset in sector, + * @param data_wra: Data write address. + * @param sector_size File system is divided into sectors each sector + * should be multiple of pagesize + * @param sector_count Amount of sectors in the file systems + * @param write_block_size Alignment size + * @param nvs_lock Mutex + * @param flash_device Flash Device + */ + +struct nvs_fs +{ + FAR struct mtd_dev_s *mtd; /* mtd device */ Review Comment: ```suggestion FAR struct mtd_dev_s *mtd; /* mtd device */ ``` -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org