Skip to content

Commit f09d861

Browse files
committed
feat(nvs_flash): Bring nvs_flash from esp-idf
Commit ID: ecd2c51
1 parent c8a91e0 commit f09d861

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+10427
-1446
lines changed

components/nvs_flash/CMakeLists.txt

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
1-
set(COMPONENT_SRCDIRS "src")
2-
set(COMPONENT_ADD_INCLUDEDIRS "include")
1+
idf_build_get_property(target IDF_TARGET)
32

4-
set(COMPONENT_PRIV_REQUIRES "spi_flash")
3+
set(srcs "src/nvs_api.cpp"
4+
"src/nvs_cxx_api.cpp"
5+
"src/nvs_item_hash_list.cpp"
6+
"src/nvs_page.cpp"
7+
"src/nvs_pagemanager.cpp"
8+
"src/nvs_storage.cpp"
9+
"src/nvs_handle_simple.cpp"
10+
"src/nvs_handle_locked.cpp"
11+
"src/nvs_partition.cpp"
12+
"src/nvs_partition_lookup.cpp"
13+
"src/nvs_partition_manager.cpp"
14+
"src/nvs_types.cpp")
515

6-
register_component()
16+
set(public_req spi_flash)
17+
18+
set(include_dirs "include")
19+
20+
idf_component_register(SRCS "${srcs}"
21+
REQUIRES "${public_req}"
22+
INCLUDE_DIRS "${include_dirs}")
23+
24+
# If we use the linux target, we need to redirect the crc functions to the linux
25+
if(${target} STREQUAL "linux")
26+
if(CONFIG_NVS_ENCRYPTION)
27+
# mbedtls isn't configured for building with linux or as mock target. It will draw in all kind of dependencies
28+
message(FATAL_ERROR "NVS currently doesn't support encryption if built for Linux.")
29+
endif()
30+
idf_component_get_property(spi_flash_dir spi_flash COMPONENT_DIR)
31+
target_include_directories(${COMPONENT_LIB} PUBLIC
32+
"${CMAKE_CURRENT_SOURCE_DIR}/mock/int"
33+
"${spi_flash_dir}/sim/stubs/freertos/include")
34+
target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mock/int/crc.cpp")
35+
target_compile_options(${COMPONENT_LIB} PUBLIC "-DLINUX_TARGET")
36+
else()
37+
# TODO: this is a workaround until IDF-2085 is fixed
38+
idf_component_get_property(mbedtls_lib mbedtls COMPONENT_LIB)
39+
target_link_libraries(${COMPONENT_LIB} PUBLIC ${mbedtls_lib})
40+
endif()
41+
42+
if(CONFIG_NVS_ENCRYPTION)
43+
target_sources(${COMPONENT_LIB} PRIVATE "src/nvs_encrypted_partition.cpp")
44+
idf_component_get_property(mbedtls_lib mbedtls COMPONENT_LIB)
45+
target_link_libraries(${COMPONENT_LIB} PUBLIC ${mbedtls_lib})
46+
endif()
47+
48+
if(${target} STREQUAL "linux")
49+
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage)
50+
target_link_libraries(${COMPONENT_LIB} PUBLIC --coverage)
51+
endif()

components/nvs_flash/Kconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
menu "NVS"
2+
3+
config NVS_ENCRYPTION
4+
bool "Enable NVS encryption"
5+
default y
6+
depends on SECURE_FLASH_ENC_ENABLED
7+
help
8+
This option enables encryption for NVS. When enabled, AES-XTS is used to encrypt
9+
the complete NVS data, except the page headers. It requires XTS encryption keys
10+
to be stored in an encrypted partition. This means enabling flash encryption is
11+
a pre-requisite for this feature.
12+
endmenu

components/nvs_flash/README.rst

-234
This file was deleted.

components/nvs_flash/component.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ COMPONENT_ADD_INCLUDEDIRS := include
66

77
COMPONENT_SRCDIRS := src
88

9-
CPPFLAGS += -DNVS_CRC_HEADER_FILE=\"rom/crc.h\"
9+
ifndef CONFIG_NVS_ENCRYPTION
10+
COMPONENT_OBJEXCLUDE := src/nvs_encr.o
11+
endif

0 commit comments

Comments
 (0)