Re: [PATCH 0/2] Implement a grub loader for RISC-V LINUX
Sent from my iPhone > On Jan 16, 2020, at 10:06 PM, Alexander Graf wrote: > > Hi Chester, > >> On 16.01.20 11:21, Chester Lin wrote: >> Implement an initial version of riscv loader and related commands to load >> and run linux kernel and initrd on RISC-V. I tested this series based on >> the following configuration: >> >> - QEMU 4.2.50 (machine: virt) >> - OpenSBI v0.5-51 >> - U-Boot 2020.01-rc5 >> - grub 2.04 >> - linux-kernel v5.4 >> - openSUSE-Tumbleweed-20191103 > > > Thanks a lot for tackling this problem - it's been on the back burner for way > too long :). Unfortunately this patch set loads grub via UEFI, but then does > not execute Linux using the UEFI protocol. While that's a nice hack for > starters, it severely limits the extensibility of the boot flow going forward. > > IIRC either Anup or Atish wanted to work on a UEFI boot stub for Linux. We > could then just unify the ARM and RISC-V UEFI boot paths in grub and use that > common code to run Linux via the UEFI stub. > > Yes. I am working on it. In fact, I got Linux kernel booting via bootefi command last week. I have tried to use as much as ARM stub code possible which will help in unifying them in future. I am yet to add UEFI run time services. But I was thinking to post a RFC series with EFI stub code first and work on run time services after that. Let me know if you think that’s not a good idea. > Thanks, > > Alex > > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 0/2] Implement a grub loader for RISC-V LINUX
On Fri, 2020-01-17 at 03:20 +, Chester Lin wrote: > Hi Alex, Atish and Anup, > > On Thu, Jan 16, 2020 at 02:27:55PM +0100, Alexander Graf wrote: > > On 16.01.20 14:14, Atish Patra wrote: > > > Sent from my iPhone > > > > > > > On Jan 16, 2020, at 10:06 PM, Alexander Graf > > > > wrote: > > > > > > > > Hi Chester, > > > > > > > > > On 16.01.20 11:21, Chester Lin wrote: > > > > > Implement an initial version of riscv loader and related > > > > > commands to load > > > > > and run linux kernel and initrd on RISC-V. I tested this > > > > > series based on > > > > > the following configuration: > > > > > > > > > >- QEMU 4.2.50 (machine: virt) > > > > >- OpenSBI v0.5-51 > > > > >- U-Boot 2020.01-rc5 > > > > >- grub 2.04 > > > > >- linux-kernel v5.4 > > > > >- openSUSE-Tumbleweed-20191103 > > > > > > > > Thanks a lot for tackling this problem - it's been on the back > > > > burner for way too long :). Unfortunately this patch set loads > > > > grub via UEFI, but then does not execute Linux using the UEFI > > > > protocol. While that's a nice hack for starters, it severely > > > > limits the extensibility of the boot flow going forward. > > > > > > > > IIRC either Anup or Atish wanted to work on a UEFI boot stub > > > > for Linux. We could then just unify the ARM and RISC-V UEFI > > > > boot paths in grub and use that common code to run Linux via > > > > the UEFI stub. > > > > > > > > > > > Yes. I am working on it. In fact, I got Linux kernel booting via > > > bootefi command last week. I have tried to use as much as ARM > > > stub code possible which will help in unifying them in future. > > > > > > I am yet to add UEFI run time services. But I was thinking to > > > post a RFC series with EFI stub code first and work on run time > > > services after that. Let me know if you think that’s not a good > > > idea. > > > > I think that's a great idea. It will also unblock any work to move > > this > > patch to boot using the UEFI protocol. > > > > > > Alex > > > > It's a huge progress! thank you for letting me know about this great > news. BTW, > it seems that u-boot uses a specific approach to unblock non-boot > harts which are > looped by the wfi command. I wonder if we have any plan to move this > operation > to the OS side? For example, let non-boot harts keep waiting until > linux kernel > unblocks them. It seems that HSM (Hart State Managment Extension) is > still under > development, would we rely on this extension to implement CPU > online/offline > functions for RISC-V? > Yes. I am currently working on HSM extension in Linux. OpenSBI implementation is done. > I raise this question because I think it could be complicated for > grub to manage > non-boot harts which are blocked in u-boot stage if no general data > structure or > boottime service provided by the previous bootloader [e.g, u-boot or > UEFI FW]. > Otherwise the efi-call start_image should specifically handle it but > that also > means UEFI or other kinds of bootloader must follow it as well. > With HSM, single core will boot all the way to Linux and bring up all the other harts via hsm calls from OpenSBI. There will be only single hart available in U-Boot during booting. As a result, grub won't need to manage non-boot harts. My current plan is to send HSM patches first and send EFI stub patches once I test them on top of HSM series to boot all the harts. > Thanks for your patience, > Chester -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH RFC/RFT 0/3] Add grub loader support for RISC-V Linux
This series adds grub loader support for RISC-V Linux. Thanks to the awesome initial RISC-V support added by Alex, we just needed a loader for RISC-V to load and execute Linux using UEFI protocol. Fortunately, ARM64 Linux loader is written in an architecture agnostic manner so thatgeneric RISC-V can easily reuse the loader code. Thus, the first patch just moves the ARM64 code to common code. I have compile tested for ARM64/ARM32. Even though it doesn't introduce any functional change for ARM/ARM64, any real testing will be helpful. I have tested this series for RISC-V on both Qemu and HiFive Unleashed. Here are the dependencies of other opensource projects. 1. OpenSBI v0.7 2. U-boot master (Head: a5f9b8a8b592 Merge https://gitlab.denx.de/u-boot/custodians/u-boot-riscv) 3. Linux kernel (efi-next + top 4 RISC-V patches from riscv-efi-for-v5.8) Linux kernel tree can be found here as well. https://github.com/atishp04/linux/pull/new/uefi_riscv_pr Atish Patra (3): loader: Move arm64 linux loader to common code RISC-V: Update image header RISC-V: Use common linux loader grub-core/Makefile.core.def | 8 ++-- grub-core/loader/{arm64 => efi}/linux.c | 2 +- grub-core/loader/riscv/linux.c | 59 - include/grub/arm/linux.h| 2 +- include/grub/arm64/linux.h | 2 +- include/grub/riscv32/linux.h| 16 --- include/grub/riscv64/linux.h| 16 --- 7 files changed, 25 insertions(+), 80 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (99%) delete mode 100644 grub-core/loader/riscv/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH RFC/RFT 3/3] RISC-V: Use common linux loader
RISC-V doesn't have to do anything very different from other architectures to loader EFI stub linux kernel. As a result, just use the common linux loader instead of defining a RISC-V specific linux loader. Signed-off-by: Atish Patra --- grub-core/Makefile.core.def| 4 +-- grub-core/loader/riscv/linux.c | 59 -- include/grub/riscv32/linux.h | 1 + include/grub/riscv64/linux.h | 1 + 4 files changed, 4 insertions(+), 61 deletions(-) delete mode 100644 grub-core/loader/riscv/linux.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 57bb70d73764..8db90762af04 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1816,8 +1816,8 @@ module = { arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/efi/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; common = loader/linux.c; common = lib/cmdline.c; enable = noemu; diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488e118d.. --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), -int argc __attribute__ ((unused)), -char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, -N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h index de0dbdcd1be5..706c69087546 100644 --- a/include/grub/riscv32/linux.h +++ b/include/grub/riscv32/linux.h @@ -38,5 +38,6 @@ struct linux_riscv_kernel_header }; #define linux_arch_kernel_header linux_riscv_kernel_header +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE #endif /* ! GRUB_RISCV32_LINUX_HEADER */ diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h index 7c28bc92278e..88d5df781899 100644 --- a/include/grub/riscv64/linux.h +++ b/include/grub/riscv64/linux.h @@ -40,5 +40,6 @@ struct linux_riscv_kernel_header }; #define linux_arch_kernel_header linux_riscv_kernel_header +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE #endif /* ! GRUB_RISCV64_LINUX_HEADER */ -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH RFC/RFT 2/3] RISC-V: Update image header
Update the RISC-V Linux kernel image headers as per the current header. Reference: /Documentation/riscv/boot-image-header.rst Signed-off-by: Atish Patra --- include/grub/riscv32/linux.h | 15 --- include/grub/riscv64/linux.h | 15 --- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h index 512b777c8a41..de0dbdcd1be5 100644 --- a/include/grub/riscv32/linux.h +++ b/include/grub/riscv32/linux.h @@ -19,20 +19,21 @@ #ifndef GRUB_RISCV32_LINUX_HEADER #define GRUB_RISCV32_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ }; diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h index 3630c30fbf1a..7c28bc92278e 100644 --- a/include/grub/riscv64/linux.h +++ b/include/grub/riscv64/linux.h @@ -19,22 +19,23 @@ #ifndef GRUB_RISCV64_LINUX_HEADER #define GRUB_RISCV64_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ #define GRUB_EFI_PE_MAGIC 0x5A4D -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ }; -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH RFC/RFT 1/3] loader: Move arm64 linux loader to common code
ARM64 linux loader code is written in such a way that it can be reused across different architectures without much change. Move it to common code so that RISC-V doesn't have to define a separate loader. Signed-off-by: Atish Patra --- grub-core/Makefile.core.def | 4 ++-- grub-core/loader/{arm64 => efi}/linux.c | 2 +- include/grub/arm/linux.h| 2 +- include/grub/arm64/linux.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (99%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 48b82e76322f..57bb70d73764 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1813,9 +1813,9 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; + arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; common = loader/linux.c; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/efi/linux.c similarity index 99% rename from grub-core/loader/arm64/linux.c rename to grub-core/loader/efi/linux.c index ef3e9f9444ca..8c7a4963f023 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/efi/linux.c @@ -51,7 +51,7 @@ static grub_addr_t initrd_end; grub_err_t grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) { - if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE) + if (lh->magic != GRUB_LINUX_ARCH_MAGIC_SIGNATURE) return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); if ((lh->code0 & 0x) != GRUB_PE32_MAGIC) diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h index 2e98a6689696..c924d15446af 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -35,7 +35,7 @@ struct linux_arm_kernel_header { }; #if defined(__arm__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE # define linux_arch_kernel_header linux_arm_kernel_header #endif diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h index 4269adc6dae5..96aa3bae01ee 100644 --- a/include/grub/arm64/linux.h +++ b/include/grub/arm64/linux.h @@ -37,7 +37,7 @@ struct linux_arm64_kernel_header }; #if defined(__aarch64__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE # define linux_arch_kernel_header linux_arm64_kernel_header #endif -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH RFC/RFT 0/3] Add grub loader support for RISC-V Linux
On Mon, Apr 27, 2020 at 3:11 PM Ard Biesheuvel wrote: > > On Mon, 27 Apr 2020 at 23:16, Heinrich Schuchardt wrote: > > > > Am April 27, 2020 8:58:57 PM UTC schrieb Heinrich Schuchardt > > : > > >Am April 27, 2020 8:52:43 PM UTC schrieb Ard Biesheuvel > > >: > > >>On Mon, 27 Apr 2020 at 22:47, Ard Biesheuvel wrote: > > >>> > > >>> On Mon, 27 Apr 2020 at 22:47, Heinrich Schuchardt > > >> wrote: > > >>> > > > >>> > Am April 27, 2020 7:39:38 PM UTC schrieb Ard Biesheuvel > > >>: > > >>> > >On Mon, 27 Apr 2020 at 21:36, Heinrich Schuchardt > > >> > > >>> > >wrote: > > >>> > >> > > >>> > >> On 4/27/20 1:01 PM, Daniel Kiper wrote: > > >>> > >> > On Mon, Apr 27, 2020 at 08:15:41AM +0200, Ard Biesheuvel > > >>wrote: > > >>> > >> >> On Sun, 26 Apr 2020 at 21:40, Atish Patra > > >> > > >>> > >wrote: > > >>> > >> >>> > > >>> > >> >>> This series adds grub loader support for RISC-V Linux. > > >>Thanks to > > >>> > >the awesome > > >>> > >> >>> initial RISC-V support added by Alex, we just needed a > > >>loader for > > >>> > >RISC-V to > > >>> > >> >>> load and execute Linux using UEFI protocol. > > >>> > >> >>> > > >>> > >> >>> Fortunately, ARM64 Linux loader is written in an > > >>architecture > > >>> > >agnostic manner > > >>> > >> >>> so thatgeneric RISC-V can easily reuse the loader code. > > >>Thus, the > > >>> > >first patch > > >>> > >> >>> just moves the ARM64 code to common code. I have compile > > >>tested > > >>> > >for > > >>> > >> >>> ARM64/ARM32. Even though it doesn't introduce any > > >functional > > >>> > >change > > >>> > >> >>> for ARM/ARM64, any real testing will be helpful. > > >>> > >> >> > > >>> > >> >> May I suggest that we not blindly adopt the ARM code here, > > >>but > > >>> > >> >> instead, use the new initrd loading protocol that removes > > >the > > >>need > > >>> > >for > > >>> > >> >> GRUB to modify or even know about the device tree at all? > > >>> > >> > > >>> > >> Does this protocol exist in EDK2 by now? > > >>> > >> > > >>> > > > > >>> > >Yes. It exists as a shell command, and as a load option for OVMF. > > >>> > > > > >>> > >> In U-Boot there is a basic implementation which can provide a > > >>single > > >>> > >> initrd image with a hardcoded file name. The file_path argument > > >>> > >passed > > >>> > >> to U-Boot is ignored due to Ilias' security concerns when he > > >>wrote > > >>> > >the > > >>> > >> patch. > > >>> > >> > > >>> > >> GRUB is only needed if we have multiple kernels to choose from > > >>with > > >>> > >> distinct initial ramdisks. > > >>> > >> > > >>> > >> Please, describe what you expect the initrd loading protocol to > > >>do > > >>> > >when > > >>> > >> called from GRUB. How will the ramdisk fitting the kernel > > >chosen > > >>in > > >>> > >GRUB > > >>> > >> be identified? > > >>> > >> > > >>> > > > > >>> > >The same what GRUB's 'initrd' command does. Whichever initrd you > > >>> > >select with it is the one that gets returned by the protocol. > > >>> > > > >>> > Will GRUB provide the absolute device path in parameter file_path? > > >>> > > > >>> > > >>> Which parameter 'file_path" is that? > > >> > > >>Ah, I guess you mean the LoadFile2 argument? That is always > > >>end-of-device-path in this case, since the initrd device path only > > >>consists of the vendor media GUID. > > >> > > >>The thing to keep in mind here is that the OS does not *choose* an > > >>initrd, it simply loads the one that the bootloader has staged for it. > > > > > >How should U-Boot know which initrd fits the kernel chosen by the user > > >in GRUB? That information exists in grub.cfg only. > > > > > >If GRUB cannot provide this information, what is GRUB's added value in > > >the boot process? > > > > Hello Ard, > > > > Did I misunderstand you and you want to provide a LOAD_FILE2 implementation > > in GRUB and not use the one in the firmware? > > > > Yes. If you use GRUB, it is provided by GRUB. Otherwise, it can be > provided by U-Boot or EDK2. > Thanks for the discussion. I got clarification as well. I will work on adding LOAD_FILE2 support in GRUB. > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH RFC/RFT 0/3] Add grub loader support for RISC-V Linux
On Wed, Apr 29, 2020 at 4:22 AM Leif Lindholm wrote: > > Hi Atish, > > On Tue, Apr 28, 2020 at 11:21:05 -0700, Atish Patra wrote: > > > > Hello Ard, > > > > > > > > Did I misunderstand you and you want to provide a LOAD_FILE2 > > > > implementation in GRUB and not use the one in the firmware? > > > > > > Yes. If you use GRUB, it is provided by GRUB. Otherwise, it can be > > > provided by U-Boot or EDK2. > > > > Thanks for the discussion. I got clarification as well. > > I will work on adding LOAD_FILE2 support in GRUB. > > I had promised to look into that, but my paperwork with the FSF is > still pending. Feel free to contact me for bouncing ideas or whatever. > Sure. > As for this set - the changes to the kernel header structs and naming > should be non-controversial, and will be required for a final unified > loader anyway. Could you possibly break those out as a separate set, > which could then be merged earlier? > Ok. I will send out riscv header changes separately. > Best Regards, > > Leif -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH] RISC-V: Update linux image header
Update the RISC-V Linux kernel image headers as per the current header defined in Linux kernel. Reference: /Documentation/riscv/boot-image-header.rst Signed-off-by: Atish Patra --- include/grub/riscv32/linux.h | 15 --- include/grub/riscv64/linux.h | 15 --- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h index 12f66dbee0ee..706c69087546 100644 --- a/include/grub/riscv32/linux.h +++ b/include/grub/riscv32/linux.h @@ -19,20 +19,21 @@ #ifndef GRUB_RISCV32_LINUX_HEADER #define GRUB_RISCV32_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ }; diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h index 682cd1812aa7..88d5df781899 100644 --- a/include/grub/riscv64/linux.h +++ b/include/grub/riscv64/linux.h @@ -19,22 +19,23 @@ #ifndef GRUB_RISCV64_LINUX_HEADER #define GRUB_RISCV64_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ #define GRUB_EFI_PE_MAGIC 0x5A4D -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ }; -- 2.26.2 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: efi_loader/RISC-V: misaligned load when running grubriscv64.efi
On Thu, Jul 30, 2020 at 4:04 AM Heinrich Schuchardt wrote: > > On 30.07.20 12:16, Sean Anderson wrote: > > On 7/30/20 6:03 AM, Heinrich Schuchardt wrote: > >> Dear Sean, > >> > >> when trying to run grubriscv64.efi from the > >> trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020 Docker image on > >> a MAIXDUINO the relocations are not naturally aligned: > >> > >> lib/efi_loader/efi_image_loader.c(133) efi_loader_relocate(): > >> > >> efi_reloc 8030a000, offset 0x101e, type 10 > >> > >> Here we are trying to change an u64 at 0x8030B01E: > >> > >> uint64_t *x64 = efi_reloc + offset; > >> *x64 += (uint64_t)delta; > >> > >> This leads to an exception in function efi_loader_relocate(): > >> > >> Unhandled exception: Load address misaligned > >> EPC: 805a95ac RA: 805a953a TVAL: 8030b01e > >> EPC: 8001c5ac RA: 8001c53a reloc > >> > >> The GRUB image is available here: > >> > >> https://gist.github.com/xypron/522a91962248e9c3888d8554cb61ad2c/raw/b959661626b38a738673a9efb2f398b2fabd5c77/grubriscv64.efi > >> > >> On QEMU the GRUB image is executed without problems: > >> > >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/132919 > >> > >> The UEFI specification requires for the ARM platform that unaligned > >> support is enabled. This is why we have implemented function > >> allow_unaligned(). > >> > >> On RISC-V we have not yet implemented allow_unaligned() yet. Is there a > >> way to switch RISCV64 CPUs especially the Kendryte K210 into a mode > >> supporting unaligned access? > > > > AFAIK RISC-V has no requirement that un-aligned loads/stores complete. I > > believe the recommended solution is to install a trap handler which > > completes the un-aligned load through a series of aligned loads and then > > returns back to the application. For an example of such an > > implementation, check out arch/riscv/kernel/traps_misaligned.c in Linux. > > This may be too complex for U-Boot, so perhaps you can simply disallow > > unaligned accesses? > > > > --Sean > > > > Working around the problem inside U-Boot is easy (just some memcpy() > calls) but the GRUB image itself also makes unaligned accesses: > > Unhandled exception: Load address misaligned > EPC: 8030b004 RA: 805a4eca TVAL: 8030b02e > EPC: 7fd7e004 RA: 80017eca reloc > > UEFI image [0x8030a000:0x80433fff] pc=0x1004 > > This is what I found in "RISC-V Unprivileged ISA V20191213" > > "Loads and stores where the effective address is not naturally > aligned to the referenced datatype (i.e., on a four-byte boundary for > 32-bit accesses, and a two-byte boundary for 16-bit accesses) have > behavior dependent on the EEI. An EEI may guarantee that misaligned > loads and stores are fully supported, and so the software running inside > the execution environment will never experience a contained or fatal > address-misaligned trap." > > @Leif > Should GRUB be built with -mstrict-align for RISC-V? > That shouldn't be necessary. Any real board with an MMU that can boot Linux needs a SBI provider such as OpenSBI. OpenSBI already implements a misaligned handler. Are we planning to support EFI booting for NoMMU platforms ? As per my understanding runtime services need to be mapped through kernel page tables. > @Ard > How about the EFI part of the Linux kernel? > > Best regards > > Heinrich -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: efi_loader/RISC-V: misaligned load when running grubriscv64.efi
On Thu, Jul 30, 2020 at 1:19 PM Heinrich Schuchardt wrote: > > Am 30. Juli 2020 22:11:39 MESZ schrieb Heinrich Schuchardt > : > >Am 30. Juli 2020 20:31:47 MESZ schrieb Atish Patra > >: > >>On Thu, Jul 30, 2020 at 4:04 AM Heinrich Schuchardt > >> wrote: > >>> > >>> On 30.07.20 12:16, Sean Anderson wrote: > >>> > On 7/30/20 6:03 AM, Heinrich Schuchardt wrote: > >>> >> Dear Sean, > >>> >> > >>> >> when trying to run grubriscv64.efi from the > >>> >> trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020 Docker > >>image on > >>> >> a MAIXDUINO the relocations are not naturally aligned: > >>> >> > >>> >> lib/efi_loader/efi_image_loader.c(133) efi_loader_relocate(): > >>> >> > >>> >> efi_reloc 8030a000, offset 0x101e, type 10 > >>> >> > >>> >> Here we are trying to change an u64 at 0x8030B01E: > >>> >> > >>> >> uint64_t *x64 = efi_reloc + offset; > >>> >> *x64 += (uint64_t)delta; > >>> >> > >>> >> This leads to an exception in function efi_loader_relocate(): > >>> >> > >>> >> Unhandled exception: Load address misaligned > >>> >> EPC: 805a95ac RA: 805a953a TVAL: > >>8030b01e > >>> >> EPC: 8001c5ac RA: 8001c53a reloc > >>> >> > >>> >> The GRUB image is available here: > >>> >> > >>> >> > >>https://gist.github.com/xypron/522a91962248e9c3888d8554cb61ad2c/raw/b959661626b38a738673a9efb2f398b2fabd5c77/grubriscv64.efi > >>> >> > >>> >> On QEMU the GRUB image is executed without problems: > >>> >> > >>> >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/132919 > >>> >> > >>> >> The UEFI specification requires for the ARM platform that > >>unaligned > >>> >> support is enabled. This is why we have implemented function > >>> >> allow_unaligned(). > >>> >> > >>> >> On RISC-V we have not yet implemented allow_unaligned() yet. Is > >>there a > >>> >> way to switch RISCV64 CPUs especially the Kendryte K210 into a > >>mode > >>> >> supporting unaligned access? > >>> > > >>> > AFAIK RISC-V has no requirement that un-aligned loads/stores > >>complete. I > >>> > believe the recommended solution is to install a trap handler > >which > >>> > completes the un-aligned load through a series of aligned loads > >and > >>then > >>> > returns back to the application. For an example of such an > >>> > implementation, check out arch/riscv/kernel/traps_misaligned.c in > >>Linux. > >>> > This may be too complex for U-Boot, so perhaps you can simply > >>disallow > >>> > unaligned accesses? > >>> > > >>> > --Sean > >>> > > >>> > >>> Working around the problem inside U-Boot is easy (just some memcpy() > >>> calls) but the GRUB image itself also makes unaligned accesses: > >>> > >>> Unhandled exception: Load address misaligned > >>> EPC: 8030b004 RA: 805a4eca TVAL: 8030b02e > >>> EPC: 7fd7e004 RA: 80017eca reloc > >>> > >>> UEFI image [0x8030a000:0x80433fff] pc=0x1004 > >>> > >>> This is what I found in "RISC-V Unprivileged ISA V20191213" > >>> > >>> "Loads and stores where the effective address is not > >>naturally > >>> aligned to the referenced datatype (i.e., on a four-byte boundary > >for > >>> 32-bit accesses, and a two-byte boundary for 16-bit accesses) have > >>> behavior dependent on the EEI. An EEI may guarantee that misaligned > >>> loads and stores are fully supported, and so the software running > >>inside > >>> the execution environment will never experience a contained or fatal > >>> address-misaligned trap." > >>> > >>> @Leif > >>> Should GRUB be built with -mstrict-align for RISC-V? > >>> > >> > >>That shouldn't be necessary. Any real board with an MMU that can boot > >>Linux needs > >>a SBI provider such as OpenSBI. OpenSBI already implements a > >misaligned > >>handler. > >> > >>Are we planning to support EFI booting for NoMMU platforms ? As per my > >>understanding > >>runtime services need to be mapped through kernel page tables. > >> > > > >My interest is to have an affordable hardware platform where I can test > >U-Boot's UEFI sub-system on RISC-V. > > Yeah. For U-Boot UEFI subsystem verification kendryte is a good choice. But we shouldn't try to boot Linux via grub on that platform :) > >With 6 MiB usable RAM. (2 MiB reserved for AI) we probably won't get > >further than running GRUB. > > > >Can OpenSBI be built for the Kendryte K210 SoC? What is the size of > >OpenSBI? > Usually, OpenSBI firmware size is around ~100 KB. > Yes: > https://github.com/riscv/opensbi/tree/master/platform/kendryte/k210 > > So we should try if we can run U-Boot with OpenSBI on the platform. > > > > >Best regards > > > >Heinrich > > > >>> @Ard > >>> How about the EFI part of the Linux kernel? > >>> > >>> Best regards > >>> > >>> Heinrich > -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 7/8] efi: implement LoadFile2 initrd loading protocol for Linux
On Sun, Oct 25, 2020 at 6:50 AM Ard Biesheuvel wrote: > > Recent Linux kernels will invoke the LoadFile2 protocol installed on a > well-known vendor media devicepath to load the initrd if it is exposed > by the firmware. Using this method is preferred for two reasons: > - the Linux kernel is in charge of allocating the memory, and so it can > implement any placement policy it wants (given that these tend to > change between kernel versions), > - it is no longer necessary to modify the device tree provided by the > firmware. > > So let's install this protocol when handling the 'initrd' command if > such a recent kernel was detected (based on the PE/COFF image version), > and defer loading the initrd contents until the point where the kernel > invokes the LoadFile2 protocol. > Thanks for adding the support for LoadFile2 protocol. This was one of the blockers for full RISC-V support. How do you prefer to proceed with RISC-V support ? For RISC-V, we just need to move the arm64 loader to a common file so that both RISC-V/ARM64 can use it apart from few header file fixes. During the last attempt[1], I moved it to loader/efi/linux.c. I am happy to test it on Qemu/hardware, if you want to send the series either part of this one or a separate series. I can rebase my previous series on top of this series as well. Please let me know your preference. [1] https://www.mail-archive.com/grub-devel@gnu.org/msg30107.html > Signed-off-by: Ard Biesheuvel > --- > grub-core/loader/arm64/linux.c | 109 +++- > 1 file changed, 108 insertions(+), 1 deletion(-) > > diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c > index 28ff8584a3b5..c6a95e1f0c43 100644 > --- a/grub-core/loader/arm64/linux.c > +++ b/grub-core/loader/arm64/linux.c > @@ -48,6 +48,10 @@ static grub_uint32_t cmdline_size; > static grub_addr_t initrd_start; > static grub_addr_t initrd_end; > > +static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; > +static grub_efi_handle_t initrd_lf2_handle; > +static int initrd_use_loadfile2; > + > grub_err_t > grub_arch_efi_linux_load_image_header (grub_file_t file, >struct linux_arch_kernel_header * lh) > @@ -81,6 +85,18 @@ grub_arch_efi_linux_load_image_header (grub_file_t file, > return grub_error(GRUB_ERR_FILE_READ_ERROR, "failed to read COFF > image header"); > } > > + /* > + * Linux kernels built for any architecture are guaranteed to support the > + * LoadFile2 based initrd loading protocol if the image version is >= 1. > + */ > + if (lh->coff_image_header.optional_header.major_image_version >= 1) > +initrd_use_loadfile2 = 1; > + else > +initrd_use_loadfile2 = 0; > + > + grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n", > + initrd_use_loadfile2 ? "en" : "dis"); > + >return GRUB_ERR_NONE; > } > > @@ -250,13 +266,86 @@ allocate_initrd_mem (int initrd_pages) >GRUB_EFI_LOADER_DATA); > } > > +struct initrd_media_device_path { > + grub_efi_vendor_media_device_path_t vendor; > + grub_efi_device_path_t end; > +} GRUB_PACKED; > + > +#define LINUX_EFI_INITRD_MEDIA_GUID \ > + { 0x5568e427, 0x68fc, 0x4f3d, \ > +{ 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ > + } > + > +static struct initrd_media_device_path initrd_lf2_device_path = { > + { > +{ > + GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, > + GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE, > + sizeof(grub_efi_vendor_media_device_path_t), > +}, > +LINUX_EFI_INITRD_MEDIA_GUID > + }, { > +GRUB_EFI_END_DEVICE_PATH_TYPE, > +GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, > +sizeof(grub_efi_device_path_t) > + } > +}; > + > +static grub_efi_status_t initrd_load_file2(grub_efi_load_file2_t *this, > + grub_efi_device_path_t > *device_path, > + grub_efi_boolean_t boot_policy, > + grub_efi_uintn_t *buffer_size, > + void *buffer); > + > +static grub_efi_load_file2_t initrd_lf2 = { > + initrd_load_file2 > +}; > + > +static grub_efi_status_t initrd_load_file2(grub_efi_load_file2_t *this, > + grub_efi_device_path_t > *device_path, > + grub_efi_boolean_t boot_policy, > + grub_efi_uintn_t *buffer_size, > + void *buffer) > +{ > + grub_efi_status_t status = GRUB_EFI_SUCCESS; > + grub_efi_uintn_t initrd_size; > + > + if (!this || this != &initrd_lf2 || !buffer_size) > +return GRUB_EFI_INVALID_PARAMETER; > + > + if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE || > + device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE) > +return GRUB_EFI_NOT_FOUND; > + > + if (boot_policy) > +ret
Re: GRUB loader support for RISC-V Linux
Hi Nikita, Yes. It was discussed earlier that we should consolidate riscv & ARM64 implementation as the ARM64 has a very generic implementation. RISC-V should also use LOAD_FILE2 always. However, I couldn’t get time to revise the patches. I am on leave until May. Is it possible to revise your patch series based on above suggestions ? You can takeover my patches if you want or just start from the scratch. Sent from my iPhone > On Apr 4, 2021, at 2:09 AM, Nikita Ermakov wrote: > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 0/7] Add LoadFile2 and riscv Linux loader
On Mon, Jun 28, 2021 at 2:24 PM Heinrich Schuchardt wrote: > > > +cc Ard Biesheuvel > > Ard, please see question for you below. > > On 6/27/21 11:01 PM, Heinrich Schuchardt wrote: > > On 6/26/21 8:07 PM, Andreas Schwab wrote: > >> On Jun 03 2021, Nikita Ermakov wrote: > >> > >>> This series contains patches to add support for LoadFile2 protocol to > >>> load > >>> initrd on EFI systems. Also it contains patches to load Linux kernel > >>> with EFI > >>> stub on riscv platforms and unites arm and riscv codes together into > >>> common > >>> loader code for EFI systems. > >> > >> That doesn't work with a CD image. When I try to run > >> http://download.opensuse.org/ports/riscv/tumbleweed/iso/openSUSE-Tumbleweed-NET-riscv64-Media.iso > >> > >> with qemu, the initrd fails to load. > > > > Please, indicate how you built u-boot.bin. > > > >> > >> $ qemu-system-riscv64 -M virt -nographic -serial mon:stdio -smp 4 -m > >> 8g -kernel u-boot.bin -drive > >> format=raw,if=virtio,media=cdrom,file=openSUSE-Tumbleweed-NET-riscv64-Media.iso > >> > > > > This command results in an error > > > > qemu-system-riscv64: warning: > > No -bios option specified. Not loading a firmware. > > > > Please, provide a repo with the GRUB code you have been compiling. > > > >> > >> OpenSBI v0.9 > >> _ _ > >>/ __ \ / | _ \_ _| > >> | | | |_ __ ___ _ __ | (___ | |_) || | > >> | | | | '_ \ / _ \ '_ \ \___ \| _ < | | > >> | |__| | |_) | __/ | | |) | |_) || |_ > >>\/| .__/ \___|_| |_|_/|/_| > >> | | > >> |_| > >> > >> Platform Name : riscv-virtio,qemu > >> Platform Features : timer,mfdeleg > >> Platform HART Count : 4 > >> Firmware Base : 0x8000 > >> Firmware Size : 124 KB > >> Runtime SBI Version : 0.2 > >> > >> Domain0 Name : root > >> Domain0 Boot HART : 1 > >> Domain0 HARTs : 0*,1*,2*,3* > >> Domain0 Region00 : 0x8000-0x8001 () > >> Domain0 Region01 : 0x-0x (R,W,X) > >> Domain0 Next Address : 0x8020 > >> Domain0 Next Arg1 : 0xbf00 > >> Domain0 Next Mode : S-mode > >> Domain0 SysReset : yes > >> > >> Boot HART ID : 1 > >> Boot HART Domain : root > >> Boot HART ISA : rv64imafdcsu > >> Boot HART Features: scounteren,mcounteren,time > >> Boot HART PMP Count : 16 > >> Boot HART PMP Granularity : 4 > >> Boot HART PMP Address Bits: 54 > >> Boot HART MHPM Count : 0 > >> Boot HART MHPM Count : 0 > >> Boot HART MIDELEG : 0x0222 > >> Boot HART MEDELEG : 0xb109 > >> > >> > >> U-Boot 2021.04 (Jun 09 2021 - 00:00:00 +) > >> > >> CPU: rv64imafdcsu > >> Model: riscv-virtio,qemu > >> DRAM: 8 GiB > >> In:uart@1000 > >> Out: uart@1000 > >> Err: uart@1000 > >> Net: No ethernet found. > >> Hit any key to stop autoboot: 0 > >> > >> Device 0: 1af4 VirtIO Block Device > >> Type: Hard Disk > >> Capacity: 225.7 MB = 0.2 GB (462376 x 512) > >> ... is now current device > >> ** Invalid partition 3 ** > >> ** Invalid partition 4 ** > >> ** Invalid partition 2 ** > >> Scanning virtio 0:1... > >> ** Unable to read file / ** > >> Failed to load '/' > >> libfdt fdt_check_header(): FDT_ERR_BADMAGIC > >> Scanning disk virtio-blk#8... > >> Found 2 disks > >> No EFI system partition > >> BootOrder not defined > >> EFI boot manager: Cannot load any image > >> Found EFI removable media binary efi/boot/bootriscv64.efi > > > > When I press 'e' in GRUB I see: > > > > setparams 'Installation' > > set gfxpayload=keep > > echo 'Loading kernel ...' > > linux /boot/riscv64/linux splash=silent > >echo 'Loading > > initial ramdisk ...' initrd > > /boot/riscv64/initrd > > > > With debug=all I get as output: > > > > kern/verifiers.c:88: file: /boot/riscv64/initrd type: 131076 > > loader/efi/linux.c:368: LoadFile2 initrd loading protocol installed > > > > With a bit of debugging enabled in U-Boot: > > > >EFI: Call: image_obj->entry(image_handle, &systab) > > EFI: Entry efi_open_protocol(ff751310, > > EFI_LOADED_IMAGE_PROTOCOL_GUID, ff73a6e0, ff750050, > > , 0x1) > > EFI: Exit: efi_open_protocol: 0 > > EFI stub: Booting Linux Kernel... > > EFI: Entry efi_locate_handle_ext(2, > > EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, , ff73a740, > > ) > > EFI: Exit: efi_locate_handle_ext: 14 > > EFI: Entry efi_locate_protocol(EFI_TPM2_GUID, , > > ff73a648) > > EFI: Exit: efi_locate_protocol: 14 > > EFI stub: Using DTB from configuration table > > EFI: Entry
Re: [PATCH v2 0/7] Add LoadFile2 and riscv Linux loader
On Wed, Jun 30, 2021 at 12:26 AM Ard Biesheuvel wrote: > > On Tue, 29 Jun 2021 at 21:13, Atish Patra wrote: > > > > On Mon, Jun 28, 2021 at 2:24 PM Heinrich Schuchardt > > wrote: > > > > > > > > > +cc Ard Biesheuvel > > > > > > Ard, please see question for you below. > > > > > > On 6/27/21 11:01 PM, Heinrich Schuchardt wrote: > > > > On 6/26/21 8:07 PM, Andreas Schwab wrote: > > > >> On Jun 03 2021, Nikita Ermakov wrote: > > > >> > > > >>> This series contains patches to add support for LoadFile2 protocol to > > > >>> load > > > >>> initrd on EFI systems. Also it contains patches to load Linux kernel > > > >>> with EFI > > > >>> stub on riscv platforms and unites arm and riscv codes together into > > > >>> common > > > >>> loader code for EFI systems. > > > >> > > > >> That doesn't work with a CD image. When I try to run > > > >> http://download.opensuse.org/ports/riscv/tumbleweed/iso/openSUSE-Tumbleweed-NET-riscv64-Media.iso > > > >> > > > >> with qemu, the initrd fails to load. > > > > > > > > Please, indicate how you built u-boot.bin. > > > > > > > >> > > > >> $ qemu-system-riscv64 -M virt -nographic -serial mon:stdio -smp 4 -m > > > >> 8g -kernel u-boot.bin -drive > > > >> format=raw,if=virtio,media=cdrom,file=openSUSE-Tumbleweed-NET-riscv64-Media.iso > > > >> > > > > > > > > This command results in an error > > > > > > > > qemu-system-riscv64: warning: > > > > No -bios option specified. Not loading a firmware. > > > > > > > > Please, provide a repo with the GRUB code you have been compiling. > > > > > > > >> > > > >> OpenSBI v0.9 > > > >> _ _ > > > >>/ __ \ / | _ \_ _| > > > >> | | | |_ __ ___ _ __ | (___ | |_) || | > > > >> | | | | '_ \ / _ \ '_ \ \___ \| _ < | | > > > >> | |__| | |_) | __/ | | |) | |_) || |_ > > > >>\/| .__/ \___|_| |_|_/|/_| > > > >> | | > > > >> |_| > > > >> > > > >> Platform Name : riscv-virtio,qemu > > > >> Platform Features : timer,mfdeleg > > > >> Platform HART Count : 4 > > > >> Firmware Base : 0x8000 > > > >> Firmware Size : 124 KB > > > >> Runtime SBI Version : 0.2 > > > >> > > > >> Domain0 Name : root > > > >> Domain0 Boot HART : 1 > > > >> Domain0 HARTs : 0*,1*,2*,3* > > > >> Domain0 Region00 : 0x8000-0x8001 () > > > >> Domain0 Region01 : 0x-0x > > > >> (R,W,X) > > > >> Domain0 Next Address : 0x8020 > > > >> Domain0 Next Arg1 : 0xbf00 > > > >> Domain0 Next Mode : S-mode > > > >> Domain0 SysReset : yes > > > >> > > > >> Boot HART ID : 1 > > > >> Boot HART Domain : root > > > >> Boot HART ISA : rv64imafdcsu > > > >> Boot HART Features: scounteren,mcounteren,time > > > >> Boot HART PMP Count : 16 > > > >> Boot HART PMP Granularity : 4 > > > >> Boot HART PMP Address Bits: 54 > > > >> Boot HART MHPM Count : 0 > > > >> Boot HART MHPM Count : 0 > > > >> Boot HART MIDELEG : 0x0222 > > > >> Boot HART MEDELEG : 0xb109 > > > >> > > > >> > > > >> U-Boot 2021.04 (Jun 09 2021 - 00:00:00 +) > > > >> > > > >> CPU: rv64imafdcsu > > > >> Model: riscv-virtio,qemu > > > >> DRAM: 8 GiB > > > >> In:uart@1000 > > > >> Out: uart@1000 > > > >> Err: uart@1000 > > > >> Net: No ethernet found. > > > >> Hit any key to stop autoboot: 0 > > > >> > > > >> Device 0: 1af4 Vir
Re: [PATCH v2 0/7] Add LoadFile2 and riscv Linux loader
On Wed, Jun 2, 2021 at 2:13 PM Nikita Ermakov wrote: > > Hello, > > This is the second version of the patch series. The patch series is almost the > same as the previous one except that the Heinrich's suggestions were > implemented. > > This series contains patches to add support for LoadFile2 protocol to load > initrd on EFI systems. Also it contains patches to load Linux kernel with EFI > stub on riscv platforms and unites arm and riscv codes together into common > loader code for EFI systems. + Wei Fu who tested this series on Beagleboard. According to Wei we do another patch to add a boot-hartid entry in the chosen node if DTB is loaded from grub instead of U-Boot [1]. [1] https://github.com/tekkamanninja/grub/commit/99c5dc1ba897e506f185eb19d4dadc6d41937214 > > Ard Biesheuvel (3): > efi: add definition of LoadFile2 protocol > efi: implemented LoadFile2 initrd loading protocol for Linux > linux: ignore FDT unless we need to modify it > > Atish Patra (3): > loader: Move arm64 linux loader to common code > RISC-V: Update image header > RISC-V: Use common linux loader > > Nikita Ermakov (1): > loader: drop argv[] argument in grub_initrd_load() > > grub-core/Makefile.core.def | 8 +- > grub-core/commands/efi/lsefi.c| 1 + > grub-core/loader/arm/linux.c | 2 +- > grub-core/loader/efi/fdt.c| 7 +- > grub-core/loader/{arm64 => efi}/linux.c | 143 +++--- > grub-core/loader/i386/linux.c | 2 +- > grub-core/loader/i386/pc/linux.c | 2 +- > grub-core/loader/i386/xen.c | 3 +- > grub-core/loader/ia64/efi/linux.c | 2 +- > grub-core/loader/linux.c | 4 +- > grub-core/loader/mips/linux.c | 2 +- > grub-core/loader/powerpc/ieee1275/linux.c | 2 +- > grub-core/loader/riscv/linux.c| 59 - > grub-core/loader/sparc64/ieee1275/linux.c | 2 +- > include/grub/arm/linux.h | 2 +- > include/grub/arm64/linux.h| 2 +- > include/grub/efi/api.h| 15 +++ > include/grub/linux.h | 2 +- > include/grub/riscv32/linux.h | 16 +-- > include/grub/riscv64/linux.h | 16 +-- > 20 files changed, 185 insertions(+), 107 deletions(-) > rename grub-core/loader/{arm64 => efi}/linux.c (72%) > delete mode 100644 grub-core/loader/riscv/linux.c > > -- > 2.29.3 > > > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v5 PATCH 0/3] Unify ARM64 & RISC-V Linux Loader
This series unifies the linux loader for ARM64 & RISC-V. The linux loader for ARM64 is pretty much arch independent. Thus, this series just moves it to the common directory and update the make files. This series is rebased on top of Ard's LoadFile2 series[1]. The unification effort was a little mess and I was to blame :(. I started the effort but couldn't follow up after. Nikita picked it up and rebased all the patches along with LoadFile2. However, Nikita did not follow up after v3 as well. Ard revised his LoadFile2 series few weeks back. As the ocotober deadline for next grub release is closing, I decided to rebase the patches so that RISC-V support can be officially part of the release. Sorry for the mess/confusion. This series has been tested with OpenSuse image in Qemu. It would be good to get more testing on ARM64 and real RISC-V boards as well. Changes from v4->v5: 1. Removed redundant macros from header file and updated the rv32 kernel header structure. Changes from v3->V4: 1. Added all the comments on v3. 2. Dropped LoadFile2 patches as Ard's series[1] updated those patches [1] https://lists.gnu.org/archive/html/grub-devel/2022-09/msg00057.html Atish Patra (3): loader: Move arm64 linux loader to common code RISC-V: Update image header RISC-V: Use common linux loader grub-core/Makefile.core.def | 8 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 grub-core/loader/riscv/linux.c | 59 - include/grub/riscv32/linux.h| 19 include/grub/riscv64/linux.h| 19 5 files changed, 25 insertions(+), 80 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) delete mode 100644 grub-core/loader/riscv/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v5 PATCH 1/3] loader: Move arm64 linux loader to common code
ARM64 linux loader code is written in such a way that it can be reused across different architectures without much change. Move it to common code so that RISC-V doesn't have to define a separate loader. Reviewed-by: Daniel Kiper Signed-off-by: Atish Patra --- grub-core/Makefile.core.def | 4 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 5212dfab1369..ce95c76eaffa 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1817,9 +1817,9 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; + arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; common = loader/linux.c; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/efi/linux.c similarity index 100% rename from grub-core/loader/arm64/linux.c rename to grub-core/loader/efi/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v5 PATCH 3/3] RISC-V: Use common linux loader
RISC-V doesn't have to do anything very different from other architectures to loader EFI stub linux kernel. As a result, just use the common linux loader instead of defining a RISC-V specific linux loader. Signed-off-by: Atish Patra --- grub-core/Makefile.core.def| 4 +-- grub-core/loader/riscv/linux.c | 59 -- 2 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 grub-core/loader/riscv/linux.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ce95c76eaffa..d6cb8a673e1b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1820,8 +1820,8 @@ module = { arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/efi/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; common = loader/linux.c; common = lib/cmdline.c; enable = noemu; diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488e118d.. --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), -int argc __attribute__ ((unused)), -char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, -N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v5 PATCH 2/3] RISC-V: Update image header
Update the RISC-V Linux kernel image headers as per the current header. Reference: /Documentation/riscv/boot-image-header.rst 474efecb65dc: ("riscv: modify the Image header to improve compatibility with the ARM64 header") Acked-by: Heinrich Schuchardt Signed-off-by: Atish Patra --- include/grub/riscv32/linux.h | 19 ++- include/grub/riscv64/linux.h | 19 +++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h index 512b777c8a41..f50b1df1e84a 100644 --- a/include/grub/riscv32/linux.h +++ b/include/grub/riscv32/linux.h @@ -19,21 +19,22 @@ #ifndef GRUB_RISCV32_LINUX_HEADER #define GRUB_RISCV32_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ - -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint64_t magic; /* magic (RISC-V specifc, deprecated)*/ + grub_uint32_t magic2;/* Magic number 2 (to match the ARM64 'magic' field pos) */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ + + struct grub_coff_image_header coff_image_header; }; #define linux_arch_kernel_header linux_riscv_kernel_header diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h index 3630c30fbf1a..bdcc143c742e 100644 --- a/include/grub/riscv64/linux.h +++ b/include/grub/riscv64/linux.h @@ -19,23 +19,26 @@ #ifndef GRUB_RISCV64_LINUX_HEADER #define GRUB_RISCV64_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#include #define GRUB_EFI_PE_MAGIC 0x5A4D -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint64_t magic; /* magic (RISC-V specifc, deprecated)*/ + grub_uint32_t magic2;/* Magic number 2 (to match the ARM64 'magic' field pos) */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ + + struct grub_coff_image_header coff_image_header; }; #define linux_arch_kernel_header linux_riscv_kernel_header -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v6 PATCH 2/3] RISC-V: Update image header
Update the RISC-V Linux kernel image headers as per the current header. Reference: /Documentation/riscv/boot-image-header.rst 474efecb65dc: ("riscv: modify the Image header to improve compatibility with the ARM64 header") Acked-by: Heinrich Schuchardt Signed-off-by: Atish Patra --- include/grub/riscv32/linux.h | 19 ++- include/grub/riscv64/linux.h | 19 +++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h index 512b777c8a41..a884d4f4760c 100644 --- a/include/grub/riscv32/linux.h +++ b/include/grub/riscv32/linux.h @@ -19,21 +19,22 @@ #ifndef GRUB_RISCV32_LINUX_HEADER #define GRUB_RISCV32_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ - -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint64_t magic; /* magic (RISC-V specifc, deprecated)*/ + grub_uint32_t magic2;/* Magic number 2 (to match the ARM64 'magic' field pos) */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ + + struct grub_pe_image_header pe_image_header; }; #define linux_arch_kernel_header linux_riscv_kernel_header diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h index 3630c30fbf1a..a69046de34ef 100644 --- a/include/grub/riscv64/linux.h +++ b/include/grub/riscv64/linux.h @@ -19,23 +19,26 @@ #ifndef GRUB_RISCV64_LINUX_HEADER #define GRUB_RISCV64_LINUX_HEADER 1 -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ +#include #define GRUB_EFI_PE_MAGIC 0x5A4D -/* From linux/Documentation/riscv/booting.txt */ +/* From linux/Documentation/riscv/boot-image-header.rst */ struct linux_riscv_kernel_header { grub_uint32_t code0; /* Executable code */ grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset; /* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ + grub_uint64_t text_offset; /* Image load offset, little endian */ + grub_uint64_t image_size;/* Effective Image size, little endian */ + grub_uint64_t flags; /* kernel flags, little endian */ + grub_uint32_t version; /* Version of this header */ + grub_uint32_t res1; /* reserved */ grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ + grub_uint64_t magic; /* magic (RISC-V specifc, deprecated)*/ + grub_uint32_t magic2;/* Magic number 2 (to match the ARM64 'magic' field pos) */ grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ + + struct grub_pe_image_header pe_image_header; }; #define linux_arch_kernel_header linux_riscv_kernel_header -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v6 PATCH 3/3] RISC-V: Use common linux loader
RISC-V doesn't have to do anything very different from other architectures to loader EFI stub linux kernel. As a result, just use the common linux loader instead of defining a RISC-V specific linux loader. Signed-off-by: Atish Patra --- grub-core/Makefile.core.def| 4 +-- grub-core/loader/riscv/linux.c | 59 -- 2 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 grub-core/loader/riscv/linux.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index ce95c76eaffa..d6cb8a673e1b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1820,8 +1820,8 @@ module = { arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/efi/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; common = loader/linux.c; common = lib/cmdline.c; enable = noemu; diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488e118d.. --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), -int argc __attribute__ ((unused)), -char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, -N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v6 PATCH 1/3] loader: Move arm64 linux loader to common code
ARM64 linux loader code is written in such a way that it can be reused across different architectures without much change. Move it to common code so that RISC-V doesn't have to define a separate loader. Reviewed-by: Daniel Kiper Signed-off-by: Atish Patra --- grub-core/Makefile.core.def | 4 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 5212dfab1369..ce95c76eaffa 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1817,9 +1817,9 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; + arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; common = loader/linux.c; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/efi/linux.c similarity index 100% rename from grub-core/loader/arm64/linux.c rename to grub-core/loader/efi/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v6 PATCH 0/3] Unify ARM64 & RISC-V Linux Loader
This series unifies the linux loader for ARM64 & RISC-V. The linux loader for ARM64 is pretty much arch independent. Thus, this series just moves it to the common directory and update the make files. This series is rebased on top of Ard's LoadFile2 series[1]. The unification effort was a little mess and I was to blame :(. I started the effort but couldn't follow up after. Nikita picked it up and rebased all the patches along with LoadFile2. However, Nikita did not follow up after v3 as well. Ard revised his LoadFile2 series few weeks back. As the ocotober deadline for next grub release is closing, I decided to rebase the patches so that RISC-V support can be officially part of the release. Sorry for the mess/confusion. This series has been tested with OpenSuse image in Qemu. It would be good to get more testing on ARM64 and real RISC-V boards as well. Changes from v5->v6: 1. Rebased on top of Ard's latest LoadFile2 series. Changes from v4->v5: 1. Removed redundant macros from header file and updated the rv32 kernel header structure. Changes from v3->V4: 1. Added all the comments on v3. 2. Dropped LoadFile2 patches as Ard's series[1] updated those patches [1] https://lists.gnu.org/archive/html/grub-devel/2022-10/msg00093.html Atish Patra (3): loader: Move arm64 linux loader to common code RISC-V: Update image header RISC-V: Use common linux loader grub-core/Makefile.core.def | 8 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 grub-core/loader/riscv/linux.c | 59 - include/grub/riscv32/linux.h| 19 include/grub/riscv64/linux.h| 19 5 files changed, 25 insertions(+), 80 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) delete mode 100644 grub-core/loader/riscv/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [v6 PATCH 2/3] RISC-V: Update image header
On Wed, Nov 23, 2022 at 1:11 AM Xiaotian Wu wrote: > > Is there a new patch? > Not sure if you are asking about this series or Ard's series [1]. I got busy with other day jobs and did not get time to revise this series as that requires a bit of work to make sure that it doesn't break ARM64 (by removing the arch specific header files). I am planning to look into this during the holidays. If anybody else has some free cycles to revise the series, please let me know. Apologies for the delay. [1] https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00153.html > 在 2022-11-08星期二的 23:59 -0800,Atish Kumar Patra写道: > > > > > > On Tue, Nov 8, 2022 at 7:56 AM Daniel Kiper > > wrote: > > > On Fri, Nov 04, 2022 at 04:26:06PM -0700, Atish Patra wrote: > > > > Update the RISC-V Linux kernel image headers as per the current > > > > header. > > > > > > > > Reference: > > > > /Documentation/riscv/boot-image-header.rst > > > > > > > > 474efecb65dc: ("riscv: modify the Image header to improve > > > > compatibility with the ARM64 header") > > > > > > The latest commit which updates Documentation/riscv/boot-image- > > > header.rst is > > > 1d5c17e47028 (RISC-V: Typo fixes in image header and > > > documentation). > > > > > > > > > > > > Yes. I was pointing out the commit the image header was actually > > modified. > > I will modify the commit text to reflect the latest commit for the > > documentation as you suggested. > > > > > > Acked-by: Heinrich Schuchardt > > > > Signed-off-by: Atish Patra > > > > > > The order of these lines should be reversed... > > > > > > > > > > > > Sure. Will do. > > > > > > --- > > > > include/grub/riscv32/linux.h | 19 ++- > > > > include/grub/riscv64/linux.h | 19 +++ > > > > 2 files changed, 21 insertions(+), 17 deletions(-) > > > > > > > > diff --git a/include/grub/riscv32/linux.h > > > > b/include/grub/riscv32/linux.h > > > > index 512b777c8a41..a884d4f4760c 100644 > > > > --- a/include/grub/riscv32/linux.h > > > > +++ b/include/grub/riscv32/linux.h > > > > @@ -19,21 +19,22 @@ > > > > #ifndef GRUB_RISCV32_LINUX_HEADER > > > > #define GRUB_RISCV32_LINUX_HEADER 1 > > > > > > > > -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ > > > > - > > > > -/* From linux/Documentation/riscv/booting.txt */ > > > > +/* From linux/Documentation/riscv/boot-image-header.rst */ > > > > struct linux_riscv_kernel_header > > > > { > > > > grub_uint32_t code0; /* Executable code */ > > > > grub_uint32_t code1; /* Executable code */ > > > > - grub_uint64_t text_offset; /* Image load offset */ > > > > - grub_uint64_t res0;/* reserved */ > > > > - grub_uint64_t res1;/* reserved */ > > > > + grub_uint64_t text_offset; /* Image load offset, little endian > > > > */ > > > > + grub_uint64_t image_size; /* Effective Image size, little > > > > endian */ > > > > + grub_uint64_t flags; /* kernel flags, little > > > > endian */ > > > > + grub_uint32_t version; /* Version of this header */ > > > > + grub_uint32_t res1;/* reserved */ > > > > grub_uint64_t res2;/* reserved */ > > > > - grub_uint64_t res3;/* reserved */ > > > > - grub_uint64_t res4;/* reserved */ > > > > - grub_uint32_t magic; /* Magic number, little > > > > endian, "RSCV" */ > > > > + grub_uint64_t magic; /* magic (RISC-V specifc, > > > > deprecated)*/ > > > > + grub_uint32_t magic2; /* Magic number 2 (to match > > > > the ARM64 'magic' field pos) */ > > > > grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ > > > > > > I can agree that hdr_offset makes more sense but > > > Documentation/riscv/boot-image-header.rst names this member as > > > res3. > > > So, I would rename hdr_offset to res3 too. Or fix > > > Documentation/riscv/boot-image-header.rst in the kernel. Or, least > > > preferred, explain in the commit message why you d
Re: [PATCH v2 2/2] efi: Put Linux specific magic number in the DOS header
On Thu, Dec 1, 2022 at 6:30 AM Daniel Kiper wrote: > > On Tue, Nov 29, 2022 at 06:56:16PM +0100, Ard Biesheuvel wrote: > > GRUB currently relies on the magic number in the image header of ARM and > > arm64 EFI kernel images to decide whether or not the image in question > > is a bootable kernel. > > > > However, the purpose of the magic number is to identify the image as one > > that implements the bare metal boot protocol, and so GRUB, which only > > does EFI boot, can only boot images that could potentially be booted in > > a non-EFI manner as well. > > > > This is problematic for the new zboot decompressor image format, as it > > can only boot in EFI mode, and must therefore not use the bare metal > > boot magic number in its header. > > > > For this reason, the strict magic number was dropped from GRUB, to > > permit essentially any kind of EFI executable to be booted via the > > 'linux' command, blurring the line between the linux loader and the > > chainloader. > > > > So let's use the same field in the DOS header that RISC-V and arm64 > > already use for their 'bare metal' magic numbers to store a 'generic > > Linux kernel' magic number, which can be used to identify bootable > > kernel images in PE format which don't necessarily implement a bare > > metal boot protocol in the same binary. Note that, in the context of > > EFI, the MSDOS header is only described in terms of the fields that it > > s/MSDOS/MS-DOS/ to be consistent with other places in the patch... > > > shares with the hybrid PE/COFF image format, (i.e., the magic number at > > offset #0 and the PE header offset at byte offset #0x3c). Since we aim > > s/the magic number at offset #0/MS-DOS EXE magic number at offset #0/? > > "the magic number at offset #0" itself is confusing in the context of > number of "magic number" phrases in the patch... :-) > > > for compatibility with EFI only, and not with MS-DOS or MS-Windows, we > > can use the remaining space in the MS-DOS header however we want. > > > > Let's set the generic magic number for x86 images as well: existing > > bootloaders already have their own methods to identify x86 Linux images > > that can be booted in a non-EFI manner, and having the magic number in > > place there will ease any future transitions in loader implementations > > to merge the x86 and non-x86 EFI boot paths. > > > > Note that 32-bit ARM already uses the same location in the header for a > > different purpose, but the ARM support is already widely implemented and > > the EFI zboot decompressor is not available on ARM anyway, so we just > > disregard it here. > > > > Cc: Huacai Chen > > Cc: Atish Patra > > Cc: Heinrich Schuchardt > > Cc: Daniel Kiper > > Cc: Leif Lindholm > > Signed-off-by: Ard Biesheuvel > > --- > > arch/loongarch/kernel/head.S| 3 ++- > > arch/x86/boot/header.S | 3 ++- > > drivers/firmware/efi/libstub/zboot-header.S | 3 ++- > > include/linux/pe.h | 7 +++ > > 4 files changed, 13 insertions(+), 3 deletions(-) > > > > diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S > > index 84970e2666588963..caa74439700eee93 100644 > > --- a/arch/loongarch/kernel/head.S > > +++ b/arch/loongarch/kernel/head.S > > @@ -25,7 +25,8 @@ _head: > > .dword kernel_entry/* Kernel entry point */ > > .dword _end - _text/* Kernel image effective size */ > > .quad 0 /* Kernel image load offset from > > start of RAM */ > > - .org0x3c/* 0x20 ~ 0x3b reserved */ > > + .org0x38/* 0x20 ~ 0x38 reserved */ > > + .long LINUX_PE_MAGIC > > .long pe_header - _head /* Offset to the PE header */ > > > > pe_header: > > diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S > > index f912d777013052ea..be8f78a7ee325475 100644 > > --- a/arch/x86/boot/header.S > > +++ b/arch/x86/boot/header.S > > @@ -80,10 +80,11 @@ bs_die: > > ljmp$0xf000,$0xfff0 > > > > #ifdef CONFIG_EFI_STUB > > - .org0x3c > > + .org0x38 > > # > > # Offset to the PE header. > > # > > + .long LINUX_PE_MAGIC > > .long pe_header > > #endif /* CONFIG_EFI_STUB */ > > > > diff --git a/drivers/firmware/efi/libstub/zboot-header.S > > b/drivers/firmwa
[v7 PATCH 0/3] Unify ARM64 & RISC-V Linux Loader
This series unifies the linux loader for ARM64 & RISC-V. The linux loader for ARM64 is pretty much arch independent. Thus, this series just moves it to the common directory and update the make files. This series also removes the arch specific kernel image haders for ARM64 & RISC-V as suggested on v6[1]. I am not quite sure if there are any issues in removing ARM headers as well. It seems okay to me after a quick glance. If that's the case, it can be done in a separate path. This series has been tested with OpenSuse image in Qemu for RISC-V. For ARM64, it has been compile tested only. It would be good to get more testing on ARM64 and real RISC-V boards as well. [1] https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00042.html Sorry for the delay in sending the series. Hopefully, it has not delayed the grub release plan. Changes from v6->v7: 1. Rebased on top of the latest upstream. 2. Addressed all the comments on v6. 3. Removed arch specific image header files for ARM64 & RISC-V. Changes from v5->v6: 1. Rebased on top of Ard's latest LoadFile2 series. Changes from v4->v5: 1. Removed redundant macros from header file and updated the rv32 kernel header structure. Changes from v3->V4: 1. Added all the comments on v3. 2. Dropped LoadFile2 patches as Ard's series[1] updated those patches Atish Patra (3): loader: Move arm64 linux loader to common code efi: Remove arch specific image headers for RISC-V & ARM64 RISC-V: Use common linux loader grub-core/Makefile.core.def | 8 ++-- grub-core/commands/file.c | 8 ++-- grub-core/loader/arm64/xen_boot.c | 3 +- grub-core/loader/{arm64 => efi}/linux.c | 1 - grub-core/loader/riscv/linux.c | 59 - include/grub/arm64/linux.h | 48 include/grub/efi/efi.h | 11 - include/grub/riscv32/linux.h| 41 - include/grub/riscv64/linux.h| 43 -- 9 files changed, 19 insertions(+), 203 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (99%) delete mode 100644 grub-core/loader/riscv/linux.c delete mode 100644 include/grub/arm64/linux.h delete mode 100644 include/grub/riscv32/linux.h delete mode 100644 include/grub/riscv64/linux.h -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v7 PATCH 1/3] loader: Move arm64 linux loader to common code
ARM64 linux loader code is written in such a way that it can be reused across different architectures without much change. Move it to common code so that RISC-V doesn't have to define a separate loader. Signed-off-by: Atish Patra Reviewed-by: Daniel Kiper --- grub-core/Makefile.core.def | 4 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 71093a1..3ec0e7b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1826,9 +1826,9 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; + arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; emu = loader/emu/linux.c; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/efi/linux.c similarity index 100% rename from grub-core/loader/arm64/linux.c rename to grub-core/loader/efi/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v7 PATCH 3/3] RISC-V: Use common linux loader
RISC-V doesn't have to do anything very different from other architectures to loader EFI stub linux kernel. As a result, just use the common linux loader instead of defining a RISC-V specific linux loader. Signed-off-by: Atish Patra Reviewed-by: Daniel Kiper --- grub-core/Makefile.core.def| 4 +-- grub-core/loader/riscv/linux.c | 59 -- 2 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 grub-core/loader/riscv/linux.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 3ec0e7b..5446099 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1829,8 +1829,8 @@ module = { arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/efi/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; emu = loader/emu/linux.c; common = loader/linux.c; common = lib/cmdline.c; diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488..000 --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), -int argc __attribute__ ((unused)), -char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, -N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v7 PATCH 2/3] efi: Remove arch specific image headers for RISC-V & ARM64
The arch specific image header details are not very useful as most of the grub just looks at the PE/COFF spec parameters (PE32 magic and header offset). Remove the arch specific images headers and define a generic arch headers that provide enough PE/COFF fields for grub to parse kernel images correctly. Signed-off-by: Atish Patra --- grub-core/commands/file.c | 8 +++--- grub-core/loader/arm64/xen_boot.c | 3 +- grub-core/loader/efi/linux.c | 1 - include/grub/arm64/linux.h| 48 --- include/grub/efi/efi.h| 11 ++- include/grub/riscv32/linux.h | 41 -- include/grub/riscv64/linux.h | 43 --- 7 files changed, 15 insertions(+), 140 deletions(-) delete mode 100644 include/grub/arm64/linux.h delete mode 100644 include/grub/riscv32/linux.h delete mode 100644 include/grub/riscv64/linux.h diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 9de0006..9ba0e5e 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -25,10 +25,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -412,13 +412,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) } case IS_ARM64_LINUX: { - struct linux_arm64_kernel_header lh; + struct linux_arch_kernel_header lh; if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) break; - if (lh.magic == - grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM64_MAGIC_SIGNATURE)) + if (lh.pe_image_header.coff_header.machine == + grub_cpu_to_le32_compile_time (GRUB_PE32_MACHINE_ARM64)) { ret = 1; break; diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c index 763d87d..26e1472 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -439,7 +438,7 @@ static grub_err_t grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { - struct linux_arm64_kernel_header lh; + struct linux_arch_kernel_header lh; grub_file_t file = NULL; grub_dl_ref (my_mod); diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 48ab34a..15e0686 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h deleted file mode 100644 index 3da71a5..000 --- a/include/grub/arm64/linux.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2013 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef GRUB_ARM64_LINUX_HEADER -#define GRUB_ARM64_LINUX_HEADER 1 - -#include -#include - -#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ - -/* From linux/Documentation/arm64/booting.txt */ -struct linux_arm64_kernel_header -{ - grub_uint32_t code0; /* Executable code */ - grub_uint32_t code1; /* Executable code */ - grub_uint64_t text_offset;/* Image load offset */ - grub_uint64_t res0; /* reserved */ - grub_uint64_t res1; /* reserved */ - grub_uint64_t res2; /* reserved */ - grub_uint64_t res3; /* reserved */ - grub_uint64_t res4; /* reserved */ - grub_uint32_t magic; /* Magic number, little endian, "ARM\x64" */ - grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ - struct grub_pe_image_header pe_image_header; -}; - -#if defined(__aarch64__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE -# define linux_arch_kernel_header linux_arm64_kernel_header -#endif - -#endif /* ! GRUB_ARM64_LINUX_HEADER */ diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e61272d..b9e7f67 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -23,6 +23,16 @@ #include #include #include +#include + +struct linux_arch_kernel_header { + grub_uint32_t code0; + grub_uint32_
Re: [v7 PATCH 2/3] efi: Remove arch specific image headers for RISC-V & ARM64
On Thu, Feb 2, 2023 at 12:12 PM Daniel Kiper wrote: > > On Fri, Jan 20, 2023 at 05:17:13PM -0800, Atish Patra wrote: > > The arch specific image header details are not very useful as > > most of the grub just looks at the PE/COFF spec parameters (PE32 magic > > and header offset). > > > > Remove the arch specific images headers and define a generic > > arch headers that provide enough PE/COFF fields for grub to parse kernel > > images correctly. > > > > Signed-off-by: Atish Patra > > --- > > grub-core/commands/file.c | 8 +++--- > > grub-core/loader/arm64/xen_boot.c | 3 +- > > grub-core/loader/efi/linux.c | 1 - > > include/grub/arm64/linux.h| 48 --- > > include/grub/efi/efi.h| 11 ++- > > include/grub/riscv32/linux.h | 41 -- > > include/grub/riscv64/linux.h | 43 --- > > 7 files changed, 15 insertions(+), 140 deletions(-) > > delete mode 100644 include/grub/arm64/linux.h > > delete mode 100644 include/grub/riscv32/linux.h > > delete mode 100644 include/grub/riscv64/linux.h > > Sadly this patch broke normal ARM builds. I had to apply following fix... > Sorry for breaking the ARM build. Can you share your build steps ? I tried a few different build configurations (no modules, a bunch of random modules that I built for RISC-V). Everything seems to build fine when cross compiling for ARM. FWIW, here is my configuration command line ./configure --target=arm-linux-gnueabi --with-platform=efi > > diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c > index 9ba0e5eca..db9fdc5f2 100644 > --- a/grub-core/commands/file.c > +++ b/grub-core/commands/file.c > @@ -391,7 +391,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char > **args) >} > case IS_ARM_LINUX: >{ > - struct linux_arm_kernel_header lh; > + struct linux_arch_kernel_header lh; > > if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) > break; > diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c > index f00b538eb..19ddedbc2 100644 > --- a/grub-core/loader/arm/linux.c > +++ b/grub-core/loader/arm/linux.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -304,7 +305,7 @@ linux_boot (void) > static grub_err_t > linux_load (const char *filename, grub_file_t file) > { > - struct linux_arm_kernel_header *lh; > + struct linux_arch_kernel_header *lh; >int size; > >size = grub_file_size (file); > diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h > index f38e695b1..5b8fb14e0 100644 > --- a/include/grub/arm/linux.h > +++ b/include/grub/arm/linux.h > @@ -24,26 +24,6 @@ > > #include > > -#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 > - > -struct linux_arm_kernel_header { > - grub_uint32_t code0; > - grub_uint32_t reserved1[8]; > - grub_uint32_t magic; > - grub_uint32_t start; /* _start */ > - grub_uint32_t end; /* _edata */ > - grub_uint32_t reserved2[3]; > - grub_uint32_t hdr_offset; > -#if defined GRUB_MACHINE_EFI > - struct grub_pe_image_header pe_image_header; > -#endif > -}; > - > -#if defined(__arm__) > -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE > -# define linux_arch_kernel_header linux_arm_kernel_header > -#endif > - > #if defined GRUB_MACHINE_UBOOT > # include > # define LINUX_ADDRESS(start_of_ram + 0x8000) > diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h > index b9e7f6724..329c4f9b2 100644 > --- a/include/grub/efi/efi.h > +++ b/include/grub/efi/efi.h > @@ -25,13 +25,15 @@ > #include > #include > > +#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 > + > struct linux_arch_kernel_header { > - grub_uint32_t code0; > - grub_uint32_t code1; > - grub_uint64_t reserved[6]; > - grub_uint32_t reserved1; > - grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ > - struct grub_pe_image_header pe_image_header; > + grub_uint32_t code0; > + grub_uint32_t code1; > + grub_uint64_t reserved[6]; > + grub_uint32_t magic; > + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ > + struct grub_pe_image_header pe_image_header; > }; > > Thanks. I did not move the ARM version in this series as I was not sure if it was required as the original intention was to unify ARM64 & RISC-V only. I didn't want to break ARM builds for no good reason. It turns out I caused that anyway. The diff looks good to
Re: [v7 PATCH 2/3] efi: Remove arch specific image headers for RISC-V & ARM64
On Tue, Feb 14, 2023 at 4:41 AM Daniel Kiper wrote: > > On Thu, Feb 09, 2023 at 04:27:11PM -0800, Atish Patra wrote: > > On Thu, Feb 2, 2023 at 12:12 PM Daniel Kiper > > wrote: > > > > > > On Fri, Jan 20, 2023 at 05:17:13PM -0800, Atish Patra wrote: > > > > The arch specific image header details are not very useful as > > > > most of the grub just looks at the PE/COFF spec parameters (PE32 magic > > > > and header offset). > > > > > > > > Remove the arch specific images headers and define a generic > > > > arch headers that provide enough PE/COFF fields for grub to parse kernel > > > > images correctly. > > > > > > > > Signed-off-by: Atish Patra > > > > --- > > > > grub-core/commands/file.c | 8 +++--- > > > > grub-core/loader/arm64/xen_boot.c | 3 +- > > > > grub-core/loader/efi/linux.c | 1 - > > > > include/grub/arm64/linux.h| 48 --- > > > > include/grub/efi/efi.h| 11 ++- > > > > include/grub/riscv32/linux.h | 41 -- > > > > include/grub/riscv64/linux.h | 43 --- > > > > 7 files changed, 15 insertions(+), 140 deletions(-) > > > > delete mode 100644 include/grub/arm64/linux.h > > > > delete mode 100644 include/grub/riscv32/linux.h > > > > delete mode 100644 include/grub/riscv64/linux.h > > > > > > Sadly this patch broke normal ARM builds. I had to apply following fix... > > > > Sorry for breaking the ARM build. Can you share your build steps ? > > I tried a few different build configurations (no modules, a bunch of > > random modules that I built for RISC-V). Everything seems to build > > fine > > when cross compiling for ARM. > > > > FWIW, here is my configuration command line > > ./configure --target=arm-linux-gnueabi --with-platform=efi > > At least this build is broken: > ./configure --target=arm-linux-gnueabihf --with-platform=coreboot ... > Ahh. I did not test that option earlier. Thanks! > > > diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c > > > index 9ba0e5eca..db9fdc5f2 100644 > > > --- a/grub-core/commands/file.c > > > +++ b/grub-core/commands/file.c > > > @@ -391,7 +391,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, > > > char **args) > > >} > > > case IS_ARM_LINUX: > > >{ > > > - struct linux_arm_kernel_header lh; > > > + struct linux_arch_kernel_header lh; > > > > > > if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) > > > break; > > > diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c > > > index f00b538eb..19ddedbc2 100644 > > > --- a/grub-core/loader/arm/linux.c > > > +++ b/grub-core/loader/arm/linux.c > > > @@ -26,6 +26,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -304,7 +305,7 @@ linux_boot (void) > > > static grub_err_t > > > linux_load (const char *filename, grub_file_t file) > > > { > > > - struct linux_arm_kernel_header *lh; > > > + struct linux_arch_kernel_header *lh; > > >int size; > > > > > >size = grub_file_size (file); > > > diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h > > > index f38e695b1..5b8fb14e0 100644 > > > --- a/include/grub/arm/linux.h > > > +++ b/include/grub/arm/linux.h > > > @@ -24,26 +24,6 @@ > > > > > > #include > > > > > > -#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 > > > - > > > -struct linux_arm_kernel_header { > > > - grub_uint32_t code0; > > > - grub_uint32_t reserved1[8]; > > > - grub_uint32_t magic; > > > - grub_uint32_t start; /* _start */ > > > - grub_uint32_t end; /* _edata */ > > > - grub_uint32_t reserved2[3]; > > > - grub_uint32_t hdr_offset; > > > -#if defined GRUB_MACHINE_EFI > > > - struct grub_pe_image_header pe_image_header; > > > -#endif > > > -}; > > > - > > > -#if defined(__arm__) > > > -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE > > > -# define linux_arch_kernel_header linux_arm_kernel_header > > > -#endif &
strange grub error on ARM64
Hi, I am working on a cross-architecture cleanup series that removes the arch specific headers from RISC-V, ARM, ARM64 and unifies the linux loader on ARM64 & Linux. The v7 version can be found here. https://lists.gnu.org/archive/html/grub-devel/2023-02/msg00046.html It had a few bugs which are fixed and can be found here. Here are the patches https://github.com/atishp04/grub/commits/riscv_uefi_v8 Anybody with ARM64 and/or test setup: Can you please do a quick test to see if you see similar or any other failure ? I noticed a very strange error during ARM64 testing. I have probably done something stupid during the grub build as I can reproduce this with upstream grub as well. I was trying to boot an OpenSuse image in qemu virt machine for ARM64 as per the instructions[1]. The stock grub image works fine however my custom build fails to boot and drops to the grub command line. It seems the grub detects the disk but doesn't read the root partition correctly on my cross-compiled image. It has one additional directory ("@") which I don't see when I mount the disk. it doesn't list any files as well. = Cross compiled grub image = grub> ls -l (hd0,gpt3)/ DIR 20230302080325 @/ grub> ls -l (hd0,gpt3)/@/ DIR 20230302080326 boot/ DIR srv/ DIR 20230302080326 usr/ DIR opt/ DIR 20230302080326 home/ DIR var/ DIR tmp/ DIR root/ grub> ls -l (hd0,gpt3)/@/boot/ DIR 20230302080326 grub2/ grub> = Stock grub image from the OpenSuse image= grub> ls (hd0,gpt3)/ dev/ run/ boot/ config.partids lib sbin srv/ usr/ opt/ config.bootoptions lib64 .snapshots/ bin home/ etc/ var/ tmp/ sys/ mnt/ proc/ root/ The same build steps works fine for RISC-V for OpenSuse image though. However, I couldn't figure out what it was. Any help is appreciated. [1] https://en.opensuse.org/openSUSE:AArch64 -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: strange grub error on ARM64
On Mon, Mar 6, 2023 at 1:25 PM Fabian Vogt wrote: > > Hi, > > Am Montag, 6. März 2023, 21:59:23 CET schrieb Daniel Kiper: > > Adding Gary and Michael... > > > > Gary, Michael, could you help with this? Or at least forward this email > > to folks who may help... > > > > Daniel > > > > On Mon, Mar 06, 2023 at 10:56:52AM -0800, Atish Patra wrote: > > > Hi, > > > I am working on a cross-architecture cleanup series that removes the > > > arch specific headers from RISC-V, ARM, ARM64 and unifies the linux > > > loader on ARM64 & Linux. > > > > > > The v7 version can be found here. > > > https://lists.gnu.org/archive/html/grub-devel/2023-02/msg00046.html > > > > > > It had a few bugs which are fixed and can be found here. > > > > > > Here are the patches > > > https://github.com/atishp04/grub/commits/riscv_uefi_v8 > > > > > > Anybody with ARM64 and/or test setup: Can you please do a quick test > > > to see if you see similar or any other failure ? > > > > > > I noticed a very strange error during ARM64 testing. I have probably > > > done something stupid during the grub build > > > as I can reproduce this with upstream grub as well. > > > > > > I was trying to boot an OpenSuse image in qemu virt machine for ARM64 as > > > per > > > the instructions[1]. The stock grub image works fine however my custom > > > build fails to boot > > > and drops to the grub command line. It seems the grub detects the disk > > > but doesn't read the root partition correctly on my cross-compiled image. > > > It has one additional directory ("@") which I don't see when I mount > > > the disk. it doesn't list any files as well. > > What you see is the expected behaviour with upstream GRUB. > The btrfs volume contains various subvolumes below @ which are mounted into > the > root file system at various points. The root filesystem itself is at > @/.snapshots//snapshot/ and set as the default subvolume. That's what > is mounted in a running system if you pass default flags. To see the same as > GRUB, you can do mount -o subvolume=/ /dev/foo3 /mnt. > Thanks!! Thank god I am not crazy as I thought I was ;) > Downstream there's a patch (and multiple related ones) that makes GRUB mount > the default subvolume instead of the root of the filesystem: > https://build.opensuse.org/package/view_file/openSUSE:Factory/grub2/grub2-btrfs-03-follow_default.patch?expand=1&rev=285 > Is this the only patch or I need to pull all the patches on that tree to make it work ? Is there an easy way to test upstream grub stuff on ARM64 in case I need to pull more dependent patches to make it work? > The design of the "Boot into Snapshot" functionality relies on this. > > > > = Cross compiled grub image = > > > grub> ls -l (hd0,gpt3)/ > > > DIR 20230302080325 @/ > > > > > > grub> ls -l (hd0,gpt3)/@/ > > > DIR 20230302080326 boot/ > > > DIR srv/ > > > DIR 20230302080326 usr/ > > > DIR opt/ > > > DIR 20230302080326 home/ > > > DIR var/ > > > DIR tmp/ > > > DIR root/ > > > > > > grub> ls -l (hd0,gpt3)/@/boot/ > > > DIR 20230302080326 grub2/ > > > > > > grub> > > > = Stock grub image from the OpenSuse > > > image= > > > grub> ls (hd0,gpt3)/ > > > dev/ run/ boot/ config.partids lib sbin srv/ usr/ opt/ config.bootoptions > > > lib64 > > > .snapshots/ bin home/ etc/ var/ tmp/ sys/ mnt/ proc/ root/ > > > > > > The same build steps works fine for RISC-V for OpenSuse image though. > > > However, I couldn't figure out what it was. Any help is appreciated. > > It's possible that it does not use snapshot or not even btrfs. > > Cheers, > Fabian > > > > [1] https://en.opensuse.org/openSUSE:AArch64 > > > > > > -- > > > Regards, > > > Atish > > > > ___ > > Grub-devel mailing list > > Grub-devel@gnu.org > > https://lists.gnu.org/mailman/listinfo/grub-devel > > -- Regards, Atish ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: strange grub error on ARM64
On Mon, Mar 6, 2023 at 7:21 PM Michael Chang wrote: > > On Mon, Mar 06, 2023 at 04:22:53PM -0800, Atish Patra wrote: > > On Mon, Mar 6, 2023 at 1:25 PM Fabian Vogt wrote: > > > > > > Hi, > > > > > > Am Montag, 6. März 2023, 21:59:23 CET schrieb Daniel Kiper: > > > > Adding Gary and Michael... > > > > > > > > Gary, Michael, could you help with this? Or at least forward this email > > > > to folks who may help... > > > > > > > > Daniel > > > > > > > > On Mon, Mar 06, 2023 at 10:56:52AM -0800, Atish Patra wrote: > > > > > Hi, > > > > > I am working on a cross-architecture cleanup series that removes the > > > > > arch specific headers from RISC-V, ARM, ARM64 and unifies the linux > > > > > loader on ARM64 & Linux. > > > > > > > > > > The v7 version can be found here. > > > > > https://lists.gnu.org/archive/html/grub-devel/2023-02/msg00046.html > > > > > > > > > > It had a few bugs which are fixed and can be found here. > > > > > > > > > > Here are the patches > > > > > https://github.com/atishp04/grub/commits/riscv_uefi_v8 > > > > > > > > > > Anybody with ARM64 and/or test setup: Can you please do a quick test > > > > > to see if you see similar or any other failure ? > > > > > > > > > > I noticed a very strange error during ARM64 testing. I have probably > > > > > done something stupid during the grub build > > > > > as I can reproduce this with upstream grub as well. > > > > > > > > > > I was trying to boot an OpenSuse image in qemu virt machine for ARM64 > > > > > as per > > > > > the instructions[1]. The stock grub image works fine however my custom > > > > > build fails to boot > > > > > and drops to the grub command line. It seems the grub detects the disk > > > > > but doesn't read the root partition correctly on my cross-compiled > > > > > image. > > > > > It has one additional directory ("@") which I don't see when I mount > > > > > the disk. it doesn't list any files as well. > > > > > > What you see is the expected behaviour with upstream GRUB. > > > The btrfs volume contains various subvolumes below @ which are mounted > > > into the > > > root file system at various points. The root filesystem itself is at > > > @/.snapshots//snapshot/ and set as the default subvolume. That's > > > what > > > is mounted in a running system if you pass default flags. To see the same > > > as > > > GRUB, you can do mount -o subvolume=/ /dev/foo3 /mnt. > > > > > > > Thanks!! Thank god I am not crazy as I thought I was ;) > > > > > Downstream there's a patch (and multiple related ones) that makes GRUB > > > mount > > > the default subvolume instead of the root of the filesystem: > > > https://build.opensuse.org/package/view_file/openSUSE:Factory/grub2/grub2-btrfs-03-follow_default.patch?expand=1&rev=285 > > > > > > > Is this the only patch or I need to pull all the patches on that tree > > to make it work ? > > You'll need other patch so that files not in default subvolume can be > accessed through mount at grub's runtime, also to enable automatic setup > via the utility grub-(install|mkconfig). > > > > > Is there an easy way to test upstream grub stuff on ARM64 in case I > > need to pull more dependent patches to make it work? > > You can also use rpm from this Open Build Service (OBS) project: > > https://build.opensuse.org/package/show/home:michael-chang:grub:devel/grub2 > > It is for merging upstream git with SUSE patches rebased regularly per > month convenient to catch early build failure, find regression, try out > new feature and so on. > Thanks for pointing that out. But it seems all the patches are on top of some older release of grub. I am trying to test patches on top of the upstream and some of these patches may not apply cleanly. I was looking for alternatives with other distros. But every other distro probably carries a similar number of out-of-tree patches. Here is the fedora one. https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.patches I have a small favor to ask. Is it possible for you to test out the changes[1] on the ARM64 platform ? You probably have to rebase suse patches on top of upstr
[v8 PATCH 0/3] Unify ARM64 & RISC-V Linux Loader
This series unifies the linux loader for ARM64 & RISC-V. The linux loader for ARM64 is pretty much arch independent. Thus, this series just moves it to the common directory and update the make files. This series also removes the arch specific kernel image haders for ARM64, RISC-V, ARM as suggested on v6[1].I have verified with coreboot, efi platform options for ARM. I am not that well versed with ARM options. If it causes any more build failure, please scream at me again :). This series has been tested with OpenSuse image in Qemu for RISC-V. For ARM64,ARM it has been compile tested only. It would be good to get more testing on ARM64 and real RISC-V boards as well. [1] https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00042.html @Daniel: I have not added your RB tag in PATCH 2 as it is changed a bit after the last round of discussion around ARM headers. Changes from v7->v8: 1. Removed the arch specific header for ARM as well. 2. Fixed ARM64 load image header with random COFF header placement. 3. Added few grub distro folks for more visibility. Sorry for spam :). Changes from v6->v7: 1. Rebased on top of the latest upstream. 2. Addressed all the comments on v6. 3. Removed arch specific image header files for ARM64 & RISC-V. Changes from v5->v6: 1. Rebased on top of Ard's latest LoadFile2 series. Changes from v4->v5: 1. Removed redundant macros from header file and updated the rv32 kernel header structure. Changes from v3->V4: 1. Added all the comments on v3. 2. Dropped LoadFile2 patches as Ard's series[1] updated those patches Atish Patra (3): loader: Move arm64 linux loader to common code efi: Remove arch specific image headers for RISC-V, ARM64, ARM RISC-V: Use common linux loader grub-core/Makefile.core.def | 8 ++-- grub-core/commands/file.c | 23 +++--- grub-core/loader/arm/linux.c| 3 +- grub-core/loader/arm64/xen_boot.c | 3 +- grub-core/loader/{arm64 => efi}/linux.c | 1 - grub-core/loader/riscv/linux.c | 59 - include/grub/arm/linux.h| 20 - include/grub/arm64/linux.h | 48 include/grub/efi/efi.h | 13 +- include/grub/riscv32/linux.h| 41 - include/grub/riscv64/linux.h| 43 -- 11 files changed, 37 insertions(+), 225 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (99%) delete mode 100644 grub-core/loader/riscv/linux.c delete mode 100644 include/grub/arm64/linux.h delete mode 100644 include/grub/riscv32/linux.h delete mode 100644 include/grub/riscv64/linux.h -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v8 PATCH 2/3] efi: Remove arch specific image headers for RISC-V, ARM64, ARM
The arch specific image header details are not very useful as most of the grub just looks at the PE/COFF spec parameters (PE32 magic and header offset). Remove the arch specific images headers and define a generic arch headers that provide enough PE/COFF fields for grub to parse kernel images correctly. Signed-off-by: Atish Patra --- grub-core/commands/file.c | 23 +++ grub-core/loader/arm/linux.c | 3 +- grub-core/loader/arm64/xen_boot.c | 3 +- grub-core/loader/efi/linux.c | 1 - include/grub/arm/linux.h | 20 - include/grub/arm64/linux.h| 48 --- include/grub/efi/efi.h| 13 - include/grub/riscv32/linux.h | 41 -- include/grub/riscv64/linux.h | 43 --- 9 files changed, 33 insertions(+), 162 deletions(-) delete mode 100644 include/grub/arm64/linux.h delete mode 100644 include/grub/riscv32/linux.h delete mode 100644 include/grub/riscv64/linux.h diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 9de0006..62ddec4 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -25,10 +25,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -391,7 +391,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) } case IS_ARM_LINUX: { - struct linux_arm_kernel_header lh; + struct linux_arch_kernel_header lh; if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) break; @@ -412,13 +412,26 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) } case IS_ARM64_LINUX: { - struct linux_arm64_kernel_header lh; + struct linux_arch_kernel_header lh; if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) break; - if (lh.magic == - grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM64_MAGIC_SIGNATURE)) + /* + * The PE/COFF header can be anywhere in the file. Load it from the correct +* offset if it is not where it is expected. +*/ +if ((grub_uint8_t *) &lh + lh.hdr_offset != (grub_uint8_t *) &lh.pe_image_header) +{ + if (grub_file_seek (file, lh.hdr_offset) == (grub_off_t) -1 + || grub_file_read (file, &lh.pe_image_header, + sizeof (struct grub_pe_image_header)) + != sizeof (struct grub_pe_image_header)) +return grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read COFF image header"); +} + + if (lh.pe_image_header.coff_header.machine == + grub_cpu_to_le32_compile_time (GRUB_PE32_MACHINE_ARM64)) { ret = 1; break; diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c index f00b538..19ddedb 100644 --- a/grub-core/loader/arm/linux.c +++ b/grub-core/loader/arm/linux.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -304,7 +305,7 @@ linux_boot (void) static grub_err_t linux_load (const char *filename, grub_file_t file) { - struct linux_arm_kernel_header *lh; + struct linux_arch_kernel_header *lh; int size; size = grub_file_size (file); diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c index 763d87d..26e1472 100644 --- a/grub-core/loader/arm64/xen_boot.c +++ b/grub-core/loader/arm64/xen_boot.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -439,7 +438,7 @@ static grub_err_t grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { - struct linux_arm64_kernel_header lh; + struct linux_arch_kernel_header lh; grub_file_t file = NULL; grub_dl_ref (my_mod); diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 48ab34a..15e0686 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h index f38e695..5b8fb14 100644 --- a/include/grub/arm/linux.h +++ b/include/grub/arm/linux.h @@ -24,26 +24,6 @@ #include -#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 - -struct linux_arm_kernel_header { - grub_uint32_t code0; - grub_uint32_t reserved1[8]; - grub_uint32_t magic; - grub_uint32_t start; /* _start */ - grub_uint32_t end; /* _edata */ - grub_uint32_t reserved2[3]; - grub_uint32_t hdr_offset; -#if defined GRUB_MACHINE_EFI - struct grub_pe_image_header pe_image_header; -#endif -}; - -#if defined(__arm__) -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE -# define linux_arch_kernel_header linux_arm_kernel
[v8 PATCH 1/3] loader: Move arm64 linux loader to common code
ARM64 linux loader code is written in such a way that it can be reused across different architectures without much change. Move it to common code so that RISC-V doesn't have to define a separate loader. Signed-off-by: Atish Patra Reviewed-by: Daniel Kiper --- grub-core/Makefile.core.def | 4 ++-- grub-core/loader/{arm64 => efi}/linux.c | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename grub-core/loader/{arm64 => efi}/linux.c (100%) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 71093a1..3ec0e7b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1826,9 +1826,9 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/arm64/linux.c; + arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; riscv32 = loader/riscv/linux.c; riscv64 = loader/riscv/linux.c; emu = loader/emu/linux.c; diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/efi/linux.c similarity index 100% rename from grub-core/loader/arm64/linux.c rename to grub-core/loader/efi/linux.c -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[v8 PATCH 3/3] RISC-V: Use common linux loader
RISC-V doesn't have to do anything very different from other architectures to loader EFI stub linux kernel. As a result, just use the common linux loader instead of defining a RISC-V specific linux loader. Signed-off-by: Atish Patra Reviewed-by: Daniel Kiper --- grub-core/Makefile.core.def| 4 +-- grub-core/loader/riscv/linux.c | 59 -- 2 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 grub-core/loader/riscv/linux.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 3ec0e7b..5446099 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1829,8 +1829,8 @@ module = { arm_efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; arm64 = loader/efi/linux.c; - riscv32 = loader/riscv/linux.c; - riscv64 = loader/riscv/linux.c; + riscv32 = loader/efi/linux.c; + riscv64 = loader/efi/linux.c; emu = loader/emu/linux.c; common = loader/linux.c; common = lib/cmdline.c; diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c deleted file mode 100644 index d17c488..000 --- a/grub-core/loader/riscv/linux.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2018 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include -#include -#include - -GRUB_MOD_LICENSE ("GPLv3+"); - -static grub_err_t -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), -int argc __attribute__ ((unused)), -char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_err_t -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); - - return grub_errno; -} - -static grub_command_t cmd_linux, cmd_initrd; - -GRUB_MOD_INIT (linux) -{ - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, -N_("Load Linux.")); - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, - N_("Load initrd.")); -} - -GRUB_MOD_FINI (linux) -{ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); -} -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel