1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00

refactor(core): combined build of coreapp + kernel, linker scripts refactoring

[no changelog]
This commit is contained in:
tychovrahe 2024-09-04 11:17:11 +02:00 committed by cepetr
parent 4df485aa03
commit 14a89de6da
85 changed files with 1061 additions and 1024 deletions

View File

@ -274,11 +274,11 @@ build_reflash: ## build reflash firmware + reflash image
build_kernel: ## build kernel image
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" \
TREZOR_MODEL="$(TREZOR_MODEL)" \
TREZOR_MODEL="$(TREZOR_MODEL)" CMAKELISTS="$(CMAKELISTS)" \
BOOTLOADER_QA="$(BOOTLOADER_QA)" BOOTLOADER_DEVEL="$(BOOTLOADER_DEVEL)" \
$(KERNEL_BUILD_DIR)/kernel.bin
build_coreapp: templates build_cross ## build coreapp with frozen modules
build_coreapp: templates build_cross build_kernel ## build coreapp with frozen modules
$(SCONS) CFLAGS="$(CFLAGS)" PRODUCTION="$(PRODUCTION)" \
TREZOR_MODEL="$(TREZOR_MODEL)" CMAKELISTS="$(CMAKELISTS)" \
PYOPT="$(PYOPT)" BITCOIN_ONLY="$(BITCOIN_ONLY)" \
@ -369,15 +369,12 @@ flash_bootloader_ci: $(BOOTLOADER_CI_BUILD_DIR)/bootloader.bin ## flash CI bootl
flash_prodtest: $(PRODTEST_BUILD_DIR)/prodtest.bin ## flash prodtest using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
flash_kernel: $(KERNEL_BUILD_DIR)/kernel.bin ## flash kernel using OpenOCD
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(KERNEL_START); exit"
flash_coreapp: $(COREAPP_BUILD_DIR)/coreapp.bin ## flash coreapp using OpenOCD
ifeq ($(MCU),$(filter $(MCU),STM32F4))
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(COREAPP_START); flash write_image erase $<.p2 $(COREAPP_P2_START); exit"
$(OPENOCD) -c "init; reset halt; flash write_image erase $<.p1 $(FIRMWARE_START); flash write_image erase $<.p2 $(FIRMWARE_P2_START); exit"
else
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(COREAPP_START); exit"
$(OPENOCD) -c "init; reset halt; flash write_image erase $< $(FIRMWARE_START); exit"
endif
flash_firmware: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using OpenOCD

View File

