diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 872eef1a2..ff8d21fb5 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -354,6 +354,8 @@ SOURCE_TREZORHAL = [ 'embed/trezorhal/vectortable.s', ] +CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN'] + if FEATURE_FLAGS["RDI"]: CPPDEFINES_MOD += ['RDI'] diff --git a/core/embed/trezorhal/common.c b/core/embed/trezorhal/common.c index d224762d7..a98874f61 100644 --- a/core/embed/trezorhal/common.c +++ b/core/embed/trezorhal/common.c @@ -25,6 +25,7 @@ #include "display.h" #include "flash.h" #include "rand.h" +#include "supervise.h" #include "stm32f4xx_ll_utils.h" @@ -33,6 +34,18 @@ extern void shutdown_privileged(void); #define COLOR_FATAL_ERROR RGB16(0x7F, 0x00, 0x00) +// from util.s +extern void shutdown_privileged(void); + +void shutdown(void) { +#ifdef USE_SVC_SHUTDOWN + svc_shutdown(); +#else + // It won't work properly unless called from the privileged mode + shutdown_privileged(); +#endif +} + void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func) { diff --git a/core/embed/trezorhal/common.h b/core/embed/trezorhal/common.h index bcdaca919..90c4e20f1 100644 --- a/core/embed/trezorhal/common.h +++ b/core/embed/trezorhal/common.h @@ -49,6 +49,8 @@ }) #endif +void shutdown(void); + void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);