|
| 1 | +From 38eb2499e1b6b4176b76014874cb6253a044d12e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Etienne Carriere <etienne.carriere@st.com> |
| 3 | +Date: Thu, 3 Jul 2025 10:36:46 +0200 |
| 4 | +Subject: [PATCH 6/6] boot: bootutil: declare fih_panic_loop() as noreturn |
| 5 | + |
| 6 | +Add noreturn attribute the fih_panic_loop() and add a terminal |
| 7 | +endless loop in the function to prevent build warnings like |
| 8 | +the below one found when build MCUBOOT in TF-M: |
| 9 | + |
| 10 | +.../arm-none-eabi/include/assert.h: In function '__assert_func': |
| 11 | +.../trusted-firmware-m/platform/ext/common/tfm_assert.c:22:1: warning: 'noreturn' function does return |
| 12 | + 22 | } |
| 13 | + | ^ |
| 14 | + |
| 15 | +Signed-off-by: Etienne Carriere <etienne.carriere@st.com> |
| 16 | +--- |
| 17 | + boot/bootutil/include/bootutil/fault_injection_hardening.h | 2 +- |
| 18 | + boot/bootutil/src/fault_injection_hardening.c | 6 ++++++ |
| 19 | + 2 files changed, 7 insertions(+), 1 deletion(-) |
| 20 | + |
| 21 | +diff --git a/boot/bootutil/include/bootutil/fault_injection_hardening.h b/boot/bootutil/include/bootutil/fault_injection_hardening.h |
| 22 | +index fdf01b53..497b437e 100644 |
| 23 | +--- a/boot/bootutil/include/bootutil/fault_injection_hardening.h |
| 24 | ++++ b/boot/bootutil/include/bootutil/fault_injection_hardening.h |
| 25 | +@@ -137,7 +137,7 @@ extern fih_ret FIH_BOOT_HOOK_REGULAR; |
| 26 | + /* Global failure handler - more resistant to unlooping. noinline and used are |
| 27 | + * used to prevent optimization |
| 28 | + */ |
| 29 | +-__attribute__((noinline)) __attribute__((used)) |
| 30 | ++__attribute__((noinline)) __attribute__((used)) __attribute__((noreturn)) |
| 31 | + void fih_panic_loop(void); |
| 32 | + #define FIH_PANIC fih_panic_loop() |
| 33 | + #else |
| 34 | +diff --git a/boot/bootutil/src/fault_injection_hardening.c b/boot/bootutil/src/fault_injection_hardening.c |
| 35 | +index 11436cfa..fbe75e87 100644 |
| 36 | +--- a/boot/bootutil/src/fault_injection_hardening.c |
| 37 | ++++ b/boot/bootutil/src/fault_injection_hardening.c |
| 38 | +@@ -63,6 +63,7 @@ void fih_cfi_decrement(void) |
| 39 | + */ |
| 40 | + __attribute__((used)) |
| 41 | + __attribute__((noinline)) |
| 42 | ++__attribute__((noreturn)) |
| 43 | + void fih_panic_loop(void) |
| 44 | + { |
| 45 | + __asm volatile ("b fih_panic_loop"); |
| 46 | +@@ -74,5 +75,10 @@ void fih_panic_loop(void) |
| 47 | + __asm volatile ("b fih_panic_loop"); |
| 48 | + __asm volatile ("b fih_panic_loop"); |
| 49 | + __asm volatile ("b fih_panic_loop"); |
| 50 | ++ |
| 51 | ++ /* An infinite loop to suppress compiler warnings |
| 52 | ++ * about the return of a noreturn function |
| 53 | ++ */ |
| 54 | ++ while (1) {} |
| 55 | + } |
| 56 | + #endif /* FIH_ENABLE_GLOBAL_FAIL */ |
| 57 | +-- |
| 58 | +2.34.1 |
| 59 | + |
0 commit comments