1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 01:48:17 +00:00

bootloader: subtle changes in bootloader.c and fastflash.c to make them more similar

This commit is contained in:
Pavol Rusnak 2017-07-01 16:22:22 +02:00
parent f274d8cd73
commit 4603b0c800
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 14 additions and 4 deletions

View File

@ -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 (;;);

View File

@ -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 (;;);
}