Skip to content

Commit 4c704a9

Browse files
committed
boot: fail closed on flash protect errors
1 parent cdf8402 commit 4c704a9

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/update_disk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ void RAMFUNCTION wolfBoot_start(void)
549549
(void)hal_hsm_server_cleanup();
550550
#endif
551551
#ifndef TZEN
552-
(void)hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE);
552+
if (hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE) < 0) {
553+
wolfBoot_printf("Error protecting bootloader flash region\r\n");
554+
wolfBoot_panic();
555+
}
553556
#endif
554557
hal_prepare_boot();
555558

src/update_flash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,10 @@ void RAMFUNCTION wolfBoot_start(void)
15031503
#endif
15041504

15051505
#ifndef TZEN
1506-
(void)hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE);
1506+
if (hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE) < 0) {
1507+
wolfBoot_printf("Error protecting bootloader flash region\n");
1508+
wolfBoot_panic();
1509+
}
15071510
#endif
15081511
hal_prepare_boot();
15091512

src/update_flash_hwswap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ void RAMFUNCTION wolfBoot_start(void)
107107
(void)hal_hsm_server_cleanup();
108108
#endif
109109
#ifndef TZEN
110-
(void)hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE);
110+
if (hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE) < 0)
111+
boot_panic();
111112
#endif
112113
hal_prepare_boot();
113114
#ifdef WOLFBOOT_HOOK_BOOT

src/update_ram.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ void RAMFUNCTION wolfBoot_start(void)
391391
#endif
392392

393393
#ifndef TZEN
394-
(void)hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE);
394+
if (hal_flash_protect(WOLFBOOT_ORIGIN, BOOTLOADER_PARTITION_SIZE) < 0) {
395+
wolfBoot_printf("Error protecting bootloader flash region\n");
396+
wolfBoot_panic();
397+
}
395398
#endif
396399
hal_prepare_boot();
397400

tools/unit-tests/unit-update-flash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ int hal_flash_protect(haladdr_t address, int len)
137137
static void reset_mock_stats(void)
138138
{
139139
wolfBoot_staged_ok = 0;
140+
#ifdef CUSTOM_ENCRYPT_KEY
140141
mock_set_encrypt_key_ret = 0;
141142
mock_set_encrypt_key_calls = 0;
143+
#endif
142144
#ifndef ARCH_SIM
143145
wolfBoot_panicked = 0;
144146
#endif

0 commit comments

Comments
 (0)