Skip to contentSkip to conversation

various cleanup

PATCH In review Leif Lindholm 2 participants 29 messages Feb 1, 2018 – Mar 5, 2018

lore
Share & tools
lore
#0 lore raw

cover various cleanup

So, sorry I dropped the ball on this last year.

This series contains what I would hope to be non-contentious cleanup in preparation for the functional changes (/fixes) for the arm64 linux loader and its reuse in the arm-efi port.

1/10 Simply moves the EFI_PAGE definition to <grub/efi/memory.h>.
2-7/10 Cleans up and aligns the macro and struct naming for

        <grub/cpu/linux.h>.

8/10 Makes it possible to include <grub/arm/linux.h> in a non-native
command or utility.
9-10/10 Switches to use the arm/arm64 kernel header structs in the
"file" command".

Leif Lindholm (10):
arm64/efi: move EFI_PAGE definitions to efi/memory.h Make arch-specific linux.h include guards architecture unique make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific
i386: make struct linux_kernel_header architecture specific
arm64: align linux kernel header struct naming with i386
arm64: align linux kernel magic macro naming with i386
arm: switch linux loader to linux_arm_kernel_header struct
arm: make linux.h safe to include for non-native builds commands/file: use definitions from arm/linux.h commands/file: use definitions from arm64/linux.h

 grub-core/commands/file.c         | 31 +++++++++++++++----------------
 grub-core/loader/arm/linux.c      | 11 +++++------
 grub-core/loader/arm64/linux.c    |  7 ++++---
 grub-core/loader/arm64/xen_boot.c |  5 +++--
 grub-core/loader/efi/fdt.c        |  1 +
 grub-core/loader/i386/linux.c     |  4 ++--
 grub-core/loader/i386/pc/linux.c  | 12 ++++++------
 grub-core/loader/i386/xen_file.c  |  4 ++--
 include/grub/arm/linux.h          | 25 +++++++++++++++++--------
 include/grub/arm64/linux.h        | 13 ++++++-------
 include/grub/efi/fdtload.h        |  3 ---
 include/grub/efi/memory.h         |  7 +++++++
 include/grub/i386/linux.h         | 10 +++++-----
 13 files changed, 73 insertions(+), 60 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/10 arm64/efi: move EFI_PAGE definitions to efi/memory.h

The EFI page definitions and macros are generic and should not be confined to arm64 headers - so move to efi/memory.h.
Also add EFI_PAGE_SIZE macro.

Update loader sources to reflect new header location.

---
 grub-core/loader/arm64/linux.c    | 1 +
 grub-core/loader/arm64/xen_boot.c | 1 +
 grub-core/loader/efi/fdt.c        | 1 +
 include/grub/efi/fdtload.h        | 3 ---
 include/grub/efi/memory.h         | 7 +++++++
 5 files changed, 10 insertions(+), 3 deletions(-)
grub-core/loader/arm64/linux.c +1 -0
index 746edd104..ca01a2349 100644
@@ -28,6 +28,7 @@
 #include <grub/cpu/linux.h>
 #include <grub/efi/efi.h>
 #include <grub/efi/fdtload.h>
+#include <grub/efi/memory.h>
 #include <grub/efi/pe32.h>
 #include <grub/i18n.h>
 #include <grub/lib/cmdline.h>
grub-core/loader/arm64/xen_boot.c +1 -0
index 6780b1f0c..0a40e16be 100644
@@ -30,6 +30,7 @@
 #include <grub/cpu/linux.h>
 #include <grub/efi/efi.h>
 #include <grub/efi/fdtload.h>
+#include <grub/efi/memory.h>
 #include <grub/efi/pe32.h>	/* required by struct xen_hypervisor_header */
 #include <grub/i18n.h>
 #include <grub/lib/cmdline.h>
grub-core/loader/efi/fdt.c +1 -0
index 17212c38d..c0c6800f7 100644
@@ -24,6 +24,7 @@
 #include <grub/file.h>
 #include <grub/efi/efi.h>
 #include <grub/efi/fdtload.h>
+#include <grub/efi/memory.h>
 
 static void *loaded_fdt;
 static void *fdt;
include/grub/efi/fdtload.h +0 -3
index 7b9ddba91..713c9424d 100644
@@ -29,7 +29,4 @@ grub_fdt_unload (void);
 grub_err_t
 grub_fdt_install (void);
 
-#define GRUB_EFI_PAGE_SHIFT	12
-#define GRUB_EFI_BYTES_TO_PAGES(bytes)   (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
-
 #endif
