From 5c7abf8d31f92ef5f59a755dd60946435e78f9ee Mon Sep 17 00:00:00 2001 From: Chansu Park Date: Tue, 21 Apr 2026 22:33:29 +0900 Subject: [PATCH] os/board/bk7239n: Add Assertion log after TFM fault log The CONFIG_TFM_S_TO_NS_DUMP_ENABLE is control the whole logging function when TFM crashes. But It's not tended to. So this commit fixes misimplemented CONFIG_TFM_S_TO_NS_DUMP_ENABLE configuration, and add assertion log after TFM fault log. Chnages: Remove conditional compilation guards for CONFIG_TFM_S_TO_NS_DUMP_ENABLE and CONFIG_SECURITY_LEVEL from the TFM dump callback registration and secure fault handlers to ensure they are always included in the build. Retain the CONFIG_TFM_S_TO_NS_DUMP_ENABLE guard around the rtos_dump_system call and CONFIG_SECURITY_LEVEL around the high security level check. Replace bk_reboot_reset_reason() with PANIC() in secure fault handlers to generate a proper panic trace instead of a silent reboot. The valid scenarios are as follows: - When CONFIG_TFM_S_TO_NS_DUMP_ENABLE=y - When SECURITY_LEVEL is HIGH, - The board should not print any crash info and reboot. - Just call PANIC with setting reboot reason.; PANIC will print log or not by security level - When SECURITY_LEVEL is LOW - The board should print ALL crash info and reboot. - Print all reg/memory dump and call PANIC with setting reboot reason.; PANIC will print log or not by security level - When CONFIG_TFM_S_TO_NS_DUMP_ENABLE is not set - When SECURITY_LEVEL is HIGH, - The board should not print any crash info and reboot. - Just call PANIC with setting reboot reason.; PANIC will print log or not by security level - When SECURITY_LEVEL is LOW - The board should print crash info summary (reg dump only. no memory dump) and reboot. - Print reg dump only and call PANIC with setting reboot reason.; PANIC will print log or not by security level --- .../src/components/bk_init/components_init.c | 5 +---- .../src/middleware/arch/cm33/trap_base.c | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/os/board/bk7239n/src/components/bk_init/components_init.c b/os/board/bk7239n/src/components/bk_init/components_init.c index 118222a879..c05ff9c37a 100755 --- a/os/board/bk7239n/src/components/bk_init/components_init.c +++ b/os/board/bk7239n/src/components/bk_init/components_init.c @@ -52,9 +52,7 @@ #include #endif -#if defined(CONFIG_TFM_S_TO_NS_DUMP_ENABLE) #include "tfm_aes_gcm_nsc.h" -#endif #include "os/mem.h" #include "cmsis_gcc.h" @@ -344,9 +342,8 @@ int components_init(void) //wdt_init(); #endif -#if defined(CONFIG_TFM_S_TO_NS_DUMP_ENABLE) && defined(CONFIG_SECURITY_LEVEL) extern void bk_security_to_nosecurity_dump_register_callback(void); bk_security_to_nosecurity_dump_register_callback(); -#endif + return BK_OK; } diff --git a/os/board/bk7239n/src/middleware/arch/cm33/trap_base.c b/os/board/bk7239n/src/middleware/arch/cm33/trap_base.c index 024dd0e181..4d3a489934 100755 --- a/os/board/bk7239n/src/middleware/arch/cm33/trap_base.c +++ b/os/board/bk7239n/src/middleware/arch/cm33/trap_base.c @@ -684,8 +684,6 @@ static void arch_dump_cpu_registers_securt_fault(uint32_t mcause, SAVED_CONTEXT } } - -#if defined(CONFIG_TFM_S_TO_NS_DUMP_ENABLE) && defined(CONFIG_SECURITY_LEVEL) //#include "tfm_aes_gcm_nsc.h" #include #define FRAME_BUF_LEN (64) @@ -813,31 +811,38 @@ static void NS_handle_securt_fault(uint32_t reset_reason, struct tfm_exception_i /* Handled Trap */ g_enter_exception = 1; - +#ifdef CONFIG_TFM_S_TO_NS_DUMP_ENABLE rtos_dump_system(msp, psp); - - +#endif +#ifdef CONFIG_SYSTEM_REBOOT_REASON up_reboot_reason_write(BK_SECURE_FAULT_REBOOT_REASON); - bk_reboot_reset_reason(); +#endif + PANIC(); while(g_enter_exception); // rtos_enable_int(int_level); } else { +#ifdef CONFIG_SYSTEM_REBOOT_REASON up_reboot_reason_write(BK_SECURE_FAULT_REBOOT_REASON); - bk_reboot_reset_reason(); +#endif + PANIC(); } } void bk_security_donmain_notifies_non_security_domain_to_dump(uint32_t *reg) { // High security level will not dump the exception information. +#ifdef CONFIG_SECURITY_LEVEL if (get_security_level() > LOW_SECURITY_LEVEL) { +#ifdef CONFIG_SYSTEM_REBOOT_REASON up_reboot_reason_write(BK_SECURE_FAULT_REBOOT_REASON); - bk_reboot_reset_reason(); +#endif + PANIC(); return; } +#endif struct tfm_exception_info_t *ctx = &tfm_exception_info; @@ -896,7 +901,6 @@ void bk_security_to_nosecurity_dump_register_callback(void) uint32_t callback_address = (uint32_t)(&bk_security_donmain_notifies_non_security_domain_to_dump); psa_register_dump_callback(callback_address, (uint32_t)&tfm_exception_info); } -#endif /* if mpu enable, accessing itcm zero pointer violates the mpu rule, please refer to mpu_cfg * if mpu disable, null pointer/zero pointer maybe is a software fault. So bk_null_trap_handler