Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bl1/bl1_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_link_options(bl1_1
target_sources(bl1_1
PRIVATE
main.c
$<$<BOOL:${CONFIG_PICOLIBC}>:${CMAKE_SOURCE_DIR}/platform/ext/common/picolibc.c>
$<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
)

Expand Down
1 change: 1 addition & 0 deletions bl1/bl1_2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ target_link_options(bl1_2
target_sources(bl1_2
PRIVATE
main.c
$<$<BOOL:${CONFIG_PICOLIBC}>:${CMAKE_SOURCE_DIR}/platform/ext/common/picolibc.c>
$<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
)

Expand Down
1 change: 1 addition & 0 deletions bl2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ add_executable(bl2
$<$<BOOL:${DEFAULT_MCUBOOT_FLASH_MAP}>:src/default_flash_map.c>
$<$<BOOL:${MCUBOOT_DATA_SHARING}>:src/shared_data.c>
$<$<BOOL:${PLATFORM_DEFAULT_PROVISIONING}>:src/provisioning.c>
$<$<BOOL:${CONFIG_PICOLIBC}>:${CMAKE_SOURCE_DIR}/platform/ext/common/picolibc.c>
$<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
)

Expand Down
5 changes: 5 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ install(DIRECTORY $<BUILD_INTERFACE:${CMSIS_PATH}/CMSIS/Core/Include>
$<BUILD_INTERFACE:${CMSIS_PATH}/CMSIS/Driver/Include>
DESTINATION ${INSTALL_PLATFORM_NS_DIR}/ext/cmsis)

if(CONFIG_PICOLIBC)
install(FILES ${PLATFORM_DIR}/ext/common/picolibc.c
DESTINATION ${INSTALL_PLATFORM_NS_DIR}/ext/common)
endif()

if(PLATFORM_DEFAULT_UART_STDOUT)
install(FILES ${PLATFORM_DIR}/ext/common/uart_stdout.c
${PLATFORM_DIR}/ext/common/uart_stdout.h
Expand Down
1 change: 1 addition & 0 deletions cmake/spe-CMakeLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ add_subdirectory(platform)

target_sources(platform_ns
PRIVATE
$<$<BOOL:${CONFIG_PICOLIBC}>:${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/common/picolibc.c>
$<$<BOOL:${PLATFORM_DEFAULT_UART_STDOUT}>:${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/common/uart_stdout.c>
)

Expand Down
4 changes: 4 additions & 0 deletions platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ target_sources(platform_s
$<$<BOOL:${PLATFORM_DEFAULT_PROVISIONING}>:ext/common/provisioning.c>
$<$<OR:$<BOOL:${TEST_S_FPU}>,$<BOOL:${TEST_NS_FPU}>>:${CMAKE_SOURCE_DIR}/platform/ext/common/test_interrupt.c>
$<$<BOOL:${TFM_SANITIZE}>:ext/common/tfm_sanitize_handlers.c>
$<$<BOOL:${CONFIG_PICOLIBC}>:ext/common/picolibc.c>
./ext/common/tfm_fatal_error.c
)

Expand Down Expand Up @@ -203,6 +204,7 @@ if(BL2)
$<$<OR:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>,$<BOOL:${PLATFORM_DEFAULT_OTP}>>:ext/common/template/flash_otp_nv_counters_backend.c>
$<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c>
$<$<BOOL:${BL2_SANITIZE}>:ext/common/tfm_sanitize_handlers.c>
$<$<BOOL:${CONFIG_PICOLIBC}>:ext/common/picolibc.c>
./ext/common/tfm_fatal_error.c
)

Expand Down Expand Up @@ -304,6 +306,7 @@ if(BL1 AND PLATFORM_DEFAULT_BL1)
$<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/flash_otp_nv_counters_backend.c>
$<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c>
$<$<OR:$<BOOL:${BL1_1_SANITIZE}>,$<BOOL:${TFM_BL1_2_SANITIZE}>>:ext/common/tfm_sanitize_handlers.c>
$<$<BOOL:${CONFIG_PICOLIBC}>:ext/common/picolibc.c>
./ext/common/tfm_fatal_error.c
)

Expand Down Expand Up @@ -359,6 +362,7 @@ if(BL1 AND PLATFORM_DEFAULT_BL1)
$<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:ext/common/template/nv_counters.c>
$<$<OR:$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>,$<BOOL:${PLATFORM_DEFAULT_OTP}>>:ext/common/template/flash_otp_nv_counters_backend.c>
$<$<BOOL:${PLATFORM_DEFAULT_OTP}>:ext/common/template/otp_flash.c>
$<$<BOOL:${CONFIG_PICOLIBC}>:ext/common/picolibc.c>
)

target_link_libraries(platform_bl1_2
Expand Down
4 changes: 4 additions & 0 deletions platform/ext/common/gcc/tfm_common_bl2.ld
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -69,6 +70,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -212,8 +214,10 @@ SECTIONS
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
PROVIDE(__heap_start = __HeapBase);
. += __heap_size__;
__HeapLimit = .;
PROVIDE(__heap_end = __HeapLimit);
__heap_limit = .; /* Add for _sbrk */
} > RAM
Image$$ARM_LIB_HEAP$$ZI$$Limit = ADDR(.heap) + SIZEOF(.heap);
Expand Down
4 changes: 4 additions & 0 deletions platform/ext/common/gcc/tfm_common_ns.ld
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -56,6 +57,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -158,8 +160,10 @@ SECTIONS
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
PROVIDE(__heap_start = __HeapBase);
. += __heap_size__;
__HeapLimit = .;
PROVIDE(__heap_end = __HeapLimit);
__heap_limit = .; /* Add for _sbrk */
} > RAM

Expand Down
10 changes: 10 additions & 0 deletions platform/ext/common/gcc/tfm_common_s.ld.template
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ SECTIONS
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
} > CODE_RAM AT > FLASH