include/grub/efi/memory.h +7 -0
index 20526b146..08fe62277 100644
@@ -22,6 +22,13 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+/* The term "page" in UEFI refers only to a 4 KiB-aligned 4 KiB size region of
+   memory. It is not concerned with underlying translation management concepts,
+   but only used as the granule for memory allocations. */
+#define GRUB_EFI_PAGE_SHIFT             12
+#define GRUB_EFI_PAGE_SIZE              (1 << GRUB_EFI_PAGE_SHIFT)
+#define GRUB_EFI_BYTES_TO_PAGES(bytes)  (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
+
 #define GRUB_MMAP_REGISTER_BY_FIRMWARE  1
 
 grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size,
Signature · 1 line
2.11.0
Reviewed-by on v1 1/10
#2 lore raw

Re: [PATCH 01/10] arm64/efi: move EFI_PAGE definitions to efi/memory.h

Quoted 7 lines · Leif Lindholm

The EFI page definitions and macros are generic and should not be confined to arm64 headers - so move to efi/memory.h.
Also add EFI_PAGE_SIZE macro.

Update loader sources to reflect new header location.

Daniel

#3 lore raw

PATCH 2/10 Make arch-specific linux.h include guards architecture unique

In reply to Leif Lindholm

Replace uses of GRUB_LINUX_MACHINE_HEADER and GRUB_LINUX_CPU_HEADER with GRUB_<arch>_LINUX_HEADER include guards to prevent issues when including more than one of them.

---
 include/grub/arm/linux.h   | 6 +++---
 include/grub/arm64/linux.h | 6 +++---
 include/grub/i386/linux.h  | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
include/grub/arm/linux.h +3 -3
index f217f8281..3706c46c6 100644
@@ -17,8 +17,8 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef GRUB_LINUX_CPU_HEADER
-#define GRUB_LINUX_CPU_HEADER 1
+#ifndef GRUB_ARM_LINUX_HEADER
+#define GRUB_ARM_LINUX_HEADER 1
 
 #define LINUX_ZIMAGE_OFFSET 0x24
 #define LINUX_ZIMAGE_MAGIC  0x016f2818
@@ -66,4 +66,4 @@ grub_arm_firmware_get_machine_type (void)
 
 #define FDT_ADDITIONAL_ENTRIES_SIZE	0x300
 
-#endif /* ! GRUB_LINUX_CPU_HEADER */
+#endif /* ! GRUB_ARM_LINUX_HEADER */
include/grub/arm64/linux.h +3 -3
index a981df5d1..a8edf50dc 100644
@@ -16,8 +16,8 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef GRUB_LINUX_CPU_HEADER
-#define GRUB_LINUX_CPU_HEADER 1
+#ifndef GRUB_ARM64_LINUX_HEADER
+#define GRUB_ARM64_LINUX_HEADER 1
 
 #include <grub/efi/efi.h>
 
@@ -43,4 +43,4 @@ grub_err_t grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header
 grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size,
                                        char *args);
 
-#endif /* ! GRUB_LINUX_CPU_HEADER */
+#endif /* ! GRUB_ARM64_LINUX_HEADER */
include/grub/i386/linux.h +3 -3
index da0ca3b83..2ff1621a4 100644
@@ -16,8 +16,8 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef GRUB_LINUX_MACHINE_HEADER
-#define GRUB_LINUX_MACHINE_HEADER	1
+#ifndef GRUB_I386_LINUX_HEADER
+#define GRUB_I386_LINUX_HEADER	1
 
 #define GRUB_LINUX_MAGIC_SIGNATURE	0x53726448      /* "HdrS" */
 #define GRUB_LINUX_DEFAULT_SETUP_SECTS	4
@@ -312,4 +312,4 @@ struct linux_kernel_params
 } GRUB_PACKED;
 #endif /* ! ASM_FILE */
 
-#endif /* ! GRUB_LINUX_MACHINE_HEADER */
+#endif /* ! GRUB_I386_LINUX_HEADER */
Signature · 1 line
2.11.0
Reviewed-by on v1 2/10
#4 lore raw

Re: [PATCH 02/10] Make arch-specific linux.h include guards architecture unique

Quoted 5 lines · Leif Lindholm

Replace uses of GRUB_LINUX_MACHINE_HEADER and GRUB_LINUX_CPU_HEADER with GRUB_<arch>_LINUX_HEADER include guards to prevent issues when including more than one of them.

Daniel

#5 lore raw

PATCH 3/10 make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

In reply to Leif Lindholm

Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE, to be usable in code that supports more than one image type.

---
 grub-core/commands/file.c        | 4 ++--
 grub-core/loader/i386/linux.c    | 2 +-
 grub-core/loader/i386/pc/linux.c | 6 +++---
 grub-core/loader/i386/xen_file.c | 2 +-
 include/grub/i386/linux.h        | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
