From d95ce32ff7fb4a5261dc0821cc1c77fe1eddd277 Mon Sep 17 00:00:00 2001 From: Alexander Lerach Date: Tue, 19 Aug 2025 17:43:49 +0200 Subject: [PATCH] bl: add unlock sequence --- platforms/nuttx/src/bootloader/common/bl.c | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/platforms/nuttx/src/bootloader/common/bl.c b/platforms/nuttx/src/bootloader/common/bl.c index 7690fe062a..45af6dd816 100644 --- a/platforms/nuttx/src/bootloader/common/bl.c +++ b/platforms/nuttx/src/bootloader/common/bl.c @@ -80,7 +80,7 @@ // RESET finalise flash programming, reset chip and starts application // -#define BL_PROTOCOL_REVISION 5 // The revision of the bootloader protocol +#define BL_PROTOCOL_REVISION 6 // The revision of the bootloader protocol //* Next revision needs to update // protocol bytes @@ -158,6 +158,8 @@ static uint8_t bl_type; static uint8_t last_input; +static int unlock_seq[] = { 0x93, 0x7C, 0xA1, 0x4E, 0x5D, 0xF0, 0xB5, 0x68 }; + int get_version(int n, uint8_t *version_str) { int len = strlen(BOOTLOADER_VERSION); @@ -626,6 +628,8 @@ bootloader(unsigned timeout) volatile uint32_t bl_state = 0; // Must see correct command sequence to erase and reboot (commit first word) uint32_t address = board_info.fw_size; /* force erase before upload will work */ uint32_t first_word = 0xffffffff; + uint32_t unlock_idx = 0; + bool bl_locked = true; /* (re)start the timer system */ arch_systic_init(); @@ -664,6 +668,23 @@ bootloader(unsigned timeout) bool full_erase = false; + if (bl_locked) { + if (unlock_seq[unlock_idx] == c) { + unlock_idx++; + sync_response(); + + } else { + unlock_idx = 0; + invalid_response(); + } + + if (unlock_idx >= sizeof(unlock_seq)) { + bl_locked = false; + } + + continue; + } + // handle the command byte switch (c) {