Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic support for u5 #3370

Merged
merged 32 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0e2b9bd
feat(core): add STM32CubeU5 submodule
cepetr Oct 4, 2023
cf41abb
feat(core): add basic support for STM32U5
TychoVrahe Jun 28, 2023
e468334
feat(core): add support for STM32U5A9J-DK board
TychoVrahe Jun 28, 2023
f980b9d
chore(core): refactor boot_args
cepetr Oct 31, 2023
e85c8f5
chore(core): refactor mpu initialization
cepetr Nov 6, 2023
134647d
chore(core): refactor trustzone initialization
cepetr Nov 13, 2023
8a5c90f
chore(core): use cortex-m33 stack protection
cepetr Nov 14, 2023
60e2295
chore(core, legacy, storage): refactor flash drivers
cepetr Nov 1, 2023
69b0260
feat(core): add support for STM32U585
TychoVrahe Nov 13, 2023
9aeccc1
fix(core): fix bootloader update on STM32U5
TychoVrahe Nov 16, 2023
8c73ca9
fix(core): fix OTP programming on U5
TychoVrahe Nov 23, 2023
af8d8f7
chore(core): unify i2c instances numbering
TychoVrahe Nov 21, 2023
504186d
feat(core): add basic support for T3T1
TychoVrahe Aug 24, 2023
0c6cc59
feat(core): add haptic feedback
TychoVrahe Aug 24, 2023
b760364
feat(core): support optiga handling on U5
TychoVrahe Nov 23, 2023
e5996fb
fix(core): improve cmakelists generation for CMSE
TychoVrahe Nov 23, 2023
08ca673
feat(core): support SD card on STM32U5
TychoVrahe Nov 25, 2023
9987b12
chore(core): optimize flash usage - tamper on U5
TychoVrahe Nov 25, 2023
6a7dd01
chore(core): optimize flash usage - SD card on U5
TychoVrahe Nov 27, 2023
89e4413
chore(core): optimize flash usage - backlight pwm
TychoVrahe Nov 27, 2023
148ea21
fix(core): fix STM32F4 display base address
TychoVrahe Nov 27, 2023
5a8817b
chore(core): change STM32Cube submodule to separate hal driver and cm…
TychoVrahe Nov 29, 2023
271940e
perf(core): optimize boot speed on U5 by using has processor to calcu…
TychoVrahe Dec 15, 2023
b405a6b
perf(core): optimize boot speed by checking empty image area by words
TychoVrahe Dec 15, 2023
d9732eb
perf(core): optimize i2c initialization on U5 by statically defining …
TychoVrahe Dec 17, 2023
d438540
perf(core): optimize boot time by removing unnecessary touch initiali…
TychoVrahe Dec 17, 2023
bfd935d
chore(core): add makefile commands for erasing bootloader and firmwar…
TychoVrahe Jan 4, 2024
f8a3c06
feat(core): add haptic to prodtest
TychoVrahe Jan 10, 2024
ba606cb
feat(core): allow SD card hotswap based on production date for Model T
TychoVrahe Jan 12, 2024
34ef0ec
fix(core): fix st7789v driver compilation for other than T models
TychoVrahe Feb 20, 2024
78f546c
refactor(core): make translations blob handling HW agnostic
TychoVrahe Feb 20, 2024
355caba
feat(core): add translations support for U5 models
TychoVrahe Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@
[submodule "vendor/fido2-tests"]
path = vendor/fido2-tests
url = https://github.com/trezor/fido2-tests.git
[submodule "vendor/cmsis_device_u5"]
path = vendor/cmsis_device_u5
url = https://github.com/STMicroelectronics/cmsis_device_u5.git
[submodule "vendor/cmsis_5"]
path = vendor/cmsis_5
url = https://github.com/ARM-software/CMSIS_5.git

