Skip to contentSkip to conversation

Linux loader for riscv64

PATCH In review Nikita Ermakov 2 participants 5 messages Mar 24, 2021 – Mar 26, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

cover Linux loader for riscv64

Hello.

In this patch series I would like to add a possibility to load Linux kernel with a EFI stub on riscv64 platform.

The first patch updates a RISC-V magic number as it was changed [1] in the kernel.

The second patch splits the grub-core/loader/riscv/linux.c to two parts -- riscv32 and riscv64. The first part, riscv32, is just a stub that informs about unsupported feature. This part is just a copy of the current grub-core/loader/riscv/linux.c. The second part is a loader for the kernel with the EFI stub. The loader is based on the arm64 linux loader with a few changes.

I tested these patches on a qemu-system-riscv64 with virt machine. A boot sequence was as follows:
OpenSBI (v0.9) -> U-Boot (v2021.04-rc4) -> grub -> Linux (v5.12-rc4)

[root@localhost ~]# uname -a
Linux localhost 5.12.0-rc4 #5 SMP Wed Mar 24 16:46:30 MSK 2021 riscv64 GNU/Linux

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=474efecb65dceb15f793b6e2f2b226e952f0f8e9

Nikita Ermakov (2):
RISC-V: Update magic number
RISC-V: Allow to boot Linux with EFI stub on riscv64

 grub-core/Makefile.core.def                 |   4 +-
 grub-core/loader/{riscv => riscv32}/linux.c |   0
 grub-core/loader/riscv64/linux.c            | 380 ++++++++++++++++++++
 include/grub/riscv32/linux.h                |   4 +-
 include/grub/riscv64/linux.h                |   4 +-
 5 files changed, 386 insertions(+), 6 deletions(-)
 rename grub-core/loader/{riscv => riscv32}/linux.c (100%)
 create mode 100644 grub-core/loader/riscv64/linux.c
Signature · 1 line
2.25.4
#1 lore raw

PATCH 1/2 RISC-V: Update magic number

The image header for riscv in the kernel was modified to improve compatibility with the ARM64 header.

---
 include/grub/riscv32/linux.h | 4 ++--
 include/grub/riscv64/linux.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
include/grub/riscv32/linux.h +2 -2
index 512b777c8..5718bf569 100644
@@ -19,7 +19,7 @@
 #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 /* little endian, 'RSC\x05' */
 
 /* From linux/Documentation/riscv/booting.txt */
 struct linux_riscv_kernel_header
@@ -32,7 +32,7 @@ struct linux_riscv_kernel_header
   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 */
 };
 
include/grub/riscv64/linux.h +2 -2
index 3630c30fb..a57fa0c81 100644
@@ -19,7 +19,7 @@
 #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 /* little endian, 'RSC\x05' */
 
 #define GRUB_EFI_PE_MAGIC	0x5A4D
 
@@ -34,7 +34,7 @@ struct linux_riscv_kernel_header
   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 */
 };
 
Signature · 1 line
2.25.4
#2 lore raw

PATCH 2/2 RISC-V: Allow to boot Linux with EFI stub on riscv64

In reply to Nikita Ermakov

- Split a riscv loader to the riscv32 and riscv64 loaders.

- Add loader to boot Linux with EFI stub on riscv64. It is based on the grub-core/loader/arm64/linux.c

---
 grub-core/Makefile.core.def                 |   4 +-
 grub-core/loader/{riscv => riscv32}/linux.c |   0
 grub-core/loader/riscv64/linux.c            | 380 ++++++++++++++++++++
 3 files changed, 382 insertions(+), 2 deletions(-)
 rename grub-core/loader/{riscv => riscv32}/linux.c (100%)
 create mode 100644 grub-core/loader/riscv64/linux.c
grub-core/Makefile.core.def +2 -2
index 8022e1c0a..655a45de7 100644
@@ -1809,8 +1809,8 @@ module = {
   arm_efi = loader/arm64/linux.c;
   arm_uboot = loader/arm/linux.c;
   arm64 = loader/arm64/linux.c;
-  riscv32 = loader/riscv/linux.c;
-  riscv64 = loader/riscv/linux.c;
+  riscv32 = loader/riscv32/linux.c;
+  riscv64 = loader/riscv64/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;
   enable = noemu;
grub-core/loader/riscv32/linux.c renamed from grub-core/loader/riscv/linux.c +0 -0
similarity index 100%
rename from grub-core/loader/riscv/linux.c
rename to grub-core/loader/riscv32/linux.c
grub-core/loader/riscv64/linux.c new file +380 -0

380 lines not on this page · raw message

Signature · 1 line
2.25.4
#3 lore raw
In reply to Nikita Ermakov

Hi Nikita,

Quoted 4 lines · Nikita Ermakov

Hello.

In this patch series I would like to add a possibility to load Linux kernel with a EFI stub on riscv64 platform.

Thank you for your patches. Sadly we are in code freeze stage before release. So, your patch set does not count as a release material at this point. I will take a look at it after release. Sorry for the inconvenience.

Daniel

#4 lore raw

Hi Daniel,

Quoted 4 lines · Daniel Kiper

Hi Nikita,

On Wed, Mar 24, 2021 at 05:50:26PM +0300, Nikita Ermakov wrote:

Quoted 9 lines
Quoted 4 lines

Hello.

In this patch series I would like to add a possibility to load Linux kernel with a EFI stub on riscv64 platform.

Thank you for your patches. Sadly we are in code freeze stage before release. So, your patch set does not count as a release material at this point. I will take a look at it after release. Sorry for the inconvenience.

No problem. Thanks for the answer!

Signature · 3 lines
Thanks,
Nikita
B8 00 4C CD 21