From d22f22640bf51a03be6aa34654576694cc746e06 Mon Sep 17 00:00:00 2001 From: Noam Camus Date: Tue, 13 Jun 2017 16:00:03 +0300 Subject: [PATCH] RISCV64: add buildroot toolchain support This is work in a progress, still got build issues defined by mlx_riscv64_defconfig Signed-off-by: Noam Camus --- arch/Config.in.riscv | 8 ++ configs/mlx_riscv64_defconfig | 11 ++ linux/riscv.patch | 10 ++ package/binutils/binutils.mk | 6 + ...IX-verlapping-FDEs-when-linking-libc.patch | 133 ++++++++++++++++++ package/gcc/gcc.mk | 6 + ...0001-remove-failed-s-selftest-target.patch | 12 ++ package/glibc/glibc.mk | 8 ++ package/linux-headers/Config.in.host | 4 + toolchain/toolchain-buildroot/Config.in | 2 +- toolchain/toolchain-common.in | 5 + 11 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 configs/mlx_riscv64_defconfig create mode 100644 linux/riscv.patch create mode 100644 package/binutils/riscv-next/0001-FIX-verlapping-FDEs-when-linking-libc.patch create mode 100644 package/gcc/riscv-next/0001-remove-failed-s-selftest-target.patch diff --git a/arch/Config.in.riscv b/arch/Config.in.riscv index d49a78ee9d..a04f8f1bc2 100644 --- a/arch/Config.in.riscv +++ b/arch/Config.in.riscv @@ -7,3 +7,11 @@ config BR2_ENDIAN config BR2_READELF_ARCH_NAME default "RISC-V" + +config BR2_GCC_TARGET_ARCH + default "rv32g" if BR2_riscv32 + default "rv64g" if BR2_riscv64 + +config BR2_GCC_TARGET_ABI + default "lp32d" if BR2_riscv32 + default "lp64d" if BR2_riscv64 diff --git a/configs/mlx_riscv64_defconfig b/configs/mlx_riscv64_defconfig new file mode 100644 index 0000000000..ccd95b2f6b --- /dev/null +++ b/configs/mlx_riscv64_defconfig @@ -0,0 +1,11 @@ +BR2_riscv64=y +BR2_GLIBC_VERSION_2_23=y +BR2_LINUX_KERNEL=y +BR2_LINUX_KERNEL_CUSTOM_GIT=y +BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/riscv/riscv-linux.git" +BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="riscv-next" +BR2_LINUX_KERNEL_PATCH="$(TOPDIR)/linux/riscv.patch" +BR2_LINUX_KERNEL_DEFCONFIG="riscv64_spike" +BR2_TARGET_ROOTFS_INITRAMFS=y +# BR2_TARGET_ROOTFS_TAR is not set +BR2_PACKAGE_HOST_MKE2IMG=y diff --git a/linux/riscv.patch b/linux/riscv.patch new file mode 100644 index 0000000000..1149d9bbef --- /dev/null +++ b/linux/riscv.patch @@ -0,0 +1,10 @@ +diff -urN linux-headers.orig/arch/riscv/include/uapi/asm/setup.h linux-headers/arch/riscv/include/uapi/asm/setup.h +--- linux-headers.orig/arch/riscv/include/uapi/asm/setup.h 1970-01-01 02:00:00.000000000 +0200 ++++ linux-headers/arch/riscv/include/uapi/asm/setup.h 2017-06-13 08:46:15.567800383 +0300 +@@ -0,0 +1,6 @@ ++/* ++ * setup.h is part of userspace header ABI so UAPI scripts have to generate it ++ * even if there's nothing to export - causing empty ++ * However to prevent "patch" from discarding it we add this placeholder ++ * comment ++ */ diff --git a/package/binutils/binutils.mk b/package/binutils/binutils.mk index bc0268eea4..017e869f9d 100644 --- a/package/binutils/binutils.mk +++ b/package/binutils/binutils.mk @@ -20,6 +20,12 @@ BINUTILS_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,binutils-gdb, BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz BINUTILS_FROM_GIT = y endif +ifeq ($(BR2_riscv64),y) +BINUTILS_VERSION = riscv-next +BINUTILS_SITE = https://github.com/riscv/riscv-binutils-gdb.git +BINUTILS_SITE_METHOD = git +BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz +endif BINUTILS_SITE ?= $(BR2_GNU_MIRROR)/binutils BINUTILS_SOURCE ?= binutils-$(BINUTILS_VERSION).tar.bz2 BINUTILS_EXTRA_CONFIG_OPTIONS = $(call qstrip,$(BR2_BINUTILS_EXTRA_CONFIG_OPTIONS)) diff --git a/package/binutils/riscv-next/0001-FIX-verlapping-FDEs-when-linking-libc.patch b/package/binutils/riscv-next/0001-FIX-verlapping-FDEs-when-linking-libc.patch new file mode 100644 index 0000000000..293483c6ab --- /dev/null +++ b/package/binutils/riscv-next/0001-FIX-verlapping-FDEs-when-linking-libc.patch @@ -0,0 +1,133 @@ +diff -urN binutils.orig/bfd/bfd-in2.h binutils/bfd/bfd-in2.h +--- binutils.orig/bfd/bfd-in2.h 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/bfd/bfd-in2.h 2017-06-13 15:52:19.961649468 +0300 +@@ -4769,6 +4769,7 @@ + BFD_RELOC_RISCV_SET8, + BFD_RELOC_RISCV_SET16, + BFD_RELOC_RISCV_SET32, ++ BFD_RELOC_RISCV_64_PCREL, + + /* Renesas RL78 Relocations. */ + BFD_RELOC_RL78_NEG8, +diff -urN binutils.orig/bfd/elfnn-riscv.c binutils/bfd/elfnn-riscv.c +--- binutils.orig/bfd/elfnn-riscv.c 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/bfd/elfnn-riscv.c 2017-06-13 15:53:06.036956405 +0300 +@@ -1566,6 +1566,7 @@ + case R_RISCV_SET8: + case R_RISCV_SET16: + case R_RISCV_SET32: ++ case R_RISCV_64_PCREL: + case R_RISCV_TLS_DTPREL32: + case R_RISCV_TLS_DTPREL64: + break; +@@ -1853,6 +1854,7 @@ + case R_RISCV_SET16: + case R_RISCV_SET32: + case R_RISCV_DELETE: ++ case R_RISCV_64_PCREL: + /* These require no special handling beyond perform_relocation. */ + break; + +diff -urN binutils.orig/bfd/elfxx-riscv.c binutils/bfd/elfxx-riscv.c +--- binutils.orig/bfd/elfxx-riscv.c 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/bfd/elfxx-riscv.c 2017-06-13 15:53:51.780243045 +0300 +@@ -849,6 +849,22 @@ + 0, /* src_mask */ + MINUS_ONE, /* dst_mask */ + FALSE), /* pcrel_offset */ ++ ++ /* Deletes bytes after this address. The addend specifies the number of ++ * bytes to delete, just like R_RISCV_ALIGN. */ ++ HOWTO (R_RISCV_64_PCREL, /* type */ ++ 0, /* rightshift */ ++ 4, /* size */ ++ 64, /* bitsize */ ++ TRUE, /* pc_relative */ ++ 0, /* bitpos */ ++ complain_overflow_dont, /* complain_on_overflow */ ++ bfd_elf_generic_reloc, /* special_function */ ++ "R_RISCV_64_PCREL", /* name */ ++ FALSE, /* partial_inplace */ ++ 0, /* src_mask */ ++ MINUS_ONE, /* dst_mask */ ++ FALSE), /* pcrel_offset */ + }; + + /* A mapping from BFD reloc types to RISC-V ELF reloc types. */ +@@ -910,6 +926,7 @@ + { BFD_RELOC_RISCV_SET8, R_RISCV_SET8 }, + { BFD_RELOC_RISCV_SET16, R_RISCV_SET16 }, + { BFD_RELOC_RISCV_SET32, R_RISCV_SET32 }, ++ { BFD_RELOC_RISCV_64_PCREL, R_RISCV_64_PCREL }, + }; + + /* Given a BFD reloc type, return a howto structure. */ +diff -urN binutils.orig/bfd/libbfd.h binutils/bfd/libbfd.h +--- binutils.orig/bfd/libbfd.h 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/bfd/libbfd.h 2017-06-13 15:54:06.212014046 +0300 +@@ -2212,6 +2212,7 @@ + "BFD_RELOC_RISCV_SET8", + "BFD_RELOC_RISCV_SET16", + "BFD_RELOC_RISCV_SET32", ++ "BFD_RELOC_RISCV_64_PCREL", + "BFD_RELOC_RL78_NEG8", + "BFD_RELOC_RL78_NEG16", + "BFD_RELOC_RL78_NEG24", +diff -urN binutils.orig/bfd/reloc.c binutils/bfd/reloc.c +--- binutils.orig/bfd/reloc.c 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/bfd/reloc.c 2017-06-13 15:54:19.819796701 +0300 +@@ -5155,6 +5155,8 @@ + BFD_RELOC_RISCV_SET16 + ENUMX + BFD_RELOC_RISCV_SET32 ++ENUMX ++ BFD_RELOC_RISCV_64_PCREL + ENUMDOC + RISC-V relocations. + +diff -urN binutils.orig/gas/config/tc-riscv.c binutils/gas/config/tc-riscv.c +--- binutils.orig/gas/config/tc-riscv.c 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/gas/config/tc-riscv.c 2017-06-13 15:55:11.218965592 +0300 +@@ -1871,6 +1871,7 @@ + bfd_byte *buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where); + bfd_boolean relaxable = FALSE; + offsetT loc; ++ segT sub_segment; + + /* Remember value for tc_gen_reloc. */ + fixP->fx_addnumber = *valP; +@@ -1919,6 +1920,23 @@ + break; + + case BFD_RELOC_64: ++ /* Use pc-relative relocation for FDE initial location. ++ The symbol address in .eh_frame may be adjusted in ++ _bfd_elf_discard_section_eh_frame, and the content of ++ .eh_frame will be adjusted in _bfd_elf_write_section_eh_frame. ++ Therefore, we cannot insert a relocation whose addend symbol is ++ in .eh_frame. Othrewise, the value may be adjusted twice.*/ ++ if (fixP->fx_addsy && fixP->fx_subsy ++ && (sub_segment = S_GET_SEGMENT (fixP->fx_subsy)) ++ && strcmp (sub_segment->name, ".eh_frame") == 0 ++ && S_GET_VALUE (fixP->fx_subsy) ++ == fixP->fx_frag->fr_address + fixP->fx_where) ++ { ++ fixP->fx_r_type = BFD_RELOC_RISCV_64_PCREL; ++ fixP->fx_subsy = NULL; ++ break; ++ } ++ /* Fall through. */ + case BFD_RELOC_32: + case BFD_RELOC_16: + case BFD_RELOC_8: +diff -urN binutils.orig/include/elf/riscv.h binutils/include/elf/riscv.h +--- binutils.orig/include/elf/riscv.h 2017-05-20 01:49:31.000000000 +0300 ++++ binutils/include/elf/riscv.h 2017-06-13 15:55:36.962544552 +0300 +@@ -87,6 +87,7 @@ + RELOC_NUMBER (R_RISCV_SET8, 54) + RELOC_NUMBER (R_RISCV_SET16, 55) + RELOC_NUMBER (R_RISCV_SET32, 56) ++ RELOC_NUMBER (R_RISCV_64_PCREL, 57) + END_RELOC_NUMBERS (R_RISCV_max) + + /* Processor specific flags for the ELF header e_flags field. */ diff --git a/package/gcc/gcc.mk b/package/gcc/gcc.mk index b52f9456b3..8e0f7f0226 100644 --- a/package/gcc/gcc.mk +++ b/package/gcc/gcc.mk @@ -16,6 +16,12 @@ GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz else ifeq ($(BR2_or1k),y) GCC_SITE = $(call github,openrisc,or1k-gcc,$(GCC_VERSION)) GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz +else ifeq ($(BR2_riscv64),y) +GCC_VERSION = riscv-next +GCC_SITE = https://github.com/riscv/riscv-gcc.git +HOST_GCC_INITIAL_SITE_METHOD = git +GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz +BR_NO_CHECK_HASH_FOR += $(GCC_SOURCE) else GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION) GCC_SOURCE = gcc-$(GCC_VERSION).tar.bz2 diff --git a/package/gcc/riscv-next/0001-remove-failed-s-selftest-target.patch b/package/gcc/riscv-next/0001-remove-failed-s-selftest-target.patch new file mode 100644 index 0000000000..bdce00b669 --- /dev/null +++ b/package/gcc/riscv-next/0001-remove-failed-s-selftest-target.patch @@ -0,0 +1,12 @@ +diff -urN gcc.orig/gcc/Makefile.in gcc/gcc/Makefile.in +--- gcc.orig/gcc/Makefile.in 2017-05-30 05:47:35.000000000 +0300 ++++ gcc/gcc/Makefile.in 2017-06-12 17:43:22.140479147 +0300 +@@ -1908,7 +1908,7 @@ + # Use "s-selftest" to ensure that we only run the selftests if the + # driver, cc1, or selftest data change. + .PHONY: selftest +-selftest: s-selftest ++selftest: # s-selftest + s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs \ + $(srcdir)/testsuite/selftests + $(GCC_FOR_TARGET) $(SELFTEST_FLAGS) diff --git a/package/glibc/glibc.mk b/package/glibc/glibc.mk index aa9b9069c9..76024f491d 100644 --- a/package/glibc/glibc.mk +++ b/package/glibc/glibc.mk @@ -9,6 +9,13 @@ GLIBC_SITE = $(BR2_GNU_MIRROR)/libc GLIBC_SOURCE = glibc-$(GLIBC_VERSION).tar.xz GLIBC_SRC_SUBDIR = . +ifeq ($(BR2_riscv64),y) +GLIBC_VERSION = riscv-next +GLIBC_SITE = https://github.com/riscv/riscv-glibc.git +GLIBC_SITE_METHOD = git +GLIBC_SOURCE = glibc-$(GLIBC_VERSION).tar.gz +endif + GLIBC_LICENSE = GPL-2.0+ (programs), LGPL-2.1+, BSD-3-Clause, MIT (library) GLIBC_LICENSE_FILES = $(addprefix $(GLIBC_SRC_SUBDIR)/,COPYING COPYING.LIB LICENSES) @@ -84,6 +91,7 @@ define GLIBC_CONFIGURE_CMDS --enable-shared \ $(if $(BR2_SOFT_FLOAT),--without-fp,--with-fp) \ $(if $(BR2_x86_64),--enable-lock-elision) \ + $(if $(BR2_riscv64),--disable-werror) \ --with-pkgversion="Buildroot" \ --without-cvs \ --disable-profile \ diff --git a/package/linux-headers/Config.in.host b/package/linux-headers/Config.in.host index 0c53416d94..5e4e3683e6 100644 --- a/package/linux-headers/Config.in.host +++ b/package/linux-headers/Config.in.host @@ -87,6 +87,10 @@ choice This is used to hide/show some packages that have strict requirements on the version of kernel headers. +config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_12 + bool "4.12.x" + select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12 + config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_11 bool "4.11.x" select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11 diff --git a/toolchain/toolchain-buildroot/Config.in b/toolchain/toolchain-buildroot/Config.in index 91cddc2374..59b40c8a24 100644 --- a/toolchain/toolchain-buildroot/Config.in +++ b/toolchain/toolchain-buildroot/Config.in @@ -47,7 +47,7 @@ config BR2_TOOLCHAIN_BUILDROOT_GLIBC BR2_mipsel || BR2_mips64 || BR2_mips64el|| \ BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le || \ BR2_sh || BR2_sparc64 || BR2_x86_64 || \ - BR2_microblaze || BR2_nios2 + BR2_microblaze || BR2_nios2 || BR2_riscv64 depends on BR2_USE_MMU depends on !BR2_STATIC_LIBS depends on !BR2_powerpc_SPE diff --git a/toolchain/toolchain-common.in b/toolchain/toolchain-common.in index d670f44747..5065ad418c 100644 --- a/toolchain/toolchain-common.in +++ b/toolchain/toolchain-common.in @@ -247,10 +247,15 @@ config BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11 bool select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_10 +config BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12 + bool + select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11 + # This order guarantees that the highest version is set, as kconfig # stops affecting a value on the first matching default. config BR2_TOOLCHAIN_HEADERS_AT_LEAST string + default "4.12" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12 default "4.11" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11 default "4.10" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_10 default "4.9" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_9