trezorhal: split memory files, adapt bootloader and loader

pull/25/head
Pavol Rusnak 7 years ago
parent 8d3020bc62
commit efb722cc97
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -42,10 +42,7 @@ testpy: ## run selected unit tests from python-trezor
## build commands:
build: build_firmware build_bootloader build_loader build_unix build_cross ## build all
build_firmware: vendor res build_cross ## build firmware with frozen modules
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS)
build: build_bootloader build_loader build_firmware build_unix build_cross ## build all
build_bootloader: vendor ## build bootloader
$(MAKE) -f Makefile.bootloader $(TREZORHAL_PORT_OPTS)
@ -53,6 +50,9 @@ build_bootloader: vendor ## build bootloader
build_loader: vendor ## build loader
$(MAKE) -f Makefile.loader $(TREZORHAL_PORT_OPTS)
build_firmware: vendor res build_cross ## build firmware with frozen modules
$(MAKE) -f Makefile.firmware $(TREZORHAL_PORT_OPTS)
build_unix: vendor ## build unix port
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix $(UNIX_PORT_OPTS)
@ -61,10 +61,7 @@ build_cross: vendor ## build mpy-cross port
## clean commands:
clean: clean_firmware clean_bootloader clean_loader clean_unix clean_cross ## clean all
clean_firmware: ## clean firmware build
$(MAKE) -f Makefile.firmware clean $(TREZORHAL_PORT_OPTS)
clean: clean_bootloader clean_loader clean_firmware clean_unix clean_cross ## clean all
clean_bootloader: ## clean bootloader build
$(MAKE) -f Makefile.bootloader clean $(TREZORHAL_PORT_OPTS)
@ -72,6 +69,9 @@ clean_bootloader: ## clean bootloader build
clean_loader: ## clean loader build
$(MAKE) -f Makefile.loader clean $(TREZORHAL_PORT_OPTS)
clean_firmware: ## clean firmware build
$(MAKE) -f Makefile.firmware clean $(TREZORHAL_PORT_OPTS)
clean_unix: ## clean unix build
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix clean $(UNIX_PORT_OPTS)
# workaround for relative paths containing ../.. in unix Makefile
@ -82,14 +82,16 @@ clean_cross: ## clean mpy-cross build
## flash commands:
flash_firmware: ## flash firmware using st-flash
st-flash write $(FIRMWARE_BUILD_DIR)/firmware.bin 0x8000000
flash: flash_bootloader flash_loader flash_firmware ## flash everything using st-flash
flash_bootloader: ## flash bootloader using st-flash
st-flash write $(BOOTLOADER_BUILD_DIR)/bootloader.bin 0x8000000
st-flash write $(BOOTLOADER_BUILD_DIR)/bootloader.bin 0x08000000
flash_loader: ## flash loader using st-flash
st-flash write $(LOADER_BUILD_DIR)/loader.bin 0x8000000
st-flash write $(LOADER_BUILD_DIR)/loader.bin 0x08010000
flash_firmware: ## flash firmware using st-flash
st-flash write $(FIRMWARE_BUILD_DIR)/firmware.bin 0x08020000
## openocd debug commands:

@ -122,7 +122,7 @@ CFLAGS += -DSTM32_HAL_H='<stm32f4xx_hal.h>'
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/trezorhal/memory.ld -Map=$@.map --cref
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/bootloader/memory.ld -Map=$@.map --cref
# remove uncalled code from the final image
CFLAGS += -fdata-sections -ffunction-sections

@ -371,7 +371,7 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/trezorhal/memory.ld -Map=$@.map --cref
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/firmware/memory.ld -Map=$@.map --cref
# remove uncalled code from the final image
CFLAGS += -fdata-sections -ffunction-sections

@ -120,7 +120,7 @@ CFLAGS += -DSTM32_HAL_H='<stm32f4xx_hal.h>'
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/trezorhal/memory.ld -Map=$@.map --cref
LDFLAGS = -nostdlib -T $(SRCDIR_FW)/loader/memory.ld -Map=$@.map --cref
# remove uncalled code from the final image
CFLAGS += -fdata-sections -ffunction-sections

@ -128,6 +128,9 @@ int main(void)
BOOTLOADER_PRINTLN("=================");
BOOTLOADER_PRINTLN("starting bootloader");
// TODO: remove debug
jump_to(LOADER_START);
if (check_sdcard()) {
if (!copy_sdcard()) {
__fatal_error("halt");
@ -140,7 +143,7 @@ int main(void)
if (check_signature((const uint8_t *)LOADER_START)) {
BOOTLOADER_PRINTLN("valid loader signature");
BOOTLOADER_PRINTLN("JUMP!");
jump_to(LOADER_START);
jump_to(LOADER_START + 256);
} else {
BOOTLOADER_PRINTLN("invalid loader signature");
}

@ -6,7 +6,7 @@
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
}

@ -0,0 +1,92 @@
/*
TREZORv2 linker script
based on common.ld and stm32f405.ld
*/
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 896K
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(4);
_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(4);
_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 */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2001c000; /* tunable */

@ -0,0 +1,92 @@
/*
TREZORv2 linker script
based on common.ld and stm32f405.ld
*/
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 64K
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(4);
_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(4);
_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 */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2001c000; /* tunable */
Loading…
Cancel
Save