new file mode 100644
@@ -0,0 +1,39 @@
+From fcf4b96cfd3a04e1cfa177b08afba4fd80c9978e Mon Sep 17 00:00:00 2001
+From: Jason Montleon <jason@montleon.com>
+Date: Fri, 3 May 2024 13:18:37 -0400
+Subject: [PATCH] Use medany instead of large model for RISCV
+
+Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]
+
+Signed-off-by: Jason Montleon <jason@montleon.com>
+Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
+---
+ configure.ac | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 0d693f8..0289fe1 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1653,7 +1653,7 @@ fi]
+
+ CFLAGS="$TARGET_CFLAGS"
+
+-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
++if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
+ # Use large model to support 4G memory
+ AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
+ CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+@@ -1663,9 +1663,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_
+ ])
+ if test "x$grub_cv_cc_mcmodel" = xyes; then
+ TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+- elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
++ elif test "$target_cpu" = sparc64; then
+ TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
+ fi
++elif test "$target_cpu" = riscv64 ; then
++ TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
+ fi
+
+ # Stack smashing protector.
@@ -19,6 +19,7 @@ SRC_URI = "${GNU_MIRROR}/grub/grub-${PV}.tar.gz \
file://0003-grub.d-10_linux.in-add-oe-s-kernel-name.patch \
file://0001-Revert-configure-Check-linker-for-image-base-support.patch \
file://0002-Revert-configure-Print-a-more-helpful-error-if-autoc.patch \
+ file://0263-Use-medany-instead-of-large-model-for-RISCV.patch \
"
SRC_URI[sha256sum] = "d0415fbb3e739237064e173743a6e5f60c33a81ec02a069cc9152d80efff4967"
From the upstream bug report, filed in 2024: |GRUB 2.12 does not compile correctly using large model on riscv64 using gcc 14.1.1 (gcc-14.1.1-5.fc40.x86_64). | |It is my understanding that the large model should not really be used on riscv64 yet and trying to build GRUB 2.12 with it results in an error: | |+ ././grub-mkimage -O riscv64-efi -o grubriscv64.efi.orig -d grub-core --sbat ././sbat.csv -m memdisk.squashfs -p /EFI/fedora all_video boot blscfg btrfs cat configfile cryptodisk echo ext2 f2fs fat font gcry_rijndael gcry_rsa gcry_serpent gcry_sha256 gcry_twofish gcry_whirlpool gfxmenu gfxterm gzio halt hfsplus http increment iso9660 jpeg loadenv loopback linux lvm luks luks2 memdisk mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 pgp png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep squash4 syslinuxcfg test tftp version video xfs zstd efi_netfs efifwsetup efinet lsefi lsefimmap connectefi |././grub-mkimage: error: relocation 0x2b is not implemented yet. | |medany builds successfully and boots on the VisionFive2 and on VMs. Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com> --- This was originally submitted to solve VisionFive 2 builds in meta-riscv: https://github.com/riscv/meta-riscv/pull/553 But it was suggested to submit here instead so it could be applied more generally. I've tested it out three ways to ensure no adverse boot/build effects: 1. MACHINE=visionfive2 in meta-riscv (the original test case) via SD card on a VisionFive 2 2. MACHINE=genericx86-64 (via QEMU), with EFI support enabled 3. MACHINE=qemuriscv64, with EFI support enabled ...any-instead-of-large-model-for-RISCV.patch | 39 +++++++++++++++++++ meta/recipes-bsp/grub/grub2.inc | 1 + 2 files changed, 40 insertions(+) create mode 100644 meta/recipes-bsp/grub/files/0263-Use-medany-instead-of-large-model-for-RISCV.patch