pico-sdk
pico-sdk copied to clipboard
Add pico_set_modified_binary_type function
This adds a function to create binaries using an existing binary type & linker script, but with modified RAM/SCRATCH addresses
A similar function is already in use by the encrypted bootloader example, and picotool xip_ram_perms binary, so this extends those by adding scratch address modification
For example, to only use SRAM1 so you can power down SRAM0 in your binary you could use
pico_set_modified_binary_type(<my_exe> default RAM "0x20040000" "256k")
To create a XIP_SRAM only binary you could use
pico_set_modified_binary_type(<my_exe> no_flash
RAM "0x13ffc000" "12k"
SCRATCH_X "0x13fff000" "2k"
SCRATCH_Y "0x13fff800" "2k")
The existing memmap_blocked_ram.ld could be created using
pico_set_modified_binary_type(<my_exe> default RAM "0x21000000" "256k")
this is useful functionality; we need to think about whether this is best as modifying the linker script or injecting as per FLASH_SIZE (either way it should - and i think it is for FLASH_SIZE be modifiable via linker script)
To create a XIP_SRAM only binary you could use
pico_set_modified_binary_type(<my_exe> no_flash RAM "0x13ffc000" "12k" SCRATCH_X "0x13fff000" "2k" SCRATCH_Y "0x13fff800" "2k")
Perhaps it would be nice if you could use symbolic aliases here, rather than having to use hardcoded addresses? :shrug:
Maybe this is a first step towards #1547 ?
this is useful functionality; we need to think about whether this is best as modifying the linker script or injecting as per FLASH_SIZE (either way it should - and i think it is for FLASH_SIZE be modifiable via linker script)
I've thought it through a bit more - injecting like FLASH_SIZE wouldn't work, because you might need different injected bits for each binary in your project, whereas FLASH_SIZE is set project-wide as it's fixed for a given board
Instead, I've added separate template linker scripts memmap_sram.template.ld and memmap_flash.template.ld, which are copies of memmap_no_flash.ld and memmap_default.ld respectively with the RAM and SCRATCH regions set to be templated. I've also added tests at compile time to kitchen_sink to ensure these files stay in sync.
These template linker scripts could then be extended further to support #1547 - but I think that's probably best for a second PR, I'd like to just get this functionality in first so you can make SRAM1 or XIP_SRAM binaries