> I found a few bugs in the grub-file utility and the corresponding command.
The second bug is that, because of the missing implementation of the 32 bit RISC-V detection, the command line options defind below that one are mixed up. I implemented the corresponding test to fix this. I don't have any EFI binaries for RISC-V though, so I couldn't test it. >From 7c59f43f89a3bdc3a75e7a88b13ab7971ce8b4e4 Mon Sep 17 00:00:00 2001 From: Lukas Fink <lukas.fi...@gmail.com> Date: Sun, 30 Aug 2020 00:04:16 +0200 Subject: [PATCH 2/3] commands/file: Add test for 32 bit RISC-V efi app This fixes a bug, where the behaviour of the options "is-riscv32-efi", "is-riscv64-efi", "is-hibernated-hiberfil", "is-x86_64-xnu", "is-i386-xnu", "is-xnu-hibr", "is-x86-bios-bootsector" matches the one described by the name of the next option of this list, with the last one ("is-x86-bios-bootsector") creating an error, because the implementation of "is-riscv32-efi" was missing. --- grub-core/commands/file.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 2574e6685..2c4718cb2 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -134,7 +134,8 @@ enum IS_IA_EFI, IS_ARM64_EFI, IS_ARM_EFI, - IS_RISCV_EFI, + IS_RISCV32_EFI, + IS_RISCV64_EFI, IS_HIBERNATED, IS_XNU64, IS_XNU32, @@ -576,7 +577,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) case IS_IA_EFI: case IS_ARM64_EFI: case IS_ARM_EFI: - case IS_RISCV_EFI: + case IS_RISCV64_EFI: + case IS_RISCV32_EFI: { char signature[4]; grub_uint32_t pe_offset; @@ -622,13 +624,16 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) && coff_head.machine != grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED)) break; - if (type == IS_RISCV_EFI + if (type == IS_RISCV64_EFI && coff_head.machine != grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV64)) - /* TODO: Determine bitness dynamically */ + break; + if (type == IS_RISCV32_EFI + && coff_head.machine != + grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV32)) break; if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI || - type == IS_RISCV_EFI) + type == IS_RISCV64_EFI) { struct grub_pe64_optional_header o64; if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64)) @@ -643,7 +648,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) ret = 1; break; } - if (type == IS_32_EFI || type == IS_ARM_EFI) + if (type == IS_32_EFI || type == IS_ARM_EFI || type == IS_RISCV32_EFI) { struct grub_pe32_optional_header o32; if (grub_file_read (file, &o32, sizeof (o32)) != sizeof (o32)) -- 2.28.0