Skip to contentSkip to conversation

util/grub-mkrescue: use capitalised paths for removable EFI images

PATCH Superseded Mingcong Bai 2 participants 6 messages Jun 11, 2024 – Jun 13, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/grub-mkrescue: use capitalised paths for removable EFI images

Per UEFI Specification, section 3.4.1.1:

... If FilePathList[0] points to a device that supports the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, then the system firmware will attempt to boot from a removable media FilePathList[0] by adding a default file name in the form \EFI\BOOT\BOOT{machine type short-name}.EFI.

While FAT < 32 filesystems are not case sensitive (which grub-mkrescue creates as a FAT12 image via mformat with a size of 2.88MiB), it seems that some of Loongson's LoongArch-based firmware (namely those found on their latest XA61200 boards) seems to treat this file system as case-sensitive. In this case, at least the XA61200 board seems incapable of identifying /efi/boot/bootloongarch64.efi as a valid removable EFI image.

In any case, according to the UEFI Specification, all paths and image filenames should be capitalised (with the exception of BOOTx64.EFI, according to section 3.5.1.1, for some reason) to stay compliant. The Loongson case is only one example of users running into buggy firmware and unbootable GRUB ISO images.

---
 util/grub-mkrescue.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
util/grub-mkrescue.c +3 -3
index 27696e034..963b47117 100644
@@ -769,8 +769,8 @@ main (int argc, char *argv[])
       || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])
     {
       FILE *f;
-      char *efidir_efi = grub_util_path_concat (2, iso9660_dir, "efi");
-      char *efidir_efi_boot = grub_util_path_concat (3, iso9660_dir, "efi", "boot");
+      char *efidir_efi = grub_util_path_concat (2, iso9660_dir, "EFI");
+      char *efidir_efi_boot = grub_util_path_concat (3, iso9660_dir, "EFI", "BOOT");
       char *imgname, *img32, *img64, *img_mac = NULL;
       char *efiimgfat, *iso_uuid_file, *diskdir, *diskdir_uuid;
       grub_install_mkdir_p (efidir_efi_boot);
@@ -792,52 +792,52 @@ main (int argc, char *argv[])
       free (diskdir_uuid);
       free (diskdir);
 
-      imgname = grub_util_path_concat (2, efidir_efi_boot, "bootia64.efi");
+      imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTIA64.EFI");
       make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, 
"ia64-efi", imgname);
       free (imgname);

       grub_install_push_module ("part_apple");
-      img64 = grub_util_path_concat (2, efidir_efi_boot, "bootx64.efi");
+      img64 = grub_util_path_concat (2, efidir_efi_boot, "BOOTx64.EFI");
       make_image_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", 
img64);
       grub_install_pop_module ();

       grub_install_push_module ("part_apple");
-      img32 = grub_util_path_concat (2, efidir_efi_boot, "bootia32.efi");
+      img32 = grub_util_path_concat (2, efidir_efi_boot, "BOOTIA32.EFI");
       make_image_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", 
img32);
       grub_install_pop_module ();

- imgname = grub_util_path_concat (2, efidir_efi_boot, "bootarm.efi");
+ imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTARM.EFI");
make_image_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi",

imgname);
       free (imgname);

- imgname = grub_util_path_concat (2, efidir_efi_boot, "bootaa64.efi");

+      imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTAA64.EFI");
       make_image_abs (GRUB_INSTALL_PLATFORM_ARM64_EFI, "arm64-efi", 
imgname);
       free (imgname);

- imgname = grub_util_path_concat (2, efidir_efi_boot, "bootloongarch64.efi");
+ imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTLOONGARCH64.EFI");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_LOONGARCH64_EFI,
"loongarch64-efi",

 			     imgname);
       free (imgname);

- imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi");
+ imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTRISCV32.EFI");
make_image_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi",

imgname);
       free (imgname);

- imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi");
+ imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOTRISCV64.EFI");
make_image_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi",

imgname);
       free (imgname);

       if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])

{
- imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi");
+ imgname = grub_util_path_concat (2, efidir_efi_boot, "BOOT.EFI");
/* For old macs. Suggested by Peter Jones. */ grub_install_copy_file (img32, imgname, 1);
}

