From 795875523b9d5b4f70d5598d296e3add91d41948 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 17 Apr 2017 18:07:34 +0200 Subject: [PATCH] unix: implement __fatal_error, simplify modtrezorutils --- micropython/extmod/modtrezorutils/modtrezorutils.c | 12 ------------ micropython/trezorhal/common.c | 1 + micropython/unix/Makefile | 3 +++ micropython/unix/common.c | 11 +++++++++++ micropython/unix/common.h | 6 ++++++ 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 micropython/unix/common.c create mode 100644 micropython/unix/common.h diff --git a/micropython/extmod/modtrezorutils/modtrezorutils.c b/micropython/extmod/modtrezorutils/modtrezorutils.c index 2176360c24..b27f52a04b 100644 --- a/micropython/extmod/modtrezorutils/modtrezorutils.c +++ b/micropython/extmod/modtrezorutils/modtrezorutils.c @@ -12,13 +12,7 @@ #if MICROPY_PY_TREZORUTILS -#if defined TREZOR_STM32 #include "common.h" -#elif defined TREZOR_UNIX -#include -#else -#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. -#endif /// def trezor.utils.memcpy(dst: bytearray, dst_ofs: int, /// src: bytearray, src_ofs: int, @@ -71,13 +65,7 @@ STATIC mp_obj_t mod_TrezorUtils_halt(size_t n_args, const mp_obj_t *args) { printf("HALT!\n"); } // TODO: is this the best we can do? -#if defined TREZOR_STM32 __fatal_error("HALT"); -#elif defined TREZOR_UNIX - exit(1); -#else -#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. -#endif return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUtils_halt_obj, 0, 1, mod_TrezorUtils_halt); diff --git a/micropython/trezorhal/common.c b/micropython/trezorhal/common.c index d17d8351fb..15056857b0 100644 --- a/micropython/trezorhal/common.c +++ b/micropython/trezorhal/common.c @@ -1,5 +1,6 @@ #include STM32_HAL_H +#include "common.h" #include "display.h" #define FATAL_FGCOLOR 0xFFFF diff --git a/micropython/unix/Makefile b/micropython/unix/Makefile index 3c9f802da4..4e1464a654 100644 --- a/micropython/unix/Makefile +++ b/micropython/unix/Makefile @@ -92,6 +92,9 @@ ifeq ($(MICROPY_PY_TREZORUTILS),1) SRC_MOD += $(EXTMOD_DIR)/modtrezorutils/modtrezorutils.c endif +CFLAGS_MOD += -I../$(EXTMOD_DIR)/../unix +SRC_MOD += $(EXTMOD_DIR)/../unix/common.c + ################################################# -include mpconfigport.mk diff --git a/micropython/unix/common.c b/micropython/unix/common.c new file mode 100644 index 0000000000..eaf3e25d92 --- /dev/null +++ b/micropython/unix/common.c @@ -0,0 +1,11 @@ +#include +#include + +#include "common.h" + +void __attribute__((noreturn)) __fatal_error(const char *msg) { + printf("FATAL ERROR:\n"); + printf(msg); + printf("\n"); + exit(1); +} diff --git a/micropython/unix/common.h b/micropython/unix/common.h new file mode 100644 index 0000000000..24cc6b5275 --- /dev/null +++ b/micropython/unix/common.h @@ -0,0 +1,6 @@ +#ifndef __TREZORUNIX_COMMON_H__ +#define __TREZORUNIX_COMMON_H__ + +void __attribute__((noreturn)) __fatal_error(const char *msg); + +#endif