Skip to content

Commit 6610e88

Browse files
TTornblomutzig
authored andcommitted
boot: Fix FIH_LABEL/FIH_CALL macros for IAR
The IAR toolchain does not handle the "%=" template. Emulate it with a combination of __LINE__ and __COUNTER__ Signed-off-by: TTornblom <[email protected]>
1 parent 59f1d29 commit 6610e88

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

boot/bootutil/include/bootutil/fault_injection_hardening.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ void fih_cfi_decrement(void);
284284
/* Label for interacting with FIH testing tool. Can be parsed from the elf file
285285
* after compilation. Does not require debug symbols.
286286
*/
287+
#if defined(__ICCARM__)
288+
#define FIH_LABEL(str, lin, cnt) __asm volatile ("FIH_LABEL_" str "_" #lin "_" #cnt "::" ::);
289+
#else
287290
#define FIH_LABEL(str) __asm volatile ("FIH_LABEL_" str "_%=:" ::);
291+
#endif
288292

289293
/* Main FIH calling macro. return variable is second argument. Does some setup
290294
* before and validation afterwards. Inserts labels for use with testing script.
@@ -301,6 +305,23 @@ void fih_cfi_decrement(void);
301305
* previously saved value. If this is equal then the function call and all child
302306
* function calls were performed.
303307
*/
308+
#if defined(__ICCARM__)
309+
#define FIH_CALL(f, ret, ...) FIH_CALL2(f, ret, __LINE__, __COUNTER__, __VA_ARGS__)
310+
311+
#define FIH_CALL2(f, ret, l, c, ...) \
312+
do { \
313+
FIH_LABEL("FIH_CALL_START", l, c); \
314+
FIH_CFI_PRECALL_BLOCK; \
315+
ret = FIH_FAILURE; \
316+
if (fih_delay()) { \
317+
ret = f(__VA_ARGS__); \
318+
} \
319+
FIH_CFI_POSTCALL_BLOCK; \
320+
FIH_LABEL("FIH_CALL_END", l, c); \
321+
} while (0)
322+
323+
#else
324+
304325
#define FIH_CALL(f, ret, ...) \
305326
do { \
306327
FIH_LABEL("FIH_CALL_START"); \
@@ -312,6 +333,7 @@ void fih_cfi_decrement(void);
312333
FIH_CFI_POSTCALL_BLOCK; \
313334
FIH_LABEL("FIH_CALL_END"); \
314335
} while (0)
336+
#endif
315337

316338
/* FIH return changes the state of the internal state machine. If you do a
317339
* FIH_CALL then you need to do a FIH_RET else the state machine will detect

0 commit comments

Comments
 (0)