Skip to contentSkip to conversation

riscv: Extend CI

PATCH Superseded Andrew Jones 1 participant 4 messages Aug 8, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover riscv: Extend CI

So far we were only building and testing 64-bit, non-efi in the CI for riscv. I had mistakenly thought Fedora's riscv compiler could only build 64-bit, but it's multilib so we just need to add some CFLAGS to get it to work. To preserve building with a 32-bit-only riscv compiler we need to introduce limits.h to our tiny libc. And, while adding 32-bit builds to CI we also add EFI builds so now we test 32-bit, 64-bit, and 64-bit EFI. And, since Fedora has been udpated, bringing in a later QEMU, we can now do the testing with the 'max' cpu type.

Andrew Jones (3):
lib: Add limits.h
riscv: Build with explicit ABI
riscv: Extend gitlab CI

 .gitlab-ci.yml | 34 +++++++++++++++++++++++++++++-----
 lib/limits.h   | 43 +++++++++++++++++++++++++++++++++++++++++++
 riscv/Makefile | 10 ++++++----
 3 files changed, 78 insertions(+), 9 deletions(-)
 create mode 100644 lib/limits.h
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/3 lib: Add limits.h

We already include limits.h from a couple places (libfdt and the sbi test for riscv). We should provide our own limits.h rather than depend on the build environment as some cross environments may not support it (building riscv with a ilp32d toolchain fails, for example).

We guard each definition to ensure we only provide them when the sizes match our expectations. If something is strange then the define won't be created, and either the includer won't notice since it wasn't used or the build will break and limits.h can be extended.

---
 lib/limits.h | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 lib/limits.h
lib/limits.h new file +43 -0
new file mode 100644
index 000000000000..234ef5325f92
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LIMITS_H_
+#define _LIMITS_H_
+
+#if __CHAR_BIT__ == 8
+# if __CHAR_UNSIGNED__
+#  define CHAR_MIN	0
+#  define CHAR_MAX	__UINT8_MAX__
+# else
+#  define CHAR_MAX	__INT8_MAX__
+#  define CHAR_MIN	(-CHAR_MAX - 1)
+# endif
+#endif
+
+#if __SHRT_WIDTH__ == 16
+#define SHRT_MAX	__INT16_MAX__
+#define SHRT_MIN	(-SHRT_MAX - 1)
+#define USHRT_MAX	__UINT16_MAX__
+#endif
+
+#if __INT_WIDTH__ == 32
+#define INT_MAX		__INT32_MAX__
+#define INT_MIN		(-INT_MAX - 1)
+#define UINT_MAX	__UINT32_MAX__
+#endif
+
+#if __LONG_WIDTH__ == 64
+#define LONG_MAX	__INT64_MAX__
+#define LONG_MIN	(-LONG_MAX - 1)
+#define ULONG_MAX	__UINT64_MAX__
+#elif __LONG_WIDTH__ == 32
+#define LONG_MAX	__INT32_MAX__
+#define LONG_MIN	(-LONG_MAX - 1)
+#define ULONG_MAX	__UINT32_MAX__
+#endif
+
+#if __LONG_LONG_WIDTH__ == 64
+#define LLONG_MAX	__INT64_MAX__
+#define LLONG_MIN	(-LLONG_MAX - 1)
+#define ULLONG_MAX	__UINT64_MAX__
+#endif
+
+#endif /* _LIMITS_H_ */
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/3 riscv: Build with explicit ABI

In reply to Andrew Jones

If we add -mabi to the command line then compilers that are built to support multiple ABIs may be used for both rv32 and rv64 builds, so add it for that reason. We also need the right linker flags, so add those too and throw in a trimming of the ISA string (drop fd) in order to keep it minimal.

---
 riscv/Makefile | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
riscv/Makefile +6 -4
index b0cd613fcd8c..7906cef7f199 100644
@@ -64,13 +64,15 @@ define arch_elf_check =
 		$(error $(1) has unsupported reloc types))
 endef
 
-ISA_COMMON = mafdc_zicsr_zifencei_zihintpause
+ISA_COMMON = imac_zicsr_zifencei_zihintpause
 
 ifeq ($(ARCH),riscv64)
-CFLAGS += -march=rv64i$(ISA_COMMON)
-CFLAGS += -DCONFIG_64BIT
+CFLAGS  += -DCONFIG_64BIT
+CFLAGS  += -mabi=lp64 -march=rv64$(ISA_COMMON)
+LDFLAGS += -melf64lriscv
 else ifeq ($(ARCH),riscv32)
-CFLAGS += -march=rv32i$(ISA_COMMON)
+CFLAGS  += -mabi=ilp32 -march=rv32$(ISA_COMMON)
+LDFLAGS += -melf32lriscv
 endif
 CFLAGS += -DCONFIG_RELOC
 CFLAGS += -mcmodel=medany
Signature · 1 line
2.45.2
#3 lore raw

PATCH 3/3 riscv: Extend gitlab CI

In reply to Andrew Jones

Fedora's riscv64 gcc supports ilp32 so enable 32-bit RISCV testing. And use the out-of-tree template for the 32-bit build to get that covered too. Also add EFI build testing and, since Fedora has been updated which brings in a later QEMU, we can now use the 'max' cpu type.

---
 .gitlab-ci.yml | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
.gitlab-ci.yml +29 -5
index e0eb85a94910..ffbed7c8d301 100644
@@ -133,18 +133,42 @@ build-ppc64le:
       | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
-# build-riscv32:
-# Fedora doesn't package a riscv32 compiler for QEMU. Oh, well.
+build-riscv32:
+ extends: .outoftree_template
+ script:
+ - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
+ - ./configure --arch=riscv32 --cross-prefix=riscv64-linux-gnu-
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
 
-# Select 'rv64' with PROCESSOR_OVERRIDE in case QEMU is too old to have 'max'
 build-riscv64:
  extends: .intree_template
  script:
  - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
  - ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu-
  - make -j2
- - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\n" >test-env
- - PROCESSOR_OVERRIDE=rv64 ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
+
+build-riscv64-efi:
+ extends: .intree_template
+ script:
+ - dnf install -y edk2-riscv64 qemu-system-riscv gcc-riscv64-linux-gnu
+ - cp /usr/share/edk2/riscv/RISCV_VIRT_CODE.fd .
+ - truncate -s 32M RISCV_VIRT_CODE.fd
+ - ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu- --enable-efi
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
       selftest
       sbi
       | tee results.txt
Signature · 1 line
2.45.2