grub-core/commands/file.c +2 -2
index 12fba99e0..474666d3a 100644
@@ -508,7 +508,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
 
 	/* FIXME: some really old kernels (< 1.3.73) will fail this.  */
 	if (lh.header !=
-	    grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+	    grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
 	    || grub_le_to_cpu16 (lh.version) < 0x0200)
 	  break;
 
@@ -521,7 +521,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
 	/* FIXME: 2.03 is not always good enough (Linux 2.4 can be 2.03 and
 	   still not support 32-bit boot.  */
 	if (lh.header !=
-	    grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+	    grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
 	    || grub_le_to_cpu16 (lh.version) < 0x0203)
 	  break;
 
grub-core/loader/i386/linux.c +1 -1
index 083f9417c..9bd5afb65 100644
@@ -721,7 +721,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   /* FIXME: 2.03 is not always good enough (Linux 2.4 can be 2.03 and
      still not support 32-bit boot.  */
-  if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+  if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
       || grub_le_to_cpu16 (lh.version) < 0x0203)
     {
       grub_error (GRUB_ERR_BAD_OS, "version too old for 32-bit boot"
grub-core/loader/i386/pc/linux.c +3 -3
index a293b17aa..31a687644 100644
@@ -169,7 +169,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   maximal_cmdline_size = 256;
 
-  if (lh.header == grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+  if (lh.header == grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
       && grub_le_to_cpu16 (lh.version) >= 0x0200)
     {
       grub_linux_is_bzimage = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL);
@@ -322,7 +322,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+  if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
       || grub_le_to_cpu16 (lh.version) < 0x0200)
     /* Clear the heap space.  */
     grub_memset (grub_linux_real_chunk
@@ -407,7 +407,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   lh = (struct linux_kernel_header *) grub_linux_real_chunk;
 
-  if (!(lh->header == grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+  if (!(lh->header == grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
 	&& grub_le_to_cpu16 (lh->version) >= 0x0200))
     {
       grub_error (GRUB_ERR_BAD_OS, "the kernel is too old for initrd");
grub-core/loader/i386/xen_file.c +1 -1
index 99fad4cad..6e76e16aa 100644
@@ -43,7 +43,7 @@ grub_xen_file (grub_file_t file)
     goto fail;
 
   if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)
-      || lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
+      || lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
       || grub_le_to_cpu16 (lh.version) < 0x0208)
     {
       grub_error (GRUB_ERR_BAD_OS, "version too old for xen boot");
include/grub/i386/linux.h +1 -1
index 2ff1621a4..3ff432be9 100644
@@ -19,7 +19,7 @@
 #ifndef GRUB_I386_LINUX_HEADER
 #define GRUB_I386_LINUX_HEADER	1
 
-#define GRUB_LINUX_MAGIC_SIGNATURE	0x53726448      /* "HdrS" */
+#define GRUB_LINUX_I386_MAGIC_SIGNATURE	0x53726448      /* "HdrS" */
 #define GRUB_LINUX_DEFAULT_SETUP_SECTS	4
 #define GRUB_LINUX_INITRD_MAX_ADDRESS	0x37FFFFFF
 #define GRUB_LINUX_MAX_SETUP_SECTS	64
Signature · 1 line
2.11.0
#6 lore raw

Re: [PATCH 03/10] make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

Quoted 1 line · Leif Lindholm

Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE,

Missing "to" between GRUB_LINUX_MAGIC_SIGNATURE and GRUB_LINUX_I386_MAGIC_SIGNATURE. I will fix it during commit.

Quoted 3 lines

to be usable in code that supports more than one image type.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Daniel

#7 lore raw

Re: [PATCH 03/10] make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

Quoted 5 lines · Daniel Kiper
Quoted 1 line · Leif Lindholm

Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE,

Missing "to" between GRUB_LINUX_MAGIC_SIGNATURE and GRUB_LINUX_I386_MAGIC_SIGNATURE.

Both forms are valid (it wasn't a typo).

Quoted 1 line

I will fix it during commit.

But I don't mind if you change it :)

Quoted 5 lines
Quoted 3 lines

to be usable in code that supports more than one image type.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Thanks!

/
Leif

#8 lore raw

Re: [PATCH 03/10] make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

Quoted 8 lines · Leif Lindholm
Quoted 5 lines · Daniel Kiper
Quoted 1 line · Leif Lindholm

Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE,

Missing "to" between GRUB_LINUX_MAGIC_SIGNATURE and GRUB_LINUX_I386_MAGIC_SIGNATURE.

Both forms are valid (it wasn't a typo).

OK, thanks.

Quoted 3 lines
Quoted 1 line

I will fix it during commit.

But I don't mind if you change it :)

I will leave it then.

Daniel

#9 lore raw

PATCH 4/10 i386: make struct linux_kernel_header architecture specific

In reply to Leif Lindholm

struct linux_kernel_header -> struct linux_i386_kernel_header

---
 grub-core/commands/file.c        | 2 +-
 grub-core/loader/i386/linux.c    | 2 +-
 grub-core/loader/i386/pc/linux.c | 6 +++---
 grub-core/loader/i386/xen_file.c | 2 +-
 include/grub/i386/linux.h        | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
grub-core/commands/file.c +1 -1
index 474666d3a..63c84499b 100644
@@ -497,7 +497,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
     case IS_X86_LINUX32:
     case IS_X86_LINUX:
       {
-	struct linux_kernel_header lh;
+	struct linux_i386_kernel_header lh;
 	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
 	if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
grub-core/loader/i386/linux.c +1 -1
index 9bd5afb65..44301e126 100644
@@ -678,7 +678,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 		int argc, char *argv[])
 {
   grub_file_t file = 0;
-  struct linux_kernel_header lh;
+  struct linux_i386_kernel_header lh;
   grub_uint8_t setup_sects;
   grub_size_t real_size, prot_size, prot_file_size;
   grub_ssize_t len;
grub-core/loader/i386/pc/linux.c +3 -3
index 31a687644..b69cb7a3a 100644
@@ -121,7 +121,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 		int argc, char *argv[])
 {
   grub_file_t file = 0;
-  struct linux_kernel_header lh;
+  struct linux_i386_kernel_header lh;
   grub_uint8_t setup_sects;
   grub_size_t real_size;
   grub_ssize_t len;
@@ -387,7 +387,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 {
   grub_size_t size = 0;
   grub_addr_t addr_max, addr_min;
-  struct linux_kernel_header *lh;
+  struct linux_i386_kernel_header *lh;
   grub_uint8_t *initrd_chunk;
   grub_addr_t initrd_addr;
   grub_err_t err;
@@ -405,7 +405,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
       goto fail;
     }
 
-  lh = (struct linux_kernel_header *) grub_linux_real_chunk;
+  lh = (struct linux_i386_kernel_header *) grub_linux_real_chunk;
 
   if (!(lh->header == grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
 	&& grub_le_to_cpu16 (lh->version) >= 0x0200))
grub-core/loader/i386/xen_file.c +1 -1
index 6e76e16aa..77a93e7b2 100644
@@ -26,7 +26,7 @@ grub_elf_t
 grub_xen_file (grub_file_t file)
 {
   grub_elf_t elf;
-  struct linux_kernel_header lh;
+  struct linux_i386_kernel_header lh;
   grub_file_t off_file;
   grub_uint32_t payload_offset, payload_length;
   grub_uint8_t magic[6];
include/grub/i386/linux.h +1 -1
index 3ff432be9..0bd758817 100644
@@ -85,7 +85,7 @@ enum
   };
 
 /* For the Linux/i386 boot protocol version 2.10.  */
-struct linux_kernel_header
+struct linux_i386_kernel_header
 {
   grub_uint8_t code1[0x0020];
   grub_uint16_t cl_magic;		/* Magic number 0xA33F */
Signature · 1 line
2.11.0
#11 lore raw

PATCH 5/10 arm64: align linux kernel header struct naming with i386

In reply to Leif Lindholm

Rename struct grub_arm64_linux_kernel_header -> linux_arm64_kernel_header.

---
 grub-core/loader/arm64/linux.c    | 4 ++--
 grub-core/loader/arm64/xen_boot.c | 4 ++--
 include/grub/arm64/linux.h        | 5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)
grub-core/loader/arm64/linux.c +2 -2
index ca01a2349..79f25a711 100644
@@ -48,7 +48,7 @@ static grub_addr_t initrd_start;
 static grub_addr_t initrd_end;
 
 grub_err_t
-grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header * lh)
+grub_arm64_uefi_check_image (struct linux_arm64_kernel_header * lh)
 {
   if (lh->magic != GRUB_ARM64_LINUX_MAGIC)
     return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
@@ -249,7 +249,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 		int argc, char *argv[])
 {
   grub_file_t file = 0;
-  struct grub_arm64_linux_kernel_header lh;
+  struct linux_arm64_kernel_header lh;
 
   grub_dl_ref (my_mod);
 
grub-core/loader/arm64/xen_boot.c +2 -2
index 0a40e16be..258264c79 100644
@@ -67,7 +67,7 @@ typedef enum module_type module_type_t;
 
 struct xen_hypervisor_header
 {
-  struct grub_arm64_linux_kernel_header efi_head;
+  struct linux_arm64_kernel_header efi_head;
 
   /* This is always PE\0\0.  */
   grub_uint8_t signature[GRUB_PE32_SIGNATURE_SIZE];
@@ -469,7 +469,7 @@ grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)),
   if (grub_file_read (file, &sh, sizeof (sh)) != (long) sizeof (sh))
     goto fail;
   if (grub_arm64_uefi_check_image
-      ((struct grub_arm64_linux_kernel_header *) &sh) != GRUB_ERR_NONE)
+      ((struct linux_arm64_kernel_header *) &sh) != GRUB_ERR_NONE)
     goto fail;
   grub_file_seek (file, 0);
 
include/grub/arm64/linux.h +2 -3
index a8edf50dc..abe7e9cc3 100644
@@ -24,7 +24,7 @@
 #define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */
 
 /* From linux/Documentation/arm64/booting.txt */
-struct grub_arm64_linux_kernel_header
+struct linux_arm64_kernel_header
 {
   grub_uint32_t code0;		/* Executable code */
   grub_uint32_t code1;		/* Executable code */
@@ -38,8 +38,7 @@ struct grub_arm64_linux_kernel_header
   grub_uint32_t hdr_offset;	/* Offset of PE/COFF header */
 };
 
-grub_err_t grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header
-                                        *lh);
+grub_err_t grub_arm64_uefi_check_image (struct linux_arm64_kernel_header *lh);
 grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size,
                                        char *args);
 
Signature · 1 line
2.11.0
#13 lore raw

PATCH 6/10 arm64: align linux kernel magic macro naming with i386

In reply to Leif Lindholm

Change GRUB_ARM64_LINUX_MAGIC to GRUB_LINUX_ARM64_MAGIC_SIGNATURE.

---
 grub-core/loader/arm64/linux.c | 2 +-
 include/grub/arm64/linux.h     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/arm64/linux.c +1 -1
index 79f25a711..ebe1e730d 100644
@@ -50,7 +50,7 @@ static grub_addr_t initrd_end;
 grub_err_t
 grub_arm64_uefi_check_image (struct linux_arm64_kernel_header * lh)
 {
-  if (lh->magic != GRUB_ARM64_LINUX_MAGIC)
+  if (lh->magic != GRUB_LINUX_ARM64_MAGIC_SIGNATURE)
     return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
 
   if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
include/grub/arm64/linux.h +1 -1
index abe7e9cc3..b06347624 100644
@@ -21,7 +21,7 @@
 
 #include <grub/efi/efi.h>
 
-#define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */
+#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
 
 /* From linux/Documentation/arm64/booting.txt */
 struct linux_arm64_kernel_header
Signature · 1 line
2.11.0
#15 lore raw

PATCH 7/10 arm: switch linux loader to linux_arm_kernel_header struct

In reply to Leif Lindholm

Use kernel header struct and magic definition to align (and coexist) with i386/arm64 ports.

---
 grub-core/loader/arm/linux.c | 11 +++++------
 include/grub/arm/linux.h     | 15 ++++++++++++---
 2 files changed, 17 insertions(+), 9 deletions(-)
grub-core/loader/arm/linux.c +5 -6
index e64c79a95..9f43e41bb 100644
@@ -46,9 +46,6 @@ static const void *current_fdt;
 
 typedef void (*kernel_entry_t) (int, unsigned long, void *);
 
-#define LINUX_ZIMAGE_OFFSET	0x24
-#define LINUX_ZIMAGE_MAGIC	0x016f2818
-
 #define LINUX_PHYS_OFFSET        (0x00008000)
 #define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000)
 #define LINUX_FDT_PHYS_OFFSET    (LINUX_INITRD_PHYS_OFFSET - 0x10000)
@@ -315,6 +312,7 @@ linux_boot (void)
 static grub_err_t
 linux_load (const char *filename, grub_file_t file)
 {
+  struct linux_arm_kernel_header *lh;
   int size;
 
   size = grub_file_size (file);
@@ -337,9 +335,10 @@ linux_load (const char *filename, grub_file_t file)
       return grub_errno;
     }
 
-  if (size > LINUX_ZIMAGE_OFFSET + 4
-      && *(grub_uint32_t *) (linux_addr + LINUX_ZIMAGE_OFFSET)
-      == LINUX_ZIMAGE_MAGIC)
+  lh = (void *) linux_addr;
+
+  if ((grub_size_t) size > sizeof (*lh) &&
+      lh->magic == GRUB_LINUX_ARM_MAGIC_SIGNATURE)
     ;
   else if (size > 0x8000 && *(grub_uint32_t *) (linux_addr) == 0xea000006
 	   && machine_type == GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI)
include/grub/arm/linux.h +12 -3
index 3706c46c6..64dd3173c 100644
@@ -20,11 +20,20 @@
 #ifndef GRUB_ARM_LINUX_HEADER
 #define GRUB_ARM_LINUX_HEADER 1
 
-#define LINUX_ZIMAGE_OFFSET 0x24
-#define LINUX_ZIMAGE_MAGIC  0x016f2818
-
 #include "system.h"
 
+#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[4];
+  grub_uint32_t hdr_offset;
+};
+
 #if defined GRUB_MACHINE_UBOOT
 # include <grub/uboot/uboot.h>
 # define LINUX_ADDRESS        (start_of_ram + 0x8000)
Signature · 1 line
2.11.0
#17 lore raw

PATCH 8/10 arm: make linux.h safe to include for non-native builds

In reply to Leif Lindholm

<grub/machine/loader.h> (for machine arm/efi) and <grub/machine/kernel.h> (for machine arm/coreboot) will not always resolve (and will likely not be valid to) if pulled in when building non-native commands, such as host tools or the "file" command. So explicitly include them with their expanded pathnames.

---
 include/grub/arm/linux.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/grub/arm/linux.h +2 -2
index 64dd3173c..cceb9c4a9 100644
@@ -43,7 +43,7 @@ struct linux_arm_kernel_header {
 # define grub_arm_firmware_get_machine_type grub_uboot_get_machine_type
 #elif defined GRUB_MACHINE_EFI
 # include <grub/efi/efi.h>
-# include <grub/machine/loader.h>
+# include <grub/arm/efi/loader.h>
 /* On UEFI platforms - load the images at the lowest available address not
    less than *_PHYS_OFFSET from the first available memory location. */
 # define LINUX_PHYS_OFFSET        (0x00008000)
@@ -57,7 +57,7 @@ grub_arm_firmware_get_machine_type (void)
 }
 #elif defined (GRUB_MACHINE_COREBOOT)
 #include <grub/fdtbus.h>
-#include <grub/machine/kernel.h>
+#include <grub/arm/coreboot/kernel.h>
 # define LINUX_ADDRESS        (start_of_ram + 0x8000)
 # define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
 # define LINUX_FDT_ADDRESS    (LINUX_INITRD_ADDRESS - 0x10000)
Signature · 1 line
2.11.0
Reviewed-by on v1 8/10
#18 lore raw

Re: [PATCH 08/10] arm: make linux.h safe to include for non-native builds

Quoted 7 lines · Leif Lindholm

<grub/machine/loader.h> (for machine arm/efi) and <grub/machine/kernel.h> (for machine arm/coreboot) will not always resolve (and will likely not be valid to) if pulled in when building non-native commands, such as host tools or the "file" command. So explicitly include them with their expanded pathnames.

Daniel

#19 lore raw

PATCH 9/10 commands/file: use definitions from arm/linux.h

In reply to Leif Lindholm

Clean up code for matching IS_ARM slightly by making use of struct linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE.

---
 grub-core/commands/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/commands/file.c +6 -8
index 63c84499b..fad191202 100644
@@ -27,6 +27,7 @@
 #include <grub/elf.h>
 #include <grub/xen_file.h>
 #include <grub/efi/pe32.h>
+#include <grub/arm/linux.h>
 #include <grub/i386/linux.h>
 #include <grub/xnu.h>
 #include <grub/machoload.h>
@@ -383,21 +384,18 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
       }
     case IS_ARM_LINUX:
       {
-	grub_uint32_t sig, sig_pi;
-	if (grub_file_read (file, &sig_pi, 4) != 4)
+	struct linux_arm_kernel_header lh;
+	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
 	/* Raspberry pi.  */
-	if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006))
+	if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006))
 	  {
 	    ret = 1;
 	    break;
 	  }
 
