new file mode 100644
@@ -0,0 +1,18 @@
+/*
+ * Memory layout for running picolibc hello-world on the 32-bit qemuarm
+ * MACHINE (QEMU "virt" board, Cortex-A15). Upstream's hello-world/arm.ld
+ * targets Cortex-M boards (flash at 0x0, RAM at 0x20000000); on "virt"
+ * 0x20000000 is PCIe MMIO, so writing .data there aborts. RAM on "virt"
+ * starts at 0x40000000.
+ *
+ * AI-generated with Claude Code.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+__flash = 0x40000000;
+__flash_size = 0x00400000;
+__ram = 0x40400000;
+__ram_size = 0x00200000;
+__stack_size = 8k;
+
+INCLUDE picolibc.ld
@@ -15,16 +15,19 @@ QB_OPT_APPEND:append = " -semihosting-config enable=on"
# picolibc comes with a set of linker scripts, set the file
# according to the architecture being built.
-PICOLIBC_LINKERSCRIPT:qemuarm64 = "aarch64.ld"
-PICOLIBC_LINKERSCRIPT:qemuarm = "arm.ld"
-PICOLIBC_LINKERSCRIPT:qemuriscv32 = "riscv.ld"
-PICOLIBC_LINKERSCRIPT:qemuriscv64 = "riscv.ld"
+PICOLIBC_LINKERSCRIPT:qemuarm64 = "${S}/hello-world/aarch64.ld"
+PICOLIBC_LINKERSCRIPT:qemuriscv32 = "${S}/hello-world/riscv.ld"
+PICOLIBC_LINKERSCRIPT:qemuriscv64 = "${S}/hello-world/riscv.ld"
+# Upstream's arm.ld is laid out for Cortex-M boards, not the QEMU "virt"
+# board used by qemuarm, so use our own memory layout instead.
+SRC_URI:append:qemuarm = " file://qemuarm-virt.ld"
+PICOLIBC_LINKERSCRIPT:qemuarm = "${UNPACKDIR}/qemuarm-virt.ld"
# Simple compile function that manually exemplifies usage; as noted,
# use a custom linker script, the GCC specs provided by picolibc
# and semihost to be able to test via QEMU's monitor
do_compile(){
- ${CC} ${CFLAGS} ${LDFLAGS} --verbose -T${S}/hello-world/${PICOLIBC_LINKERSCRIPT} -specs=picolibc.specs --oslib=semihost -o ${BAREMETAL_BINNAME}.elf ${S}/hello-world/hello-world.c
+ ${CC} ${CFLAGS} ${LDFLAGS} --verbose -T${PICOLIBC_LINKERSCRIPT} -specs=picolibc.specs --oslib=semihost -o ${BAREMETAL_BINNAME}.elf ${S}/hello-world/hello-world.c
${OBJCOPY} -O binary ${BAREMETAL_BINNAME}.elf ${BAREMETAL_BINNAME}.bin
}
On qemuarm the hello-world image hung without output. Upstream's hello-world/arm.ld targets Cortex-M boards with RAM at 0x20000000, but on the QEMU "virt" board used by qemuarm that address is PCIe MMIO, not RAM. The startup code faults when it copies initialized data there, and picolibc's default exception handler loops forever, so the image hangs before main(). arm.ld has had this layout since it was added upstream in 2021, so qemuarm never booted. Add a 32-bit linker script with the virt memory map (RAM at 0x40000000) and use it for qemuarm. Tested by building picolibc-helloworld for qemuarm, qemuarm64, qemuriscv32 and qemuriscv64 and running each ELF under QEMU with semihosting; all print "hello, world" and exit 0. AI-Generated: Uses Claude Code (Claude Opus 5.5) Signed-off-by: Tim Orling <tim.orling@konsulko.com> --- .../picolibc-helloworld/qemuarm-virt.ld | 18 ++++++++++++++++++ .../picolibc/picolibc-helloworld_git.bb | 13 ++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 meta/recipes-core/picolibc/picolibc-helloworld/qemuarm-virt.ld