Re: A thread on grub-bug could need attention

2018-02-01 Thread Michel Bouissou
Hi,

Le 01/02/2018 à 01:02, Thomas Schmitt a écrit :
> Michel - on his way to India - could zeroize 512-byte block 1 of the
> Debian Live ISO and then try to boot it from USB stick
> 
>   dd if=/dev/zero conv=notrunc bs=512 seek=1 count=1 of=...image.or.stick...
> 
> where "...image.or.stick..." mabe either something like debian-live-*.iso
> or /dev/sdc.
> This would further deface the GPT and possibly de-confuse the firmware.

I made it (with latest debian-gnome 9.3 live), and tested it OK on
*another* machine.

But on the machine where the problem is, it does *NOT* boot.

It does display the key brand/model (instead of "Windows boot manager")
but when selecting it, the punishment is as usual : black screen with
cursor, game over.

No grub message or output of any kind.

ॐ

-- 
Michel Bouissou  OpenPGP ID 0xEB04D09C

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2018-02-01 Thread 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.

Signed-off-by: Leif Lindholm 
---
 grub-core/commands/file.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 63c84499b..fad191202 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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, _pi, 4) != 4)
+   struct linux_arm_kernel_header lh;
+   if (grub_file_read (file, , sizeof (lh)) != sizeof (lh))
  break;
/* Raspberry pi.  */
-   if (sig_pi == grub_cpu_to_le32_compile_time (0xea06))
+   if (lh.code0 == grub_cpu_to_le32_compile_time (0xea06))
  {
ret = 1;
break;
  }
 
-   if (grub_file_seek (file, 0x24) == (grub_size_t) -1)
- break;
-   if (grub_file_read (file, , 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;
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 07/10] arm: switch linux loader to linux_arm_kernel_header struct

2018-02-01 Thread Leif Lindholm
Use kernel header struct and magic definition to align (and coexist) with
i386/arm64 ports.

Signed-off-by: Leif Lindholm 
---
 grub-core/loader/arm/linux.c | 11 +--
 include/grub/arm/linux.h | 15 ---
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
index e64c79a95..9f43e41bb 100644
--- a/grub-core/loader/arm/linux.c
+++ b/grub-core/loader/arm/linux.c
@@ -46,9 +46,6 @@ static const void *current_fdt;
 
 typedef void (*kernel_entry_t) (int, unsigned long, void *);
 
-#define LINUX_ZIMAGE_OFFSET0x24
-#define LINUX_ZIMAGE_MAGIC 0x016f2818
-
 #define LINUX_PHYS_OFFSET(0x8000)
 #define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x0200)
 #define LINUX_FDT_PHYS_OFFSET(LINUX_INITRD_PHYS_OFFSET - 0x1)
@@ -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) == 0xea06
   && machine_type == GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI)
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
index 3706c46c6..64dd3173c 100644
--- a/include/grub/arm/linux.h
+++ b/include/grub/arm/linux.h
@@ -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 
 # define LINUX_ADDRESS(start_of_ram + 0x8000)
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 05/10] arm64: align linux kernel header struct naming with i386

2018-02-01 Thread Leif Lindholm
Rename struct grub_arm64_linux_kernel_header -> linux_arm64_kernel_header.

Signed-off-by: Leif Lindholm 
---
 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(-)

diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index ca01a2349..79f25a711 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -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);
 
diff --git a/grub-core/loader/arm64/xen_boot.c 
b/grub-core/loader/arm64/xen_boot.c
index 0a40e16be..258264c79 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -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, , sizeof (sh)) != (long) sizeof (sh))
 goto fail;
   if (grub_arm64_uefi_check_image
-  ((struct grub_arm64_linux_kernel_header *) ) != GRUB_ERR_NONE)
+  ((struct linux_arm64_kernel_header *) ) != GRUB_ERR_NONE)
 goto fail;
   grub_file_seek (file, 0);
 
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
index a8edf50dc..abe7e9cc3 100644
--- a/include/grub/arm64/linux.h
+++ b/include/grub/arm64/linux.h
@@ -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);
 
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2018-02-01 Thread 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.

Signed-off-by: Leif Lindholm 
---
 grub-core/commands/file.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index fad191202..dd729a8a8 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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, , 4) != 4)
