[v3,3/6] arm64 linux loader: rename functions and macros and move to common headers

Message ID 20180627171720.27028-4-leif.lindholm@linaro.org
State Superseded
Headers show
Series
  • efi: arm linux loader unification and correctness
Related show

Commit Message

Leif Lindholm June 27, 2018, 5:17 p.m.
In preparation for using the linux loader for 32-bit and 64-bit platforms,
rename grub_arm64*/GRUB_ARM64* to grub_efi*/GRUB_EFI*.

Move prototypes for now-common functions to efi/efi.h.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

---
 grub-core/loader/arm64/linux.c    | 14 +++++++-------
 grub-core/loader/arm64/xen_boot.c | 10 +++++-----
 include/grub/arm64/linux.h        |  9 ++++-----
 include/grub/efi/efi.h            |  4 ++++
 4 files changed, 20 insertions(+), 17 deletions(-)

-- 
2.11.0


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

Comments

Daniel Kiper July 6, 2018, 3:28 p.m. | #1
On Wed, Jun 27, 2018 at 06:17:17PM +0100, Leif Lindholm wrote:
> In preparation for using the linux loader for 32-bit and 64-bit platforms,

> rename grub_arm64*/GRUB_ARM64* to grub_efi*/GRUB_EFI*.

>

> Move prototypes for now-common functions to efi/efi.h.

>

> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---

>  grub-core/loader/arm64/linux.c    | 14 +++++++-------

>  grub-core/loader/arm64/xen_boot.c | 10 +++++-----

>  include/grub/arm64/linux.h        |  9 ++++-----

>  include/grub/efi/efi.h            |  4 ++++

>  4 files changed, 20 insertions(+), 17 deletions(-)

>

> diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c

> index ebe1e730d..577fbda54 100644

> --- a/grub-core/loader/arm64/linux.c

> +++ b/grub-core/loader/arm64/linux.c

> @@ -48,9 +48,9 @@ static grub_addr_t initrd_start;

>  static grub_addr_t initrd_end;

>

>  grub_err_t

> -grub_arm64_uefi_check_image (struct linux_arm64_kernel_header * lh)

> +grub_efi_linux_check_image (struct linux_armxx_kernel_header * lh)


s/grub_efi_linux_check_image/grub_armxx_efi_linux_check_image/

This and functions below seems to be ARM specific, so, I would
add "_armxx_" to the name as above. Same below please.

>  {

> -  if (lh->magic != GRUB_LINUX_ARM64_MAGIC_SIGNATURE)

> +  if (lh->magic != LINUX_ARMXX_MAGIC_SIGNATURE)


s/LINUX_ARMXX_MAGIC_SIGNATURE/GRUB_LINUX_ARMXX_MAGIC_SIGNATURE/g

Hmmm... Why do you drop "GRUB_" prefix?

>      return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");

>

>    if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)

> @@ -109,7 +109,7 @@ failure:

>  }

>

>  grub_err_t

> -grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)

> +grub_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)


s/grub_efi_linux_boot_image/grub_armxx_efi_linux_boot_image/g

...and below please...

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
Leif Lindholm July 6, 2018, 4:28 p.m. | #2
On Fri, Jul 06, 2018 at 05:28:17PM +0200, Daniel Kiper wrote:
> On Wed, Jun 27, 2018 at 06:17:17PM +0100, Leif Lindholm wrote:

> > In preparation for using the linux loader for 32-bit and 64-bit platforms,

> > rename grub_arm64*/GRUB_ARM64* to grub_efi*/GRUB_EFI*.

> >

> > Move prototypes for now-common functions to efi/efi.h.

> >

> > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>

> > ---

> >  grub-core/loader/arm64/linux.c    | 14 +++++++-------

> >  grub-core/loader/arm64/xen_boot.c | 10 +++++-----

> >  include/grub/arm64/linux.h        |  9 ++++-----

> >  include/grub/efi/efi.h            |  4 ++++

> >  4 files changed, 20 insertions(+), 17 deletions(-)

> >

> > diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c

> > index ebe1e730d..577fbda54 100644

> > --- a/grub-core/loader/arm64/linux.c

> > +++ b/grub-core/loader/arm64/linux.c

> > @@ -48,9 +48,9 @@ static grub_addr_t initrd_start;

> >  static grub_addr_t initrd_end;

> >

> >  grub_err_t

> > -grub_arm64_uefi_check_image (struct linux_arm64_kernel_header * lh)

> > +grub_efi_linux_check_image (struct linux_armxx_kernel_header * lh)

> 

> s/grub_efi_linux_check_image/grub_armxx_efi_linux_check_image/

> 

> This and functions below seems to be ARM specific, so, I would

> add "_armxx_" to the name as above. Same below please.


