diff --git a/core/embed/sys/linker/stm32f4/boardloader.ld b/core/embed/sys/linker/stm32f4/boardloader.ld index a12041c2a3..720d77db06 100644 --- a/core/embed/sys/linker/stm32f4/boardloader.ld +++ b/core/embed/sys/linker/stm32f4/boardloader.ld @@ -14,12 +14,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + SIZEOF(.data); + +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = 0; +_confidential_section_start = 0; +_confidential_section_end = 0; /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_CCMRAM; diff --git a/core/embed/sys/linker/stm32f4/bootloader.ld b/core/embed/sys/linker/stm32f4/bootloader.ld index 5b3b66e619..8963fd6ac7 100644 --- a/core/embed/sys/linker/stm32f4/bootloader.ld +++ b/core/embed/sys/linker/stm32f4/bootloader.ld @@ -14,12 +14,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + SIZEOF(.data); + +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = 0; +_confidential_section_start = 0; +_confidential_section_end = 0; /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_CCMRAM; diff --git a/core/embed/sys/linker/stm32f4/firmware.ld b/core/embed/sys/linker/stm32f4/firmware.ld index cf27f7f442..46da6431e9 100644 --- a/core/embed/sys/linker/stm32f4/firmware.ld +++ b/core/embed/sys/linker/stm32f4/firmware.ld @@ -13,13 +13,16 @@ _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + SIZEOF(.stack); _stack_section_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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + SIZEOF(.data); -bss_start = ADDR(.bss); -bss_end = ADDR(.bss) + SIZEOF(.bss); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = 0; +_confidential_section_start = 0; +_confidential_section_end = 0; _codelen = LENGTH(FLASH) - SIZEOF(.vendorheader) - SIZEOF(.header) + SIZEOF(.flash2); _heap_start = ADDR(.heap); diff --git a/core/embed/sys/linker/stm32f4/kernel.ld b/core/embed/sys/linker/stm32f4/kernel.ld index 001a01f3a2..0d05aa6c74 100644 --- a/core/embed/sys/linker/stm32f4/kernel.ld +++ b/core/embed/sys/linker/stm32f4/kernel.ld @@ -14,12 +14,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + SIZEOF(.data); + +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = 0; +_confidential_section_start = 0; +_confidential_section_end = 0; /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_CCMRAM; diff --git a/core/embed/sys/linker/stm32f4/prodtest.ld b/core/embed/sys/linker/stm32f4/prodtest.ld index ecf0a94ed4..20f27efbc2 100644 --- a/core/embed/sys/linker/stm32f4/prodtest.ld +++ b/core/embed/sys/linker/stm32f4/prodtest.ld @@ -14,12 +14,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + SIZEOF(.data); + +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = 0; +_confidential_section_start = 0; +_confidential_section_end = 0; /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_CCMRAM; diff --git a/core/embed/sys/linker/stm32u58/boardloader.ld b/core/embed/sys/linker/stm32u58/boardloader.ld index df21f7c8cb..e3ae88f15b 100644 --- a/core/embed/sys/linker/stm32u58/boardloader.ld +++ b/core/embed/sys/linker/stm32u58/boardloader.ld @@ -17,17 +17,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/linker/stm32u58/bootloader.ld b/core/embed/sys/linker/stm32u58/bootloader.ld index d140114c41..297e0b4c1e 100644 --- a/core/embed/sys/linker/stm32u58/bootloader.ld +++ b/core/embed/sys/linker/stm32u58/bootloader.ld @@ -16,17 +16,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/linker/stm32u58/firmware.ld b/core/embed/sys/linker/stm32u58/firmware.ld index 212ad22bff..6f6223fc2b 100644 --- a/core/embed/sys/linker/stm32u58/firmware.ld +++ b/core/embed/sys/linker/stm32u58/firmware.ld @@ -12,17 +12,16 @@ _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + SIZEOF(.stack); _stack_section_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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); _codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential); _flash_start = ORIGIN(FLASH); diff --git a/core/embed/sys/linker/stm32u58/kernel.ld b/core/embed/sys/linker/stm32u58/kernel.ld index 4a0fd08e7c..09e685c1b9 100644 --- a/core/embed/sys/linker/stm32u58/kernel.ld +++ b/core/embed/sys/linker/stm32u58/kernel.ld @@ -19,17 +19,16 @@ ustack_base = ADDR(.udata) + 512; _sustack = ADDR(.udata) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/linker/stm32u58/prodtest.ld b/core/embed/sys/linker/stm32u58/prodtest.ld index 985e71a706..0ae7d5cede 100644 --- a/core/embed/sys/linker/stm32u58/prodtest.ld +++ b/core/embed/sys/linker/stm32u58/prodtest.ld @@ -16,17 +16,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/linker/stm32u5g/boardloader.ld b/core/embed/sys/linker/stm32u5g/boardloader.ld index ce6be59f39..9128b3c72e 100644 --- a/core/embed/sys/linker/stm32u5g/boardloader.ld +++ b/core/embed/sys/linker/stm32u5g/boardloader.ld @@ -17,17 +17,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1 + BOOTARGS_SIZE; diff --git a/core/embed/sys/linker/stm32u5g/bootloader.ld b/core/embed/sys/linker/stm32u5g/bootloader.ld index aafcd5ea0b..1e0799c974 100644 --- a/core/embed/sys/linker/stm32u5g/bootloader.ld +++ b/core/embed/sys/linker/stm32u5g/bootloader.ld @@ -16,18 +16,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1 + BOOTARGS_SIZE; _startup_clear_ram_0_end = MCU_SRAM1 + MCU_SRAM1_SIZE; diff --git a/core/embed/sys/linker/stm32u5g/firmware.ld b/core/embed/sys/linker/stm32u5g/firmware.ld index a806612422..de559d22e0 100644 --- a/core/embed/sys/linker/stm32u5g/firmware.ld +++ b/core/embed/sys/linker/stm32u5g/firmware.ld @@ -11,17 +11,16 @@ _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + SIZEOF(.stack); _stack_section_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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); _codelen = SIZEOF(.padding) + SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.confidential); _flash_start = ORIGIN(FLASH); diff --git a/core/embed/sys/linker/stm32u5g/kernel.ld b/core/embed/sys/linker/stm32u5g/kernel.ld index 924413bd27..b212a23dc1 100644 --- a/core/embed/sys/linker/stm32u5g/kernel.ld +++ b/core/embed/sys/linker/stm32u5g/kernel.ld @@ -20,17 +20,16 @@ ustack_base = ADDR(.udata) + 512; _sustack = ADDR(.udata) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/linker/stm32u5g/prodtest.ld b/core/embed/sys/linker/stm32u5g/prodtest.ld index 17190dcfcf..ca1e757d52 100644 --- a/core/embed/sys/linker/stm32u5g/prodtest.ld +++ b/core/embed/sys/linker/stm32u5g/prodtest.ld @@ -16,17 +16,16 @@ MEMORY { _stack_section_start = ADDR(.stack); _stack_section_end = ADDR(.stack) + 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); +_data_section_loadaddr = LOADADDR(.data); +_data_section_start = ADDR(.data); +_data_section_end = ADDR(.data) + 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); +_bss_section_start = ADDR(.bss); +_bss_section_end = ADDR(.bss) + SIZEOF(.bss); + +_confidential_section_loadaddr = LOADADDR(.confidential); +_confidential_section_start = ADDR(.confidential); +_confidential_section_end = ADDR(.confidential) + SIZEOF(.confidential); /* used by the startup code to wipe memory */ _startup_clear_ram_0_start = MCU_SRAM1; diff --git a/core/embed/sys/startup/stm32f4/startup_stage_0.s b/core/embed/sys/startup/stm32f4/startup_stage_0.s index 5659f009f3..0f244b9c5c 100644 --- a/core/embed/sys/startup/stm32f4/startup_stage_0.s +++ b/core/embed/sys/startup/stm32f4/startup_stage_0.s @@ -38,9 +38,10 @@ reset_handler: 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") diff --git a/core/embed/sys/startup/stm32f4/startup_stage_1.s b/core/embed/sys/startup/stm32f4/startup_stage_1.s index fba58a7025..adc977605a 100644 --- a/core/embed/sys/startup/stm32f4/startup_stage_1.s +++ b/core/embed/sys/startup/stm32f4/startup_stage_1.s @@ -15,9 +15,10 @@ reset_handler: 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value diff --git a/core/embed/sys/startup/stm32f4/startup_stage_2.s b/core/embed/sys/startup/stm32f4/startup_stage_2.s index 8a275704ed..8805d4f0d2 100644 --- a/core/embed/sys/startup/stm32f4/startup_stage_2.s +++ b/core/embed/sys/startup/stm32f4/startup_stage_2.s @@ -13,11 +13,12 @@ reset_handler: ldr r0, =_startup_clear_ram_1_start ldr r1, =_startup_clear_ram_1_end 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value diff --git a/core/embed/sys/startup/stm32f4/startup_stage_4.s b/core/embed/sys/startup/stm32f4/startup_stage_4.s index d1a921abb3..683cf3a3f7 100644 --- a/core/embed/sys/startup/stm32f4/startup_stage_4.s +++ b/core/embed/sys/startup/stm32f4/startup_stage_4.s @@ -12,16 +12,17 @@ reset_handler: ldr r0, = __stack_chk_guard str r2, [r0] - ldr r0, =bss_start + ldr r0, =_bss_section_start ldr r1, =0 - ldr r2, =bss_end + ldr r2, =_bss_section_end sub r2, r2, r0 bl memset // copy data in from flash - ldr r0, =data_vma // dst addr - ldr r1, =data_lma // src addr - ldr r2, =data_size // size in bytes + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end + sub r2, r2, r0 // size in bytes bl memcpy pop {r0, r1} diff --git a/core/embed/sys/startup/stm32u5/startup_stage_0.s b/core/embed/sys/startup/stm32u5/startup_stage_0.s index 7c27989319..baa68ccbfe 100644 --- a/core/embed/sys/startup/stm32u5/startup_stage_0.s +++ b/core/embed/sys/startup/stm32u5/startup_stage_0.s @@ -55,15 +55,17 @@ clear_ram: 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // copy confidential data in from flash - ldr r0, =confidential_vma // dst addr - ldr r1, =confidential_lma // src addr - ldr r2, =confidential_size // size in bytes + ldr r0, =_confidential_section_start // dst addr + ldr r1, =_confidential_section_loadaddr // src addr + ldr r2, =_confidential_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value diff --git a/core/embed/sys/startup/stm32u5/startup_stage_1.s b/core/embed/sys/startup/stm32u5/startup_stage_1.s index e8e0ed37e4..72c3eef2d5 100644 --- a/core/embed/sys/startup/stm32u5/startup_stage_1.s +++ b/core/embed/sys/startup/stm32u5/startup_stage_1.s @@ -23,15 +23,17 @@ reset_handler: 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // copy confidential data in from flash - ldr r0, =confidential_vma // dst addr - ldr r1, =confidential_lma // src addr - ldr r2, =confidential_size // size in bytes + ldr r0, =_confidential_section_start // dst addr + ldr r1, =_confidential_section_loadaddr // src addr + ldr r2, =_confidential_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value diff --git a/core/embed/sys/startup/stm32u5/startup_stage_2.s b/core/embed/sys/startup/stm32u5/startup_stage_2.s index 20355ff8ed..c3acb8ab7d 100644 --- a/core/embed/sys/startup/stm32u5/startup_stage_2.s +++ b/core/embed/sys/startup/stm32u5/startup_stage_2.s @@ -23,15 +23,17 @@ reset_handler: 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 + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // copy confidential data in from flash - ldr r0, =confidential_vma // dst addr - ldr r1, =confidential_lma // src addr - ldr r2, =confidential_size // size in bytes + ldr r0, =_confidential_section_start // dst addr + ldr r1, =_confidential_section_loadaddr // src addr + ldr r2, =_confidential_section_end // size in bytes + sub r2, r2, r0 bl memcpy // setup the stack protector (see build script "-fstack-protector-all") with an unpredictable value diff --git a/core/embed/sys/startup/stm32u5/startup_stage_4.s b/core/embed/sys/startup/stm32u5/startup_stage_4.s index cc26b7470b..04c8819366 100644 --- a/core/embed/sys/startup/stm32u5/startup_stage_4.s +++ b/core/embed/sys/startup/stm32u5/startup_stage_4.s @@ -12,22 +12,24 @@ reset_handler: ldr r0, = __stack_chk_guard str r2, [r0] - ldr r0, =bss_start + ldr r0, =_bss_section_start ldr r1, =0 - ldr r2, =bss_end + ldr r2, =_bss_section_end sub r2, r2, r0 bl memset // copy data in from flash - ldr r0, =data_vma - ldr r1, =data_lma - ldr r2, =data_size + ldr r0, =_data_section_start // dst addr + ldr r1, =_data_section_loadaddr // src addr + ldr r2, =_data_section_end // size in bytes + sub r2, r2, r0 bl memcpy // copy confidential data in from flash - ldr r0, =confidential_vma - ldr r1, =confidential_lma - ldr r2, =confidential_size + ldr r0, =_confidential_section_start // dst addr + ldr r1, =_confidential_section_loadaddr // src addr + ldr r2, =_confidential_section_end // size in bytes + sub r2, r2, r0 bl memcpy pop {r0, r1} diff --git a/core/embed/sys/task/stm32/system.c b/core/embed/sys/task/stm32/system.c index 4fbb91c0c9..1231a4d2aa 100644 --- a/core/embed/sys/task/stm32/system.c +++ b/core/embed/sys/task/stm32/system.c @@ -232,22 +232,24 @@ __attribute((naked, no_stack_protector)) void system_emergency_rescue( // Clear .bss, initialize .data, ... // -------------------------------------------------------------- - "LDR R0, =bss_start \n" // Clear .bss + "LDR R0, =_bss_section_start \n" // Clear .bss "MOV R1, #0 \n" - "LDR R2, =bss_end \n" + "LDR R2, =_bss_section_end \n" "SUB R2, R2, R0 \n" "BL memset \n" - "LDR R0, =data_vma \n" // Initialize .data - "LDR R1, =data_lma \n" - "LDR R2, =data_size \n" + "LDR R0, =_data_section_start \n" // Initialize .data + "LDR R1, =_data_section_loadaddr \n" + "LDR R2, =_data_section_end \n" + "SUB R2, R2, R0 \n" "BL memcpy \n" #ifdef STM32U5 - "LDR R0, =confidential_vma \n" // Initialize .confidental - "LDR R1, =confidential_lma \n" - "LDR R2, =confidential_size \n" - "BL memcpy \n" + "LDR R0, =_confidential_section_start \n" // Initialize .confidental + "LDR R1, =_confidential_section_loadaddr \n" + "LDR R2, =_confidential_section_end \n" + "SUB R2, R2, R0 \n" + "BL memcpy \n" #endif // --------------------------------------------------------------