T398: Source cleanup for tool chain integration
This is a code cleanup to improve portability.
Specific issues addressed:
- Added type casts to (void *) here and there
- Changed non-standard \e escapes to \033
- Added cmake function to handle preinclude
- Changed a few Image$$ references to make use of the REGION_DECLARE
macro
- Reordered code slightly to avoid the need for a "void *rangeptr"
variable
- Changed compile time check typedef "err_msg" to avoid declaring
zero sized array, which is not standards compliant. It will now
either be -1 (error) or 1 (ok), not -1 and 0
- Reordered the *nfsptr_t typedef to make the cmse_nonsecure_call
standards compliant
- Added null tests to both secure and non_secure suites to avoid
defining zero length array. Also use this to find end of list
- Only define __stdout for ARMCLANG builds and conditionalize ns printf
output for ARMCLANG/GCC/IAR
- Cleaned up some enum type mismatches
- Changed non standard EINVAL error return to -1. The value was only
checked against 0 anyway
- Added type cast for conversion from float to int
Have tested with IAR, which starts and runs the idle thread. Changes
related to this is not included in this commit.
Author: Thomas Tornblom <thomas.tornblom@iar.com>
Signed-off-by: Thomas Tornblom <thomas.tornblom@iar.com>
Note: Sign off authority needs to adhere to the [DCO](./dco.txt)
rules.
Change-Id: I3e5229c0777623b128474af0311020ccacc1b797
diff --git a/BuildMbedtls.cmake b/BuildMbedtls.cmake
index afb5307..3856248 100644
--- a/BuildMbedtls.cmake
+++ b/BuildMbedtls.cmake
@@ -43,7 +43,8 @@
if((NOT DEFINED MBEDTLS_PREINCLUDE_PREFIX) OR (NOT DEFINED MBEDTLS_PREINCLUDE_HEADER))
message(STATUS "Building mbedTLS without pre-included headers and global symbols prefixing.")
else()
- set(MBEDTLS_PREINCLUDE_C_FLAGS " -DLIB_PREFIX_NAME=${MBEDTLS_PREINCLUDE_PREFIX} -include ${MBEDTLS_PREINCLUDE_HEADER}")
+ compiler_get_preinclude_option_string(${MBEDTLS_PREINCLUDE_HEADER} _PRE_INC_STRING)
+ set(MBEDTLS_PREINCLUDE_C_FLAGS " -DLIB_PREFIX_NAME=${MBEDTLS_PREINCLUDE_PREFIX} ${_PRE_INC_STRING}")
string(APPEND MBEDTLS_C_FLAGS ${MBEDTLS_PREINCLUDE_C_FLAGS})
endif()
diff --git a/app/main_ns.c b/app/main_ns.c
index 0205b1b..c648dfe 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -57,6 +57,7 @@
*/
};
+#if defined(__ARMCC_VERSION)
/* Struct FILE is implemented in stdio.h. Used to redirect printf to
* NS_DRIVER_STDIO
*/
@@ -68,6 +69,7 @@
/* Return character written */
return ch;
}
+#elif defined(__GNUC__)
/* redirects gcc printf to NS_DRIVER_STDIO */
int _write(int fd, char * str, int len)
{
@@ -75,6 +77,15 @@
return len;
}
+#elif defined(__ICCARM__)
+int putchar(int ch)
+{
+ /* Send byte to NS_DRIVER_STDIO */
+ (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
+ /* Return character written */
+ return ch;
+}
+#endif
/**
* \brief List of RTOS thread attributes
diff --git a/app/os_wrapper_rtx.c b/app/os_wrapper_rtx.c
index 0952b2c..9a9a887 100644
--- a/app/os_wrapper_rtx.c
+++ b/app/os_wrapper_rtx.c
@@ -23,7 +23,7 @@
task_attribs.attr_bits = osThreadJoinable;
task_attribs.stack_size = stack_size;
task_attribs.name = name;
- task_attribs.priority = priority;
+ task_attribs.priority = (osPriority_t) priority;
thread_id = osThreadNew(func, arg, &task_attribs);
if (thread_id == NULL) {
diff --git a/app/tfm_integ_test.h b/app/tfm_integ_test.h
index a823ff1..1e419d2 100644
--- a/app/tfm_integ_test.h
+++ b/app/tfm_integ_test.h
@@ -50,10 +50,10 @@
#ifndef LOG_MSG_HANDLER_MODE_PRINTF_ENABLED
/* if IPSR is non-zero, exception is active. NOT banked S/NS */
if (!__get_IPSR()) {
- printf("\t\e[1;32m[Non-Sec] %s\e[0m\r\n", MSG);
+ printf("\t\033[1;32m[Non-Sec] %s\033[0m\r\n", MSG);
}
#else
- printf("\t\e[1;32m[Non-Sec] %s\e[0m\r\n", MSG);
+ printf("\t\033[1;32m[Non-Sec] %s\033[0m\r\n", MSG);
#endif
}
diff --git a/bl2/ext/mcuboot/flash_map.c b/bl2/ext/mcuboot/flash_map.c
index 09d0ad0..937c18e 100644
--- a/bl2/ext/mcuboot/flash_map.c
+++ b/bl2/ext/mcuboot/flash_map.c
@@ -95,7 +95,7 @@
if (fd_id != FLASH_DEVICE_ID) {
BOOT_LOG_ERR("invalid flash ID %d; expected %d",
fd_id, FLASH_DEVICE_ID);
- return -EINVAL;
+ return -1;
}
*ret = FLASH_DEVICE_BASE;
return 0;
diff --git a/bl2/ext/mcuboot/include/bl2_util.h b/bl2/ext/mcuboot/include/bl2_util.h
index 8315681..ea8df98 100644
--- a/bl2/ext/mcuboot/include/bl2_util.h
+++ b/bl2/ext/mcuboot/include/bl2_util.h
@@ -19,9 +19,17 @@
/* Evaluates to 0 if array is an array; compile error if not array (e.g.
* pointer)
*/
+#if defined(NO_TYPEOF)
+ /* __typeof__ is a non-standard gcc extension, not universally available.
+ * As this is just compile time data type test, assume things are ok for
+ * tool chains missing this feature.
+ */
+#define IS_ARRAY(array) 0
+#else
#define IS_ARRAY(array) \
ZERO_OR_COMPILE_ERROR(!__builtin_types_compatible_p(__typeof__(array), \
__typeof__(&(array)[0])))
+#endif
#define ARRAY_SIZE(array) \
((unsigned long) (IS_ARRAY(array) + \
diff --git a/cmake/Common/CompilerArmClangCommon.cmake b/cmake/Common/CompilerArmClangCommon.cmake
index de3fea4..9817473 100644
--- a/cmake/Common/CompilerArmClangCommon.cmake
+++ b/cmake/Common/CompilerArmClangCommon.cmake
@@ -56,6 +56,43 @@
include(Compiler/ARMClang-ASM)
endif()
+function(compiler_get_preinclude_option_string INCLUDE RES)
+ set(${RES} "-include ${INCLUDE}" PARENT_SCOPE)
+endfunction()
+
+function(compiler_set_preinclude_file)
+ #Option (on/off) arguments.
+ set( _OPTIONS_ARGS GLOBAL)
+ #Single option arguments.
+ set( _ONE_VALUE_ARGS INCLUDE)
+ #List arguments
+ set( _MULTI_VALUE_ARGS TARGETS FILES)
+ cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
+ if(NOT DEFINED _MY_PARAMS)
+ message(FATAL_ERROR "compiler_set_preinclude_file: missing mandatory parameter INCLUDE.")
+ endif()
+ compiler_get_preinclude_option_string(${INCLUDE} _OPTION_STRING)
+ #If include is to be set globally, we ignore TARGETS and FILES
+ if(_MY_PARAMS_GLOBAL)
+ set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY COMPILE_OPTIONS "${_OPTION_STRING}")
+ else()
+ #If GLOBAL was not passed, then either TARGETS or FILES must be present
+ if(NOT DEFINED _MY_PARAM_TARGETS AND NOT DEFINED _MY_PARAM_FILES)
+ message(FATAL_ERROR "compiler_set_preinclude_file: missing mandatory parameter. Either TARGETS and/or FILES must be specified.")
+ endif()
+ #Iterate over targets. Note: call embedded_set_target_compile_flags to
+ #allow the target to be defined after this function call. This helps
+ #modularisation
+ foreach(_TGT IN_LISTS _MY_PARAM_TARGETS)
+ embedded_set_target_compile_flags(TARGET ${_TGT} LANGUAGE "C" FLAGS "${_OPTION_STRING}")
+ endforeach()
+ #Iterate over files
+ foreach(_FILE IN_LISTS _MY_PARAM_FILES)
+ set_property(FILE ${_FILE} APPEND PROPERTY COMPILE_OPTIONS "${_OPTION_STRING}")
+ endforeach()
+ endif()
+endfunction()
+
function(compiler_set_linkercmdfile)
set( _OPTIONS_ARGS ) #Option (on/off) arguments.
set( _ONE_VALUE_ARGS TARGET PATH) #Single option arguments.
diff --git a/cmake/Common/CompilerGNUARMCommon.cmake b/cmake/Common/CompilerGNUARMCommon.cmake
index 2f7639f..cf515cf 100644
--- a/cmake/Common/CompilerGNUARMCommon.cmake
+++ b/cmake/Common/CompilerGNUARMCommon.cmake
@@ -56,6 +56,43 @@
include(Compiler/GNUARM-ASM)
endif()
+function(compiler_get_preinclude_option_string INCLUDE RES)
+ set(${RES} "-include ${INCLUDE}" PARENT_SCOPE)
+endfunction()
+
+function(compiler_set_preinclude_file)
+ #Option (on/off) arguments.
+ set( _OPTIONS_ARGS GLOBAL)
+ #Single option arguments.
+ set( _ONE_VALUE_ARGS INCLUDE)
+ #List arguments
+ set( _MULTI_VALUE_ARGS TARGETS FILES)
+ cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
+ if(NOT DEFINED _MY_PARAMS)
+ message(FATAL_ERROR "compiler_set_preinclude_file: missing mandatory parameter INCLUDE.")
+ endif()
+ compiler_get_preinclude_option_string(${INCLUDE} _OPTION_STRING)
+ #If include is to be set globally, we ignore TARGETS and FILES
+ if(_MY_PARAMS_GLOBAL)
+ set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY COMPILE_OPTIONS "${_OPTION_STRING}")
+ else()
+ #If GLOBAL was not passed, then either TARGETS or FILES must be present
+ if(NOT DEFINED _MY_PARAM_TARGETS AND NOT DEFINED _MY_PARAM_FILES)
+ message(FATAL_ERROR "compiler_set_preinclude_file: missing mandatory parameter. Either TARGETS and/or FILES must be specified.")
+ endif()
+ #Iterate over targets. Note: call embedded_set_target_compile_flags to
+ #allow the target to be defined after this function call. This helps
+ #modularisation
+ foreach(_TGT IN_LISTS _MY_PARAM_TARGETS)
+ embedded_set_target_compile_flags(TARGET ${_TGT} LANGUAGE "C" FLAGS "${_OPTION_STRING}")
+ endforeach()
+ #Iterate over files
+ foreach(_FILE IN_LISTS _MY_PARAM_FILES)
+ set_property(FILE ${_FILE} APPEND PROPERTY COMPILE_OPTIONS "${_OPTION_STRING}")
+ endforeach()
+ endif()
+endfunction()
+
function(compiler_set_linkercmdfile)
set( _OPTIONS_ARGS ) #Option (on/off) arguments.
set( _ONE_VALUE_ARGS TARGET PATH) #Single option arguments.
diff --git a/interface/src/tfm_audit_api.c b/interface/src/tfm_audit_api.c
index 0770bd0..9ce86ef 100644
--- a/interface/src/tfm_audit_api.c
+++ b/interface/src/tfm_audit_api.c
@@ -26,7 +26,7 @@
struct audit_core_retrieve_output output_s = {.buffer = buffer,
.record_size = record_size};
- return tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_retrieve_record,
+ return (enum psa_audit_err) tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_retrieve_record,
(uint32_t)&input_s,
(uint32_t)&output_s,
0,
@@ -36,7 +36,7 @@
enum psa_audit_err psa_audit_get_info(uint32_t *num_records,
uint32_t *size)
{
- return tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_get_info,
+ return (enum psa_audit_err) tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_get_info,
(uint32_t)num_records,
(uint32_t)size,
0,
@@ -46,7 +46,7 @@
enum psa_audit_err psa_audit_get_record_info(const uint32_t record_index,
uint32_t *size)
{
- return tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_get_record_info,
+ return (enum psa_audit_err) tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_get_record_info,
(uint32_t)record_index,
(uint32_t)size,
0,
@@ -57,7 +57,7 @@
const uint8_t *token,
const uint32_t token_size)
{
- return tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_delete_record,
+ return (enum psa_audit_err) tfm_ns_lock_dispatch((veneer_fn)tfm_audit_veneer_delete_record,
(uint32_t)record_index,
(uint32_t)token,
(uint32_t)token_size,
diff --git a/lib/ext/qcbor/src/qcbor_decode.c b/lib/ext/qcbor/src/qcbor_decode.c
index 8e485ab..fa89b09 100644
--- a/lib/ext/qcbor/src/qcbor_decode.c
+++ b/lib/ext/qcbor/src/qcbor_decode.c
@@ -660,7 +660,7 @@
/*
The epoch formatted date. Turns lots of different forms of encoding date into uniform one
*/
-static int DecodeDateEpoch(QCBORItem *pDecodedItem)
+static QCBORError DecodeDateEpoch(QCBORItem *pDecodedItem)
{
// Stack usage: 1
QCBORError nReturn = QCBOR_SUCCESS;
@@ -688,7 +688,7 @@
nReturn = QCBOR_ERR_DATE_OVERFLOW;
goto Done;
}
- pDecodedItem->val.epochDate.nSeconds = d; // Float to integer conversion happening here.
+ pDecodedItem->val.epochDate.nSeconds = (int64_t) d; // Float to integer conversion happening here.
pDecodedItem->val.epochDate.fSecondsFraction = d - pDecodedItem->val.epochDate.nSeconds;
}
break;
@@ -1199,7 +1199,7 @@
*/
QCBORError QCBORDecode_Finish(QCBORDecodeContext *me)
{
- int nReturn = QCBOR_SUCCESS;
+ QCBORError nReturn = QCBOR_SUCCESS;
// Error out if all the maps/arrays are not closed out
if(DecodeNesting_IsNested(&(me->nesting))) {
diff --git a/lib/ext/qcbor/src/qcbor_encode.c b/lib/ext/qcbor/src/qcbor_encode.c
index c652f79..1155cda 100644
--- a/lib/ext/qcbor/src/qcbor_encode.c
+++ b/lib/ext/qcbor/src/qcbor_encode.c
@@ -576,7 +576,7 @@
*/
QCBORError QCBOREncode_Finish(QCBOREncodeContext *me, UsefulBufC *pEncodedCBOR)
{
- QCBORError uReturn = me->uError;
+ QCBORError uReturn = (QCBORError) me->uError;
if(uReturn != QCBOR_SUCCESS) {
goto Done;
diff --git a/lib/ext/qcbor/test/float_tests.c b/lib/ext/qcbor/test/float_tests.c
index eaf75aa..4f12ca6 100644
--- a/lib/ext/qcbor/test/float_tests.c
+++ b/lib/ext/qcbor/test/float_tests.c
@@ -73,7 +73,7 @@
UsefulBufC HalfPrecision = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedHalf);
QCBORDecodeContext DC;
- QCBORDecode_Init(&DC, HalfPrecision, 0);
+ QCBORDecode_Init(&DC, HalfPrecision, QCBOR_DECODE_MODE_NORMAL);
QCBORItem Item;
@@ -194,7 +194,7 @@
// Now parse the hand-constructed CBOR. This will invoke the conversion to a float
QCBORDecodeContext DC;
- QCBORDecode_Init(&DC, UsefulOutBuf_OutUBuf(&UOB), 0);
+ QCBORDecode_Init(&DC, UsefulOutBuf_OutUBuf(&UOB), QCBOR_DECODE_MODE_NORMAL);
QCBORItem Item;
diff --git a/lib/ext/qcbor/util/qcbor_util.c b/lib/ext/qcbor/util/qcbor_util.c
index bcace0a..22c8eae 100644
--- a/lib/ext/qcbor/util/qcbor_util.c
+++ b/lib/ext/qcbor/util/qcbor_util.c
@@ -232,7 +232,7 @@
goto Done;
}
- QCBORDecode_Init(&decode_context, payload, 0);
+ QCBORDecode_Init(&decode_context, payload, QCBOR_DECODE_MODE_NORMAL);
return_value = qcbor_util_get_item_in_map(&decode_context,
label,
diff --git a/lib/t_cose/src/t_cose_sign1_verify.c b/lib/t_cose/src/t_cose_sign1_verify.c
index 29b6c10..27cb419 100644
--- a/lib/t_cose/src/t_cose_sign1_verify.c
+++ b/lib/t_cose/src/t_cose_sign1_verify.c
@@ -92,7 +92,7 @@
QCBORDecodeContext decode_context;
QCBORItem item;
- QCBORDecode_Init(&decode_context, protected_headers, 0);
+ QCBORDecode_Init(&decode_context, protected_headers, QCBOR_DECODE_MODE_NORMAL);
if(qcbor_util_get_item_in_map(&decode_context,
COSE_HEADER_PARAM_ALG,
diff --git a/platform/ext/common/uart_stdout.c b/platform/ext/common/uart_stdout.c
index dea538f..a8bfe58 100644
--- a/platform/ext/common/uart_stdout.c
+++ b/platform/ext/common/uart_stdout.c
@@ -27,11 +27,6 @@
/* Imports USART driver */
extern ARM_DRIVER_USART TFM_DRIVER_STDIO;
-/* Struct FILE is implemented in stdio.h. Used to redirect printf to
- * TFM_DRIVER_STDIO
- */
-FILE __stdout;
-
static void uart_putc(unsigned char c)
{
int32_t ret = ARM_DRIVER_OK;
@@ -42,6 +37,11 @@
/* Redirects printf to TFM_DRIVER_STDIO in case of ARMCLANG*/
#if defined(__ARMCC_VERSION)
+/* Struct FILE is implemented in stdio.h. Used to redirect printf to
+ * TFM_DRIVER_STDIO
+ */
+FILE __stdout;
+
/* __ARMCC_VERSION is only defined starting from Arm compiler version 6 */
int fputc(int ch, FILE *f)
{
@@ -65,6 +65,15 @@
/* Return the number of characters written */
return len;
}
+#elif defined(__ICCARM__)
+int putchar(int ch)
+{
+ /* Send byte to USART */
+ uart_putc(ch);
+
+ /* Return character written */
+ return ch;
+}
#endif
void stdio_init(void)
diff --git a/platform/ext/target/musca_a/Device/Source/device_definition.c b/platform/ext/target/musca_a/Device/Source/device_definition.c
index 09d1cac..cdafe2b 100644
--- a/platform/ext/target/musca_a/Device/Source/device_definition.c
+++ b/platform/ext/target/musca_a/Device/Source/device_definition.c
@@ -496,7 +496,7 @@
.def_parity = UART_PL011_PARITY_DISABLED,
.def_stopbit = UART_PL011_STOPBIT_1};
static struct uart_pl011_dev_data_t UART0_PL011_DEV_DATA_S = {
- .state = 0,
+ .state = UART_PL011_UNINITIALIZED,
.uart_clk = 0,
.baudrate = 0};
struct uart_pl011_dev_t UART0_PL011_DEV_S = {&(UART0_PL011_DEV_CFG_S),
@@ -511,7 +511,7 @@
.def_parity = UART_PL011_PARITY_DISABLED,
.def_stopbit = UART_PL011_STOPBIT_1};
static struct uart_pl011_dev_data_t UART0_PL011_DEV_DATA_NS = {
- .state = 0,
+ .state = UART_PL011_UNINITIALIZED,
.uart_clk = 0,
.baudrate = 0};
struct uart_pl011_dev_t UART0_PL011_DEV_NS = {&(UART0_PL011_DEV_CFG_NS),
@@ -526,7 +526,7 @@
.def_parity = UART_PL011_PARITY_DISABLED,
.def_stopbit = UART_PL011_STOPBIT_1};
static struct uart_pl011_dev_data_t UART1_PL011_DEV_DATA_S = {
- .state = 0,
+ .state = UART_PL011_UNINITIALIZED,
.uart_clk = 0,
.baudrate = 0};
struct uart_pl011_dev_t UART1_PL011_DEV_S = {&(UART1_PL011_DEV_CFG_S),
@@ -541,7 +541,7 @@
.def_parity = UART_PL011_PARITY_DISABLED,
.def_stopbit = UART_PL011_STOPBIT_1};
static struct uart_pl011_dev_data_t UART1_PL011_DEV_DATA_NS = {
- .state = 0,
+ .state = UART_PL011_UNINITIALIZED,
.uart_clk = 0,
.baudrate = 0};
struct uart_pl011_dev_t UART1_PL011_DEV_NS = {&(UART1_PL011_DEV_CFG_NS),
diff --git a/secure_fw/core/tfm_core.c b/secure_fw/core/tfm_core.c
index fc060f3..dd65cd5 100644
--- a/secure_fw/core/tfm_core.c
+++ b/secure_fw/core/tfm_core.c
@@ -195,8 +195,8 @@
#ifndef TFM_PSA_API
tfm_spm_partition_set_state(TFM_SP_CORE_ID, SPM_PARTITION_STATE_RUNNING);
- extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
- uint32_t psp_stack_bottom = (uint32_t)Image$$ARM_LIB_STACK$$ZI$$Base;
+ REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base)[];
+ uint32_t psp_stack_bottom = (uint32_t)REGION_NAME(Image$$, ARM_LIB_STACK, $$ZI$$Base);
__set_PSPLIM(psp_stack_bottom);
diff --git a/secure_fw/core/tfm_func_api.c b/secure_fw/core/tfm_func_api.c
index aeaf5f2..2edb3b6 100644
--- a/secure_fw/core/tfm_func_api.c
+++ b/secure_fw/core/tfm_func_api.c
@@ -497,8 +497,8 @@
(struct tfm_exc_stack_t *)ret_part_data->stack_ptr);
*excReturn = ret_part_data->lr;
__set_PSP(ret_part_data->stack_ptr);
- extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
- uint32_t psp_stack_bottom = (uint32_t)Image$$ARM_LIB_STACK$$ZI$$Base;
+ REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base)[];
+ uint32_t psp_stack_bottom = (uint32_t)REGION_NAME(Image$$, ARM_LIB_STACK, $$ZI$$Base);
__set_PSPLIM(psp_stack_bottom);
/* FIXME: The condition should be removed once all the secure service
@@ -829,7 +829,6 @@
uint32_t running_partition_flags =
tfm_spm_partition_get_flags(running_partition_idx);
int32_t flags = 0;
- void *rangeptr;
if (!(running_partition_flags & SPM_PART_FLAG_APP_ROT) || (size == 0)) {
/* This handler should only be called from a secure partition. */
@@ -848,16 +847,14 @@
}
/* Check if partition access to address would fail */
- rangeptr = cmse_check_address_range((void *)ptr, size, flags);
-
- /* Get regions associated with address */
- cmse_address_info_t addr_info = cmse_TT((void *)ptr);
-
- if (rangeptr == NULL) {
+ if (cmse_check_address_range((void *)ptr, size, flags) == NULL) {
svc_args[0] = TFM_ERROR_INVALID_PARAMETER;
return;
}
+ /* Get regions associated with address */
+ cmse_address_info_t addr_info = cmse_TT((void *)ptr);
+
if (addr_info.flags.secure) {
#if TFM_LVL == 1
/* For privileged partition execution, all secure data memory is
diff --git a/secure_fw/core/tfm_handler.c b/secure_fw/core/tfm_handler.c
index 10a91a56..3195634 100644
--- a/secure_fw/core/tfm_handler.c
+++ b/secure_fw/core/tfm_handler.c
@@ -203,7 +203,7 @@
break;
#endif
case TFM_SVC_PRINT:
- printf("\e[1;34m[Sec Thread] %s\e[0m\r\n", (char *)svc_args[0]);
+ printf("\033[1;34m[Sec Thread] %s\033[0m\r\n", (char *)svc_args[0]);
break;
case TFM_SVC_GET_BOOT_DATA:
tfm_core_get_boot_data_handler(svc_args);
diff --git a/secure_fw/core/tfm_internal.h b/secure_fw/core/tfm_internal.h
index 6273478..dad36ad 100644
--- a/secure_fw/core/tfm_internal.h
+++ b/secure_fw/core/tfm_internal.h
@@ -17,7 +17,7 @@
* Registers will be cleared before branching so that no information leaks
* from secure to non-secure world.
*/
-typedef void __attribute__((cmse_nonsecure_call)) (*nsfptr_t) (void);
+typedef void (*nsfptr_t) (void) __attribute__((cmse_nonsecure_call));
extern nsfptr_t ns_entry;
diff --git a/secure_fw/ns_callable/tfm_audit_veneers.c b/secure_fw/ns_callable/tfm_audit_veneers.c
index a48ec87..7256482 100644
--- a/secure_fw/ns_callable/tfm_audit_veneers.c
+++ b/secure_fw/ns_callable/tfm_audit_veneers.c
@@ -17,7 +17,7 @@
struct audit_core_retrieve_output *output_s)
{
TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID,
- audit_core_retrieve_record_wrapper,
+ (void *) audit_core_retrieve_record_wrapper,
input_s, output_s, 0, 0);
}
@@ -25,7 +25,7 @@
enum psa_audit_err tfm_audit_veneer_add_record(
const struct psa_audit_record *record)
{
- TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, audit_core_add_record,
+ TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, (void *) audit_core_add_record,
record, 0, 0, 0);
}
@@ -33,7 +33,7 @@
enum psa_audit_err tfm_audit_veneer_get_info(uint32_t *num_records,
uint32_t *size)
{
- TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, audit_core_get_info,
+ TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, (void *) audit_core_get_info,
num_records, size, 0, 0);
}
@@ -41,7 +41,7 @@
enum psa_audit_err tfm_audit_veneer_get_record_info(const uint32_t record_index,
uint32_t *size)
{
- TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, audit_core_get_record_info,
+ TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, (void *) audit_core_get_record_info,
record_index, size, 0, 0);
}
@@ -50,6 +50,6 @@
const uint8_t *token,
const uint32_t token_size)
{
- TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, audit_core_delete_record,
+ TFM_CORE_SFN_REQUEST(TFM_SP_AUDIT_LOG_ID, (void *) audit_core_delete_record,
record_index, token, token_size, 0);
}
diff --git a/secure_fw/ns_callable/tfm_veneers.c b/secure_fw/ns_callable/tfm_veneers.c
index 3effa95..2ba8a2c 100644
--- a/secure_fw/ns_callable/tfm_veneers.c
+++ b/secure_fw/ns_callable/tfm_veneers.c
@@ -118,7 +118,7 @@
size_t out_len) \
{ \
TFM_CORE_IOVEC_SFN_REQUEST(partition_name##_ID, \
- sfn_name, \
+ (void *) sfn_name, \
in_vec, in_len, out_vec, out_len); \
}
diff --git a/secure_fw/ns_callable/tfm_veneers.c.template b/secure_fw/ns_callable/tfm_veneers.c.template
index 828a8c4..b58b2f3 100644
--- a/secure_fw/ns_callable/tfm_veneers.c.template
+++ b/secure_fw/ns_callable/tfm_veneers.c.template
@@ -32,7 +32,7 @@
size_t out_len) \
{ \
TFM_CORE_IOVEC_SFN_REQUEST(partition_name##_ID, \
- sfn_name, \
+ (void *) sfn_name, \
in_vec, in_len, out_vec, out_len); \
}
diff --git a/secure_fw/services/secure_storage/sst_utils.h b/secure_fw/services/secure_storage/sst_utils.h
index 6a3662f..b03b6c7 100644
--- a/secure_fw/services/secure_storage/sst_utils.h
+++ b/secure_fw/services/secure_storage/sst_utils.h
@@ -39,7 +39,7 @@
* "... error: 'err_msg' declared as an array with a negative size"
*/
#define SST_UTILS_BOUND_CHECK(err_msg, data_size, data_buf_size) \
-typedef char err_msg[(data_size <= data_buf_size) - 1]
+typedef char err_msg[(data_size <= data_buf_size)*2 - 1]
/**
* \brief Macro to get the number of bytes aligned with the
diff --git a/test/framework/non_secure_suites.c b/test/framework/non_secure_suites.c
index e0f9d13..fac7299 100644
--- a/test/framework/non_secure_suites.c
+++ b/test/framework/non_secure_suites.c
@@ -86,12 +86,13 @@
/* Non-secure IPC test cases */
{®ister_testsuite_ns_ipc_interface, 0, 0, 0},
#endif
+ /* End of test suites */
+ {0, 0, 0, 0}
};
void start_integ_test(void)
{
- integ_test("Non-secure", test_suites,
- sizeof(test_suites)/sizeof(test_suites[0]));
+ integ_test("Non-secure", test_suites);
}
/* Service stand-in for NS tests. To be called from a non-secure context */
diff --git a/test/framework/secure_suites.c b/test/framework/secure_suites.c
index 8eda21f..89613d4 100644
--- a/test/framework/secure_suites.c
+++ b/test/framework/secure_suites.c
@@ -65,6 +65,8 @@
#endif
#endif /* SERVICES_TEST_S */
#endif /* TFM_LVL == 3 */
+ /* End of test suites */
+ {0, 0, 0, 0}
};
static void setup_integ_test(void)
@@ -84,8 +86,6 @@
void start_integ_test(void)
{
setup_integ_test();
- integ_test("Secure",
- test_suites,
- sizeof(test_suites)/sizeof(test_suites[0]));
+ integ_test("Secure", test_suites);
tear_down_integ_test();
}
diff --git a/test/framework/test_framework_integ_test_helper.c b/test/framework/test_framework_integ_test_helper.c
index 414b333..a163c2b 100644
--- a/test/framework/test_framework_integ_test_helper.c
+++ b/test/framework/test_framework_integ_test_helper.c
@@ -11,8 +11,7 @@
#include "test_framework_integ_test_helper.h"
void integ_test(const char *suite_type,
- struct test_suite_t test_suites[],
- uint32_t test_suite_cnt)
+ struct test_suite_t test_suites[])
{
uint32_t i;
@@ -20,7 +19,7 @@
printf("\r\n#### Execute test suites for the %s area ####\r\n", suite_type);
/* Executes test suites */
- for (i = 0; i < test_suite_cnt; i++) {
+ for (i = 0; test_suites[i].freg != NULL; i++) {
if (run_testsuite(&test_suites[i]) != TEST_SUITE_ERR_NO_ERROR) {
/* End function execution */
return;
@@ -30,7 +29,7 @@
/* Prints test suites summary */
printf_set_color(YELLOW);
printf("\r\n*** %s test suites summary ***\r\n", suite_type);
- for (i = 0; i < test_suite_cnt; i++) {
+ for (i = 0; test_suites[i].freg != NULL; i++) {
printf_set_color(WHITE);
printf("Test suite '%s' has ", test_suites[i].name);
if (test_suites[i].val == TEST_PASSED) {
diff --git a/test/framework/test_framework_integ_test_helper.h b/test/framework/test_framework_integ_test_helper.h
index cfe7ace..af6221b 100644
--- a/test/framework/test_framework_integ_test_helper.h
+++ b/test/framework/test_framework_integ_test_helper.h
@@ -23,8 +23,7 @@
* \param[in] test_suite_cnt The number of test suites to be executed.
*/
void integ_test(const char *suite_type,
- struct test_suite_t test_suites[],
- uint32_t test_suite_cnt);
+ struct test_suite_t test_suites[]);
#ifdef __cplusplus
}
diff --git a/test/suites/attestation/attest_token_decode.c b/test/suites/attestation/attest_token_decode.c
index f6ed477..d4145d7 100644
--- a/test/suites/attestation/attest_token_decode.c
+++ b/test/suites/attestation/attest_token_decode.c
@@ -68,7 +68,7 @@
(void)me; /* unused parameter */
(void)cose_pub_key; /* unused parameter */
- return 0;
+ return ATTEST_TOKEN_ERR_SUCCESS;
}
@@ -279,7 +279,7 @@
goto Done;
}
- QCBORDecode_Init(&decode_context, me->payload, 0);
+ QCBORDecode_Init(&decode_context, me->payload, QCBOR_DECODE_MODE_NORMAL);
return_value = qcbor_util_get_item_in_map(&decode_context,
label,
@@ -327,7 +327,7 @@
goto Done;
}
- QCBORDecode_Init(&decode_context, me->payload, 0);
+ QCBORDecode_Init(&decode_context, me->payload, QCBOR_DECODE_MODE_NORMAL);
return_value = qcbor_util_get_item_in_map(&decode_context,
label,
@@ -417,7 +417,7 @@
goto Done;
}
- QCBORDecode_Init(&decode_context, me->payload, 0);
+ QCBORDecode_Init(&decode_context, me->payload, QCBOR_DECODE_MODE_NORMAL);
return_value = qcbor_util_get_items_in_map(&decode_context,
list);
@@ -697,7 +697,7 @@
goto Done;
}
- QCBORDecode_Init(&decode_context, me->payload, 0);
+ QCBORDecode_Init(&decode_context, me->payload, QCBOR_DECODE_MODE_NORMAL);
/* Find the map containing all the SW Components */
return_value = qcbor_util_decode_to_labeled_item(&decode_context,