Yeah, fair point.

> >  {

> > -  if (lh->magic != GRUB_LINUX_ARM64_MAGIC_SIGNATURE)

> > +  if (lh->magic != LINUX_ARMXX_MAGIC_SIGNATURE)

> 

> s/LINUX_ARMXX_MAGIC_SIGNATURE/GRUB_LINUX_ARMXX_MAGIC_SIGNATURE/g

> 

> Hmmm... Why do you drop "GRUB_" prefix?


I stumbled a bit around here tbh.
My rationale was a bit like for struct linux_*_kernel_header instead
of grub_linux_*_kernel_header.

I don't mind changing.

> >      return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");

> >

> >    if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)

> > @@ -109,7 +109,7 @@ failure:

> >  }

> >

> >  grub_err_t

> > -grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)

> > +grub_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)

> 

> s/grub_efi_linux_boot_image/grub_armxx_efi_linux_boot_image/g

> 

> ...and below please...


Sure.

/
    Leif

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

Patch

diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index ebe1e730d..577fbda54 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -48,9 +48,9 @@  static grub_addr_t initrd_start;
 static grub_addr_t initrd_end;
 
 grub_err_t
-grub_arm64_uefi_check_image (struct linux_arm64_kernel_header * lh)
+grub_efi_linux_check_image (struct linux_armxx_kernel_header * lh)
 {
-  if (lh->magic != GRUB_LINUX_ARM64_MAGIC_SIGNATURE)
+  if (lh->magic != LINUX_ARMXX_MAGIC_SIGNATURE)
     return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
 
   if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
@@ -109,7 +109,7 @@  failure:
 }
 
 grub_err_t
-grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)
+grub_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
 {
   grub_efi_memory_mapped_device_path_t *mempath;
   grub_efi_handle_t image_handle;
@@ -172,8 +172,8 @@  grub_linux_boot (void)
   if (finalize_params_linux () != GRUB_ERR_NONE)
     return grub_errno;
 
-  return (grub_arm64_uefi_boot_image((grub_addr_t)kernel_addr,
-                                     kernel_size, linux_args));
+  return (grub_efi_linux_boot_image((grub_addr_t)kernel_addr,
+                                    kernel_size, linux_args));
 }
 
 static grub_err_t
@@ -249,7 +249,7 @@  grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 		int argc, char *argv[])
 {
   grub_file_t file = 0;
-  struct linux_arm64_kernel_header lh;
+  struct linux_armxx_kernel_header lh;
 
   grub_dl_ref (my_mod);
 
@@ -268,7 +268,7 @@  grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
     return grub_errno;
 
-  if (grub_arm64_uefi_check_image (&lh) != GRUB_ERR_NONE)
+  if (grub_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
     goto fail;
 
   grub_loader_unset();
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
index 258264c79..b86704757 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -265,9 +265,9 @@  xen_boot (void)
   if (err)
     return err;
 
-  return grub_arm64_uefi_boot_image (xen_hypervisor->start,
-				     xen_hypervisor->size,
-				     xen_hypervisor->cmdline);
+  return grub_efi_linux_boot_image (xen_hypervisor->start,
+				    xen_hypervisor->size,
+				    xen_hypervisor->cmdline);
 }
 
 static void
@@ -468,8 +468,8 @@  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 linux_arm64_kernel_header *) &sh) != GRUB_ERR_NONE)
+  if (grub_efi_linux_check_image
+      ((struct linux_armxx_kernel_header *) &sh) != 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 b06347624..4c0d8d239 100644
--- a/include/grub/arm64/linux.h
+++ b/include/grub/arm64/linux.h
@@ -19,8 +19,6 @@ 
 #ifndef GRUB_ARM64_LINUX_HEADER
 #define GRUB_ARM64_LINUX_HEADER 1
 
-#include <grub/efi/efi.h>
-
 #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
 
 /* From linux/Documentation/arm64/booting.txt */
@@ -38,8 +36,9 @@  struct linux_arm64_kernel_header
   grub_uint32_t hdr_offset;	/* Offset of PE/COFF header */
 };
 
-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);
+#if defined(__aarch64__)
+# define LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
+# define linux_armxx_kernel_header linux_arm64_kernel_header
+#endif
 
 #endif /* ! GRUB_ARM64_LINUX_HEADER */
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index 57db74b57..5888bf6ac 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -95,6 +95,10 @@  void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
 #endif
 #if defined(__aarch64__)
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
+#include <grub/cpu/linux.h>
+grub_err_t grub_efi_linux_check_image(struct linux_armxx_kernel_header *lh);
+grub_err_t grub_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
+                                     char *args);
 #endif
 
 grub_addr_t grub_efi_modules_addr (void);