if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
- img_mac = grub_util_path_concat (2, core_services, "boot.efi");
+ img_mac = grub_util_path_concat (2, core_services, "BOOT.EFI");

if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
&& source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])

Signature · 7 lines
2.45.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

Hi,

Quoted 9 lines · Mingcong Bai

While FAT < 32 filesystems are not case sensitive (which grub-mkrescue creates
as a FAT12 image via mformat with a size of 2.88MiB), it seems that some of Loongson's LoongArch-based firmware (namely those found on their latest XA61200 boards) seems to treat this file system as case-sensitive.
[...]

        if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
          || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])

Review

Quoted 5 lines
(quoted diff) +1 -1
-       img_mac = grub_util_path_concat (2, core_services, "boot.efi");
+       img_mac = grub_util_path_concat (2, core_services, "BOOT.EFI");
 
        if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
          && source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])

I think that this name does not end up in a FAT filesystem but rather in HFS+, where it gets blessed. (It also ends up in ISO 9660.)

707: core_services = grub_util_path_concat (4, iso9660_dir, "System", "Library", "CoreServices");

753:              xorriso_push ("-hfs-bless-by");
754:              xorriso_push ("i");
755:              xorriso_push ("/System/Library/CoreServices/boot.efi");

This xorrisofs option would not reach a file in the EFI boot image.

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 34 lines · 在 2024-06-12 02:35,Thomas Schmitt via Grub-devel 写道:

Hi,

Quoted 9 lines · Mingcong Bai

While FAT < 32 filesystems are not case sensitive (which grub-mkrescue creates
as a FAT12 image via mformat with a size of 2.88MiB), it seems that some of Loongson's LoongArch-based firmware (namely those found on their latest XA61200 boards) seems to treat this file system as case-sensitive.
[...]

        if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
          || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
Quoted 7 lines

- img_mac = grub_util_path_concat (2, core_services,
"boot.efi");
+ img_mac = grub_util_path_concat (2, core_services,
"BOOT.EFI");

        if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
          && source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])

I think that this name does not end up in a FAT filesystem but rather in HFS+, where it gets blessed. (It also ends up in ISO 9660.)

707: core_services = grub_util_path_concat (4, iso9660_dir, "System", "Library", "CoreServices");

753:              xorriso_push ("-hfs-bless-by");
754:              xorriso_push ("i");
755:              xorriso_push ("/System/Library/CoreServices/boot.efi");

This xorrisofs option would not reach a file in the EFI boot image.

Have a nice day :)

Quoted 7 lines

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Hi Thomas!

Thanks for your review. I will now submit v2.

Best Regards,
Mingcong Bai

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw

Hi,

Quoted 1 line · Mingcong Bai

Thanks for your review. I will now submit v2.

Well, it's not actually a review but rather pointing out a problem which
would probably cause a failure of the xorriso run, when the option
-hfs-bless-by i /System/Library/CoreServices/boot.efi
does not find "boot.efi" because it would now be named "BOOT.EFI".
I'd expect this message and no resulting ISO image:
xorriso : FAILURE : Cannot find path '/System/Library/CoreServices/boot.efi' in loaded ISO image

I'm only qualified for judging the xorriso aspect of grub-mkrescue. The EFI aspect is mostly out of my scope. So i can't add a "Reviewed-by:".

Two more thoughts which came to me since monday:

- Which of the platforms did you actually test ?
(I would be astonished if GRUB_INSTALL_PLATFORM_I386_EFI and GRUB_INSTALL_PLATFORM_X86_64_EFI were among them, because else xorriso should have thrown above error.)

