Skip to content

Commit 40120ba

Browse files
michalek-nonordicjm
authored andcommitted
bootloader: bl_boot: minor ifdef rework
Changing ifdef's for consistency improvement. This also spares few bytes of flash. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 1b9c394 commit 40120ba

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

samples/bootloader/src/main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#include <zephyr/sys/printk.h>
1010
#include <pm_config.h>
1111
#include <fw_info.h>
12-
#ifdef CONFIG_FPROTECT
12+
#if defined(CONFIG_FPROTECT)
1313
#include <fprotect.h>
1414
#else
1515
#warning "FPROTECT not enabled, the bootloader will be unprotected."
1616
#endif
1717
#include <bl_storage.h>
1818
#include <bl_boot.h>
1919
#include <bl_validation.h>
20-
#ifdef CONFIG_NRFX_NVMC
20+
#if defined(CONFIG_NRFX_NVMC)
2121
#include <nrfx_nvmc.h>
2222
#elif defined(CONFIG_NRFX_RRAMC)
2323
#include <nrfx_rramc.h>
@@ -38,7 +38,7 @@ int load_huk(void)
3838

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

129129
int main(void)
130130
{
131-
int err = 0;
132131

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-
}
132+
#if defined(CONFIG_FPROTECT)
133+
int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
138134

139135
if (err) {
140136
printk("Failed to protect B0 flash, cancel startup.\n\r");
141137
return 0;
142138
}
139+
#else
140+
printk("Fprotect disabled. No protection applied.\n\r");
141+
#endif
143142

144143
uint32_t s0_addr = s0_address_read();
145144
uint32_t s1_addr = s1_address_read();

subsys/bootloader/bl_boot/bl_boot.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void uninit_used_uarte(NRF_UARTE_Type *p_reg)
4141

4242
static void uninit_used_peripherals(void)
4343
{
44-
#ifdef CONFIG_UART_NRFX
44+
#if defined(CONFIG_UART_NRFX)
4545
#if defined(CONFIG_HAS_HW_NRF_UART0)
4646
nrf_uart_disable(NRF_UART0);
4747
#elif defined(CONFIG_HAS_HW_NRF_UARTE0)
@@ -82,18 +82,17 @@ void bl_boot(const struct fw_info *fw_info)
8282
* bootloader storage data is locked together with the network core
8383
* application.
8484
*/
85-
int err = 0;
86-
87-
if (IS_ENABLED(CONFIG_FPROTECT)) {
88-
err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
89-
} else {
90-
printk("Fprotect disabled. No protection applied.\n\r");
91-
}
85+
#if defined(CONFIG_FPROTECT)
86+
int err = fprotect_area(PM_PROVISION_ADDRESS, PM_PROVISION_SIZE);
9287

9388
if (err) {
9489
printk("Failed to protect bootloader storage.\n\r");
9590
return;
9691
}
92+
#else
93+
printk("Fprotect disabled. No protection applied.\n\r");
94+
#endif
95+
9796
#endif
9897

9998
#if CONFIG_ARCH_HAS_USERSPACE

0 commit comments

Comments
 (0)