Skip to content

Commit 5aa4bd6

Browse files
Add support for using XIP cache as SRAM (#2932)
* Separate linker scripts out into include files Allows for much simpler custom linker scripts * Add customisable heap location, with pico_set_linker_script_var function * Add kitchen sink test of custom linker scripts * Separate out rp2_common and platform-specific linker script sections * More de-duplication * Make overriding ram locations simpler * Make it possible to reference default locations in pico_set_linker_script_var variables Means that CMake doesn't need to know the default memory addresses for different platforms * Add pico_add_linker_script_override_path to make overriding individual files easier Restructured so that it includes the platform-specific files before common ones, so common ones can be overridden * Add simple overlay demo * Add scripts to bazel build Use new include_linker_script_dir and use_linker_script_file functions to add the linker arguments * Move linker scripts out of crt0 Breaking change for Bazel builds using different binary types, instead of setting PICO_DEFAULT_LINKER_SCRIPT to eg `//src/rp2_common/pico_crt0:no_flash_linker_script` it is now `//src/rp2_common/pico_standard_link:no_flash_linker_script` * Make rp2350 text sections the default Treat rp2040 layout (boot2 instead of embedded blocks) as the outlier * Rename scripts include directories to standard_scripts and platform_scripts * Move and add example to Bazel docs for changing linker scripts * Add cc_library load to new bazel files * Add excludes.ld files for default memmap Allows overriding what to exclude from .text/.rodata and put in .data * Put mem functions in SRAM These were being placed in Flash due to a missing space, and also are under libc on some compilers * Rename standard_scripts and platform_scripts to script_include * Move pico_platform_link stuff into pico_plaftorm * Remove rigidity from linker include paths Add PICO_LINKER_SCRIPT_INCLUDE_DIRS and PICO_LINKER_DEFAULT_LOCATIONS_PATH, instead of hardcoded paths under PICO_LINKER_SCRIPT_PATH Also improve pico_set_linker_script_var and pico_add_linker_script_override_path to better utilise generator expressions * Rename all linker scripts intended to be included to .incl Required changes to the way bazel views these files * Separate into section_... files which do only contain one section, and sections_... which contain multiple Only exceptions are section_..._data and section_bss, as these contain data/bss and tdata/tbss - these are kept together as they are treated as a single section * Add section_extra files to make adding extra sections simpler * Fix comments, and add some more extra files * Add generated override files - currently unused, but can be overridden in the future by CMake/bazel functions * pico_add_linker_script_override_path can now be called after target_link_libraries, as it uses generator expressions Also add more checks to kitchen_sink * Add extra post_platform_end sections Intended for platform specific overrides, whereas post_end is for cross-platform overrides, similar to section_end vs section_platform_end * review fixups * Save/restore XIP cache state around flash functions * Fix PICO_USE_SW_SPIN_LOCKS=0 on RP2350 Use spinlock IDs that are unaffected by E2 * Working XIP SRAM binaries * Change implementation to use pico_use_xip_sram_for_time_critical instead of new binary types Adds pico_include_in_generated_section to fill section_generated_... files with lists of include files, and pico_set_compile_definition to allow setting the same definition multiple times on a target without getting warnings * Add some CMake function docs * Fix bazel and RP2350 build Has missed setting PICO_CRT0_PIN_XIP_SRAM * Fix bazel build Ordering of transistions matters * Improve new __time_critical_func description Special treatment is no longer in the future * Add pico_test, and improve SRAM thrashing * fix bazel build * fixup merge * Move memory_xip_ram.incl to match location in other PRs * Review fixups Place RAM_SECTION_NAME in .time_critical.text Typo in __time_critical_func description * fixup merge * review fixup * add memmap_xip_ram.cmake * some minor cleanup * Doesn't require data copy for no_flash use_xip_cache_as_ram on RP2040 The code is still loaded before boot on rp2040, so doesn't need copying * remove copy-paste typo * Fixes for compatibility with low power Skip low power unpinning when PICO_USE_XIP_CACHE_AS_RAM is set Take xip_ram as argument to pico_set_persistent_data_loc, to allow placing normally instead of specifying address Add pico_critical_xip_sram_test_low_power test to check usin xip_ram for both works * Improve pico_set_persistent_data_loc description * add () inside #define * Update memory_extra.incl examples PSRAM and xip_ram are now supported by default * Improve binary type generator expressions Use PICO_DEFAULT_BINARY_TYPE in the generator expressions, to remove need for PICO_NO_FLASH etc, and fixup the legacy variable handling to that effect Now throws an error if both PICO_DEFAULT_BINARY_TYPE and one of PICO_NO_FLASH etc are specified - just use PICO_DEFAULT_BINARY_TYPE * Refactor to place functions using compile definitions instead of linker script injections This adds section_xip_ram.incl into every linker script, and provides the __in_xip_ram macro to put stuff there __time_critical_func then uses the PICO_TIME_CRITICAL_PLACEMENT define to select where to place code, so that can be overriden to be __in_xip_ram to place time critical functions in xip_ram Also works for placing time critical functions in scratch x/y * pico_use_xip_cache_as_sram -> pico_use_xip_cache_as_ram for consistency Also re-add note to pico_place_time_critical_functions not to use xip_ram for flash binaries * fix bazel linting * remove memory_aliases_xip_ram_only now identical to memory_aliases_no_flash * Re-arrange sections.h to be clearer what everything does All `__in_xxx` macros place directly into linker sections, which are located in the relevant memory `__scratch_x` and `__scratch_y` are kept as aliases to `__in_scratch_x` and `__in_scratch_y` `__not_in_flash` is placed using `PICO_NOT_IN_FLASH_PLACEMENT` which defaults to `__in_ram`, and the same for `__time_critical_func`, so they can be placed separately pico_place_time_critical_functions -> pico_set_time_critical_placement, and add pico_set_not_in_flash_placement * Make memmap_xip_ram.incl include memmap_no_flash.incl Removes the ability to override XIP_RAM_ORIGIN and XIP_RAM_LENGTH (to prevent duplicate includes, which Clang doesn't like), but that is fine * Fixup bazel build Note that the xip_ram binary type still doesn't work in bazel, as the bazel build doesn't fit in xip_ram * fix bazel buildifier checks --------- Co-authored-by: graham sanderson <graham.sanderson@raspberrypi.com>
1 parent 3d63b1d commit 5aa4bd6

