mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-03 11:20:59 +00:00
Put persistent variables at end of stack
Two variables of the bootloader are persistent: - __stack_chk_guard is used by interrupt handlers - system_millis is used by timer interrupt and service routines Note that currently __stack_chk_guard is shared between unprivileged firmware and bootloader. If we get more variables later it may make sense to make a section for this.
This commit is contained in:
parent
ed7a8bfa6c
commit
be64864efc
@ -18,5 +18,8 @@ INCLUDE libopencm3_stm32f2.ld
|
|||||||
|
|
||||||
_ram_start = ORIGIN(ram);
|
_ram_start = ORIGIN(ram);
|
||||||
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
||||||
|
_stack = _ram_end - 8;
|
||||||
|
__stack_chk_guard = _ram_end - 8;
|
||||||
|
system_millis = _ram_end - 4;
|
||||||
|
|
||||||
_data_size = SIZEOF(.data);
|
_data_size = SIZEOF(.data);
|
||||||
|
@ -18,5 +18,8 @@ INCLUDE libopencm3_stm32f2.ld
|
|||||||
|
|
||||||
_ram_start = ORIGIN(ram);
|
_ram_start = ORIGIN(ram);
|
||||||
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
_ram_end = ORIGIN(ram) + LENGTH(ram);
|
||||||
|
_stack = _ram_end - 8;
|
||||||
|
__stack_chk_guard = _ram_end - 8;
|
||||||
|
system_millis = _ram_end - 4;
|
||||||
|
|
||||||
_data_size = SIZEOF(.data);
|
_data_size = SIZEOF(.data);
|
||||||
|
2
setup.c
2
setup.c
@ -29,8 +29,6 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
uint32_t __stack_chk_guard;
|
|
||||||
|
|
||||||
static inline void __attribute__((noreturn)) fault_handler(const char *line1) {
|
static inline void __attribute__((noreturn)) fault_handler(const char *line1) {
|
||||||
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, "detected.", NULL, "Please unplug", "the device.", NULL);
|
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, "detected.", NULL, "Please unplug", "the device.", NULL);
|
||||||
for (;;) {} // loop forever
|
for (;;) {} // loop forever
|
||||||
|
2
timer.c
2
timer.c
@ -25,7 +25,7 @@
|
|||||||
#include <libopencm3/cm3/vector.h>
|
#include <libopencm3/cm3/vector.h>
|
||||||
|
|
||||||
/* 1 tick = 1 ms */
|
/* 1 tick = 1 ms */
|
||||||
volatile uint32_t system_millis;
|
extern volatile uint32_t system_millis;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the Cortex-M3 SysTick timer
|
* Initialise the Cortex-M3 SysTick timer
|
||||||
|
9
util.h
9
util.h
@ -48,6 +48,7 @@ extern void __attribute__((noreturn)) shutdown(void);
|
|||||||
#if !EMULATOR
|
#if !EMULATOR
|
||||||
// defined in memory.ld
|
// defined in memory.ld
|
||||||
extern uint8_t _ram_start[], _ram_end[];
|
extern uint8_t _ram_start[], _ram_end[];
|
||||||
|
extern uint8_t _stack[];
|
||||||
|
|
||||||
// defined in startup.s
|
// defined in startup.s
|
||||||
extern void memset_reg(void *start, void *stop, uint32_t val);
|
extern void memset_reg(void *start, void *stop, uint32_t val);
|
||||||
@ -59,12 +60,12 @@ static inline void __attribute__((noreturn)) jump_to_firmware(const vector_table
|
|||||||
{
|
{
|
||||||
if (FW_SIGNED == trust) { // trusted signed firmware
|
if (FW_SIGNED == trust) { // trusted signed firmware
|
||||||
SCB_VTOR = (uint32_t)vector_table; // * relocate vector table
|
SCB_VTOR = (uint32_t)vector_table; // * relocate vector table
|
||||||
} else { // untrusted firmware
|
|
||||||
mpu_config(); // * configure MPU
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set stack pointer
|
// Set stack pointer
|
||||||
__asm__ volatile("msr msp, %0" :: "r" (vector_table->initial_sp_value));
|
__asm__ volatile("msr msp, %0" :: "r" (vector_table->initial_sp_value));
|
||||||
|
} else { // untrusted firmware
|
||||||
|
mpu_config(); // * configure MPU
|
||||||
|
__asm__ volatile("msr msp, %0" :: "r" (_stack));
|
||||||
|
}
|
||||||
|
|
||||||
// Jump to address
|
// Jump to address
|
||||||
vector_table->reset();
|
vector_table->reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user