Skip to contentSkip to conversation

arch: add support for RISC-V 32-bit (riscv32) architecture

PATCH Superseded Mark Corbin 2 participants 6 messages Oct 20, 2018 – Oct 21, 2018 RISC-V

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 arch: add support for RISC-V 32-bit (riscv32) architecture

This enables a riscv32 system to be built with a Buildroot generated toolchain (gcc >= 7.x, binutils >= 2.30, glibc only).

This requires a custom version of glibc 2.26 from the riscv-glibc repository. Note that there are no tags in this repository, so the glibc version just consists of the 40 character commit id string.

Thanks to Fabrice Bellard for pointing me towards the 32-bit glibc repository and for providing the necessary patch to get it to build.

---
 arch/Config.in.riscv                          | 23 +++++++++++--
 arch/arch.mk.riscv                            |  4 ++-
 configs/qemu_riscv64_virt_defconfig           |  1 +
 .../0001-riscv32.patch                        | 33 +++++++++++++++++++
 .../glibc.hash                                |  7 ++++
 package/glibc/glibc.mk                        |  7 ++++
 6 files changed, 71 insertions(+), 4 deletions(-)
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash
arch/Config.in.riscv +20 -3
index 4361890bf4..4615f3c797 100644
@@ -66,13 +66,26 @@ config BR2_RISCV_ISA_CUSTOM_RVC
 endif
 
 config BR2_RISCV_64
-	bool
-	default y
+	bool "64-bit"
+	default n
 	select BR2_ARCH_IS_64
 
 choice
 	prompt "Target ABI"
-	default BR2_RISCV_ABI_LP64
+	default BR2_RISCV_ABI_ILP32 if !BR2_ARCH_IS_64
+	default BR2_RISCV_ABI_LP64 if BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32
+	bool "ilp32"
+	depends on !BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32F
+	bool "ilp32f"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVF
+
+config BR2_RISCV_ABI_ILP32D
+	bool "ilp32d"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVD
 
 config BR2_RISCV_ABI_LP64
 	bool "lp64"
@@ -88,12 +101,16 @@ config BR2_RISCV_ABI_LP64D
 endchoice
 
 config BR2_ARCH
+	default "riscv32" if !BR2_ARCH_IS_64
 	default "riscv64" if BR2_ARCH_IS_64
 
 config BR2_ENDIAN
 	default "LITTLE"
 
 config BR2_GCC_TARGET_ABI
+	default "ilp32" if BR2_RISCV_ABI_ILP32
+	default "ilp32f" if BR2_RISCV_ABI_ILP32F
+	default "ilp32d" if BR2_RISCV_ABI_ILP32D
 	default "lp64" if BR2_RISCV_ABI_LP64
 	default "lp64f" if BR2_RISCV_ABI_LP64F
 	default "lp64d" if BR2_RISCV_ABI_LP64D
arch/arch.mk.riscv +3 -1
index 022d1a6809..f3bf2b3467 100644
@@ -5,8 +5,10 @@
 
 ifeq ($(BR2_riscv),y)
 
-ifeq ($(BR2_ARCH_IS_64),y)
+ifeq ($(BR2_RISCV_64),y)
 GCC_TARGET_ARCH := rv64i
+else
+GCC_TARGET_ARCH := rv32i
 endif
 
 ifeq ($(BR2_RISCV_ISA_RVM),y)
configs/qemu_riscv64_virt_defconfig +1 -0
index 59343ee98f..e15f804341 100644
@@ -1,5 +1,6 @@
 # Architecture
 BR2_riscv=y
