From 4603b0c8005a201adb7a8516a158447e9e0a5563 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 1 Jul 2017 16:22:22 +0200 Subject: [PATCH] bootloader: subtle changes in bootloader.c and fastflash.c to make them more similar --- bootloader/bootloader.c | 7 ++++++- firmware/fastflash.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c index 4b9f757d72..cb891a7bba 100644 --- a/bootloader/bootloader.c +++ b/bootloader/bootloader.c @@ -78,10 +78,15 @@ void show_unofficial_warning(const uint8_t *hash) void __attribute__((noreturn)) load_app(void) { - // jump to app + // Relocate vector tables SCB_VTOR = FLASH_APP_START; // & 0xFFFF; + + // Set stack pointer __asm__ volatile("msr msp, %0"::"g" (*(volatile uint32_t *)FLASH_APP_START)); + + // Jump to address (*(void (**)())(FLASH_APP_START + 4))(); + // forever loop to indicate to the compiler that this function does not return. // this avoids the stack protector injecting code that faults with the new stack. for (;;); diff --git a/firmware/fastflash.c b/firmware/fastflash.c index 85aef6ffb9..d2bc1b326d 100644 --- a/firmware/fastflash.c +++ b/firmware/fastflash.c @@ -29,11 +29,14 @@ extern uint32_t __bootloader_loadaddr__[]; extern uint32_t __bootloader_runaddr__[]; extern uint8_t __bootloader_size__[]; -void load_bootloader() { +void load_bootloader(void) +{ memcpy(__bootloader_runaddr__, __bootloader_loadaddr__, (size_t) __bootloader_size__); } -void run_bootloader() { +// adapted from load_app() in bootloader.c +void __attribute__((noreturn)) run_bootloader(void) +{ // Relocate vector tables SCB_VTOR = (uint32_t) __bootloader_runaddr__; @@ -43,5 +46,7 @@ void run_bootloader() { // Jump to address ((void (*)(void))(__bootloader_runaddr__[1]))(); - while (true); + // forever loop to indicate to the compiler that this function does not return. + // this avoids the stack protector injecting code that faults with the new stack. + for (;;); }