2017-10-09 15:44:58 +00:00
|
|
|
.syntax unified
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
.global reset_handler
|
|
|
|
.type reset_handler, STT_FUNC
|
|
|
|
reset_handler:
|
2020-05-14 10:46:25 +00:00
|
|
|
|
2021-12-12 14:45:10 +00:00
|
|
|
// The following loading of VTOR address only works if T1 bootloader was built with PRODUCTION=0
|
2020-11-11 13:43:09 +00:00
|
|
|
// or the firmware was properly signed. All other variants end up in hard fault due to MPU
|
2020-05-21 06:49:59 +00:00
|
|
|
// (cf mpu_config_firmware in legacy bootloader)
|
|
|
|
|
2020-05-14 10:46:25 +00:00
|
|
|
#if TREZOR_MODEL == 1
|
2021-06-14 14:28:07 +00:00
|
|
|
cpsid if
|
2020-05-21 06:49:59 +00:00
|
|
|
ldr r0, =0xE000ED08 // r0 = VTOR address
|
|
|
|
ldr r1, =0x08010400 // r1 = FLASH_APP_START
|
|
|
|
str r1, [r0] // assign
|
|
|
|
|
2020-05-14 10:46:25 +00:00
|
|
|
ldr r0, =_estack - 8 // r0 = stack pointer, T1 bootloader had 8 bytes reserved at end
|
|
|
|
msr msp, r0 // set stack pointer
|
|
|
|
dsb
|
|
|
|
isb
|
|
|
|
#endif
|
|
|
|
|
2017-10-09 15:44:58 +00:00
|
|
|
// setup environment for subsequent stage of code
|
|
|
|
ldr r0, =ccmram_start // r0 - point to beginning of CCMRAM
|
|
|
|
ldr r1, =ccmram_end // r1 - point to byte after the end of CCMRAM
|
|
|
|
ldr r2, =0 // r2 - the word-sized value to be written
|
|
|
|
bl memset_reg
|
|
|
|
|
|
|
|
ldr r0, =sram_start // r0 - point to beginning of SRAM
|
|
|
|
ldr r1, =sram_end // r1 - point to byte after the end of SRAM
|
|
|
|
ldr r2, =0 // r2 - the word-sized value to be written
|
|
|
|
bl memset_reg
|
|
|
|
|
|
|
|
// copy data in from flash
|
|
|
|
ldr r0, =data_vma // dst addr
|
|
|
|
ldr r1, =data_lma // src addr
|
|
|
|
ldr r2, =data_size // size in bytes
|
|
|
|
bl memcpy
|
|
|
|
|
2017-10-14 10:25:13 +00:00
|
|
|
// setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value
|
|
|
|
bl rng_get
|
|
|
|
ldr r1, = __stack_chk_guard
|
|
|
|
str r0, [r1]
|
|
|
|
|
2017-10-09 17:55:54 +00:00
|
|
|
// re-enable exceptions
|
|
|
|
// according to "ARM Cortex-M Programming Guide to Memory Barrier Instructions" Application Note 321, section 4.7:
|
|
|
|
// "If it is not necessary to ensure that a pended interrupt is recognized immediately before
|
|
|
|
// subsequent operations, it is not necessary to insert a memory barrier instruction."
|
2021-06-14 14:28:07 +00:00
|
|
|
#if TREZOR_MODEL == T
|
2017-10-09 17:55:54 +00:00
|
|
|
cpsie f
|
2021-06-14 14:28:07 +00:00
|
|
|
#elif TREZOR_MODEL == 1
|
|
|
|
cpsie if
|
|
|
|
#endif
|
2017-10-09 17:55:54 +00:00
|
|
|
|
2017-10-09 15:44:58 +00:00
|
|
|
// enter the application code
|
|
|
|
bl main
|
|
|
|
|
2021-06-14 14:28:13 +00:00
|
|
|
b shutdown_privileged
|
2017-10-09 15:44:58 +00:00
|
|
|
|
|
|
|
.end
|