rp2_common/pico_standard_link: implement customizable linker script #1547
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #398
Background:
For cases where modifications to the linker script are required, pico-sdk only provides the option to provide an entire linker script using
pico_set_linker_script
. This patch adds a functionpico_customize_linker_script
to create a linker script in the build process, based on a template provided by pico-sdk and local settings provided by the user.The tool of choice is the C preprocessor, but I am open to suggestions for an alternative.
Use cases for linker script modification include:
memmap_blocked_ram.ld
which differs in only one line from the default)In such cases, deriving the linker script from a template may/should lead to code that is easier to maintain.
Implementation:
The template is
memmap.ld.in
, the user input is provided by specifying a customization file to be included, and the linker script is generated by the C preprocessor. This of course is just one of many template solutions, but this one only requires a C compiler, which is available by definition.The template exposes a few settings by #defining them before including the customization file, and provides a few hooks to add elements to the template.
Examples and hints for use, based on a working example where cyw43 firmware lives in a separate region in flash:
in CMakeLists.txt:
tweaks.h:
Details:
${TARGET}.ld
\\
at the end of lines, newlines are inserted in the resulting linker script in a postprocessing step. This is done to improve readability of the resulting linker script.#
need to be removed from the output; they are now turned into/*comments*/
#undef
fed before redefining them, which is a bit awkward; another option is to use#ifdef
for each and every variable in the template; yet another option (for integers) is to use linker variables (i.e. simply settingMAIN_FLASH_LENGTH=256k
).TODO:
This was only tested on OS X with makefile builds, so broader testing is probably needed (although this new feature doesn't change/break anything existing).
As mentioned above, at least
memmap_blocked_ram.ld
(andmemmap_default.ld
) could easily be derived at runtime from the template. Maybe the other linker scripts can also derive from the template with the right tweaks.