From ebbd7f9d35a064ae0d0e747b656fab85f9b1e64f Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Fri, 23 Jun 2023 16:50:13 +0200 Subject: [PATCH] refactor(core): restructure trezorhal, prepare to support more platforms [no changelog] --- core/SConscript.boardloader | 78 ++---------- core/SConscript.bootloader | 89 +++----------- core/SConscript.bootloader_ci | 74 ++--------- core/SConscript.bootloader_emu | 21 ++-- core/SConscript.firmware | 115 ++++-------------- core/SConscript.prodtest | 79 +++--------- core/SConscript.reflash | 76 ++---------- core/SConscript.unix | 22 ++-- core/embed/bootloader/bootui.c | 2 +- core/embed/bootloader/main.c | 4 +- core/embed/bootloader_ci/main.c | 2 +- core/embed/extmod/modtrezorio/modtrezorio.c | 2 +- core/embed/firmware/main.c | 4 +- core/embed/{trezorhal => lib}/mini_printf.c | 0 core/embed/{trezorhal => lib}/mini_printf.h | 0 core/embed/{trezorhal => lib}/secbool.h | 0 core/embed/{trezorhal/touch => lib}/touch.c | 2 + core/embed/prodtest/main.c | 2 +- core/embed/reflash/main.c | 2 +- core/embed/rust/Cargo.toml | 1 + core/embed/rust/build.rs | 6 +- core/embed/rust/trezorhal.h | 2 +- .../{unix => trezorhal/boards}/board-unix.h | 0 core/embed/trezorhal/common.h | 14 +-- core/embed/trezorhal/flash.h | 2 + core/embed/trezorhal/lowlevel.h | 1 - .../trezorhal/{ => stm32f4}/backlight_pwm.c | 0 .../trezorhal/{ => stm32f4}/backlight_pwm.h | 0 .../{ => stm32f4}/board_capabilities.c | 0 core/embed/trezorhal/{ => stm32f4}/button.c | 0 core/embed/trezorhal/{ => stm32f4}/common.c | 2 +- .../trezorhal/{ => stm32f4}/compiler_traits.h | 0 .../{ => stm32f4}/consumption_mask.c | 0 .../{ => stm32f4}/displays/ili9341_spi.c | 0 .../{ => stm32f4}/displays/ili9341_spi.h | 0 .../trezorhal/{ => stm32f4}/displays/ltdc.c | 0 .../trezorhal/{ => stm32f4}/displays/ltdc.h | 0 .../{ => stm32f4}/displays/panels/154a.c | 0 .../{ => stm32f4}/displays/panels/154a.h | 0 .../displays/panels/lx154a2411.c | 0 .../displays/panels/lx154a2411.h | 0 .../displays/panels/lx154a2422.c | 0 .../displays/panels/lx154a2422.h | 0 .../{ => stm32f4}/displays/panels/tf15411a.c | 0 .../{ => stm32f4}/displays/panels/tf15411a.h | 0 .../{ => stm32f4}/displays/st7789v.c | 0 .../{ => stm32f4}/displays/st7789v.h | 0 .../{ => stm32f4}/displays/ug-2828tswig01.c | 0 .../{ => stm32f4}/displays/ug-2828tswig01.h | 0 .../{ => stm32f4}/displays/vg-2864ksweg01.c | 0 .../{ => stm32f4}/displays/vg-2864ksweg01.h | 0 core/embed/trezorhal/{ => stm32f4}/dma.c | 0 core/embed/trezorhal/{ => stm32f4}/dma.h | 0 core/embed/trezorhal/{ => stm32f4}/dma2d.c | 0 core/embed/trezorhal/{ => stm32f4}/flash.c | 0 core/embed/trezorhal/{ => stm32f4}/i2c.c | 0 core/embed/trezorhal/{ => stm32f4}/i2c.h | 0 core/embed/trezorhal/{ => stm32f4}/image.c | 0 core/embed/trezorhal/{ => stm32f4}/irq.h | 0 core/embed/trezorhal/{ => stm32f4}/lowlevel.c | 0 core/embed/trezorhal/{ => stm32f4}/mpu.c | 0 .../trezorhal/{stm32.c => stm32f4/platform.c} | 2 +- .../trezorhal/{stm32.h => stm32f4/platform.h} | 11 ++ .../trezorhal/{ => stm32f4}/random_delays.c | 0 core/embed/trezorhal/{ => stm32f4}/rgb_led.c | 0 core/embed/trezorhal/{ => stm32f4}/rng.c | 0 core/embed/trezorhal/{ => stm32f4}/sbu.c | 0 .../sdcard-set_clr_card_detect.h | 0 core/embed/trezorhal/{ => stm32f4}/sdcard.c | 0 core/embed/trezorhal/{ => stm32f4}/sdram.c | 0 core/embed/trezorhal/{ => stm32f4}/sdram.h | 0 .../{ => stm32f4}/stm32f4xx_hal_conf.h | 0 .../embed/trezorhal/{ => stm32f4}/supervise.h | 0 core/embed/trezorhal/stm32f4/systemview.h | 1 + core/embed/trezorhal/{ => stm32f4}/systick.c | 0 core/embed/trezorhal/{ => stm32f4}/systick.h | 0 .../trezorhal/{ => stm32f4}/touch/ft6x36.c | 0 .../trezorhal/{ => stm32f4}/touch/ft6x36.h | 0 .../trezorhal/{ => stm32f4}/touch/stmpe811.c | 0 .../trezorhal/{ => stm32f4}/touch/stmpe811.h | 0 core/embed/trezorhal/{ => stm32f4}/usb.c | 0 .../trezorhal/{ => stm32f4}/usb_hid-impl.h | 0 .../trezorhal/{ => stm32f4}/usb_vcp-impl.h | 0 .../trezorhal/{ => stm32f4}/usb_webusb-impl.h | 0 .../embed/trezorhal/{ => stm32f4}/usbd_conf.c | 0 .../embed/trezorhal/{ => stm32f4}/usbd_conf.h | 0 .../embed/trezorhal/{ => stm32f4}/usbd_core.c | 0 .../embed/trezorhal/{ => stm32f4}/usbd_core.h | 0 .../trezorhal/{ => stm32f4}/usbd_ctlreq.c | 0 .../trezorhal/{ => stm32f4}/usbd_ctlreq.h | 0 core/embed/trezorhal/{ => stm32f4}/usbd_def.h | 0 .../trezorhal/{ => stm32f4}/usbd_ioreq.c | 0 .../trezorhal/{ => stm32f4}/usbd_ioreq.h | 0 core/embed/trezorhal/{ => stm32f4}/util.s | 0 .../trezorhal/{ => stm32f4}/vectortable.s | 0 core/embed/trezorhal/systemview.h | 1 - core/embed/trezorhal/{touch => }/touch.h | 0 .../embed/{ => trezorhal}/unix/background_1.h | 0 .../{ => trezorhal}/unix/background_1.jpg | Bin .../embed/{ => trezorhal}/unix/background_T.h | 0 .../{ => trezorhal}/unix/background_T.jpg | Bin .../{ => trezorhal}/unix/background_raspi.h | 0 .../{ => trezorhal}/unix/background_raspi.jpg | Bin core/embed/{ => trezorhal}/unix/common.c | 0 .../embed/{ => trezorhal}/unix/display-unix.c | 0 .../embed/{ => trezorhal}/unix/display-unix.h | 0 core/embed/{ => trezorhal}/unix/flash.c | 0 core/embed/trezorhal/unix/image.c | 1 + core/embed/trezorhal/unix/platform.h | 2 + .../{ => trezorhal}/unix/random_delays.c | 0 .../{ => trezorhal}/unix/random_delays.h | 0 core/embed/{ => trezorhal}/unix/rng.c | 0 core/embed/{ => trezorhal}/unix/sbu.c | 0 core/embed/{ => trezorhal}/unix/sdcard.c | 0 core/embed/{ => trezorhal}/unix/touch/touch.c | 0 core/embed/{ => trezorhal}/unix/usb.c | 0 core/embed/unix/button.h | 1 - core/embed/unix/common.h | 66 ---------- core/embed/unix/dma2d.h | 43 ------- core/embed/unix/flash.h | 1 - core/embed/unix/image.h | 1 - core/embed/unix/rgb_led.h | 4 - core/embed/unix/rng.h | 1 - core/embed/unix/sbu.h | 1 - core/embed/unix/sdcard.h | 1 - core/embed/unix/secbool.h | 1 - core/embed/unix/touch/touch.h | 1 - core/embed/unix/usb.h | 1 - core/embed/unix/usb_hid-defs.h | 1 - core/embed/unix/usb_vcp-defs.h | 1 - core/embed/unix/usb_webusb-defs.h | 1 - core/site_scons/boards/discovery.py | 44 +++++-- core/site_scons/boards/stm32f4_common.py | 52 ++++++++ core/site_scons/boards/trezor_1.py | 32 ++++- core/site_scons/boards/trezor_r_v10.py | 40 ++++-- core/site_scons/boards/trezor_r_v3.py | 36 ++++-- core/site_scons/boards/trezor_r_v4.py | 34 ++++-- core/site_scons/boards/trezor_r_v6.py | 34 ++++-- core/site_scons/boards/trezor_t.py | 46 +++++-- core/site_scons/tools.py | 15 +-- 140 files changed, 426 insertions(+), 652 deletions(-) rename core/embed/{trezorhal => lib}/mini_printf.c (100%) rename core/embed/{trezorhal => lib}/mini_printf.h (100%) rename core/embed/{trezorhal => lib}/secbool.h (100%) rename core/embed/{trezorhal/touch => lib}/touch.c (94%) rename core/embed/{unix => trezorhal/boards}/board-unix.h (100%) rename core/embed/trezorhal/{ => stm32f4}/backlight_pwm.c (100%) rename core/embed/trezorhal/{ => stm32f4}/backlight_pwm.h (100%) rename core/embed/trezorhal/{ => stm32f4}/board_capabilities.c (100%) rename core/embed/trezorhal/{ => stm32f4}/button.c (100%) rename core/embed/trezorhal/{ => stm32f4}/common.c (99%) rename core/embed/trezorhal/{ => stm32f4}/compiler_traits.h (100%) rename core/embed/trezorhal/{ => stm32f4}/consumption_mask.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ili9341_spi.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ili9341_spi.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ltdc.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ltdc.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/154a.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/154a.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/lx154a2411.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/lx154a2411.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/lx154a2422.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/lx154a2422.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/tf15411a.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/panels/tf15411a.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/st7789v.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/st7789v.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ug-2828tswig01.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/ug-2828tswig01.h (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/vg-2864ksweg01.c (100%) rename core/embed/trezorhal/{ => stm32f4}/displays/vg-2864ksweg01.h (100%) rename core/embed/trezorhal/{ => stm32f4}/dma.c (100%) rename core/embed/trezorhal/{ => stm32f4}/dma.h (100%) rename core/embed/trezorhal/{ => stm32f4}/dma2d.c (100%) rename core/embed/trezorhal/{ => stm32f4}/flash.c (100%) rename core/embed/trezorhal/{ => stm32f4}/i2c.c (100%) rename core/embed/trezorhal/{ => stm32f4}/i2c.h (100%) rename core/embed/trezorhal/{ => stm32f4}/image.c (100%) rename core/embed/trezorhal/{ => stm32f4}/irq.h (100%) rename core/embed/trezorhal/{ => stm32f4}/lowlevel.c (100%) rename core/embed/trezorhal/{ => stm32f4}/mpu.c (100%) rename core/embed/trezorhal/{stm32.c => stm32f4/platform.c} (99%) rename core/embed/trezorhal/{stm32.h => stm32f4/platform.h} (71%) rename core/embed/trezorhal/{ => stm32f4}/random_delays.c (100%) rename core/embed/trezorhal/{ => stm32f4}/rgb_led.c (100%) rename core/embed/trezorhal/{ => stm32f4}/rng.c (100%) rename core/embed/trezorhal/{ => stm32f4}/sbu.c (100%) rename core/embed/trezorhal/{ => stm32f4}/sdcard-set_clr_card_detect.h (100%) rename core/embed/trezorhal/{ => stm32f4}/sdcard.c (100%) rename core/embed/trezorhal/{ => stm32f4}/sdram.c (100%) rename core/embed/trezorhal/{ => stm32f4}/sdram.h (100%) rename core/embed/trezorhal/{ => stm32f4}/stm32f4xx_hal_conf.h (100%) rename core/embed/trezorhal/{ => stm32f4}/supervise.h (100%) create mode 120000 core/embed/trezorhal/stm32f4/systemview.h rename core/embed/trezorhal/{ => stm32f4}/systick.c (100%) rename core/embed/trezorhal/{ => stm32f4}/systick.h (100%) rename core/embed/trezorhal/{ => stm32f4}/touch/ft6x36.c (100%) rename core/embed/trezorhal/{ => stm32f4}/touch/ft6x36.h (100%) rename core/embed/trezorhal/{ => stm32f4}/touch/stmpe811.c (100%) rename core/embed/trezorhal/{ => stm32f4}/touch/stmpe811.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usb.c (100%) rename core/embed/trezorhal/{ => stm32f4}/usb_hid-impl.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usb_vcp-impl.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usb_webusb-impl.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_conf.c (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_conf.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_core.c (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_core.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_ctlreq.c (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_ctlreq.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_def.h (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_ioreq.c (100%) rename core/embed/trezorhal/{ => stm32f4}/usbd_ioreq.h (100%) rename core/embed/trezorhal/{ => stm32f4}/util.s (100%) rename core/embed/trezorhal/{ => stm32f4}/vectortable.s (100%) delete mode 120000 core/embed/trezorhal/systemview.h rename core/embed/trezorhal/{touch => }/touch.h (100%) rename core/embed/{ => trezorhal}/unix/background_1.h (100%) rename core/embed/{ => trezorhal}/unix/background_1.jpg (100%) rename core/embed/{ => trezorhal}/unix/background_T.h (100%) rename core/embed/{ => trezorhal}/unix/background_T.jpg (100%) rename core/embed/{ => trezorhal}/unix/background_raspi.h (100%) rename core/embed/{ => trezorhal}/unix/background_raspi.jpg (100%) rename core/embed/{ => trezorhal}/unix/common.c (100%) rename core/embed/{ => trezorhal}/unix/display-unix.c (100%) rename core/embed/{ => trezorhal}/unix/display-unix.h (100%) rename core/embed/{ => trezorhal}/unix/flash.c (100%) create mode 120000 core/embed/trezorhal/unix/image.c create mode 100644 core/embed/trezorhal/unix/platform.h rename core/embed/{ => trezorhal}/unix/random_delays.c (100%) rename core/embed/{ => trezorhal}/unix/random_delays.h (100%) rename core/embed/{ => trezorhal}/unix/rng.c (100%) rename core/embed/{ => trezorhal}/unix/sbu.c (100%) rename core/embed/{ => trezorhal}/unix/sdcard.c (100%) rename core/embed/{ => trezorhal}/unix/touch/touch.c (100%) rename core/embed/{ => trezorhal}/unix/usb.c (100%) delete mode 120000 core/embed/unix/button.h delete mode 100644 core/embed/unix/common.h delete mode 100644 core/embed/unix/dma2d.h delete mode 120000 core/embed/unix/flash.h delete mode 120000 core/embed/unix/image.h delete mode 100644 core/embed/unix/rgb_led.h delete mode 120000 core/embed/unix/rng.h delete mode 120000 core/embed/unix/sbu.h delete mode 120000 core/embed/unix/sdcard.h delete mode 120000 core/embed/unix/secbool.h delete mode 120000 core/embed/unix/touch/touch.h delete mode 120000 core/embed/unix/usb.h delete mode 120000 core/embed/unix/usb_hid-defs.h delete mode 120000 core/embed/unix/usb_vcp-defs.h delete mode 120000 core/embed/unix/usb_webusb-defs.h create mode 100644 core/site_scons/boards/stm32f4_common.py diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index 058e0dcdb2..050d23cdfd 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -24,6 +24,9 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] # modtrezorcrypto CCFLAGS_MOD += '-Wno-sequence-point ' @@ -57,31 +60,7 @@ SOURCE_MOD += [ 'embed/lib/colors.c', 'embed/lib/fonts/fonts.c', 'embed/lib/fonts/font_bitmap.c', -] - -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + 'embed/lib/mini_printf.c', ] SOURCE_BOARDLOADER = [ @@ -89,24 +68,9 @@ SOURCE_BOARDLOADER = [ 'embed/boardloader/main.c', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/board_capabilities.c', - 'embed/trezorhal/common.c', - 'embed/trezorhal/dma.c', - 'embed/trezorhal/image.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/lowlevel.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] - env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Replace( CP='cp', @@ -123,17 +87,6 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL, ) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' -elif TREZOR_MODEL in ('DISC1',): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F429xx' -else: - raise ValueError('Unknown Trezor model') - env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' @@ -143,7 +96,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/boardloader/memory.ld -Wl,--gc-sections -Wl,-Map=build/boardloader/boardloader.map -Wl,--warn-common -Wl,--print-memory-usage', CPPPATH=[ @@ -152,23 +105,19 @@ env.Replace( 'embed/models', 'embed/trezorhal', 'embed/extmod/modtrezorui', - 'vendor/micropython/stmhal', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'BOARDLOADER', 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, - ASPPFLAGS='$CFLAGS $CCFLAGS', ) + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], + ASPPFLAGS='$CFLAGS $CCFLAGS', + ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOARDLOADER + SOURCE_STMHAL + SOURCE_TREZORHAL, + ALLSOURCES=SOURCE_MOD + SOURCE_BOARDLOADER + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) cmake_gen = env.Command( @@ -184,8 +133,7 @@ cmake_gen = env.Command( obj_program = [] obj_program += env.Object(source=SOURCE_MOD) obj_program += env.Object(source=SOURCE_BOARDLOADER) -obj_program += env.Object(source=SOURCE_STMHAL) -obj_program += env.Object(source=SOURCE_TREZORHAL) +obj_program += env.Object(source=SOURCE_HAL) program_elf = env.Command( target='boardloader.elf', diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index ae54a8a2de..b4b68cace4 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -20,12 +20,15 @@ if TREZOR_MODEL in ('1', ): ) Return() -FEATURES_WANTED = ["input", "rgb_led", "consumption_mask"] +FEATURES_WANTED = ["input", "rgb_led", "consumption_mask", "usb"] CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] if TREZOR_MODEL in ('R', ): FONT_NORMAL='Font_PixelOperator_Regular_8' @@ -75,6 +78,7 @@ CPPPATH_MOD += [ ] SOURCE_MOD += [ + 'embed/lib/mini_printf.c', 'embed/lib/unit_variant.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', @@ -87,31 +91,6 @@ SOURCE_MOD += [ 'vendor/micropython/lib/uzlib/tinflate.c', ] -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', -] - SOURCE_NANOPB = [ 'vendor/nanopb/pb_common.c', 'vendor/nanopb/pb_decode.c', @@ -127,25 +106,6 @@ SOURCE_BOOTLOADER = [ 'embed/bootloader/protob/messages.pb.c', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/common.c', - 'embed/trezorhal/image.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/mpu.c', - 'embed/trezorhal/random_delays.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/usb.c', - 'embed/trezorhal/usbd_conf.c', - 'embed/trezorhal/usbd_core.c', - 'embed/trezorhal/usbd_ctlreq.c', - 'embed/trezorhal/usbd_ioreq.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] - # fonts tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD) @@ -155,7 +115,7 @@ tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}") -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Replace( CP='cp', @@ -172,19 +132,6 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL, ) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' - RUST_TARGET = 'thumbv7em-none-eabihf' -elif TREZOR_MODEL in ('DISC1', ): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F429xx' - RUST_TARGET = 'thumbv7em-none-eabihf' -else: - raise ValueError('Unknown Trezor model') - env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' @@ -194,7 +141,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/bootloader/memory.ld -Wl,--gc-sections -Wl,-Map=build/bootloader/bootloader.map -Wl,--warn-common -Wl,--print-memory-usage', CPPPATH=[ @@ -206,30 +153,27 @@ env.Replace( 'embed/models', 'embed/trezorhal', 'embed/extmod/modtrezorui', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', 'vendor/nanopb', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'BOOTLOADER', 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), 'PB_FIELD_16BIT', 'PB_ENCODE_ARRAYS_UNPACKED', 'PB_VALIDATE_UTF8', - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, - ASPPFLAGS='$CFLAGS $CCFLAGS', ) + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], + ASPPFLAGS='$CFLAGS $CCFLAGS', + ) env.Replace( HEADERTOOL='tools/headertool.py', ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_STMHAL + SOURCE_TREZORHAL, + ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}"])) cmake_gen = env.Command( @@ -245,7 +189,7 @@ cmake_gen = env.Command( RUST_PROFILE = 'release' RUST_LIB = 'trezor_lib' -RUST_LIBDIR = f'build/bootloader/rust/{RUST_TARGET}/{RUST_PROFILE}' +RUST_LIBDIR = f'build/bootloader/rust/{env.get("ENV")["RUST_TARGET"]}/{RUST_PROFILE}' RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a' def cargo_build(): @@ -266,7 +210,7 @@ def cargo_build(): features.extend(FEATURES_AVAILABLE) cargo_opts = [ - f'--target={RUST_TARGET}', + f'--target={env.get("ENV")["RUST_TARGET"]}', f'--target-dir=../../build/bootloader/rust', '--no-default-features', '--features ' + ','.join(features), @@ -292,8 +236,7 @@ obj_program = [] obj_program += env.Object(source=SOURCE_MOD) obj_program += env.Object(source=SOURCE_BOOTLOADER) obj_program += env.Object(source=SOURCE_NANOPB) -obj_program += env.Object(source=SOURCE_STMHAL) -obj_program += env.Object(source=SOURCE_TREZORHAL) +obj_program += env.Object(source=SOURCE_HAL) program_elf = env.Command( diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index 5670cf1f02..30df7ae0d4 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -18,12 +18,15 @@ if TREZOR_MODEL in ('1', 'DISC1'): ) Return() -FEATURES_WANTED = ["input"] +FEATURES_WANTED = ["input", "usb"] CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] if TREZOR_MODEL in ('1', 'R'): FONT_NORMAL='Font_PixelOperator_Regular_8' @@ -73,34 +76,13 @@ SOURCE_MOD += [ 'embed/lib/colors.c', 'embed/lib/fonts/fonts.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/mini_printf.c', 'embed/extmod/modtrezorcrypto/rand.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', ] -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', -] - SOURCE_NANOPB = [ 'vendor/nanopb/pb_common.c', 'vendor/nanopb/pb_decode.c', @@ -116,24 +98,6 @@ SOURCE_BOOTLOADER = [ 'embed/bootloader_ci/protob/messages.pb.c', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/common.c', - 'embed/trezorhal/image.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/mpu.c', - 'embed/trezorhal/random_delays.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/usb.c', - 'embed/trezorhal/usbd_conf.c', - 'embed/trezorhal/usbd_core.c', - 'embed/trezorhal/usbd_ctlreq.c', - 'embed/trezorhal/usbd_ioreq.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] # fonts tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD) @@ -144,7 +108,7 @@ tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Replace( CP='cp', @@ -161,13 +125,6 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL, ) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' -else: - raise ValueError('Unknown Trezor model') - env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' @@ -177,7 +134,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/bootloader_ci/memory.ld -Wl,--gc-sections -Wl,-Map=build/bootloader_ci/bootloader.map -Wl,--warn-common', CPPPATH=[ @@ -188,30 +145,26 @@ env.Replace( 'embed/models', 'embed/trezorhal', 'embed/extmod/modtrezorui', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', 'vendor/nanopb', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), 'PB_FIELD_16BIT', 'PB_ENCODE_ARRAYS_UNPACKED', 'PB_VALIDATE_UTF8', - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], ASPPFLAGS='$CFLAGS $CCFLAGS', - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_STMHAL + SOURCE_TREZORHAL+ SOURCE_NANOPB, ) + ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_HAL+ SOURCE_NANOPB, ) env.Replace( HEADERTOOL='tools/headertool.py', ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_STMHAL + SOURCE_TREZORHAL, + ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) cmake_gen = env.Command( @@ -229,8 +182,7 @@ obj_program = [] obj_program += env.Object(source=SOURCE_MOD) obj_program += env.Object(source=SOURCE_BOOTLOADER) obj_program += env.Object(source=SOURCE_NANOPB) -obj_program += env.Object(source=SOURCE_STMHAL) -obj_program += env.Object(source=SOURCE_TREZORHAL) +obj_program += env.Object(source=SOURCE_HAL) program_elf = env.Command( target='bootloader.elf', diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index 94f1d2acee..435364542b 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -82,6 +82,7 @@ SOURCE_MOD += [ 'embed/lib/display.c', 'embed/lib/fonts/fonts.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/touch.c', 'embed/extmod/modtrezorcrypto/rand.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', @@ -103,18 +104,18 @@ SOURCE_BOOTLOADER = [ ] SOURCE_TREZORHAL = [ - 'embed/trezorhal/image.c', + 'embed/trezorhal/unix/image.c', + 'embed/trezorhal/unix/display-unix.c', + 'embed/trezorhal/unix/flash.c', + 'embed/trezorhal/unix/common.c', + 'embed/trezorhal/unix/touch/touch.c', + 'embed/trezorhal/unix/rng.c', + 'embed/trezorhal/unix/usb.c', + 'embed/trezorhal/unix/random_delays.c', ] SOURCE_UNIX = [ - 'embed/unix/common.c', - 'embed/unix/display-unix.c', - 'embed/unix/flash.c', 'embed/unix/profile.c', - 'embed/unix/random_delays.c', - 'embed/unix/rng.c', - 'embed/unix/touch/touch.c', - 'embed/unix/usb.c', ] # fonts @@ -170,6 +171,8 @@ env.Replace( 'embed/bootloader/protob', 'embed/lib', 'embed/models', + 'embed/trezorhal', + 'embed/trezorhal/unix', 'embed/unix', 'embed/extmod/modtrezorui', 'vendor/nanopb', @@ -181,7 +184,7 @@ env.Replace( 'HW_MODEL=' + MODEL_AS_NUMBER, 'HW_REVISION=' + ('6' if TREZOR_MODEL in ('R',) else '0'), 'TREZOR_MODEL_'+TREZOR_MODEL, - 'TREZOR_BOARD=\\"board-unix.h\\"', + 'TREZOR_BOARD=\\"boards/board-unix.h\\"', 'PB_FIELD_16BIT', 'PB_ENCODE_ARRAYS_UNPACKED', 'PB_VALIDATE_UTF8', diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 374c47c186..f0d5a0101b 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -18,12 +18,15 @@ FEATURE_FLAGS = { "SYSTEM_VIEW": False, } -FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask"] +FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb"] CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] PYOPT = ARGUMENTS.get('PYOPT', '1') FROZEN = True @@ -174,6 +177,7 @@ CPPPATH_MOD += [ 'vendor/micropython/lib/uzlib', ] SOURCE_MOD += [ + 'embed/lib/mini_printf.c', 'embed/lib/unit_variant.c', 'embed/lib/buffers.c', 'embed/lib/colors.c', @@ -328,31 +332,6 @@ SOURCE_MICROPYTHON_SPEED = [ 'vendor/micropython/py/vm.c', ] -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', -] - SOURCE_FIRMWARE = [ 'embed/firmware/bl_check.c', 'embed/firmware/delay.c', @@ -363,28 +342,6 @@ SOURCE_FIRMWARE = [ 'embed/firmware/startup.S', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/board_capabilities.c', - 'embed/trezorhal/common.c', - 'embed/trezorhal/dma.c', - 'embed/trezorhal/image.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/mpu.c', - 'embed/trezorhal/random_delays.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/usb.c', - 'embed/trezorhal/usbd_conf.c', - 'embed/trezorhal/usbd_core.c', - 'embed/trezorhal/usbd_ctlreq.c', - 'embed/trezorhal/usbd_ioreq.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] - - CPPDEFINES_MOD += ['USE_SVC_SHUTDOWN'] if FEATURE_FLAGS["RDI"]: @@ -417,7 +374,7 @@ SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DPYOPT={PYOPT} -DBOOTLOADER_QA={int(BOOTLOADER_QA)} -DBITCOIN_ONLY={BITCOIN_ONLY}") -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Tool('micropython') @@ -437,26 +394,10 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL,) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' - LD_VARIANT = '' - RUST_TARGET = 'thumbv7em-none-eabihf' -elif TREZOR_MODEL in ('DISC1', ): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F429xx' - LD_VARIANT = '' - RUST_TARGET = 'thumbv7em-none-eabihf' -elif TREZOR_MODEL in ('1',): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m3 -mfloat-abi=soft' - CPU_CCFLAGS = '-mthumb -mtune=cortex-m3 -mcpu=cortex-m3 -mfloat-abi=soft ' - CPU_MODEL = 'STM32F405xx' +if TREZOR_MODEL in ('1',): LD_VARIANT = '' if EVERYTHING else '_min' - RUST_TARGET = 'thumbv7m-none-eabi' else: - raise ValueError('Unknown Trezor model') + LD_VARIANT = '' env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), @@ -467,7 +408,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/firmware/memory_${TREZOR_MODEL}%s.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common' % LD_VARIANT, CPPPATH=[ @@ -479,19 +420,16 @@ env.Replace( 'embed/trezorhal', 'embed/extmod/modtrezorui', 'vendor/micropython', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'FIRMWARE', 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, - ASPPFLAGS='$CFLAGS $CCFLAGS', ) + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], + ASPPFLAGS='$CFLAGS $CCFLAGS', + ) env.Replace( HEADERTOOL='tools/headertool.py', @@ -725,7 +663,7 @@ env.Depends(protobuf_blobs, qstr_generated) RUST_PROFILE = 'release' RUST_LIB = 'trezor_lib' -RUST_LIBDIR = f'build/firmware/rust/{RUST_TARGET}/{RUST_PROFILE}' +RUST_LIBDIR = f'build/firmware/rust/{env.get("ENV")["RUST_TARGET"]}/{RUST_PROFILE}' RUST_LIBPATH = f'{RUST_LIBDIR}/lib{RUST_LIB}.a' def cargo_build(): @@ -751,7 +689,7 @@ def cargo_build(): features.extend(FEATURES_AVAILABLE) cargo_opts = [ - f'--target={RUST_TARGET}', + f'--target={env.get("ENV")["RUST_TARGET"]}', f'--target-dir=../../build/firmware/rust', '--no-default-features', '--features ' + ','.join(features), @@ -776,7 +714,7 @@ env.Append(LINKFLAGS=f' -l{RUST_LIB}') # Program objects # -source_files = SOURCE_MOD + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_STMHAL + SOURCE_TREZORHAL +source_files = SOURCE_MOD + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_HAL obj_program = [] obj_program.extend(env.Object(source=SOURCE_MOD)) if FEATURE_FLAGS["SECP256K1_ZKP"]: @@ -785,8 +723,7 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]: obj_program.extend(env.Object(source=SOURCE_FIRMWARE)) obj_program.extend(env.Object(source=SOURCE_MICROPYTHON)) obj_program.extend(env.Object(source=SOURCE_MICROPYTHON_SPEED, COPT='-O3')) -obj_program.extend(env.Object(source=SOURCE_STMHAL)) -obj_program.extend(env.Object(source=SOURCE_TREZORHAL)) +obj_program.extend(env.Object(source=SOURCE_HAL)) if FROZEN: obj_program.extend(env.Object(source=source_mpyc)) @@ -812,13 +749,15 @@ elif PRODUCTION: else: VENDORHEADER = f'embed/vendorheader/{MODEL_IDENTIFIER}/vendorheader_unsafe_signed_prod.bin' -obj_program.extend( - env.Command( - target='embed/firmware/vendorheader.o', - source=VENDORHEADER, - action='$OBJCOPY -I binary -O elf32-littlearm -B arm' - ' --rename-section .data=.vendorheader,alloc,load,readonly,contents' - ' $SOURCE $TARGET', )) + +if TREZOR_MODEL not in ('1',): + obj_program.extend( + env.Command( + target='embed/firmware/vendorheader.o', + source=VENDORHEADER, + action='$OBJCOPY -I binary -O elf32-littlearm -B arm' + ' --rename-section .data=.vendorheader,alloc,load,readonly,contents' + ' $SOURCE $TARGET', )) if TREZOR_MODEL not in ('DISC1', ): obj_program.extend( diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index a382ea8bc1..008219898e 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -17,7 +17,7 @@ if TREZOR_MODEL in ('DISC1', ): action=build_prodtest) Return() -FEATURES_WANTED = ["input", "sbu", "sd_card", "rdb_led"] +FEATURES_WANTED = ["input", "sbu", "sd_card", "rdb_led", "usb"] CCFLAGS_MOD = '' CPPPATH_MOD = [] @@ -25,6 +25,9 @@ CPPDEFINES_MOD = [ 'USE_INSECURE_PRNG', ] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] if TREZOR_MODEL in ('1', 'R'): FONT_NORMAL=None @@ -61,58 +64,19 @@ SOURCE_MOD += [ 'embed/lib/colors.c', 'embed/lib/fonts/fonts.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/mini_printf.c', 'embed/lib/qr-code-generator/qrcodegen.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', ] -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', -] - SOURCE_PRODTEST = [ 'embed/prodtest/startup.s', 'embed/prodtest/header.S', 'embed/prodtest/main.c', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/common.c', - 'embed/trezorhal/dma.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/random_delays.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/usb.c', - 'embed/trezorhal/usbd_conf.c', - 'embed/trezorhal/usbd_core.c', - 'embed/trezorhal/usbd_ctlreq.c', - 'embed/trezorhal/usbd_ioreq.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] - # fonts tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD) @@ -122,7 +86,7 @@ tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Replace( CP='cp', @@ -139,17 +103,6 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL, ) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' -elif TREZOR_MODEL in ('1',): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m3 -mfloat-abi=soft' - CPU_CCFLAGS = '-mthumb -mtune=cortex-m3 -mcpu=cortex-m3 -mfloat-abi=soft ' - CPU_MODEL = 'STM32F405xx' -else: - raise ValueError('Unknown Trezor model') - env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' @@ -159,7 +112,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/prodtest/memory.ld -Wl,--gc-sections -Wl,-Map=build/prodtest/prodtest.map -Wl,--warn-common', CPPPATH=[ @@ -168,19 +121,16 @@ env.Replace( 'embed/models', 'embed/trezorhal', 'embed/extmod/modtrezorui', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'TREZOR_PRODTEST', 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, - ASPPFLAGS='$CFLAGS $CCFLAGS', ) + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], + ASPPFLAGS='$CFLAGS $CCFLAGS', + ) env.Replace( HEADERTOOL='tools/headertool.py', @@ -188,7 +138,7 @@ env.Replace( env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_PRODTEST + SOURCE_STMHAL + SOURCE_TREZORHAL, + ALLSOURCES=SOURCE_MOD + SOURCE_PRODTEST + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) cmake_gen = env.Command( @@ -205,8 +155,7 @@ cmake_gen = env.Command( obj_program = [] obj_program.extend(env.Object(source=SOURCE_MOD)) obj_program.extend(env.Object(source=SOURCE_PRODTEST)) -obj_program.extend(env.Object(source=SOURCE_STMHAL)) -obj_program.extend(env.Object(source=SOURCE_TREZORHAL)) +obj_program.extend(env.Object(source=SOURCE_HAL)) MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) diff --git a/core/SConscript.reflash b/core/SConscript.reflash index 2f4a038619..804d448f58 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -23,6 +23,9 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +CPPDEFINES_HAL = [] +SOURCE_HAL = [] +PATH_HAL = [] if TREZOR_MODEL in ('1', 'R'): FONT_NORMAL=None @@ -54,56 +57,18 @@ SOURCE_MOD += [ 'embed/lib/colors.c', 'embed/lib/fonts/fonts.c', 'embed/lib/fonts/font_bitmap.c', + 'embed/lib/mini_printf.c', 'vendor/micropython/lib/uzlib/adler32.c', 'vendor/micropython/lib/uzlib/crc32.c', 'vendor/micropython/lib/uzlib/tinflate.c', ] -SOURCE_STMHAL = [ - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', -] - SOURCE_REFLASH = [ 'embed/reflash/startup.s', 'embed/reflash/header.S', 'embed/reflash/main.c', ] -SOURCE_TREZORHAL = [ - 'embed/trezorhal/common.c', - 'embed/trezorhal/dma.c', - 'embed/trezorhal/flash.c', - 'embed/trezorhal/mini_printf.c', - 'embed/trezorhal/rng.c', - 'embed/trezorhal/systick.c', - 'embed/trezorhal/stm32.c', - 'embed/trezorhal/usb.c', - 'embed/trezorhal/usbd_conf.c', - 'embed/trezorhal/usbd_core.c', - 'embed/trezorhal/usbd_ctlreq.c', - 'embed/trezorhal/usbd_ioreq.c', - 'embed/trezorhal/util.s', - 'embed/trezorhal/vectortable.s', -] - # fonts tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD) tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD) @@ -113,7 +78,7 @@ tools.add_font('BIG', FONT_BIG, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) -FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) +FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL) env.Replace( CP='cp', @@ -130,17 +95,6 @@ env.Replace( env.Replace( TREZOR_MODEL=TREZOR_MODEL, ) -if TREZOR_MODEL in ('T', 'R'): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' - CPU_CCFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' - CPU_MODEL = 'STM32F427xx' -elif TREZOR_MODEL in ('1',): - CPU_ASFLAGS = '-mthumb -mcpu=cortex-m3 -mfloat-abi=soft' - CPU_CCFLAGS = '-mthumb -mtune=cortex-m3 -mcpu=cortex-m3 -mfloat-abi=soft ' - CPU_MODEL = 'STM32F405xx' -else: - raise ValueError('Unknown Trezor model') - env.Replace( COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' @@ -150,7 +104,7 @@ env.Replace( '-fsingle-precision-constant -fdata-sections -ffunction-sections ' '-ffreestanding ' '-fstack-protector-all ' - + CPU_CCFLAGS + CCFLAGS_MOD, + + env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', LINKFLAGS='-T embed/reflash/memory.ld -Wl,--gc-sections -Wl,-Map=build/reflash/reflash.map -Wl,--warn-common', CPPPATH=[ @@ -159,25 +113,22 @@ env.Replace( 'embed/models', 'embed/trezorhal', 'embed/extmod/modtrezorui', - 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', - 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', 'vendor/micropython/lib/cmsis/inc', - ] + CPPPATH_MOD, + ] + CPPPATH_MOD + PATH_HAL, CPPDEFINES=[ 'TREZOR_MODEL_'+TREZOR_MODEL, - CPU_MODEL, 'USE_HAL_DRIVER', - ('STM32_HAL_H', '""'), - ] + CPPDEFINES_MOD, - ASFLAGS=CPU_ASFLAGS, - ASPPFLAGS='$CFLAGS $CCFLAGS', ) + ] + CPPDEFINES_MOD + CPPDEFINES_HAL, + ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], + ASPPFLAGS='$CFLAGS $CCFLAGS', + ) env.Replace( HEADERTOOL='tools/headertool.py', ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_REFLASH + SOURCE_STMHAL + SOURCE_TREZORHAL, + ALLSOURCES=SOURCE_MOD + SOURCE_REFLASH + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) cmake_gen = env.Command( @@ -193,8 +144,7 @@ cmake_gen = env.Command( obj_program = [] obj_program += env.Object(source=SOURCE_MOD) obj_program += env.Object(source=SOURCE_REFLASH) -obj_program += env.Object(source=SOURCE_STMHAL) -obj_program += env.Object(source=SOURCE_TREZORHAL) +obj_program += env.Object(source=SOURCE_HAL) MODEL_IDENTIFIER = tools.get_model_identifier(TREZOR_MODEL) diff --git a/core/SConscript.unix b/core/SConscript.unix index 632da95bf2..104920776c 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -351,16 +351,16 @@ SOURCE_MICROPYTHON = [ ] SOURCE_UNIX = [ - 'embed/unix/common.c', - 'embed/unix/display-unix.c', - 'embed/unix/flash.c', + 'embed/trezorhal/unix/common.c', + 'embed/trezorhal/unix/display-unix.c', + 'embed/trezorhal/unix/flash.c', + 'embed/trezorhal/unix/random_delays.c', + 'embed/trezorhal/unix/rng.c', + 'embed/trezorhal/unix/usb.c', + 'embed/trezorhal/unix/touch/touch.c', 'embed/unix/main.c', 'embed/unix/main_main.c', 'embed/unix/profile.c', - 'embed/unix/random_delays.c', - 'embed/unix/rng.c', - 'embed/unix/touch/touch.c', - 'embed/unix/usb.c', 'vendor/micropython/shared/runtime/gchelper_generic.c', 'vendor/micropython/ports/unix/alloc.c', 'vendor/micropython/ports/unix/gccollect.c', @@ -369,8 +369,8 @@ SOURCE_UNIX = [ ] if TREZOR_MODEL in ('T', 'R'): SOURCE_UNIX += [ - 'embed/unix/sbu.c', - 'embed/unix/sdcard.c', + 'embed/trezorhal/unix/sbu.c', + 'embed/trezorhal/unix/sdcard.c', ] if DMA2D: @@ -469,6 +469,8 @@ env.Replace( 'embed/lib', 'embed/models', 'embed/unix', + 'embed/trezorhal', + 'embed/trezorhal/unix', 'embed/extmod/modtrezorui', 'vendor/micropython', 'vendor/micropython/ports/unix', @@ -478,7 +480,7 @@ env.Replace( CPU_MODEL, 'TREZOR_EMULATOR', 'TREZOR_MODEL_'+TREZOR_MODEL, - 'TREZOR_BOARD=\\"board-unix.h\\"', + 'TREZOR_BOARD=\\"boards/board-unix.h\\"', ('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'), ] + CPPDEFINES_MOD, ASPPFLAGS='$CFLAGS $CCFLAGS', ) diff --git a/core/embed/bootloader/bootui.c b/core/embed/bootloader/bootui.c index f19c09ae38..dea589ad4d 100644 --- a/core/embed/bootloader/bootui.c +++ b/core/embed/bootloader/bootui.c @@ -110,7 +110,7 @@ void ui_screen_boot_wait(int wait_seconds) { } #if defined USE_TOUCH -#include "touch/touch.h" +#include "touch.h" void ui_click(void) { // flush touch events if any diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index 6beae2f542..46940dbe84 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -32,7 +32,7 @@ #include "compiler_traits.h" #include "mini_printf.h" #include "mpu.h" -#include "stm32.h" +#include "platform.h" #endif #ifdef USE_DMA2D #include "dma2d.h" @@ -41,7 +41,7 @@ #include "i2c.h" #endif #ifdef USE_TOUCH -#include "touch/touch.h" +#include "touch.h" #endif #ifdef USE_BUTTON #include "button.h" diff --git a/core/embed/bootloader_ci/main.c b/core/embed/bootloader_ci/main.c index d7e5e6cb47..901d2b494c 100644 --- a/core/embed/bootloader_ci/main.c +++ b/core/embed/bootloader_ci/main.c @@ -30,7 +30,7 @@ #include "rng.h" #include "secbool.h" #ifdef USE_TOUCH -#include "touch/touch.h" +#include "touch.h" #endif #include "usb.h" #include "version.h" diff --git a/core/embed/extmod/modtrezorio/modtrezorio.c b/core/embed/extmod/modtrezorio/modtrezorio.c index 0874f166bc..72fa781f4f 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio.c +++ b/core/embed/extmod/modtrezorio/modtrezorio.c @@ -29,7 +29,7 @@ #include TREZOR_BOARD #include "button.h" -#include "touch/touch.h" +#include "touch.h" #include "usb.h" // Whether USB data pins were connected on last check (USB configured) diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index f6b43f8b33..e2a50b036f 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -61,7 +61,7 @@ #include "i2c.h" #endif #ifdef USE_TOUCH -#include "touch/touch.h" +#include "touch.h" #endif #ifdef USE_SD_CARD #include "sdcard.h" @@ -71,8 +71,8 @@ #ifdef SYSTEM_VIEW #include "systemview.h" #endif +#include "platform.h" #include "rng.h" -#include "stm32.h" #include "supervise.h" #ifdef USE_SECP256K1_ZKP #include "zkp_context.h" diff --git a/core/embed/trezorhal/mini_printf.c b/core/embed/lib/mini_printf.c similarity index 100% rename from core/embed/trezorhal/mini_printf.c rename to core/embed/lib/mini_printf.c diff --git a/core/embed/trezorhal/mini_printf.h b/core/embed/lib/mini_printf.h similarity index 100% rename from core/embed/trezorhal/mini_printf.h rename to core/embed/lib/mini_printf.h diff --git a/core/embed/trezorhal/secbool.h b/core/embed/lib/secbool.h similarity index 100% rename from core/embed/trezorhal/secbool.h rename to core/embed/lib/secbool.h diff --git a/core/embed/trezorhal/touch/touch.c b/core/embed/lib/touch.c similarity index 94% rename from core/embed/trezorhal/touch/touch.c rename to core/embed/lib/touch.c index 3b0cf265c6..197d209f67 100644 --- a/core/embed/trezorhal/touch/touch.c +++ b/core/embed/lib/touch.c @@ -1,4 +1,5 @@ +#ifdef USE_TOUCH #include "touch.h" uint32_t touch_click(void) { @@ -18,3 +19,4 @@ uint32_t touch_click(void) { // return last touch coordinate return r; } +#endif diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index abdf125623..d04e874f63 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -34,7 +34,7 @@ #include "sbu.h" #include "sdcard.h" #include "secbool.h" -#include "touch/touch.h" +#include "touch.h" #include "usb.h" #include "memzero.h" diff --git a/core/embed/reflash/main.c b/core/embed/reflash/main.c index 6f5f2f8896..10a2fb1f0b 100644 --- a/core/embed/reflash/main.c +++ b/core/embed/reflash/main.c @@ -31,7 +31,7 @@ #include "sbu.h" #include "sdcard.h" #include "secbool.h" -#include "touch/touch.h" +#include "touch.h" static void progress_callback(int pos, int len) { display_printf("."); } diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index bb34304e3d..46e4e011e7 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -28,6 +28,7 @@ sbu = [] sd_card = [] rgb_led = [] backlight = [] +usb = [] test = [ "button", "cc", diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index 130bc7cbd9..ca55fa579b 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -21,7 +21,7 @@ fn model() -> String { fn board() -> String { if !is_firmware() { - return String::from("board-unix.h"); + return String::from("boards/board-unix.h"); } match env::var("TREZOR_BOARD") { @@ -76,6 +76,7 @@ fn prepare_bindings() -> bindgen::Builder { "-I../../vendor/micropython", "-I../../vendor/micropython/lib/uzlib", "-I../lib", + "-I../trezorhal", "-DSTM32F427xx", format!("-DTREZOR_MODEL_{}", model()).as_str(), format!("-DTREZOR_BOARD=\"{}\"", board()).as_str(), @@ -86,7 +87,7 @@ fn prepare_bindings() -> bindgen::Builder { bindings = bindings.clang_args(&[ "-nostdinc", "-I../firmware", - "-I../trezorhal", + "-I../trezorhal/stm32f4", "-I../../build/firmware", "-I../../vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc", "-I../../vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include", @@ -117,6 +118,7 @@ fn prepare_bindings() -> bindgen::Builder { } else { bindings = bindings.clang_args(&[ "-I../unix", + "-I../trezorhal/unix", "-I../../build/unix", "-I../../vendor/micropython/ports/unix", "-DTREZOR_EMULATOR", diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h index 23ec6b5e61..f8bb797a94 100644 --- a/core/embed/rust/trezorhal.h +++ b/core/embed/rust/trezorhal.h @@ -10,7 +10,7 @@ #include "rgb_led.h" #include "secbool.h" #include "storage.h" -#include "touch/touch.h" +#include "touch.h" #include "usb.h" #include "bip39.h" diff --git a/core/embed/unix/board-unix.h b/core/embed/trezorhal/boards/board-unix.h similarity index 100% rename from core/embed/unix/board-unix.h rename to core/embed/trezorhal/boards/board-unix.h diff --git a/core/embed/trezorhal/common.h b/core/embed/trezorhal/common.h index 2a61f4302e..2ffe59d0e2 100644 --- a/core/embed/trezorhal/common.h +++ b/core/embed/trezorhal/common.h @@ -24,6 +24,8 @@ #include #include "secbool.h" +#include "platform.h" + #ifndef MIN_8bits #define MIN_8bits(a, b) \ ({ \ @@ -70,20 +72,8 @@ void show_pin_too_many_screen(void); void hal_delay(uint32_t ms); uint32_t hal_ticks_ms(); -void clear_otg_hs_memory(void); - -extern uint32_t __stack_chk_guard; - void collect_hw_entropy(void); #define HW_ENTROPY_LEN (12 + 32) extern uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN]; -// the following functions are defined in util.s - -void memset_reg(volatile void *start, volatile void *stop, uint32_t val); -void jump_to(uint32_t address); -void jump_to_unprivileged(uint32_t address); -void jump_to_with_flag(uint32_t address, uint32_t register_flag); -void ensure_compatible_settings(void); - #endif diff --git a/core/embed/trezorhal/flash.h b/core/embed/trezorhal/flash.h index b0770bb8f6..e874e7f02c 100644 --- a/core/embed/trezorhal/flash.h +++ b/core/embed/trezorhal/flash.h @@ -92,6 +92,8 @@ extern const uint8_t FIRMWARE_SECTORS[FIRMWARE_SECTORS_COUNT]; void flash_init(void); +uint32_t flash_wait_and_clear_status_flags(void); + secbool __wur flash_unlock_write(void); secbool __wur flash_lock_write(void); diff --git a/core/embed/trezorhal/lowlevel.h b/core/embed/trezorhal/lowlevel.h index df154dba65..49757aeac9 100644 --- a/core/embed/trezorhal/lowlevel.h +++ b/core/embed/trezorhal/lowlevel.h @@ -22,7 +22,6 @@ #include "secbool.h" -uint32_t flash_wait_and_clear_status_flags(void); secbool flash_check_option_bytes(void); void flash_lock_option_bytes(void); void flash_unlock_option_bytes(void); diff --git a/core/embed/trezorhal/backlight_pwm.c b/core/embed/trezorhal/stm32f4/backlight_pwm.c similarity index 100% rename from core/embed/trezorhal/backlight_pwm.c rename to core/embed/trezorhal/stm32f4/backlight_pwm.c diff --git a/core/embed/trezorhal/backlight_pwm.h b/core/embed/trezorhal/stm32f4/backlight_pwm.h similarity index 100% rename from core/embed/trezorhal/backlight_pwm.h rename to core/embed/trezorhal/stm32f4/backlight_pwm.h diff --git a/core/embed/trezorhal/board_capabilities.c b/core/embed/trezorhal/stm32f4/board_capabilities.c similarity index 100% rename from core/embed/trezorhal/board_capabilities.c rename to core/embed/trezorhal/stm32f4/board_capabilities.c diff --git a/core/embed/trezorhal/button.c b/core/embed/trezorhal/stm32f4/button.c similarity index 100% rename from core/embed/trezorhal/button.c rename to core/embed/trezorhal/stm32f4/button.c diff --git a/core/embed/trezorhal/common.c b/core/embed/trezorhal/stm32f4/common.c similarity index 99% rename from core/embed/trezorhal/common.c rename to core/embed/trezorhal/stm32f4/common.c index 29fca8a36c..fc27142fec 100644 --- a/core/embed/trezorhal/common.c +++ b/core/embed/trezorhal/stm32f4/common.c @@ -27,8 +27,8 @@ #include "rust_ui.h" #endif #include "flash.h" +#include "platform.h" #include "rand.h" -#include "stm32.h" #include "supervise.h" #include "mini_printf.h" diff --git a/core/embed/trezorhal/compiler_traits.h b/core/embed/trezorhal/stm32f4/compiler_traits.h similarity index 100% rename from core/embed/trezorhal/compiler_traits.h rename to core/embed/trezorhal/stm32f4/compiler_traits.h diff --git a/core/embed/trezorhal/consumption_mask.c b/core/embed/trezorhal/stm32f4/consumption_mask.c similarity index 100% rename from core/embed/trezorhal/consumption_mask.c rename to core/embed/trezorhal/stm32f4/consumption_mask.c diff --git a/core/embed/trezorhal/displays/ili9341_spi.c b/core/embed/trezorhal/stm32f4/displays/ili9341_spi.c similarity index 100% rename from core/embed/trezorhal/displays/ili9341_spi.c rename to core/embed/trezorhal/stm32f4/displays/ili9341_spi.c diff --git a/core/embed/trezorhal/displays/ili9341_spi.h b/core/embed/trezorhal/stm32f4/displays/ili9341_spi.h similarity index 100% rename from core/embed/trezorhal/displays/ili9341_spi.h rename to core/embed/trezorhal/stm32f4/displays/ili9341_spi.h diff --git a/core/embed/trezorhal/displays/ltdc.c b/core/embed/trezorhal/stm32f4/displays/ltdc.c similarity index 100% rename from core/embed/trezorhal/displays/ltdc.c rename to core/embed/trezorhal/stm32f4/displays/ltdc.c diff --git a/core/embed/trezorhal/displays/ltdc.h b/core/embed/trezorhal/stm32f4/displays/ltdc.h similarity index 100% rename from core/embed/trezorhal/displays/ltdc.h rename to core/embed/trezorhal/stm32f4/displays/ltdc.h diff --git a/core/embed/trezorhal/displays/panels/154a.c b/core/embed/trezorhal/stm32f4/displays/panels/154a.c similarity index 100% rename from core/embed/trezorhal/displays/panels/154a.c rename to core/embed/trezorhal/stm32f4/displays/panels/154a.c diff --git a/core/embed/trezorhal/displays/panels/154a.h b/core/embed/trezorhal/stm32f4/displays/panels/154a.h similarity index 100% rename from core/embed/trezorhal/displays/panels/154a.h rename to core/embed/trezorhal/stm32f4/displays/panels/154a.h diff --git a/core/embed/trezorhal/displays/panels/lx154a2411.c b/core/embed/trezorhal/stm32f4/displays/panels/lx154a2411.c similarity index 100% rename from core/embed/trezorhal/displays/panels/lx154a2411.c rename to core/embed/trezorhal/stm32f4/displays/panels/lx154a2411.c diff --git a/core/embed/trezorhal/displays/panels/lx154a2411.h b/core/embed/trezorhal/stm32f4/displays/panels/lx154a2411.h similarity index 100% rename from core/embed/trezorhal/displays/panels/lx154a2411.h rename to core/embed/trezorhal/stm32f4/displays/panels/lx154a2411.h diff --git a/core/embed/trezorhal/displays/panels/lx154a2422.c b/core/embed/trezorhal/stm32f4/displays/panels/lx154a2422.c similarity index 100% rename from core/embed/trezorhal/displays/panels/lx154a2422.c rename to core/embed/trezorhal/stm32f4/displays/panels/lx154a2422.c diff --git a/core/embed/trezorhal/displays/panels/lx154a2422.h b/core/embed/trezorhal/stm32f4/displays/panels/lx154a2422.h similarity index 100% rename from core/embed/trezorhal/displays/panels/lx154a2422.h rename to core/embed/trezorhal/stm32f4/displays/panels/lx154a2422.h diff --git a/core/embed/trezorhal/displays/panels/tf15411a.c b/core/embed/trezorhal/stm32f4/displays/panels/tf15411a.c similarity index 100% rename from core/embed/trezorhal/displays/panels/tf15411a.c rename to core/embed/trezorhal/stm32f4/displays/panels/tf15411a.c diff --git a/core/embed/trezorhal/displays/panels/tf15411a.h b/core/embed/trezorhal/stm32f4/displays/panels/tf15411a.h similarity index 100% rename from core/embed/trezorhal/displays/panels/tf15411a.h rename to core/embed/trezorhal/stm32f4/displays/panels/tf15411a.h diff --git a/core/embed/trezorhal/displays/st7789v.c b/core/embed/trezorhal/stm32f4/displays/st7789v.c similarity index 100% rename from core/embed/trezorhal/displays/st7789v.c rename to core/embed/trezorhal/stm32f4/displays/st7789v.c diff --git a/core/embed/trezorhal/displays/st7789v.h b/core/embed/trezorhal/stm32f4/displays/st7789v.h similarity index 100% rename from core/embed/trezorhal/displays/st7789v.h rename to core/embed/trezorhal/stm32f4/displays/st7789v.h diff --git a/core/embed/trezorhal/displays/ug-2828tswig01.c b/core/embed/trezorhal/stm32f4/displays/ug-2828tswig01.c similarity index 100% rename from core/embed/trezorhal/displays/ug-2828tswig01.c rename to core/embed/trezorhal/stm32f4/displays/ug-2828tswig01.c diff --git a/core/embed/trezorhal/displays/ug-2828tswig01.h b/core/embed/trezorhal/stm32f4/displays/ug-2828tswig01.h similarity index 100% rename from core/embed/trezorhal/displays/ug-2828tswig01.h rename to core/embed/trezorhal/stm32f4/displays/ug-2828tswig01.h diff --git a/core/embed/trezorhal/displays/vg-2864ksweg01.c b/core/embed/trezorhal/stm32f4/displays/vg-2864ksweg01.c similarity index 100% rename from core/embed/trezorhal/displays/vg-2864ksweg01.c rename to core/embed/trezorhal/stm32f4/displays/vg-2864ksweg01.c diff --git a/core/embed/trezorhal/displays/vg-2864ksweg01.h b/core/embed/trezorhal/stm32f4/displays/vg-2864ksweg01.h similarity index 100% rename from core/embed/trezorhal/displays/vg-2864ksweg01.h rename to core/embed/trezorhal/stm32f4/displays/vg-2864ksweg01.h diff --git a/core/embed/trezorhal/dma.c b/core/embed/trezorhal/stm32f4/dma.c similarity index 100% rename from core/embed/trezorhal/dma.c rename to core/embed/trezorhal/stm32f4/dma.c diff --git a/core/embed/trezorhal/dma.h b/core/embed/trezorhal/stm32f4/dma.h similarity index 100% rename from core/embed/trezorhal/dma.h rename to core/embed/trezorhal/stm32f4/dma.h diff --git a/core/embed/trezorhal/dma2d.c b/core/embed/trezorhal/stm32f4/dma2d.c similarity index 100% rename from core/embed/trezorhal/dma2d.c rename to core/embed/trezorhal/stm32f4/dma2d.c diff --git a/core/embed/trezorhal/flash.c b/core/embed/trezorhal/stm32f4/flash.c similarity index 100% rename from core/embed/trezorhal/flash.c rename to core/embed/trezorhal/stm32f4/flash.c diff --git a/core/embed/trezorhal/i2c.c b/core/embed/trezorhal/stm32f4/i2c.c similarity index 100% rename from core/embed/trezorhal/i2c.c rename to core/embed/trezorhal/stm32f4/i2c.c diff --git a/core/embed/trezorhal/i2c.h b/core/embed/trezorhal/stm32f4/i2c.h similarity index 100% rename from core/embed/trezorhal/i2c.h rename to core/embed/trezorhal/stm32f4/i2c.h diff --git a/core/embed/trezorhal/image.c b/core/embed/trezorhal/stm32f4/image.c similarity index 100% rename from core/embed/trezorhal/image.c rename to core/embed/trezorhal/stm32f4/image.c diff --git a/core/embed/trezorhal/irq.h b/core/embed/trezorhal/stm32f4/irq.h similarity index 100% rename from core/embed/trezorhal/irq.h rename to core/embed/trezorhal/stm32f4/irq.h diff --git a/core/embed/trezorhal/lowlevel.c b/core/embed/trezorhal/stm32f4/lowlevel.c similarity index 100% rename from core/embed/trezorhal/lowlevel.c rename to core/embed/trezorhal/stm32f4/lowlevel.c diff --git a/core/embed/trezorhal/mpu.c b/core/embed/trezorhal/stm32f4/mpu.c similarity index 100% rename from core/embed/trezorhal/mpu.c rename to core/embed/trezorhal/stm32f4/mpu.c diff --git a/core/embed/trezorhal/stm32.c b/core/embed/trezorhal/stm32f4/platform.c similarity index 99% rename from core/embed/trezorhal/stm32.c rename to core/embed/trezorhal/stm32f4/platform.c index e337d656b7..e2dd41a95f 100644 --- a/core/embed/trezorhal/stm32.c +++ b/core/embed/trezorhal/stm32f4/platform.c @@ -19,7 +19,7 @@ #include STM32_HAL_H -#include "stm32.h" +#include "platform.h" #include "rng.h" const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, diff --git a/core/embed/trezorhal/stm32.h b/core/embed/trezorhal/stm32f4/platform.h similarity index 71% rename from core/embed/trezorhal/stm32.h rename to core/embed/trezorhal/stm32f4/platform.h index 9c63d51c36..b2d87e8624 100644 --- a/core/embed/trezorhal/stm32.h +++ b/core/embed/trezorhal/stm32f4/platform.h @@ -21,6 +21,7 @@ #define TREZORHAL_STM32_H #include STM32_HAL_H +#include typedef enum { CLOCK_180_MHZ = 0, @@ -29,5 +30,15 @@ typedef enum { } clock_settings_t; void set_core_clock(clock_settings_t settings); +// the following functions are defined in util.s + +void memset_reg(volatile void *start, volatile void *stop, uint32_t val); +void jump_to(uint32_t address); +void jump_to_unprivileged(uint32_t address); +void jump_to_with_flag(uint32_t address, uint32_t register_flag); +void ensure_compatible_settings(void); +void clear_otg_hs_memory(void); + +extern uint32_t __stack_chk_guard; #endif // TREZORHAL_STM32_H diff --git a/core/embed/trezorhal/random_delays.c b/core/embed/trezorhal/stm32f4/random_delays.c similarity index 100% rename from core/embed/trezorhal/random_delays.c rename to core/embed/trezorhal/stm32f4/random_delays.c diff --git a/core/embed/trezorhal/rgb_led.c b/core/embed/trezorhal/stm32f4/rgb_led.c similarity index 100% rename from core/embed/trezorhal/rgb_led.c rename to core/embed/trezorhal/stm32f4/rgb_led.c diff --git a/core/embed/trezorhal/rng.c b/core/embed/trezorhal/stm32f4/rng.c similarity index 100% rename from core/embed/trezorhal/rng.c rename to core/embed/trezorhal/stm32f4/rng.c diff --git a/core/embed/trezorhal/sbu.c b/core/embed/trezorhal/stm32f4/sbu.c similarity index 100% rename from core/embed/trezorhal/sbu.c rename to core/embed/trezorhal/stm32f4/sbu.c diff --git a/core/embed/trezorhal/sdcard-set_clr_card_detect.h b/core/embed/trezorhal/stm32f4/sdcard-set_clr_card_detect.h similarity index 100% rename from core/embed/trezorhal/sdcard-set_clr_card_detect.h rename to core/embed/trezorhal/stm32f4/sdcard-set_clr_card_detect.h diff --git a/core/embed/trezorhal/sdcard.c b/core/embed/trezorhal/stm32f4/sdcard.c similarity index 100% rename from core/embed/trezorhal/sdcard.c rename to core/embed/trezorhal/stm32f4/sdcard.c diff --git a/core/embed/trezorhal/sdram.c b/core/embed/trezorhal/stm32f4/sdram.c similarity index 100% rename from core/embed/trezorhal/sdram.c rename to core/embed/trezorhal/stm32f4/sdram.c diff --git a/core/embed/trezorhal/sdram.h b/core/embed/trezorhal/stm32f4/sdram.h similarity index 100% rename from core/embed/trezorhal/sdram.h rename to core/embed/trezorhal/stm32f4/sdram.h diff --git a/core/embed/trezorhal/stm32f4xx_hal_conf.h b/core/embed/trezorhal/stm32f4/stm32f4xx_hal_conf.h similarity index 100% rename from core/embed/trezorhal/stm32f4xx_hal_conf.h rename to core/embed/trezorhal/stm32f4/stm32f4xx_hal_conf.h diff --git a/core/embed/trezorhal/supervise.h b/core/embed/trezorhal/stm32f4/supervise.h similarity index 100% rename from core/embed/trezorhal/supervise.h rename to core/embed/trezorhal/stm32f4/supervise.h diff --git a/core/embed/trezorhal/stm32f4/systemview.h b/core/embed/trezorhal/stm32f4/systemview.h new file mode 120000 index 0000000000..fda5c909e7 --- /dev/null +++ b/core/embed/trezorhal/stm32f4/systemview.h @@ -0,0 +1 @@ +../../firmware/systemview.h \ No newline at end of file diff --git a/core/embed/trezorhal/systick.c b/core/embed/trezorhal/stm32f4/systick.c similarity index 100% rename from core/embed/trezorhal/systick.c rename to core/embed/trezorhal/stm32f4/systick.c diff --git a/core/embed/trezorhal/systick.h b/core/embed/trezorhal/stm32f4/systick.h similarity index 100% rename from core/embed/trezorhal/systick.h rename to core/embed/trezorhal/stm32f4/systick.h diff --git a/core/embed/trezorhal/touch/ft6x36.c b/core/embed/trezorhal/stm32f4/touch/ft6x36.c similarity index 100% rename from core/embed/trezorhal/touch/ft6x36.c rename to core/embed/trezorhal/stm32f4/touch/ft6x36.c diff --git a/core/embed/trezorhal/touch/ft6x36.h b/core/embed/trezorhal/stm32f4/touch/ft6x36.h similarity index 100% rename from core/embed/trezorhal/touch/ft6x36.h rename to core/embed/trezorhal/stm32f4/touch/ft6x36.h diff --git a/core/embed/trezorhal/touch/stmpe811.c b/core/embed/trezorhal/stm32f4/touch/stmpe811.c similarity index 100% rename from core/embed/trezorhal/touch/stmpe811.c rename to core/embed/trezorhal/stm32f4/touch/stmpe811.c diff --git a/core/embed/trezorhal/touch/stmpe811.h b/core/embed/trezorhal/stm32f4/touch/stmpe811.h similarity index 100% rename from core/embed/trezorhal/touch/stmpe811.h rename to core/embed/trezorhal/stm32f4/touch/stmpe811.h diff --git a/core/embed/trezorhal/usb.c b/core/embed/trezorhal/stm32f4/usb.c similarity index 100% rename from core/embed/trezorhal/usb.c rename to core/embed/trezorhal/stm32f4/usb.c diff --git a/core/embed/trezorhal/usb_hid-impl.h b/core/embed/trezorhal/stm32f4/usb_hid-impl.h similarity index 100% rename from core/embed/trezorhal/usb_hid-impl.h rename to core/embed/trezorhal/stm32f4/usb_hid-impl.h diff --git a/core/embed/trezorhal/usb_vcp-impl.h b/core/embed/trezorhal/stm32f4/usb_vcp-impl.h similarity index 100% rename from core/embed/trezorhal/usb_vcp-impl.h rename to core/embed/trezorhal/stm32f4/usb_vcp-impl.h diff --git a/core/embed/trezorhal/usb_webusb-impl.h b/core/embed/trezorhal/stm32f4/usb_webusb-impl.h similarity index 100% rename from core/embed/trezorhal/usb_webusb-impl.h rename to core/embed/trezorhal/stm32f4/usb_webusb-impl.h diff --git a/core/embed/trezorhal/usbd_conf.c b/core/embed/trezorhal/stm32f4/usbd_conf.c similarity index 100% rename from core/embed/trezorhal/usbd_conf.c rename to core/embed/trezorhal/stm32f4/usbd_conf.c diff --git a/core/embed/trezorhal/usbd_conf.h b/core/embed/trezorhal/stm32f4/usbd_conf.h similarity index 100% rename from core/embed/trezorhal/usbd_conf.h rename to core/embed/trezorhal/stm32f4/usbd_conf.h diff --git a/core/embed/trezorhal/usbd_core.c b/core/embed/trezorhal/stm32f4/usbd_core.c similarity index 100% rename from core/embed/trezorhal/usbd_core.c rename to core/embed/trezorhal/stm32f4/usbd_core.c diff --git a/core/embed/trezorhal/usbd_core.h b/core/embed/trezorhal/stm32f4/usbd_core.h similarity index 100% rename from core/embed/trezorhal/usbd_core.h rename to core/embed/trezorhal/stm32f4/usbd_core.h diff --git a/core/embed/trezorhal/usbd_ctlreq.c b/core/embed/trezorhal/stm32f4/usbd_ctlreq.c similarity index 100% rename from core/embed/trezorhal/usbd_ctlreq.c rename to core/embed/trezorhal/stm32f4/usbd_ctlreq.c diff --git a/core/embed/trezorhal/usbd_ctlreq.h b/core/embed/trezorhal/stm32f4/usbd_ctlreq.h similarity index 100% rename from core/embed/trezorhal/usbd_ctlreq.h rename to core/embed/trezorhal/stm32f4/usbd_ctlreq.h diff --git a/core/embed/trezorhal/usbd_def.h b/core/embed/trezorhal/stm32f4/usbd_def.h similarity index 100% rename from core/embed/trezorhal/usbd_def.h rename to core/embed/trezorhal/stm32f4/usbd_def.h diff --git a/core/embed/trezorhal/usbd_ioreq.c b/core/embed/trezorhal/stm32f4/usbd_ioreq.c similarity index 100% rename from core/embed/trezorhal/usbd_ioreq.c rename to core/embed/trezorhal/stm32f4/usbd_ioreq.c diff --git a/core/embed/trezorhal/usbd_ioreq.h b/core/embed/trezorhal/stm32f4/usbd_ioreq.h similarity index 100% rename from core/embed/trezorhal/usbd_ioreq.h rename to core/embed/trezorhal/stm32f4/usbd_ioreq.h diff --git a/core/embed/trezorhal/util.s b/core/embed/trezorhal/stm32f4/util.s similarity index 100% rename from core/embed/trezorhal/util.s rename to core/embed/trezorhal/stm32f4/util.s diff --git a/core/embed/trezorhal/vectortable.s b/core/embed/trezorhal/stm32f4/vectortable.s similarity index 100% rename from core/embed/trezorhal/vectortable.s rename to core/embed/trezorhal/stm32f4/vectortable.s diff --git a/core/embed/trezorhal/systemview.h b/core/embed/trezorhal/systemview.h deleted file mode 120000 index e6efe1fe5e..0000000000 --- a/core/embed/trezorhal/systemview.h +++ /dev/null @@ -1 +0,0 @@ -../firmware/systemview.h \ No newline at end of file diff --git a/core/embed/trezorhal/touch/touch.h b/core/embed/trezorhal/touch.h similarity index 100% rename from core/embed/trezorhal/touch/touch.h rename to core/embed/trezorhal/touch.h diff --git a/core/embed/unix/background_1.h b/core/embed/trezorhal/unix/background_1.h similarity index 100% rename from core/embed/unix/background_1.h rename to core/embed/trezorhal/unix/background_1.h diff --git a/core/embed/unix/background_1.jpg b/core/embed/trezorhal/unix/background_1.jpg similarity index 100% rename from core/embed/unix/background_1.jpg rename to core/embed/trezorhal/unix/background_1.jpg diff --git a/core/embed/unix/background_T.h b/core/embed/trezorhal/unix/background_T.h similarity index 100% rename from core/embed/unix/background_T.h rename to core/embed/trezorhal/unix/background_T.h diff --git a/core/embed/unix/background_T.jpg b/core/embed/trezorhal/unix/background_T.jpg similarity index 100% rename from core/embed/unix/background_T.jpg rename to core/embed/trezorhal/unix/background_T.jpg diff --git a/core/embed/unix/background_raspi.h b/core/embed/trezorhal/unix/background_raspi.h similarity index 100% rename from core/embed/unix/background_raspi.h rename to core/embed/trezorhal/unix/background_raspi.h diff --git a/core/embed/unix/background_raspi.jpg b/core/embed/trezorhal/unix/background_raspi.jpg similarity index 100% rename from core/embed/unix/background_raspi.jpg rename to core/embed/trezorhal/unix/background_raspi.jpg diff --git a/core/embed/unix/common.c b/core/embed/trezorhal/unix/common.c similarity index 100% rename from core/embed/unix/common.c rename to core/embed/trezorhal/unix/common.c diff --git a/core/embed/unix/display-unix.c b/core/embed/trezorhal/unix/display-unix.c similarity index 100% rename from core/embed/unix/display-unix.c rename to core/embed/trezorhal/unix/display-unix.c diff --git a/core/embed/unix/display-unix.h b/core/embed/trezorhal/unix/display-unix.h similarity index 100% rename from core/embed/unix/display-unix.h rename to core/embed/trezorhal/unix/display-unix.h diff --git a/core/embed/unix/flash.c b/core/embed/trezorhal/unix/flash.c similarity index 100% rename from core/embed/unix/flash.c rename to core/embed/trezorhal/unix/flash.c diff --git a/core/embed/trezorhal/unix/image.c b/core/embed/trezorhal/unix/image.c new file mode 120000 index 0000000000..8c435077cb --- /dev/null +++ b/core/embed/trezorhal/unix/image.c @@ -0,0 +1 @@ +../stm32f4/image.c \ No newline at end of file diff --git a/core/embed/trezorhal/unix/platform.h b/core/embed/trezorhal/unix/platform.h new file mode 100644 index 0000000000..0cab1411c1 --- /dev/null +++ b/core/embed/trezorhal/unix/platform.h @@ -0,0 +1,2 @@ + +void emulator_poll_events(void); diff --git a/core/embed/unix/random_delays.c b/core/embed/trezorhal/unix/random_delays.c similarity index 100% rename from core/embed/unix/random_delays.c rename to core/embed/trezorhal/unix/random_delays.c diff --git a/core/embed/unix/random_delays.h b/core/embed/trezorhal/unix/random_delays.h similarity index 100% rename from core/embed/unix/random_delays.h rename to core/embed/trezorhal/unix/random_delays.h diff --git a/core/embed/unix/rng.c b/core/embed/trezorhal/unix/rng.c similarity index 100% rename from core/embed/unix/rng.c rename to core/embed/trezorhal/unix/rng.c diff --git a/core/embed/unix/sbu.c b/core/embed/trezorhal/unix/sbu.c similarity index 100% rename from core/embed/unix/sbu.c rename to core/embed/trezorhal/unix/sbu.c diff --git a/core/embed/unix/sdcard.c b/core/embed/trezorhal/unix/sdcard.c similarity index 100% rename from core/embed/unix/sdcard.c rename to core/embed/trezorhal/unix/sdcard.c diff --git a/core/embed/unix/touch/touch.c b/core/embed/trezorhal/unix/touch/touch.c similarity index 100% rename from core/embed/unix/touch/touch.c rename to core/embed/trezorhal/unix/touch/touch.c diff --git a/core/embed/unix/usb.c b/core/embed/trezorhal/unix/usb.c similarity index 100% rename from core/embed/unix/usb.c rename to core/embed/trezorhal/unix/usb.c diff --git a/core/embed/unix/button.h b/core/embed/unix/button.h deleted file mode 120000 index 1b202d3c5f..0000000000 --- a/core/embed/unix/button.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/button.h \ No newline at end of file diff --git a/core/embed/unix/common.h b/core/embed/unix/common.h deleted file mode 100644 index 08f8471237..0000000000 --- a/core/embed/unix/common.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __TREZORUNIX_COMMON_H__ -#define __TREZORUNIX_COMMON_H__ - -#include -#include "secbool.h" - -#ifndef MIN -#define MIN(a, b) \ - ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a < _b ? _a : _b; \ - }) -#endif -#ifndef MAX -#define MAX(a, b) \ - ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a > _b ? _a : _b; \ - }) -#endif - -void __attribute__((noreturn)) trezor_shutdown(void); - -void __attribute__((noreturn)) -__fatal_error(const char *expr, const char *msg, const char *file, int line, - const char *func); -void __attribute__((noreturn)) -error_shutdown(const char *label, const char *msg); -void show_wipe_code_screen(void); -void show_pin_too_many_screen(void); - -#define ensure(expr, msg) \ - (((expr) == sectrue) \ - ? (void)0 \ - : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__)) - -void hal_delay(uint32_t ms); -uint32_t hal_ticks_ms(); -void emulator_poll_events(void); - -void collect_hw_entropy(void); -#define HW_ENTROPY_LEN (12 + 32) -extern uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN]; - -#endif diff --git a/core/embed/unix/dma2d.h b/core/embed/unix/dma2d.h deleted file mode 100644 index 263ec54eb9..0000000000 --- a/core/embed/unix/dma2d.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef _DMA2D_H -#define _DMA2D_H - -// Mockup file so that rust doesn't complain when building bindings - -#include "common.h" - -void dma2d_init(void); - -void dma2d_setup_const(void); -void dma2d_setup_4bpp(uint16_t fg_color, uint16_t bg_color); -void dma2d_setup_16bpp(void); -void dma2d_setup_4bpp_over_4bpp(uint16_t fg_color, uint16_t bg_color, - uint16_t overlay_color); -void dma2d_setup_4bpp_over_16bpp(uint16_t overlay_color); - -void dma2d_start(uint8_t* in_addr, uint8_t* out_addr, int32_t pixels); -void dma2d_start_const(uint16_t color, uint8_t* out_addr, int32_t pixels); -void dma2d_start_blend(uint8_t* overlay_addr, uint8_t* bg_addr, - uint8_t* out_addr, int32_t pixels); - -void dma2d_wait_for_transfer(void); - -#endif //_DMA2D_H diff --git a/core/embed/unix/flash.h b/core/embed/unix/flash.h deleted file mode 120000 index 46dc1c0a9e..0000000000 --- a/core/embed/unix/flash.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/flash.h \ No newline at end of file diff --git a/core/embed/unix/image.h b/core/embed/unix/image.h deleted file mode 120000 index 9e643d0995..0000000000 --- a/core/embed/unix/image.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/image.h \ No newline at end of file diff --git a/core/embed/unix/rgb_led.h b/core/embed/unix/rgb_led.h deleted file mode 100644 index a342b9a858..0000000000 --- a/core/embed/unix/rgb_led.h +++ /dev/null @@ -1,4 +0,0 @@ - -void rgb_led_init(void); - -void rgb_led_set_color(uint32_t color); diff --git a/core/embed/unix/rng.h b/core/embed/unix/rng.h deleted file mode 120000 index 917f74c3e7..0000000000 --- a/core/embed/unix/rng.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/rng.h \ No newline at end of file diff --git a/core/embed/unix/sbu.h b/core/embed/unix/sbu.h deleted file mode 120000 index a6eedac6cc..0000000000 --- a/core/embed/unix/sbu.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/sbu.h \ No newline at end of file diff --git a/core/embed/unix/sdcard.h b/core/embed/unix/sdcard.h deleted file mode 120000 index 01c8fd0cff..0000000000 --- a/core/embed/unix/sdcard.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/sdcard.h \ No newline at end of file diff --git a/core/embed/unix/secbool.h b/core/embed/unix/secbool.h deleted file mode 120000 index 8885c975f3..0000000000 --- a/core/embed/unix/secbool.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/secbool.h \ No newline at end of file diff --git a/core/embed/unix/touch/touch.h b/core/embed/unix/touch/touch.h deleted file mode 120000 index 898ca660a8..0000000000 --- a/core/embed/unix/touch/touch.h +++ /dev/null @@ -1 +0,0 @@ -../../trezorhal/touch/touch.h \ No newline at end of file diff --git a/core/embed/unix/usb.h b/core/embed/unix/usb.h deleted file mode 120000 index f9347c7111..0000000000 --- a/core/embed/unix/usb.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/usb.h \ No newline at end of file diff --git a/core/embed/unix/usb_hid-defs.h b/core/embed/unix/usb_hid-defs.h deleted file mode 120000 index ddb30c83e3..0000000000 --- a/core/embed/unix/usb_hid-defs.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/usb_hid-defs.h \ No newline at end of file diff --git a/core/embed/unix/usb_vcp-defs.h b/core/embed/unix/usb_vcp-defs.h deleted file mode 120000 index 1bb8c4481b..0000000000 --- a/core/embed/unix/usb_vcp-defs.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/usb_vcp-defs.h \ No newline at end of file diff --git a/core/embed/unix/usb_webusb-defs.h b/core/embed/unix/usb_webusb-defs.h deleted file mode 120000 index 52d4243ba0..0000000000 --- a/core/embed/unix/usb_webusb-defs.h +++ /dev/null @@ -1 +0,0 @@ -../trezorhal/usb_webusb-defs.h \ No newline at end of file diff --git a/core/site_scons/boards/discovery.py b/core/site_scons/boards/discovery.py index 6f279c2f1c..17267b8c22 100644 --- a/core/site_scons/boards/discovery.py +++ b/core/site_scons/boards/discovery.py @@ -1,24 +1,39 @@ +from __future__ import annotations + from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files - -def configure(env, features_wanted, defines, sources): - features_available = [] +def configure( + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], +) -> list[str]: + features_available: list[str] = [] board = "stm32f429i-disc1.h" display = "ltdc.c" hw_model = get_hw_model_as_number("D001") hw_revision = 0 + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F429xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] - sources += ["embed/trezorhal/displays/ili9341_spi.c"] - sources += ["embed/trezorhal/sdram.c"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] + sources += ["embed/trezorhal/stm32f4/displays/ili9341_spi.c"] + sources += ["embed/trezorhal/stm32f4/sdram.c"] if "input" in features_wanted: - sources += ["embed/trezorhal/i2c.c"] - sources += ["embed/trezorhal/touch/touch.c"] - sources += ["embed/trezorhal/touch/stmpe811.c"] + sources += ["embed/trezorhal/stm32f4/i2c.c"] + sources += ["embed/trezorhal/stm32f4/touch/stmpe811.c"] + sources += ["embed/lib/touch.c"] features_available.append("touch") if "dma2d" in features_wanted: @@ -26,6 +41,17 @@ def configure(env, features_wanted, defines, sources): sources += ["embed/lib/dma2d_emul.c"] features_available.append("dma2d") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + env.get("ENV")["TREZOR_BOARD"] = board return features_available diff --git a/core/site_scons/boards/stm32f4_common.py b/core/site_scons/boards/stm32f4_common.py new file mode 100644 index 0000000000..f59176bb1a --- /dev/null +++ b/core/site_scons/boards/stm32f4_common.py @@ -0,0 +1,52 @@ +from __future__ import annotations + + +def stm32f4_common_files(defines, sources, paths): + defines += [ + ('STM32_HAL_H', '""'), + ] + + paths += [ + 'embed/trezorhal/stm32f4', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Inc', + 'vendor/micropython/lib/stm32lib/CMSIS/STM32F4xx/Include', + ] + + sources += [ + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c', + ] + + sources += [ + 'embed/trezorhal/stm32f4/board_capabilities.c', + 'embed/trezorhal/stm32f4/common.c', + 'embed/trezorhal/stm32f4/image.c', + 'embed/trezorhal/stm32f4/flash.c', + 'embed/trezorhal/stm32f4/lowlevel.c', + 'embed/trezorhal/stm32f4/mpu.c', + 'embed/trezorhal/stm32f4/platform.c', + 'embed/trezorhal/stm32f4/systick.c', + 'embed/trezorhal/stm32f4/random_delays.c', + 'embed/trezorhal/stm32f4/rng.c', + 'embed/trezorhal/stm32f4/util.s', + 'embed/trezorhal/stm32f4/vectortable.s', + ] + diff --git a/core/site_scons/boards/trezor_1.py b/core/site_scons/boards/trezor_1.py index e48ca93b8f..28752106ca 100644 --- a/core/site_scons/boards/trezor_1.py +++ b/core/site_scons/boards/trezor_1.py @@ -1,13 +1,15 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( - env: dict, - features_wanted: list[str], - defines: list[str | tuple[str, str]], - sources: list[str], + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] board = "trezor_1.h" @@ -15,15 +17,33 @@ def configure( hw_model = get_hw_model_as_number("T1B1") hw_revision = 0 + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m3 -mfloat-abi=soft' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mtune=cortex-m3 -mcpu=cortex-m3 -mfloat-abi=soft ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7m-none-eabi' + + defines += ["STM32F405xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] if "input" in features_wanted: - sources += ["embed/trezorhal/button.c"] + sources += ["embed/trezorhal/stm32f4/button.c"] features_available.append("button") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + env.get("ENV")["TREZOR_BOARD"] = board return features_available diff --git a/core/site_scons/boards/trezor_r_v10.py b/core/site_scons/boards/trezor_r_v10.py index a5ec8c94aa..9d56ee868d 100644 --- a/core/site_scons/boards/trezor_r_v10.py +++ b/core/site_scons/boards/trezor_r_v10.py @@ -1,13 +1,15 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( - env: dict, - features_wanted: list[str], - defines: list[str | tuple[str, str]], - sources: list[str], + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] hw_model = get_hw_model_as_number("T2B1") @@ -15,23 +17,43 @@ def configure( board = "trezor_r_v10.h" display = "vg-2864ksweg01.c" + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F427xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] - sources += [f"embed/trezorhal/i2c.c"] + sources += [f"embed/trezorhal/stm32f4/i2c.c"] if "input" in features_wanted: - sources += ["embed/trezorhal/button.c"] + sources += ["embed/trezorhal/stm32f4/button.c"] features_available.append("button") if "sbu" in features_wanted: - sources += ["embed/trezorhal/sbu.c"] + sources += ["embed/trezorhal/stm32f4/sbu.c"] features_available.append("sbu") if "consumption_mask" in features_wanted: - sources += ["embed/trezorhal/consumption_mask.c"] + sources += ["embed/trezorhal/stm32f4/consumption_mask.c"] + sources += ["vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"] + sources += ["embed/trezorhal/stm32f4/dma.c"] + + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") env.get("ENV")["TREZOR_BOARD"] = board diff --git a/core/site_scons/boards/trezor_r_v3.py b/core/site_scons/boards/trezor_r_v3.py index 57495effe9..10c86a420e 100644 --- a/core/site_scons/boards/trezor_r_v3.py +++ b/core/site_scons/boards/trezor_r_v3.py @@ -1,13 +1,15 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( - env: dict, - features_wanted: list[str], - defines: list[str | tuple[str, str]], - sources: list[str], + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] hw_model = get_hw_model_as_number("T2B1") @@ -15,23 +17,41 @@ def configure( board = "trezor_r_v3.h" display = "ug-2828tswig01.c" + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F427xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] if "input" in features_wanted: - sources += ["embed/trezorhal/button.c"] + sources += ["embed/trezorhal/stm32f4/button.c"] features_available.append("button") if "rgb_led" in features_wanted: - sources += ["embed/trezorhal/rgb_led.c"] + sources += ["embed/trezorhal/stm32f4/rgb_led.c"] features_available.append("rgb_led") if "sbu" in features_wanted: - sources += ["embed/trezorhal/sbu.c"] + sources += ["embed/trezorhal/stm32f4/sbu.c"] features_available.append("sbu") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + env.get("ENV")["TREZOR_BOARD"] = board return features_available diff --git a/core/site_scons/boards/trezor_r_v4.py b/core/site_scons/boards/trezor_r_v4.py index 8d4151f1ee..b8c5c5674f 100644 --- a/core/site_scons/boards/trezor_r_v4.py +++ b/core/site_scons/boards/trezor_r_v4.py @@ -1,13 +1,15 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( - env: dict, - features_wanted: list[str], - defines: list[str | tuple[str, str]], - sources: list[str], + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] hw_model = get_hw_model_as_number("T2B1") @@ -15,19 +17,37 @@ def configure( board = "trezor_r_v4.h" display = "vg-2864ksweg01.c" + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F427xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] if "input" in features_wanted: - sources += ["embed/trezorhal/button.c"] + sources += ["embed/trezorhal/stm32f4/button.c"] features_available.append("button") if "sbu" in features_wanted: - sources += ["embed/trezorhal/sbu.c"] + sources += ["embed/trezorhal/stm32f4/sbu.c"] features_available.append("sbu") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + env.get("ENV")["TREZOR_BOARD"] = board return features_available diff --git a/core/site_scons/boards/trezor_r_v6.py b/core/site_scons/boards/trezor_r_v6.py index b52129ba83..58b403e5cc 100644 --- a/core/site_scons/boards/trezor_r_v6.py +++ b/core/site_scons/boards/trezor_r_v6.py @@ -1,13 +1,15 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( - env: dict, - features_wanted: list[str], - defines: list[str | tuple[str, str]], - sources: list[str], + env: dict, + features_wanted: list[str], + defines: list[str | tuple[str, str]], + sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] hw_model = get_hw_model_as_number("T2B1") @@ -15,19 +17,37 @@ def configure( board = "trezor_r_v6.h" display = "vg-2864ksweg01.c" + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F427xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] if "input" in features_wanted: - sources += ["embed/trezorhal/button.c"] + sources += ["embed/trezorhal/stm32f4/button.c"] features_available.append("button") if "sbu" in features_wanted: - sources += ["embed/trezorhal/sbu.c"] + sources += ["embed/trezorhal/stm32f4/sbu.c"] features_available.append("sbu") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + env.get("ENV")["TREZOR_BOARD"] = board return features_available diff --git a/core/site_scons/boards/trezor_t.py b/core/site_scons/boards/trezor_t.py index 07cfcd9870..256d72786f 100644 --- a/core/site_scons/boards/trezor_t.py +++ b/core/site_scons/boards/trezor_t.py @@ -1,6 +1,7 @@ from __future__ import annotations from . import get_hw_model_as_number +from .stm32f4_common import stm32f4_common_files def configure( @@ -8,6 +9,7 @@ def configure( features_wanted: list[str], defines: list[str | tuple[str, str]], sources: list[str], + paths: list[str], ) -> list[str]: features_available: list[str] = [] board = "trezor_t.h" @@ -16,37 +18,57 @@ def configure( hw_revision = 0 features_available.append("disp_i8080_8bit_dw") + stm32f4_common_files(defines, sources, paths) + + env.get("ENV")['CPU_ASFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' + env.get("ENV")['CPU_CCFLAGS'] = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 ' + env.get("ENV")['RUST_TARGET'] = 'thumbv7em-none-eabihf' + + defines += ["STM32F427xx"] defines += [f'TREZOR_BOARD=\\"boards/{board}\\"'] defines += [f"HW_MODEL={hw_model}"] defines += [f"HW_REVISION={hw_revision}"] - sources += [f"embed/trezorhal/displays/{display}"] - sources += [f"embed/trezorhal/backlight_pwm.c"] - sources += [f'embed/trezorhal/displays/panels/tf15411a.c', ] - sources += [f'embed/trezorhal/displays/panels/154a.c', ] - sources += [f'embed/trezorhal/displays/panels/lx154a2411.c', ] - sources += [f'embed/trezorhal/displays/panels/lx154a2422.c', ] + sources += [f"embed/trezorhal/stm32f4/displays/{display}"] + sources += [f"embed/trezorhal/stm32f4/backlight_pwm.c"] + sources += [f'embed/trezorhal/stm32f4/displays/panels/tf15411a.c', ] + sources += [f'embed/trezorhal/stm32f4/displays/panels/154a.c', ] + sources += [f'embed/trezorhal/stm32f4/displays/panels/lx154a2411.c', ] + sources += [f'embed/trezorhal/stm32f4/displays/panels/lx154a2422.c', ] features_available.append("backlight") if "input" in features_wanted: - sources += ["embed/trezorhal/i2c.c"] - sources += ["embed/trezorhal/touch/touch.c"] - sources += ["embed/trezorhal/touch/ft6x36.c"] + sources += ["embed/trezorhal/stm32f4/i2c.c"] + sources += ["embed/trezorhal/stm32f4/touch/ft6x36.c"] + sources += ["embed/lib/touch.c"] features_available.append("touch") if "sd_card" in features_wanted: - sources += ["embed/trezorhal/sdcard.c"] + sources += ["embed/trezorhal/stm32f4/sdcard.c"] sources += ["embed/extmod/modtrezorio/ff.c"] sources += ["embed/extmod/modtrezorio/ffunicode.c"] + sources += ["vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"] + sources += ["embed/trezorhal/stm32f4/dma.c"] features_available.append("sd_card") if "sbu" in features_wanted: - sources += ["embed/trezorhal/sbu.c"] + sources += ["embed/trezorhal/stm32f4/sbu.c"] features_available.append("sbu") + if "usb" in features_wanted: + sources += [ + 'embed/trezorhal/stm32f4/usb.c', + 'embed/trezorhal/stm32f4/usbd_conf.c', + 'embed/trezorhal/stm32f4/usbd_core.c', + 'embed/trezorhal/stm32f4/usbd_ctlreq.c', + 'embed/trezorhal/stm32f4/usbd_ioreq.c', + 'vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c', + ] + features_available.append("usb") + if "dma2d" in features_wanted: defines += ["USE_DMA2D"] - sources += ["embed/trezorhal/dma2d.c"] + sources += ["embed/trezorhal/stm32f4/dma2d.c"] sources += [ "vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c" ] diff --git a/core/site_scons/tools.py b/core/site_scons/tools.py index 40672bf253..f7c8505584 100644 --- a/core/site_scons/tools.py +++ b/core/site_scons/tools.py @@ -30,24 +30,25 @@ def configure_board( env: dict, # type: ignore defines: list[str | tuple[str, str]], sources: list[str], + paths: list[str], ): model_r_version = 10 if model in ("1",): - return trezor_1.configure(env, features_wanted, defines, sources) + return trezor_1.configure(env, features_wanted, defines, sources, paths) elif model in ("T",): - return trezor_t.configure(env, features_wanted, defines, sources) + return trezor_t.configure(env, features_wanted, defines, sources, paths) elif model in ("R",): if model_r_version == 3: - return trezor_r_v3.configure(env, features_wanted, defines, sources) + return trezor_r_v3.configure(env, features_wanted, defines, sources, paths) elif model_r_version == 4: - return trezor_r_v4.configure(env, features_wanted, defines, sources) + return trezor_r_v4.configure(env, features_wanted, defines, sources, paths) elif model_r_version == 6: - return trezor_r_v6.configure(env, features_wanted, defines, sources) + return trezor_r_v6.configure(env, features_wanted, defines, sources, paths) elif model_r_version == 10: - return trezor_r_v10.configure(env, features_wanted, defines, sources) + return trezor_r_v10.configure(env, features_wanted, defines, sources, paths) elif model in ('DISC1',): - return discovery.configure(env, features_wanted, defines, sources) + return discovery.configure(env, features_wanted, defines, sources, paths) else: raise Exception("Unknown model")