-	if (grub_file_seek (file, 0x24) == (grub_size_t) -1)
-	  break;
-	if (grub_file_read (file, &sig, 4) != 4)
-	  break;
-	if (sig == grub_cpu_to_le32_compile_time (0x016f2818))
+	if (lh.magic ==
+	    grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM_MAGIC_SIGNATURE))
 	  {
 	    ret = 1;
 	    break;
Signature · 1 line
2.11.0
#20 lore raw

Re: [PATCH 09/10] commands/file: use definitions from arm/linux.h

Quoted 22 lines · Leif Lindholm

Clean up code for matching IS_ARM slightly by making use of struct linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE.

---
 grub-core/commands/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/commands/file.c +1 -0
index 63c84499b..fad191202 100644
@@ -27,6 +27,7 @@
 #include <grub/elf.h>
 #include <grub/xen_file.h>
 #include <grub/efi/pe32.h>
+#include <grub/arm/linux.h>
 #include <grub/i386/linux.h>
 #include <grub/xnu.h>
 #include <grub/machoload.h>
@@ -383,21 +384,18 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
       }

grub-core/commands/file.c grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) · line 391

Quoted 10 lines
grub-core/commands/file.c +3 -3
     case IS_ARM_LINUX:
       {
-	grub_uint32_t sig, sig_pi;
-	if (grub_file_read (file, &sig_pi, 4) != 4)
+	struct linux_arm_kernel_header lh;
+	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
 	/* Raspberry pi.  */
-	if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006))
+	if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006))

