From dbd072dfd56b0b4e4a1226c2230802607373afd9 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 6 Oct 2024 04:09:17 +0900 Subject: [PATCH 1/2] soc: raspberrypi: Defining memory-region with devicetree The definition of memory areas will be changed to use DeviceTree, which makes it easier to coexist with other Zephyr functions. Signed-off-by: TOKITA Hiroshi --- dts/arm/raspberrypi/rpi_pico/rp2040.dtsi | 8 ++++++++ dts/arm/raspberrypi/rpi_pico/rp2350.dtsi | 8 ++++++++ soc/raspberrypi/rpi_pico/rp2040/linker.ld | 4 ---- soc/raspberrypi/rpi_pico/rp2350/linker.ld | 5 ----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dts/arm/raspberrypi/rpi_pico/rp2040.dtsi b/dts/arm/raspberrypi/rpi_pico/rp2040.dtsi index 6398674e0e02..90c54c595872 100644 --- a/dts/arm/raspberrypi/rpi_pico/rp2040.dtsi +++ b/dts/arm/raspberrypi/rpi_pico/rp2040.dtsi @@ -429,6 +429,14 @@ io-channels = <&adc 4>; status = "disabled"; }; + + boot_flash: flash@10000000 { + compatible = "zephyr,memory-region"; + reg = <0x10000000 0x100>; + zephyr,memory-region = "BOOT_FLASH"; + zephyr,memory-region-flags = "r"; + status = "okay"; + }; }; &nvic { diff --git a/dts/arm/raspberrypi/rpi_pico/rp2350.dtsi b/dts/arm/raspberrypi/rpi_pico/rp2350.dtsi index 687cafc19aad..ab57b5d4ece2 100644 --- a/dts/arm/raspberrypi/rpi_pico/rp2350.dtsi +++ b/dts/arm/raspberrypi/rpi_pico/rp2350.dtsi @@ -435,4 +435,12 @@ compatible = "raspberrypi,pico-temp"; status = "disabled"; }; + + image_def_flash: flash@10000000 { + compatible = "zephyr,memory-region"; + reg = <0x10000000 0x80>; + zephyr,memory-region = "IMAGE_DEF_FLASH"; + zephyr,memory-region-flags = "r"; + status = "okay"; + }; }; diff --git a/soc/raspberrypi/rpi_pico/rp2040/linker.ld b/soc/raspberrypi/rpi_pico/rp2040/linker.ld index 5e1db9a81758..ea8f4362fc70 100644 --- a/soc/raspberrypi/rpi_pico/rp2040/linker.ld +++ b/soc/raspberrypi/rpi_pico/rp2040/linker.ld @@ -13,10 +13,6 @@ * such as mcuboot. */ #if CONFIG_RP2_REQUIRES_SECOND_STAGE_BOOT -MEMORY -{ - BOOT_FLASH (r) : ORIGIN = 0x10000000, LENGTH = 256 -} SECTIONS { diff --git a/soc/raspberrypi/rpi_pico/rp2350/linker.ld b/soc/raspberrypi/rpi_pico/rp2350/linker.ld index 6368409c9e27..a83afdf5e697 100644 --- a/soc/raspberrypi/rpi_pico/rp2350/linker.ld +++ b/soc/raspberrypi/rpi_pico/rp2350/linker.ld @@ -6,11 +6,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -MEMORY -{ - IMAGE_DEF_FLASH (r) : ORIGIN = 0x10000000, LENGTH = 128 -} - SECTIONS { .image_def : { From 864d04282ef75c7ec93ef633b14373e7932ddcb8 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 6 Oct 2024 04:13:30 +0900 Subject: [PATCH 2/2] soc: raspberrypi: rpi_pico: Use zephyr_linker_sources to define sections Use zephyr_linker_sources() to separate definitions of soc-specific sections. Also, we can directly include `include/zephyr/arch/arm/cortex_m/scripts/linker.ld` in CMakeLists.txt, which will fit Zephyr's build system properly. Signed-off-by: TOKITA Hiroshi --- .../rpi_pico/rp2040/CMakeLists.txt | 6 ++++- .../rp2040/{linker.ld => sections.ld} | 15 +++---------- .../rpi_pico/rp2350/CMakeLists.txt | 4 +++- soc/raspberrypi/rpi_pico/rp2350/linker.ld | 22 ------------------- soc/raspberrypi/rpi_pico/rp2350/sections.ld | 15 +++++++++++++ 5 files changed, 26 insertions(+), 36 deletions(-) rename soc/raspberrypi/rpi_pico/rp2040/{linker.ld => sections.ld} (53%) delete mode 100644 soc/raspberrypi/rpi_pico/rp2350/linker.ld create mode 100644 soc/raspberrypi/rpi_pico/rp2350/sections.ld diff --git a/soc/raspberrypi/rpi_pico/rp2040/CMakeLists.txt b/soc/raspberrypi/rpi_pico/rp2040/CMakeLists.txt index 4c53cf10d0fd..3d4501b5c9cc 100644 --- a/soc/raspberrypi/rpi_pico/rp2040/CMakeLists.txt +++ b/soc/raspberrypi/rpi_pico/rp2040/CMakeLists.txt @@ -3,4 +3,8 @@ zephyr_include_directories(.) -set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "") +zephyr_linker_sources_ifdef(CONFIG_RP2_REQUIRES_SECOND_STAGE_BOOT + SECTIONS sections.ld +) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/raspberrypi/rpi_pico/rp2040/linker.ld b/soc/raspberrypi/rpi_pico/rp2040/sections.ld similarity index 53% rename from soc/raspberrypi/rpi_pico/rp2040/linker.ld rename to soc/raspberrypi/rpi_pico/rp2040/sections.ld index ea8f4362fc70..3c3f27759acd 100644 --- a/soc/raspberrypi/rpi_pico/rp2040/linker.ld +++ b/soc/raspberrypi/rpi_pico/rp2040/sections.ld @@ -1,5 +1,3 @@ -/* linker.ld - Linker command/script file */ - /* * Copyright (c) 2014 Wind River Systems, Inc. * Copyright (c) 2021 Yonatan Schachter @@ -12,14 +10,7 @@ * resides at 0x100. This can be the application, or a bootloader * such as mcuboot. */ -#if CONFIG_RP2_REQUIRES_SECOND_STAGE_BOOT - -SECTIONS -{ - .boot2 : { - KEEP(*(.boot2)) - } > BOOT_FLASH -} -#endif /* CONFIG_RP2_REQUIRES_SECOND_STAGE_BOOT */ -#include +.boot2 : { + KEEP(*(.boot2)) +} > BOOT_FLASH diff --git a/soc/raspberrypi/rpi_pico/rp2350/CMakeLists.txt b/soc/raspberrypi/rpi_pico/rp2350/CMakeLists.txt index 8f48fc01aba9..36e38d5b59d8 100644 --- a/soc/raspberrypi/rpi_pico/rp2350/CMakeLists.txt +++ b/soc/raspberrypi/rpi_pico/rp2350/CMakeLists.txt @@ -7,4 +7,6 @@ zephyr_library_sources(soc.c) zephyr_include_directories(.) -set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "") +zephyr_linker_sources(SECTIONS sections.ld) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/raspberrypi/rpi_pico/rp2350/linker.ld b/soc/raspberrypi/rpi_pico/rp2350/linker.ld deleted file mode 100644 index a83afdf5e697..000000000000 --- a/soc/raspberrypi/rpi_pico/rp2350/linker.ld +++ /dev/null @@ -1,22 +0,0 @@ -/* linker.ld - Linker command/script file */ - -/* - * Copyright (c) 2024 Andrew Featherstone - * - * SPDX-License-Identifier: Apache-2.0 - */ - -SECTIONS -{ - .image_def : { - LONG(0xffffded3) /* PICOBIN_BLOCK_MARKER_START */ - LONG(0x10210142) /* IMAGE_DEF Item */ - LONG(0x00000203) /* VECTOR_TABLE Item */ - LONG(ABSOLUTE(_vector_start)) /* - Address of the vector table in flash */ - LONG(0x000003ff) /* Last Item in Block */ - LONG(0x00000000) /* End of block loop */ - LONG(0xab123579) /* PICOBIN_BLOCK_MARKER_END */ - } > IMAGE_DEF_FLASH -} - -#include diff --git a/soc/raspberrypi/rpi_pico/rp2350/sections.ld b/soc/raspberrypi/rpi_pico/rp2350/sections.ld new file mode 100644 index 000000000000..827efa671187 --- /dev/null +++ b/soc/raspberrypi/rpi_pico/rp2350/sections.ld @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024 Andrew Featherstone + * + * SPDX-License-Identifier: Apache-2.0 + */ + +.image_def : { + LONG(0xffffded3) /* PICOBIN_BLOCK_MARKER_START */ + LONG(0x10210142) /* IMAGE_DEF Item */ + LONG(0x00000203) /* VECTOR_TABLE Item */ + LONG(ABSOLUTE(_vector_start)) /* - Address of the vector table in flash */ + LONG(0x000003ff) /* Last Item in Block */ + LONG(0x00000000) /* End of block loop */ + LONG(0xab123579) /* PICOBIN_BLOCK_MARKER_END */ +} > IMAGE_DEF_FLASH