1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 13:52:35 +00:00

feat(core): add emulator support for T3W1

[no changelog]

Co-authored-by: Martin Milata <martin@martinmilata.cz>
This commit is contained in:
tychovrahe 2023-06-21 15:27:19 +02:00 committed by Martin Milata
parent 37fde954b4
commit 31bf565730
16 changed files with 284 additions and 20 deletions

View File

@ -36,7 +36,7 @@ if TREZOR_MODEL in ('R', ):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'

View File

@ -34,7 +34,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD=None
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_Roboto_Regular_20'
FONT_DEMIBOLD=None
FONT_BOLD=None

View File

@ -33,7 +33,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'
@ -164,7 +164,7 @@ env.Replace(
env.Replace(
TREZOR_MODEL=TREZOR_MODEL, )
if TREZOR_MODEL in ('T', 'R'):
if TREZOR_MODEL in ('T', 'R', 'T3W1'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'

View File

@ -41,7 +41,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
@ -386,7 +386,7 @@ env = Environment(ENV=os.environ, CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODU
FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
if TREZOR_MODEL in ('T', 'DISC1'):
if TREZOR_MODEL in ('T', 'T3W1', 'DISC1'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
@ -673,6 +673,7 @@ if FROZEN:
bitcoin_only=BITCOIN_ONLY,
backlight='backlight' in FEATURES_AVAILABLE,
optiga='optiga' in FEATURES_AVAILABLE,
ble='ble' in FEATURES_AVAILABLE,
ui_layout=UI_LAYOUT,
)
@ -831,7 +832,7 @@ BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
if TREZOR_MODEL in ('T', 'R', 'DISC1'):
if TREZOR_MODEL in ('T', 'R', 'T3W1', 'DISC1'):
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',

View File

@ -38,7 +38,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO=None
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL=None
FONT_DEMIBOLD=None
FONT_BOLD='Font_Roboto_Bold_20'

View File

@ -33,7 +33,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO=None
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL=None
FONT_DEMIBOLD=None
FONT_BOLD='Font_Roboto_Bold_20'

View File

@ -7,7 +7,7 @@ import tools
BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
EVERYTHING = BITCOIN_ONLY != '1'
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
DMA2D = TREZOR_MODEL in ('T', )
DMA2D = TREZOR_MODEL in ('T', 'T3W1')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
if TREZOR_MODEL in ('DISC1', ):
@ -42,7 +42,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'T3W1'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
@ -176,7 +176,7 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]:
SOURCE_MOD += [
'embed/extmod/modtrezorio/modtrezorio.c',
]
if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
SOURCE_MOD += [
'embed/extmod/modtrezorio/ff.c',
'embed/extmod/modtrezorio/ffunicode.c',
@ -212,6 +212,10 @@ elif TREZOR_MODEL in ('R', ):
SOURCE_MOD += [
'embed/models/model_T2B1_layout.c',
]
elif TREZOR_MODEL in ('T3W1', ):
SOURCE_MOD += [
'embed/models/model_T3W1_layout.c',
]
@ -386,7 +390,8 @@ SOURCE_UNIX = [
'vendor/micropython/ports/unix/input.c',
'vendor/micropython/ports/unix/unix_mphal.c',
]
if TREZOR_MODEL in ('T', 'R'):
if TREZOR_MODEL in ('T', 'R', 'T3W1'):
SOURCE_UNIX += [
'embed/trezorhal/unix/sbu.c',
]
@ -396,6 +401,15 @@ if TREZOR_MODEL == 'R':
'embed/trezorhal/unix/optiga.c',
]
if TREZOR_MODEL == 'T3W1':
SOURCE_UNIX += [
'embed/trezorhal/unix/ble.c',
'embed/lib/ble/state.c',
'embed/lib/ble/fwu.c',
'embed/lib/ble/messages.c',
'embed/lib/ble/dfu.c',
]
if DMA2D:
CPPDEFINES_MOD += [
'USE_DMA2D',
@ -423,7 +437,7 @@ else:
env = Environment(ENV=os.environ, CFLAGS='%s -DPYOPT=%s -DBITCOIN_ONLY=%s %s' % (ARGUMENTS.get('CFLAGS', ''), PYOPT, BITCOIN_ONLY, STATIC))
if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
@ -432,7 +446,7 @@ elif TREZOR_MODEL in ('1', 'R'):
else:
raise ValueError('Unknown Trezor model')
if TREZOR_MODEL in ('T',):
if TREZOR_MODEL in ('T', 'T3W1'):
SDCARD = True
SOURCE_UNIX += [
'embed/trezorhal/unix/sdcard.c',
@ -488,7 +502,7 @@ if ARGUMENTS.get('TREZOR_MEMPERF', '0') == '1':
env.Replace(
TREZOR_MODEL=TREZOR_MODEL, )
if TREZOR_MODEL in ('T', 'R'):
if TREZOR_MODEL in ('T', 'R', 'T3W1'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'
@ -749,8 +763,9 @@ if FROZEN:
source=SOURCE_PY,
source_dir=SOURCE_PY_DIR,
bitcoin_only=BITCOIN_ONLY,
backlight=TREZOR_MODEL in ('T',),
backlight=TREZOR_MODEL in ('T','T3W1'),
optiga=TREZOR_MODEL in ('R',),
ble=TREZOR_MODEL in ('T3W1',),
ui_layout=UI_LAYOUT,
)
@ -799,6 +814,11 @@ def cargo_build():
if TREZOR_MODEL in ('T',):
features.append('touch')
features.append('sd_card')
if TREZOR_MODEL in ('T3W1',):
features.append('touch')
features.append('button')
features.append('sd_card')
features.append('ble')
if TREZOR_MODEL in ('R', '1'):
features.append('button')

View File

@ -9,6 +9,8 @@
#include "model_T2T1.h"
#elif defined TREZOR_MODEL_R
#include "model_T2B1.h"
#elif defined TREZOR_MODEL_T3W1
#include "model_T3W1.h"
#elif defined TREZOR_MODEL_DISC1
#include "model_D001.h"
#else

View File

@ -0,0 +1,30 @@
#ifndef MODELS_MODEL_T3W1_H_
#define MODELS_MODEL_T3W1_H_
#define MODEL_NAME "T3W1"
#define MODEL_FULL_NAME "Trezor T3W1"
#define MODEL_INTERNAL_NAME "T3W1"
#define MODEL_INTERNAL_NAME_TOKEN T3W1
#define MODEL_INTERNAL_NAME_QSTR MP_QSTR_T3W1
/*** Using DEV KEYS temporarily ***/
#define MODEL_BOARDLOADER_KEYS \
(const uint8_t *)"\xdb\x99\x5f\xe2\x51\x69\xd1\x41\xca\xb9\xbb\xba\x92\xba\xa0\x1f\x9f\x2e\x1e\xce\x7d\xf4\xcb\x2a\xc0\x51\x90\xf3\x7f\xcc\x1f\x9d", \
(const uint8_t *)"\x21\x52\xf8\xd1\x9b\x79\x1d\x24\x45\x32\x42\xe1\x5f\x2e\xab\x6c\xb7\xcf\xfa\x7b\x6a\x5e\xd3\x00\x97\x96\x0e\x06\x98\x81\xdb\x12", \
(const uint8_t *)"\x22\xfc\x29\x77\x92\xf0\xb6\xff\xc0\xbf\xcf\xdb\x7e\xdb\x0c\x0a\xa1\x4e\x02\x5a\x36\x5e\xc0\xe3\x42\xe8\x6e\x38\x29\xcb\x74\xb6",
#define MODEL_BOOTLOADER_KEYS \
(const uint8_t *)"\xd7\x59\x79\x3b\xbc\x13\xa2\x81\x9a\x82\x7c\x76\xad\xb6\xfb\xa8\xa4\x9a\xee\x00\x7f\x49\xf2\xd0\x99\x2d\x99\xb8\x25\xad\x2c\x48", \
(const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \
(const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48",
#define BOARDLOADER_START 0x08000000
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define IMAGE_CHUNK_SIZE (128 * 1024)
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024)
#endif

View File

@ -0,0 +1,82 @@
#include "flash.h"
#include "model.h"
const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
{
.num_subareas = 1,
.subarea[0] =
{
.first_sector = 4,
.num_sectors = 1,
},
},
{
.num_subareas = 1,
.subarea[0] =
{
.first_sector = 16,
.num_sectors = 1,
},
},
};
const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1,
.subarea[0] =
{
.first_sector = 0,
.num_sectors = 3,
},
};
const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1,
.subarea[0] =
{
.first_sector = 5,
.num_sectors = 1,
},
};
const flash_area_t FIRMWARE_AREA = {
.num_subareas = 2,
.subarea[0] =
{
.first_sector = 6,
.num_sectors = 6,
},
.subarea[1] =
{
.first_sector = 17,
.num_sectors = 7,
},
};
const flash_area_t WIPE_AREA = {
.num_subareas = 3,
.subarea[0] =
{
.first_sector = 4,
.num_sectors = 1,
},
.subarea[1] =
{
.first_sector = 6,
.num_sectors =
9, // sector 15 skipped due to bootloader MPU settings
},
.subarea[2] =
{
.first_sector = 16,
.num_sectors = 8,
},
};
const flash_area_t ALL_WIPE_AREA = {
.num_subareas = 1,
.subarea[0] =
{
.first_sector = 3,
.num_sectors = 21,
},
};

View File

@ -9,6 +9,15 @@
#define USE_BACKLIGHT 1
#endif
#ifdef TREZOR_MODEL_T3W1
#define USE_TOUCH 1
#define USE_SD_CARD 1
#define USE_SBU 1
#define USE_RGB_COLORS 1
#define USE_BACKLIGHT 1
#define USE_BLE 1
#endif
#ifdef TREZOR_MODEL_1
#define USE_BUTTON 1
#endif

View File

@ -64,6 +64,12 @@
#define TOUCH_OFFSET_X 32
#define TOUCH_OFFSET_Y 84
#elif defined TREZOR_MODEL_T3W1
#define WINDOW_WIDTH 400
#define WINDOW_HEIGHT 600
#define TOUCH_OFFSET_X 80
#define TOUCH_OFFSET_Y 110
#else
#error Unknown Trezor model
#endif
@ -286,7 +292,8 @@ int display_orientation(int degrees) {
if (degrees != DISPLAY_ORIENTATION) {
#if defined TREZOR_MODEL_T
if (degrees == 0 || degrees == 90 || degrees == 180 || degrees == 270) {
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
#elif defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R || \
defined TREZOR_MODEL_T3W1
if (degrees == 0 || degrees == 180) {
#else
#error Unknown Trezor model

View File

@ -3,6 +3,14 @@
#include <stdint.h>
#ifdef TREZOR_MODEL_T3W1
#define MAX_DISPLAY_RESX 240
#define MAX_DISPLAY_RESY 320
#define DISPLAY_RESX 240
#define DISPLAY_RESY 320
#define TREZOR_FONT_BPP 4
#endif
#ifdef TREZOR_MODEL_T
// ILI9341V, GC9307 and ST7789V drivers support 240px x 320px display resolution
#define MAX_DISPLAY_RESX 240

View File

@ -35,7 +35,8 @@
#define FLASH_FILE profile_flash_path()
#endif
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R || \
defined TREZOR_MODEL_T3W1
#define FLASH_SECTOR_COUNT 24
#elif defined TREZOR_MODEL_1
#define FLASH_SECTOR_COUNT 12
@ -56,7 +57,8 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[9] = 0x080A0000, // - 0x080BFFFF | 128 KiB
[10] = 0x080C0000, // - 0x080DFFFF | 128 KiB
[11] = 0x080E0000, // - 0x080FFFFF | 128 KiB
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R || \
defined TREZOR_MODEL_T3W1
[12] = 0x08100000, // - 0x08103FFF | 16 KiB
[13] = 0x08104000, // - 0x08107FFF | 16 KiB
[14] = 0x08108000, // - 0x0810BFFF | 16 KiB

View File

@ -0,0 +1,98 @@
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],
paths: list[str],
) -> list[str]:
features_available: list[str] = []
board = "trezor_t3w1_d1.h"
display = "st7789v.c"
hw_model = get_hw_model_as_number("T3W1")
hw_revision = 0
features_available.append("disp_i8080_16bit_dw")
mcu = "STM32F427xx"
stm32f4_common_files(env, 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 += [mcu]
defines += [f'TREZOR_BOARD=\\"boards/{board}\\"']
defines += [f"HW_MODEL={hw_model}"]
defines += [f"HW_REVISION={hw_revision}"]
sources += [
"embed/models/model_T3W1_layout.c",
]
sources += [f"embed/trezorhal/stm32f4/displays/{display}"]
sources += ["embed/trezorhal/stm32f4/backlight_pwm.c"]
sources += ["embed/trezorhal/stm32f4/displays/panels/lhs200kb-if21.c"]
features_available.append("backlight")
if "input" in features_wanted:
sources += ["embed/lib/touch.c"]
sources += ["embed/trezorhal/stm32f4/i2c.c"]
sources += ["embed/trezorhal/stm32f4/touch/ft6x36.c"]
features_available.append("touch")
sources += ["embed/trezorhal/stm32f4/button.c"]
features_available.append("button")
if "sd_card" in features_wanted:
sources += ["embed/trezorhal/stm32f4/sdcard.c"]
sources += ["embed/extmod/modtrezorio/ff.c"]
sources += ["embed/extmod/modtrezorio/ffunicode.c"]
features_available.append("sd_card")
if "ble" in features_wanted:
sources += ["embed/trezorhal/stm32f4/ble_hal.c"]
sources += ["embed/lib/ble/dfu.c"]
sources += ["embed/lib/ble/fwu.c"]
sources += ["embed/lib/ble/state.c"]
sources += ["embed/lib/ble/messages.c"]
features_available.append("ble")
if "ble" in features_wanted or "sd_card" in features_wanted:
sources += [
"vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"
]
if "sbu" in features_wanted:
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/stm32f4/dma2d.c"]
sources += [
"vendor/micropython/lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c",
]
features_available.append("dma2d")
env.get("ENV")["TREZOR_BOARD"] = board
env.get("ENV")["MCU_TYPE"] = mcu
return features_available

View File

@ -12,6 +12,7 @@ from boards import (
trezor_r_v6,
trezor_r_v10,
trezor_t,
trezor_t3w1_d1,
)
HERE = Path(__file__).parent.resolve()
@ -57,6 +58,8 @@ def configure_board(
elif model_r_version == 10:
return trezor_r_v10.configure(env, features_wanted, defines, sources, paths)
raise Exception("Unknown model_r_version")
elif model in ("T3W1",):
return trezor_t3w1_d1.configure(env, features_wanted, defines, sources, paths)
elif model in ("DISC1",):
return discovery.configure(env, features_wanted, defines, sources, paths)
raise Exception("Unknown model")
@ -69,6 +72,8 @@ def get_model_identifier(model: str) -> str:
return "T2T1"
elif model == "R":
return "T2B1"
elif model == "T3W1":
return "T3W1"
elif model == "DISC1":
return "D001"
else: