Skip to contentSkip to conversation

Unify ARM64 & RISC-V Linux Loader

PATCH Superseded Atish Patra 4 participants 13 messages Oct 7, 2022 – Nov 3, 2022 RISC-V

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover 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

#1 lore raw

PATCH v5 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.

---
 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%)
grub-core/Makefile.core.def +2 -2
index 5212dfab1369..ce95c76eaffa 100644
@@ -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;
grub-core/loader/efi/linux.c renamed from grub-core/loader/arm64/linux.c +0 -0
similarity index 100%
rename from grub-core/loader/arm64/linux.c
rename to grub-core/loader/efi/linux.c
Signature · 1 line
2.25.1
#2 lore raw

PATCH v5 2/3 RISC-V: Update image header

In reply to Atish Patra

Update the RISC-V Linux kernel image headers as per the current header.

Reference:
<Linux kernel source>/Documentation/riscv/boot-image-header.rst

474efecb65dc: ("riscv: modify the Image header to improve compatibility with the ARM64 header")

---
 include/grub/riscv32/linux.h | 19 ++++++++++---------
 include/grub/riscv64/linux.h | 19 +++++++++++--------
 2 files changed, 21 insertions(+), 17 deletions(-)
include/grub/riscv32/linux.h +10 -9
index 512b777c8a41..f50b1df1e84a 100644
@@ -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
include/grub/riscv64/linux.h +11 -8
index 3630c30fbf1a..bdcc143c742e 100644
@@ -19,23 +19,26 @@
 #ifndef GRUB_RISCV64_LINUX_HEADER
 #define GRUB_RISCV64_LINUX_HEADER 1
 
-#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */
+#include <grub/efi/pe32.h>
 
 #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
Signature · 1 line
2.25.1
#3 lore raw

PATCH v5 3/3 RISC-V: Use common linux loader

In reply to Atish Patra

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.

---
 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
grub-core/Makefile.core.def +2 -2
index ce95c76eaffa..d6cb8a673e1b 100644
@@ -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;
grub-core/loader/riscv/linux.c deleted +0 -59

59 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw
In reply to Atish Patra
Quoted 6 lines · Atish Patra

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].

Quoted 8 lines

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.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review and take Atish first. Then Ard would need to rebase. Any objections?

Daniel

#5 lore raw
Quoted 17 lines · Daniel Kiper
Quoted 6 lines · Atish Patra

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].

Quoted 8 lines

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.

Quoted 5 lines

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review and take Atish first. Then Ard would need to rebase. Any objections?

Why would you do that? You told me 2 months ago that you were going to review the patches in september. Now you are telling me you are first going to review and merge a series that Atish sent out on 7 october, forcing me to put in additional work to do the rebase?

#6 lore raw
Quoted 17 lines · Ard Biesheuvel
Quoted 16 lines · Daniel Kiper
Quoted 14 lines · Atish Patra

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.

Quoted 7 lines
Quoted 4 lines

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review and take Atish first. Then Ard would need to rebase. Any objections?

Why would you do that? You told me 2 months ago that you were going to review the patches in september. Now you are telling me you are first

Sorry for delay but...

Quoted 2 lines

going to review and merge a series that Atish sent out on 7 october, forcing me to put in additional work to do the rebase?

Atish said he rebased his own patch set on top of yours and is OK to do it once again if it is needed. Then I will review and merge Ard's patch set first. I hope it will happen in the following week or two.

Daniel

#7 lore raw
In reply to Daniel Kiper
Quoted 14 lines · Daniel Kiper
Quoted 6 lines · Atish Patra

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].

Quoted 7 lines

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

Quoted 9 lines

support

Quoted 1 line

can be officially part of the release. Sorry for the mess/confusion.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review and take Atish first. Then Ard would need to rebase. Any objections?

I have rebased this series on top of Ard's series already. So I think it would be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to rebase once again
if required.

Quoted 2 lines

Daniel

#8 lore raw
Quoted 29 lines · Atish Kumar Patra

On Mon, Oct 10, 2022 at 7:54 AM Daniel Kiper <[email protected]> wrote:
On Fri, Oct 07, 2022 at 01:50:27AM -0700, Atish Patra wrote:
> 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.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review
and take Atish first. Then Ard would need to rebase. Any objections?

Quoted 5 lines

I have rebased this series on top of Ard's series already. So I think it would be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to rebase once again
if required.

Cool! Thanks a lot!

Daniel

#9 lore raw
Quoted 36 lines · Daniel Kiper
Quoted 29 lines · Atish Kumar Patra

On Mon, Oct 10, 2022 at 7:54 AM Daniel Kiper <[email protected]> wrote:
On Fri, Oct 07, 2022 at 01:50:27AM -0700, Atish Patra wrote:
> 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.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review
and take Atish first. Then Ard would need to rebase. Any objections?

Quoted 5 lines

I have rebased this series on top of Ard's series already. So I think it would be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to rebase once again
if required.

Quoted 3 lines

Cool! Thanks a lot!

Daniel

Great, I hope the v4 and v5 patches are merged into the master branch soon.

Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw
In reply to Atish Kumar Patra
Quoted 29 lines · Atish Kumar Patra

On Mon, Oct 10, 2022 at 7:54 AM Daniel Kiper <[email protected]> wrote:
On Fri, Oct 07, 2022 at 01:50:27AM -0700, Atish Patra wrote:
> 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.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I would review
and take Atish first. Then Ard would need to rebase. Any objections?

Quoted 5 lines

I have rebased this series on top of Ard's series already. So I think it would be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to rebase once again
if required.

Aitsh, right now Ard's LoadFile2 series is in. Please rebase and repost your patch set.

Daniel

#11 lore raw

Is there any new message?

Quoted 53 lines · 在 2022-10-27星期四的 21:18 +0200,Daniel Kiper写道:
Quoted 39 lines · Atish Kumar Patra

On Mon, Oct 10, 2022 at 7:54 AM Daniel Kiper <[email protected]> wrote:
     On Fri, Oct 07, 2022 at 01:50:27AM -0700, Atish Patra wrote:
     > 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.

     No worries, I know how it works. Thank you for rebase.

     Ard, Atish, your patch series seem to conflict. I think I would
     review
     and take Atish first. Then Ard would need to rebase. Any objections?

Quoted 7 lines

I have rebased this series on top of Ard's series already. So I think it would
be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to
rebase once again
if required.

Aitsh, right now Ard's LoadFile2 series is in. Please rebase and repost
your patch set.

Daniel

#12 lore raw
Quoted 55 lines · Xiaotian Wu

Is there any new message?

Quoted 52 lines · 在 2022-10-27星期四的 21:18 +0200,Daniel Kiper写道:
Quoted 39 lines · Atish Kumar Patra

On Mon, Oct 10, 2022 at 7:54 AM Daniel Kiper <[email protected]> wrote:
On Fri, Oct 07, 2022 at 01:50:27AM -0700, Atish Patra wrote:
> 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.

No worries, I know how it works. Thank you for rebase.

Ard, Atish, your patch series seem to conflict. I think I
would
review
and take Atish first. Then Ard would need to rebase. Any
objections?

Quoted 7 lines

I have rebased this series on top of Ard's series already. So I think it would
be easier if Ard's series
is merged first. As this series has minimal changes, it won't take much time to
rebase once again
if required.

Aitsh, right now Ard's LoadFile2 series is in. Please rebase and repost
your patch set.

Arrgh. I completely missed this message. Sorry.
I will send the patches today.

Quoted 4 lines
Quoted 2 lines

Daniel