+   if (grub_file_read (file, , 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;
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 06/10] arm64: align linux kernel magic macro naming with i386

2018-02-01 Thread Leif Lindholm
Change GRUB_ARM64_LINUX_MAGIC to GRUB_LINUX_ARM64_MAGIC_SIGNATURE.

Signed-off-by: Leif Lindholm 
---
 grub-core/loader/arm64/linux.c | 2 +-
 include/grub/arm64/linux.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index 79f25a711..ebe1e730d 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -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 & 0x) != GRUB_PE32_MAGIC)
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
index abe7e9cc3..b06347624 100644
--- a/include/grub/arm64/linux.h
+++ b/include/grub/arm64/linux.h
@@ -21,7 +21,7 @@
 
 #include 
 
-#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
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 03/10] make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

2018-02-01 Thread Leif Lindholm
Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE,
to be usable in code that supports more than one image type.

Signed-off-by: Leif Lindholm 
---
 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(-)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 12fba99e0..474666d3a 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -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;
 
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 083f9417c..9bd5afb65 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -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"
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
index a293b17aa..31a687644 100644
--- a/grub-core/loader/i386/pc/linux.c
+++ b/grub-core/loader/i386/pc/linux.c
@@ -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");
diff --git a/grub-core/loader/i386/xen_file.c b/grub-core/loader/i386/xen_file.c
index 99fad4cad..6e76e16aa 100644
--- a/grub-core/loader/i386/xen_file.c
+++ b/grub-core/loader/i386/xen_file.c
@@ -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");
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
index 2ff1621a4..3ff432be9 100644
--- a/include/grub/i386/linux.h
+++ b/include/grub/i386/linux.h
@@ -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_SIGNATURE0x53726448  /* "HdrS" */
 #define GRUB_LINUX_DEFAULT_SETUP_SECTS 4
 #define GRUB_LINUX_INITRD_MAX_ADDRESS  0x37FF
 #define GRUB_LINUX_MAX_SETUP_SECTS 64
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2018-02-01 Thread Leif Lindholm
 (for machine arm/efi) and
 (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.

Signed-off-by: Leif Lindholm 
---
 include/grub/arm/linux.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
index 64dd3173c..cceb9c4a9 100644
--- a/include/grub/arm/linux.h
+++ b/include/grub/arm/linux.h
@@ -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 
-# include 
+# include 
 /* 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(0x8000)
@@ -57,7 +57,7 @@ grub_arm_firmware_get_machine_type (void)
 }
 #elif defined (GRUB_MACHINE_COREBOOT)
 #include 
-#include 
+#include 
 # define LINUX_ADDRESS(start_of_ram + 0x8000)
 # define LINUX_INITRD_ADDRESS (start_of_ram + 0x0200)
 # define LINUX_FDT_ADDRESS(LINUX_INITRD_ADDRESS - 0x1)
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 04/10] i386: make struct linux_kernel_header architecture specific

2018-02-01 Thread Leif Lindholm
struct linux_kernel_header -> struct linux_i386_kernel_header

Signed-off-by: Leif Lindholm 
---
 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(-)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 474666d3a..63c84499b 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -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, , sizeof (lh)) != sizeof (lh))
  break;
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
index 9bd5afb65..44301e126 100644
--- a/grub-core/loader/i386/linux.c
+++ b/grub-core/loader/i386/linux.c
@@ -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;
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
index 31a687644..b69cb7a3a 100644
--- a/grub-core/loader/i386/pc/linux.c
+++ b/grub-core/loader/i386/pc/linux.c
@@ -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))
diff --git a/grub-core/loader/i386/xen_file.c b/grub-core/loader/i386/xen_file.c
index 6e76e16aa..77a93e7b2 100644
--- a/grub-core/loader/i386/xen_file.c
+++ b/grub-core/loader/i386/xen_file.c
@@ -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];
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
index 3ff432be9..0bd758817 100644
--- a/include/grub/i386/linux.h
+++ b/include/grub/i386/linux.h
@@ -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 */
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2018-02-01 Thread 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.

Signed-off-by: Leif Lindholm 
---
 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(-)

diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index 746edd104..ca01a2349 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/grub-core/loader/arm64/xen_boot.c 
b/grub-core/loader/arm64/xen_boot.c
index 6780b1f0c..0a40e16be 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include  /* required by struct xen_hypervisor_header */
 #include 
 #include 
diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
index 17212c38d..c0c6800f7 100644
--- a/grub-core/loader/efi/fdt.c
+++ b/grub-core/loader/efi/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void *loaded_fdt;
 static void *fdt;
diff --git a/include/grub/efi/fdtload.h b/include/grub/efi/fdtload.h
index 7b9ddba91..713c9424d 100644
--- a/include/grub/efi/fdtload.h
+++ b/include/grub/efi/fdtload.h
@@ -29,7 +29,4 @@ grub_fdt_unload (void);
 grub_err_t
 grub_fdt_install (void);
 
-#define GRUB_EFI_PAGE_SHIFT12
-#define GRUB_EFI_BYTES_TO_PAGES(bytes)   (((bytes) + 0xfff) >> 
GRUB_EFI_PAGE_SHIFT)
-
 #endif