[submodule "vendor/stm32u5xx_hal_driver"]
path = vendor/stm32u5xx_hal_driver
url = https://github.com/trezor/stm32u5xx_hal_driver.git
1 change: 1 addition & 0 deletions core/.changelog.d/3370.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added basic support for STM32U5
1 change: 1 addition & 0 deletions core/.changelog.d/3940.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[T2T1] Allow SD card hotswap based on production date
109 changes: 98 additions & 11 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,91 @@ TEST_LANG ?= "en"
OPENOCD_INTERFACE ?= stlink
# OpenOCD transport default. Alternative: jtag
OPENOCD_TRANSPORT ?= hla_swd
OPENOCD = openocd -f interface/$(OPENOCD_INTERFACE).cfg -c "transport select $(OPENOCD_TRANSPORT)" -f target/stm32f4x.cfg
OPENOCD_T1 = openocd -f interface/$(OPENOCD_INTERFACE).cfg -c "transport select $(OPENOCD_TRANSPORT)" -f target/stm32f2x.cfg

ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T R DISC1))
OPENOCD_TARGET = target/stm32f4x.cfg
BOARDLOADER_START = 0x08000000
BOARDLOADER_END = 0x0800C000
BOOTLOADER_START = 0x08020000
FIRMWARE_P1_START = 0x08040000
FIRMWARE_START = 0x08040000
FIRMWARE_P2_START = 0x08120000
PRODTEST_START = 0x08040000
FIRMWARE_T1_START = 0x08010000

STORAGE_1_OFFSET = 0x10000
STORAGE_2_OFFSET = 0x110000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_P1_MAXSIZE = 786432
FIRMWARE_P2_MAXSIZE = 917504
FIRMWARE_MAXSIZE = 1703936
BOARDLOADER_SECTOR_START = 0
BOARDLOADER_SECTOR_END = 3
BOOTLOADER_SECTOR_START = 5
BOOTLOADER_SECTOR_END = 5
FIRMWARE_SECTOR_START = 6
FIRMWARE_SECTOR_END = 11
FIRMWARE_P2_SECTOR_START = 17
FIRMWARE_P2_SECTOR_END = 23
STORAGE_1_SECTOR_START = 4
STORAGE_1_SECTOR_END = 4
STORAGE_2_SECTOR_START = 16
STORAGE_2_SECTOR_END = 16

else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3T1))
OPENOCD_TARGET = target/stm32u5x.cfg
BOARDLOADER_START = 0x0C004000
BOARDLOADER_END = 0x0C010000
BOOTLOADER_START = 0x0C010000
FIRMWARE_START = 0x0C050000
PRODTEST_START = 0x0C050000
STORAGE_1_OFFSET = 0x30000
STORAGE_2_OFFSET = 0x50000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_MAXSIZE = 1703936
BOARDLOADER_SECTOR_START = 0x2
BOARDLOADER_SECTOR_END = 0x7
BOOTLOADER_SECTOR_START = 0x8
BOOTLOADER_SECTOR_END = 0x17
FIRMWARE_SECTOR_START = 0x28
FIRMWARE_SECTOR_END = 0xF8
STORAGE_1_SECTOR_START = 0x18
STORAGE_1_SECTOR_END = 0x1F
STORAGE_2_SECTOR_START = 0x20
STORAGE_2_SECTOR_END = 0x27
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC2))
OPENOCD_TARGET = target/stm32u5x.cfg
BOARDLOADER_START = 0x0C004000
BOARDLOADER_END = 0x0C010000
BOOTLOADER_START = 0x0C010000
FIRMWARE_START = 0x0C050000
PRODTEST_START = 0x0C050000
STORAGE_1_OFFSET = 0x30000
STORAGE_2_OFFSET = 0x50000
STORAGE_SIZE = 0x10000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_MAXSIZE = 3735552
BOARDLOADER_SECTOR_START = 0x2
BOARDLOADER_SECTOR_END = 0x7
BOOTLOADER_SECTOR_START = 0x8
BOOTLOADER_SECTOR_END = 0x17
FIRMWARE_SECTOR_START = 0x28
FIRMWARE_SECTOR_END = 0x1F8
STORAGE_1_SECTOR_START = 0x18
STORAGE_1_SECTOR_END = 0x1F
STORAGE_2_SECTOR_START = 0x20
STORAGE_2_SECTOR_END = 0x27
else ifeq ($(TREZOR_MODEL), 1)
OPENOCD_TARGET = target/stm32f2x.cfg
FIRMWARE_START = 0x08010000
else
$(error Unknown TREZOR_MODEL: $(TREZOR_MODEL))
endif


OPENOCD = openocd -f interface/$(OPENOCD_INTERFACE).cfg -c "transport select $(OPENOCD_TRANSPORT)" -f $(OPENOCD_TARGET)

CFLAGS += -DSCM_REVISION='\"$(shell git rev-parse HEAD | sed 's:\(..\):\\x\1:g')\"'

Expand Down Expand Up @@ -289,22 +359,35 @@ flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenO
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(PRODTEST_START); exit"

flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_P1_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
ifdef FIRMWARE_P2_START
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"