Could you define 0xea000006 as a constant? If you add the comment what does it mean that will be perfect.

Daniel

#21 lore raw

Re: [PATCH 09/10] commands/file: use definitions from arm/linux.h

Quoted 28 lines · Daniel Kiper
Quoted 27 lines · Leif Lindholm

Clean up code for matching IS_ARM slightly by making use of struct linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE.

---
 grub-core/commands/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/commands/file.c +2 -2
index 63c84499b..fad191202 100644
@@ -27,6 +27,7 @@
 #include <grub/elf.h>
 #include <grub/xen_file.h>
 #include <grub/efi/pe32.h>
+#include <grub/arm/linux.h>
 #include <grub/i386/linux.h>
 #include <grub/xnu.h>
 #include <grub/machoload.h>
@@ -383,21 +384,18 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
       }
     case IS_ARM_LINUX:
       {
-	grub_uint32_t sig, sig_pi;
-	if (grub_file_read (file, &sig_pi, 4) != 4)
+	struct linux_arm_kernel_header lh;
Quoted 8 lines

grub-core/commands/file.c grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) · line 391

Quoted 5 lines
grub-core/commands/file.c +2 -1
+	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
 	/* Raspberry pi.  */
-	if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006))
+	if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006))

Could you define 0xea000006 as a constant? If you add the comment what does it mean that will be perfect.

