Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add loong64 old-world firmware compatibility #15

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
grub2 (2.12-1deepin8) unstable; urgency=medium

* (loong64) Introduce a patch for old-world firmware compatibility.

-- Mingcong Bai <baimingcong@uniontech.com> Thu, 08 Aug 2024 11:34:13 +0800

grub2 (2.12-1deepin7) unstable; urgency=medium

* grub-mkrescue: use upper-case paths for EFI images.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
From ce9bc1a3687bba025d2a236cf1f2132d0c760b06 Mon Sep 17 00:00:00 2001
From: Mingcong Bai <jeffbai@aosc.io>
Date: Fri, 9 Aug 2024 17:31:35 +0800
Subject: [PATCH] grub-install: (loongarch64-efi) also install
BOOTLOONGARCH.EFI

Some old-world firmware (especially that of the BPI01000 revision) does not
recognise the standardised BOOTLOONGARCH64.EFI and only sees BOOTLOONGARCH.EFI
as the removable image name. Make a copy (since it is FAT/VFAT) to satisfy
both old- and new-world firmware.
---
util/grub-install.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/util/grub-install.c b/util/grub-install.c
index dfcd269..81fdfb4 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -958,6 +958,8 @@ main (int argc, char *argv[])
int is_efi = 0;
const char *efi_distributor = NULL;
const char *efi_suffix = NULL, *efi_suffix_upper = NULL;
+ // For LoongArch old-world firmware compatibility.
+ const char *efi_suffix_ow = NULL, *efi_suffix_upper_ow = NULL;
char *efi_file = NULL;
char **grub_devices;
grub_fs_t grub_fs;
@@ -1285,6 +1287,8 @@ main (int argc, char *argv[])
case GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI:
efi_suffix = "loongarch64";
efi_suffix_upper = "LOONGARCH64";
+ efi_suffix_ow = "loongarch";
+ efi_suffix_upper_ow = "LOONGARCH";
break;
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
efi_suffix = "riscv32";
@@ -2145,6 +2149,7 @@ main (int argc, char *argv[])
{
char *dst = grub_util_path_concat (2, efidir, efi_file);
char *removable_file = xasprintf ("BOOT%s.EFI", efi_suffix_upper);
+ char *removable_file_ow = xasprintf ("BOOT%s.EFI", efi_suffix_upper_ow);

if (uefi_secure_boot)
{
@@ -2222,6 +2227,10 @@ main (int argc, char *argv[])
grub_util_info ("Secure boot: installing shim and image into rm path");
also_install_removable (shim_signed, base_efidir, removable_file, 1);

+ if (platform == GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI) {
+ also_install_removable (shim_signed, base_efidir, removable_file_ow, 1);
+ }
+
also_install_removable (efi_signed, base_efidir, chained_base, 1);
also_install_removable (mok_src, base_efidir, mok_file, 0);

@@ -2251,6 +2260,10 @@ main (int argc, char *argv[])
{
grub_util_info ("Secure boot (no shim): installing signed grub binary into rm path");
also_install_removable (efi_signed, base_efidir, removable_file, 1);
+
+ if (platform == GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI) {
+ also_install_removable (efi_signed, base_efidir, removable_file_ow, 1);
+ }
}
}

@@ -2274,8 +2287,12 @@ main (int argc, char *argv[])
/* No secure boot - just install our newly-generated image */
grub_util_info ("No Secure Boot: installing core image");
grub_install_copy_file (imgfile, dst, 1);
- if (force_extra_removable)
+ if (force_extra_removable) {
also_install_removable (imgfile, base_efidir, removable_file, 1);
+ if (platform == GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI) {
+ also_install_removable (imgfile, base_efidir, removable_file_ow, 1);
+ }
+ }
}

grub_set_install_backup_ponr ();
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From 6740b5a0d995e41d1407ed844f4f5e358df9a421 Mon Sep 17 00:00:00 2001
From: Miao Wang <shankerwangmiao@gmail.com>
Date: Wed, 17 Jul 2024 09:16:26 +0800
Subject: [PATCH] loongarch64: able to start on legacy firmware

On legacy firmware, the DMW is already enabled by the firmware, and the
addresses in all the pointers and the PC register are virtual addresses.
GRUB, however, is location independent, so will not be affected. The
only problem happens at the GRUB_EFI_MAX_USABLE_ADDRESS, which should
be dynamically decided by detecting if DMW is enabled.
---
include/grub/loongarch64/efi/memory.h | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/grub/loongarch64/efi/memory.h b/include/grub/loongarch64/efi/memory.h
index d460267be..534ba4b32 100644
--- a/include/grub/loongarch64/efi/memory.h
+++ b/include/grub/loongarch64/efi/memory.h
@@ -19,6 +19,25 @@
#ifndef GRUB_MEMORY_CPU_HEADER
#include <grub/efi/memory.h>

-#define GRUB_EFI_MAX_USABLE_ADDRESS 0xfffffffffffULL
+static inline grub_uint64_t
+grub_efi_max_usable_address(void)
+{
+ static grub_uint64_t addr;
+ static int addr_valid = 0;
+
+ if (!addr_valid)
+ {
+ asm volatile ("csrrd %0, 0x181" : "=r" (addr));
+ if (addr & 0x1)
+ addr |= 0xfffffffffffUL;
+ else
+ addr = 0xfffffffffffUL;
+ addr_valid = 1;
+ }
+
+ return addr;
+}
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS (grub_efi_max_usable_address())

#endif /* ! GRUB_MEMORY_CPU_HEADER */
--
2.46.0

3 changes: 3 additions & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -102,3 +102,6 @@ deepin-Also-install-x86_64-efi-to-grub-efi.patch
#
# https://lists.gnu.org/archive/html/grub-devel/2024-06/msg00101.html
deepin/0001-util-grub-mkrescue-use-capitalised-paths-for-removab.patch
# loong64 old-world firmware compatibility
0001-loongarch64-able-to-start-on-legacy-firmware.patch
0001-grub-install-loongarch64-efi-also-install-BOOTLOONGA.patch