Browse Source

riscv: start experimenting with riscv32 / newlib toolchain

Waldemar Brodkorb 7 years ago
parent
commit
f139fafceb

+ 1 - 0
target/arch.lst

@@ -27,6 +27,7 @@ nios2
 or1k
 ppc
 ppc64
+riscv
 rx
 s390
 sparc

+ 3 - 0
target/config/Config.in.binutils

@@ -28,6 +28,7 @@ config ADK_TOOLCHAIN_BINUTILS_2_27
 	depends on !ADK_TARGET_ARCH_ARC
 	depends on !ADK_TARGET_ARCH_AVR32
 	depends on !ADK_TARGET_ARCH_NDS32
+	depends on !ADK_TARGET_ARCH_RISCV
 	depends on !ADK_TARGET_CPU_CRIS_CRISV10
 
 config ADK_TOOLCHAIN_BINUTILS_2_26_1
@@ -37,6 +38,7 @@ config ADK_TOOLCHAIN_BINUTILS_2_26_1
 	depends on !ADK_TARGET_ARCH_FRV
 	depends on !ADK_TARGET_ARCH_H8300
 	depends on !ADK_TARGET_ARCH_NDS32
+	depends on !ADK_TARGET_ARCH_RISCV
 	depends on !ADK_TARGET_SYSTEM_NUMATO_MIMASV2
 
 config ADK_TOOLCHAIN_BINUTILS_2_25_1
@@ -48,6 +50,7 @@ config ADK_TOOLCHAIN_BINUTILS_2_25_1
 	depends on !ADK_TARGET_ARCH_H8300
 	depends on !ADK_TARGET_ARCH_MOXIE
 	depends on !ADK_TARGET_ARCH_NDS32
+	depends on !ADK_TARGET_ARCH_RISCV
 	depends on !ADK_TARGET_CPU_CRIS_CRISV10
 	depends on !ADK_TARGET_SYSTEM_NUMATO_MIMASV2
 

+ 3 - 0
target/config/Config.in.compiler

@@ -54,6 +54,7 @@ config ADK_TOOLCHAIN_GCC_6
 	depends on !ADK_TARGET_ARCH_METAG
 	depends on !ADK_TARGET_ARCH_NDS32
 	depends on !ADK_TARGET_ARCH_OR1K
+	depends on !ADK_TARGET_ARCH_RISCV
 	select ADK_DISABLE_HONOUR_CFLAGS
 
 config ADK_TOOLCHAIN_GCC_5
@@ -71,6 +72,7 @@ config ADK_TOOLCHAIN_GCC_5
 	depends on !ADK_TARGET_ARCH_NIOS2
 	depends on !ADK_TARGET_ARCH_OR1K
 	depends on !ADK_TARGET_ARCH_LM32
+	depends on !ADK_TARGET_ARCH_RISCV
 	depends on !ADK_TARGET_SYSTEM_KINETIS_K70
 	depends on !(ADK_TARGET_LIB_GLIBC && ADK_TARGET_ARCH_SH)
 	depends on !ADK_TARGET_CPU_MIPS_MIPS32R6
@@ -90,6 +92,7 @@ config ADK_TOOLCHAIN_GCC_4_9
 	depends on !ADK_TARGET_ARCH_NIOS2
 	depends on !ADK_TARGET_ARCH_OR1K
 	depends on !ADK_TARGET_ARCH_TILE
+	depends on !ADK_TARGET_ARCH_RISCV
 	depends on !ADK_TARGET_CPU_MIPS_MIPS32R6
 	depends on !ADK_TARGET_CPU_MIPS64_MIPS64R6
 	depends on !ADK_TARGET_SYSTEM_NUMATO_MIMASV2

+ 7 - 0
target/config/Config.in.cpu

@@ -1009,6 +1009,12 @@ config ADK_TARGET_CPU_PPC64_POWER8
 	select ADK_TARGET_WITH_MMU
 	depends on ADK_TARGET_ARCH_PPC64
 
+# riscv 
+config ADK_TARGET_CPU_RISCV
+	bool "riscv"
+	select ADK_TARGET_WITH_MMU
+	depends on ADK_TARGET_ARCH_RISCV
+
 # rx
 config ADK_TARGET_CPU_RX
 	bool "rx"
@@ -2049,6 +2055,7 @@ config ADK_TARGET_CPU_ARCH
 	default "ppc" if ADK_TARGET_ARCH_PPC
 	default "ppc64le" if ADK_TARGET_ARCH_PPC64 && ADK_TARGET_LITTLE_ENDIAN
 	default "ppc64" if ADK_TARGET_ARCH_PPC64 && ADK_TARGET_BIG_ENDIAN
+	default "riscv32" if ADK_TARGET_ARCH_RISCV
 	default "rx" if ADK_TARGET_ARCH_RX
 	default "s390x" if ADK_TARGET_ARCH_S390
 	default "sh" if ADK_TARGET_CPU_SH_SH && ADK_TARGET_LITTLE_ENDIAN

+ 8 - 2
target/config/Config.in.libc

@@ -110,6 +110,7 @@ config ADK_TARGET_LIB_NEWLIB
 		ADK_TARGET_ARCH_NDS32 || \
 		ADK_TARGET_ARCH_OR1K || \
 		ADK_TARGET_ARCH_PPC || \
+		ADK_TARGET_ARCH_RISCV || \
 		ADK_TARGET_ARCH_RX || \
 		ADK_TARGET_ARCH_SH || \
 		ADK_TARGET_ARCH_SPARC || \
@@ -152,11 +153,15 @@ config ADK_TARGET_LIB_MUSL_GIT
 
 config ADK_TARGET_LIB_NEWLIB_2_5_0
 	bool "2.5.0"
-	depends on ADK_TARGET_LIB_NEWLIB
+	depends on ADK_TARGET_LIB_NEWLIB && !ADK_TARGET_ARCH_RISCV
+
+config ADK_TARGET_LIB_NEWLIB_RISCV
+	bool "2.4.0-riscv"
+	depends on ADK_TARGET_LIB_NEWLIB && ADK_TARGET_ARCH_RISCV
 
 config ADK_TARGET_LIB_NEWLIB_GIT
 	bool "git"
-	depends on ADK_TARGET_LIB_NEWLIB
+	depends on ADK_TARGET_LIB_NEWLIB && !ADK_TARGET_ARCH_RISCV
 
 endchoice
 
@@ -205,6 +210,7 @@ config ADK_LIBC_VERSION
 	default "1.1.16" if ADK_TARGET_LIB_MUSL_1_1_16
 	default "2.25" if ADK_TARGET_LIB_GLIBC_2_25
 	default "2.4.0" if ADK_TARGET_LIB_NEWLIB_2_4_0
+	default "2.4.0-riscv" if ADK_TARGET_LIB_NEWLIB_RISCV
 	default "git" if ADK_TARGET_LIB_UCLIBC_NG_GIT || \
 		         ADK_TARGET_LIB_MUSL_GIT || \
 		         ADK_TARGET_LIB_GLIBC_GIT || \

+ 43 - 0
target/riscv/Makefile

@@ -0,0 +1,43 @@
+# This file is part of the OpenADK project. OpenADK is copyrighted
+# material, please see the LICENCE file in the top-level directory.
+
+include $(ADK_TOPDIR)/rules.mk
+include $(ADK_TOPDIR)/mk/kernel-build.mk
+include $(ADK_TOPDIR)/mk/image.mk
+
+KERNEL:=$(LINUX_DIR)/vmlinux
+OSTRIP:=-R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
+QEMU_ARGS:=-nographic
+
+# target helper text
+ifeq ($(ADK_TARGET_FS),initramfs)
+targethelp:
+	@echo 'The kernel file is: $(FW_DIR)/${TARGET_KERNEL}'
+	@echo 'The initramfs image is: ${FW_DIR}/${INITRAMFS}'
+endif
+ifeq ($(ADK_TARGET_FS),initramfsarchive)
+targethelp:
+	@echo 'The kernel file is: $(FW_DIR)/${TARGET_KERNEL}'
+	@echo "The RootFS tarball is: $(FW_DIR)/$(ROOTFSUSERTARBALL)"
+endif
+ifeq ($(ADK_TARGET_FS),initramfspiggyback)
+targethelp:
+	@echo 'The kernel+initramfs file is: $(FW_DIR)/${TARGET_KERNEL}'
+endif
+
+kernel-strip:
+	$(TARGET_CROSS)objcopy $(OSTRIP) -S $(KERNEL) $(BUILD_DIR)/$(TARGET_KERNEL)
+
+kernel-install: kernel-strip
+	@cp $(BUILD_DIR)/$(TARGET_KERNEL) $(FW_DIR)/$(TARGET_KERNEL)
+
+# filesystem specific targets
+ifeq ($(ADK_TARGET_FS),initramfs)
+imageinstall: kernel-install $(FW_DIR)/$(INITRAMFS) targethelp
+endif
+ifeq ($(ADK_TARGET_FS),initramfsarchive)
+imageinstall: kernel-install $(FW_DIR)/$(ROOTFSUSERTARBALL) targethelp
+endif
+ifeq ($(ADK_TARGET_FS),initramfspiggyback)
+imageinstall: createinitramfs targethelp
+endif

+ 7 - 0
toolchain/newlib/Makefile.inc

@@ -15,3 +15,10 @@ PKG_HASH:=		5b76a9b97c9464209772ed25ce55181a7bb144a66e5669aaec945aa64da3189b
 PKG_SITES:=		ftp://sourceware.org/pub/newlib/
 DISTFILES:=		${PKG_NAME}-${PKG_VERSION}.tar.gz
 endif
+ifeq ($(ADK_TARGET_LIB_NEWLIB_RISCV),y)
+PKG_VERSION:=		riscv-newlib-2.4.0
+PKG_GIT:=		branch
+PKG_RELEASE:=		1
+PKG_SITES:=		https://github.com/riscv/riscv-newlib.git
+DISTFILES:=		${PKG_NAME}-${PKG_VERSION}.tar.xz
+endif

+ 12 - 0
toolchain/newlib/patches/riscv-newlib-2.4.0/fix-tooldir.patch

@@ -0,0 +1,12 @@
+diff -Nur newlib-2.2.0-1.orig/configure newlib-2.2.0-1/configure
+--- newlib-2.2.0-1.orig/configure	2014-07-05 23:09:07.000000000 +0200
++++ newlib-2.2.0-1/configure	2015-11-25 06:33:11.461178398 +0100
+@@ -6985,7 +6985,7 @@
+ 
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'
+ build_tooldir=${tooldir}
+ 
+ # Create a .gdbinit file which runs the one in srcdir