I'll be completely honest here and say "I don't have a clue".

Well, that's not true, I'm broken enough to see that that is a short forward branch in the A32 ("ARM") instruction set. What I don't understand is what significance that has for Raspberry Pi. I just kept the logic for compatibility.

Vladimir?

/
Leif

#22 lore raw

Re: [PATCH 09/10] commands/file: use definitions from arm/linux.h

Quoted 38 lines · Leif Lindholm
Quoted 28 lines · Daniel Kiper
Quoted 27 lines · Leif Lindholm

Clean up code for matching IS_ARM slightly by making use of struct linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE.

---
 grub-core/commands/file.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
grub-core/commands/file.c +2 -2
index 63c84499b..fad191202 100644
@@ -27,6 +27,7 @@
 #include <grub/elf.h>
 #include <grub/xen_file.h>
 #include <grub/efi/pe32.h>
+#include <grub/arm/linux.h>
 #include <grub/i386/linux.h>
 #include <grub/xnu.h>
 #include <grub/machoload.h>
@@ -383,21 +384,18 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
       }
     case IS_ARM_LINUX:
       {
-	grub_uint32_t sig, sig_pi;
-	if (grub_file_read (file, &sig_pi, 4) != 4)
+	struct linux_arm_kernel_header lh;
Quoted 8 lines

grub-core/commands/file.c grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) · line 391

