diff --git a/.gitmodules b/.gitmodules index 2af5b7bbef9432..fac9c7aa1afe47 100644 --- a/.gitmodules +++ b/.gitmodules @@ -280,11 +280,6 @@ url = https://git.gitlab.arm.com/iot/open-iot-sdk/sdk.git branch = main platforms = openiotsdk -[submodule "open-iot-sdk-storage"] - path = third_party/open-iot-sdk/storage - url = https://git.gitlab.arm.com/iot/open-iot-sdk/storage.git - branch = main - platforms = openiotsdk [submodule "bouffalolab_sdk"] path = third_party/bouffalolab/repo url = https://github.com/bouffalolab/bl_iot_sdk_tiny.git diff --git a/config/openiotsdk/CMakeLists.txt b/config/openiotsdk/CMakeLists.txt index 43f9fca7b5dd9a..70bb737b217563 100644 --- a/config/openiotsdk/CMakeLists.txt +++ b/config/openiotsdk/CMakeLists.txt @@ -60,9 +60,9 @@ matter_add_gn_arg_bool ("chip_detail_logging" CONFIG_CHIP_DETA matter_add_gn_arg_bool ("chip_progress_logging" CONFIG_CHIP_PROGRESS_LOGGING) matter_add_gn_arg_bool ("chip_automation_logging" CONFIG_CHIP_AUTOMATION_LOGGING) matter_add_gn_arg_bool ("chip_error_logging" CONFIG_CHIP_ERROR_LOGGING) -matter_add_gn_arg_bool ("chip_openiotsdk_use_tfm" TFM_SUPPORT) -matter_add_gn_arg_bool ("chip_openiotsdk_use_psa_ps" CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS) matter_add_gn_arg_string("chip_crypto" "${CONFIG_CHIP_CRYPTO}") +matter_add_gn_arg_string("chip_openiotsdk_software_version" "${CONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION}") +matter_add_gn_arg_string("chip_openiotsdk_software_version_string" "${CONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION_STRING}") if (TARGET cmsis-rtos-api) matter_add_gn_arg_string("target_os" "cmsis-rtos") endif() @@ -76,6 +76,7 @@ matter_generate_args_tmp_file() matter_build(chip LIB_SHELL ${CONFIG_CHIP_LIB_SHELL} LIB_TESTS ${CONFIG_CHIP_LIB_TESTS} + GN_DEPENDENCIES ${CONFIG_GN_DEPENDENCIES} ) target_link_libraries(chip INTERFACE diff --git a/config/openiotsdk/cmake/chip.cmake b/config/openiotsdk/cmake/chip.cmake index 6e1a78bcb8debf..5875d10dd88a4f 100644 --- a/config/openiotsdk/cmake/chip.cmake +++ b/config/openiotsdk/cmake/chip.cmake @@ -31,12 +31,10 @@ set(CONFIG_CHIP_PROGRESS_LOGGING YES CACHE BOOL "Enable logging at progress leve set(CONFIG_CHIP_AUTOMATION_LOGGING YES CACHE BOOL "Enable logging at automation level") set(CONFIG_CHIP_ERROR_LOGGING YES CACHE BOOL "Enable logging at error level") -set(CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS NO CACHE BOOL "Enable using PSA Protected Storage") set(CONFIG_CHIP_CRYPTO "mbedtls" CACHE STRING "Matter crypto backend. Mbedtls as default") - -if(CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS AND NOT TFM_SUPPORT) - message( FATAL_ERROR "You can not use PSA Protected Storage without TF-M support" ) -endif() +set(CONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION "0" CACHE STRING "Software version number") +set(CONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION_STRING ${TFM_NS_APP_VERSION} CACHE STRING "Software version in string format x.x.x") +set(CONFIG_GN_DEPENDENCIES "") if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CONFIG_CHIP_DEBUG YES) @@ -44,16 +42,14 @@ else() set(CONFIG_CHIP_DEBUG NO) endif() +# TF-M support requires the right order of generating targets +list(APPEND CONFIG_GN_DEPENDENCIES tfm-ns-interface) + # Add CHIP sources add_subdirectory(${OPEN_IOT_SDK_CONFIG} ./chip_build) # Additional chip target configuration -# TF-M support requires the right order of generating targets -if(TFM_SUPPORT) - add_dependencies(chip-gn tfm-ns-interface) -endif() - if ("${CONFIG_CHIP_CRYPTO}" STREQUAL "psa") target_compile_definitions(chip INTERFACE diff --git a/config/openiotsdk/cmake/sdk.cmake b/config/openiotsdk/cmake/sdk.cmake index 6f391bd235033f..f4d151455c6eea 100644 --- a/config/openiotsdk/cmake/sdk.cmake +++ b/config/openiotsdk/cmake/sdk.cmake @@ -22,13 +22,11 @@ include(FetchContent) get_filename_component(OPEN_IOT_SDK_SOURCE ${CHIP_ROOT}/third_party/open-iot-sdk/sdk REALPATH) -get_filename_component(OPEN_IOT_SDK_STORAGE_SOURCE ${CHIP_ROOT}/third_party/open-iot-sdk/storage REALPATH) # Open IoT SDK targets passed to CHIP build list(APPEND CONFIG_CHIP_EXTERNAL_TARGETS) # Additional Open IoT SDK build configuration -set(TFM_SUPPORT NO CACHE BOOL "Add Trusted Firmware-M (TF-M) support to application") set(TFM_NS_APP_VERSION "0.0.0" CACHE STRING "TF-M non-secure application version (in the x.x.x format)") set(CONFIG_CHIP_OPEN_IOT_SDK_LWIP_DEBUG NO CACHE BOOL "Enable LwIP debug logs") @@ -72,26 +70,23 @@ set(IOTSDK_FETCH_LIST mbedtls lwip cmsis-sockets-api + trusted-firmware-m ) set(MDH_PLATFORM ARM_AN552_MPS3) set(VARIANT "FVP") set(FETCHCONTENT_QUIET OFF) -if(TFM_SUPPORT) - list(APPEND IOTSDK_FETCH_LIST trusted-firmware-m) - set(TFM_PLATFORM ${OPEN_IOT_SDK_EXAMPLE_COMMON}/tf-m/targets/an552) - set(TFM_PSA_FIRMWARE_UPDATE ON) - set(MCUBOOT_IMAGE_VERSION_NS ${TFM_NS_APP_VERSION}) - set(TFM_CMAKE_ARGS "-DCONFIG_TFM_ENABLE_FP=ON;-DTFM_PROFILE=profile_medium;-DTFM_EXCEPTION_INFO_DUMP=ON;-DCONFIG_TFM_HALT_ON_CORE_PANIC=ON;-DTFM_ISOLATION_LEVEL=1;-DTFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH=${OPEN_IOT_SDK_CONFIG}/mbedtls/mbedtls_config_psa.h;-DMBEDCRYPTO_BUILD_TYPE=${CMAKE_BUILD_TYPE};-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") - if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DMCUBOOT_LOG_LEVEL=INFO;-DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_DEBUG;-DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_INFO") - else() - set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DMCUBOOT_LOG_LEVEL=ERROR;-DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_DEBUG;-DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_ERROR") - endif() - if(TFM_PROJECT_CONFIG_HEADER_FILE) - set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DPROJECT_CONFIG_HEADER_FILE=${TFM_PROJECT_CONFIG_HEADER_FILE}") - endif() - set(LINKER_SCRIPT ${OPEN_IOT_SDK_CONFIG}/ld/cs300_gcc_tfm.ld) +set(TFM_PLATFORM ${OPEN_IOT_SDK_EXAMPLE_COMMON}/tf-m/targets/an552) +set(TFM_PSA_FIRMWARE_UPDATE ON) +set(MCUBOOT_IMAGE_VERSION_NS ${TFM_NS_APP_VERSION}) +set(TFM_CMAKE_ARGS "-DCONFIG_TFM_ENABLE_FP=ON;-DTFM_PROFILE=profile_medium;-DTFM_EXCEPTION_INFO_DUMP=ON;-DCONFIG_TFM_HALT_ON_CORE_PANIC=ON;-DTFM_ISOLATION_LEVEL=1;-DTFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH=${OPEN_IOT_SDK_CONFIG}/mbedtls/mbedtls_config_psa.h;-DMBEDCRYPTO_BUILD_TYPE=${CMAKE_BUILD_TYPE};-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DMCUBOOT_LOG_LEVEL=INFO;-DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_DEBUG;-DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_INFO") +else() + set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DMCUBOOT_LOG_LEVEL=ERROR;-DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_DEBUG;-DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_ERROR") +endif() +if(TFM_PROJECT_CONFIG_HEADER_FILE) + set(TFM_CMAKE_ARGS "${TFM_CMAKE_ARGS};-DPROJECT_CONFIG_HEADER_FILE=${TFM_PROJECT_CONFIG_HEADER_FILE}") endif() # Add Open IoT SDK source @@ -124,7 +119,7 @@ if(TARGET cmsis-rtos-api) target_compile_definitions(cmsis-rtos-api PUBLIC - DOMAIN_NS=$,1,0> + DOMAIN_NS=1 ) if(TARGET freertos-kernel) @@ -142,11 +137,6 @@ if(TARGET cmsis-rtos-api) PUBLIC freertos-cmsis-rtos ) - - target_compile_definitions(cmsis-rtos-api - INTERFACE - CONFIG_RUN_FREERTOS_SECURE_ONLY=$,0,1> - ) elseif(TARGET cmsis-rtx) target_link_libraries(cmsis-rtos-api INTERFACE @@ -191,7 +181,7 @@ endif() if(TARGET mcu-driver-hal) target_compile_definitions(mcu-driver-hal INTERFACE - DOMAIN_NS=$,1,0> + DOMAIN_NS=1 ) # Fixing the optimization issue for mcu-driver-hal target in the release build. @@ -283,24 +273,8 @@ if("mbedtls" IN_LIST IOTSDK_FETCH_LIST) ) endif() -# Additional Open IoT SDK port components - -# Add Open IoT SDK storage source -add_subdirectory(${OPEN_IOT_SDK_STORAGE_SOURCE} ./sdk_storage_build) -list(APPEND CONFIG_CHIP_EXTERNAL_TARGETS - iotsdk-blockdevice - iotsdk-tdbstore -) - -# Add custom storage library -add_subdirectory(${OPEN_IOT_SDK_CONFIG}/storage storage_build) -list(APPEND CONFIG_CHIP_EXTERNAL_TARGETS - openiotsdk-storage -) - function(sdk_post_build target) string(REPLACE "_ns" "" APP_NAME ${target}) -if(TFM_SUPPORT) include(ConvertElfToBin) include(SignTfmImage) ExternalProject_Get_Property(trusted-firmware-m-build BINARY_DIR) @@ -355,29 +329,4 @@ if(TFM_SUPPORT) $/${target}_merged.elf VERBATIM ) -else() - add_custom_command( - TARGET - ${target} - POST_BUILD - DEPENDS - $/${target}.elf - $/${target}.map - COMMAND - # Rename output elf file - ${CMAKE_COMMAND} -E copy - $/${target}.elf - $/${APP_NAME}.elf - COMMAND - # Rename output map file - ${CMAKE_COMMAND} -E copy - $/${target}.map - $/${APP_NAME}.map - COMMAND rm - ARGS -Rf - $/${target}.elf - $/${target}.map - VERBATIM - ) -endif() #TFM_SUPPORT endfunction() diff --git a/config/openiotsdk/ld/cs300_gcc.ld b/config/openiotsdk/ld/cs300_gcc.ld index 97ec041ff09ed6..fd1d951258d917 100644 --- a/config/openiotsdk/ld/cs300_gcc.ld +++ b/config/openiotsdk/ld/cs300_gcc.ld @@ -17,11 +17,8 @@ MEMORY { - ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 32K - /* Vector table is copied to RAM, so RAM address needs to be adjusted */ - DTCM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K - DATA_SRAM (rwx) : ORIGIN = 0x21000000, LENGTH = 2M - QSPI_RAM (rx) : ORIGIN = 0x28000000, LENGTH = 8M + FLASH (rx) : ORIGIN = ((0x28000000) + (0x60000) + (0x400)), LENGTH = ((0x200000) - (0x400) - (0x800)) + RAM (rwx) : ORIGIN = 0x21000000, LENGTH = 0x200000 } __stack_size__ = 0x1000; @@ -31,28 +28,26 @@ GROUP(libgcc.a libc.a libm.a libnosys.a) SECTIONS { - .vectors : + .text : { KEEP(*(.vectors)) __Vectors_End = .; __Vectors_Size = __Vectors_End - __Vectors; __end__ = .; + *(.text*) + KEEP(*(.init)) KEEP(*(.fini)) + /* .ctors */ *crtbegin.o(.ctors) *crtbegin?.o(.ctors) *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) *(SORT(.ctors.*)) *(.ctors) - } > ITCM - .text : - { - *(.text*) - /* .dtors */ *crtbegin.o(.dtors) *crtbegin?.o(.dtors) @@ -63,19 +58,19 @@ SECTIONS *(.rodata*) KEEP(*(.eh_frame*)) - } > QSPI_RAM + } > FLASH .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) - } > QSPI_RAM + } > FLASH __exidx_start = .; .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > QSPI_RAM + } > FLASH __exidx_end = .; @@ -92,7 +87,7 @@ SECTIONS LONG (DEFINED(__data2_start__) ? __data2_start__ : 0) LONG (DEFINED(__data2_start__) ? __data2_end__ - __data2_start__ : 0) __copy_table_end__ = .; - } > QSPI_RAM + } > FLASH .zero.table : { @@ -103,7 +98,7 @@ SECTIONS LONG (DEFINED(__bss2_start__) ? __bss2_start__ : 0) LONG (DEFINED(__bss2_start__) ? __bss2_end__ - __bss2_start__ : 0) __zero_table_end__ = .; - } > QSPI_RAM + } > FLASH __etext = .; @@ -137,7 +132,7 @@ SECTIONS . = ALIGN(4); /* All data end */ __data_end__ = .; - } > DATA_SRAM + } > RAM .bss : { @@ -147,7 +142,7 @@ SECTIONS *(COMMON) . = ALIGN(4); __bss_end__ = .; - } > DATA_SRAM + } > RAM bss_size = __bss_end__ - __bss_start__; @@ -158,7 +153,7 @@ SECTIONS KEEP(*(.stack*)) . += __stack_size__; __StackTop = .; - } > DTCM + } > RAM PROVIDE(__stack = __StackTop); .heap (COPY): @@ -168,10 +163,10 @@ SECTIONS __end__ = .; end = __end__; KEEP(*(.heap*)) - . += (ORIGIN(DATA_SRAM) + LENGTH(DATA_SRAM) - .); + . += (ORIGIN(RAM) + LENGTH(RAM) - .); __HeapLimit = .; __heap_limit = .; - } > DATA_SRAM + } > RAM - ASSERT(__StackTop <= (ORIGIN(DTCM) + LENGTH(DTCM)), "RAM region overflowed") + ASSERT(__HeapLimit <= (ORIGIN(RAM) + LENGTH(RAM)), "RAM region overflowed") } diff --git a/config/openiotsdk/ld/cs300_gcc_tfm.ld b/config/openiotsdk/ld/cs300_gcc_tfm.ld deleted file mode 100644 index fd1d951258d917..00000000000000 --- a/config/openiotsdk/ld/cs300_gcc_tfm.ld +++ /dev/null @@ -1,172 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed 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. - */ - -MEMORY -{ - FLASH (rx) : ORIGIN = ((0x28000000) + (0x60000) + (0x400)), LENGTH = ((0x200000) - (0x400) - (0x800)) - RAM (rwx) : ORIGIN = 0x21000000, LENGTH = 0x200000 -} - -__stack_size__ = 0x1000; - -/* Library configurations */ -GROUP(libgcc.a libc.a libm.a libnosys.a) - -SECTIONS -{ - .text : - { - KEEP(*(.vectors)) - __Vectors_End = .; - __Vectors_Size = __Vectors_End - __Vectors; - __end__ = .; - - *(.text*) - - KEEP(*(.init)) - KEEP(*(.fini)) - - - /* .ctors */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - - /* .dtors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.rodata*) - - KEEP(*(.eh_frame*)) - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - - __exidx_end = .; - - /* To copy multiple ROM to RAM sections, - * define etext2/data2_start/data2_end */ - .copy.table : - { - . = ALIGN(4); - __copy_table_start__ = .; - LONG (__etext) - LONG (__data_start__) - LONG (__data_end__ - __data_start__) - LONG (DEFINED(__etext2) ? __etext2 : 0) - LONG (DEFINED(__data2_start__) ? __data2_start__ : 0) - LONG (DEFINED(__data2_start__) ? __data2_end__ - __data2_start__ : 0) - __copy_table_end__ = .; - } > FLASH - - .zero.table : - { - . = ALIGN(4); - __zero_table_start__ = .; - LONG (__bss_start__) - LONG (__bss_end__ - __bss_start__) - LONG (DEFINED(__bss2_start__) ? __bss2_start__ : 0) - LONG (DEFINED(__bss2_start__) ? __bss2_end__ - __bss2_start__ : 0) - __zero_table_end__ = .; - } > FLASH - - __etext = .; - - .data : AT (__etext) - { - __data_start__ = .; - *(vtable) - *(.data*) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP(*(SORT(.fini_array.*))) - KEEP(*(.fini_array)) - PROVIDE_HIDDEN (__fini_array_end = .); - - KEEP(*(.jcr*)) - . = ALIGN(4); - /* All data end */ - __data_end__ = .; - } > RAM - - .bss : - { - . = ALIGN(4); - __bss_start__ = .; - *(.bss*) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - bss_size = __bss_end__ - __bss_start__; - - .stack : - { - . = ALIGN(8); - __StackLimit = .; - KEEP(*(.stack*)) - . += __stack_size__; - __StackTop = .; - } > RAM - PROVIDE(__stack = __StackTop); - - .heap (COPY): - { - . = ALIGN(8); - __HeapBase = .; - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - . += (ORIGIN(RAM) + LENGTH(RAM) - .); - __HeapLimit = .; - __heap_limit = .; - } > RAM - - ASSERT(__HeapLimit <= (ORIGIN(RAM) + LENGTH(RAM)), "RAM region overflowed") -} diff --git a/config/openiotsdk/storage/CMakeLists.txt b/config/openiotsdk/storage/CMakeLists.txt deleted file mode 100644 index a7f1e0b53f0e4a..00000000000000 --- a/config/openiotsdk/storage/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2022 Project CHIP Authors -# -# Licensed 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. -# - -cmake_minimum_required(VERSION 3.21) - -# Declare Open IoT SDK app interface target -add_library(openiotsdk-storage - FlashBlockDevice.cpp -) - -target_include_directories(openiotsdk-storage - PUBLIC - . - ${CHIP_ROOT}/src/platform/openiotsdk -) - -target_link_libraries(openiotsdk-storage - PUBLIC - mcu-driver-hal - iotsdk-blockdevice -) diff --git a/config/openiotsdk/storage/FlashBlockDevice.cpp b/config/openiotsdk/storage/FlashBlockDevice.cpp deleted file mode 100644 index e876dec9eaed19..00000000000000 --- a/config/openiotsdk/storage/FlashBlockDevice.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed 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. - */ - -/** - * @file - * Utilities for interacting with the the Open IoT SDK key-value storage. - */ - -#include - -#include "FlashBlockDevice.h" -#include - -extern "C" { -#include -} - -#define FLASH_BASE_ADDRESS (SRAM_BASE_NS) /* 0x01000000 */ -#define FLASH_TOTAL_SIZE (SRAM_SIZE) /* 2 MB */ -#define FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4 KB */ -#define FLASH_PAGE_SIZE 256 -#define FLASH_END_ADDRESS (FLASH_BASE_ADDRESS + FLASH_TOTAL_SIZE) -#define FLASH_READ_SIZE 1 -#define FLASH_ERASE_VALUE 0xFFU - -namespace iotsdk { -namespace storage { - -FlashBlockDevice::FlashBlockDevice(uint32_t address, uint32_t size) : _base(address), _size(size), _is_initialized(false) {} - -FlashBlockDevice::~FlashBlockDevice() {} - -bd_status FlashBlockDevice::init() -{ - if (!_base) - { - _base = FLASH_BASE_ADDRESS; - } - - if (!_size) - { - _size = FLASH_TOTAL_SIZE - (_base - FLASH_BASE_ADDRESS); - } - - if (_size + _base > FLASH_TOTAL_SIZE + FLASH_BASE_ADDRESS) - { - return bd_status::INCORRECT_SIZE; - } - - if (_base < FLASH_BASE_ADDRESS) - { - return bd_status::INCORRECT_ADDRESS; - } - - _is_initialized = true; - return bd_status::OK; -} - -bd_status FlashBlockDevice::deinit() -{ - if (!_is_initialized) - { - return bd_status::OK; - } - - _is_initialized = false; - - return bd_status::OK; -} - -bd_status FlashBlockDevice::read(void * buffer, bd_addr_t virtual_address, bd_size_t size) -{ - if (!_is_initialized) - { - return bd_status::DEVICE_NOT_INITIALIZED; - } - - /* Check that the address and size are properly aligned and fit. */ - bd_status status = is_valid_read(virtual_address, size); - if (status != bd_status::OK) - { - return status; - } - - /* Convert virtual address to the physical address for the device. */ - const auto physical_address = static_cast(_base + virtual_address); - - /* Read data */ - memcpy(static_cast(buffer), (void *) physical_address, static_cast(size)); - - return bd_status::OK; -} - -bd_status FlashBlockDevice::program(const void * buffer, bd_addr_t virtual_address, bd_size_t size) -{ - if (!_is_initialized) - { - return bd_status::DEVICE_NOT_INITIALIZED; - } - - /* Check that the address and size are properly aligned and fit. */ - bd_status status = is_valid_program(virtual_address, size); - if (status != bd_status::OK) - { - return status; - } - - /* Convert virtual address to the physical address for the device. */ - auto physical_address = static_cast(_base + virtual_address); - auto remaining_size = static_cast(size); - const auto * buf = static_cast(buffer); - - while (remaining_size > 0) - { - /* Multiple pages can be programmed at once but cannot cross sector boundaries */ - const auto sector_size = FLASH_AREA_IMAGE_SECTOR_SIZE; - const auto sector_end = (physical_address / sector_size + 1) * sector_size; - const auto chunk = (physical_address + remaining_size > sector_end) ? (sector_end - physical_address) : remaining_size; - /* Write data */ - memcpy((void *) physical_address, buf, chunk); - physical_address += chunk; - remaining_size -= chunk; - buf += chunk; - } - - return bd_status::OK; -} - -bd_status FlashBlockDevice::erase(bd_addr_t virtual_address, bd_size_t size) -{ - if (!_is_initialized) - { - return bd_status::DEVICE_NOT_INITIALIZED; - } - - /* Check that the address and size are properly aligned and fit. */ - const bd_status status = is_valid_erase(virtual_address, size); - if (status != bd_status::OK) - { - return status; - } - - /* Convert virtual address to the physical address for the device. */ - auto physical_address = static_cast(_base + virtual_address); - const auto sector_size = FLASH_AREA_IMAGE_SECTOR_SIZE; - const auto erase_region = (physical_address + size) - sector_size; - - while (physical_address <= erase_region) - { - memset((void *) physical_address, FLASH_ERASE_VALUE, FLASH_AREA_IMAGE_SECTOR_SIZE); - physical_address += sector_size; - } - - return bd_status::OK; -} - -bd_size_t FlashBlockDevice::get_read_size() const -{ - return FLASH_READ_SIZE; -} - -bd_size_t FlashBlockDevice::get_program_size() const -{ - if (!_is_initialized) - { - return 0; - } - - return FLASH_PAGE_SIZE; -} - -bd_size_t FlashBlockDevice::get_erase_size() const -{ - return 0; -} - -bd_size_t FlashBlockDevice::get_erase_size(bd_addr_t addr) const -{ - if (!_is_initialized) - { - return 0; - } - - if (static_cast(_base) + addr > UINT32_MAX) - { - return 0; - } - - return FLASH_AREA_IMAGE_SECTOR_SIZE; -} - -int FlashBlockDevice::get_erase_value() const -{ - if (!_is_initialized) - { - return -1; - } - - return FLASH_ERASE_VALUE; -} - -bd_size_t FlashBlockDevice::size() const -{ - return _size; -} - -const char * FlashBlockDevice::get_type() const -{ - return "FLASH_BD"; -} - -bd_status FlashBlockDevice::is_valid_read(bd_addr_t addr, bd_size_t size) const -{ - if (static_cast(_base) + addr > UINT32_MAX) - { - return bd_status::INCORRECT_ADDRESS; - } - - if (size > UINT32_MAX) - { - return bd_status::INCORRECT_SIZE; - } - - return BlockDevice::is_valid_read(addr, size); -} - -bd_status FlashBlockDevice::is_valid_program(bd_addr_t addr, bd_size_t size) const -{ - if (static_cast(_base) + addr > UINT32_MAX) - { - return bd_status::INCORRECT_ADDRESS; - } - - if (size > UINT32_MAX) - { - return bd_status::INCORRECT_SIZE; - } - - return BlockDevice::is_valid_program(addr, size); -} - -bd_status FlashBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const -{ - if (static_cast(_base) + addr > UINT32_MAX) - { - return bd_status::INCORRECT_ADDRESS; - } - - if (size > UINT32_MAX) - { - return bd_status::INCORRECT_SIZE; - } - - return BlockDevice::is_valid_erase(addr, size); -} - -} // namespace storage -} // namespace iotsdk - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -static iotsdk::storage::FlashBlockDevice gBlockDevice(0, 0); - -iotsdk::storage::BlockDevice * GetBlockDevice() -{ - return &gBlockDevice; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip diff --git a/config/openiotsdk/storage/FlashBlockDevice.h b/config/openiotsdk/storage/FlashBlockDevice.h deleted file mode 100644 index 95ba8375e7c9db..00000000000000 --- a/config/openiotsdk/storage/FlashBlockDevice.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed 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. - */ - -/** - * @file - */ - -#ifndef IOTSDK_FLASH_BLOCKDEVICE_H -#define IOTSDK_FLASH_BLOCKDEVICE_H - -#include "iotsdk/BlockDevice.h" - -#include - -namespace iotsdk { -namespace storage { -/** BlockDevice using the flash memory for TF-M application - * - */ -class FlashBlockDevice final : public BlockDevice -{ -public: - /** Creates a FlashBlockDevice - * @param address Physical address where the block device start - * @param size The block device size - */ - FlashBlockDevice(uint32_t address, uint32_t size); - - ~FlashBlockDevice(); - - /** Initialize a block device - * - * This method must be called before attempting any further block device operations. - * - * @return bd_status::OK on success or an error status on failure - */ - bd_status init() override; - - /** Deinitialize a block device - * - * @return bd_status::OK on success or an error status on failure - */ - bd_status deinit() override; - - /** Read blocks from a block device - * - * If a failure occurs, it is not possible to determine how many bytes succeeded. - * - * @param buffer Buffer to write blocks to - * @param addr Address of block to begin reading from - * @param size Size to read in bytes, must be a multiple of the read block size - * @return bd_status::OK on success or an error status on failure - */ - bd_status read(void * buffer, bd_addr_t addr, bd_size_t size) override; - - /** Program blocks to a block device - * - * The blocks must have been erased prior to being programmed. - * - * If a failure occurs, it is not possible to determine how many bytes succeeded. - * - * @param buffer Buffer of data to write to blocks - * @param addr Address of block to begin writing to - * @param size Size to write in bytes, must be a multiple of the program block size - * @return bd_status::OK on success or an error status on failure - */ - bd_status program(const void * buffer, bd_addr_t addr, bd_size_t size) override; - - /** Erase blocks on a block device - * - * The state of an erased block is undefined until it has been programmed, - * unless get_erase_value returns a non-negative byte value. - * - * @param addr Address of block to begin erasing - * @param size Size to erase in bytes, must be a multiple of the erase block size - * @return bd_status::OK on success or an error status on failure - */ - bd_status erase(bd_addr_t addr, bd_size_t size) override; - - /** Get the size of a readable block - * - * @return Size of a readable block in bytes - */ - bd_size_t get_read_size() const override; - - /** Get the size of a programmable block - * - * @return Size of a programmable block in bytes - * @note Must be a multiple of the read size - */ - bd_size_t get_program_size() const override; - - /** Get the size of an erasable block for the whole device - * - * @return Size of an erasable block in bytes for the whole device - * @note Must be a multiple of the program size, or 0 if no common erase size exists - * across all regions or the underlying implementation does not provide this - * information in which case you need to call get_erase_size(bd_addr_t) instead - * @note For FlashBlockDevice, this always returns 0 because the underlying - * MCU-Driver-HAL flash API does not indicate whether all sectors have the same - * size - */ - bd_size_t get_erase_size() const override; - - /** Get the size of an erasable block given address - * - * @param addr Address within the erasable block - * @return Size of an erasable block in bytes - * @note Must be a multiple of the program size - */ - bd_size_t get_erase_size(bd_addr_t addr) const override; - - /** Get the value of storage when erased - * - * If get_erase_value returns a non-negative byte value, the underlying - * storage is set to that value when erased, and storage containing - * that value can be programmed without another erase. - * - * @return The value of storage when erased, or -1 if you can't - * rely on the value of the erased storage - */ - int get_erase_value() const override; - - /** Get the total size of the underlying device - * - * @return Size of the underlying device in bytes - */ - bd_size_t size() const override; - - /** Convenience function for checking block read validity - * - * @param addr Address of block to begin reading from - * @param size Size to read in bytes - * @return bd_status::OK if read is valid for underlying block device - */ - bd_status is_valid_read(bd_addr_t addr, bd_size_t size) const override; - - /** Convenience function for checking block program validity - * - * @param addr Address of block to begin writing to - * @param size Size to write in bytes - * @return bd_status::OK if program is valid for underlying block device - */ - bd_status is_valid_program(bd_addr_t addr, bd_size_t size) const override; - - /** Convenience function for checking block erase validity - * - * @param addr Address of block to begin erasing - * @param size Size to erase in bytes - * @return bd_status::OK if erase is valid for underlying block device - */ - bd_status is_valid_erase(bd_addr_t addr, bd_size_t size) const override; - - /** Get the BlockDevice class type. - * - * @return A string represent the BlockDevice class type. - */ - const char * get_type() const override; - -private: - // Device configuration - uint32_t _base; - uint32_t _size; - bool _is_initialized; -}; - -} // namespace storage -} // namespace iotsdk - -#endif /* IOTSDK_FLASH_BLOCKDEVICE_H */ diff --git a/docs/guides/openiotsdk_examples.md b/docs/guides/openiotsdk_examples.md index 2d1d7a0813a2c1..289fa33aace366 100644 --- a/docs/guides/openiotsdk_examples.md +++ b/docs/guides/openiotsdk_examples.md @@ -281,18 +281,13 @@ More information about the Python tools you can find ### Trusted Firmware-M -To add [TF-M](https://tf-m-user-guide.trustedfirmware.org) support to Matter -example you need to set `TFM_SUPPORT` variable inside main application -`CMakeLists.txt` file. +Matter examples support the [TF-M](https://tf-m-user-guide.trusted firmware.org) +by default. -``` -set(TFM_SUPPORT YES) -``` - -This causes the Matter example to be built as non-secure application in -Non-secure Processing Environment (`NSPE`). The bootloader and the secure part -are also built from `TF-M` sources. All components are merged into a single -executable file at the end of the building process. +This means the example is built as non-secure application in a Non-secure +Processing Environment (`NSPE`). The bootloader and the secure part are also +built from `TF-M` sources. All components are merged into a single executable +file at the end of the building process. You can also provide the own version of Matter example by setting `TFM_NS_APP_VERSION` variable. @@ -301,43 +296,6 @@ You can also provide the own version of Matter example by setting set(TFM_NS_APP_VERSION "0.0.1") ``` -### Trusted Firmware-M Protected Storage - -By default, the -[Block Device storage](./openiotsdk_platform_overview.md#storage) is used for -storing Matter key-value data. - -There is an option to add -[TF-M Protected Storage Service](https://tf-m-user-guide.trustedfirmware.org/integration_guide/services/tfm_ps_integration_guide.html) -support for `key-value` storage component in the Matter examples. Set the -variable `CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS` to `YES` to add -`TF-M Protected Storage` support to your application. You can put it inside the -main application `CMakeLists.txt` file: - -``` -set(CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS YES) -``` - -or add as a Cmake command-line parameter: - -``` -cmake -G <...> -DCONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS=YES <...> -``` - -This option causes `key-value` objects will be stored in a secure part of flash -memory and the Protected Storage Service takes care of their encryption and -authentication. - -> 💡 **Notes**: -> -> The `TF-M Protected Storage` option requires enabling -> [TF-M](#trusted-firmware-m) support. -> -> The `-k/--kvsstore` option in -> [Open IoT SDK build script](../../scripts/examples/openiotsdk_example.sh) -> selects key-value storage implementation for the Matter's examples. It -> demonstrates how to use the `CONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS` variable. - ### Storing persistent memory block in external files The persistent storage is required to store key-value data of the Matter @@ -355,13 +313,6 @@ available Depending on the storage implementation, different flags are used in the `FVP` options. -For block device storage use: - -``` ---dump mps3_board.sram=@0:0x0,0x100000 ---data mps3_board.sram=@0:0x0 -``` - For `TF-M` protected storage use: ``` diff --git a/docs/guides/openiotsdk_platform_overview.md b/docs/guides/openiotsdk_platform_overview.md index f52d18b4e65aa0..ace951e98b129d 100644 --- a/docs/guides/openiotsdk_platform_overview.md +++ b/docs/guides/openiotsdk_platform_overview.md @@ -66,14 +66,12 @@ Configuration of Mbed TLS is in ## Storage -Storage in Open IoT SDK is provided by -[TDBStore](https://gitlab.arm.com/iot/open-iot-sdk/storage) which is a simple -key-value storage over a block device. - -If the application uses -[Trusted Firmware-M](https://tf-m-user-guide.trustedfirmware.org) then +The application uses +[Trusted Firmware-M](https://tf-m-user-guide.trustedfirmware.org) and [TF-M Protected Storage Service](https://tf-m-user-guide.trustedfirmware.org/integration_guide/services/tfm_ps_integration_guide.html) -can be used as an alternative for persistence in secure memory. +is used for persistence in secure memory. The `key-value` objects are stored in +a secure part of flash memory and the Protected Storage Service takes care of +their encryption and authentication. --- diff --git a/examples/lock-app/openiotsdk/CMakeLists.txt b/examples/lock-app/openiotsdk/CMakeLists.txt index 492e5cb3b1f971..021095c44c38ea 100644 --- a/examples/lock-app/openiotsdk/CMakeLists.txt +++ b/examples/lock-app/openiotsdk/CMakeLists.txt @@ -26,9 +26,7 @@ list(APPEND CMAKE_MODULE_PATH ${LOCK_APP_COMMON}) set(APP_TARGET chip-openiotsdk-lock-app-example_ns) -set(TFM_SUPPORT YES) set(TFM_PROJECT_CONFIG_HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/tf-m-config/TfmProjectConfig.h") -set(TFM_NS_APP_VERSION "0.0.1") # Toolchain files need to exist before first call to project include(toolchain) @@ -48,7 +46,7 @@ chip_add_data_model(openiotsdk-app PUBLIC lock) # Add common lock-app sources include(lock-app) -chip_add_lock_app_common(openiotsdk-app +chip_add_lock_app_common(openiotsdk-app SCOPE PUBLIC ) diff --git a/examples/lock-app/openiotsdk/freertos-config/FreeRTOSConfig.h b/examples/lock-app/openiotsdk/freertos-config/FreeRTOSConfig.h index bfcd8f09e9b4aa..9efedc9f133712 100644 --- a/examples/lock-app/openiotsdk/freertos-config/FreeRTOSConfig.h +++ b/examples/lock-app/openiotsdk/freertos-config/FreeRTOSConfig.h @@ -190,7 +190,7 @@ extern uint32_t SystemCoreClock; // Use TrustZone Secure Side Only // This settings prevents FreeRTOS contex switch to Non-Secure side. // Enable this setting when FreeRTOS runs on the Secure side only. -#define configRUN_FREERTOS_SECURE_ONLY CONFIG_RUN_FREERTOS_SECURE_ONLY +#define configRUN_FREERTOS_SECURE_ONLY 0 // Use TrustZone Security Extension // Using TrustZone affects context handling. diff --git a/examples/platform/openiotsdk/app/CMakeLists.txt b/examples/platform/openiotsdk/app/CMakeLists.txt index c9939ea6a74fcd..c4caf953b34e9b 100644 --- a/examples/platform/openiotsdk/app/CMakeLists.txt +++ b/examples/platform/openiotsdk/app/CMakeLists.txt @@ -24,50 +24,32 @@ add_library(openiotsdk-startup target_link_libraries(openiotsdk-startup PUBLIC - # iotsdk-serial-retarget contains the UART but we don't need the retarget part + # iotsdk-serial-retarget contains the UART but we don't need the retarget part $,EXCLUDE,.*gcc_retarget.*> cmsis-rtos-api mcu-driver-hal + tfm-ns-interface ) target_link_options(openiotsdk-startup PUBLIC "-Wl,--wrap,__malloc_lock" - "-Wl,--wrap,__malloc_unlock" + "-Wl,--wrap,__malloc_unlock" ) -if(TFM_SUPPORT) - target_compile_definitions(openiotsdk-startup - PUBLIC - TFM_SUPPORT - ) - - target_link_libraries(openiotsdk-startup - PUBLIC - tfm-ns-interface - ) -endif() - # Declare Open IoT SDK app interface target add_library(openiotsdk-app openiotsdk_platform.cpp ${CHIP_ROOT}/examples/providers/DeviceInfoProviderImpl.cpp ) -target_include_directories(openiotsdk-app +target_include_directories(openiotsdk-app PUBLIC . ${CHIP_ROOT}/examples/providers ) -target_link_libraries(openiotsdk-app +target_link_libraries(openiotsdk-app PUBLIC chip ) - -if(TFM_SUPPORT) - target_compile_definitions(openiotsdk-app - PUBLIC - TFM_SUPPORT - ) -endif() diff --git a/examples/platform/openiotsdk/app/openiotsdk_platform.cpp b/examples/platform/openiotsdk/app/openiotsdk_platform.cpp index dff6a15e21cb93..e787112a0efb1d 100644 --- a/examples/platform/openiotsdk/app/openiotsdk_platform.cpp +++ b/examples/platform/openiotsdk/app/openiotsdk_platform.cpp @@ -48,11 +48,9 @@ #include #endif // USE_CHIP_DATA_MODEL -#ifdef TFM_SUPPORT #include "psa/fwu_config.h" #include "psa/update.h" #include "tfm_ns_interface.h" -#endif // TFM_SUPPORT using namespace ::chip; using namespace ::chip::Platform; @@ -71,12 +69,10 @@ static osEventFlagsId_t event_flags_id; static DeviceLayer::DeviceInfoProviderImpl gDeviceInfoProvider; -#ifdef TFM_SUPPORT extern "C" { // RTOS-specific initialization that is not declared in any header file uint32_t tfm_ns_interface_init(void); } -#endif // TFM_SUPPORT /** Wait for specific event and check error */ static int wait_for_event(uint32_t event) @@ -140,7 +136,6 @@ static void network_state_callback(network_state_callback_event_t event) } } -#ifdef TFM_SUPPORT static int get_psa_images_details() { psa_status_t status; @@ -168,7 +163,6 @@ static int get_psa_images_details() return EXIT_SUCCESS; } -#endif // TFM_SUPPORT int openiotsdk_platform_init(void) { @@ -192,14 +186,12 @@ int openiotsdk_platform_init(void) } #endif -#ifdef TFM_SUPPORT ret = get_psa_images_details(); if (ret != 0) { ChipLogError(NotSpecified, "Get PSA image details failed: %d", ret); return EXIT_FAILURE; } -#endif // TFM_SUPPORT return EXIT_SUCCESS; } @@ -300,6 +292,9 @@ int openiotsdk_chip_run(void) emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); #endif // USE_CHIP_DATA_MODEL + ChipLogProgress(NotSpecified, "Current software version: [%ld] %s", uint32_t(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION), + CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); + return EXIT_SUCCESS; } diff --git a/examples/platform/openiotsdk/app/openiotsdk_startup_gcc.cpp b/examples/platform/openiotsdk/app/openiotsdk_startup_gcc.cpp index bf143db5d32877..abe68ff3fc3c09 100644 --- a/examples/platform/openiotsdk/app/openiotsdk_startup_gcc.cpp +++ b/examples/platform/openiotsdk/app/openiotsdk_startup_gcc.cpp @@ -32,9 +32,7 @@ extern "C" { #include "hal/serial_api.h" } -#ifdef TFM_SUPPORT extern "C" uint32_t tfm_ns_interface_init(void); -#endif // TFM_SUPPORT #define CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0)) @@ -228,7 +226,6 @@ static void main_thread(void * argument) // It is safe to use printf from this point -#ifdef TFM_SUPPORT { int ret = tfm_ns_interface_init(); if (ret != 0) @@ -237,7 +234,6 @@ static void main_thread(void * argument) abort(); } } -#endif /* Run the C++ global object constructors */ __libc_init_array(); diff --git a/examples/shell/openiotsdk/CMakeLists.txt b/examples/shell/openiotsdk/CMakeLists.txt index 13ea384b261ff6..7961e7199388f2 100644 --- a/examples/shell/openiotsdk/CMakeLists.txt +++ b/examples/shell/openiotsdk/CMakeLists.txt @@ -25,9 +25,6 @@ list(APPEND CMAKE_MODULE_PATH ${OPEN_IOT_SDK_CONFIG}/cmake) set(APP_TARGET chip-openiotsdk-shell-example_ns) -set(TFM_SUPPORT YES) -set(TFM_NS_APP_VERSION "0.0.1") - # Toolchain files need to exist before first call to project include(toolchain) @@ -37,7 +34,7 @@ include(sdk) add_executable(${APP_TARGET}) -# Application CHIP build configuration +# Application CHIP build configuration set(CONFIG_CHIP_LIB_SHELL YES) include(chip) @@ -53,13 +50,13 @@ target_compile_definitions(openiotsdk-startup IOT_SDK_APP_MAIN_STACK_SIZE=8192 ) -target_include_directories(${APP_TARGET} +target_include_directories(${APP_TARGET} PRIVATE main/include ${SHELL_COMMON}/include ) -target_sources(${APP_TARGET} +target_sources(${APP_TARGET} PRIVATE main/main_ns.cpp ${SHELL_COMMON}/cmd_misc.cpp diff --git a/examples/shell/openiotsdk/freertos-config/FreeRTOSConfig.h b/examples/shell/openiotsdk/freertos-config/FreeRTOSConfig.h index 38b2a2678a34dc..dfdc0ab14f06e0 100644 --- a/examples/shell/openiotsdk/freertos-config/FreeRTOSConfig.h +++ b/examples/shell/openiotsdk/freertos-config/FreeRTOSConfig.h @@ -190,7 +190,7 @@ extern uint32_t SystemCoreClock; // Use TrustZone Secure Side Only // This settings prevents FreeRTOS contex switch to Non-Secure side. // Enable this setting when FreeRTOS runs on the Secure side only. -#define configRUN_FREERTOS_SECURE_ONLY CONFIG_RUN_FREERTOS_SECURE_ONLY +#define configRUN_FREERTOS_SECURE_ONLY 0 // Use TrustZone Security Extension // Using TrustZone affects context handling. diff --git a/scripts/examples/openiotsdk_example.sh b/scripts/examples/openiotsdk_example.sh index f80b537d1e0668..968e95127f871d 100755 --- a/scripts/examples/openiotsdk_example.sh +++ b/scripts/examples/openiotsdk_example.sh @@ -41,12 +41,12 @@ TELNET_CONNECTION_PORT="" FAILED_TESTS=0 IS_UNIT_TEST=0 FVP_NETWORK="user" -KVS_STORAGE_TYPE="tdb" KVS_STORAGE_FILE="" NO_ACTIVATE="" CRYPTO_BACKEND="mbedtls" +APP_VERSION="1" +APP_VERSION_STR="0.0.1" -declare -A tdb_storage_param=([instance]=sram [memspace]=0 [address]=0x0 [size]=0x100000) declare -A ps_storage_param=([instance]=qspi_sram [memspace]=0 [address]=0x660000 [size]=0x12000) readarray -t SUPPORTED_APP_NAMES <"$CHIP_ROOT"/examples/platform/openiotsdk/supported_examples.txt @@ -67,11 +67,12 @@ Options: -C,--command Action to execute -d,--debug Build in debug mode -l,--lwipdebug Build with LwIP debug logs support - -k,--kvsstore Select KVS storage type -b,--backend -p,--path Build path -K,--kvsfile Path to KVS storage file which will be used to ensure persistence -n,--network FVP network interface name + -v,--version Application version number + -V,--versionStr Application version string --no-activate Do not activate the chip build environment Examples: EOF @@ -122,6 +123,8 @@ function build_with_cmake() { fi BUILD_OPTIONS=(-DCMAKE_SYSTEM_PROCESSOR=cortex-m55) + BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION="$APP_VERSION") + BUILD_OPTIONS+=(-DTFM_NS_APP_VERSION="$APP_VERSION_STR") if "$DEBUG"; then BUILD_OPTIONS+=(-DCMAKE_BUILD_TYPE=Debug) @@ -133,10 +136,6 @@ function build_with_cmake() { BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_LWIP_DEBUG=YES) fi - if [[ $KVS_STORAGE_TYPE == "ps" ]]; then - BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_USE_PSA_PS=YES) - fi - BUILD_OPTIONS+=(-DCONFIG_CHIP_CRYPTO="$CRYPTO_BACKEND") cmake -G Ninja -S "$EXAMPLE_PATH" -B "$BUILD_PATH" --toolchain="$TOOLCHAIN_PATH" "${BUILD_OPTIONS[@]}" @@ -179,11 +178,7 @@ function run_fvp() { fi if [ -n "$KVS_STORAGE_FILE" ]; then - if [[ $KVS_STORAGE_TYPE == "ps" ]]; then - declare -n storage_param=ps_storage_param - else - declare -n storage_param=tdb_storage_param - fi + declare -n storage_param=ps_storage_param if [ -f "$KVS_STORAGE_FILE" ]; then RUN_OPTIONS+=(--data "mps3_board.${storage_param[instance]}=$KVS_STORAGE_FILE@${storage_param[memspace]}:${storage_param[address]}") fi @@ -273,8 +268,8 @@ function run_test() { fi } -SHORT=C:,p:,d:,l:,b:,n:,k:,K:,c,s,h -LONG=command:,path:,debug:,lwipdebug:,backend:,network:,kvsstore:,kvsfile:,clean,scratch,help,no-activate +SHORT=C:,p:,d:,l:,b:,n:,k:,K:,v:,V:,c,s,h +LONG=command:,path:,debug:,lwipdebug:,backend:,network:,kvsstore:,kvsfile:,version:,versionStr:,clean,scratch,help,no-activate OPTS=$(getopt -n build --options "$SHORT" --longoptions "$LONG" -- "$@") eval set -- "$OPTS" @@ -305,10 +300,6 @@ while :; do LWIP_DEBUG=$2 shift 2 ;; - -k | --kvsstore) - KVS_STORAGE_TYPE=$2 - shift 2 - ;; -K | --kvsfile) KVS_STORAGE_FILE=$2 shift 2 @@ -329,6 +320,14 @@ while :; do NO_ACTIVATE='YES' shift ;; + -v | --version) + APP_VERSION=$2 + shift 2 + ;; + -V | --versionStr) + APP_VERSION_STR=$2 + shift 2 + ;; -* | --*) shift break @@ -384,15 +383,6 @@ else EXAMPLE_PATH="$CHIP_ROOT/examples/$EXAMPLE/openiotsdk" fi -case "$KVS_STORAGE_TYPE" in - ps | tdb) ;; - *) - echo "Wrong KVS storage type definition" - show_usage - exit 2 - ;; -esac - case "$CRYPTO_BACKEND" in psa | mbedtls) ;; *) diff --git a/src/platform/openiotsdk/BUILD.gn b/src/platform/openiotsdk/BUILD.gn index 984b4ff28b157f..843e3ad08ec5f0 100644 --- a/src/platform/openiotsdk/BUILD.gn +++ b/src/platform/openiotsdk/BUILD.gn @@ -20,35 +20,24 @@ import("${chip_root}/src/platform/device.gni") assert(chip_device_platform == "openiotsdk") declare_args() { - # Add Trusted Firmware-M (TF-M) support - chip_openiotsdk_use_tfm = false + # Default value of software version + chip_openiotsdk_software_version = "0" - # By default use flash block device storage - chip_openiotsdk_use_psa_ps = false + # Default value of software version in string + chip_openiotsdk_software_version_string = "0.0.0" } buildconfig_header("openiotsdk_buildconfig") { header = "OpenIoTSDKConfig.h" header_dir = "ois" - if (chip_openiotsdk_use_psa_ps) { - _chip_openiotsdk_kv_store_config_include = - "" - _chip_openiotsdk_persisted_storage_key_type = "uint64_t" - } else { - _chip_openiotsdk_kv_store_config_include = - "" - _chip_openiotsdk_persisted_storage_key_type = "const char *" - } + _chip_openiotsdk_persisted_storage_key_type = "uint64_t" defines = [ - "CHIP_OPEN_IOT_SDK_KV_STORE_CONFIG_INCLUDE=${_chip_openiotsdk_kv_store_config_include}", "CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE=${_chip_openiotsdk_persisted_storage_key_type}", + "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${chip_openiotsdk_software_version_string}\"", + "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=${chip_openiotsdk_software_version}", ] - - if (chip_openiotsdk_use_tfm) { - defines += [ "CHIP_OPEN_IOT_SDK_USE_TFM=1" ] - } } static_library("openiotsdk") { @@ -65,6 +54,8 @@ static_library("openiotsdk") { "DiagnosticDataProviderImpl.cpp", "DiagnosticDataProviderImpl.h", "InetPlatformConfig.h", + "KVPsaPsStore.cpp", + "KVPsaPsStore.h", "KeyValueStoreManagerImpl.cpp", "KeyValueStoreManagerImpl.h", "Logging.cpp", @@ -85,17 +76,5 @@ static_library("openiotsdk") { "${chip_root}/src/platform:platform_base", ] - if (chip_openiotsdk_use_psa_ps) { - sources += [ - "KVPsaPsStore.cpp", - "KVPsaPsStore.h", - ] - } else { - sources += [ - "KVBlockDeviceStore.cpp", - "KVBlockDeviceStore.h", - ] - } - cflags = [ "-Wconversion" ] } diff --git a/src/platform/openiotsdk/ConfigurationManagerImpl.cpp b/src/platform/openiotsdk/ConfigurationManagerImpl.cpp index 84da3ef5c767c1..ffad98ff7ef4e2 100644 --- a/src/platform/openiotsdk/ConfigurationManagerImpl.cpp +++ b/src/platform/openiotsdk/ConfigurationManagerImpl.cpp @@ -28,11 +28,7 @@ #include -#ifdef CHIP_OPEN_IOT_SDK_USE_TFM #include "tfm_platform_api.h" -#else -#include "cmsis.h" -#endif namespace chip { namespace DeviceLayer { @@ -155,12 +151,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) // Restart the system. ChipLogProgress(DeviceLayer, "System restarting"); -#ifdef CHIP_OPEN_IOT_SDK_USE_TFM tfm_platform_system_reset(); -#else - __disable_irq(); - NVIC_SystemReset(); -#endif } ConfigurationManager & ConfigurationMgrImpl() diff --git a/src/platform/openiotsdk/ConfigurationManagerImpl.h b/src/platform/openiotsdk/ConfigurationManagerImpl.h index 044c3d55d6f377..9c7e2c2d092c81 100644 --- a/src/platform/openiotsdk/ConfigurationManagerImpl.h +++ b/src/platform/openiotsdk/ConfigurationManagerImpl.h @@ -25,8 +25,7 @@ #pragma once #include - -#include CHIP_OPEN_IOT_SDK_KV_STORE_CONFIG_INCLUDE +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/openiotsdk/KVBlockDeviceStore.cpp b/src/platform/openiotsdk/KVBlockDeviceStore.cpp deleted file mode 100644 index ef623b1f9bc2b9..00000000000000 --- a/src/platform/openiotsdk/KVBlockDeviceStore.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed 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. - */ - -/** - * @file - * Open IoT SDK key-value storage base on flash TDBStore. - */ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices. - -// NVS namespaces used to store device configuration information. -#define CHIP_CONFIG_FACTORY_PREFIX "chip-factory-" -#define CHIP_CONFIG_CONFIG_PREFIX "chip-config-" -#define CHIP_CONFIG_COUNTER_PREFIX "chip-counters-" - -#define FACTORY_KEY(key) CHIP_CONFIG_FACTORY_PREFIX key -#define CONFIG_KEY(key) CHIP_CONFIG_CONFIG_PREFIX key -#define COUNTER_KEY(key) CHIP_CONFIG_COUNTER_PREFIX key - -// Keys stored in the chip-factory namespace -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_SerialNum = { FACTORY_KEY("serial-num") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_MfrDeviceId = { FACTORY_KEY("device-id") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_MfrDeviceCert = { FACTORY_KEY("device-cert") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_MfrDeviceICACerts = { FACTORY_KEY("device-ca-certs") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_MfrDevicePrivateKey = { FACTORY_KEY("device-key") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_HardwareVersion = { FACTORY_KEY("hardware-ver") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_ManufacturingDate = { FACTORY_KEY("mfg-date") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_SetupPinCode = { FACTORY_KEY("pin-code") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_SetupDiscriminator = { FACTORY_KEY("discriminator") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_Spake2pIterationCount = { FACTORY_KEY("iteration-count") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_Spake2pSalt = { FACTORY_KEY("salt") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_Spake2pVerifier = { FACTORY_KEY("verifier") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_VendorId = { FACTORY_KEY("vendor-id") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_ProductId = { FACTORY_KEY("product-id") }; - -// Keys stored in the chip-config namespace -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_ServiceConfig = { CONFIG_KEY("service-config") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_PairedAccountId = { CONFIG_KEY("account-id") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_ServiceId = { CONFIG_KEY("service-id") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_LastUsedEpochKeyId = { CONFIG_KEY("last-ek-id") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_FailSafeArmed = { CONFIG_KEY("fail-safe-armed") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_WiFiStationSecType = { CONFIG_KEY("sta-sec-type") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_RegulatoryLocation = { CONFIG_KEY("regulatory-location") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_CountryCode = { CONFIG_KEY("country-code") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_LocationCapability = { CONFIG_KEY("location-capability") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kConfigKey_UniqueId = { CONFIG_KEY("unique-id") }; - -// Keys stored in the Chip-counters namespace -const KVBlockDeviceStore::Key KVBlockDeviceStore::kCounterKey_RebootCount = { COUNTER_KEY("reboot-count") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kCounterKey_UpTime = { COUNTER_KEY("up-time") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kCounterKey_TotalOperationalHours = { COUNTER_KEY("total-operational-hours") }; -const KVBlockDeviceStore::Key KVBlockDeviceStore::kCounterKey_BootReason = { COUNTER_KEY("boot-reason") }; - -using iotsdk::storage::kv_status; -using iotsdk::storage::KVStore; - -iotsdk::storage::TDBStore * KVBlockDeviceStore::tdb = nullptr; - -CHIP_ERROR KVBlockDeviceStore::Init(void) -{ - if (tdb) - { - return CHIP_NO_ERROR; - } - - // Create a TDBStore using the underlying storage - tdb = new iotsdk::storage::TDBStore(GetBlockDevice()); - - if (!tdb) - { - return CHIP_ERROR_INTERNAL; - } - - // KVStore uses dual stage initialization so we can handle any errors - // Call the `init` method to setup the TDBStore - kv_status err = tdb->init(); - if (err != kv_status::OK) - { - delete tdb; - // zero tdb as we use it keep track of init - tdb = nullptr; - return CHIP_ERROR_INTERNAL; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::Shutdown(void) -{ - if (!tdb) - { - return CHIP_NO_ERROR; - } - - tdb->deinit(); - delete tdb; - tdb = nullptr; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValue(Key key, bool & val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - if (!ConfigValueExists(key)) - { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - } - - size_t actual_size = 0; - kv_status err = tdb->get(key, reinterpret_cast(&val), sizeof(val), &actual_size); - - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - if (actual_size != sizeof(val)) - { - return CHIP_ERROR_BAD_REQUEST; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValue(Key key, uint32_t & val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - if (!ConfigValueExists(key)) - { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - } - - size_t actual_size = 0; - kv_status err = tdb->get(key, reinterpret_cast(&val), sizeof(val), &actual_size); - - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - if (actual_size != sizeof(val)) - { - return CHIP_ERROR_BAD_REQUEST; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValue(Key key, uint64_t & val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - if (!ConfigValueExists(key)) - { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - } - - size_t actual_size = 0; - kv_status err = tdb->get(key, &val, sizeof(val), &actual_size); - - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - if (actual_size != sizeof(val)) - { - return CHIP_ERROR_BAD_REQUEST; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) -{ - CHIP_ERROR err = ReadConfigValueBin(key, reinterpret_cast(buf), bufSize, outLen); - // Note: The system expect the trailing null to be added. - if (err != CHIP_NO_ERROR) - { - return err; - } - if (outLen >= bufSize) - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - buf[outLen] = 0; - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) -{ - return ReadConfigValueBin(key, buf, bufSize, outLen, 0); -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen, size_t offset) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - if (!ConfigValueExists(key)) - { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - } - - KVStore::info_t info; - - kv_status err = tdb->get_info(key, &info); - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - err = tdb->get(key, reinterpret_cast(buf), bufSize, &outLen, offset); - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - if (bufSize < info.size - offset) - { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR KVBlockDeviceStore::ReadConfigValueCounter(Key counterId, uint32_t & value) -{ - char key[50] = { 0 }; - auto err = ConstructCounterKey(counterId, key, sizeof(key)); - if (err != CHIP_NO_ERROR) - { - return err; - } - - return ReadConfigValue(key, value); -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValue(Key key, bool val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - kv_status err = tdb->set(key, reinterpret_cast(&val), sizeof(val), 0); - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValue(Key key, uint32_t val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - kv_status err = tdb->set(key, reinterpret_cast(&val), sizeof(val), 0); - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValue(Key key, uint64_t val) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - kv_status err = tdb->set(key, reinterpret_cast(&val), sizeof(val), 0); - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValueStr(Key key, const char * str) -{ - return WriteConfigValueBin(key, reinterpret_cast(str), (str != nullptr) ? strlen(str) : 0); -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValueStr(Key key, const char * str, size_t strLen) -{ - return WriteConfigValueBin(key, reinterpret_cast(str), (strLen > 0) ? strLen : 1); -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - // Two different behavior: If the pointer is not null, the value is updated - // or create. If the pointer is null, the key is removed if it exist. - if (data != nullptr) - { - kv_status err = tdb->set(key, reinterpret_cast(data), dataLen, 0); - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; - } - else if (ConfigValueExists(key)) - { - return ClearConfigValue(key); - } - else - { - // Nothing to do, data is null and the key does not exist. - return CHIP_NO_ERROR; - } -} - -CHIP_ERROR KVBlockDeviceStore::WriteConfigValueCounter(Key counterId, uint32_t value) -{ - char key[50] = { 0 }; - auto err = ConstructCounterKey(counterId, key, sizeof(key)); - if (err != CHIP_NO_ERROR) - { - return err; - } - - return WriteConfigValue(key, value); -} - -CHIP_ERROR KVBlockDeviceStore::ClearConfigValue(Key key) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - kv_status err = tdb->remove(key); - if (err == kv_status::ITEM_NOT_FOUND) - { - return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - } - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -CHIP_ERROR KVBlockDeviceStore::FactoryResetConfig() -{ - // tdb->reset is not used, we want to preserve other setting and factory - // configuration - auto err = ClearNamespace(CHIP_CONFIG_CONFIG_PREFIX); - if (err != CHIP_NO_ERROR) - { - return err; - } - return ClearNamespace(CHIP_CONFIG_COUNTER_PREFIX); -} - -void KVBlockDeviceStore::RunConfigUnitTest() -{ - // Run common unit test. - ::chip::DeviceLayer::Internal::RunConfigUnitTest(); -} - -bool KVBlockDeviceStore::ConfigValueExists(Key key) -{ - if (Init() != CHIP_NO_ERROR) - { - return false; - } - - KVStore::info_t info; - kv_status err = tdb->get_info(key, &info); - return err == kv_status::OK ? true : false; -} - -CHIP_ERROR KVBlockDeviceStore::ConstructCounterKey(Key id, char * buf, size_t bufSize) -{ - auto length = snprintf(buf, bufSize - 1, CHIP_CONFIG_COUNTER_PREFIX "%s", id); - if (length < 0) - { - return CHIP_ERROR_INTERNAL; - } - else if ((size_t) length > (bufSize - 1)) - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - else - { - return CHIP_NO_ERROR; - } -} - -CHIP_ERROR KVBlockDeviceStore::ClearNamespace(const char * ns) -{ - if (Init() != CHIP_NO_ERROR) - { - return CHIP_ERROR_INTERNAL; - } - - iotsdk::storage::KVStore::iterator_t it; - char key[iotsdk::storage::KVStore::MAX_KEY_SIZE]; - kv_status err = tdb->iterator_open(&it, ns); - if (err != kv_status::OK) - { - return CHIP_ERROR_INTERNAL; - } - - while (true) - { - err = tdb->iterator_next(it, key, sizeof(key)); - if (err == kv_status::OK) - { - tdb->remove(key); - memset(key, 0, sizeof(key)); - } - else if (err == kv_status::ITEM_NOT_FOUND) - { - break; - } - else - { - (void) tdb->iterator_close(it); - return CHIP_ERROR_INTERNAL; - } - } - - err = tdb->iterator_close(it); - return err == kv_status::OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL; -} - -KVBlockDeviceStoreKeyBuilder::KVBlockDeviceStoreKeyBuilder(const char * key) -{ - // Check sign by sign if key contains illegal characters - // Each illegal character will be replaced by '!' + capital encoded letter value - char * out = buffer + strlen(buffer); - char * illegal_ptr; - while ((out < buffer + sizeof(buffer) - 3) && *key) // 2 chars for potential illegal char + 1 for \0 - { - illegal_ptr = strchr(illegalCharacters, *key); - if (illegal_ptr) - { - *out++ = '!'; - *out++ = static_cast('A' + (int) (illegal_ptr - illegalCharacters)); - } - else - { - *out++ = *key; - } - key++; - } - valid = true; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/openiotsdk/KVBlockDeviceStore.h b/src/platform/openiotsdk/KVBlockDeviceStore.h deleted file mode 100644 index e817d9dde17f28..00000000000000 --- a/src/platform/openiotsdk/KVBlockDeviceStore.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed 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. - */ - -/** - * @file - * Open IoT SDK key-value storage base on flash TDBStore. - */ - -#pragma once - -#include - -#include -#include -#include -#include - -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -/** - * This class provides access to configuration information for Open IoT SDK platform - * stored in Lightweight Key Value storage over a flash block device. - */ -class KVBlockDeviceStore -{ -public: - using Key = chip::Platform::PersistedStorage::Key; - - // Key definitions for well-known keys. - // Factory keys - static const Key kConfigKey_SerialNum; - static const Key kConfigKey_MfrDeviceId; - static const Key kConfigKey_MfrDeviceCert; - static const Key kConfigKey_MfrDeviceICACerts; - static const Key kConfigKey_MfrDevicePrivateKey; - static const Key kConfigKey_HardwareVersion; - static const Key kConfigKey_ManufacturingDate; - static const Key kConfigKey_SetupPinCode; - static const Key kConfigKey_SetupDiscriminator; - static const Key kConfigKey_Spake2pIterationCount; - static const Key kConfigKey_Spake2pSalt; - static const Key kConfigKey_Spake2pVerifier; - static const Key kConfigKey_VendorId; - static const Key kConfigKey_ProductId; - - // Config Keys - static const Key kConfigKey_ServiceConfig; - static const Key kConfigKey_PairedAccountId; - static const Key kConfigKey_ServiceId; - static const Key kConfigKey_LastUsedEpochKeyId; - static const Key kConfigKey_FailSafeArmed; - static const Key kConfigKey_WiFiStationSecType; - static const Key kConfigKey_RegulatoryLocation; - static const Key kConfigKey_CountryCode; - static const Key kConfigKey_LocationCapability; - static const Key kConfigKey_UniqueId; - - // Counter Keys - static const Key kCounterKey_RebootCount; - static const Key kCounterKey_UpTime; - static const Key kCounterKey_TotalOperationalHours; - static const Key kCounterKey_BootReason; - - // Initialization - static CHIP_ERROR Init(void); - static CHIP_ERROR Shutdown(void); - - // Config value accessors - static CHIP_ERROR ReadConfigValue(Key key, bool & val); - static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val); - static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val); - static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); - static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen); - static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen, size_t offset); - static CHIP_ERROR ReadConfigValueCounter(Key counterId, uint32_t & val); - - static CHIP_ERROR WriteConfigValue(Key key, bool val); - static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); - static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); - static CHIP_ERROR WriteConfigValueStr(Key key, const char * str); - static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen); - static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen); - static CHIP_ERROR WriteConfigValueCounter(Key counterId, uint32_t val); - - static CHIP_ERROR ClearConfigValue(Key key); - - // Additional functions - static CHIP_ERROR FactoryResetConfig(void); - static void RunConfigUnitTest(void); - static bool ConfigValueExists(Key key); - -private: - static iotsdk::storage::TDBStore * tdb; - - // NVS Namespace helper functions - static CHIP_ERROR ConstructCounterKey(Key id, char * buf, size_t bufSize); - static CHIP_ERROR ClearNamespace(const char * ns); -}; - -class KVBlockDeviceStoreKeyBuilder -{ -public: - KVBlockDeviceStoreKeyBuilder(const char * key); - - void AddKey(void) {} - void RemoveKey(void) {} - - KVBlockDeviceStore::Key GetKey() const; - -private: - char buffer[PersistentStorageDelegate::kKeyLengthMax + 1] = "chip-kvs-"; - bool valid; - // Mbed KV storage does not accept these characters in the key definition - const char * illegalCharacters = " */?:;\"|<>\\"; -}; - -inline KVBlockDeviceStore::Key KVBlockDeviceStoreKeyBuilder::GetKey() const -{ - return valid ? buffer : nullptr; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -using KVStoreConfig = chip::DeviceLayer::Internal::KVBlockDeviceStore; -using KVStoreKeyBuilder = chip::DeviceLayer::Internal::KVBlockDeviceStoreKeyBuilder; diff --git a/src/platform/openiotsdk/KeyValueStoreManagerImpl.cpp b/src/platform/openiotsdk/KeyValueStoreManagerImpl.cpp index 8cf11d2e1ffc77..6901db25812a47 100644 --- a/src/platform/openiotsdk/KeyValueStoreManagerImpl.cpp +++ b/src/platform/openiotsdk/KeyValueStoreManagerImpl.cpp @@ -27,8 +27,7 @@ #include #include - -#include CHIP_OPEN_IOT_SDK_KV_STORE_CONFIG_INCLUDE +#include using namespace ::chip::DeviceLayer::Internal; diff --git a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt index 740e4e55261ee3..1cde881e574bd9 100644 --- a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt +++ b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt @@ -22,9 +22,7 @@ get_filename_component(OPEN_IOT_SDK_EXAMPLE_COMMON ${CHIP_ROOT}/examples/platfor list(APPEND CMAKE_MODULE_PATH ${OPEN_IOT_SDK_CONFIG}/cmake) -set(TFM_SUPPORT YES) - -# Application CHIP build configuration +# Application CHIP build configuration set(CONFIG_CHIP_LIB_TESTS YES) set(CONFIG_CHIP_DETAIL_LOGGING NO) set(CONFIG_CHIP_PROGRESS_LOGGING NO) diff --git a/src/test_driver/openiotsdk/unit-tests/freertos-config/FreeRTOSConfig.h b/src/test_driver/openiotsdk/unit-tests/freertos-config/FreeRTOSConfig.h index 0e306efb13d231..960b03ef96a7b4 100644 --- a/src/test_driver/openiotsdk/unit-tests/freertos-config/FreeRTOSConfig.h +++ b/src/test_driver/openiotsdk/unit-tests/freertos-config/FreeRTOSConfig.h @@ -190,7 +190,7 @@ extern uint32_t SystemCoreClock; // Use TrustZone Secure Side Only // This settings prevents FreeRTOS contex switch to Non-Secure side. // Enable this setting when FreeRTOS runs on the Secure side only. -#define configRUN_FREERTOS_SECURE_ONLY CONFIG_RUN_FREERTOS_SECURE_ONLY +#define configRUN_FREERTOS_SECURE_ONLY 0 // Use TrustZone Security Extension // Using TrustZone affects context handling. diff --git a/third_party/open-iot-sdk/storage b/third_party/open-iot-sdk/storage deleted file mode 160000 index b5e4edc1b65ada..00000000000000 --- a/third_party/open-iot-sdk/storage +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b5e4edc1b65adafbe6f646c474bc8c206cd8370a