Unify ARM64 & RISC-V Linux Loader
v4 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 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 | 15 ++++---
include/grub/riscv64/linux.h | 21 +++++----
5 files changed, 25 insertions(+), 78 deletions(-)rename grub-core/loader/{arm64 => efi}/linux.c (100%) delete mode 100644 grub-core/loader/riscv/linux.c
--
2.25.1
PATCH v4 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
@@ -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
Signature · 1 line
2.25.1
PATCH v4 2/3 RISC-V: Update image header
In reply to Atish PatraUpdate 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 | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)
include/grub/riscv32/linux.h +8 -7
@@ -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 */ };
include/grub/riscv64/linux.h +13 -8
@@ -19,23 +19,28 @@#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_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_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
Re: [v4 PATCH 2/3] RISC-V: Update image header
Quoted 18 lines · 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")Signed-off-by Atish Patra <[email protected]>--- include/grub/riscv32/linux.h | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)include/grub/riscv32/linux.h +0
-0
include/grub/riscv32/linux.h line 22
Quoted 5 lines
include/grub/riscv32/linux.h +1
-1@@ -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' */
Thanks for following up on this series.
Considering 69edb312056 ("loader/arm64/linux: Remove magic number header field check") why should this constant exist in GRUB at all?
In a follow up patch we could remove it together with GRUB_LINUX_ARM_MAGIC_SIGNATURE, GRUB_LINUX_ARMXX_MAGIC_SIGNATURE, and GRUB_LINUX_ARMXX_MAGIC_SIGNATURE.
Quoted 7 lines
include/grub/riscv32/linux.h +1
-1-/* 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 */
include/grub/riscv32/linux.h line 35
Quoted 10 lines
include/grub/riscv32/linux.h +5
-3-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 */
According to tag next-20221006 of Documentation/riscv/boot-image-header.rst and of arch/riscv/include/asm/image.h this field is called 'magic' and filled it with the string 'RISCV\0\0\0'.
include/grub/riscv32/linux.h line 36
Quoted 3 lines
include/grub/riscv32/linux.h +1
-2-grub_uint64_t res4;/* reserved */ -grub_uint32_t magic;/* Magic number, little endian, "RSCV" */ +grub_uint32_t magic;/* Magic number, little endian, "RSC\x05" */
The Linux kernel documentation calls this field magic2.
Of course this is functionally irrelevant as we don't care about the content of both fields.
Quoted 8 lines
include/grub/riscv32/linux.h +0
-0grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ };include/grub/riscv64/linux.h +0
-0
include/grub/riscv64/linux.h line 24
Quoted 7 lines
include/grub/riscv64/linux.h +3
-1@@ -19,23 +19,28 @@#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_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */
to be removed in future
Best regards
Heinrich
Quoted 29 lines
include/grub/riscv64/linux.h +10
-7#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
Re: [v4 PATCH 2/3] RISC-V: Update image header
Quoted 30 lines · Heinrich Schuchardt
Quoted 18 lines · 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")Signed-off-by Atish Patra <[email protected]>--- include/grub/riscv32/linux.h | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)include/grub/riscv32/linux.h +0
-0include/grub/riscv32/linux.h line 22
Quoted 5 lines
include/grub/riscv32/linux.h +1
-1@@ -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' */ Thanks for following up on this series.
Quoted 7 lines
Considering
69edb312056("loader/arm64/linux: Remove magic number header field check") why should this constant exist in GRUB at all?In a follow up patch we could remove it together with
GRUB_LINUX_ARM_MAGIC_SIGNATURE,GRUB_LINUX_ARMXX_MAGIC_SIGNATURE, andGRUB_LINUX_ARMXX_MAGIC_SIGNATURE.
Indeed.
But by the same reasoning, why do we need per-arch kernel header typedefs at all? The only fields we access are generic PE/COFF header fields.
Quoted 83 lines
Quoted 7 lines
include/grub/riscv32/linux.h +1
-1-/* 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 */ include/grub/riscv32/linux.h line 35
Quoted 10 lines
include/grub/riscv32/linux.h +5
-3-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 */ According to tag next-20221006 of
Documentation/riscv/boot-image-header.rstand ofarch/riscv/include/asm/image.hthis field is called 'magic' and filled it with the string 'RISCV\0\0\0'.include/grub/riscv32/linux.h line 36
Quoted 3 lines
include/grub/riscv32/linux.h +1
-2-grub_uint64_t res4;/* reserved */ -grub_uint32_t magic;/* Magic number, little endian, "RSCV" */ +grub_uint32_t magic;/* Magic number, little endian, "RSC\x05" */ The Linux kernel documentation calls this field magic2.
Of course this is functionally irrelevant as we don't care about the content of both fields.
Quoted 8 lines
include/grub/riscv32/linux.h +0
-0grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ };include/grub/riscv64/linux.h +0
-0include/grub/riscv64/linux.h line 24
Quoted 7 lines
include/grub/riscv64/linux.h +3
-1@@ -19,23 +19,28 @@#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_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */ to be removed in future
Best regards
Heinrich
Quoted 29 lines
include/grub/riscv64/linux.h +10
-7#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
Heinrich Schuchardt
Acked-byRe: [v4 PATCH 2/3] RISC-V: Update image header
Quoted 40 lines · Ard Biesheuvel
Quoted 30 lines · Heinrich Schuchardt
Quoted 18 lines · 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")Signed-off-by Atish Patra <[email protected]>--- include/grub/riscv32/linux.h | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)include/grub/riscv32/linux.h +0
-0include/grub/riscv32/linux.h line 22
Quoted 5 lines
include/grub/riscv32/linux.h +1
-1@@ -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' */ Thanks for following up on this series.
Quoted 7 lines
Considering
69edb312056("loader/arm64/linux: Remove magic number header field check") why should this constant exist in GRUB at all?In a follow up patch we could remove it together with
GRUB_LINUX_ARM_MAGIC_SIGNATURE,GRUB_LINUX_ARMXX_MAGIC_SIGNATURE, andGRUB_LINUX_ARMXX_MAGIC_SIGNATURE.
Quoted 5 lines
Indeed.
But by the same reasoning, why do we need per-arch kernel header typedefs at all? The only fields we access are generic PE/COFF header fields.
That said I would suggest to put the series in without any further iterations and clean up afterwards.
Quoted 84 lines
Quoted 84 lines
Quoted 8 lines
include/grub/riscv32/linux.h +1
-1-/* 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 */ include/grub/riscv32/linux.h line 35
Quoted 10 lines
include/grub/riscv32/linux.h +5
-3-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 */ According to tag next-20221006 of
Documentation/riscv/boot-image-header.rstand ofarch/riscv/include/asm/image.hthis field is called 'magic' and filled it with the string 'RISCV\0\0\0'.include/grub/riscv32/linux.h line 36
Quoted 3 lines
include/grub/riscv32/linux.h +1
-2-grub_uint64_t res4;/* reserved */ -grub_uint32_t magic;/* Magic number, little endian, "RSCV" */ +grub_uint32_t magic;/* Magic number, little endian, "RSC\x05" */ The Linux kernel documentation calls this field magic2.
Of course this is functionally irrelevant as we don't care about the content of both fields.
Quoted 8 lines
include/grub/riscv32/linux.h +0
-0grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ };include/grub/riscv64/linux.h +0
-0include/grub/riscv64/linux.h line 24
Quoted 7 lines
include/grub/riscv64/linux.h +3
-1@@ -19,23 +19,28 @@#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_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */ to be removed in future
Best regards
Heinrich
Quoted 29 lines
include/grub/riscv64/linux.h +10
-7#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
Re: [v4 PATCH 2/3] RISC-V: Update image header
Quoted 31 lines · Heinrich Schuchardt
Quoted 27 lines · Ard Biesheuvel
Quoted 25 lines · Heinrich Schuchardt
Quoted 21 lines · 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")Signed-off-by Atish Patra <[email protected]>--- include/grub/riscv32/linux.h | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)include/grub/riscv32/linux.h +0
-0@@ -19,20 +19,21 @@#ifndef GRUB_RISCV32_LINUX_HEADER #define GRUB_RISCV32_LINUX_HEADER 1
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/grub/riscv32/linux.h line 22
Quoted 2 lines
include/grub/riscv32/linux.h +1
-1-#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356/* 'RSCV' */ +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */ Thanks for following up on this series.
Considering
69edb312056("loader/arm64/linux: Remove magic number header field check") why should this constant exist in GRUB at all?
Yes. Those are not required. I will remove those.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
In a follow up patch we could remove it together with
GRUB_LINUX_ARM_MAGIC_SIGNATURE,GRUB_LINUX_ARMXX_MAGIC_SIGNATURE, andGRUB_LINUX_ARMXX_MAGIC_SIGNATURE.
GRUB_LINUX_ARM_MAGIC_SIGNATURE is still being used in ARM32 loaders. The other one can be removed.
Quoted 41 lines
Quoted 5 lines
Indeed.
But by the same reasoning, why do we need per-arch kernel header typedefs at all? The only fields we access are generic PE/COFF header fields.
That said I would suggest to put the series in without any further iterations and clean up afterwards.
Quoted 30 lines
Quoted 30 lines
Quoted 8 lines
include/grub/riscv32/linux.h +1
-1-/* 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 */ include/grub/riscv32/linux.h line 35
Quoted 10 lines
include/grub/riscv32/linux.h +5
-3-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 */ According to tag next-20221006 of
Documentation/riscv/boot-image-header.rstand ofarch/riscv/include/asm/image.hthis field is called 'magic' and filled it with the string 'RISCV\0\0\0'.include/grub/riscv32/linux.h line 36
Quoted 3 lines
include/grub/riscv32/linux.h +1
-2-grub_uint64_t res4;/* reserved */ -grub_uint32_t magic;/* Magic number, little endian, "RSCV" */ +grub_uint32_t magic;/* Magic number, little endian, "RSC\x05" */ The Linux kernel documentation calls this field magic2.
Yes. I forgot to update this one for rv32. RV64 header file has the correct fields.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Of course this is functionally irrelevant as we don't care about the content of both fields.
Quoted 11 lines
include/grub/riscv32/linux.h +0
-0grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ };include/grub/riscv64/linux.h +0
-0@@ -19,23 +19,28 @@#ifndef GRUB_RISCV64_LINUX_HEADER #define GRUB_RISCV64_LINUX_HEADER 1
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
include/grub/riscv64/linux.h line 24
Quoted 4 lines
include/grub/riscv64/linux.h +3
-1-#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356/* 'RSCV' */ +#include <grub/efi/pe32.h> + +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */
Done.
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
to be removed in future
Best regards
Heinrich
Quoted 29 lines
include/grub/riscv64/linux.h +10
-7#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 · 2 lines
Regards, Atish
Re: [v4 PATCH 2/3] RISC-V: Update image header
In reply to Heinrich SchuchardtQuoted 46 lines · Heinrich Schuchardt
Quoted 42 lines · Ard Biesheuvel
Quoted 30 lines · Heinrich Schuchardt
Quoted 18 lines · 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")Signed-off-by Atish Patra <[email protected]>--- include/grub/riscv32/linux.h | 15 ++++++++------- include/grub/riscv64/linux.h | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-)include/grub/riscv32/linux.h +0
-0include/grub/riscv32/linux.h line 22
Quoted 5 lines
include/grub/riscv32/linux.h +1
-1@@ -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' */ Thanks for following up on this series.
Quoted 7 lines
Considering
69edb312056("loader/arm64/linux: Remove magic number header field check") why should this constant exist in GRUB at all?In a follow up patch we could remove it together with
GRUB_LINUX_ARM_MAGIC_SIGNATURE,GRUB_LINUX_ARMXX_MAGIC_SIGNATURE, andGRUB_LINUX_ARMXX_MAGIC_SIGNATURE.Indeed.
Quoted 9 lines
Quoted 3 lines
But by the same reasoning, why do we need per-arch kernel header typedefs at all? The only fields we access are generic PE/COFF header fields.
That said I would suggest to put the series in without any further iterations and clean up afterwards.
Thanks for reviewing it. I will send the next version right now. I screwed up my scripts and grub-devel was not in the CC also.
Quoted 84 lines
Quoted 84 lines
Quoted 84 lines
Quoted 8 lines
include/grub/riscv32/linux.h +1
-1-/* 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 */ include/grub/riscv32/linux.h line 35
Quoted 10 lines
include/grub/riscv32/linux.h +5
-3-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 */ According to tag next-20221006 of
Documentation/riscv/boot-image-header.rstand ofarch/riscv/include/asm/image.hthis field is called 'magic' and filled it with the string 'RISCV\0\0\0'.include/grub/riscv32/linux.h line 36
Quoted 3 lines
include/grub/riscv32/linux.h +1
-2-grub_uint64_t res4;/* reserved */ -grub_uint32_t magic;/* Magic number, little endian, "RSCV" */ +grub_uint32_t magic;/* Magic number, little endian, "RSC\x05" */ The Linux kernel documentation calls this field magic2.
Of course this is functionally irrelevant as we don't care about the content of both fields.
Quoted 8 lines
include/grub/riscv32/linux.h +0
-0grub_uint32_t hdr_offset;/* Offset of PE/COFF header */ };include/grub/riscv64/linux.h +0
-0include/grub/riscv64/linux.h line 24
Quoted 7 lines
include/grub/riscv64/linux.h +3
-1@@ -19,23 +19,28 @@#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_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352/* 'RSC\0x5' */ to be removed in future
Best regards
Heinrich
Quoted 29 lines
include/grub/riscv64/linux.h +10
-7#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 · 2 lines
Regards, Atish
PATCH v4 3/3 RISC-V: Use common linux loader
In reply to Atish PatraRISC-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
@@ -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