Quoted 5 lines
grub-core/commands/file.c +2 -1
+	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
 	/* Raspberry pi.  */
-	if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006))
+	if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006))

Could you define 0xea000006 as a constant? If you add the comment what does it mean that will be perfect.

Quoted 8 lines

I'll be completely honest here and say "I don't have a clue".

Well, that's not true, I'm broken enough to see that that is a short forward branch in the A32 ("ARM") instruction set. What I don't understand is what significance that has for Raspberry Pi. I just kept the logic for compatibility.

Vladimir?

If Vladimir or anybody else is not able to say then I would not like to hold on you any longer. I am happy with your guess in the comment if you say that it is a guess.

Daniel

#23 lore raw

PATCH 10/10 commands/file: use definitions from arm64/linux.h

In reply to Leif Lindholm

Clean up code for matching IS_ARM64 slightly by making use of struct linux_arm_kernel_header and GRUB_LINUX_ARM64_MAGIC_SIGNATURE.

---
 grub-core/commands/file.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
grub-core/commands/file.c +6 -5
index fad191202..dd729a8a8 100644
@@ -28,6 +28,7 @@
 #include <grub/xen_file.h>
 #include <grub/efi/pe32.h>
 #include <grub/arm/linux.h>
+#include <grub/arm64/linux.h>
 #include <grub/i386/linux.h>
 #include <grub/xnu.h>
 #include <grub/machoload.h>
