Discussion:
[PATCH 2/2] commands/file: use definitions from arm64/linux.h
Leif Lindholm
2018-06-25 17:01:29 UTC
Permalink
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 <***@linaro.org>
---
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 b0fb524b3..6dbb43f0d 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -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;
--
2.11.0
Leif Lindholm
2018-06-25 17:01:28 UTC
Permalink
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 <***@linaro.org>
---
grub-core/commands/file.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 63c84499b..b0fb524b3 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -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))
+ /* Short forward branch in A32 state (for Raspberry pi kernels). */
+ 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;
--
2.11.0
Daniel Kiper
2018-07-04 14:54:46 UTC
Permalink
We now have pretty, architecture-safe, structs and macros for
kernel image headers and magic values. Use this to get rid of
some hardcoding in the "file" command.
Reviewed-by: Daniel Kiper <***@oracle.com>

If there are no objections I will apply both patches in a week or so.

Daniel

Continue reading on narkive:
Loading...