From ab881c561f5eeca0b6c5e12ab57e2a93da7b92f7 Mon Sep 17 00:00:00 2001 From: Michal Sieron Date: Fri, 30 Jul 2021 14:36:20 +0200 Subject: [PATCH] Implement initial support for lm32 and or1k Picolibc doesn't maintain meson.build or cross*.txt files for lm32 and or1k CPUs. This commit adds meson.build files for both of them. Also libc/Makefile got modifed to determine CPU family from $(CPU) value and generate cross.txt file. Now picolibc gets compiled with LiteX flags too. It doesn't compile on neither of them yet, but at least riscv still works. --- litex/soc/software/libc/Makefile | 49 +++++++++++++++++++++++- litex/soc/software/libc/cross-rv32im.txt | 18 --------- litex/soc/software/libc/lm32-meson.build | 48 +++++++++++++++++++++++ litex/soc/software/libc/or1k-meson.build | 48 +++++++++++++++++++++++ 4 files changed, 143 insertions(+), 20 deletions(-) delete mode 100644 litex/soc/software/libc/cross-rv32im.txt create mode 100644 litex/soc/software/libc/lm32-meson.build create mode 100644 litex/soc/software/libc/or1k-meson.build diff --git a/litex/soc/software/libc/Makefile b/litex/soc/software/libc/Makefile index 2f005a821..cc7ed0e95 100644 --- a/litex/soc/software/libc/Makefile +++ b/litex/soc/software/libc/Makefile @@ -3,10 +3,55 @@ include $(SOC_DIRECTORY)/software/common.mak all: libc.a iob.c.o -libc.a: +CPUFAMILY= + +ifneq ($(findstring $(CPU), serv femtorv picorv32 minerva vexriscv vexriscv_smp ibex cv32e40p rocket blackparrot),) + CPUFAMILY = riscv +else ifeq ($(CPU), lm32) + CPUFAMILY = lm32 +else ifeq ($(CPU), mor1kx) + CPUFAMILY = or1k +else ifeq ($(CPU), microwatt) + CPUFAMILY = powerpc +else ifeq ($(CPU), zynq7000) + CPUFAMILY = arm +else + $(error Unsupported CPU) +endif + +define CROSSFILE +[binaries] +c = '$(TRIPLE)-gcc' +ar = '$(TRIPLE)-ar' +as = '$(TRIPLE)-as' +nm = '$(TRIPLE)-nm' +strip = '$(TRIPLE)-strip' + +[host_machine] +system = 'unknown' +cpu_family = '$(CPUFAMILY)' +cpu = '$(CPU)' +endian = '$(CPUENDIANNESS)' + +[built-in options] +c_args = [ '-DPRINTF_LEVEL=1', $(foreach flag,$(filter-out $(INCLUDES) $(DEPFLAGS),$(CFLAGS)),'$(flag)',) ] +c_link_args = [ '-DPRINTF_LEVEL=1', $(foreach flag,$(LDFLAGS),'$(flag)',) ] +endef + +export CROSSFILE +cross.txt: + @echo "$$CROSSFILE" > $@ + +$(PICOLIBC_DIRECTORY)/newlib/libc/machine/$(CPUFAMILY)/meson.build: + cp $(LIBC_DIRECTORY)/$(CPUFAMILY)-meson.build $@ + +libc.a: cross.txt $(PICOLIBC_DIRECTORY)/newlib/libc/machine/$(CPUFAMILY)/meson.build meson $(PICOLIBC_DIRECTORY) \ -Dmultilib=false \ - --cross-file "$(LIBC_DIRECTORY)/cross-rv32im.txt" + -Dpicocrt=false \ + -Dincludedir=picolibc/$(TRIPLE)/include \ + -Dlibdir=picolibc/$(TRIPLE)/lib \ + --cross-file cross.txt meson compile cp newlib/libc.a libc.a diff --git a/litex/soc/software/libc/cross-rv32im.txt b/litex/soc/software/libc/cross-rv32im.txt deleted file mode 100644 index 865f30324..000000000 --- a/litex/soc/software/libc/cross-rv32im.txt +++ /dev/null @@ -1,18 +0,0 @@ -[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 = [ '-DPRINTF_LEVEL=1', '-DSCANF_LEVEL=1', '-nostdlib', '-mno-save-restore', '-march=rv32im', '-mabi=ilp32'] -c_link_args = [ '-DPRINTF_LEVEL=1', '-DSCANF_LEVEL=1', '-nostdlib', '-mno-save-restore', '-march=rv32im', '-mabi=ilp32'] -skip_sanity_check = true - diff --git a/litex/soc/software/libc/lm32-meson.build b/litex/soc/software/libc/lm32-meson.build new file mode 100644 index 000000000..09804d424 --- /dev/null +++ b/litex/soc/software/libc/lm32-meson.build @@ -0,0 +1,48 @@ +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright © 2019 Keith Packard +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +# OF THE POSSIBILITY OF SUCH DAMAGE. +# +srcs_machine = [ + 'setjmp.S', +] + +foreach target : targets + value = get_variable('target_' + target) + set_variable('lib_machine' + target, + static_library('machine' + target, + srcs_machine, + pic: false, + include_directories: inc, + c_args: value[1] + arg_fnobuiltin)) +endforeach + diff --git a/litex/soc/software/libc/or1k-meson.build b/litex/soc/software/libc/or1k-meson.build new file mode 100644 index 000000000..09804d424 --- /dev/null +++ b/litex/soc/software/libc/or1k-meson.build @@ -0,0 +1,48 @@ +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright © 2019 Keith Packard +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +# OF THE POSSIBILITY OF SUCH DAMAGE. +# +srcs_machine = [ + 'setjmp.S', +] + +foreach target : targets + value = get_variable('target_' + target) + set_variable('lib_machine' + target, + static_library('machine' + target, + srcs_machine, + pic: false, + include_directories: inc, + c_args: value[1] + arg_fnobuiltin)) +endforeach +