46 files changed

Lines changed: 926 additions & 78 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bazel/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ string_flag(
237237
"no_flash",
238238
"copy_to_ram",
239239
"blocked_ram",
240+
"xip_ram",
240241
],
241242
)
242243

bazel/constraint/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,8 @@ config_setting(
303303
name = "pico_binary_type_blocked_ram",
304304
flag_values = {"//bazel/config:PICO_DEFAULT_BINARY_TYPE": "blocked_ram"},
305305
)
306+
307+
config_setting(
308+
name = "pico_binary_type_xip_ram",
309+
flag_values = {"//bazel/config:PICO_DEFAULT_BINARY_TYPE": "xip_ram"},
310+
)

src/common/pico_base_headers/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ cc_library(
7878
"//bazel/constraint:pico_binary_type_no_flash": ["PICO_NO_FLASH=1"],
7979
"//bazel/constraint:pico_binary_type_copy_to_ram": ["PICO_COPY_TO_RAM=1"],
8080
"//bazel/constraint:pico_binary_type_blocked_ram": ["PICO_USE_BLOCKED_RAM=1"],
81+
"//bazel/constraint:pico_binary_type_xip_ram": [
82+
"PICO_XIP_RAM=1",
83+
"PICO_NO_FLASH=1",
84+
],
8185
"//conditions:default": [],
8286
}),
8387
)

src/rp2040/pico_platform/memmap_blocked_ram.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function(pico_add_memmap_link_depends_internal TARGET)
3737
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl)
3838
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl)
3939
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl)
40+
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl)
4041
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl)
4142
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default.incl)
4243
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl)

src/rp2040/pico_platform/memmap_blocked_ram.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ INCLUDE "memmap_default.incl"
4545
* ├── section_extra_post_scratch.incl rp2_common/pico_standard_link
4646
* ├── sections_stack.incl rp2_common/pico_standard_link
4747
* ├── sections_psram.incl rp2040/pico_platform
48+
* ├── section_xip_ram.incl rp2_common/pico_standard_link
4849
* ├── section_flash_end.incl rp2_common/pico_standard_link
4950
* ├── section_end.incl rp2_common/pico_standard_link
5051
* ├── section_generated_post_end.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_copy_to_ram.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function(pico_add_memmap_link_depends_internal TARGET)
3636
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl)
3737
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl)
3838
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl)
39+
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl)
3940
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl)
4041
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl)
4142
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl)

src/rp2040/pico_platform/memmap_copy_to_ram.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ INCLUDE "memmap_copy_to_ram.incl"
4141
* ├── section_extra_post_scratch.incl rp2_common/pico_standard_link
4242
* ├── sections_stack.incl rp2_common/pico_standard_link
4343
* ├── sections_psram.incl rp2040/pico_platform
44+
* ├── section_xip_ram.incl rp2_common/pico_standard_link
4445
* ├── section_flash_end.incl rp2_common/pico_standard_link
4546
* ├── section_end.incl rp2_common/pico_standard_link
4647
* ├── section_generated_post_end.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_default.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function(pico_add_memmap_link_depends_internal TARGET)
3737
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl)
3838
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl)
3939
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl)
40+
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl)
4041
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl)
4142
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default.incl)
4243
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl)

src/rp2040/pico_platform/memmap_default.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ INCLUDE "memmap_default.incl"
4242
* ├── section_extra_post_scratch.incl rp2_common/pico_standard_link
4343
* ├── sections_stack.incl rp2_common/pico_standard_link
4444
* ├── sections_psram.incl rp2040/pico_platform
45+
* ├── section_xip_ram.incl rp2_common/pico_standard_link
4546
* ├── section_flash_end.incl rp2_common/pico_standard_link
4647
* ├── section_end.incl rp2_common/pico_standard_link
4748
* ├── section_generated_post_end.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_no_flash.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function(pico_add_memmap_link_depends_internal TARGET)
2929
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_persistent_data.incl)
3030
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl)
3131
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl)
32+
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl)
3233
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl)
3334
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl)
3435
pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl)

0 commit comments

Comments
 (0)