From d71d9e9c343ad04a7f28d6b02f8d3f8945af30d6 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Mon, 7 Oct 2024 15:16:11 +0200 Subject: [PATCH] feat(core): add T3W1 emulator build [no changelog] --- core/SConscript.bootloader_emu | 1 - core/SConscript.unix | 1 - core/embed/models/T3W1/boards/t3w1-unix.h | 26 +++++++++ core/embed/trezorhal/unix/display_driver.c | 2 + core/embed/trezorhal/unix/flash.c | 8 +-- core/embed/trezorhal/unix/optiga.c | 3 ++ core/site_scons/models/T3W1/__init__.py | 3 +- core/site_scons/models/T3W1/emulator.py | 61 ++++++++++++++++++++++ 8 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 core/embed/models/T3W1/boards/t3w1-unix.h create mode 100644 core/site_scons/models/T3W1/emulator.py diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index f2c3d770fd..d8ace1f240 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -72,7 +72,6 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/extmod/modtrezorcrypto/rand.c', - 'embed/lib/buffers.c', 'embed/lib/colors.c', 'embed/lib/display_utils.c', 'embed/lib/error_handling.c', diff --git a/core/SConscript.unix b/core/SConscript.unix index e7f1bfe5f4..aa46f36af6 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -204,7 +204,6 @@ CPPPATH_MOD += [ ] SOURCE_MOD += [ 'embed/extmod/modtrezorui/modtrezorui.c', - 'embed/lib/buffers.c', 'embed/lib/colors.c', 'embed/lib/display_utils.c', 'embed/lib/error_handling.c', diff --git a/core/embed/models/T3W1/boards/t3w1-unix.h b/core/embed/models/T3W1/boards/t3w1-unix.h new file mode 100644 index 0000000000..4ba457ffaf --- /dev/null +++ b/core/embed/models/T3W1/boards/t3w1-unix.h @@ -0,0 +1,26 @@ +#ifndef BOARDS_T3W1_UNIX_H +#define BOARDS_T3W1_UNIX_H + +#define USE_TOUCH 1 +#define USE_SBU 1 +#define USE_RGB_COLORS 1 +#define USE_BACKLIGHT 1 +#define USE_OPTIGA 1 + +#define MAX_DISPLAY_RESX 380 +#define MAX_DISPLAY_RESY 520 +#define DISPLAY_RESX 380 +#define DISPLAY_RESY 520 +#define TREZOR_FONT_BPP 4 + +#define WINDOW_WIDTH 400 +#define WINDOW_HEIGHT 600 +#define TOUCH_OFFSET_X 80 +#define TOUCH_OFFSET_Y 102 + +#define ORIENTATION_NS 1 + +// #define BACKGROUND_FILE "T3W1/background_T3W1.h" +// #define BACKGROUND_NAME background_T3W1_jpg + +#endif // BOARDS_T3W1_UNIX_H diff --git a/core/embed/trezorhal/unix/display_driver.c b/core/embed/trezorhal/unix/display_driver.c index d4b7939ac2..5a23218264 100644 --- a/core/embed/trezorhal/unix/display_driver.c +++ b/core/embed/trezorhal/unix/display_driver.c @@ -122,12 +122,14 @@ void display_init(display_content_mode_t mode) { SDL_PumpEvents(); SDL_SetWindowSize(drv->window, WINDOW_WIDTH, WINDOW_HEIGHT); #endif +#ifdef BACKGROUND_FILE #include BACKGROUND_FILE #define CONCAT_LEN_HELPER(name) name##_len #define CONCAT_LEN(name) CONCAT_LEN_HELPER(name) drv->background = IMG_LoadTexture_RW( drv->renderer, SDL_RWFromMem(BACKGROUND_NAME, CONCAT_LEN(BACKGROUND_NAME)), 0); +#endif if (drv->background) { SDL_SetTextureBlendMode(drv->background, SDL_BLENDMODE_NONE); sdl_touch_offset_x = TOUCH_OFFSET_X; diff --git a/core/embed/trezorhal/unix/flash.c b/core/embed/trezorhal/unix/flash.c index 60f1907f90..acd967aba3 100644 --- a/core/embed/trezorhal/unix/flash.c +++ b/core/embed/trezorhal/unix/flash.c @@ -35,16 +35,16 @@ #define FLASH_FILE profile_flash_path() #endif -#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R +#if defined STM32F427xx || defined STM32F429xx #define FLASH_SECTOR_COUNT 24 -#elif defined TREZOR_MODEL_T3T1 || defined TREZOR_MODEL_T3B1 +#elif defined STM32U585xx || defined STM32U5A9xx #define FLASH_SECTOR_COUNT 256 #else #error Unknown MCU #endif static uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = { -#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R +#if defined STM32F427xx || defined STM32F429xx [0] = 0x08000000, // - 0x08003FFF | 16 KiB [1] = 0x08004000, // - 0x08007FFF | 16 KiB [2] = 0x08008000, // - 0x0800BFFF | 16 KiB @@ -70,7 +70,7 @@ static uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = { [22] = 0x081C0000, // - 0x081DFFFF | 128 KiB [23] = 0x081E0000, // - 0x081FFFFF | 128 KiB [24] = 0x08200000, // last element - not a valid sector -#elif defined TREZOR_MODEL_T3T1 || defined TREZOR_MODEL_T3B1 +#elif defined STM32U585xx || defined STM32U5A9xx [0] = 0x08000000, // - 0x08001FFF | 8 KiB // rest is initialized in flash_init #else diff --git a/core/embed/trezorhal/unix/optiga.c b/core/embed/trezorhal/unix/optiga.c index 44a2b97cf4..8a5fe94c67 100644 --- a/core/embed/trezorhal/unix/optiga.c +++ b/core/embed/trezorhal/unix/optiga.c @@ -34,6 +34,9 @@ #elif defined(TREZOR_MODEL_T3B1) #include "certs/T2B1.h" #define DEVICE_CERT_CHAIN T2B1_der +#elif defined(TREZOR_MODEL_T3W1) +#include "certs/T2B1.h" +#define DEVICE_CERT_CHAIN T2B1_der #else #error "Cert chain for specified model is not available." #endif diff --git a/core/site_scons/models/T3W1/__init__.py b/core/site_scons/models/T3W1/__init__.py index 6874ed2f0e..45f16a8c64 100644 --- a/core/site_scons/models/T3W1/__init__.py +++ b/core/site_scons/models/T3W1/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional -from . import trezor_t3w1_d1 +from . import emulator, trezor_t3w1_d1 def configure_board( @@ -18,6 +18,7 @@ def configure_board( # Mapping of revisions to their respective configurations revision_map = { + "emulator": emulator, "d1": trezor_t3w1_d1, } diff --git a/core/site_scons/models/T3W1/emulator.py b/core/site_scons/models/T3W1/emulator.py new file mode 100644 index 0000000000..9f1aee1cc1 --- /dev/null +++ b/core/site_scons/models/T3W1/emulator.py @@ -0,0 +1,61 @@ +from __future__ import annotations + +from .. import get_hw_model_as_number + + +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 = "T3W1/boards/t3w1-unix.h" + hw_model = get_hw_model_as_number("T3W1") + hw_revision = 0 + mcu = "STM32F427xx" + + defines += ["XFRAMEBUFFER", "DISPLAY_RGB585"] + features_available.append("xframebuffer") + features_available.append("display_rgb565") + + defines += [mcu] + defines += [f'TREZOR_BOARD=\\"{board}\\"'] + defines += [f"HW_MODEL={hw_model}"] + defines += [f"HW_REVISION={hw_revision}"] + defines += [f"MCU_TYPE={mcu}"] + # todo change to blockwise flash when implemented in unix + defines += ["FLASH_BIT_ACCESS=1"] + defines += ["FLASH_BLOCK_WORDS=1"] + + if "dma2d" in features_wanted: + features_available.append("dma2d") + if "new_rendering" in features_wanted: + sources += [ + "embed/trezorhal/unix/dma2d_bitblt.c", + ] + else: + sources += ["embed/lib/dma2d_emul.c"] + defines += ["USE_DMA2D"] + + if "sbu" in features_wanted: + sources += ["embed/trezorhal/unix/sbu.c"] + + if "optiga_hal" in features_wanted: + sources += ["embed/trezorhal/unix/optiga_hal.c"] + + if "optiga" in features_wanted: + sources += ["embed/trezorhal/unix/optiga.c"] + features_available.append("optiga") + + if "input" in features_wanted: + sources += ["embed/trezorhal/unix/touch.c"] + features_available.append("touch") + + features_available.append("backlight") + + sources += ["embed/trezorhal/stm32f4/layout.c"] + + return features_available