Skip to content

Commit

Permalink
[OIS] TF-M and kv store improvements (#27481)
Browse files Browse the repository at this point in the history
* [OIS] Add software version to Matter stack

Set Matter stack software version configurable from application level.
Add software version options in build script.

Signed-off-by: ATmobica <[email protected]>

* [OIS] Remove block device storage support

Remove block device KVS store from OIS platform.
Remove flash block device class implementation.
Remove block device support from build script, cmake and documentation.
Remove OIS storage git submodule.

Signed-off-by: ATmobica <[email protected]>

* [OIS] Set default TF-M support to examples

Remove non TF-M example build option.
Now, all OIS applications support TF-M by default.
Remove TFM_SUPPORT flag.
Remove non TF-M linker script.
Documentation udpate.

Signed-off-by: ATmobica <[email protected]>

---------

Signed-off-by: ATmobica <[email protected]>
  • Loading branch information
ATmobica authored and pull[bot] committed Aug 8, 2023
1 parent 309c414 commit 2581133
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 1,597 deletions.
5 changes: 0 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions config/openiotsdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions config/openiotsdk/cmake/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,25 @@ 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)
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
Expand Down
79 changes: 14 additions & 65 deletions config/openiotsdk/cmake/sdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -124,7 +119,7 @@ if(TARGET cmsis-rtos-api)

target_compile_definitions(cmsis-rtos-api
PUBLIC
DOMAIN_NS=$<IF:$<BOOL:${TFM_SUPPORT}>,1,0>
DOMAIN_NS=1
)

if(TARGET freertos-kernel)
Expand All @@ -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=$<IF:$<BOOL:${TFM_SUPPORT}>,0,1>
)
elseif(TARGET cmsis-rtx)
target_link_libraries(cmsis-rtos-api
INTERFACE
Expand Down Expand Up @@ -191,7 +181,7 @@ endif()
if(TARGET mcu-driver-hal)
target_compile_definitions(mcu-driver-hal
INTERFACE
DOMAIN_NS=$<IF:$<BOOL:${TFM_SUPPORT}>,1,0>
DOMAIN_NS=1
)

# Fixing the optimization issue for mcu-driver-hal target in the release build.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -355,29 +329,4 @@ if(TFM_SUPPORT)
$<TARGET_FILE_DIR:${target}>/${target}_merged.elf
VERBATIM
)
else()
add_custom_command(
TARGET
${target}
POST_BUILD
DEPENDS
$<TARGET_FILE_DIR:${target}>/${target}.elf
$<TARGET_FILE_DIR:${target}>/${target}.map
COMMAND
# Rename output elf file
${CMAKE_COMMAND} -E copy
$<TARGET_FILE_DIR:${target}>/${target}.elf
$<TARGET_FILE_DIR:${target}>/${APP_NAME}.elf
COMMAND
# Rename output map file
${CMAKE_COMMAND} -E copy
$<TARGET_FILE_DIR:${target}>/${target}.map
$<TARGET_FILE_DIR:${target}>/${APP_NAME}.map
COMMAND rm
ARGS -Rf
$<TARGET_FILE_DIR:${target}>/${target}.elf
$<TARGET_FILE_DIR:${target}>/${target}.map
VERBATIM
)
endif() #TFM_SUPPORT
endfunction()
39 changes: 17 additions & 22 deletions config/openiotsdk/ld/cs300_gcc.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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 = .;

Expand All @@ -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 :
{
Expand All @@ -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 = .;

Expand Down Expand Up @@ -137,7 +132,7 @@ SECTIONS
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > DATA_SRAM
} > RAM

.bss :
{
Expand All @@ -147,7 +142,7 @@ SECTIONS
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > DATA_SRAM
} > RAM

bss_size = __bss_end__ - __bss_start__;

Expand All @@ -158,7 +153,7 @@ SECTIONS
KEEP(*(.stack*))
. += __stack_size__;
__StackTop = .;
} > DTCM
} > RAM
PROVIDE(__stack = __StackTop);

.heap (COPY):
Expand All @@ -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")
}
Loading

0 comments on commit 2581133

Please sign in to comment.