flash_firmware_t1: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash T1 core port on T1 using OpenOCD
$(OPENOCD_T1) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_T1_START); exit"
else
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
endif

flash_combine: $(PRODTEST_BUILD_DIR)/combined.bin ## flash combined using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(BOARDLOADER_START); exit"

flash_erase: ## erase all sectors in flash bank 0
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 0 last; flash erase_check 0; exit"

flash_erase_bootloader: ## erase bootloader
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(BOOTLOADER_SECTOR_START) $(BOOTLOADER_SECTOR_END); exit"

flash_erase_firmware: ## erase bootloader
ifdef FIRMWARE_P2_START
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(FIRMWARE_SECTOR_START) $(FIRMWARE_SECTOR_END); flash erase_sector 0 $(FIRMWARE_P2_SECTOR_START) $(FIRMWARE_P2_SECTOR_END); exit"

else
$(OPENOCD) -c "init; reset halt; flash info 0; flash erase_sector 0 $(FIRMWARE_SECTOR_START) $(FIRMWARE_SECTOR_END); exit"
endif

flash_read_storage: ## read storage sectors from flash
$(OPENOCD) -c "init; flash read_bank 0 storage1.data 0x10000 65536; flash read_bank 0 storage2.data 0x110000 65536; exit"
$(OPENOCD) -c "init; reset halt; flash read_bank 0 storage1.data $(STORAGE_1_OFFSET) $(STORAGE_SIZE); flash read_bank 0 storage2.data $(STORAGE_2_OFFSET) $(STORAGE_SIZE); exit"

flash_erase_storage: ## erase storage sectors from flash
$(OPENOCD) -c "init; flash erase_sector 0 4 4; flash erase_sector 0 16 16; exit"
$(OPENOCD) -c "init; reset halt; flash erase_sector 0 $(STORAGE_1_SECTOR_START) $(STORAGE_1_SECTOR_END); flash erase_sector 0 $(STORAGE_2_SECTOR_START) $(STORAGE_2_SECTOR_END); exit"

flash_bootloader_jlink: $(BOOTLOADER_BUILD_DIR)/bootloader.bin ## flash bootloader using JLink
JLinkExe -nogui 1 -commanderscript embed/bootloader/bootloader_flash.jlink
Expand Down Expand Up @@ -367,7 +450,11 @@ combine: ## combine boardloader + bootloader + prodtest into one combined image
$(BOARDLOADER_BUILD_DIR)/boardloader.bin \
$(BOOTLOADER_BUILD_DIR)/bootloader.bin \
$(PRODTEST_BUILD_DIR)/prodtest.bin \
$(PRODTEST_BUILD_DIR)/combined.bin
$(PRODTEST_BUILD_DIR)/combined.bin \
$(BOARDLOADER_START) \
$(BOARDLOADER_END) \
$(BOOTLOADER_START) \
$(PRODTEST_START)

upload: ## upload firmware using trezorctl
trezorctl firmware_update -s -f $(FIRMWARE_BUILD_DIR)/firmware.bin
Expand Down
25 changes: 16 additions & 9 deletions core/SConscript.boardloader
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/sha2.c',
'vendor/trezor-storage/flash_area.c',
]

# modtrezorui
Expand All @@ -65,18 +66,24 @@ SOURCE_MOD += [
'embed/lib/image.c',
'embed/lib/mini_printf.c',
'embed/lib/terminal.c',
'vendor/trezor-storage/flash_common.c',

]

env = Environment(ENV=os.environ,
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
CONSTRAINTS=["limited_util_s"],
CPPDEFINES_IMPLICIT=[]
)

FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)

FILE_SUFFIX= env.get('ENV')['SUFFIX']
LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT']

SOURCE_BOARDLOADER = [
'embed/boardloader/startup.s',
f"embed/boardloader/startup_{FILE_SUFFIX}.s",
'embed/boardloader/main.c',
]

env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')), CONSTRAINTS=["limited_util_s"])

FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)

