1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-07 13:12:41 +00:00

refactor(core): rename linker script section constants

[no changelog]
This commit is contained in:
cepetr 2025-01-29 21:34:20 +01:00 committed by cepetr
parent 2671404e44
commit 7613fe310a
24 changed files with 202 additions and 180 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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
// --------------------------------------------------------------