Skip to content

Commit 78af8b6

Browse files
michalek-norlubos
authored andcommitted
bootloader: Fix up lacking fprotect guards
Instead of just failing on compilation this commit changes fprotect requirements so that it prints out a warning and error in log. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent c607b33 commit 78af8b6

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

samples/bootloader/src/main.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#include <zephyr/sys/printk.h>
1010
#include <pm_config.h>
1111
#include <fw_info.h>
12+
#ifdef CONFIG_FPROTECT
1213
#include <fprotect.h>
14+
#else
15+
#warning "FPROTECT not enabled, the bootloader will be unprotected."
16+
#endif
1317
#include <bl_storage.h>
1418
#include <bl_boot.h>
1519
#include <bl_validation.h>
@@ -60,7 +64,7 @@ SYS_INIT(load_huk, PRE_KERNEL_2, 0);
6064
#endif
6165

6266

63-
static void validate_and_boot(const struct fw_info *fw_info, uint16_t slot)
67+
static void validate_and_boot(const struct fw_info *fw_info, counter_t slot)
6468
{
6569
printk("Attempting to boot slot %d.\r\n", slot);
6670

@@ -81,7 +85,8 @@ static void validate_and_boot(const struct fw_info *fw_info, uint16_t slot)
8185

8286
printk("Firmware version %d\r\n", fw_info->version);
8387

84-
uint16_t stored_version;
88+
counter_t stored_version;
89+
8590
int err = get_monotonic_version(&stored_version);
8691

8792
if (err) {
@@ -123,7 +128,13 @@ static void validate_and_boot(const struct fw_info *fw_info, uint16_t slot)
123128

124129
int main(void)
125130
{
126-
int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
131+
int err = 0;
132+
133+
if (IS_ENABLED(CONFIG_FPROTECT)) {
134+
err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
135+
} else {
136+
printk("Fprotect disabled. No protection applied.\n\r");
137+
}
127138

128139
if (err) {
129140
printk("Failed to protect B0 flash, cancel startup.\n\r");

subsys/bootloader/bl_boot/bl_boot.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <soc.h>
88
#include <zephyr/sys/printk.h>
9+
#include <zephyr/kernel.h>
910
#include <pm_config.h>
1011
#include <fw_info.h>
1112
#include <fprotect.h>
@@ -67,8 +68,9 @@ extern uint32_t _vector_table_pointer;
6768
void bl_boot(const struct fw_info *fw_info)
6869
{
6970
#if !(defined(CONFIG_SOC_SERIES_NRF91X) \
70-
|| defined(CONFIG_SOC_NRF5340_CPUNET) \
71-
|| defined(CONFIG_SOC_NRF5340_CPUAPP))
71+
|| defined(CONFIG_SOC_SERIES_NRF54LX) \
72+
|| defined(CONFIG_SOC_NRF5340_CPUNET) \
73+
|| defined(CONFIG_SOC_NRF5340_CPUAPP))
7274
/* Protect bootloader storage data after firmware is validated so
7375
* invalidation of public keys can be written into the page if needed.
7476
* Note that for some devices (for example, nRF9160 and the nRF5340
@@ -77,7 +79,13 @@ void bl_boot(const struct fw_info *fw_info)
7779
* bootloader storage data is locked together with the network core
7880
* application.
7981
*/
80-
int err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
82+
int err = 0;
83+
84+
if (IS_ENABLED(CONFIG_FPROTECT)) {
85+
err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
86+
} else {
87+
printk("Fprotect disabled. No protection applied.\n\r");
88+
}
8189

8290
if (err) {
8391
printk("Failed to protect bootloader storage.\n\r");

0 commit comments

Comments
 (0)