/* Reset current position for subsequent sections */
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);
Comment on lines +203 to +204
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did the linker get confused exactly? Is this really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. got set to LOADADDR instead of ADDR when building with binutils 2.43. I'm afraid that after spending several hours chasing this down, I didn't dig into the linker code to figure out precisely why that happened.

Copy link
Contributor Author

@keith-packard keith-packard Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've re-added this patch as it is necessary even with SDK 0.17.4.


ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")

Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);
Expand All @@ -225,6 +228,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -234,6 +238,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -273,6 +278,9 @@ SECTIONS
/* .zero.table */
. = ALIGN(4);
__zero_table_start__ = .;
LONG (ADDR(.TFM_BSS))
LONG (SIZEOF(.TFM_BSS) / 4)

LONG (ADDR(.TFM_PSA_ROT_LINKER_BSS))
LONG (SIZEOF(.TFM_PSA_ROT_LINKER_BSS) / 4) /* Aligment checked after the section */

Expand Down Expand Up @@ -406,8 +414,10 @@ SECTIONS
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
PROVIDE(__heap_start = __HeapBase);
. += __heap_size__;
__HeapLimit = .;
PROVIDE(__heap_end = __HeapLimit);
__heap_limit = .; /* Add for _sbrk */
} > RAM
#endif
Expand Down
10 changes: 10 additions & 0 deletions platform/ext/common/gcc/tfm_isolation_s.ld.template
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -227,6 +228,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -264,6 +266,9 @@ SECTIONS
/* .zero.table */
. = ALIGN(4);
__zero_table_start__ = .;
LONG (ADDR(.TFM_BSS))
LONG (SIZEOF(.TFM_BSS) / 4)

{% for partition in partitions %}
LONG (ADDR(.ER_{{partition.manifest.name}}_BSS))
LONG (SIZEOF(.ER_{{partition.manifest.name}}_BSS) / 4) /* Aligment checked after the section */
Expand Down Expand Up @@ -350,6 +355,9 @@ SECTIONS
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
} > CODE_RAM AT > FLASH

/* Reset current position for subsequent sections */
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);

ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")

Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);
Expand Down Expand Up @@ -510,8 +518,10 @@ SECTIONS
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
PROVIDE(__heap_start = __HeapBase);
. += __heap_size__;
__HeapLimit = .;
PROVIDE(__heap_end = __HeapLimit);
__heap_limit = .; /* Add for _sbrk */
} > RAM
#endif
Expand Down
2 changes: 2 additions & 0 deletions platform/ext/common/llvm/tfm_common_ns.ldc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -51,6 +52,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down
5 changes: 5 additions & 0 deletions platform/ext/common/llvm/tfm_isolation_s.ld.template
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ SECTIONS
{
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -201,6 +202,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -323,6 +325,9 @@ SECTIONS
. = ALIGN(4); /* This alignment is needed to make the section size 4 bytes aligned */
} > CODE_RAM AT > FLASH

