1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00

refactor(core): restructure trezorhal, prepare to support more platforms

[no changelog]
This commit is contained in:
tychovrahe 2023-06-23 16:50:13 +02:00 committed by TychoVrahe
parent 34a563018d
commit ebbd7f9d35
140 changed files with 426 additions and 652 deletions

View File

@ -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', '"<stm32f4xx.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',

View File

@ -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', '"<stm32f4xx.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(

View File

@ -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', '"<stm32f4xx.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',

View File

@ -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',

View File

@ -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', '"<stm32f4xx.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(

View File

@ -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', '"<stm32f4xx.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)

View File

@ -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', '"<stm32f4xx.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)

View File

@ -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', )

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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)

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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("."); }

View File

@ -28,6 +28,7 @@ sbu = []
sd_card = []
rgb_led = []
backlight = []
usb = []
test = [
"button",
"cc",

View File

@ -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",

View File

@ -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"

View File

@ -24,6 +24,8 @@
#include <stdint.h>
#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

View File

@ -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);

View File

@ -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);

View File

@ -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"

View File

@ -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,

View File

@ -21,6 +21,7 @@
#define TREZORHAL_STM32_H
#include STM32_HAL_H
#include <stdint.h>
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

View File

@ -0,0 +1 @@
../../firmware/systemview.h

View File

@ -1 +0,0 @@
../firmware/systemview.h

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Some files were not shown because too many files have changed in this diff Show More