From 9019ec7e2b1cf489a88430b9ccc92b2c8df3ccb5 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 25 Sep 2017 15:49:42 +0200 Subject: [PATCH] build: add firmware0 target (firmware with no headers) --- Makefile | 5 +++ SConscript.firmware | 15 +++++++ embed/firmware/memory0.ld | 93 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 embed/firmware/memory0.ld diff --git a/Makefile b/Makefile index 5791ced01..4a6e0bbea 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ build_bootloader: ## build bootloader build_firmware: res build_cross ## build firmware with frozen modules $(SCONS) CFLAGS="$(CFLAGS)" build/firmware/firmware.bin + $(SCONS) CFLAGS="$(CFLAGS)" build/firmware/firmware0.bin build_unix: ## build unix port $(SCONS) build/unix/micropython $(UNIX_PORT_OPTS) @@ -114,6 +115,9 @@ flash_bootloader: ## flash bootloader using st-flash flash_firmware: ## flash firmware using st-flash st-flash write $(FIRMWARE_BUILD_DIR)/firmware.bin 0x08020000 +flash_firmware0: ## flash firmware0 using st-flash + st-flash write $(FIRMWARE_BUILD_DIR)/firmware0.bin 0x08000000 + flash_combine: ## flash combined image using st-flash st-flash write $(FIRMWARE_BUILD_DIR)/combined.bin 0x08000000 @@ -144,6 +148,7 @@ sizecheck: ## check sizes of binary files test 32768 -ge $(shell stat -c%s $(BOARDLOADER_BUILD_DIR)/boardloader.bin) test 65536 -ge $(shell stat -c%s $(BOOTLOADER_BUILD_DIR)/bootloader.bin) test 917504 -ge $(shell stat -c%s $(FIRMWARE_BUILD_DIR)/firmware.bin) + test 1048576 -ge $(shell stat -c%s $(FIRMWARE_BUILD_DIR)/firmware0.bin) combine: ## combine boardloader + bootloader + firmware into one combined image ./tools/combine_firmware \ diff --git a/SConscript.firmware b/SConscript.firmware index 2b059b4ad..6547b1a75 100644 --- a/SConscript.firmware +++ b/SConscript.firmware @@ -326,6 +326,7 @@ env.Replace( CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB', CCFLAGS_OPT='-O3', LINKFLAGS='-nostdlib -T embed/firmware/memory.ld --gc-sections', + LINKFLAGS0='-nostdlib -T embed/firmware/memory0.ld --gc-sections', CPPPATH=[ '.', 'embed/firmware', @@ -421,6 +422,13 @@ program_elf = env.Command( '$LINK -o $TARGET $LINKFLAGS $SOURCES `$CC $CFLAGS $CCFLAGS $_CCCOMCOM -print-libgcc-file-name`', ) +program0_elf = env.Command( + target='firmware0.elf', + source=obj_program, + action= + '$LINK -o $TARGET $LINKFLAGS0 $SOURCES `$CC $CFLAGS $CCFLAGS $_CCCOMCOM -print-libgcc-file-name`', +) + program_bin = env.Command( target='firmware.bin', source=program_elf, @@ -428,3 +436,10 @@ program_bin = env.Command( '$OBJCOPY -O binary -j .header -j .flash -j .data $SOURCE $TARGET', '$BINCTL $TARGET -s 1 4141414141414141414141414141414141414141414141414141414141414141', ], ) + +program0_bin = env.Command( + target='firmware0.bin', + source=program0_elf, + action=[ + '$OBJCOPY -O binary -j .flash -j .data $SOURCE $TARGET', + ], ) diff --git a/embed/firmware/memory0.ld b/embed/firmware/memory0.ld new file mode 100644 index 000000000..1302641b1 --- /dev/null +++ b/embed/firmware/memory0.ld @@ -0,0 +1,93 @@ +/* + TREZORv2 linker script + based on common.ld and stm32f405.ld +*/ + +/* Specify the memory areas */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K + CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K +} + +/* produce a link error if there is not this amount of RAM for these sections */ +_minimum_stack_size = 2K; +_minimum_heap_size = 16K; + +/* Define tho top end of the stack. The stack is full descending so begins just + above last byte of RAM. Note that EABI requires the stack to be 8-byte + aligned for a call. */ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +ENTRY(Reset_Handler) + +/* define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .flash : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + *(.text*) /* .text* sections (code) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(512); + _etext = .; /* define a global symbol at end of code */ + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* This is the initialized data section + The program executes knowing that the data is in the RAM + but the loader puts the initial values in the FLASH (inidata). + It is one task of the startup to copy the initial values from FLASH to RAM. */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */ + *(.data*) /* .data* sections */ + + . = ALIGN(512); + _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ + } >RAM AT> FLASH + + /* Uninitialized data section */ + .bss : + { + . = ALIGN(4); + _sbss = .; /* define a global symbol at bss start; used by startup code */ + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end; used by startup code and GC */ + } >RAM + + /* this is to define the start of the heap, and make sure we have a minimum size */ + .heap : + { + . = ALIGN(4); + . = . + _minimum_heap_size; + . = ALIGN(4); + } >RAM + + /* this just checks there is enough RAM for the stack */ + .stack : + { + . = ALIGN(4); + . = . + _minimum_stack_size; + . = ALIGN(4); + } >RAM + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + +/* RAM extents for the garbage collector */ +_codelen = SIZEOF(.flash) + SIZEOF(.data); +_ram_start = ORIGIN(RAM); +_ram_end = ORIGIN(RAM) + LENGTH(RAM); +_heap_start = _ebss; /* heap starts just after statically allocated memory */ +_heap_end = 0x2001c000; /* tunable */