diff --git a/SConscript.boardloader b/SConscript.boardloader index 77f03ad200..725db3cc6a 100644 --- a/SConscript.boardloader +++ b/SConscript.boardloader @@ -86,6 +86,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -109,7 +110,7 @@ env.Replace( 'vendor/micropython/lib/cmsis/inc', ] + CPPPATH_MOD, CPPDEFINES=[ - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'STM32F427xx', 'USE_HAL_DRIVER', ('STM32_HAL_H', '""'), diff --git a/SConscript.bootloader b/SConscript.bootloader index 79c5befb2a..601a792afb 100644 --- a/SConscript.bootloader +++ b/SConscript.bootloader @@ -107,6 +107,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -131,7 +132,7 @@ env.Replace( 'vendor/micropython/lib/cmsis/inc', ] + CPPPATH_MOD, CPPDEFINES=[ - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'STM32F427xx', 'USE_HAL_DRIVER', ('STM32_HAL_H', '""'), diff --git a/SConscript.firmware b/SConscript.firmware index 6190598136..e7c956e53a 100644 --- a/SConscript.firmware +++ b/SConscript.firmware @@ -300,6 +300,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -311,7 +312,7 @@ env.Replace( '-fstack-protector-all ' + CCFLAGS_MOD, CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', - LINKFLAGS='-T embed/firmware/memory.ld -Wl,--gc-sections -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common', + LINKFLAGS='-T embed/firmware/memory_${TREZOR_MODEL}.ld -Wl,--gc-sections -Wl,-Map=build/firmware/firmware.map -Wl,--warn-common', CPPPATH=[ '.', 'embed/firmware', @@ -324,7 +325,7 @@ env.Replace( 'vendor/micropython/ports/stm32', ] + CPPPATH_MOD, CPPDEFINES=[ - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'STM32F427xx', 'USE_HAL_DRIVER', ('STM32_HAL_H', '""'), diff --git a/SConscript.prodtest b/SConscript.prodtest index 415ae8514b..86e5854c9a 100644 --- a/SConscript.prodtest +++ b/SConscript.prodtest @@ -76,6 +76,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -98,7 +99,7 @@ env.Replace( 'vendor/micropython/ports/stm32', ] + CPPPATH_MOD, CPPDEFINES=[ - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'STM32F427xx', ('STM32_HAL_H', '""'), ] + CPPDEFINES_MOD, diff --git a/SConscript.reflash b/SConscript.reflash index be2d88fc65..981eaac7ad 100644 --- a/SConscript.reflash +++ b/SConscript.reflash @@ -76,6 +76,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -98,7 +99,7 @@ env.Replace( 'vendor/micropython/ports/stm32', ] + CPPPATH_MOD, CPPDEFINES=[ - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'STM32F427xx', ('STM32_HAL_H', '""'), ] + CPPDEFINES_MOD, diff --git a/SConscript.unix b/SConscript.unix index a68da8011b..e3d548f7b7 100644 --- a/SConscript.unix +++ b/SConscript.unix @@ -249,6 +249,7 @@ env.Replace( OBJCOPY='objcopy', ) env.Replace( + TREZOR_MODEL=env.get('ENV').get('TREZOR_MODEL', 'T'), COPT=env.get('ENV').get('OPTIMIZE', '-Os'), CCFLAGS='$COPT ' '-g3 ' @@ -266,7 +267,7 @@ env.Replace( ] + CPPPATH_MOD, CPPDEFINES=[ 'TREZOR_EMULATOR', - ('TREZOR_MODEL', 'T'), + ('TREZOR_MODEL', '$TREZOR_MODEL'), 'MICROPY_USE_READLINE', ('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'), ] + CPPDEFINES_MOD, diff --git a/embed/firmware/memory_1.ld b/embed/firmware/memory_1.ld new file mode 100644 index 0000000000..6036086395 --- /dev/null +++ b/embed/firmware/memory_1.ld @@ -0,0 +1,66 @@ +/* TREZORv1 firmware linker script */ + +ENTRY(reset_handler) + +MEMORY { + FLASH (rx) : ORIGIN = 0x08040000, LENGTH = 768K + SRAM (wal) : ORIGIN = 0x20000000, LENGTH = 128K +} + +main_stack_base = ORIGIN(SRAM) + LENGTH(SRAM); /* 8-byte aligned full descending stack */ +_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 */ +ccmram_start = 0; +ccmram_end = 0; + +/* 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 = LENGTH(FLASH) - SIZEOF(.header); +_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 + + .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 - 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 +} diff --git a/embed/firmware/memory.ld b/embed/firmware/memory_T.ld similarity index 100% rename from embed/firmware/memory.ld rename to embed/firmware/memory_T.ld