From 4099a60d6b15eae1ee7c7ef702c8ad34f18eb948 Mon Sep 17 00:00:00 2001 From: Maarten van der Schrieck Date: Wed, 8 Nov 2023 12:46:58 +0100 Subject: [PATCH 1/2] *.ld: updated to match memmap_default.ld (on which they are based) again --- bootloader_shell.ld | 21 ++++++++++----------- standalone.ld | 21 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/bootloader_shell.ld b/bootloader_shell.ld index fcb5ffc..3c3b3c6 100644 --- a/bootloader_shell.ld +++ b/bootloader_shell.ld @@ -142,10 +142,7 @@ SECTIONS __binary_info_end = .; . = ALIGN(4); - /* End of .text-like segments */ - __etext = .; - - .ram_vector_table (COPY): { + .ram_vector_table (NOLOAD): { *(.ram_vector_table) } > RAM @@ -198,8 +195,10 @@ SECTIONS /* All data end */ __data_end__ = .; } > RAM AT> FLASH + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); - .uninitialized_data (COPY): { + .uninitialized_data (NOLOAD): { . = ALIGN(4); *(.uninitialized_data*) } > RAM @@ -230,11 +229,11 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (COPY): + .heap (NOLOAD): { __end__ = .; end = __end__; - *(.heap*) + KEEP(*(.heap*)) __HeapLimit = .; } > RAM @@ -247,17 +246,17 @@ SECTIONS /* by default we put core 0 stack at the end of scratch Y, so that if core 1 * stack is not used then all of SCRATCH_X is free. */ - .stack1_dummy (COPY): + .stack1_dummy (NOLOAD): { *(.stack1*) } > SCRATCH_X - .stack_dummy (COPY): + .stack_dummy (NOLOAD): { - *(.stack*) + KEEP(*(.stack*)) } > SCRATCH_Y .flash_end : { - __flash_binary_end = .; + PROVIDE(__flash_binary_end = .); } > FLASH /* stack limit is poorly named, but historically is maximum heap ptr */ diff --git a/standalone.ld b/standalone.ld index 040f6ad..7c968f6 100644 --- a/standalone.ld +++ b/standalone.ld @@ -99,10 +99,7 @@ SECTIONS __binary_info_end = .; . = ALIGN(4); - /* End of .text-like segments */ - __etext = .; - - .ram_vector_table (COPY): { + .ram_vector_table (NOLOAD): { *(.ram_vector_table) } > RAM @@ -155,8 +152,10 @@ SECTIONS /* All data end */ __data_end__ = .; } > RAM AT> FLASH + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); - .uninitialized_data (COPY): { + .uninitialized_data (NOLOAD): { . = ALIGN(4); *(.uninitialized_data*) } > RAM @@ -187,11 +186,11 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (COPY): + .heap (NOLOAD): { __end__ = .; end = __end__; - *(.heap*) + KEEP(*(.heap*)) __HeapLimit = .; } > RAM @@ -204,17 +203,17 @@ SECTIONS /* by default we put core 0 stack at the end of scratch Y, so that if core 1 * stack is not used then all of SCRATCH_X is free. */ - .stack1_dummy (COPY): + .stack1_dummy (NOLOAD): { *(.stack1*) } > SCRATCH_X - .stack_dummy (COPY): + .stack_dummy (NOLOAD): { - *(.stack*) + KEEP(*(.stack*)) } > SCRATCH_Y .flash_end : { - __flash_binary_end = .; + PROVIDE(__flash_binary_end = .); } > FLASH /* stack limit is poorly named, but historically is maximum heap ptr */ From ab7cef858b92ec906a1b8ae4283fe22f133cc777 Mon Sep 17 00:00:00 2001 From: Maarten van der Schrieck Date: Wed, 8 Nov 2023 13:57:31 +0100 Subject: [PATCH 2/2] picowota: tweak ld scripts for fix strange issue in picowota binary generation The objcopy step that updates sections with binary data failed because of an error with sections now marked NOLOAD instead of COPY. The error disappeared with moving section .uninitialized_data to near .ram_vector_table, which somehow triggered adding a section that reserved a piece of RAM (which is fine) with reference to a flash area (which is strange). Note that these uninitialized sections are explicitly requested by __uninitialized_ram() directives: pico-sdk/src/rp2_common/pico_platform/include/pico/platform.h: #define __uninitialized_ram(group) __attribute__((section(".uninitialized_data." #group))) group Their use is to keep ram uninitialized on purpose, to collect entropy (for RNG) or data left over from before reset. --- bootloader_shell.ld | 12 ++++++------ standalone.ld | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bootloader_shell.ld b/bootloader_shell.ld index 3c3b3c6..e012fcb 100644 --- a/bootloader_shell.ld +++ b/bootloader_shell.ld @@ -142,10 +142,15 @@ SECTIONS __binary_info_end = .; . = ALIGN(4); - .ram_vector_table (NOLOAD): { + .ram_vector_table (NOLOAD): { *(.ram_vector_table) } > RAM + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + .data : { __data_start__ = .; *(vtable) @@ -198,11 +203,6 @@ SECTIONS /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ __etext = LOADADDR(.data); - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* Start and end symbols must be word-aligned */ .scratch_x : { __scratch_x_start__ = .; diff --git a/standalone.ld b/standalone.ld index 7c968f6..cd3d924 100644 --- a/standalone.ld +++ b/standalone.ld @@ -99,10 +99,15 @@ SECTIONS __binary_info_end = .; . = ALIGN(4); - .ram_vector_table (NOLOAD): { + .ram_vector_table (NOLOAD): { *(.ram_vector_table) } > RAM + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + .data : { __data_start__ = .; *(vtable) @@ -155,11 +160,6 @@ SECTIONS /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ __etext = LOADADDR(.data); - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* Start and end symbols must be word-aligned */ .scratch_x : { __scratch_x_start__ = .;