diff --git a/Makefile.boardloader b/Makefile.boardloader index 0ff07d1da..19d5aca06 100644 --- a/Makefile.boardloader +++ b/Makefile.boardloader @@ -118,6 +118,7 @@ CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi CFLAGS += -DSTM32F405xx -DMCU_SERIES_F4 CFLAGS += -DSTM32_HAL_H='' +CFLAGS += -DTREZOR_STM32 LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) diff --git a/Makefile.bootloader b/Makefile.bootloader index 817570613..162c6e1d5 100644 --- a/Makefile.bootloader +++ b/Makefile.bootloader @@ -130,6 +130,7 @@ CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi CFLAGS += -DSTM32F405xx -DMCU_SERIES_F4 CFLAGS += -DSTM32_HAL_H='' +CFLAGS += -DTREZOR_STM32 LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) diff --git a/Makefile.firmware b/Makefile.firmware index c0b556bc4..d7f937797 100644 --- a/Makefile.firmware +++ b/Makefile.firmware @@ -356,6 +356,7 @@ CFLAGS += -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi CFLAGS += -DSTM32F405xx -DMCU_SERIES_F4 CFLAGS += -DSTM32_HAL_H='' +CFLAGS += -DTREZOR_STM32 CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool CFLAGS += -DMICROPY_MODULE_FROZEN_MPY diff --git a/micropython/extmod/modtrezorconfig/norcow_config.h b/micropython/extmod/modtrezorconfig/norcow_config.h index 3a89769b2..49d68833c 100644 --- a/micropython/extmod/modtrezorconfig/norcow_config.h +++ b/micropython/extmod/modtrezorconfig/norcow_config.h @@ -1,10 +1,10 @@ -#ifdef UNIX -#define NORCOW_UNIX 1 -#define NORCOW_FILE "/var/tmp/trezor.config" -#endif - -#ifdef STM32_HAL_H +#if defined TREZOR_STM32 #define NORCOW_STM32 1 #define NORCOW_START_SECTOR 2 #define NORCOW_START_ADDRESS 0x08008000 +#elif defined TREZOR_UNIX +#define NORCOW_UNIX 1 +#define NORCOW_FILE "/var/tmp/trezor.config" +#else +#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. #endif diff --git a/micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h b/micropython/extmod/modtrezormsg/modtrezormsg-stm32.h similarity index 100% rename from micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h rename to micropython/extmod/modtrezormsg/modtrezormsg-stm32.h diff --git a/micropython/extmod/modtrezormsg/modtrezormsg.c b/micropython/extmod/modtrezormsg/modtrezormsg.c index b5242f786..c3b4223da 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg.c +++ b/micropython/extmod/modtrezormsg/modtrezormsg.c @@ -15,12 +15,12 @@ #if MICROPY_PY_TREZORMSG -#if defined STM32_HAL_H -#include "modtrezormsg-stmhal.h" -#elif defined UNIX +#if defined TREZOR_STM32 +#include "modtrezormsg-stm32.h" +#elif defined TREZOR_UNIX #include "modtrezormsg-unix.h" #else -#error Unsupported port. Only STMHAL and UNIX ports are supported. +#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. #endif #define MAX_INTERFACES 8 diff --git a/micropython/extmod/modtrezorui/display-stmhal.h b/micropython/extmod/modtrezorui/display-stm32.h similarity index 100% rename from micropython/extmod/modtrezorui/display-stmhal.h rename to micropython/extmod/modtrezorui/display-stm32.h diff --git a/micropython/extmod/modtrezorui/display.c b/micropython/extmod/modtrezorui/display.c index 362100b9c..16dc8ce87 100644 --- a/micropython/extmod/modtrezorui/display.c +++ b/micropython/extmod/modtrezorui/display.c @@ -20,10 +20,12 @@ static int DISPLAY_BACKLIGHT = 0; static int DISPLAY_ORIENTATION = 0; static int DISPLAY_OFFSET[2] = {0, 0}; -#if defined STM32_HAL_H -#include "display-stmhal.h" -#else +#if defined TREZOR_STM32 +#include "display-stm32.h" +#elif defined TREZOR_UNIX #include "display-unix.h" +#else +#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. #endif // common display functions diff --git a/micropython/extmod/modtrezorutils/modtrezorutils.c b/micropython/extmod/modtrezorutils/modtrezorutils.c index f46c29a54..2176360c2 100644 --- a/micropython/extmod/modtrezorutils/modtrezorutils.c +++ b/micropython/extmod/modtrezorutils/modtrezorutils.c @@ -8,16 +8,18 @@ #include #include -#if defined STM32_HAL_H -#include "common.h" -#elif defined UNIX -#include -#endif - #include "py/runtime.h" #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, // n: int) -> int: @@ -69,12 +71,12 @@ 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 STM32_HAL_H +#if defined TREZOR_STM32 __fatal_error("HALT"); -#elif defined UNIX +#elif defined TREZOR_UNIX exit(1); #else -#error Unsupported port. Only STMHAL and UNIX ports are supported. +#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported. #endif return mp_const_none; } diff --git a/micropython/unix/Makefile b/micropython/unix/Makefile index 5d27cd02d..3c9f802da 100644 --- a/micropython/unix/Makefile +++ b/micropython/unix/Makefile @@ -121,6 +121,8 @@ CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS += -DTREZOR_UNIX + # Debugging/Optimization ifdef DEBUG CFLAGS += -g