/* Reset current position for subsequent sections */
. = LOADADDR(.ER_CODE_SRAM) + SIZEOF(.ER_CODE_SRAM);

ASSERT(S_RAM_CODE_START % 4 == 0, "S_RAM_CODE_START must be divisible by 4")

Image$$ER_CODE_SRAM$$RO$$Base = ADDR(.ER_CODE_SRAM);
Expand Down
56 changes: 56 additions & 0 deletions platform/ext/common/picolibc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2025, Keith Packard <keithp@keithp.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/

#include <stdint.h>
#include <string.h>
#include "config_impl.h"

#ifdef __PICOLIBC__

/*
* Picolibc's startup code only initializes a single data and bss
* segment. Replace that to initialize all of the segments using
* the lists provided by the linker script.
*/

void __libc_init_array(void);
void _start(void);
int main(int, char **);

void
_start(void)
{
typedef struct __copy_table {
uint32_t const* src;
uint32_t* dest;
uint32_t wlen;
} __copy_table_t;

typedef struct __zero_table {
uint32_t* dest;
uint32_t wlen;
} __zero_table_t;

extern const __copy_table_t __copy_table_start__;
extern const __copy_table_t __copy_table_end__;
extern const __zero_table_t __zero_table_start__;
extern const __zero_table_t __zero_table_end__;

for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
memcpy(pTable->dest, pTable->src, pTable->wlen << 2);
}

for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
memset(pTable->dest, 0, pTable->wlen << 2);
}

__libc_init_array();
main(0, NULL);
return;
}

#endif /* __PICOLIBC__ */
1 change: 1 addition & 0 deletions platform/ext/common/provisioning_bundle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ target_sources(provisioning_bundle
PRIVATE
./provisioning_code.c
./provisioning_data.c
$<$<BOOL:${CONFIG_PICOLIBC}>:${CMAKE_SOURCE_DIR}/platform/ext/common/picolibc.c>
$<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:${CMAKE_SOURCE_DIR}/platform/ext/common/syscalls_stub.c>
)

Expand Down
10 changes: 10 additions & 0 deletions platform/ext/common/syscalls_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __PICOLIBC__
__attribute__((weak))
void _exit(int status)
{
(void) status;
for(;;);
}
#else
__attribute__((weak))
void _close(void)
{
Expand Down Expand Up @@ -53,3 +61,5 @@ __attribute__((weak))
void _write(void)
{
}

#endif /* !__PICOLIBC__ */
2 changes: 1 addition & 1 deletion platform/ext/common/uart_stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int fputc(int ch, FILE *f)
/* Redirect sdtio for PicoLib in LLVM toolchain
as per https://github.com/picolibc/picolibc/blob/main/doc/os.md
'fputch()' named intentionally different from 'fputc()' from picolib */
#elif defined(__clang_major__)
#elif defined(__PICOLIBC__)

int fputch(char ch, struct __file *f)
{
Expand Down
4 changes: 4 additions & 0 deletions platform/ext/target/adi/max32657/device/gcc/max32657_sla.ld
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SECTIONS
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
PROVIDE(__bothinit_array_start = __preinit_array_start);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);

Expand All @@ -59,6 +60,7 @@ SECTIONS
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE(__bothinit_array_end = __init_array_end);

. = ALIGN(4);
/* finit data */
Expand Down Expand Up @@ -196,8 +198,10 @@ SECTIONS
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
PROVIDE(__heap_start = __HeapBase);
. += __heap_size__;
__HeapLimit = .;
PROVIDE(__heap_end = __HeapLimit);
__heap_limit = .; /* Add for _sbrk */
} > RAM
Image$$ARM_LIB_HEAP$$ZI$$Limit = ADDR(.heap) + SIZEOF(.heap);
Expand Down
Loading