Skip to content

Commit ae82a60

Browse files
committed
rp2350: custom ldscript + TZEN work in progress
1 parent b19d9d6 commit ae82a60

File tree

8 files changed

+762
-7
lines changed

8 files changed

+762
-7
lines changed

IDE/pico-sdk/rp2350/test-app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_executable(blink
1717
blink.c
1818
)
1919

20+
pico_set_linker_script(blink ../../../../../hal/rp2350-app.ld)
2021
target_link_libraries(blink pico_stdlib)
2122

2223
# create map/bin/hex/uf2 file etc.

IDE/pico-sdk/rp2350/test-app/build-signed-app.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
mkdir -p build
44
cd build
55
cmake .. -DPICO_SDK_PATH=$PICO_SDK_PATH -DPICO_PLATFORM=rp2350
6-
cat pico_flash_region.ld | sed -e "s/0x10000000/0x10040400/g" >pico_flash_region_wolfboot.ld
7-
cp pico_flash_region_wolfboot.ld pico_flash_region.ld
86

97
# Get off-tree source file from raspberry pico-examples
108
curl -o blink.c https://raw.githubusercontent.com/raspberrypi/pico-examples/refs/tags/sdk-2.1.0/blink/blink.c

IDE/pico-sdk/rp2350/wolfboot/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.13)
2-
set(WOLFBOOT_PATH ../../../../)
2+
set(WOLFBOOT_PATH ../../../..)
33
set(CMAKE_CXX_COMPILER arm-none-eabi-gcc)
44

55
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
@@ -64,6 +64,7 @@ target_include_directories(wolfboot PRIVATE
6464
)
6565

6666
target_link_libraries(wolfboot pico_stdlib hardware_flash)
67+
pico_set_linker_script(wolfboot ../../../../../hal/rp2350.ld)
6768

6869
pico_enable_stdio_usb(wolfboot 1)
6970
pico_enable_stdio_uart(wolfboot 0)

hal/stm32_tz.h renamed to hal/armv8m_tz.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* stm32_tz.h
1+
/* armv8m_tz.h
22
*
33
* Copyright (C) 2024 wolfSSL Inc.
44
*
@@ -19,8 +19,8 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*/
2121

22-
#ifndef STM32_TZ_INCLUDED
23-
#define STM32_TZ_INCLUDED
22+
#ifndef TZ_INCLUDED
23+
#define TZ_INCLUDED
2424
#include <stdint.h>
2525

2626
/* SAU registers, used to define memory mapped regions */