@ -7,6 +7,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1'
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
if TREZOR_MODEL in ('1', ):
# skip boardloader build
@ -102,7 +103,6 @@ env = Environment(ENV=os.environ,
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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 = [
f"embed/boardloader/startup_{FILE_SUFFIX}.s",
@ -111,6 +111,7 @@ SOURCE_BOARDLOADER = [
env.Replace(
CAT='cat',
CP='cp',
AS='arm-none-eabi-as',
AR='arm-none-eabi-ar',
@ -136,7 +137,7 @@ env.Replace(
'-fstack-protector-strong '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
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",
LINKFLAGS="-T build/boardloader/memory.ld -Wl,--gc-sections -Wl,-Map=build/boardloader/boardloader.map -Wl,--warn-common -Wl,--print-memory-usage",
CPPPATH=[
'embed/boardloader',
'embed/lib',
@ -174,6 +175,12 @@ obj_program += env.Object(source=SOURCE_MOD_CRYPTO, CCFLAGS='$CCFLAGS -ftrivial-
obj_program += env.Object(source=SOURCE_BOARDLOADER)
obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='boardloader')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='boardloader.elf',
source=obj_program,
@ -181,6 +188,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
BINARY_NAME = f"build/boardloader/boardloader-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/boardloader/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()

View File

@ -9,6 +9,7 @@ BOOTLOADER_QA = ARGUMENTS.get('BOOTLOADER_QA', '0') == '1'
PRODUCTION = 0 if BOOTLOADER_QA else ARGUMENTS.get('PRODUCTION', '0') == '1'
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' or TREZOR_MODEL in ('T3T1',)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
if TREZOR_MODEL in ('1', ):
# skip bootloader build
@ -161,7 +162,6 @@ env = Environment(
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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',
@ -175,6 +175,7 @@ SOURCE_BOOTLOADER = [
env.Replace(
CAT='cat',
CP='cp',
AS='arm-none-eabi-as',
AR='arm-none-eabi-ar',
@ -212,7 +213,7 @@ env.Replace(
'-fstack-protector-strong '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
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',
LINKFLAGS='-T build/bootloader/memory.ld -Wl,--gc-sections -Wl,-Map=build/bootloader/bootloader.map -Wl,--warn-common -Wl,--print-memory-usage',
CPPPATH=ALLPATHS,
CPPDEFINES=[
'BOOTLOADER',
@ -309,6 +310,12 @@ obj_program += env.Object(source=SOURCE_NANOPB)
obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='bootloader.elf',
source=obj_program,
@ -316,6 +323,7 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
env.Depends(program_elf, rust)
SUFFIX = '_qa' if BOOTLOADER_QA else ''

View File

@ -7,6 +7,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' or TREZOR_MODEL in ('T3T1',)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
if TREZOR_MODEL in ('1', 'DISC1', 'DISC2'):
# skip bootloader_ci build
@ -134,7 +135,6 @@ env = Environment(
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, 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_ci/startup_{FILE_SUFFIX}.s',
@ -171,7 +171,7 @@ env.Replace(
'-fstack-protector-strong '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
LINKFLAGS=f'-T embed/bootloader_ci/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/bootloader_ci/bootloader.map -Wl,--warn-common',
LINKFLAGS=f'-T build/bootloader_ci/memory.ld -Wl,--gc-sections -Wl,-Map=build/bootloader_ci/bootloader.map -Wl,--warn-common',
CPPPATH=[
'embed/bootloader_ci',
'embed/bootloader_ci/nanopb',
@ -220,6 +220,12 @@ obj_program += env.Object(source=SOURCE_BOOTLOADER)
obj_program += env.Object(source=SOURCE_NANOPB)
obj_program += env.Object(source=SOURCE_HAL)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='bootloader')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='bootloader.elf',
source=obj_program,
@ -227,6 +233,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
BINARY_NAME = f"build/bootloader_ci/bootloader_ci-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/bootloader_ci/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()

View File

@ -16,7 +16,7 @@ DISABLE_OPTIGA = ARGUMENTS.get('DISABLE_OPTIGA', '0') == '1'
HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
THP = ARGUMENTS.get('THP', '0') == '1' # Trezor-Host Protocol
NEW_RENDERING = ARGUMENTS.get('NEW_RENDERING', '1') == '1' or TREZOR_MODEL in ('T3T1',)
MODEL_IDENTIFIER = models.get_model_identifier(TREZOR_MODEL)
FEATURE_FLAGS = {
"RDI": True,
@ -478,11 +478,6 @@ env.Replace(
env.Replace(
TREZOR_MODEL=TREZOR_MODEL,)
if TREZOR_MODEL in ('1',):
LD_VARIANT = '' if EVERYTHING else '_min'
else:
LD_VARIANT = ''
ALLPATHS = [
'.',
'embed/rust',
@ -505,7 +500,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/coreapp/memory_${TREZOR_MODEL}%s.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/coreapp/coreapp.map -Wl,--warn-common' % LD_VARIANT,
LINKFLAGS='-T build/coreapp/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/coreapp/coreapp.map -Wl,--warn-common',
CPPPATH=ALLPATHS,
CPPDEFINES=[
'FIRMWARE',
@ -879,17 +874,33 @@ else:
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
if TREZOR_MODEL not in ('1',):
obj_program.extend(
env.Command(
target='embed/coreapp/vendorheader.o',
source=VENDORHEADER,
action='$OBJCOPY -I binary -O elf32-littlearm -B arm'
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
obj_program.extend(
env.Command(
target='embed/coreapp/vendorheader.o',
source=VENDORHEADER,
action='$OBJCOPY -I binary -O elf32-littlearm -B arm'
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
tools.embed_raw_binary(
obj_program,
env,
'kernel',
'build/kernel/kernel.o',
f'build/kernel/kernel.bin',
)
env.Depends(obj_program, qstr_generated)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='coreapp')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='coreapp.elf',
source=obj_program,
@ -897,11 +908,13 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
if CMAKELISTS != 0:
env.Depends(program_elf, cmake_gen)
env.Depends(program_elf, rust)
BINARY_NAME = f"build/coreapp/coreapp-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME = f"build/coreapp/coreapp-{MODEL_IDENTIFIER}"
if not EVERYTHING:
BINARY_NAME += "-btconly"
BINARY_NAME += "-" + tools.get_version('embed/coreapp/version.h')
@ -910,30 +923,23 @@ BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
if TREZOR_MODEL in ('1'):
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .header -j .flash -j .data -j .confidential $SOURCE $TARGET',
'../legacy/bootloader/firmware_sign.py -f $TARGET',
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',
'$CAT ${TARGET}.p1 ${TARGET}.p2 > $TARGET',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$DD if=$TARGET of=${TARGET}.p1 skip=0 bs=128k count=6',
'$CP $TARGET ' + BINARY_NAME,
]
else:
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',
'$CAT ${TARGET}.p1 ${TARGET}.p2 > $TARGET',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$DD if=$TARGET of=${TARGET}.p1 skip=0 bs=128k count=6',
'$CP $TARGET ' + BINARY_NAME,
elif 'STM32U5A9xx' in CPPDEFINES_HAL or 'STM32U585xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential $SOURCE ${TARGET}',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$CP $TARGET ' + BINARY_NAME,
]
elif 'STM32U5A9xx' in CPPDEFINES_HAL or 'STM32U585xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential $SOURCE ${TARGET}',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$CP $TARGET ' + BINARY_NAME,
]
else:
raise Exception("Unknown MCU")
else:
raise Exception("Unknown MCU")
program_bin = env.Command(
target='coreapp.bin',

View File

@ -225,6 +225,7 @@ CPPPATH_MOD += [
]
SOURCE_MOD += [
'embed/extmod/modtrezorui/modtrezorui.c',
'embed/lib/bl_check.c',
'embed/lib/buffers.c',
'embed/lib/colors.c',
'embed/lib/display_utils.c',
@ -453,7 +454,6 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FILE_SUFFIX= env.get('ENV')['SUFFIX']
SOURCE_FIRMWARE = [
'embed/firmware/bl_check.c',
'embed/firmware/delay.c',
'embed/firmware/header.S',
'embed/firmware/main.c',
@ -498,11 +498,6 @@ env.Replace(
env.Replace(
TREZOR_MODEL=TREZOR_MODEL,)
if TREZOR_MODEL in ('1',):
LD_VARIANT = '' if EVERYTHING else '_min'
else:
LD_VARIANT = ''
ALLPATHS = [
'.',
'embed/rust',
@ -525,7 +520,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/firmware/memory_${TREZOR_MODEL}%s.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common' % LD_VARIANT,
LINKFLAGS='-T build/firmware/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common',
CPPPATH=ALLPATHS,
CPPDEFINES=[
'FIRMWARE',
@ -909,17 +904,24 @@ if TREZOR_MODEL not in ('1',):
' $SOURCE $TARGET', ))
if TREZOR_MODEL not in ('DISC1', 'DISC2'):
tools.embed_binary(
tools.embed_compressed_binary(
obj_program,
env,
'bootloader',
'embed/firmware/bootloaders/bootloader.o',
'embed/bootloaders/bootloader.o',
f'embed/models/{MODEL_IDENTIFIER}/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
'firmware'
)
env.Depends(obj_program, qstr_generated)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='firmware.elf',
source=obj_program,
@ -927,6 +929,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
if CMAKELISTS != 0:
env.Depends(program_elf, cmake_gen)
env.Depends(program_elf, rust)

View File

@ -42,38 +42,11 @@ PATH_HAL = []
FROZEN = True
if TREZOR_MODEL in ('1', 'R'):
FONT_NORMAL='Font_PixelOperator_Regular_8'
FONT_DEMIBOLD='Font_Unifont_Bold_16'
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
FONT_NORMAL_UPPER='Font_PixelOperator_Regular_8_upper'
FONT_BOLD_UPPER='Font_PixelOperator_Bold_8_upper'
FONT_SUB=None
elif TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD=None
FONT_MONO='Font_RobotoMono_Medium_20'
FONT_BIG=None
FONT_NORMAL_UPPER=None
FONT_BOLD_UPPER='Font_TTHoves_Bold_17_upper'
FONT_SUB=None
elif TREZOR_MODEL in ('T3T1',):
FONT_NORMAL='Font_TTSatoshi_DemiBold_21'
FONT_DEMIBOLD='Font_TTSatoshi_DemiBold_21'
FONT_BOLD='Font_TTSatoshi_DemiBold_21'
FONT_MONO='Font_RobotoMono_Medium_21'
FONT_BIG='Font_TTSatoshi_DemiBold_42'
FONT_NORMAL_UPPER=None
FONT_BOLD_UPPER=None
FONT_SUB='Font_TTSatoshi_DemiBold_18'
# modtrezorconfig
CPPPATH_MOD += [
'embed/extmod/modtrezorconfig',
'vendor/trezor-storage',
'vendor/micropython/lib/uzlib',
]
SOURCE_MOD += [
# 'embed/extmod/modtrezorconfig/modtrezorconfig.c',
@ -210,6 +183,7 @@ if FEATURE_FLAGS["AES_GCM"]:
]
SOURCE_MOD += [
'embed/lib/bl_check.c',
# 'embed/lib/buffers.c',
# 'embed/lib/colors.c',
# 'embed/lib/display_utils.c',
@ -227,6 +201,9 @@ SOURCE_MOD += [
'embed/lib/translations.c',
'embed/lib/unit_variant.c',
'embed/extmod/modtrezorcrypto/rand.c',
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',
]
if NEW_RENDERING:
@ -241,7 +218,6 @@ else:
CPPDEFINES_MOD += [
'TREZOR_UI2',
'TRANSLATIONS',
]
@ -282,15 +258,6 @@ if THP:
'vendor/trezor-crypto/elligator2.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)
tools.add_font('NORMAL_UPPER', FONT_NORMAL_UPPER, CPPDEFINES_MOD, SOURCE_MOD)
tools.add_font('BOLD_UPPER', FONT_BOLD_UPPER, CPPDEFINES_MOD, SOURCE_MOD)
tools.add_font('SUB', FONT_SUB, CPPDEFINES_MOD, SOURCE_MOD)
env = Environment(
ENV=os.environ,
@ -303,24 +270,10 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FILE_SUFFIX= env.get('ENV')['SUFFIX']
SOURCE_FIRMWARE = [
'embed/kernel/header.S',
'embed/kernel/main.c',
f'embed/kernel/startup_{FILE_SUFFIX}.S',
]
if TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
UI_LAYOUT = 'UI_LAYOUT_TR'
ui_layout_feature = 'model_tr'
elif TREZOR_MODEL in ('T3T1',):
UI_LAYOUT = 'UI_LAYOUT_MERCURY'
ui_layout_feature = 'model_mercury'
else:
raise ValueError('Unknown Trezor model')
if 'sd_card' in FEATURES_AVAILABLE:
SDCARD = True
else:
@ -342,11 +295,6 @@ env.Replace(
env.Replace(
TREZOR_MODEL=TREZOR_MODEL,)
if TREZOR_MODEL in ('1',):
LD_VARIANT = '' if EVERYTHING else '_min'
else:
LD_VARIANT = ''
ALLPATHS = [
'.',
'embed/firmware',
@ -365,14 +313,13 @@ env.Replace(
'-ffreestanding '
'-fstack-protector-all '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
LINKFLAGS='-T embed/kernel/memory_${TREZOR_MODEL}%s.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/kernel/kernel.map -Wl,--warn-common' % LD_VARIANT,
LINKFLAGS='-T build/kernel/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage -Wl,-Map=build/kernel/kernel.map -Wl,--warn-common',
CPPPATH=ALLPATHS,
CPPDEFINES=[
'KERNEL',
'TREZOR_MODEL_'+TREZOR_MODEL,
'USE_HAL_DRIVER',
'ARM_USER_MODE',
UI_LAYOUT,
] + CPPDEFINES_MOD + CPPDEFINES_HAL,
ASFLAGS=env.get('ENV')['CPU_ASFLAGS'],
ASPPFLAGS='$CFLAGS $CCFLAGS',
@ -381,8 +328,6 @@ env.Replace(
env.Replace(
HEADERTOOL='headertool',
PYTHON='python',
MAKEVERSIONHDR='$PYTHON vendor/micropython/py/makeversionhdr.py',
MAKEMODULEDEFS='$PYTHON vendor/micropython/py/makemoduledefs.py',
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py',
)
@ -433,24 +378,29 @@ else:
VENDORHEADER = f'embed/models/{MODEL_IDENTIFIER}/vendorheader/vendorheader_{vendor}.bin'
if TREZOR_MODEL not in ('1',):
obj_program.extend(
env.Command(
target='embed/kernel/vendorheader.o',
source=VENDORHEADER,
action='$OBJCOPY -I binary -O elf32-littlearm -B arm'
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
obj_program.extend(
env.Command(
target='embed/kernel/vendorheader.o',
source=VENDORHEADER,
action='$OBJCOPY -I binary -O elf32-littlearm -B arm'
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
if False: # TREZOR_MODEL not in ('DISC1', 'DISC2'):
tools.embed_binary(
if TREZOR_MODEL not in ('DISC1', 'DISC2'):
tools.embed_compressed_binary(
obj_program,
env,
'bootloader',
'embed/firmware/bootloaders/bootloader.o',
f'embed/firmware/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
'embed/bootloaders/bootloader.o',
f'embed/models/{MODEL_IDENTIFIER}/bootloaders/bootloader_{BOOTLOADER_SUFFIX}.bin',
'kernel'
)
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='kernel')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='kernel.elf',
@ -459,6 +409,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $SOURCES $LINKFLAGS -lc_nano -lm -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
if CMAKELISTS != 0:
env.Depends(program_elf, cmake_gen)
@ -470,31 +422,10 @@ BINARY_NAME += "-" + tools.get_git_revision_short_hash()
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
if TREZOR_MODEL in ('1'):
action_bin=[
'$OBJCOPY -O binary -j .header -j .flash -j .data -j .confidential $SOURCE $TARGET',
'../legacy/bootloader/firmware_sign.py -f $TARGET',
'$CP $TARGET ' + BINARY_NAME,
]
else:
if 'STM32F427xx' in CPPDEFINES_HAL or 'STM32F429xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential --pad-to 0x08100000 $SOURCE ${TARGET}.p1',
'$OBJCOPY -O binary -j .flash2 $SOURCE ${TARGET}.p2',
'$CAT ${TARGET}.p1 ${TARGET}.p2 > $TARGET',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$DD if=$TARGET of=${TARGET}.p1 skip=0 bs=128k count=6',
'$CP $TARGET ' + BINARY_NAME,
]
elif 'STM32U5A9xx' in CPPDEFINES_HAL or 'STM32U585xx' in CPPDEFINES_HAL:
action_bin=[
'$OBJCOPY -O binary -j .vendorheader -j .header -j .flash -j .data -j .confidential $SOURCE ${TARGET}',
'$HEADERTOOL -h $TARGET ' + ('-D' if not PRODUCTION else ''),
'$CP $TARGET ' + BINARY_NAME,
]
else:
raise Exception("Unknown MCU")
action_bin=[
'$OBJCOPY -O binary -j .flash -j .uflash -j .data -j .confidential $SOURCE ${TARGET}',
'$CP $TARGET ' + BINARY_NAME,
]
program_bin = env.Command(
target='kernel.bin',

View File

@ -153,7 +153,6 @@ env = Environment(
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
FILE_SUFFIX= env.get('ENV')['SUFFIX']
LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT']
SOURCE_PRODTEST = [
@ -169,6 +168,7 @@ if 'optiga' in FEATURES_AVAILABLE:
]
env.Replace(
CAT='cat',
CP='cp',
AS='arm-none-eabi-as',
AR='arm-none-eabi-ar',
@ -194,7 +194,7 @@ env.Replace(
'-fstack-protector-all '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
LINKFLAGS=f'-T embed/prodtest/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/prodtest/prodtest.map -Wl,--warn-common',
LINKFLAGS=f'-T build/prodtest/memory.ld -Wl,--gc-sections -Wl,-Map=build/prodtest/prodtest.map -Wl,--warn-common',
CPPPATH=[
'embed/prodtest',
'embed/lib',
@ -266,6 +266,12 @@ obj_program.extend(
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='prodtest.elf',
source=obj_program,
@ -273,6 +279,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
BINARY_NAME = f"build/prodtest/prodtest-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/prodtest/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()

View File

@ -104,14 +104,12 @@ tools.add_font('SUB', FONT_SUB, CPPDEFINES_MOD, SOURCE_MOD)
env = Environment(
ENV=os.environ,
CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')),
CONSTRAINTS=["limited_util_s"],
CPPDEFINES_IMPLICIT=[]
)
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
FILE_SUFFIX= env.get('ENV')['SUFFIX']
LINKER_SCRIPT_SUFFIX= env.get('ENV')['LINKER_SCRIPT']
SOURCE_REFLASH = [
f'embed/reflash/startup_{FILE_SUFFIX}.s',
@ -120,6 +118,7 @@ SOURCE_REFLASH = [
]
env.Replace(
CAT='cat',
CP='cp',
AS='arm-none-eabi-as',
AR='arm-none-eabi-ar',
@ -145,7 +144,7 @@ env.Replace(
'-fstack-protector-all '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
LINKFLAGS=f'-T embed/reflash/memory_{LINKER_SCRIPT_SUFFIX}.ld -Wl,--gc-sections -Wl,-Map=build/reflash/reflash.map -Wl,--warn-common',
LINKFLAGS=f'-T build/reflash/memory.ld -Wl,--gc-sections -Wl,-Map=build/reflash/reflash.map -Wl,--warn-common',
CPPPATH=[
'embed/reflash',
'embed/lib',
@ -197,6 +196,12 @@ obj_program.extend(
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))
linkerscript_gen = env.Command(
target='memory.ld',
source=[f'embed/models/{MODEL_IDENTIFIER}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='prodtest')],
action='$CAT $SOURCES > $TARGET',
)
program_elf = env.Command(
target='reflash.elf',
source=obj_program,
@ -204,6 +209,8 @@ program_elf = env.Command(
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES -lc_nano -lgcc',
)
env.Depends(program_elf, linkerscript_gen)
BINARY_NAME = f"build/reflash/reflash-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/reflash/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()

View File

@ -1,108 +0,0 @@
/* Trezor v2 bootloader linker script */
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C010000, LENGTH = 128K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 512K
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
confidential_vma = ADDR(.confidential);
confidential_size = SIZEOF(.confidential);
/* used by the startup code to wipe memory */
sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
sram4_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(512);
} >FLASH AT>FLASH
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM1 AT>FLASH
/DISCARD/ : {
*(.ARM.exidx*);
}
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM1
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM1
.stack : ALIGN(8) {
. = 16K; /* Exactly 16K allocated for stack. Overflow causes Usage fault. */
} >SRAM2
.confidential : ALIGN(512) {
*(.confidential*);
. = ALIGN(512);
} >SRAM2 AT>FLASH
.fb : ALIGN(4) {
__fb_start = .;
*(.fb1*);
*(.fb2*);
__fb_end = .;
. = ALIGN(4);
} >SRAM3
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);
*(.boot_args*);
. = ALIGN(8);
} >BOOT_ARGS
}

View File

@ -1,112 +0,0 @@
/* Trezor v2 bootloader linker script */
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C010000, LENGTH = 128K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x300BFF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 0
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
confidential_vma = ADDR(.confidential);
confidential_size = SIZEOF(.confidential);
/* used by the startup code to wipe memory */
sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
sram4_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(1024) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(512);
} >FLASH AT>FLASH
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM1 AT>FLASH
/DISCARD/ : {
*(.ARM.exidx*);
}
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM1
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM1
.stack : ALIGN(8) {
. = 16K; /* Overflow causes UsageFault */
} >SRAM2
.confidential : ALIGN(512) {
*(.confidential*);
. = ALIGN(512);
} >SRAM2 AT>FLASH
.fb1 : ALIGN(4) {
__fb_start = .;
*(.fb1*);
*(.gfxmmu_table*);
*(.framebuffer_select*);
. = ALIGN(4);
} >SRAM3
.fb2 : ALIGN(4) {
*(.fb2*);
__fb_end = .;
. = ALIGN(4);
} >SRAM5
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);
*(.boot_args*);
. = ALIGN(8);
} >BOOT_ARGS
}

View File

@ -1 +0,0 @@
memory_T.ld

View File

@ -1 +0,0 @@
memory_T.ld

View File

@ -1 +0,0 @@
memory_T3T1.ld

View File

@ -1,74 +0,0 @@
/* TREZORv1 firmware linker script */
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 1024K - 64K
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 128K
}
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to wipe memory */
/* we have no CCMRAM, so erase the first word of SRAM as hack */
ccmram_start = ORIGIN(SRAM);
ccmram_end = ORIGIN(SRAM) + 4;
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
_ram_start = sram_start;
_ram_end = sram_end;
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.exidx);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);
SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(512);
} >FLASH AT>FLASH
/* exception handling info generated by llvm which should consist of 8 bytes of "cantunwind" */
.exidx : ALIGN(4) {
*(.ARM.exidx*);
. = ALIGN(4);
} >FLASH AT>FLASH
.stack : ALIGN(8) {
. = 16K; /* Exactly 16K allocated for stack. Overflow causes MemManage fault (when using MPU). */
} >SRAM
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM AT>FLASH
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM
.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram_end - 8); /* this explicitly sets the end of the heap, T1 bootloader had 8 bytes reserved at end */
} >SRAM
}

View File

@ -1,74 +0,0 @@
/* TREZORv1 firmware linker script */
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 1024K - 64K
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 128K
}
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to wipe memory */
/* we have no CCMRAM, so erase the first word of SRAM as hack */
ccmram_start = ORIGIN(SRAM);
ccmram_end = ORIGIN(SRAM) + 4;
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
_ram_start = sram_start;
_ram_end = sram_end;
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.exidx);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);
SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(512);
} >FLASH AT>FLASH
/* exception handling info generated by llvm which should consist of 8 bytes of "cantunwind" */
.exidx : ALIGN(4) {
*(.ARM.exidx*);
. = ALIGN(4);
} >FLASH AT>FLASH
.stack : ALIGN(8) {
. = 16K; /* Exactly 16K allocated for stack. Overflow causes MemManage fault (when using MPU). */
} >SRAM
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM AT>FLASH
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM
.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram_end - 8); /* this explicitly sets the end of the heap, T1 bootloader had 8 bytes reserved at end */
} >SRAM
}

View File

@ -1 +0,0 @@
memory_T.ld

View File

@ -1 +0,0 @@
memory_T.ld

View File

@ -1 +0,0 @@
memory_T3T1.ld

View File

@ -1,54 +0,0 @@
.syntax unified
#include "version.h"
.section .header, "a"
.type g_header, %object
.size g_header, .-g_header
// Firmware header for both Trezor One and Trezor T.
// Trezor One must have bootloader version >= 1.8.0 (before that version the hdrlen used to be reset vector)
g_header:
.byte 'T','R','Z','F' // magic
.word g_header_end - g_header // hdrlen
#ifdef TREZOR_MODEL_T
.word 0 // expiry
#else
.word 1 // expiry
#endif
.word _codelen // codelen
.byte VERSION_MAJOR // vmajor
.byte VERSION_MINOR // vminor
.byte VERSION_PATCH // vpatch
.byte VERSION_BUILD // vbuild
.byte FIX_VERSION_MAJOR // fix_vmajor
.byte FIX_VERSION_MINOR // fix_vminor
.byte FIX_VERSION_PATCH // fix_vpatch
.byte FIX_VERSION_BUILD // fix_vbuild
.word HW_MODEL // type of the designated hardware
.byte HW_REVISION // revision of the designated hardware
.byte VERSION_MONOTONIC // monotonic version of the binary
. = . + 2 // reserved
. = . + 512 // hash1 ... hash16
#if !defined TREZOR_MODEL_1
// trezor-core header style
. = . + 415 // reserved
.byte 0 // sigmask
. = . + 64 // sig
#else
// model 1 compatibility header
. = . + 64 // sig1
. = . + 64 // sig2
. = . + 64 // sig3
.byte 0 // sigindex1
.byte 0 // sigindex2
.byte 0 // sigindex3
. = . + 220 // reserved
. = . + 65 // reserved
#endif
g_header_end:

View File

@ -22,8 +22,11 @@
#include <string.h>
#include "applet.h"
#include "bl_check.h"
#include "board_capabilities.h"
#include "bootutils.h"
#include "button.h"
#include "consumption_mask.h"
#include "display.h"
#include "dma2d.h"
#include "entropy.h"
@ -115,7 +118,7 @@ void drivers_init() {
entropy_init();
#if PRODUCTION || BOOTLOADER_QA
// check_and_replace_bootloader();
check_and_replace_bootloader();
#endif
#ifdef USE_BUTTON
@ -171,10 +174,13 @@ void drivers_init() {
#endif
}
extern uint32_t _codelen;
#define KERNEL_SIZE (uint32_t) & _codelen
// Initializes coreapp applet
static void coreapp_init(applet_t *applet) {
applet_header_t *coreapp_header =
(applet_header_t *)(COREAPP_START + IMAGE_HEADER_SIZE + 0x0400);
(applet_header_t *)COREAPP_CODE_ALIGN(KERNEL_START + KERNEL_SIZE);
applet_layout_t coreapp_layout = {
0

View File

@ -0,0 +1,46 @@
.syntax unified
.text
.global reset_handler
.type reset_handler, STT_FUNC
reset_handler:
// setup environment for subsequent stage of code
ldr r0, =ccmram_start // r0 - point to beginning of CCMRAM
ldr r1, =ccmram_end // r1 - point to byte after the end of CCMRAM
ldr r2, =0 // r2 - the word-sized value to be written
bl memset_reg
ldr r0, =boot_args_start // r0 - point to beginning of BOOT_ARGS
ldr r1, =boot_args_end // r1 - point to byte after the end of BOOT_ARGS
ldr r2, =0 // r2 - the word-sized value to be written
bl memset_reg
ldr r0, =sram_start // r0 - point to beginning of SRAM
ldr r1, =sram_end // r1 - point to byte after the end of SRAM
ldr r2, =0 // r2 - the word-sized value to be written
bl memset_reg
// copy data in from flash
ldr r0, =data_vma // dst addr
ldr r1, =data_lma // src addr
ldr r2, =data_size // size in bytes
bl memcpy
// setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value
bl rng_get
ldr r1, = __stack_chk_guard
str r0, [r1]
// re-enable exceptions
// according to "ARM Cortex-M Programming Guide to Memory Barrier Instructions" Application Note 321, section 4.7:
// "If it is not necessary to ensure that a pended interrupt is recognized immediately before
// subsequent operations, it is not necessary to insert a memory barrier instruction."
cpsie f
// enter the application code
bl main
b shutdown_privileged
.end

View File

@ -29,10 +29,8 @@
#include "uzlib.h"
// symbols from bootloader.bin => bootloader.o
extern const void
_binary_embed_firmware_bootloaders_bootloader_bin_deflated_start;
extern const void
_binary_embed_firmware_bootloaders_bootloader_bin_deflated_size;
extern const void _binary_embed_bootloaders_bootloader_bin_deflated_start;
extern const void _binary_embed_bootloaders_bootloader_bin_deflated_size;
#define CONCAT_NAME_HELPER(prefix, name, suffix) prefix##name##suffix
#define CONCAT_NAME(name, var) CONCAT_NAME_HELPER(BOOTLOADER_, name, var)
@ -82,6 +80,7 @@ static void uzlib_prepare(struct uzlib_uncomp *decomp, uint8_t *window,
void check_and_replace_bootloader(void) {
#if PRODUCTION || BOOTLOADER_QA
mpu_mode_t mode = mpu_reconfig(MPU_MODE_BOOTLOADER);
// compute current bootloader hash
uint8_t hash[BLAKE2S_DIGEST_LENGTH];
@ -95,15 +94,16 @@ void check_and_replace_bootloader(void) {
// do we have the latest bootloader?
if (sectrue == latest_bootloader(hash, BLAKE2S_DIGEST_LENGTH)) {
mpu_reconfig(mode);
return;
}
// replace bootloader with the latest one
const uint32_t *data =
(const uint32_t
*)&_binary_embed_firmware_bootloaders_bootloader_bin_deflated_start;
*)&_binary_embed_bootloaders_bootloader_bin_deflated_start;
const uint32_t len =
(const uint32_t)&_binary_embed_firmware_bootloaders_bootloader_bin_deflated_size;
(const uint32_t)&_binary_embed_bootloaders_bootloader_bin_deflated_size;
struct uzlib_uncomp decomp = {0};
uint8_t decomp_window[UZLIB_WINDOW_SIZE] = {0};
@ -134,6 +134,7 @@ void check_and_replace_bootloader(void) {
if (new_bld_hdr->monotonic < current_bld_hdr->monotonic) {
// reject downgrade
mpu_reconfig(mode);
return;
}
@ -180,5 +181,7 @@ void check_and_replace_bootloader(void) {
}
ensure(flash_lock_write(), NULL);
mpu_reconfig(mode);
#endif
}

View File

@ -39,6 +39,12 @@
#define IMAGE_CODE_ALIGN(addr) \
((((uint32_t)(uintptr_t)addr) + (CODE_ALIGNMENT - 1)) & ~(CODE_ALIGNMENT - 1))
#define COREAPP_ALIGNMENT 512
#define COREAPP_CODE_ALIGN(addr) \
((((uint32_t)(uintptr_t)addr) + (COREAPP_ALIGNMENT - 1)) & \
~(COREAPP_ALIGNMENT - 1))
typedef struct {
uint32_t magic;
uint32_t hdrlen;

View File

@ -0,0 +1,25 @@
FLASH_START = 0x8000000;
BOARDLOADER_START = 0x8000000;
BOOTLOADER_START = 0x8020000;
FIRMWARE_START = 0x8040000;
FIRMWARE_P2_START = 0x8120000;
STORAGE_1_OFFSET = 0x10000;
STORAGE_2_OFFSET = 0x110000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x1a0000;
FIRMWARE_P1_IMAGE_MAXSIZE = 0xc0000;
FIRMWARE_P2_IMAGE_MAXSIZE = 0xe0000;
BOARDLOADER_SECTOR_START = 0x0;
BOARDLOADER_SECTOR_END = 0x3;
BOOTLOADER_SECTOR_START = 0x5;
BOOTLOADER_SECTOR_END = 0x5;
FIRMWARE_SECTOR_START = 0x6;
FIRMWARE_SECTOR_END = 0xb;
FIRMWARE_P2_SECTOR_START = 0x11;
FIRMWARE_P2_SECTOR_END = 0x17;
STORAGE_1_SECTOR_START = 0x4;
STORAGE_1_SECTOR_END = 0x4;
STORAGE_2_SECTOR_START = 0x10;
STORAGE_2_SECTOR_END = 0x10;

View File

@ -0,0 +1,30 @@
FLASH_START = 0xc000000;
BOARDLOADER_START = 0xc004000;
BOOTLOADER_START = 0xc010000;
KERNEL_START = 0xc050000;
FIRMWARE_START = 0xc050000;
STORAGE_1_OFFSET = 0x30000;
STORAGE_2_OFFSET = 0x50000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x3a0000;
KERNEL_IMAGE_MAXSIZE = 0x80000;
BOARDLOADER_SECTOR_START = 0x2;
BOARDLOADER_SECTOR_END = 0x7;
BOOTLOADER_SECTOR_START = 0x8;
BOOTLOADER_SECTOR_END = 0x17;
FIRMWARE_SECTOR_START = 0x28;
FIRMWARE_SECTOR_END = 0x1f7;
STORAGE_1_SECTOR_START = 0x18;
STORAGE_1_SECTOR_END = 0x1f;
STORAGE_2_SECTOR_START = 0x20;
STORAGE_2_SECTOR_END = 0x27;
KERNEL_U_FLASH_SIZE = 0x200;
KERNEL_U_RAM_SIZE = 0x200;
KERNEL_SRAM1_SIZE = 0x4000;
KERNEL_SRAM2_SIZE = 0x2400;
KERNEL_SRAM3_SIZE = 0xbb800;
BOOTARGS_SIZE = 0x100;
BOARD_CAPABILITIES_ADDR = 0xc00ff00;
CODE_ALIGNMENT = 0x400;

View File

@ -25,16 +25,12 @@
#define IMAGE_CHUNK_SIZE SIZE_256K
#define IMAGE_HASH_SHA256
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x400
// SHARED WITH MAKEFILE
// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
#define FLASH_START 0x0C000000
#define BOARDLOADER_START 0x0C004000
#define BOOTLOADER_START 0x0C010000
#define KERNEL_START 0x0C050000
#define KERNEL_SIZE 0x00028000
#define COREAPP_START 0x0C078000
#define FIRMWARE_START 0x0C050000
#define STORAGE_1_OFFSET 0x30000
#define STORAGE_2_OFFSET 0x50000
@ -42,6 +38,7 @@
#define BOARDLOADER_IMAGE_MAXSIZE (6 * 8 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (16 * 8 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (464 * 8 * 1024) // 3712 kB
#define KERNEL_IMAGE_MAXSIZE (512 * 1024) // 512 kB
#define BOARDLOADER_SECTOR_START 0x2
#define BOARDLOADER_SECTOR_END 0x7
#define BOOTLOADER_SECTOR_START 0x8
@ -53,4 +50,14 @@
#define STORAGE_2_SECTOR_START 0x20
#define STORAGE_2_SECTOR_END 0x27
#define KERNEL_U_FLASH_SIZE 512
#define KERNEL_U_RAM_SIZE 512
#define KERNEL_SRAM1_SIZE 16 * 1024
#define KERNEL_SRAM2_SIZE 9 * 1024
#define KERNEL_SRAM3_SIZE 750 * 1024
#define BOOTARGS_SIZE 0x100
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x400
#endif

View File

@ -0,0 +1,14 @@
FLASH_START = 0x8000000;
BOOTLOADER_START = 0x8000000;
FIRMWARE_START = 0x8010000;
NORCOW_SECTOR_SIZE = 0x10000;
BOOTLOADER_IMAGE_MAXSIZE = 0x8000;
FIRMWARE_IMAGE_MAXSIZE = 0xf0000;
BOOTLOADER_SECTOR_START = 0x0;
BOOTLOADER_SECTOR_END = 0x2;
FIRMWARE_SECTOR_START = 0x4;
FIRMWARE_SECTOR_END = 0xb;
STORAGE_1_SECTOR_START = 0x2;
STORAGE_1_SECTOR_END = 0x2;
STORAGE_2_SECTOR_START = 0x3;
STORAGE_2_SECTOR_END = 0x3;

View File

@ -0,0 +1,30 @@
FLASH_START = 0x8000000;
BOARDLOADER_START = 0x8000000;
BOOTLOADER_START = 0x8020000;
FIRMWARE_START = 0x8040000;
FIRMWARE_P2_START = 0x8120000;
KERNEL_START = 0x8040000;
STORAGE_1_OFFSET = 0x10000;
STORAGE_2_OFFSET = 0x110000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x1a0000;
FIRMWARE_P1_IMAGE_MAXSIZE = 0xc0000;
FIRMWARE_P2_IMAGE_MAXSIZE = 0xe0000;
KERNEL_IMAGE_MAXSIZE = 0x80000;
BOARDLOADER_SECTOR_START = 0x0;
BOARDLOADER_SECTOR_END = 0x3;
BOOTLOADER_SECTOR_START = 0x5;
BOOTLOADER_SECTOR_END = 0x5;
FIRMWARE_SECTOR_START = 0x6;
FIRMWARE_SECTOR_END = 0xb;
FIRMWARE_P2_SECTOR_START = 0x11;
FIRMWARE_P2_SECTOR_END = 0x17;
STORAGE_1_SECTOR_START = 0x4;
STORAGE_1_SECTOR_END = 0x4;
STORAGE_2_SECTOR_START = 0x10;
STORAGE_2_SECTOR_END = 0x10;
BOOTARGS_SIZE = 0x100;
BOARD_CAPABILITIES_ADDR = 0x800bf00;
CODE_ALIGNMENT = 0x200;

View File

@ -24,8 +24,6 @@
#define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_BLAKE2S
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define CODE_ALIGNMENT 0x200
// SHARED WITH MAKEFILE
#define FLASH_START 0x08000000
@ -33,6 +31,7 @@
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define FIRMWARE_P2_START 0x08120000
#define KERNEL_START 0x08040000
#define STORAGE_1_OFFSET 0x10000
#define STORAGE_2_OFFSET 0x110000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
@ -41,6 +40,7 @@
#define FIRMWARE_IMAGE_MAXSIZE (13 * 128 * 1024) // 1664 kB
#define FIRMWARE_P1_IMAGE_MAXSIZE (6 * 128 * 1024)
#define FIRMWARE_P2_IMAGE_MAXSIZE (7 * 128 * 1024)
#define KERNEL_IMAGE_MAXSIZE (4 * 128 * 1024)
#define BOARDLOADER_SECTOR_START 0
#define BOARDLOADER_SECTOR_END 3
#define BOOTLOADER_SECTOR_START 5
@ -54,4 +54,8 @@
#define STORAGE_2_SECTOR_START 16
#define STORAGE_2_SECTOR_END 16
#define BOOTARGS_SIZE 0x100
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define CODE_ALIGNMENT 0x200
#endif

View File

@ -0,0 +1,32 @@
FLASH_START = 0x8000000;
BOARDLOADER_START = 0x8000000;
BOOTLOADER_START = 0x8020000;
FIRMWARE_START = 0x8040000;
FIRMWARE_P2_START = 0x8120000;
KERNEL_START = 0x8040000;
STORAGE_1_OFFSET = 0x10000;
STORAGE_2_OFFSET = 0x110000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x1a0000;
FIRMWARE_P1_IMAGE_MAXSIZE = 0xc0000;
FIRMWARE_P2_IMAGE_MAXSIZE = 0xe0000;
KERNEL_IMAGE_MAXSIZE = 0x80000;
BOARDLOADER_SECTOR_START = 0x0;
BOARDLOADER_SECTOR_END = 0x3;
BOOTLOADER_SECTOR_START = 0x5;
BOOTLOADER_SECTOR_END = 0x5;
FIRMWARE_SECTOR_START = 0x6;
FIRMWARE_SECTOR_END = 0xb;
FIRMWARE_P2_SECTOR_START = 0x11;
FIRMWARE_P2_SECTOR_END = 0x17;
STORAGE_1_SECTOR_START = 0x4;
STORAGE_1_SECTOR_END = 0x4;
STORAGE_2_SECTOR_START = 0x10;
STORAGE_2_SECTOR_END = 0x10;
KERNEL_CCMRAM_SIZE = 0x4000;
KERNEL_SRAM_SIZE = 0x0;
BOOTARGS_SIZE = 0x100;
BOARD_CAPABILITIES_ADDR = 0x800bf00;
CODE_ALIGNMENT = 0x200;

View File

@ -24,8 +24,6 @@
#define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_BLAKE2S
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define CODE_ALIGNMENT 0x200
// SHARED WITH MAKEFILE
#define FLASH_START 0x08000000
@ -33,6 +31,7 @@
#define BOOTLOADER_START 0x08020000
#define FIRMWARE_START 0x08040000
#define FIRMWARE_P2_START 0x08120000
#define KERNEL_START 0x08040000
#define STORAGE_1_OFFSET 0x10000
#define STORAGE_2_OFFSET 0x110000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
@ -41,6 +40,7 @@
#define FIRMWARE_IMAGE_MAXSIZE (13 * 128 * 1024) // 1664 kB
#define FIRMWARE_P1_IMAGE_MAXSIZE (6 * 128 * 1024)
#define FIRMWARE_P2_IMAGE_MAXSIZE (7 * 128 * 1024)
#define KERNEL_IMAGE_MAXSIZE (4 * 128 * 1024)
#define BOARDLOADER_SECTOR_START 0
#define BOARDLOADER_SECTOR_END 3
#define BOOTLOADER_SECTOR_START 5
@ -53,5 +53,11 @@
#define STORAGE_1_SECTOR_END 4
#define STORAGE_2_SECTOR_START 16
#define STORAGE_2_SECTOR_END 16
#define KERNEL_CCMRAM_SIZE 16 * 1024
#define KERNEL_SRAM_SIZE 0 * 1024
#define BOOTARGS_SIZE 0x100
#define BOARD_CAPABILITIES_ADDR 0x0800BF00
#define CODE_ALIGNMENT 0x200
#endif

View File

@ -0,0 +1,30 @@
FLASH_START = 0xc000000;
BOARDLOADER_START = 0xc004000;
BOOTLOADER_START = 0xc010000;
KERNEL_START = 0xc050000;
FIRMWARE_START = 0xc050000;
STORAGE_1_OFFSET = 0x30000;
STORAGE_2_OFFSET = 0x50000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x1a0000;
KERNEL_IMAGE_MAXSIZE = 0x80000;
BOARDLOADER_SECTOR_START = 0x2;
BOARDLOADER_SECTOR_END = 0x7;
BOOTLOADER_SECTOR_START = 0x8;
BOOTLOADER_SECTOR_END = 0x17;
FIRMWARE_SECTOR_START = 0x28;
FIRMWARE_SECTOR_END = 0xf7;
STORAGE_1_SECTOR_START = 0x18;
STORAGE_1_SECTOR_END = 0x1f;
STORAGE_2_SECTOR_START = 0x20;
STORAGE_2_SECTOR_END = 0x27;
KERNEL_U_FLASH_SIZE = 0x200;
KERNEL_U_RAM_SIZE = 0x200;
KERNEL_SRAM1_SIZE = 0x4000;
KERNEL_SRAM2_SIZE = 0x2000;
KERNEL_SRAM3_SIZE = 0x38400;
BOOTARGS_SIZE = 0x100;
BOARD_CAPABILITIES_ADDR = 0xc00ff00;
CODE_ALIGNMENT = 0x200;

View File

@ -25,13 +25,12 @@
#define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_SHA256
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x200
// SHARED WITH MAKEFILE
// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
#define FLASH_START 0x0C000000
#define BOARDLOADER_START 0x0C004000
#define BOOTLOADER_START 0x0C010000
#define KERNEL_START 0x0C050000
#define FIRMWARE_START 0x0C050000
#define STORAGE_1_OFFSET 0x30000
#define STORAGE_2_OFFSET 0x50000
@ -39,6 +38,7 @@
#define BOARDLOADER_IMAGE_MAXSIZE (6 * 8 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (16 * 8 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (208 * 8 * 1024) // 1664 kB
#define KERNEL_IMAGE_MAXSIZE (512 * 1024) // 512 kB
#define BOARDLOADER_SECTOR_START 0x2
#define BOARDLOADER_SECTOR_END 0x7
#define BOOTLOADER_SECTOR_START 0x8
@ -50,4 +50,14 @@
#define STORAGE_2_SECTOR_START 0x20
#define STORAGE_2_SECTOR_END 0x27
#define KERNEL_U_FLASH_SIZE 512
#define KERNEL_U_RAM_SIZE 512
#define KERNEL_SRAM1_SIZE 16 * 1024
#define KERNEL_SRAM2_SIZE 8 * 1024
#define KERNEL_SRAM3_SIZE 0x38400
#define BOOTARGS_SIZE 0x100
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x200
#endif

View File

@ -0,0 +1,30 @@
FLASH_START = 0xc000000;
BOARDLOADER_START = 0xc004000;
BOOTLOADER_START = 0xc010000;
KERNEL_START = 0xc050000;
FIRMWARE_START = 0xc050000;
STORAGE_1_OFFSET = 0x30000;
STORAGE_2_OFFSET = 0x50000;
NORCOW_SECTOR_SIZE = 0x10000;
BOARDLOADER_IMAGE_MAXSIZE = 0xc000;
BOOTLOADER_IMAGE_MAXSIZE = 0x20000;
FIRMWARE_IMAGE_MAXSIZE = 0x1a0000;
KERNEL_IMAGE_MAXSIZE = 0x80000;
BOARDLOADER_SECTOR_START = 0x2;
BOARDLOADER_SECTOR_END = 0x7;
BOOTLOADER_SECTOR_START = 0x8;
BOOTLOADER_SECTOR_END = 0x17;
FIRMWARE_SECTOR_START = 0x28;
FIRMWARE_SECTOR_END = 0xf7;
STORAGE_1_SECTOR_START = 0x18;
STORAGE_1_SECTOR_END = 0x1f;
STORAGE_2_SECTOR_START = 0x20;
STORAGE_2_SECTOR_END = 0x27;
KERNEL_U_FLASH_SIZE = 0x200;
KERNEL_U_RAM_SIZE = 0x200;
KERNEL_SRAM1_SIZE = 0x4000;
KERNEL_SRAM2_SIZE = 0x2000;
KERNEL_SRAM3_SIZE = 0x38400;
BOOTARGS_SIZE = 0x100;
BOARD_CAPABILITIES_ADDR = 0xc00ff00;
CODE_ALIGNMENT = 0x200;

View File

@ -25,16 +25,12 @@
#define IMAGE_CHUNK_SIZE (128 * 1024)
#define IMAGE_HASH_SHA256
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x200
// SHARED WITH MAKEFILE
// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
#define FLASH_START 0x0C000000
#define BOARDLOADER_START 0x0C004000
#define BOOTLOADER_START 0x0C010000
#define KERNEL_START 0x0C050000
#define KERNEL_SIZE 0x00028000
#define COREAPP_START 0x0C078000
#define FIRMWARE_START 0x0C050000
#define STORAGE_1_OFFSET 0x30000
#define STORAGE_2_OFFSET 0x50000
@ -42,6 +38,7 @@
#define BOARDLOADER_IMAGE_MAXSIZE (6 * 8 * 1024) // 48 kB
#define BOOTLOADER_IMAGE_MAXSIZE (16 * 8 * 1024) // 128 kB
#define FIRMWARE_IMAGE_MAXSIZE (208 * 8 * 1024) // 1664 kB
#define KERNEL_IMAGE_MAXSIZE (512 * 1024) // 512 kB
#define BOARDLOADER_SECTOR_START 0x2
#define BOARDLOADER_SECTOR_END 0x7
#define BOOTLOADER_SECTOR_START 0x8
@ -53,4 +50,14 @@
#define STORAGE_2_SECTOR_START 0x20
#define STORAGE_2_SECTOR_END 0x27
#define KERNEL_U_FLASH_SIZE 512
#define KERNEL_U_RAM_SIZE 512
#define KERNEL_SRAM1_SIZE 16 * 1024
#define KERNEL_SRAM2_SIZE 8 * 1024
#define KERNEL_SRAM3_SIZE 0x38400
#define BOOTARGS_SIZE 0x100
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define CODE_ALIGNMENT 0x200
#endif

View File

@ -1,127 +0,0 @@
/* TREZORv2 firmware linker script */
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 3648K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x300BFF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 0
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
confidential_vma = ADDR(.confidential);
confidential_size = SIZEOF(.confidential);
/* used by the startup code to wipe memory */
sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
sram4_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);
SECTIONS {
.vendorheader : ALIGN(4) {
KEEP(*(.vendorheader))
} >FLASH AT>FLASH
.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(1024) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM1 AT>FLASH
/DISCARD/ : {
*(.ARM.exidx*);
}
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM1
.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
. = ALIGN(4);
} >SRAM1
.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram1_end); /* this explicitly sets the end of the heap */
} >SRAM1
.stack : ALIGN(8) {
. = 16K; /* Overflow causes UsageFault */
} >SRAM2
.confidential : ALIGN(512) {
*(.confidential*);
. = ALIGN(512);
} >SRAM2 AT>FLASH
.fb1 : ALIGN(4) {
__fb_start = .;
*(.fb1*);
*(.gfxmmu_table*);
*(.framebuffer_select*);
. = ALIGN(4);
} >SRAM3
.fb2 : ALIGN(4) {
*(.fb2*);
__fb_end = .;
. = ALIGN(4);
} >SRAM5
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);
*(.boot_args*);
. = ALIGN(8);
} >BOOT_ARGS
}

View File

@ -1,19 +1,23 @@
/* Trezor v2 boardloader linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 48K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = MCU_FLASH_ORIGIN, LENGTH = BOARDLOADER_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE
}
main_stack_base = ORIGIN(CCMRAM) + LENGTH(CCMRAM); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(CCMRAM);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(CCMRAM);
@ -24,7 +28,7 @@ sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
SECTIONS {
.vector_table : ALIGN(512) {
.vector_table : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
} >FLASH AT>FLASH
@ -54,7 +58,7 @@ SECTIONS {
} >SRAM
/* Hard-coded address for capabilities structure */
.capabilities 0x0800BF00 : {KEEP(*(.capabilities_section))}
.capabilities BOARD_CAPABILITIES_ADDR : {KEEP(*(.capabilities_section))}
.stack : ALIGN(8) {
. = 4K; /* this acts as a build time assertion that at least this much memory is available for stack use */

View File

@ -1,12 +1,12 @@
/* Trezor v2 bootloader linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 128K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x1000FF00, LENGTH = 0x100
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = BOOTLOADER_START, LENGTH = BOOTLOADER_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE
}
main_stack_base = ORIGIN(CCMRAM) + SIZEOF(.stack) ; /* 8-byte aligned full descending stack */
@ -17,6 +17,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(CCMRAM);
@ -37,7 +39,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
@ -67,6 +69,8 @@ SECTIONS {
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
*(.no_dma_buffers*);
. = ALIGN(4);
} >SRAM
.boot_args : ALIGN(8) {
@ -74,9 +78,4 @@ SECTIONS {
. = ALIGN(8);
} >BOOT_ARGS
.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
. = ALIGN(4);
} >CCMRAM
}

View File

@ -1,18 +1,18 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 768K
FLASH2 (r) : ORIGIN = 0x08120000, LENGTH = 896K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x1000FF00, LENGTH = 0x100
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_P1_IMAGE_MAXSIZE
FLASH2 (r) : ORIGIN = FIRMWARE_P2_START, LENGTH = FIRMWARE_P2_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE - KERNEL_CCMRAM_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE - KERNEL_SRAM_SIZE
}
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM);
_estack = main_stack_base;
_stack_size = SIZEOF(.stack);
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
@ -23,16 +23,15 @@ data_size = SIZEOF(.data);
ccmram_start = ORIGIN(CCMRAM);
ccmram_end = ORIGIN(CCMRAM) + LENGTH(CCMRAM);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
_ram_start = sram_start;
_ram_end = sram_end;
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
_codelen = LENGTH(FLASH) - SIZEOF(.vendorheader) - SIZEOF(.header) + SIZEOF(.flash2);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
@ -48,12 +47,12 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash2 : ALIGN(512) {
build/firmware/frozen_mpy.o(.rodata*);
build/firmware/vendor/secp256k1-zkp/src/secp256k1.o(.rodata*);
build/firmware/vendor/secp256k1-zkp/src/precomputed_ecmult.o(.rodata*);
build/firmware/vendor/secp256k1-zkp/src/precomputed_ecmult_gen.o(.rodata*);
build/firmware/vendor/trezor-crypto/aes/aestab.o(.rodata*);
.flash2 : ALIGN(CODE_ALIGNMENT) {
build/coreapp/frozen_mpy.o(.rodata*);
build/coreapp/vendor/secp256k1-zkp/src/secp256k1.o(.rodata*);
build/coreapp/vendor/secp256k1-zkp/src/precomputed_ecmult.o(.rodata*);
build/coreapp/vendor/secp256k1-zkp/src/precomputed_ecmult_gen.o(.rodata*);
build/coreapp/vendor/trezor-crypto/aes/aestab.o(.rodata*);
. = ALIGN(4);
*/libtrezor_lib.a:(.text*);
. = ALIGN(4);
@ -62,14 +61,14 @@ SECTIONS {
} >FLASH2 AT>FLASH2
.flash : ALIGN(512) {
KEEP(*(.kernel));
. = ALIGN(512);
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH
@ -102,8 +101,9 @@ SECTIONS {
. = ALIGN(4);
} >CCMRAM
.boot_args : ALIGN(8) {
*(.boot_args*);
. = ALIGN(8);
} >BOOT_ARGS
/DISCARD/ : {
*(.ARM.exidx*);
}
}

View File

@ -1,13 +1,13 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 768K
FLASH2 (r) : ORIGIN = 0x08120000, LENGTH = 896K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x1000FF00, LENGTH = 0x100
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_P1_IMAGE_MAXSIZE
FLASH2 (r) : ORIGIN = FIRMWARE_P2_START, LENGTH = FIRMWARE_P2_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE
}
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -18,6 +18,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(CCMRAM);
@ -61,7 +63,7 @@ SECTIONS {
. = ALIGN(512);
} >FLASH2 AT>FLASH2
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);

View File

@ -1,53 +1,67 @@
/* Trezor v2 bootloader linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 128K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x1000FF00, LENGTH = 0x100
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = KERNEL_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - KERNEL_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = KERNEL_CCMRAM_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM + KERNEL_SRAM_SIZE, LENGTH = KERNEL_SRAM_SIZE
}
main_stack_base = ORIGIN(CCMRAM) + SIZEOF(.stack) ; /* 8-byte aligned full descending stack */
_sstack = ORIGIN(CCMRAM);
main_stack_base = ORIGIN(SRAM) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM);
_estack = main_stack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(CCMRAM);
ccmram_end = ORIGIN(CCMRAM) + LENGTH(CCMRAM);
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data);
/* used by the startup code to wipe memory */
sram_start = ORIGIN(SRAM);
sram_end = ORIGIN(SRAM) + LENGTH(SRAM);
_ram_start = sram_start;
_ram_end = sram_end;
_codelen = SIZEOF(.vendorheader) + SIZEOF(.header) + SIZEOF(.flash) + SIZEOF(.data) ;
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
.vendorheader : ALIGN(4) {
KEEP(*(.vendorheader))
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.header : ALIGN(4) {
. = 1K;
. = ALIGN(CODE_ALIGNMENT);
} >FLASH AT>FLASH
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH
.stack : ALIGN(8) {
. = 16K; /* Exactly 16K allocated for stack. Overflow causes MemManage fault (when using MPU). */
. = 6K; /* Exactly 6k allocated for stack. Overflow causes MemManage fault (when using MPU). */
} >CCMRAM
.data : ALIGN(4) {
@ -55,10 +69,6 @@ SECTIONS {
. = ALIGN(512);
} >CCMRAM AT>FLASH
/DISCARD/ : {
*(.ARM.exidx*);
}
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
@ -67,8 +77,6 @@ SECTIONS {
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
*(.no_dma_buffers*);
. = ALIGN(4);
} >SRAM
.boot_args : ALIGN(8) {
@ -76,4 +84,8 @@ SECTIONS {
. = ALIGN(8);
} >BOOT_ARGS
/DISCARD/ : {
*(.ARM.exidx*);
}
}

View File

@ -0,0 +1,6 @@
MCU_FLASH_ORIGIN = 0x08000000;
MCU_FLASH_SIZE = 2M;
MCU_CCMRAM = 0x10000000;
MCU_CCMRAM_SIZE = 64K;
MCU_SRAM = 0x20000000;
MCU_SRAM_SIZE = 192K;

View File

@ -1,12 +1,12 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32f4/linker/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 768K
CCMRAM (wal) : ORIGIN = 0x10000000, LENGTH = 64K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x1000FF00, LENGTH = 0x100
SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 192K
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_P1_IMAGE_MAXSIZE
CCMRAM (wal) : ORIGIN = MCU_CCMRAM, LENGTH = MCU_CCMRAM_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_CCMRAM + MCU_CCMRAM_SIZE - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM (wal) : ORIGIN = MCU_SRAM, LENGTH = MCU_SRAM_SIZE
}
main_stack_base = ORIGIN(SRAM) + LENGTH(SRAM); /* 8-byte aligned full descending stack */
@ -17,6 +17,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to wipe memory */
ccmram_start = ORIGIN(CCMRAM);
@ -47,7 +49,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
@ -70,11 +72,6 @@ SECTIONS {
. = ALIGN(4);
} >SRAM
.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram_end - 16K); /* this explicitly sets the end of the heap effectively giving the stack at most 16K */
} >SRAM
.stack : ALIGN(8) {
. = 4K; /* this acts as a build time assertion that at least this much memory is available for stack use */
} >SRAM

View File

@ -133,4 +133,4 @@ void secret_prepare_fw(secbool allow_run_with_secret, secbool _trust_all) {
#endif
}
#endif // KERNEL_MODE
#endif // KERNEL_MODE

View File

@ -158,6 +158,14 @@ void syscall_handler(uint32_t *args, uint32_t syscall) {
case SYSCALL_DISPLAY_WAIT_FOR_SYNC: {
display_wait_for_sync();
} break;
case SYSCALL_DISPLAY_FILL: {
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
display_fill(bb);
} break;
case SYSCALL_DISPLAY_COPY_RGB565: {
const gfx_bitblt_t *bb = (const gfx_bitblt_t *)args[0];
display_copy_rgb565(bb);
} break;
#endif
case SYSCALL_DISPLAY_REFRESH: {
display_refresh();

View File

@ -49,6 +49,8 @@ typedef enum {
SYSCALL_DISPLAY_GET_FB_INFO,
SYSCALL_DISPLAY_WAIT_FOR_SYNC,
SYSCALL_DISPLAY_REFRESH,
SYSCALL_DISPLAY_FILL,
SYSCALL_DISPLAY_COPY_RGB565,
SYSCALL_USB_INIT,
SYSCALL_USB_DEINIT,
@ -146,4 +148,4 @@ typedef enum {
} syscall_number_t;
#endif // SYSCALL_NUMBERS_H
#endif // SYSCALL_NUMBERS_H

View File

@ -159,6 +159,15 @@ display_fb_info_t display_get_frame_buffer(void) {
void display_wait_for_sync(void) {
syscall_invoke0(SYSCALL_DISPLAY_WAIT_FOR_SYNC);
}
void display_fill(const gfx_bitblt_t *bb) {
syscall_invoke1((uint32_t)bb, SYSCALL_DISPLAY_FILL);
}
void display_copy_rgb565(const gfx_bitblt_t *bb) {
syscall_invoke1((uint32_t)bb, SYSCALL_DISPLAY_COPY_RGB565);
}
#endif
void display_refresh(void) { syscall_invoke0(SYSCALL_DISPLAY_REFRESH); }

View File

@ -2,6 +2,8 @@
.text
#ifdef KERNEL_MODE
.global memset_reg
.type memset_reg, STT_FUNC
memset_reg:
@ -10,10 +12,13 @@ memset_reg:
// r1 - address of first word following the address in r0 to NOT write (exclusive)
// r2 - word value to be written
// both addresses in r0 and r1 needs to be divisible by 4!
cmp r0, r1
beq .L_loop_end
.L_loop_begin:
str r2, [r0], 4 // store the word in r2 to the address in r0, post-indexed
cmp r0, r1
bne .L_loop_begin
.L_loop_end:
bx lr
// Jump to address given in first argument R0 that points to next's stage's VTOR
@ -112,4 +117,6 @@ shutdown_privileged:
ldr r0, =0
b . // loop forever
#endif
.end

View File

@ -24,14 +24,14 @@
#include "irq.h"
#include "mpu.h"
#ifdef KERNEL_MODE
__IO DISP_MEM_TYPE *const DISPLAY_CMD_ADDRESS =
(__IO DISP_MEM_TYPE *const)((uint32_t)DISPLAY_MEMORY_BASE);
__IO DISP_MEM_TYPE *const DISPLAY_DATA_ADDRESS =
(__IO DISP_MEM_TYPE *const)((uint32_t)DISPLAY_MEMORY_BASE |
(DISPLAY_ADDR_SHIFT << DISPLAY_MEMORY_PIN));
#ifdef KERNEL_MODE
void display_io_init_gpio(void) {
// init peripherals
__HAL_RCC_GPIOE_CLK_ENABLE();

View File

@ -51,8 +51,6 @@ static inline void set_window(const gfx_bitblt_t* bb) {
bb->dst_y + bb->height + 1);
}
#endif // KERNEL_MODE
// For future notice, if we ever want to do a new model using progressive
// rendering.
//
@ -122,3 +120,5 @@ void display_copy_mono4(const gfx_bitblt_t* bb) {
src_row += bb->src_stride / sizeof(*src_row);
}
}
#endif // KERNEL_MODE

View File

@ -31,6 +31,7 @@
#include "consumption_mask.h"
#endif
#ifdef KERNEL_MODE
#if (DISPLAY_RESX != 128) || (DISPLAY_RESY != 64)
#error "Incompatible display resolution"
#endif
@ -38,7 +39,9 @@
// This file implements display driver for monochromatic display V-2864KSWEG01
// with 128x64 resolution connected to CPU via SPI interface.
//
// This type of display is used with T3T1 model (Trezor TS3)
// This type of display is used with T3B1 model (Trezor TS3)
__attribute__((section(".fb1"))) uint8_t framebuf[DISPLAY_RESX * DISPLAY_RESY];
// Display driver context.
typedef struct {
@ -47,7 +50,7 @@ typedef struct {
// SPI driver instance
SPI_HandleTypeDef spi;
// Frame buffer (8-bit Mono)
uint8_t framebuf[DISPLAY_RESX * DISPLAY_RESY];
uint8_t *framebuf;
// Current display orientation (0 or 180)
int orientation_angle;
// Current backlight level ranging from 0 to 255
@ -233,6 +236,7 @@ void display_init(display_content_mode_t mode) {
memset(drv, 0, sizeof(display_driver_t));
drv->backlight_level = 255;
drv->framebuf = framebuf;
if (mode == DISPLAY_RESET_CONTENT) {
OLED_DC_CLK_ENA();
@ -390,29 +394,31 @@ void display_refresh(void) {
display_sync_with_fb(drv);
}
void display_fill(const gfx_bitblt_t *bb) {
display_driver_t *drv = &g_display_driver;
#endif
if (!drv->initialized) {
void display_fill(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();
if (fb.ptr != NULL) {
return;
}
gfx_bitblt_t bb_new = *bb;
bb_new.dst_row = &drv->framebuf[DISPLAY_RESX * bb_new.dst_y];
bb_new.dst_row = &(((uint8_t *)fb.ptr)[DISPLAY_RESX * bb_new.dst_y]);
bb_new.dst_stride = DISPLAY_RESX;
gfx_mono8_fill(&bb_new);
}
void display_copy_mono1p(const gfx_bitblt_t *bb) {
display_driver_t *drv = &g_display_driver;
display_fb_info_t fb = display_get_frame_buffer();
if (!drv->initialized) {
if (fb.ptr != NULL) {
return;
}
gfx_bitblt_t bb_new = *bb;
bb_new.dst_row = &drv->framebuf[DISPLAY_RESX * bb_new.dst_y];
bb_new.dst_row = &(((uint8_t *)fb.ptr)[DISPLAY_RESX * bb_new.dst_y]);
bb_new.dst_stride = DISPLAY_RESX;
gfx_mono8_copy_mono1p(&bb_new);

View File

@ -1,16 +1,16 @@
/* Trezor v2 boardloader linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C004000, LENGTH = 48K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 512K
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = BOARDLOADER_START, LENGTH = BOARDLOADER_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE
SRAM6 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM6_SIZE
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -40,15 +42,13 @@ sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
SECTIONS {
.vector_table : ALIGN(512) {
.vector_table : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
} >FLASH AT>FLASH
@ -108,5 +108,5 @@ SECTIONS {
/* Hard-coded address for capabilities structure */
.capabilities 0x0C00FF00 : {KEEP(*(.capabilities_section))}
.capabilities BOARD_CAPABILITIES_ADDR : {KEEP(*(.capabilities_section))}
}

View File

@ -1,16 +1,16 @@
/* Trezor v2 bootloader linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C010000, LENGTH = 128K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 512K
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = BOOTLOADER_START, LENGTH = BOOTLOADER_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -40,8 +42,6 @@ sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
@ -54,7 +54,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);

View File

@ -1,16 +1,16 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000 + 0x28000, LENGTH = 1664K - 0x28000
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 16K
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000 + 8K, LENGTH = 64K - 8K
SRAM3 (wal) : ORIGIN = 0x30040000 + 0x38400, LENGTH = 512K - 0x38400
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - KERNEL_SRAM1_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE, LENGTH = MCU_SRAM2_SIZE - KERNEL_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3 + KERNEL_SRAM3_SIZE, LENGTH = MCU_SRAM3_SIZE - KERNEL_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = 0K /* not allocated to coreapp */
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -22,6 +22,8 @@ _stack_size = SIZEOF(.stack);
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -41,8 +43,6 @@ sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
@ -61,9 +61,12 @@ SECTIONS {
.header : ALIGN(4) {
KEEP(*(.header));
. = ALIGN(CODE_ALIGNMENT);
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.kernel));
. = ALIGN(512);
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);

View File

@ -1,16 +1,16 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 1664K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 512K
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -40,8 +42,6 @@ sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
@ -62,7 +62,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);

View File

@ -0,0 +1,143 @@
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = KERNEL_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM2 - KERNEL_SRAM1_SIZE, LENGTH = KERNEL_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = KERNEL_SRAM2_SIZE - KERNEL_U_RAM_SIZE
SRAM2_U (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE - KERNEL_U_RAM_SIZE, LENGTH = KERNEL_U_RAM_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = KERNEL_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
ustack_base = ORIGIN(SRAM2_U) + 512;
_sustack = ORIGIN(SRAM2_U) + 256;
_eustack = ustack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
confidential_vma = ADDR(.confidential);
confidential_size = SIZEOF(.confidential);
/* used by the startup code to wipe memory */
sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram2_u_start = ORIGIN(SRAM2_U);
sram2_u_end = ORIGIN(SRAM2_U) + LENGTH(SRAM2_U);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
sram4_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.vendorheader) + SIZEOF(.header) + SIZEOF(.flash) + SIZEOF(.uflash) + SIZEOF(.data) + SIZEOF(.confidential);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_uflash_start = ADDR(.uflash);
_uflash_end = ADDR(.uflash) + SIZEOF(.uflash);
SECTIONS {
.vendorheader : ALIGN(4) {
KEEP(*(.vendorheader))
} >FLASH AT>FLASH
.header : ALIGN(4) {
. = 1K;
. = ALIGN(CODE_ALIGNMENT);
} >FLASH AT>FLASH
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH
.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM1 AT>FLASH
/DISCARD/ : {
*(.ARM.exidx*);
}
.bss : ALIGN(4) {
*(.no_dma_buffers*);
*(.bss*);
. = ALIGN(4);
} >SRAM1
.stack : ALIGN(8) {
. = 6K; /* Overflow causes UsageFault */
} >SRAM2
/* unprivileged data and stack for SAES */
.udata : ALIGN(512) {
*(.udata*);
. = ALIGN(256);
. = 256; /* Overflow causes UsageFault */
} >SRAM2_U
.confidential : ALIGN(512) {
*(.confidential*);
. = ALIGN(CODE_ALIGNMENT);
} >SRAM2 AT>FLASH
.uflash : ALIGN(512) {
*(.uflash*);
. = ALIGN(512);
} >FLASH AT>FLASH
.fb : ALIGN(4) {
__fb_start = .;
*(.fb1*);
*(.fb2*);
*(.framebuffer_select*);
__fb_end = .;
. = ALIGN(4);
} >SRAM3
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM3
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);
*(.boot_args*);
. = ALIGN(8);
} >BOOT_ARGS
}

View File

@ -0,0 +1,18 @@
MCU_FLASH_S_ORIGIN = 0x0C000000;
MCU_FLASH_ORIGIN = 0x08000000;
MCU_FLASH_SIZE = 2M;
MCU_SRAM1 = 0x30000000;
MCU_SRAM1_SIZE = 192K;
MCU_SRAM2 = 0x30030000;
MCU_SRAM2_SIZE = 64K;
MCU_SRAM3 = 0x30040000;
MCU_SRAM3_SIZE = 512K;
MCU_SRAM4 = 0x38000000;
MCU_SRAM4_SIZE = 16K;
MCU_SRAM5 = 0x30080000;
MCU_SRAM5_SIZE = 0K; /* SRAM5 is not available */
MCU_SRAM6 = 0x30080000;
MCU_SRAM6_SIZE = 0K ; /* SRAM6 is not available */

View File

@ -1,16 +1,16 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u58/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 160K
SRAM1 (wal) : ORIGIN = 0x3002C000, LENGTH = 16K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 8K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 0x38400
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = FIRMWARE_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -51,8 +51,6 @@ boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);
SECTIONS {
.vendorheader : ALIGN(4) {
@ -63,7 +61,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
@ -91,7 +89,7 @@ SECTIONS {
} >SRAM1
.stack : ALIGN(8) {
. = 4K; /* Overflow causes UsageFault */
. = 16K; /* Overflow causes UsageFault */
} >SRAM2
.confidential : ALIGN(512) {
@ -103,19 +101,10 @@ SECTIONS {
__fb_start = .;
*(.fb1*);
*(.fb2*);
*(.framebuffer_select*);
__fb_end = .;
. = ALIGN(4);
} >SRAM3
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM3
.heap : ALIGN(4) {
} >SRAM3
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);

View File

@ -1,16 +1,16 @@
/* Trezor v2 boardloader linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u5a/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C004000, LENGTH = 48K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x300BFF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 0K /* 512K on U5G */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = BOARDLOADER_START, LENGTH = BOARDLOADER_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE
SRAM6 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM6_SIZE
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -46,7 +48,7 @@ boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
SECTIONS {
.vector_table : ALIGN(1024) {
.vector_table : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
} >FLASH AT>FLASH
@ -111,5 +113,5 @@ SECTIONS {
/* Hard-coded address for capabilities structure */
.capabilities 0x0C00FF00 : {KEEP(*(.capabilities_section))}
.capabilities BOARD_CAPABILITIES_ADDR : {KEEP(*(.capabilities_section))}
}

View File

@ -1,16 +1,16 @@
/* Trezor v2 bootloader linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u5a/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C010000, LENGTH = 128K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x300BFF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 0
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = BOOTLOADER_START, LENGTH = BOOTLOADER_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = MCU_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = MCU_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -52,7 +54,7 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(1024) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);

View File

@ -1,26 +1,29 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u5a/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 1664K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 192K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x3002FF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x30030000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x30040000, LENGTH = 512K
SRAM5 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = 0x30080000, LENGTH = 0K /* SRAM6 is not available */
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = FIRMWARE_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM1, LENGTH = MCU_SRAM1_SIZE - KERNEL_SRAM1_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE, LENGTH = MCU_SRAM2_SIZE - KERNEL_SRAM2_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3 + KERNEL_SRAM3_SIZE, LENGTH = MCU_SRAM3_SIZE - KERNEL_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = 0K /* not allocated to coreapp */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = 0K /* not allocated to coreapp */
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = 0K /* not allocated to coreapp */
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
_stack_size = SIZEOF(.stack);
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -40,8 +43,6 @@ sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
@ -62,15 +63,14 @@ SECTIONS {
KEEP(*(.header));
} >FLASH AT>FLASH
.flash : ALIGN(512) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.kernel));
. = ALIGN(512);
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH
@ -84,12 +84,8 @@ SECTIONS {
}
.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM1
.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
*(.bss*);
. = ALIGN(4);
} >SRAM1
@ -99,7 +95,7 @@ SECTIONS {
} >SRAM1
.stack : ALIGN(8) {
. = 16K; /* Overflow causes UsageFault */
. = 32K; /* Overflow causes UsageFault */
} >SRAM2
.confidential : ALIGN(512) {
@ -107,12 +103,8 @@ SECTIONS {
. = ALIGN(512);
} >SRAM2 AT>FLASH
.fb : ALIGN(4) {
__fb_start = .;
*(.fb1*);
*(.fb2*);
*(.framebuffer_select*);
__fb_end = .;
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM3

View File

@ -1,26 +1,33 @@
/* TREZORv2 firmware linker script */
INCLUDE "./embed/trezorhal/stm32u5/linker/u5a/memory.ld";
ENTRY(reset_handler)
MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 3648K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - 0x100
BOOT_ARGS (wal) : ORIGIN = 0x300BFF00, LENGTH = 0x100
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 0
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
FLASH (rx) : ORIGIN = KERNEL_START, LENGTH = KERNEL_IMAGE_MAXSIZE
SRAM1 (wal) : ORIGIN = MCU_SRAM2 - KERNEL_SRAM1_SIZE, LENGTH = KERNEL_SRAM1_SIZE - BOOTARGS_SIZE
BOOT_ARGS (wal) : ORIGIN = MCU_SRAM2 - BOOTARGS_SIZE, LENGTH = BOOTARGS_SIZE
SRAM2 (wal) : ORIGIN = MCU_SRAM2, LENGTH = KERNEL_SRAM2_SIZE - KERNEL_U_RAM_SIZE
SRAM2_U (wal) : ORIGIN = MCU_SRAM2 + KERNEL_SRAM2_SIZE - KERNEL_U_RAM_SIZE, LENGTH = KERNEL_U_RAM_SIZE
SRAM3 (wal) : ORIGIN = MCU_SRAM3, LENGTH = KERNEL_SRAM3_SIZE
SRAM5 (wal) : ORIGIN = MCU_SRAM5, LENGTH = MCU_SRAM5_SIZE /* SRAM5 is not available */
SRAM6 (wal) : ORIGIN = MCU_SRAM6, LENGTH = MCU_SRAM6_SIZE
SRAM4 (wal) : ORIGIN = MCU_SRAM4, LENGTH = MCU_SRAM4_SIZE
}
main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2);
_estack = main_stack_base;
ustack_base = ORIGIN(SRAM2_U) + 512;
_sustack = ORIGIN(SRAM2_U) + 256;
_eustack = ustack_base;
/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -32,6 +39,8 @@ sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram2_u_start = ORIGIN(SRAM2_U);
sram2_u_end = ORIGIN(SRAM2_U) + LENGTH(SRAM2_U);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
@ -45,11 +54,12 @@ sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
_codelen = SIZEOF(.vendorheader) + SIZEOF(.header) + SIZEOF(.flash) + SIZEOF(.uflash) + SIZEOF(.data) + SIZEOF(.confidential);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);
_uflash_start = ADDR(.uflash);
_uflash_end = ADDR(.uflash) + SIZEOF(.uflash);
SECTIONS {
.vendorheader : ALIGN(4) {
@ -57,10 +67,11 @@ SECTIONS {
} >FLASH AT>FLASH
.header : ALIGN(4) {
KEEP(*(.header));
. = 1K;
. = ALIGN(CODE_ALIGNMENT);
} >FLASH AT>FLASH
.flash : ALIGN(1024) {
.flash : ALIGN(CODE_ALIGNMENT) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
@ -82,31 +93,32 @@ SECTIONS {
}
.bss : ALIGN(4) {
*(.no_dma_buffers*);
*(.bss*);
. = ALIGN(4);
} >SRAM1
.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
. = ALIGN(4);
*(.buf*);
. = ALIGN(4);
} >SRAM1
.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram1_end); /* this explicitly sets the end of the heap */
} >SRAM1
.stack : ALIGN(8) {
. = 16K; /* Overflow causes UsageFault */
. = 6K; /* Overflow causes UsageFault */
} >SRAM2
/* unprivileged data and stack for SAES */
.udata : ALIGN(512) {
*(.udata*);
. = ALIGN(256);
. = 256; /* Overflow causes UsageFault */
} >SRAM2_U
.confidential : ALIGN(512) {
*(.confidential*);
. = ALIGN(512);
} >SRAM2 AT>FLASH
.uflash : ALIGN(512) {
*(.uflash*);
. = ALIGN(512);
} >FLASH AT>FLASH
.fb1 : ALIGN(4) {
__fb_start = .;
*(.fb1*);
@ -121,6 +133,12 @@ SECTIONS {
. = ALIGN(4);
} >SRAM5
.buf : ALIGN(4) {
*(.buf*);
. = ALIGN(4);
} >SRAM3
.boot_args : ALIGN(8) {
*(.boot_command*);
. = ALIGN(8);

View File

@ -0,0 +1,18 @@
MCU_FLASH_S_ORIGIN = 0x0C000000;
MCU_FLASH_ORIGIN = 0x08000000;
MCU_FLASH_SIZE = 2M;
MCU_SRAM1 = 0x30000000;
MCU_SRAM1_SIZE = 768K;
MCU_SRAM2 = 0x300C0000;
MCU_SRAM2_SIZE = 64K;
MCU_SRAM3 = 0x300D0000;
MCU_SRAM3_SIZE = 832K;
MCU_SRAM4 = 0x38000000;
MCU_SRAM4_SIZE = 16K;
MCU_SRAM5 = 0x301A0000;
MCU_SRAM5_SIZE = 832K;
MCU_SRAM6 = 0x30270000;
MCU_SRAM6_SIZE = 0K ;

View File

@ -21,6 +21,8 @@ _estack = main_stack_base;
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);
bss_start = ADDR(.bss);
bss_end = ADDR(.bss) + SIZEOF(.bss);
/* used by the startup code to populate variables used by the C code */
confidential_lma = LOADADDR(.confidential);
@ -44,7 +46,6 @@ sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);
/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
@ -89,8 +90,6 @@ SECTIONS {
.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
. = ALIGN(4);
*(.buf*);
. = ALIGN(4);
} >SRAM1
.heap : ALIGN(4) {

View File

@ -115,20 +115,19 @@ static void mpu_set_attributes(void) {
#define SECRET_START FLASH_BASE
#define SECRET_SIZE SIZE_16K
#define BOARDLOADER_SIZE SIZE_48K
#define BOARDLOADER_SIZE BOARDLOADER_IMAGE_MAXSIZE
#define BOOTLOADER_SIZE BOOTLOADER_IMAGE_MAXSIZE
#define FIRMWARE_SIZE FIRMWARE_IMAGE_MAXSIZE
#define COREAPP_SIZE (FIRMWARE_IMAGE_MAXSIZE - KERNEL_SIZE)
#define STORAGE_START \
(FLASH_BASE + SECRET_SIZE + BOARDLOADER_SIZE + BOOTLOADER_SIZE)
#define STORAGE_SIZE NORCOW_SECTOR_SIZE* STORAGE_AREAS_COUNT
#if defined STM32U5A9xx
#define SRAM_SIZE SIZE_2496K
#define SRAM_SIZE SRAM1_SIZE + SRAM2_SIZE + SRAM3_SIZE + SRAM5_SIZE
#elif defined STM32U5G9xx
#define SRAM_SIZE (SIZE_2496K + SIZE_512K)
#define SRAM_SIZE SRAM1_SIZE + SRAM2_SIZE + SRAM3_SIZE + SRAM5_SIZE + SRAM6_SIZE
#elif defined STM32U585xx
#define SRAM_SIZE SIZE_768K
#define SRAM_SIZE SRAM1_SIZE + SRAM2_SIZE + SRAM3_SIZE
#else
#error "Unknown MCU"
#endif
@ -161,14 +160,38 @@ static void mpu_set_attributes(void) {
// clang-format on
#define KERNEL_RAM_START (SRAM2_BASE - SIZE_16K)
#define KERNEL_RAM_SIZE (SIZE_24K)
#define KERNEL_RAM_START (SRAM2_BASE - KERNEL_SRAM1_SIZE)
#define KERNEL_RAM_SIZE \
((KERNEL_SRAM1_SIZE + KERNEL_SRAM2_SIZE) - KERNEL_U_RAM_SIZE)
#ifdef SYSCALL_DISPATCH
extern uint32_t _uflash_start;
extern uint32_t _uflash_end;
#define KERNEL_RAM_U_START (KERNEL_RAM_START + KERNEL_RAM_SIZE)
#define KERNEL_RAM_U_SIZE KERNEL_U_RAM_SIZE
#define KERNEL_FLASH_U_START (uint32_t) & _uflash_start
#define KERNEL_FLASH_U_SIZE ((uint32_t) & _uflash_end - KERNEL_FLASH_U_START)
#else
#define KERNEL_RAM_U_START 0
#define KERNEL_RAM_U_SIZE 0
#define KERNEL_FLASH_U_START 0
#define KERNEL_FLASH_U_SIZE 0
#endif
extern uint32_t _codelen;
#define KERNEL_SIZE (uint32_t) & _codelen
#define KERNEL_FLASH_START KERNEL_START
#define KERNEL_FLASH_SIZE (KERNEL_SIZE - KERNEL_U_FLASH_SIZE)
#define COREAPP_FLASH_START (KERNEL_FLASH_START + KERNEL_SIZE)
#define COREAPP_FLASH_SIZE (FIRMWARE_IMAGE_MAXSIZE - KERNEL_SIZE)
#define COREAPP_RAM1_START SRAM1_BASE
#define COREAPP_RAM1_SIZE (SIZE_192K - SIZE_16K)
#define COREAPP_RAM1_SIZE (SRAM1_SIZE - KERNEL_SRAM1_SIZE)
#define COREAPP_RAM2_START (SRAM2_BASE + SIZE_8K)
#define COREAPP_RAM2_SIZE (SRAM_SIZE - (SIZE_192K + SIZE_8K))
#define COREAPP_RAM2_START (SRAM2_BASE + KERNEL_SRAM2_SIZE)
#define COREAPP_RAM2_SIZE (SRAM_SIZE - (SRAM1_SIZE + KERNEL_SRAM2_SIZE))
typedef struct {
// Set if the driver is initialized
@ -207,12 +230,12 @@ static void mpu_init_fixed_regions(void) {
#endif
#if defined(KERNEL)
// REGION ADDRESS SIZE TYPE WRITE UNPRIV
SET_REGION( 0, KERNEL_START, KERNEL_SIZE, FLASH_CODE, NO, NO );
SET_REGION( 1, KERNEL_RAM_START, KERNEL_RAM_SIZE, SRAM, YES, NO );
SET_REGION( 2, COREAPP_START, COREAPP_SIZE, FLASH_CODE, NO, YES );
SET_REGION( 3, COREAPP_RAM1_START, COREAPP_RAM1_SIZE, SRAM, YES, YES );
SET_REGION( 4, COREAPP_RAM2_START, COREAPP_RAM2_SIZE, SRAM, YES, YES );
SET_REGION( 5, GRAPHICS_START, GRAPHICS_SIZE, SRAM, YES, YES );
SET_REGION( 0, KERNEL_FLASH_START, KERNEL_FLASH_SIZE, FLASH_CODE, NO, NO ); // Kernel Code
SET_REGION( 1, KERNEL_RAM_START, KERNEL_RAM_SIZE, SRAM, YES, NO ); // Kernel RAM
SET_REGION( 2, COREAPP_FLASH_START, COREAPP_FLASH_SIZE, FLASH_CODE, NO, YES ); // CoreApp Code
SET_REGION( 3, COREAPP_RAM1_START, COREAPP_RAM1_SIZE, SRAM, YES, YES ); // SRAM1
SET_REGION( 4, COREAPP_RAM2_START, COREAPP_RAM2_SIZE, SRAM, YES, YES ); // SRAM2/3/5
SET_REGION( 5, GRAPHICS_START, GRAPHICS_SIZE, SRAM, YES, YES ); // Frame buffer or display interface
#endif
#if defined(FIRMWARE)
// REGION ADDRESS SIZE TYPE WRITE UNPRIV
@ -283,6 +306,16 @@ mpu_mode_t mpu_reconfig(mpu_mode_t mode) {
HAL_MPU_Disable();
// Region #5 is banked
// clang-format off
switch (mode) {
default:
SET_REGION( 5, GRAPHICS_START, GRAPHICS_SIZE, SRAM, YES, YES ); // Peripherals
break;
}
// clang-format on
// Region #6 is banked
// clang-format off

View File

@ -1,6 +1,8 @@
#include STM32_HAL_H
#include TREZOR_BOARD
#ifdef KERNEL_MODE
#include "common.h"
#include "i2c_bus.h"
#include "irq.h"
@ -1314,3 +1316,5 @@ uint32_t touch_get_event(void) {
return event;
}
#endif

View File

@ -30,6 +30,8 @@
#error "Incompatible display resolution"
#endif
#ifdef KERNEL_MODE
// Display driver instance
display_driver_t g_display_driver = {
.initialized = false,
@ -143,6 +145,8 @@ int display_get_orientation(void) {
return drv->orientation_angle;
}
#endif
void display_fill(const gfx_bitblt_t *bb) {
display_fb_info_t fb = display_get_frame_buffer();

View File

@ -26,6 +26,8 @@
#include <xdisplay.h>
#include "display_internal.h"
#ifdef KERNEL_MODE
// Physical frame buffers in internal SRAM memory
__attribute__((section(".fb1")))
ALIGN_32BYTES(uint32_t physical_frame_buffer_0[PHYSICAL_FRAME_BUFFER_SIZE]);
@ -91,3 +93,5 @@ void display_refresh(void) {
sizeof(physical_frame_buffer_1));
}
}
#endif

View File

@ -68,6 +68,8 @@
#include "display_internal.h"
#include "irq.h"
#ifdef KERNEL_MODE
/* Common Error codes */
#define BSP_ERROR_NONE 0
#define BSP_ERROR_NO_INIT -1
@ -1557,3 +1559,5 @@ int32_t BSP_LCD_Reinit(uint32_t Instance) {
return status;
}
#endif

View File

@ -37,9 +37,7 @@ def configure(
"embed/models/D001/model_D001_layout.c",
]
sources += [
"embed/trezorhal/stm32f4/i2c_bus.c"
]
sources += ["embed/trezorhal/stm32f4/i2c_bus.c"]
if "new_rendering" in features_wanted:
sources += [

View File

@ -18,7 +18,7 @@ def configure(
hw_revision = 0
mcu = "STM32U5A9xx"
linker_script = "stm32u5a"
linker_script = """embed/trezorhal/stm32u5/linker/u5a/{target}.ld"""
stm32u5_common_files(env, defines, sources, paths)
@ -44,9 +44,7 @@ def configure(
"embed/models/D002/model_D002_layout.c",
]
sources += [
"embed/trezorhal/stm32u5/i2c_bus.c"
]
sources += ["embed/trezorhal/stm32u5/i2c_bus.c"]
if "new_rendering" in features_wanted:
sources += [

View File

@ -43,9 +43,7 @@ def configure(
"embed/models/T2T1/compat_settings.c",
]
sources += [
"embed/trezorhal/stm32f4/i2c_bus.c"
]
sources += ["embed/trezorhal/stm32f4/i2c_bus.c"]
if "new_rendering" in features_wanted:
sources += ["embed/trezorhal/xdisplay_legacy.c"]

View File

@ -23,7 +23,7 @@ def configure(
features_available.append("display_mono")
mcu = "STM32U585xx"
linker_script = "stm32u58"
linker_script = """embed/trezorhal/stm32u5/linker/u58/{target}.ld"""
stm32u5_common_files(env, defines, sources, paths)

View File

@ -27,7 +27,7 @@ def configure(
defines += ["XFRAMEBUFFER"]
mcu = "STM32U585xx"
linker_script = "stm32u58"
linker_script = """embed/trezorhal/stm32u5/linker/u58/{target}.ld"""
stm32u5_common_files(env, defines, sources, paths)
@ -47,9 +47,7 @@ def configure(
"embed/models/T3T1/model_T3T1_layout.c",
]
sources += [
"embed/trezorhal/stm32u5/i2c_bus.c"
]
sources += ["embed/trezorhal/stm32u5/i2c_bus.c"]
if "new_rendering" in features_wanted:
sources += ["embed/trezorhal/xdisplay_legacy.c"]

View File

@ -27,7 +27,7 @@ def configure(
defines += ["XFRAMEBUFFER"]
mcu = "STM32U585xx"
linker_script = "stm32u58"
linker_script = """embed/trezorhal/stm32u5/linker/u58/{target}.ld"""
stm32u5_common_files(env, defines, sources, paths)
@ -48,7 +48,7 @@ def configure(
]
sources += [
f"embed/trezorhal/stm32u5/displays/{display}",
"embed/trezorhal/stm32u5/i2c_bus.c"
"embed/trezorhal/stm32u5/i2c_bus.c",
]
if "new_rendering" in features_wanted:

View File

@ -80,4 +80,4 @@ def stm32f4_common_files(env, defines, sources, paths):
]
env.get("ENV")["SUFFIX"] = "stm32f4"
env.get("ENV")["LINKER_SCRIPT"] = "stm32f4"
env.get("ENV")["LINKER_SCRIPT"] = """embed/trezorhal/stm32f4/linker/{target}.ld"""

View File

@ -99,12 +99,12 @@ def get_bindgen_defines(
return ",".join(rest_defs)
def embed_binary(obj_program, env, section, target_, file):
def embed_compressed_binary(obj_program, env, section, target_, file, build):
_in = f"embedded_{section}.bin.deflated"
def redefine_sym(name):
src = (
"_binary_build_firmware_"
f"_binary_build_{build}_"
+ _in.replace("/", "_").replace(".", "_")
+ "_"
+ name
@ -140,3 +140,14 @@ def embed_binary(obj_program, env, section, target_, file):
)
env.Depends(obj_program, compress)
def embed_raw_binary(obj_program, env, section, target_, file):
obj_program.extend(
env.Command(
target=target_,
source=file,
action="$OBJCOPY -I binary -O elf32-littlearm -B arm"
f" --rename-section .data=.{section}" + " $SOURCE $TARGET",
)
)

View File

@ -76,8 +76,9 @@ A Python package that exposes certain functionalities as CLI commands.
`headertool` and `combine_firmware` live here, more may be moved or added.
One additional tool is `layout_parser`, which is used to extract memory layout
information from a model `.h` file.
Additional tools are `layout_parser`, which is used to extract memory layout
information from a model `.h` file, and related tool `lsgen` to generate linker script files
from the model `.h`.
### `alloc.py`

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "trezor_core_tools"
version = "0.1.0"
version = "0.1.1"
description = "Collection of CLI tools for trezor-core development"
authors = ["matejcik <jan.matejek@satoshilabs.com>"]
license = "GPLv3+"
@ -17,4 +17,5 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
headertool = "trezor_core_tools.headertool:cli"
layout_parser = "trezor_core_tools.layout_parser:main"
lsgen = "trezor_core_tools.lsgen:main"
combine_firmware = "trezor_core_tools.combine_firmware:main"

View File

@ -19,3 +19,7 @@ MODELS_DICT = {
def get_layout_for_model(model: str) -> Path:
model = MODELS_DICT.get(model, model)
return MODELS_DIR / model / f"model_{model}.h"
def get_linkerscript_for_model(model: str) -> Path:
model = MODELS_DICT.get(model, model)
return MODELS_DIR / model / f"memory.ld"

View File

@ -19,7 +19,12 @@ SEARCH_PATTERN = r"#define (\w+) (.+?)(?:\s*//.*)?$"
def find_all_values(model: str) -> dict[str, int]:
layout = get_layout_for_model(model)
values = {}
begin = False
for line in open(layout):
if not begin:
if line.startswith("// SHARED"):
begin = True
continue
match = re.match(SEARCH_PATTERN, line)
if match is not None:
name, value = match.groups()

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
from __future__ import annotations
import click
from .common import get_linkerscript_for_model, MODELS_DIR
from .layout_parser import find_all_values
@click.command()
@click.option("--check", is_flag=True)
def main(check: bool) -> None:
models = list(MODELS_DIR.iterdir())
models = [model for model in models if model.is_dir()]
for model in models:
values = find_all_values(model.name)
content = ""
for name, value in values.items():
content += f"{name} = {hex(value)};\n"
if not check:
get_linkerscript_for_model(model.name).write_text(content)
else:
#todo
pass
if __name__ == "__main__":
main()

2
poetry.lock generated
View File

@ -1582,7 +1582,7 @@ url = "python"
[[package]]
name = "trezor-core-tools"
version = "0.1.0"
version = "0.1.1"
description = "Collection of CLI tools for trezor-core development"
optional = false
python-versions = "^3.8"