From 5c5a86e5430c3da6bdcc735ec432bc0d7e675a28b08ea0fe91d3b12932453eb4 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Wed, 23 Oct 2019 06:00:37 +0000 Subject: [PATCH] Accepting request 741725 from home:Andreas_Schwab:Factory - Enable support for riscv64 - Backports from upstream: * risc-v-fix-computation-of-pc-relative-relocation-offset.patch * risc-v-add-clzdi2-symbol.patch * grub-install-define-default-platform-for-risc-v.patch OBS-URL: https://build.opensuse.org/request/show/741725 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=341 --- ...l-define-default-platform-for-risc-v.patch | 34 ++++++++++++++ grub2.changes | 9 ++++ grub2.spec | 21 +++++++-- risc-v-add-clzdi2-symbol.patch | 46 +++++++++++++++++++ ...ion-of-pc-relative-relocation-offset.patch | 39 ++++++++++++++++ 5 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 grub-install-define-default-platform-for-risc-v.patch create mode 100644 risc-v-add-clzdi2-symbol.patch create mode 100644 risc-v-fix-computation-of-pc-relative-relocation-offset.patch diff --git a/grub-install-define-default-platform-for-risc-v.patch b/grub-install-define-default-platform-for-risc-v.patch new file mode 100644 index 0000000..00315a4 --- /dev/null +++ b/grub-install-define-default-platform-for-risc-v.patch @@ -0,0 +1,34 @@ +From 11268841e2e0130a862d15fce86d42cd6501bb49 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Thu, 15 Aug 2019 16:55:13 +0200 +Subject: [PATCH] grub-install: Define default platform for RISC-V + +Signed-off-by: Andreas Schwab +Reviewed-by: Daniel Kiper +Reviewed-by: Alexander Graf +--- + util/grub-install.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/util/grub-install.c b/util/grub-install.c +index 8a55ad4b8..8970b73aa 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -324,6 +324,14 @@ get_default_platform (void) + return "arm64-efi"; + #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) + return grub_install_get_default_x86_platform (); ++#elif defined (__riscv) ++#if __riscv_xlen == 32 ++ return "riscv32-efi"; ++#elif __riscv_xlen == 64 ++ return "riscv64-efi"; ++#else ++ return NULL; ++#endif + #elif defined (__s390x__) + return "s390x-emu"; + #else +-- +2.23.0 + diff --git a/grub2.changes b/grub2.changes index 917c2c7..04e3484 100644 --- a/grub2.changes +++ b/grub2.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Tue Oct 22 08:05:19 UTC 2019 - Andreas Schwab + +- Enable support for riscv64 +- Backports from upstream: + * risc-v-fix-computation-of-pc-relative-relocation-offset.patch + * risc-v-add-clzdi2-symbol.patch + * grub-install-define-default-platform-for-risc-v.patch + ------------------------------------------------------------------- Thu Oct 17 06:34:52 UTC 2019 - Michael Chang diff --git a/grub2.spec b/grub2.spec index c13a4aa..2039c9f 100644 --- a/grub2.spec +++ b/grub2.spec @@ -101,11 +101,17 @@ BuildRequires: update-bootloader-rpm-macros %define only_efi 1 %endif +%ifarch riscv64 +%define grubcpu riscv64 +%define platform efi +%define only_efi 1 +%endif + %define grubarch %{grubcpu}-%{platform} # build efi bootloader on some platforms only: %if ! 0%{?efi:1} -%global efi %{ix86} x86_64 ia64 aarch64 %{arm} +%global efi %{ix86} x86_64 ia64 aarch64 %{arm} riscv64 %endif %ifarch %{efi} @@ -277,6 +283,10 @@ Patch501: grub2-btrfs-help-on-snapper-rollback.patch Patch510: grub2-video-limit-the-resolution-for-fixed-bimap-font.patch # Support long menuentries (FATE#325760) Patch511: grub2-gfxmenu-support-scrolling-menu-entry-s-text.patch +# RISC-V fixes +Patch601: risc-v-fix-computation-of-pc-relative-relocation-offset.patch +Patch602: risc-v-add-clzdi2-symbol.patch +Patch603: grub-install-define-default-platform-for-risc-v.patch Requires: gettext-runtime %if 0%{?suse_version} >= 1140 @@ -310,7 +320,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build %if 0%{?only_x86_64:1} ExclusiveArch: x86_64 %else -ExclusiveArch: %{ix86} x86_64 ppc ppc64 ppc64le s390x aarch64 %{arm} +ExclusiveArch: %{ix86} x86_64 ppc ppc64 ppc64le s390x aarch64 %{arm} riscv64 %endif %description @@ -371,10 +381,10 @@ provides support for %{platform} systems. %package %{grubefiarch} Summary: Bootloader with support for Linux, Multiboot and more -# Require efibootmgr -# Without it grub-install is broken so break the package as well if unavailable Group: System/Boot BuildArch: noarch +# Require efibootmgr +# Without it grub-install is broken so break the package as well if unavailable Requires: efibootmgr Requires(post): efibootmgr Requires: %{name} = %{version} @@ -541,6 +551,9 @@ swap partition while in resuming %patch501 -p1 %patch510 -p1 %patch511 -p1 +%patch601 -p1 +%patch602 -p1 +%patch603 -p1 %build # collect evidence to debug spurious build failure on SLE15 diff --git a/risc-v-add-clzdi2-symbol.patch b/risc-v-add-clzdi2-symbol.patch new file mode 100644 index 0000000..a42d38f --- /dev/null +++ b/risc-v-add-clzdi2-symbol.patch @@ -0,0 +1,46 @@ +From a57977b5faf800ac68f7dfe6b84138208c7e6072 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Thu, 19 Sep 2019 09:39:04 +0200 +Subject: [PATCH] RISC-V: Add __clzdi2 symbol + +This is needed for the zstd module build for riscv64-emu. + +Signed-off-by: Andreas Schwab +Reviewed-by: Daniel Kiper +--- + configure.ac | 2 +- + include/grub/compiler-rt-emu.h | 5 +++++ + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index e07ba4b56..7d74eba66 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1370,7 +1370,7 @@ fi + + # Check for libgcc symbols + if test x"$platform" = xemu; then +-AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) ++AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __clzdi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) + fi + + if test "x$TARGET_APPLE_LINKER" = x1 ; then +diff --git a/include/grub/compiler-rt-emu.h b/include/grub/compiler-rt-emu.h +index b21425d9e..fde620ac1 100644 +--- a/include/grub/compiler-rt-emu.h ++++ b/include/grub/compiler-rt-emu.h +@@ -74,6 +74,11 @@ unsigned + EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); + #endif + ++#ifdef HAVE___CLZDI2 ++int ++EXPORT_FUNC (__clzdi2) (grub_uint64_t x); ++#endif ++ + #ifdef HAVE___AEABI_UIDIV + grub_uint32_t + EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); +-- +2.23.0 + diff --git a/risc-v-fix-computation-of-pc-relative-relocation-offset.patch b/risc-v-fix-computation-of-pc-relative-relocation-offset.patch new file mode 100644 index 0000000..b77926a --- /dev/null +++ b/risc-v-fix-computation-of-pc-relative-relocation-offset.patch @@ -0,0 +1,39 @@ +From 2bf40e9e5be9808b17852e688eead87acff14420 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Wed, 26 Jun 2019 16:50:03 +0200 +Subject: [PATCH] RISC-V: Fix computation of pc-relative relocation offset + +The offset calculation was missing the relocation addend. + +Signed-off-by: Andreas Schwab +Tested-by: Chester Lin +Reviewed-by: Daniel Kiper +--- + util/grub-mkimagexx.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c +index bc087c2b5..d16ec63a1 100644 +--- a/util/grub-mkimagexx.c ++++ b/util/grub-mkimagexx.c +@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, + grub_uint32_t *t32 = (grub_uint32_t *) target; + grub_uint16_t *t16 = (grub_uint16_t *) target; + grub_uint8_t *t8 = (grub_uint8_t *) target; +- grub_int64_t off = (long)sym_addr - target_section_addr - offset +- - image_target->vaddr_offset; ++ grub_int64_t off; + + /* + * Instructions and instruction encoding are documented in the RISC-V +@@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd, + */ + + sym_addr += addend; ++ off = sym_addr - target_section_addr - offset - image_target->vaddr_offset; + + switch (ELF_R_TYPE (info)) + { +-- +2.23.0 +