hal/rp2350-app.ld

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
/* Based on GCC ARM embedded samples.
2+
Defines the following symbols for use by code:
3+
__exidx_start
4+
__exidx_end
5+
__etext
6+
__data_start__
7+
__preinit_array_start
8+
__preinit_array_end
9+
__init_array_start
10+
__init_array_end
11+
__fini_array_start
12+
__fini_array_end
13+
__data_end__
14+
__bss_start__
15+
__bss_end__
16+
__end__
17+
end
18+
__HeapLimit
19+
__StackLimit
20+
__StackTop
21+
__stack (== StackTop)
22+
*/
23+
24+
MEMORY
25+
{
26+
FLASH(rx) : ORIGIN = 0x10040400, LENGTH = 0x1D0000
27+
RAM(rwx) : ORIGIN = 0x20008000, LENGTH = 472k
28+
SCRATCH_X(rwx) : ORIGIN = 0x2007E000, LENGTH = 4k
29+
SCRATCH_Y(rwx) : ORIGIN = 0x2007F000, LENGTH = 4k
30+
}
31+
32+
ENTRY(_entry_point)
33+
34+
SECTIONS
35+
{
36+
.flash_begin : {
37+
__flash_binary_start = .;
38+
} > FLASH
39+
40+
/* The bootrom will enter the image at the point indicated in your
41+
IMAGE_DEF, which is usually the reset handler of your vector table.
42+
43+
The debugger will use the ELF entry point, which is the _entry_point
44+
symbol, and in our case is *different from the bootrom's entry point.*
45+
This is used to go back through the bootrom on debugger launches only,
46+
to perform the same initial flash setup that would be performed on a
47+
cold boot.
48+
*/
49+
50+
.text : {
51+
__logical_binary_start = .;
52+
KEEP (*(.vectors))
53+
KEEP (*(.binary_info_header))
54+
__binary_info_header_end = .;
55+
KEEP (*(.embedded_block))
56+
__embedded_block_end = .;
57+
KEEP (*(.reset))
58+
/* TODO revisit this now memset/memcpy/float in ROM */
59+
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
60+
* FLASH ... we will include any thing excluded here in .data below by default */
61+
*(.init)
62+
*libgcc.a:cmse_nonsecure_call.o
63+
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
64+
*(.fini)
65+
/* Pull all c'tors into .text */
66+
*crtbegin.o(.ctors)
67+
*crtbegin?.o(.ctors)
68+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
69+
*(SORT(.ctors.*))
70+
*(.ctors)
71+
/* Followed by destructors */
72+
*crtbegin.o(.dtors)
73+
*crtbegin?.o(.dtors)
74+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
75+
*(SORT(.dtors.*))
76+
*(.dtors)
77+
78+
. = ALIGN(4);
79+
/* preinit data */
80+
PROVIDE_HIDDEN (__preinit_array_start = .);
81+
KEEP(*(SORT(.preinit_array.*)))
82+
KEEP(*(.preinit_array))
83+
PROVIDE_HIDDEN (__preinit_array_end = .);
84+
85+
. = ALIGN(4);
86+
/* init data */
87+
PROVIDE_HIDDEN (__init_array_start = .);
88+
KEEP(*(SORT(.init_array.*)))
89+
KEEP(*(.init_array))
90+
PROVIDE_HIDDEN (__init_array_end = .);
91+
92+
. = ALIGN(4);
93+
/* finit data */
94+
PROVIDE_HIDDEN (__fini_array_start = .);
95+
*(SORT(.fini_array.*))
96+
*(.fini_array)
97+
PROVIDE_HIDDEN (__fini_array_end = .);
98+
99+
*(.eh_frame*)
100+
. = ALIGN(4);
101+
} > FLASH
102+
103+
/* Note the boot2 section is optional, and should be discarded if there is
104+
no reference to it *inside* the binary, as it is not called by the
105+
bootrom. (The bootrom performs a simple best-effort XIP setup and
106+
leaves it to the binary to do anything more sophisticated.) However
107+
there is still a size limit of 256 bytes, to ensure the boot2 can be
108+
stored in boot RAM.
109+
110+
Really this is a "XIP setup function" -- the name boot2 is historic and
111+
refers to its dual-purpose on RP2040, where it also handled vectoring
112+
from the bootrom into the user image.
113+
*/
114+
115+
.boot2 : {
116+
__boot2_start__ = .;
117+
*(.boot2)
118+
__boot2_end__ = .;
119+
} > FLASH
120+
121+
ASSERT(__boot2_end__ - __boot2_start__ <= 256,
122+
"ERROR: Pico second stage bootloader must be no more than 256 bytes in size")
123+
124+
.rodata : {
125+
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
126+
*(.srodata*)
127+
. = ALIGN(4);
128+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
129+
. = ALIGN(4);
130+
} > FLASH
131+
132+
.ARM.extab :
133+
{
134+
*(.ARM.extab* .gnu.linkonce.armextab.*)
135+
} > FLASH
136+
137+
__exidx_start = .;
138+
.ARM.exidx :
139+
{
140+
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
141+
} > FLASH
142+
__exidx_end = .;
143+
144+
/* Machine inspectable binary information */
145+
. = ALIGN(4);
146+
__binary_info_start = .;
147+
.binary_info :
148+
{
149+
KEEP(*(.binary_info.keep.*))
150+
*(.binary_info.*)
151+
} > FLASH
152+
__binary_info_end = .;
153+
. = ALIGN(4);
154+
155+
.ram_vector_table (NOLOAD): {
156+
*(.ram_vector_table)
157+
} > RAM
158+
159+
.uninitialized_data (NOLOAD): {
160+
. = ALIGN(4);
161+
*(.uninitialized_data*)
162+
} > RAM
163+
164+
.data : {
165+
__data_start__ = .;
166+
*(vtable)
167+
168+
*(.time_critical*)
169+
170+
/* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
171+
*(.text*)
172+
. = ALIGN(4);
173+
*(.rodata*)
174+
. = ALIGN(4);
175+
176+
*(.data*)
177+
*(.sdata*)
178+
179+
. = ALIGN(4);
180+
*(.after_data.*)
181+
. = ALIGN(4);
182+
/* preinit data */
183+
PROVIDE_HIDDEN (__mutex_array_start = .);
184+
KEEP(*(SORT(.mutex_array.*)))
185+
KEEP(*(.mutex_array))
186+
PROVIDE_HIDDEN (__mutex_array_end = .);
187+
188+
*(.jcr)
189+
. = ALIGN(4);
190+
} > RAM AT> FLASH
191+
192+
.tdata : {
193+
. = ALIGN(4);
194+
*(.tdata .tdata.* .gnu.linkonce.td.*)
195+
/* All data end */
196+
__tdata_end = .;
197+
} > RAM AT> FLASH
198+
PROVIDE(__data_end__ = .);
199+
200+
/* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
201+
__etext = LOADADDR(.data);
202+
203+
.tbss (NOLOAD) : {
204+
. = ALIGN(4);
205+
__bss_start__ = .;
206+
__tls_base = .;
207+
*(.tbss .tbss.* .gnu.linkonce.tb.*)
208+
*(.tcommon)
209+
210+
__tls_end = .;
211+
} > RAM
212+
213+
.bss (NOLOAD) : {
214+
. = ALIGN(4);
215+
__tbss_end = .;
216+
217+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
218+
*(COMMON)
219+
PROVIDE(__global_pointer$ = . + 2K);
220+
*(.sbss*)
221+
. = ALIGN(4);
222+
__bss_end__ = .;
223+
} > RAM
224+
225+
.heap (NOLOAD):
226+
{
227+
__end__ = .;
228+
end = __end__;
229+
KEEP(*(.heap*))
230+
} > RAM
231+
/* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however
232+
to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */
233+
__HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
234+
235+
/* Start and end symbols must be word-aligned */
236+
.scratch_x : {
237+
__scratch_x_start__ = .;
238+
*(.scratch_x.*)
239+
. = ALIGN(4);
240+
__scratch_x_end__ = .;
241+
} > SCRATCH_X AT > FLASH
242+
__scratch_x_source__ = LOADADDR(.scratch_x);
243+
244+
.scratch_y : {
245+
__scratch_y_start__ = .;
246+
*(.scratch_y.*)
247+
. = ALIGN(4);
248+
__scratch_y_end__ = .;
249+
} > SCRATCH_Y AT > FLASH
250+
__scratch_y_source__ = LOADADDR(.scratch_y);
251+
252+
/* .stack*_dummy section doesn't contains any symbols. It is only
253+
* used for linker to calculate size of stack sections, and assign
254+
* values to stack symbols later
255+
*
256+
* stack1 section may be empty/missing if platform_launch_core1 is not used */
257+
258+
/* by default we put core 0 stack at the end of scratch Y, so that if core 1
259+
* stack is not used then all of SCRATCH_X is free.
260+
*/
261+
.stack1_dummy (NOLOAD):
262+
{
263+
*(.stack1*)
264+
} > SCRATCH_X
265+
.stack_dummy (NOLOAD):
266+
{
267+
KEEP(*(.stack*))
268+
} > SCRATCH_Y
269+
270+
.flash_end : {
271+
KEEP(*(.embedded_end_block*))
272+
PROVIDE(__flash_binary_end = .);
273+
} > FLASH =0xaa
274+
275+
/* stack limit is poorly named, but historically is maximum heap ptr */
276+
__StackLimit = ORIGIN(RAM) + LENGTH(RAM);
277+
__StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
278+
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
279+
__StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
280+
__StackBottom = __StackTop - SIZEOF(.stack_dummy);
281+
PROVIDE(__stack = __StackTop);
282+
283+
/* picolibc and LLVM */
284+
PROVIDE (__heap_start = __end__);
285+
PROVIDE (__heap_end = __HeapLimit);
286+
PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );
287+
PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1));
288+
PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );
289+
290+
/* llvm-libc */
291+
PROVIDE (_end = __end__);
292+
PROVIDE (__llvm_libc_heap_limit = __HeapLimit);
293+
294+
/* Check if data + heap + stack exceeds RAM limit */
295+
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
296+
297+
ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary")
298+
ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary")
299+
300+
/* todo assert on extra code */
301+
}
302+

0 commit comments

Comments
 (0)