env.Replace(
CP='cp',
Expand Down Expand Up @@ -104,7 +111,7 @@ env.Replace(
'-fstack-protector-all '
+ 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',
LINKFLAGS=f"-T embed/boardloader/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/boardloader/boardloader.map -Wl,--warn-common -Wl,--print-memory-usage",
CPPPATH=[
'embed/boardloader',
'embed/lib',
Expand All @@ -124,7 +131,7 @@ env.Replace(

env.Replace(
ALLSOURCES=SOURCE_MOD + SOURCE_BOARDLOADER + SOURCE_HAL,
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES']))
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT']))

cmake_gen = env.Command(
target='CMakeLists.txt',
Expand Down Expand Up @@ -161,7 +168,7 @@ program_bin = env.Command(
target='boardloader.bin',
source=program_elf,
action=[
'$OBJCOPY -O binary $SOURCE $TARGET',
'$OBJCOPY -O binary -j .vector_table -j .text -j .data -j .rodata -j .capabilities -j .sensitive $SOURCE $TARGET',
'$CP $TARGET ' + BINARY_NAME,
],
)
43 changes: 25 additions & 18 deletions core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ 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', 'T3T1', 'DISC1', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_DEMIBOLD='Font_TTHoves_Regular_21'
FONT_BOLD='Font_TTHoves_Bold_17'
FONT_MONO=None
FONT_MONO='Font_TTHoves_Regular_21'
FONT_BIG=None

# modtrezorcrypto
Expand Down Expand Up @@ -71,6 +71,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/rand.c',
'vendor/trezor-crypto/sha2.c',
'vendor/trezor-storage/flash_area.c',
]

# modtrezorui
Expand All @@ -93,7 +94,6 @@ SOURCE_MOD += [
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',
'vendor/trezor-storage/flash_common.c',
]

SOURCE_NANOPB = [
Expand All @@ -102,26 +102,34 @@ SOURCE_NANOPB = [
'vendor/nanopb/pb_encode.c',
]

SOURCE_BOOTLOADER = [
'embed/bootloader/startup.s',
'embed/bootloader/header.S',
'embed/bootloader/bootui.c',
'embed/bootloader/main.c',
'embed/bootloader/messages.c',
'embed/bootloader/protob/messages.pb.c',
]

# fonts
tools.add_font('NORMAL', FONT_NORMAL, CPPDEFINES_MOD, SOURCE_MOD)
tools.add_font('BOLD', FONT_BOLD, CPPDEFINES_MOD, SOURCE_MOD)
tools.add_font('DEMIBOLD', FONT_DEMIBOLD, CPPDEFINES_MOD, SOURCE_MOD)
tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD)
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)}")
env = Environment(
ENV=os.environ,
CFLAGS=f"{ARGUMENTS.get('CFLAGS', '')} -DPRODUCTION={int(PRODUCTION)} -DBOOTLOADER_QA={int(BOOTLOADER_QA)}",
CPPDEFINES_IMPLICIT=[]
)

FEATURES_AVAILABLE = tools.configure_board(TREZOR_MODEL, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)

FILE_SUFFIX= env.get('ENV')['SUFFIX']
LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT']

SOURCE_BOOTLOADER = [
f'embed/bootloader/startup_{FILE_SUFFIX}.s',
'embed/bootloader/header.S',
'embed/bootloader/bootui.c',
'embed/bootloader/main.c',
'embed/bootloader/messages.c',
'embed/bootloader/protob/messages.pb.c',
]


env.Replace(
CP='cp',
AS='arm-none-eabi-as',
Expand All @@ -148,7 +156,7 @@ env.Replace(
'-fstack-protector-all '
+ 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',
LINKFLAGS=f'-T embed/bootloader/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/bootloader/bootloader.map -Wl,--warn-common -Wl,--print-memory-usage',
CPPPATH=[
'embed/rust',
'embed/bootloader',
Expand All @@ -158,7 +166,6 @@ env.Replace(
'embed/models',
'embed/trezorhal',
'embed/extmod/modtrezorui',
'vendor/micropython/lib/cmsis/inc',
'vendor/nanopb',
] + CPPPATH_MOD + PATH_HAL,
CPPDEFINES=[
Expand All @@ -179,7 +186,7 @@ env.Replace(

env.Replace(
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)}"]))
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}"]))

cmake_gen = env.Command(
target='CMakeLists.txt',
Expand Down Expand Up @@ -268,7 +275,7 @@ program_bin = env.Command(
target='bootloader.bin',
source=program_elf,
action=[
'$OBJCOPY -O binary -j .header -j .flash -j .data $SOURCE $TARGET',
'$OBJCOPY -O binary -j .header -j .flash -j .data -j .sensitive $SOURCE $TARGET',
'$HEADERTOOL $TARGET ' + ('-D' if not PRODUCTION else ''),
'$CP $TARGET ' + BINARY_NAME,
], )
Loading
Loading