+BR2_RISCV_64=y
 
 # System
 BR2_SYSTEM_DHCP="eth0"
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +33 -0
new file mode 100644
index 0000000000..0d5a6b7710
@@ -0,0 +1,33 @@
+diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
+index 51d3819d4a..e728e8907e 100644
+--- a/elf/dl-runtime.c
++++ b/elf/dl-runtime.c
+@@ -146,6 +146,7 @@ _dl_fixup (
+   if (__glibc_unlikely (GLRO(dl_bind_not)))
+     return value;
+ 
++  (void)refsym;
+   return elf_machine_fixup_plt (l, result, refsym, sym, reloc, rel_addr, value);
+ }
+ 
+diff --git a/sysdeps/riscv/ldsodefs.h b/sysdeps/riscv/ldsodefs.h
+index db993df80a..91e7a8c88f 100644
+--- a/sysdeps/riscv/ldsodefs.h
++++ b/sysdeps/riscv/ldsodefs.h
+@@ -25,14 +25,14 @@ struct La_riscv_regs;
+ struct La_riscv_retval;
+ 
+ #define ARCH_PLTENTER_MEMBERS						\
+-    Elf64_Addr (*riscv_gnu_pltenter) (Elf64_Sym *, unsigned int,	\
++    ElfW(Addr) (*riscv_gnu_pltenter) (ElfW(Sym) *, unsigned int,	\
+ 				      uintptr_t *, uintptr_t *,		\
+ 				      const struct La_riscv_regs *,	\
+ 				      unsigned int *, const char *name,	\
+ 				      long int *framesizep);
+ 
+ #define ARCH_PLTEXIT_MEMBERS						\
+-    unsigned int (*riscv_gnu_pltexit) (Elf64_Sym *, unsigned int,	\
++    unsigned int (*riscv_gnu_pltexit) (ElfW(Sym) *, unsigned int,	\
+ 				       uintptr_t *, uintptr_t *,	\
+ 				       const struct La_riscv_regs *,	\
+ 				       struct La_riscv_retval *,	\
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash new file +7 -0
new file mode 100644
index 0000000000..3eb5e04e96
@@ -0,0 +1,7 @@
+# Locally calculated (fetched from Github)
+sha256 a40f908125135bad2cf92c18d07ad25b3091b161b3a5d3aea46c23ffd2ac90b8  glibc-4e2943456e690d89f48e6e710757dd09404b0c9a.tar.gz
+
+# Hashes for license files
+sha256 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 COPYING
+sha256 dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551 COPYING.LIB
+sha256 61abdd6930c9c599062d89e916b3e7968783879b6be0ee1c6229dd6169def431 LICENSES
package/glibc/glibc.mk +7 -0
index 708c22f723..cea77dff39 100644
@@ -7,6 +7,9 @@
 ifeq ($(BR2_arc),y)
 GLIBC_VERSION =  arc-2018.03-release
 GLIBC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,glibc,$(GLIBC_VERSION))
+else ifeq ($(BR2_riscv)$(BR2_RISCV_64),y)
+GLIBC_VERSION = 4e2943456e690d89f48e6e710757dd09404b0c9a
+GLIBC_SITE = $(call github,riscv,riscv-glibc,$(GLIBC_VERSION))
 else
 # Generate version string using:
 #   git describe --match 'glibc-*' --abbrev=40 origin/release/MAJOR.MINOR/master
@@ -79,7 +82,11 @@ GLIBC_CONF_ENV = \
 # Override the default library locations of /lib64/<abi> and
 # /usr/lib64/<abi>/ for RISC-V.
 ifeq ($(BR2_riscv),y)
+ifeq ($(BR2_RISCV_64),y)
 GLIBC_CONF_ENV += libc_cv_slibdir=/lib64 libc_cv_rtlddir=/lib
+else
+GLIBC_CONF_ENV += libc_cv_slibdir=/lib32 libc_cv_rtlddir=/lib
+endif
 endif
 
 # Even though we use the autotools-package infrastructure, we have to
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 configs/qemu: add qemu_riscv32_virt_defconfig

Add RISC-V 32-bit defconfig for QEMU virt machine.

Tested with QEMU 2.12.1

---
 board/qemu/riscv32-virt/linux.config | 23 +++++++++++++++++++++++
 board/qemu/riscv32-virt/readme.txt   |  7 +++++++
 configs/qemu_riscv32_virt_defconfig  | 24 ++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 board/qemu/riscv32-virt/linux.config
 create mode 100644 board/qemu/riscv32-virt/readme.txt
 create mode 100644 configs/qemu_riscv32_virt_defconfig
board/qemu/riscv32-virt/linux.config new file +23 -0
new file mode 100644
index 0000000000..c25583f768
@@ -0,0 +1,23 @@
+CONFIG_ARCH_RV32I=y
+CONFIG_SMP=y
+CONFIG_NR_CPUS=8
+CONFIG_PCI=y
+CONFIG_SYSVIPC=y
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_WIRELESS is not set
+CONFIG_VIRTIO_BLK=y
+CONFIG_NETDEVICES=y
+CONFIG_VIRTIO_NET=y
+# CONFIG_ETHERNET is not set
+# CONFIG_WLAN is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_VIRT_DRIVERS=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_EXT2_FS=y
+CONFIG_EXT4_FS=y
+CONFIG_TMPFS=y
board/qemu/riscv32-virt/readme.txt new file +7 -0
new file mode 100644
index 0000000000..2da99580e5
@@ -0,0 +1,7 @@
+Run the emulation with:
+
+  qemu-system-riscv32 -M virt -kernel output/images/bbl -append "root=/dev/vda ro console=ttyS0" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic
+
+The login prompt will appear in the terminal that started Qemu.
+
+Tested with QEMU 2.12.1
configs/qemu_riscv32_virt_defconfig new file +24 -0
new file mode 100644
index 0000000000..aec85e4639
@@ -0,0 +1,24 @@
+# Architecture
+BR2_riscv=y
+
+# System
+BR2_SYSTEM_DHCP="eth0"
+
+# Filesystem
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_GENERIC_GETTY=y
+BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
+
+# Linux headers same as kernel, a 4.15 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_15=y
+
+# Kernel
+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="fe92d7905c6ea0ebeabeb725b8040754ede7c220"
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/riscv32-virt/linux.config"
+
+# Bootloader
+BR2_TARGET_RISCV_PK=y
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 configs/qemu: add qemu_riscv32_virt_defconfig

Le 20/10/2018 ? 23:24, Mark Corbin a ?crit?:

Quoted 4 lines

Add RISC-V 32-bit defconfig for QEMU virt machine.

Tested with QEMU 2.12.1

Best regards,
Romain

Quoted 83 lines
---
 board/qemu/riscv32-virt/linux.config | 23 +++++++++++++++++++++++
 board/qemu/riscv32-virt/readme.txt   |  7 +++++++
 configs/qemu_riscv32_virt_defconfig  | 24 ++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 board/qemu/riscv32-virt/linux.config
 create mode 100644 board/qemu/riscv32-virt/readme.txt
 create mode 100644 configs/qemu_riscv32_virt_defconfig
board/qemu/riscv32-virt/linux.config new file +23 -0
new file mode 100644
index 0000000000..c25583f768
@@ -0,0 +1,23 @@
+CONFIG_ARCH_RV32I=y
+CONFIG_SMP=y
+CONFIG_NR_CPUS=8
+CONFIG_PCI=y
+CONFIG_SYSVIPC=y
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_WIRELESS is not set
+CONFIG_VIRTIO_BLK=y
+CONFIG_NETDEVICES=y
+CONFIG_VIRTIO_NET=y
+# CONFIG_ETHERNET is not set
+# CONFIG_WLAN is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_VIRT_DRIVERS=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_EXT2_FS=y
+CONFIG_EXT4_FS=y
+CONFIG_TMPFS=y
board/qemu/riscv32-virt/readme.txt new file +7 -0
new file mode 100644
index 0000000000..2da99580e5
@@ -0,0 +1,7 @@
+Run the emulation with:
+
+  qemu-system-riscv32 -M virt -kernel output/images/bbl -append "root=/dev/vda ro console=ttyS0" -drive file=output/images/rootfs.ext2,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0 -device virtio-net-device,netdev=net0 -nographic
+
+The login prompt will appear in the terminal that started Qemu.
+
+Tested with QEMU 2.12.1
configs/qemu_riscv32_virt_defconfig new file +24 -0
new file mode 100644
index 0000000000..aec85e4639
@@ -0,0 +1,24 @@
+# Architecture
+BR2_riscv=y
+
+# System
+BR2_SYSTEM_DHCP="eth0"
+
+# Filesystem
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_GENERIC_GETTY=y
+BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
+
+# Linux headers same as kernel, a 4.15 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_15=y
+
+# Kernel
+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="fe92d7905c6ea0ebeabeb725b8040754ede7c220"
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/riscv32-virt/linux.config"
+
+# Bootloader
+BR2_TARGET_RISCV_PK=y
#3 lore raw

PATCH 1/2 arch: add support for RISC-V 32-bit (riscv32) architecture

In reply to Mark Corbin

Hi Mark,

Le 20/10/2018 ? 23:24, Mark Corbin a ?crit?:

Quoted 6 lines

This enables a riscv32 system to be built with a Buildroot generated toolchain (gcc >= 7.x, binutils >= 2.30, glibc only).

This requires a custom version of glibc 2.26 from the riscv-glibc repository. Note that there are no tags in this repository, so the glibc version just consists of the 40 character commit id string.

This fork is based on the glibc 2.26 official release and not based on the glibc 2.26 stable branch. This particular version is know to have issues with C++ support on x86/x86_64 but it should not affect riscv32.

Quoted 72 lines

Thanks to Fabrice Bellard for pointing me towards the 32-bit glibc repository and for providing the necessary patch to get it to build.

---
 arch/Config.in.riscv                          | 23 +++++++++++--
 arch/arch.mk.riscv                            |  4 ++-
 configs/qemu_riscv64_virt_defconfig           |  1 +
 .../0001-riscv32.patch                        | 33 +++++++++++++++++++
 .../glibc.hash                                |  7 ++++
 package/glibc/glibc.mk                        |  7 ++++
 6 files changed, 71 insertions(+), 4 deletions(-)
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash
arch/Config.in.riscv +20 -3
index 4361890bf4..4615f3c797 100644
@@ -66,13 +66,26 @@ config BR2_RISCV_ISA_CUSTOM_RVC
 endif
 
 config BR2_RISCV_64
-	bool
-	default y
+	bool "64-bit"
+	default n
 	select BR2_ARCH_IS_64
 
 choice
 	prompt "Target ABI"
-	default BR2_RISCV_ABI_LP64
+	default BR2_RISCV_ABI_ILP32 if !BR2_ARCH_IS_64
+	default BR2_RISCV_ABI_LP64 if BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32
+	bool "ilp32"
+	depends on !BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32F
+	bool "ilp32f"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVF
+
+config BR2_RISCV_ABI_ILP32D
+	bool "ilp32d"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVD
 
 config BR2_RISCV_ABI_LP64
 	bool "lp64"
@@ -88,12 +101,16 @@ config BR2_RISCV_ABI_LP64D
 endchoice
 
 config BR2_ARCH
+	default "riscv32" if !BR2_ARCH_IS_64
 	default "riscv64" if BR2_ARCH_IS_64
 
 config BR2_ENDIAN
 	default "LITTLE"
 
 config BR2_GCC_TARGET_ABI
+	default "ilp32" if BR2_RISCV_ABI_ILP32
+	default "ilp32f" if BR2_RISCV_ABI_ILP32F
+	default "ilp32d" if BR2_RISCV_ABI_ILP32D
 	default "lp64" if BR2_RISCV_ABI_LP64
 	default "lp64f" if BR2_RISCV_ABI_LP64F
 	default "lp64d" if BR2_RISCV_ABI_LP64D
arch/arch.mk.riscv +0 -0
index 022d1a6809..f3bf2b3467 100644

arch/arch.mk.riscv line 8

Quoted 5 lines
arch/arch.mk.riscv +1 -1
@@ -5,8 +5,10 @@
 
 ifeq ($(BR2_riscv),y)
 
-ifeq ($(BR2_ARCH_IS_64),y)
+ifeq ($(BR2_RISCV_64),y)

Why this change is needed to add riscv32 support ? BR2_ARCH_IS_64 looks fine here. (BR2_ARCH_IS_64 is selected by BR2_RISCV_64)

package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch

Quoted 22 lines
arch/arch.mk.riscv +2 -0
 GCC_TARGET_ARCH := rv64i
+else
+GCC_TARGET_ARCH := rv32i
 endif
 
 ifeq ($(BR2_RISCV_ISA_RVM),y)
configs/qemu_riscv64_virt_defconfig +1 -0
index 59343ee98f..e15f804341 100644
@@ -1,5 +1,6 @@
 # Architecture
 BR2_riscv=y
+BR2_RISCV_64=y
 
 # System
 BR2_SYSTEM_DHCP="eth0"
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +0 -0
new file mode 100644
index 0000000000..0d5a6b7710

Please use git format-patch and add a small patch description, uptream status and your SoB line.

Quoted 52 lines
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +33 -0
@@ -0,0 +1,33 @@
+diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
+index 51d3819d4a..e728e8907e 100644
+--- a/elf/dl-runtime.c
++++ b/elf/dl-runtime.c
+@@ -146,6 +146,7 @@ _dl_fixup (
+   if (__glibc_unlikely (GLRO(dl_bind_not)))
+     return value;
+ 
++  (void)refsym;
+   return elf_machine_fixup_plt (l, result, refsym, sym, reloc, rel_addr, value);
+ }
+ 
+diff --git a/sysdeps/riscv/ldsodefs.h b/sysdeps/riscv/ldsodefs.h
+index db993df80a..91e7a8c88f 100644
+--- a/sysdeps/riscv/ldsodefs.h
++++ b/sysdeps/riscv/ldsodefs.h
+@@ -25,14 +25,14 @@ struct La_riscv_regs;
+ struct La_riscv_retval;
+ 
+ #define ARCH_PLTENTER_MEMBERS						\
+-    Elf64_Addr (*riscv_gnu_pltenter) (Elf64_Sym *, unsigned int,	\
++    ElfW(Addr) (*riscv_gnu_pltenter) (ElfW(Sym) *, unsigned int,	\
+ 				      uintptr_t *, uintptr_t *,		\
+ 				      const struct La_riscv_regs *,	\
+ 				      unsigned int *, const char *name,	\
+ 				      long int *framesizep);
+ 
+ #define ARCH_PLTEXIT_MEMBERS						\
+-    unsigned int (*riscv_gnu_pltexit) (Elf64_Sym *, unsigned int,	\
++    unsigned int (*riscv_gnu_pltexit) (ElfW(Sym) *, unsigned int,	\
+ 				       uintptr_t *, uintptr_t *,	\
+ 				       const struct La_riscv_regs *,	\
+ 				       struct La_riscv_retval *,	\
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash new file +7 -0
new file mode 100644
index 0000000000..3eb5e04e96
@@ -0,0 +1,7 @@
+# Locally calculated (fetched from Github)
+sha256 a40f908125135bad2cf92c18d07ad25b3091b161b3a5d3aea46c23ffd2ac90b8  glibc-4e2943456e690d89f48e6e710757dd09404b0c9a.tar.gz
+
+# Hashes for license files
+sha256 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 COPYING
+sha256 dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551 COPYING.LIB
+sha256 61abdd6930c9c599062d89e916b3e7968783879b6be0ee1c6229dd6169def431 LICENSES
package/glibc/glibc.mk +0 -0
index 708c22f723..cea77dff39 100644

package/glibc/glibc.mk line 10

Quoted 4 lines
package/glibc/glibc.mk +1 -0
@@ -7,6 +7,9 @@
 ifeq ($(BR2_arc),y)
 GLIBC_VERSION =  arc-2018.03-release
 GLIBC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,glibc,$(GLIBC_VERSION))
+else ifeq ($(BR2_riscv)$(BR2_RISCV_64),y)

usually we do something like "ifeq ($(BR2_riscv):$(BR2_RISCV_64),y:)" when there is multiple BR2 variables in a condition. Ok, in this case we can't have BR2_RISCV_64 without selecting BR2_riscv.

Otherwise it looks ok.

Best regards,
Romain

Quoted 18 lines
package/glibc/glibc.mk +6 -0
+GLIBC_VERSION = 4e2943456e690d89f48e6e710757dd09404b0c9a
+GLIBC_SITE = $(call github,riscv,riscv-glibc,$(GLIBC_VERSION))
 else
 # Generate version string using:
 #   git describe --match 'glibc-*' --abbrev=40 origin/release/MAJOR.MINOR/master
@@ -79,7 +82,11 @@ GLIBC_CONF_ENV = \
 # Override the default library locations of /lib64/<abi> and
 # /usr/lib64/<abi>/ for RISC-V.
 ifeq ($(BR2_riscv),y)
+ifeq ($(BR2_RISCV_64),y)
 GLIBC_CONF_ENV += libc_cv_slibdir=/lib64 libc_cv_rtlddir=/lib
+else
+GLIBC_CONF_ENV += libc_cv_slibdir=/lib32 libc_cv_rtlddir=/lib
+endif
 endif
 
 # Even though we use the autotools-package infrastructure, we have to
#4 lore raw

PATCH 1/2 arch: add support for RISC-V 32-bit (riscv32) architecture

Hello Romain

Quoted 85 lines · Romain Naour

Hi Mark,

Le 20/10/2018 ? 23:24, Mark Corbin a ?crit?:

Quoted 6 lines

This enables a riscv32 system to be built with a Buildroot generated toolchain (gcc >= 7.x, binutils >= 2.30, glibc only).

This requires a custom version of glibc 2.26 from the riscv-glibc repository. Note that there are no tags in this repository, so the glibc version just consists of the 40 character commit id string.

This fork is based on the glibc 2.26 official release and not based on the glibc 2.26 stable branch. This particular version is know to have issues with C++ support on x86/x86_64 but it should not affect riscv32.

Quoted 72 lines

Thanks to Fabrice Bellard for pointing me towards the 32-bit glibc repository and for providing the necessary patch to get it to build.

---
 arch/Config.in.riscv                          | 23 +++++++++++--
 arch/arch.mk.riscv                            |  4 ++-
 configs/qemu_riscv64_virt_defconfig           |  1 +
 .../0001-riscv32.patch                        | 33 +++++++++++++++++++
 .../glibc.hash                                |  7 ++++
 package/glibc/glibc.mk                        |  7 ++++
 6 files changed, 71 insertions(+), 4 deletions(-)
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch
 create mode 100644 package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash
arch/Config.in.riscv +20 -3
index 4361890bf4..4615f3c797 100644
@@ -66,13 +66,26 @@ config BR2_RISCV_ISA_CUSTOM_RVC
 endif
 
 config BR2_RISCV_64
-	bool
-	default y
+	bool "64-bit"
+	default n
 	select BR2_ARCH_IS_64
 
 choice
 	prompt "Target ABI"
-	default BR2_RISCV_ABI_LP64
+	default BR2_RISCV_ABI_ILP32 if !BR2_ARCH_IS_64
+	default BR2_RISCV_ABI_LP64 if BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32
+	bool "ilp32"
+	depends on !BR2_ARCH_IS_64
+
+config BR2_RISCV_ABI_ILP32F
+	bool "ilp32f"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVF
+
+config BR2_RISCV_ABI_ILP32D
+	bool "ilp32d"
+	depends on !BR2_ARCH_IS_64 && BR2_RISCV_ISA_RVD
 
 config BR2_RISCV_ABI_LP64
 	bool "lp64"
@@ -88,12 +101,16 @@ config BR2_RISCV_ABI_LP64D
 endchoice
 
 config BR2_ARCH
+	default "riscv32" if !BR2_ARCH_IS_64
 	default "riscv64" if BR2_ARCH_IS_64
 
 config BR2_ENDIAN
 	default "LITTLE"
 
 config BR2_GCC_TARGET_ABI
+	default "ilp32" if BR2_RISCV_ABI_ILP32
+	default "ilp32f" if BR2_RISCV_ABI_ILP32F
+	default "ilp32d" if BR2_RISCV_ABI_ILP32D
 	default "lp64" if BR2_RISCV_ABI_LP64
 	default "lp64f" if BR2_RISCV_ABI_LP64F
 	default "lp64d" if BR2_RISCV_ABI_LP64D
arch/arch.mk.riscv +0 -0
index 022d1a6809..f3bf2b3467 100644
@@ -5,8 +5,10 @@
 
Quoted 6 lines

arch/arch.mk.riscv line 8

Quoted 4 lines
arch/arch.mk.riscv +1 -1
 ifeq ($(BR2_riscv),y)
 
-ifeq ($(BR2_ARCH_IS_64),y)
+ifeq ($(BR2_RISCV_64),y)

Why this change is needed to add riscv32 support ? BR2_ARCH_IS_64 looks fine here. (BR2_ARCH_IS_64 is selected by BR2_RISCV_64)

I talked to Thomas and he has no real preference, but it probably makes sense to use BR2_RISCV_64 for things relating directly to the RISC-V architecture and BR2_ARCH_IS_64 for more generic features.

Quoted 16 lines
Quoted 16 lines
arch/arch.mk.riscv +2 -0
 GCC_TARGET_ARCH := rv64i
+else
+GCC_TARGET_ARCH := rv32i
 endif
 
 ifeq ($(BR2_RISCV_ISA_RVM),y)
configs/qemu_riscv64_virt_defconfig +1 -0
index 59343ee98f..e15f804341 100644
@@ -1,5 +1,6 @@
 # Architecture
 BR2_riscv=y
+BR2_RISCV_64=y
 
Quoted 9 lines

package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch

Quoted 7 lines
configs/qemu_riscv64_virt_defconfig +0 -0
 # System
 BR2_SYSTEM_DHCP="eth0"
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +0 -0
new file mode 100644
index 0000000000..0d5a6b7710

Please use git format-patch and add a small patch description, uptream status and your SoB line.

I will re-generate the patch.

Quoted 52 lines
Quoted 52 lines
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +33 -0
@@ -0,0 +1,33 @@
+diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
+index 51d3819d4a..e728e8907e 100644
+--- a/elf/dl-runtime.c
++++ b/elf/dl-runtime.c
+@@ -146,6 +146,7 @@ _dl_fixup (
+   if (__glibc_unlikely (GLRO(dl_bind_not)))
+     return value;
+ 
++  (void)refsym;
+   return elf_machine_fixup_plt (l, result, refsym, sym, reloc, rel_addr, value);
+ }
+ 
+diff --git a/sysdeps/riscv/ldsodefs.h b/sysdeps/riscv/ldsodefs.h
+index db993df80a..91e7a8c88f 100644
+--- a/sysdeps/riscv/ldsodefs.h
++++ b/sysdeps/riscv/ldsodefs.h
+@@ -25,14 +25,14 @@ struct La_riscv_regs;
+ struct La_riscv_retval;
+ 
+ #define ARCH_PLTENTER_MEMBERS						\
+-    Elf64_Addr (*riscv_gnu_pltenter) (Elf64_Sym *, unsigned int,	\
++    ElfW(Addr) (*riscv_gnu_pltenter) (ElfW(Sym) *, unsigned int,	\
+ 				      uintptr_t *, uintptr_t *,		\
+ 				      const struct La_riscv_regs *,	\
+ 				      unsigned int *, const char *name,	\
+ 				      long int *framesizep);
+ 
+ #define ARCH_PLTEXIT_MEMBERS						\
+-    unsigned int (*riscv_gnu_pltexit) (Elf64_Sym *, unsigned int,	\
++    unsigned int (*riscv_gnu_pltexit) (ElfW(Sym) *, unsigned int,	\
+ 				       uintptr_t *, uintptr_t *,	\
+ 				       const struct La_riscv_regs *,	\
+ 				       struct La_riscv_retval *,	\
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/glibc.hash new file +7 -0
new file mode 100644
index 0000000000..3eb5e04e96
@@ -0,0 +1,7 @@
+# Locally calculated (fetched from Github)
+sha256 a40f908125135bad2cf92c18d07ad25b3091b161b3a5d3aea46c23ffd2ac90b8  glibc-4e2943456e690d89f48e6e710757dd09404b0c9a.tar.gz
+
+# Hashes for license files
+sha256 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 COPYING
+sha256 dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551 COPYING.LIB
+sha256 61abdd6930c9c599062d89e916b3e7968783879b6be0ee1c6229dd6169def431 LICENSES
package/glibc/glibc.mk +0 -0
index 708c22f723..cea77dff39 100644
Quoted 8 lines

package/glibc/glibc.mk line 10

Quoted 5 lines
package/glibc/glibc.mk +1 -0
@@ -7,6 +7,9 @@
 ifeq ($(BR2_arc),y)
 GLIBC_VERSION =  arc-2018.03-release
 GLIBC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,glibc,$(GLIBC_VERSION))
+else ifeq ($(BR2_riscv)$(BR2_RISCV_64),y)

usually we do something like "ifeq ($(BR2_riscv):$(BR2_RISCV_64),y:)" when there is multiple BR2 variables in a condition. Ok, in this case we can't have BR2_RISCV_64 without selecting BR2_riscv.

Ok, I'll change this.

Regards

Mark

Quoted 24 lines

Otherwise it looks ok.

Best regards,
Romain

Quoted 18 lines
package/glibc/glibc.mk +6 -0
+GLIBC_VERSION = 4e2943456e690d89f48e6e710757dd09404b0c9a
+GLIBC_SITE = $(call github,riscv,riscv-glibc,$(GLIBC_VERSION))
 else
 # Generate version string using:
 #   git describe --match 'glibc-*' --abbrev=40 origin/release/MAJOR.MINOR/master
@@ -79,7 +82,11 @@ GLIBC_CONF_ENV = \
 # Override the default library locations of /lib64/<abi> and
 # /usr/lib64/<abi>/ for RISC-V.
 ifeq ($(BR2_riscv),y)
+ifeq ($(BR2_RISCV_64),y)
 GLIBC_CONF_ENV += libc_cv_slibdir=/lib64 libc_cv_rtlddir=/lib
+else
+GLIBC_CONF_ENV += libc_cv_slibdir=/lib32 libc_cv_rtlddir=/lib
+endif
 endif
 
 # Even though we use the autotools-package infrastructure, we have to
Signature · 22 lines
*Mark Corbin*
Embedded Operating Systems Lead
Phone: +44 1590 610184?????Mobile: +44 7765 703479
Email: mark.corbin at embecosm.com
<mailto:[email protected]>?????Web: https://www.embecosm.com

Embecosm Logo

Embecosm Ltd., Palamos House #208, 66/67 High Street, Lymington, SO41
9AL, UK
Company No. 6577021 (England & Wales).
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20181021/f9824391/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo.png
Type: image/png
Size: 8442 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20181021/f9824391/attachment.png>
#5 lore raw

PATCH 1/2 arch: add support for RISC-V 32-bit (riscv32) architecture

Hi Mark,

Le 21/10/2018 ? 14:13, Mark Corbin a ?crit?:

Quoted 21 lines

Hello Romain

Quoted 18 lines · Romain Naour

Hi Mark,

Le 20/10/2018 ? 23:24, Mark Corbin a ?crit?:

Quoted 6 lines

This enables a riscv32 system to be built with a Buildroot generated toolchain (gcc >= 7.x, binutils >= 2.30, glibc only).

This requires a custom version of glibc 2.26 from the riscv-glibc repository. Note that there are no tags in this repository, so the glibc version just consists of the 40 character commit id string.

This fork is based on the glibc 2.26 official release and not based on the glibc 2.26 stable branch. This particular version is know to have issues with C++ support on x86/x86_64 but it should not affect riscv32.

Quoted 5 lines

Thanks to Fabrice Bellard for pointing me towards the 32-bit glibc repository and for providing the necessary patch to get it to build.

---

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
arch/arch.mk.riscv +0 -0
index 022d1a6809..f3bf2b3467 100644
@@ -5,8 +5,10 @@
 
 ifeq ($(BR2_riscv),y)
 
Quoted 7 lines
Quoted 4 lines

arch/arch.mk.riscv line 8

Quoted 2 lines
arch/arch.mk.riscv +1 -1
-ifeq ($(BR2_ARCH_IS_64),y)
+ifeq ($(BR2_RISCV_64),y)

Why this change is needed to add riscv32 support ? BR2_ARCH_IS_64 looks fine here. (BR2_ARCH_IS_64 is selected by BR2_RISCV_64)

I talked to Thomas and he has no real preference, but it probably makes sense to use BR2_RISCV_64 for things relating directly to the RISC-V architecture and BR2_ARCH_IS_64 for more generic features.

ok.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/arch.mk.riscv +2 -0
 GCC_TARGET_ARCH := rv64i
+else
+GCC_TARGET_ARCH := rv32i
 endif
 
 ifeq ($(BR2_RISCV_ISA_RVM),y)

[...]

Quoted 8 lines
Quoted 7 lines

package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch

Quoted 5 lines
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +0 -0
new file mode 100644
index 0000000000..0d5a6b7710

Please use git format-patch and add a small patch description, uptream status and your SoB line.

I will re-generate the patch.

ok thanks!

Quoted 1 line
Quoted 1 line
Quoted 1 line
package/glibc/4e2943456e690d89f48e6e710757dd09404b0c9a/0001-riscv32.patch new file +0 -0
@@ -0,0 +1,33 @@

[...]

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
package/glibc/glibc.mk +0 -0
index 708c22f723..cea77dff39 100644
Quoted 8 lines

package/glibc/glibc.mk line 10

Quoted 5 lines
package/glibc/glibc.mk +1 -0
@@ -7,6 +7,9 @@
 ifeq ($(BR2_arc),y)
 GLIBC_VERSION =  arc-2018.03-release
 GLIBC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,glibc,$(GLIBC_VERSION))
+else ifeq ($(BR2_riscv)$(BR2_RISCV_64),y)

usually we do something like "ifeq ($(BR2_riscv):$(BR2_RISCV_64),y:)" when there is multiple BR2 variables in a condition. Ok, in this case we can't have BR2_RISCV_64 without selecting BR2_riscv.

Quoted 1 line

Ok, I'll change this.

Best regards,
Romain

Quoted 42 lines

Regards

Mark

Quoted 24 lines

Otherwise it looks ok.

Best regards,
Romain

Quoted 18 lines
package/glibc/glibc.mk +6 -0
+GLIBC_VERSION = 4e2943456e690d89f48e6e710757dd09404b0c9a
+GLIBC_SITE = $(call github,riscv,riscv-glibc,$(GLIBC_VERSION))
 else
 # Generate version string using:
 #   git describe --match 'glibc-*' --abbrev=40 origin/release/MAJOR.MINOR/master
@@ -79,7 +82,11 @@ GLIBC_CONF_ENV = \
 # Override the default library locations of /lib64/<abi> and
 # /usr/lib64/<abi>/ for RISC-V.
 ifeq ($(BR2_riscv),y)
+ifeq ($(BR2_RISCV_64),y)
 GLIBC_CONF_ENV += libc_cv_slibdir=/lib64 libc_cv_rtlddir=/lib
+else
+GLIBC_CONF_ENV += libc_cv_slibdir=/lib32 libc_cv_rtlddir=/lib
+endif
 endif
 
 # Even though we use the autotools-package infrastructure, we have to
Signature · 11 lines
*Mark Corbin*
Embedded Operating Systems Lead
Phone: +44 1590 610184?????Mobile: +44 7765 703479
Email: mark.corbin at embecosm.com <mailto:[email protected]>?????Web:
https://www.embecosm.com

Embecosm Logo

Embecosm Ltd., Palamos House #208, 66/67 High Street, Lymington, SO41 9AL, UK
Company No. 6577021 (England & Wales).
--