diff --git a/include/grub/efi/memory.h b/include/grub/efi/memory.h
index 20526b146..08fe62277 100644
--- a/include/grub/efi/memory.h
+++ b/include/grub/efi/memory.h
@@ -22,6 +22,13 @@
 #include 
 #include 
 
+/* 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,
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2018-02-01 Thread Leif Lindholm
Replace uses of GRUB_LINUX_MACHINE_HEADER and GRUB_LINUX_CPU_HEADER
with GRUB__LINUX_HEADER include guards to prevent issues when
including more than one of them.

Signed-off-by: Leif Lindholm 
---
 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(-)

diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
index f217f8281..3706c46c6 100644
--- a/include/grub/arm/linux.h
+++ b/include/grub/arm/linux.h
@@ -17,8 +17,8 @@
  *  along with GRUB.  If not, see .
  */
 
-#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_SIZE0x300
 
-#endif /* ! GRUB_LINUX_CPU_HEADER */
+#endif /* ! GRUB_ARM_LINUX_HEADER */
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
index a981df5d1..a8edf50dc 100644
--- a/include/grub/arm64/linux.h
+++ b/include/grub/arm64/linux.h
@@ -16,8 +16,8 @@
  *  along with GRUB.  If not, see .
  */
 
-#ifndef GRUB_LINUX_CPU_HEADER
-#define GRUB_LINUX_CPU_HEADER 1
+#ifndef GRUB_ARM64_LINUX_HEADER
+#define GRUB_ARM64_LINUX_HEADER 1
 
 #include 
 
@@ -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 */
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
index da0ca3b83..2ff1621a4 100644
--- a/include/grub/i386/linux.h
+++ b/include/grub/i386/linux.h
@@ -16,8 +16,8 @@
  *  along with GRUB.  If not, see .
  */
 
-#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 */
-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 00/10] various cleanup

2018-02-01 Thread 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.

   1/10 Simply moves the EFI_PAGE definition to .
 2-7/10 Cleans up and aligns the macro and struct naming for 
.
   8/10 Makes it possible to include  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(-)

-- 
2.11.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] chainloader: patch in BPB's sectors_per_track and num_heads

2018-02-01 Thread C. Masloch

These fields must reflect the ROM-BIOS's geometry for CHS-based
loaders to correctly load their next stage. Most loaders do not
query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
the correct values already.

Tested with lDebug booted in qemu via grub2's
FreeDOS direct loading support, refer to
https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
(For this test, lDebug's iniload.asm must be assembled with
-D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)

Signed-off-by: C. Masloch 
---
 grub-core/loader/i386/pc/chainloader.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/i386/pc/chainloader.c
b/grub-core/loader/i386/pc/chainloader.c
index 18220b7aa..ef3a322b7 100644
--- a/grub-core/loader/i386/pc/chainloader.c
+++ b/grub-core/loader/i386/pc/chainloader.c
@@ -19,6 +19,7 @@

 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -86,9 +87,16 @@ grub_chainloader_unload (void)
 void
 grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl)
 {
-  grub_uint32_t part_start = 0;
+  grub_uint32_t part_start = 0, heads = 0, sectors = 0;
   if (dev && dev->disk)
-part_start = grub_partition_get_start (dev->disk->partition);
+{
+  part_start = grub_partition_get_start (dev->disk->partition);
+  if (dev->disk->data)
+{
+  heads = ((struct grub_biosdisk_data *)(dev->disk->data))->heads;
+  sectors = ((struct grub_biosdisk_data
*)(dev->disk->data))->sectors;
+}
+}
   if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name,
   "NTFS", 4) == 0)
 {
@@ -127,12 +135,20 @@ grub_chainloader_patch_bpb (void *bs,
grub_device_t dev, grub_uint8_t dl)
{
  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
  bpb->version_specific.fat12_or_fat16.num_ph_drive = dl;
+  if (sectors)
+bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
+  if (heads)
+bpb->num_heads = grub_cpu_to_le16 (heads);
  return;
}
   if (bpb->version_specific.fat32.sectors_per_fat_32)
{
  bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
  bpb->version_specific.fat32.num_ph_drive = dl;
+  if (sectors)
+bpb->sectors_per_track = grub_cpu_to_le16 (sectors);
+  if (heads)
+bpb->num_heads = grub_cpu_to_le16 (heads);
  return;
}
   break;
-- 
2.11.0

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel