poky/meta/recipes-core/picolibc/picolibc-helloworld_git.bb
Alejandro Hernandez Samaniego 09b49a35e1 tclibc-picolibc: Adds a new TCLIBC variant to build with picolibc as C library
Enables usage of TCLIBC=picolibc extending OE functionality to build and use
picolibc based toolchains to build baremetal applications.

Picolibc is a set of standard C libraries, both libc and libm, designed for
smaller embedded systems with limited ROM and RAM. Picolibc includes code
from Newlib and AVR Libc, but adresses some of newlibs concerns, it retains
newlibs directory structure, math, string and locale implementations, but
removed the GPL bits used to build the library, swiches old C style code for
C18 and replaces autotools with meson.

This patch adds a picolibc recipe for the C library, a picolibc-helloworld
recipe that contains an example application and a testcase that builds it.

Picolibc can be built for ARM and RISCV architectures, its been tested both
for 32 and 64 bits, the provided example recipe produces the following output:

hello, world

Runqemu does not automatically show any output since it hides QEMU stderr which
is where the QEMU monitors output is directed to when using semihosting, but,
manually running the same QEMU command does work properly.

(From OE-Core rev: c7535ecaccb72ef21a61f9aec5c68e61fb4f6fb6)

Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-07-26 12:28:42 +01:00

41 lines
1.5 KiB
BlitzBasic

require picolibc.inc
# baremetal-image overrides
BAREMETAL_BINNAME ?= "hello_picolibc_${MACHINE}"
IMAGE_LINK_NAME ?= "baremetal-picolibc-image-${MACHINE}"
IMAGE_NAME_SUFFIX ?= ""
QB_DEFAULT_KERNEL ?= "${IMAGE_LINK_NAME}.elf"
inherit baremetal-image
COMPATIBLE_MACHINE = "qemuarm|qemuarm64|qemuriscv32|qemuriscv64"
# Use semihosting to test via QEMU
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"
# 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
${OBJCOPY} -O binary ${BAREMETAL_BINNAME}.elf ${BAREMETAL_BINNAME}.bin
}
do_install(){
install -d ${D}/${base_libdir}/firmware
install -m 755 ${B}/${BAREMETAL_BINNAME}.elf ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf
install -m 755 ${B}/${BAREMETAL_BINNAME}.bin ${D}/${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin
}
FILES:${PN} += " \
${base_libdir}/firmware/${BAREMETAL_BINNAME}.elf \
${base_libdir}/firmware/${BAREMETAL_BINNAME}.bin \
"