@@ -404,13 +405,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
       }
     case IS_ARM64_LINUX:
       {
-	grub_uint32_t sig;
+	struct linux_arm64_kernel_header lh;
 
-	if (grub_file_seek (file, 0x38) == (grub_size_t) -1)
-	  break;
-	if (grub_file_read (file, &sig, 4) != 4)
+	if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
 	  break;
-	if (sig == grub_cpu_to_le32_compile_time (0x644d5241))
+
+	if (lh.magic ==
+	    grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM64_MAGIC_SIGNATURE))
 	  {
 	    ret = 1;
 	    break;
Signature · 1 line
2.11.0
#25 lore raw
In reply to Leif Lindholm

Sorry for delay.

Quoted 6 lines · Leif Lindholm

So, sorry I dropped the ball on this last year.

This series contains what I would hope to be non-contentious cleanup in preparation for the functional changes (/fixes) for the arm64 linux loader and its reuse in the arm-efi port.

Quoted 7 lines

1/10 Simply moves the EFI_PAGE definition to <grub/efi/memory.h>.
2-7/10 Cleans up and aligns the macro and struct naming for

        <grub/cpu/linux.h>.

8/10 Makes it possible to include <grub/arm/linux.h> in a non-native
command or utility.
9-10/10 Switches to use the arm/arm64 kernel header structs in the
"file" command".

I am OK, excluding patch 9, with this patch series. If there are no objections I will apply patches 1-8 and 10 next week.

Daniel

#26 lore raw
Quoted 17 lines · Daniel Kiper

Sorry for delay.

Quoted 6 lines · Leif Lindholm

So, sorry I dropped the ball on this last year.

This series contains what I would hope to be non-contentious cleanup in preparation for the functional changes (/fixes) for the arm64 linux loader and its reuse in the arm-efi port.

Quoted 7 lines

1/10 Simply moves the EFI_PAGE definition to <grub/efi/memory.h>.
2-7/10 Cleans up and aligns the macro and struct naming for

        <grub/cpu/linux.h>.

8/10 Makes it possible to include <grub/arm/linux.h> in a non-native
command or utility.
9-10/10 Switches to use the arm/arm64 kernel header structs in the
"file" command".

Quoted 2 lines

I am OK, excluding patch 9, with this patch series. If there are no objections I will apply patches 1-8 and 10 next week.

Due to conflicts in patch 10 I have just applied patches 1-8. Please repost patches 9 and 10.

FYI, this is last time when I sent commit confirmation. If I send one in the future then this will be rather exception than rule. So, if you receive my reviewed-by and patch is not committed in a week or two then it means that it fallen into abyss and you have to ping me.

Have a nice weekend,

Daniel

#27 lore raw
Quoted 8 lines · Daniel Kiper
Quoted 5 lines
Quoted 2 lines

9-10/10 Switches to use the arm/arm64 kernel header structs in the
"file" command".

I am OK, excluding patch 9, with this patch series. If there are no objections I will apply patches 1-8 and 10 next week.

Due to conflicts in patch 10 I have just applied patches 1-8. Please repost patches 9 and 10.

I could re-post them, but they would look identical.
I'm a bit confused as to what the conflict is, since I can rebase the two commits onto current master without issues, and cherry-pick them cleanly.

Could you try cherry-picking them from
https://git.linaro.org/people/leif.lindholm/grub.git/log/?h=linux-cleanup
?

If you still have issues, can you show me the conflict?

Best Regards,

Leif

#28 lore raw
Quoted 15 lines · Leif Lindholm
Quoted 8 lines · Daniel Kiper
Quoted 5 lines
Quoted 2 lines

9-10/10 Switches to use the arm/arm64 kernel header structs in the
"file" command".

I am OK, excluding patch 9, with this patch series. If there are no objections I will apply patches 1-8 and 10 next week.

Due to conflicts in patch 10 I have just applied patches 1-8. Please repost patches 9 and 10.

I could re-post them, but they would look identical.
I'm a bit confused as to what the conflict is, since I can rebase the two commits onto current master without issues, and cherry-pick them cleanly.

Quoted 5 lines

Could you try cherry-picking them from
https://git.linaro.org/people/leif.lindholm/grub.git/log/?h=linux-cleanup
?

If you still have issues, can you show me the conflict?

It looks that I was not clear enough. Sorry about that. I had some comments for patch 9. So, I decided to skip it and apply patch 10 after 8. Sadly it looks that patch 10 depends on some changes in patch 9, so, I was not able to apply it. Hence, please fix patch 9, as I ask for, and repost both patch 9 and 10.

I hope that helps.

Daniel