Skip to content

Commit

Permalink
bootloader: Fix up lacking fprotect guards
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
michalek-no committed Aug 6, 2024
1 parent b445df3 commit ccbb381
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 14 additions & 3 deletions samples/bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#include <zephyr/sys/printk.h>
#include <pm_config.h>
#include <fw_info.h>
#ifdef CONFIG_FPROTECT
#include <fprotect.h>
#else
#warning "FPROTECT not enabled, the bootloader will be unprotected."
#endif
#include <bl_storage.h>
#include <bl_boot.h>
#include <bl_validation.h>
Expand Down Expand Up @@ -60,7 +64,7 @@ SYS_INIT(load_huk, PRE_KERNEL_2, 0);
#endif


static void validate_and_boot(const struct fw_info *fw_info, uint16_t slot)
static void validate_and_boot(const struct fw_info *fw_info, counter_t slot)
{
printk("Attempting to boot slot %d.\r\n", slot);

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

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

uint16_t stored_version;
counter_t stored_version;

int err = get_monotonic_version(&stored_version);

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

int main(void)
{
int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
int err = 0;

if (IS_ENABLED(CONFIG_FPROTECT)) {
err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
} else {
printk("Fprotect disabled. No protection applied.\n\r");
}

if (err) {
printk("Failed to protect B0 flash, cancel startup.\n\r");
Expand Down
9 changes: 8 additions & 1 deletion subsys/bootloader/bl_boot/bl_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <soc.h>
#include <zephyr/sys/printk.h>
#include <zephyr/kernel.h>
#include <pm_config.h>
#include <fw_info.h>
#include <fprotect.h>
Expand Down Expand Up @@ -77,7 +78,13 @@ void bl_boot(const struct fw_info *fw_info)
* bootloader storage data is locked together with the network core
* application.
*/
int err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
int err = 0;

if (IS_ENABLED(CONFIG_FPROTECT)) {
err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
} else {
printk("Fprotect disabled. No protection applied.\n\r");
}

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

0 comments on commit ccbb381

Please sign in to comment.