Skip to content

Commit 9cb10ad

Browse files
committed
Bootloader protection of flash memory may also be turned on by setting the SECURE_BY_DEFAULT compile flag, either through an argument to make, or by setting flag in sam_ba_monitor.h.
1 parent 7d69dd6 commit 9cb10ad

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

bootloaders/zero/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ else
7171
CFLAGS+=-Os -DDEBUG=0 -flto
7272
endif
7373

74+
ifdef SECURE_BY_DEFAULT
75+
CFLAGS+=-DSECURE_BY_DEFAULT=1
76+
endif
77+
7478
ELF=$(NAME).elf
7579
BIN=$(NAME).bin
7680
HEX=$(NAME).hex
7781

78-
7982
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.5.0/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/"
8083

8184
# -----------------------------------------------------------------------------

bootloaders/zero/sam_ba_monitor.c

+13
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ const t_monitor_if usbcdc_if =
8484
/* The pointer to the interface object use by the monitor */
8585
t_monitor_if * ptr_monitor_if;
8686

87+
#ifdef SECURE_BY_DEFAULT
88+
bool b_security_enabled = true;
89+
#else
8790
bool b_security_enabled = false;
91+
#endif
8892

8993
/* b_terminal_mode mode (ascii) or hex mode */
9094
volatile bool b_terminal_mode = false;
@@ -225,6 +229,7 @@ void sam_ba_putdata_term(uint8_t* data, uint32_t length)
225229
return;
226230
}
227231

232+
#ifndef SECURE_BY_DEFAULT
228233
volatile uint32_t sp;
229234
void call_applet(uint32_t address)
230235
{
@@ -247,6 +252,7 @@ void call_applet(uint32_t address)
247252
/* Jump to application Reset Handler in the application */
248253
asm("bx %0"::"r"(app_start_address));
249254
}
255+
#endif
250256

251257
uint32_t current_number;
252258
uint32_t erased_from = 0;
@@ -413,6 +419,7 @@ static void sam_ba_monitor_loop(void)
413419

414420
sam_ba_putdata_term((uint8_t*) &current_number, 4);
415421
}
422+
#ifndef SECURE_BY_DEFAULT
416423
else if (!b_security_enabled && command == 'G') // Execute code. Will not allow when security is enabled.
417424
{
418425
call_applet(current_number);
@@ -423,6 +430,7 @@ static void sam_ba_monitor_loop(void)
423430
ptr_monitor_if->put_c(0x6);
424431
}
425432
}
433+
#endif
426434
else if (command == 'T') // Turn on terminal mode
427435
{
428436
b_terminal_mode = 1;
@@ -711,7 +719,12 @@ void sam_ba_monitor_run(void)
711719
PAGES = NVMCTRL->PARAM.bit.NVMP;
712720
MAX_FLASH = PAGE_SIZE * PAGES;
713721

722+
#ifdef SECURE_BY_DEFAULT
723+
b_security_enabled = true;
724+
#else
714725
b_security_enabled = NVMCTRL->STATUS.bit.SB != 0;
726+
#endif
727+
715728
ptr_data = NULL;
716729
command = 'z';
717730
while (1)

bootloaders/zero/sam_ba_monitor.h

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
/* Selects USB as the communication interface of the monitor */
3737
#define SIZEBUFMAX 64
3838

39+
// Set this flag to let the bootloader enforce read restrictions of flash memory, even if security bit is not set
40+
//#define SECURE_BY_DEFAULT
41+
3942
/**
4043
* \brief Initialize the monitor
4144
*

0 commit comments

Comments
 (0)