- The new name "BOOTx64.EFI" isn't actually all uppercase.
I am aware that the specs indeed mention the name that way in UEFI 2.8 table 15. But that table is obviously buggy by calling in column 1 all three RISC-V architectures "32-bit".
So the lowercase "x" in "BOOTx64.EFI" might be an old typo in the specs. (It's already present in UEFI 2.4 table 12.)

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Hi Thomas,

Quoted 5 lines · 在 2024-06-13 16:30,Thomas Schmitt via Grub-devel 写道:

Hi,

Quoted 1 line · Mingcong Bai

Thanks for your review. I will now submit v2.

Quoted 8 lines

Well, it's not actually a review but rather pointing out a problem which would probably cause a failure of the xorriso run, when the option
-hfs-bless-by i /System/Library/CoreServices/boot.efi
does not find "boot.efi" because it would now be named "BOOT.EFI". I'd expect this message and no resulting ISO image:
xorriso : FAILURE : Cannot find path
'/System/Library/CoreServices/boot.efi' in loaded ISO image

Yes, good catch. I have removed this change in v2.

Quoted 2 lines

I'm only qualified for judging the xorriso aspect of grub-mkrescue. The EFI aspect is mostly out of my scope. So i can't add a "Reviewed-by:".

No worries, it's appreciated nonetheless.

Quoted 9 lines

Two more thoughts which came to me since monday:

- Which of the platforms did you actually test ?
(I would be astonished if GRUB_INSTALL_PLATFORM_I386_EFI and GRUB_INSTALL_PLATFORM_X86_64_EFI were among them, because else
xorriso
should have thrown above error.)

I was testing for loongarch64-efi. As noted in the commit message, I found that Loongson's firmware incapable of handling non-upper-case EFI boot paths (which grub-install happens to evade, as it creates upper-case paths and filenames in the first place).

And yes, with the boot.efi change removed, there shouldn't be any more error - right?

Quoted 9 lines

- The new name "BOOTx64.EFI" isn't actually all uppercase. I am aware that the specs indeed mention the name that way in UEFI
2.8
table 15. But that table is obviously buggy by calling in column 1 all three RISC-V architectures "32-bit".
So the lowercase "x" in "BOOTx64.EFI" might be an old typo in the
specs.
(It's already present in UEFI 2.4 table 12.)

Indeed, but I'm no one to argue with the specifications. I would be happy to hear what others have to say about this - should we stick with BOOTX64.EFI or use BOOTx64.EFI as ordered.

Quoted 10 lines

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

Hi,

Quoted 3 lines · Mingcong Bai

I was testing for loongarch64-efi. As noted in the commit message, I found that Loongson's firmware incapable of handling non-upper-case EFI boot paths

If no test reports emerge about other platforms, then i would consider to reduce the patch to what was tested and is really needed with real-world firmware.

The potential xorriso failure would only show up with x86 platforms. So reducing the patch to the smallest needed change would be the best way to avoid such mishaps with untested platforms.

Quoted 2 lines

with the boot.efi change removed, there shouldn't be any more error - right?

I see no other change in your patch which would influence the ISO 9660 filesystem tree and the possible HFS+ tree. Thus i think it should be safe.

Note that the name "boot.efi" gets used for two occasions: Once it gets into the FAT filesystem and once into the ISO 9660 / HFS+ filesystem. The comments in the code and my conversations with Vladimir Serbinenko indicate that both times it is for x86 Macs. Those which read HFS+ are probably quite old.
The FAT filesystem image becomes a data file in the ISO filesystem. xorriso will not peek into the FAT filesystem. So renaming the "boot.efi" which goes into FAT will not cause the need for changes about the xorriso options.

(File names in the ISO 9660 fileystem are case-insensitive for the dull ISO names, but case-sensitive for the Rock Ridge extensions which augment the ISO 9660 filesystem to comply with X/Open specs. The HFS+ tree, which shares data file content with the ISO tree, is case-insensitive. Since the "xo" in the name "xorriso" stands for X/Open and the "rr" stands for Rock Ridge, xorriso is case-sensitive with its file path arguments.)

Quoted 3 lines
Quoted 1 line

- The new name "BOOTx64.EFI" isn't actually all uppercase.

Indeed, but I'm no one to argue with the specifications.

Avoiding to change it would elegantly avoid the question whether we know better than the specs.
Else you would possibly have to change the patch title to something like:
"use paths for removable EFI images as prescribed by UEFI"

Quoted 2 lines

non-upper-case EFI boot paths (which grub-install happens to evade, as it creates upper-case paths and filenames in the first place)

So you could call the patch a unification of name habits between grub-install and grub-mkrescue. Maybe this attracts more testers for the other platforms.

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel