diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 4633845dd..cc24531f4 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -41,6 +41,7 @@ soc_software_packages = [ # LiteX cores. "libbase", + "libc", # LiteX Ecosystem cores. "libfatfs", @@ -138,8 +139,10 @@ class Builder: for k, v in export.get_cpu_mak(self.soc.cpu, self.compile_software): define(k, v) - # Define the SoC/Compiler-RT/Software/Include directories. + # Define the SoC/Picolibc/Compiler-RT/Software/Include directories. define("SOC_DIRECTORY", soc_directory) + picolibc_directory = get_data_mod("software", "picolibc").data_location + define("PICOLIBC_DIRECTORY", picolibc_directory) compiler_rt_directory = get_data_mod("software", "compiler_rt").data_location define("COMPILER_RT_DIRECTORY", compiler_rt_directory) variables_contents.append("export BUILDINC_DIRECTORY") diff --git a/litex/soc/software/libc/Makefile b/litex/soc/software/libc/Makefile new file mode 100644 index 000000000..7f47e0299 --- /dev/null +++ b/litex/soc/software/libc/Makefile @@ -0,0 +1,7 @@ +include ../include/generated/variables.mak +include $(SOC_DIRECTORY)/software/common.mak + +newlib/libc.a: + $(LIBC_DIRECTORY)/do-rv32im-configure $(PICOLIBC_DIRECTORY) + meson compile + sh $(LIBC_DIRECTORY)/swap_libc.sh diff --git a/litex/soc/software/libc/cross-rv32im.txt b/litex/soc/software/libc/cross-rv32im.txt new file mode 100644 index 000000000..15abc56ee --- /dev/null +++ b/litex/soc/software/libc/cross-rv32im.txt @@ -0,0 +1,18 @@ +[binaries] +c = 'riscv64-unknown-elf-gcc' +ar = 'riscv64-unknown-elf-ar' +as = 'riscv64-unknown-elf-as' +nm = 'riscv64-unknown-elf-nm' +strip = 'riscv64-unknown-elf-strip' + +[host_machine] +system = 'unknown' +cpu_family = 'riscv' +cpu = 'riscv32' +endian = 'little' + +[properties] +c_args = [ '-nostdlib', '-mno-save-restore', '-march=rv32im', '-mabi=ilp32'] +c_link_args = [ '-nostdlib', '-mno-save-restore', '-march=rv32im', '-mabi=ilp32'] +skip_sanity_check = true + diff --git a/litex/soc/software/libc/do-rv32im-configure b/litex/soc/software/libc/do-rv32im-configure new file mode 100755 index 000000000..64bf04d47 --- /dev/null +++ b/litex/soc/software/libc/do-rv32im-configure @@ -0,0 +1,11 @@ +#!/bin/sh + +ARCH=riscv64-unknown-elf +DIR=`dirname $0` +meson "$1" \ + -Dtests=true \ + -Dmultilib=false \ + -Dincludedir="picolibc/$ARCH/include" \ + -Dlibdir="picolibc/$ARCH/lib" \ + --cross-file "$DIR/cross-rv32im.txt" \ + diff --git a/litex/soc/software/libc/swap_libc.sh b/litex/soc/software/libc/swap_libc.sh new file mode 100644 index 000000000..6a13f3f24 --- /dev/null +++ b/litex/soc/software/libc/swap_libc.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +AR=riscv64-unknown-elf-ar + +for obj in \ + vsnprintf.c.o \ + vfprintf.c.o \ + fputc.c.o \ + filestrput.c.o \ + dtoa_ryu.c.o \ + ryu_table.c.o \ + ryu_umul128.c.o \ + ryu_log10.c.o \ + ryu_log2pow5.c.o \ + ryu_pow5bits.c.o \ + ryu_divpow2.c.o \ + qsort.c.o \ + strchr.c.o \ + strpbrk.c.o \ + strrchr.c.o \ + strcpy.c.o \ + strncpy.c.o \ + strcmp.S.o \ + strncmp.c.o \ + strcat.c.o \ + strncat.c.o \ + strlen.c.o \ + strnlen.c.o \ + strspn.c.o \ + memcmp.c.o \ + memset.S.o \ + memcpy.c.o \ + memmove.S.o \ + strstr.c.o \ + memchr.c.o \ + strtoul.c.o \ + strtol.c.o \ + snprintf.c.o \ + sprintf.c.o \ + rand.c.o \ + srand.c.o \ + abort.c.o \ + errno.c.o \ + strerror.c.o \ + strtod.c.o \ + ctype_.c.o \ + locale.c.o \ + mbtowc_r.c.o \ + wctomb_r.c.o \ + strcasecmp.c.o \ + isdigit.c.o \ +; do + $AR x "newlib/libc.a" $obj + $AR csr "../libbase/libbase.a" $obj + $AR csr "../libbase/libbase-nofloat.a" $obj + rm $obj +done +