1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-08 22:40:59 +00:00

feat(legacy): add supervisor call for reboot to bootloader

This commit is contained in:
Ondrej Mikle 2021-02-09 08:29:36 +01:00 committed by Pavol Rusnak
parent 10edcb0d3a
commit 65aa3b49d9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "supervise.h"
#include <libopencm3/stm32/flash.h>
#include <vendor/libopencm3/include/libopencmsis/core_cm3.h>
#include <stdint.h>
#include "memory.h"
@ -62,6 +63,11 @@ static uint32_t svhandler_flash_lock(void) {
return FLASH_SR;
}
static void __attribute__((noreturn)) svhandler_reboot_to_bootloader(void) {
__asm__ __volatile__("ldr r12, =0x55aa55aa");
scb_reset_system();
}
extern volatile uint32_t system_millis;
void svc_handler_main(uint32_t *stack) {
@ -82,6 +88,9 @@ void svc_handler_main(uint32_t *stack) {
case SVC_TIMER_MS:
stack[0] = system_millis;
break;
case SVC_REBOOT_TO_BOOTLOADER:
svhandler_reboot_to_bootloader();
break;
default:
stack[0] = 0xffffffff;
break;

View File

@ -29,6 +29,7 @@
#define SVC_FLASH_PROGRAM 2
#define SVC_FLASH_LOCK 3
#define SVC_TIMER_MS 4
#define SVC_REBOOT_TO_BOOTLOADER 5
/* Unlocks flash. This function needs to be called before programming
* or erasing. Multiple calls of flash_program and flash_erase can
@ -71,6 +72,14 @@ inline uint32_t svc_timer_ms(void) {
return r0;
}
/* Reboot to bootloader.
* Sets a flag in register and reboots. When bootloader runs, it will recognize
* flag and won't run firmware, but enter bootloader mode.
*/
inline void svc_reboot_to_bootloader(void) {
__asm__ __volatile__("svc %0" ::"i"(SVC_REBOOT_TO_BOOTLOADER) : "memory");
}
#else
extern void svc_flash_unlock(void);