Skip to content

Commit

Permalink
bootloader: bl_boot: minor ifdef rework
Browse files Browse the repository at this point in the history
Changing ifdef's for consistency improvement.
This also spares few bytes of flash.

Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
  • Loading branch information
michalek-no authored and nordicjm committed Nov 6, 2024
1 parent 1b9c394 commit 40120ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
17 changes: 8 additions & 9 deletions samples/bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include <zephyr/sys/printk.h>
#include <pm_config.h>
#include <fw_info.h>
#ifdef CONFIG_FPROTECT
#if defined(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>
#ifdef CONFIG_NRFX_NVMC
#if defined(CONFIG_NRFX_NVMC)
#include <nrfx_nvmc.h>
#elif defined(CONFIG_NRFX_RRAMC)
#include <nrfx_rramc.h>
Expand All @@ -38,7 +38,7 @@ int load_huk(void)

if (*(uint32_t *)huk_flag_addr == 0xFFFFFFFF) {
printk("First boot, expecting app to write HUK.\n");
#ifdef CONFIG_NRFX_NVMC
#if defined(CONFIG_NRFX_NVMC)
nrfx_nvmc_word_write(huk_flag_addr, 0);
#elif defined(CONFIG_NRFX_RRAMC)
nrfx_rramc_word_write(huk_flag_addr, 0);
Expand Down Expand Up @@ -128,18 +128,17 @@ static void validate_and_boot(const struct fw_info *fw_info, counter_t slot)

int main(void)
{
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 defined(CONFIG_FPROTECT)
int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);

if (err) {
printk("Failed to protect B0 flash, cancel startup.\n\r");
return 0;
}
#else
printk("Fprotect disabled. No protection applied.\n\r");
#endif

uint32_t s0_addr = s0_address_read();
uint32_t s1_addr = s1_address_read();
Expand Down
15 changes: 7 additions & 8 deletions subsys/bootloader/bl_boot/bl_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void uninit_used_uarte(NRF_UARTE_Type *p_reg)

static void uninit_used_peripherals(void)
{
#ifdef CONFIG_UART_NRFX
#if defined(CONFIG_UART_NRFX)
#if defined(CONFIG_HAS_HW_NRF_UART0)
nrf_uart_disable(NRF_UART0);
#elif defined(CONFIG_HAS_HW_NRF_UARTE0)
Expand Down Expand Up @@ -82,18 +82,17 @@ void bl_boot(const struct fw_info *fw_info)
* bootloader storage data is locked together with the network core
* application.
*/
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 defined(CONFIG_FPROTECT)
int err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);

if (err) {
printk("Failed to protect bootloader storage.\n\r");
return;
}
#else
printk("Fprotect disabled. No protection applied.\n\r");
#endif

#endif

#if CONFIG_ARCH_HAS_USERSPACE
Expand Down

0 comments on commit 40120ba

Please sign in to comment.