Add basic Boot Loader Interface support
v5 cover Add basic Boot Loader Interface support
This is a step towards supporting unified kernel images (UKI) in Grub.
Add a new module named boot_loader_interface, which provides a command with the same name. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.
This module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:
- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.
- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2]. This is especially useful for UKIs, where the kernel command line is fixed and usually does not contain any information about the root partition.
This module is only available on EFI platforms.
This series also unifies the GUID implementations and introduces a printf format specifier for them: %pG.
[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
v5:
- Replace more grub_*_guid with the new grub_guid struct
v4:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00058.html
- Place grub_utf8_to_utf16_alloc() in kern/misc.c and use it in kern/efi.c
- bli: rework partition GUID code, improve error reporting
- Add documentation for the bli module
- Address other comments
v3:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00008.html
- Unify GUID implementations for GPT and EFI
- Add printf format specifier for GUIDs, drop guid print function from v2.
- WIP/Please comment: Started extracting utf8->utf16 code. Where should this go?
- Address other comments
v2:
- https://mail.gnu.org/archive/html/grub-devel/2023-02/msg00099.html
- Addressed comments from Daniel
- Added a print function for gpt guids`
- Added integer overflow check in UTF16 conversion
- Added config drop-in file that loads the module on EFI
v1:
- https://mail.gnu.org/archive/html/grub-devel/2023-01/msg00104.html
Oliver Steffen (8):
efi: Add grub_efi_set_variable_with_attributes Unify GUID types
kern/misc: Add a format specifier GUIDs.
grub-core: Make use of guid printf format specifier types.h: Add GRUB_SSIZE_MAX
kern/misc, kern/efi: Extract UTF-8 to UTF-16 code Add a module for the Boot Loader Interface util/grub.d: Activate bli module on EFI
Makefile.util.def | 6 + docs/grub.texi | 22 ++++ grub-core/Makefile.core.def | 6 + grub-core/commands/acpi.c | 4 +- grub-core/commands/bli.c | 166 +++++++++++++++++++++++++++ grub-core/commands/efi/efifwsetup.c | 4 +- grub-core/commands/efi/loadbios.c | 14 +-- grub-core/commands/efi/lsefi.c | 17 +-- grub-core/commands/efi/lsefisystab.c | 10 +- grub-core/commands/efi/lssal.c | 4 +- grub-core/commands/efi/smbios.c | 12 +- grub-core/commands/efi/tpm.c | 6 +- grub-core/commands/probe.c | 11 +- grub-core/disk/efi/efidisk.c | 4 +- grub-core/disk/ldm.c | 2 +- grub-core/efiemu/i386/pc/cfgtables.c | 6 +- grub-core/efiemu/main.c | 4 +- grub-core/efiemu/runtime/efiemu.c | 14 +-- grub-core/kern/efi/acpi.c | 12 +- grub-core/kern/efi/efi.c | 86 +++++--------- grub-core/kern/efi/fdt.c | 2 +- grub-core/kern/efi/init.c | 2 +- grub-core/kern/efi/sb.c | 4 +- grub-core/kern/misc.c | 118 +++++++++++++++---- grub-core/loader/efi/fdt.c | 2 +- grub-core/loader/efi/linux.c | 4 +- grub-core/loader/i386/xnu.c | 13 +-- grub-core/loader/ia64/efi/linux.c | 2 +- grub-core/net/drivers/efi/efinet.c | 4 +- grub-core/partmap/gpt.c | 4 +- grub-core/term/efi/console.c | 2 +- grub-core/term/efi/serial.c | 2 +- grub-core/video/efi_gop.c | 8 +- grub-core/video/efi_uga.c | 2 +- include/grub/efi/api.h | 69 +++++------ include/grub/efi/efi.h | 20 ++-- include/grub/efiemu/efiemu.h | 10 +- include/grub/efiemu/runtime.h | 2 +- include/grub/gpt_partition.h | 13 +-- include/grub/misc.h | 3 + include/grub/types.h | 11 ++ util/grub-install.c | 2 +- util/grub-probe.c | 2 +- util/grub.d/25_bli.in | 25 ++++ 44 files changed, 491 insertions(+), 245 deletions(-) create mode 100644 grub-core/commands/bli.c create mode 100644 util/grub.d/25_bli.in
Signature · 1 line
2.39.2
PATCH v5 1/8 efi: Add grub_efi_set_variable_with_attributes
Add a function to the EFI module that allows setting EFI variables with specific attributes.
This is useful for marking variables as volatile, for example.
--- grub-core/kern/efi/efi.c | 19 +++++++++++++------ include/grub/efi/efi.h | 6 ++++++ 2 files changed, 19 insertions(+), 6 deletions(-)
grub-core/kern/efi/efi.c +13 -6
@@ -201,8 +201,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, }grub_err_t -grub_efi_set_variable (const char *var,const grub_efi_guid_t *guid, -void *data,grub_size_t datasize) +grub_efi_set_variable_with_attributes (const char *var,const grub_efi_guid_t *guid, +void *data,grub_size_t datasize,grub_efi_uint32_t attributes) {grub_efi_status_t status;grub_efi_runtime_services_t *r;
@@ -219,10 +219,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, r = grub_efi_system_table->runtime_services; - status =efi_call_5 (r->set_variable, var16, guid, - (GRUB_EFI_VARIABLE_NON_VOLATILE - |GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS - |GRUB_EFI_VARIABLE_RUNTIME_ACCESS ), + status =efi_call_5 (r->set_variable, var16, guid, attributes, datasize, data);grub_free (var16);if (status ==GRUB_EFI_SUCCESS )
@@ -231,6 +228,16 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,return grub_error (GRUB_ERR_IO ,"could not set EFI variable `%s'" , var); } +grub_err_t +grub_efi_set_variable (const char *var,const grub_efi_guid_t *guid, +void *data,grub_size_t datasize) +{ +return grub_efi_set_variable_with_attributes (var, guid, data, datasize, +GRUB_EFI_VARIABLE_NON_VOLATILE + |GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS + |GRUB_EFI_VARIABLE_RUNTIME_ACCESS ); +} + grub_efi_status_t grub_efi_get_variable_with_attributes (const char *var, const grub_efi_guid_t *guid,
include/grub/efi/efi.h +6 -0
@@ -98,6 +98,12 @@ grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable, grub_size_t *datasize_out, void **data_out);grub_err_t +EXPORT_FUNC (grub_efi_set_variable_with_attributes ) (const char *var, +const grub_efi_guid_t *guid, +void *data, +grub_size_t datasize, +grub_efi_uint32_t attributes); +grub_err_t EXPORT_FUNC (grub_efi_set_variable) (const char *var, const grub_efi_guid_t *guid, void *data,
Signature · 1 line
2.39.2
PATCH v5 2/8 Unify GUID types
In reply to Oliver SteffenThere are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.
It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.
--- grub-core/commands/acpi.c | 4 +- grub-core/commands/efi/efifwsetup.c | 4 +- grub-core/commands/efi/loadbios.c | 14 +++--- grub-core/commands/efi/lsefi.c | 4 +- grub-core/commands/efi/lsefisystab.c | 4 +- grub-core/commands/efi/lssal.c | 4 +- grub-core/commands/efi/smbios.c | 12 +++--- grub-core/commands/efi/tpm.c | 6 +-- grub-core/commands/probe.c | 2 +- grub-core/disk/efi/efidisk.c | 4 +- grub-core/disk/ldm.c | 2 +- grub-core/efiemu/i386/pc/cfgtables.c | 6 +-- grub-core/efiemu/main.c | 4 +- grub-core/efiemu/runtime/efiemu.c | 14 +++--- grub-core/kern/efi/acpi.c | 12 +++--- grub-core/kern/efi/efi.c | 22 +++++----- grub-core/kern/efi/fdt.c | 2 +- grub-core/kern/efi/init.c | 2 +- grub-core/kern/efi/sb.c | 4 +- grub-core/loader/efi/fdt.c | 2 +- grub-core/loader/efi/linux.c | 4 +- grub-core/loader/i386/xnu.c | 4 +- grub-core/loader/ia64/efi/linux.c | 2 +- grub-core/net/drivers/efi/efinet.c | 4 +- grub-core/partmap/gpt.c | 4 +- grub-core/term/efi/console.c | 2 +- grub-core/term/efi/serial.c | 2 +- grub-core/video/efi_gop.c | 8 ++-- grub-core/video/efi_uga.c | 2 +- include/grub/efi/api.h | 64 ++++++++++------------------ include/grub/efi/efi.h | 16 +++---- include/grub/efiemu/efiemu.h | 10 ++--- include/grub/efiemu/runtime.h | 2 +- include/grub/gpt_partition.h | 13 +----- include/grub/types.h | 9 ++++ util/grub-install.c | 2 +- util/grub-probe.c | 2 +- 37 files changed, 130 insertions(+), 148 deletions(-)
grub-core/commands/acpi.c +2 -2
@@ -759,8 +759,8 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)#ifdef GRUB_MACHINE_EFI { -struct grub_efi_guid acpi =GRUB_EFI_ACPI_TABLE_GUID ; -struct grub_efi_guid acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ; +grub_guid_t acpi =GRUB_EFI_ACPI_TABLE_GUID ; +grub_guid_t acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ;efi_call_2 (grub_efi_system_table->boot_services->install_configuration_table, &acpi20,grub_acpi_get_rsdpv2 ());
grub-core/commands/efi/efifwsetup.c +2 -2
@@ -38,7 +38,7 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),grub_efi_uint64_t os_indications =GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI ;grub_err_t status;grub_size_t oi_size; -static grub_efi_guid_t global =GRUB_EFI_GLOBAL_VARIABLE_GUID ; +static grub_guid_t global =GRUB_EFI_GLOBAL_VARIABLE_GUID ;if (argc >=1 &&grub_strcmp (args[0 ],"--is-supported" ) ==0 )return !efifwsetup_is_supported ();
@@ -72,7 +72,7 @@ efifwsetup_is_supported (void) {grub_efi_uint64_t *os_indications_supported =NULL ;grub_size_t oi_size =0 ; -static grub_efi_guid_t global =GRUB_EFI_GLOBAL_VARIABLE_GUID ; +static grub_guid_t global =GRUB_EFI_GLOBAL_VARIABLE_GUID ;grub_efi_boolean_t ret =0 ; grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
grub-core/commands/efi/loadbios.c +7 -7
@@ -27,9 +27,9 @@GRUB_MOD_LICENSE ("GPLv3+" ); -static grub_efi_guid_t acpi_guid =GRUB_EFI_ACPI_TABLE_GUID ; -static grub_efi_guid_t acpi2_guid =GRUB_EFI_ACPI_20_TABLE_GUID ; -static grub_efi_guid_t smbios_guid =GRUB_EFI_SMBIOS_TABLE_GUID ; +static grub_guid_t acpi_guid =GRUB_EFI_ACPI_TABLE_GUID ; +static grub_guid_t acpi2_guid =GRUB_EFI_ACPI_20_TABLE_GUID ; +static grub_guid_t smbios_guid =GRUB_EFI_SMBIOS_TABLE_GUID ;#define EBDA_SEG_ADDR 0x40e#define LOW_MEM_ADDR 0x413
@@ -105,15 +105,15 @@ fake_bios_data (int use_rom) smbios =0 ;for (i =0 ; i < grub_efi_system_table->num_table_entries; i++) { -grub_efi_packed_guid_t *guid = +grub_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; -if (!grub_memcmp (guid, &acpi2_guid,sizeof (grub_efi_guid_t))) +if (!grub_memcmp (guid, &acpi2_guid,sizeof (grub_guid_t))) { acpi = grub_efi_system_table->configuration_table[i].vendor_table;grub_dprintf ("efi" ,"ACPI2: %p\n" , acpi); } -else if (!grub_memcmp (guid, &acpi_guid,sizeof (grub_efi_guid_t))) +else if (!grub_memcmp (guid, &acpi_guid,sizeof (grub_guid_t))) {void *t;
@@ -122,7 +122,7 @@ fake_bios_data (int use_rom) acpi = t;grub_dprintf ("efi" ,"ACPI: %p\n" , t); } -else if (!grub_memcmp (guid, &smbios_guid,sizeof (grub_efi_guid_t))) +else if (!grub_memcmp (guid, &smbios_guid,sizeof (grub_guid_t))) { smbios = grub_efi_system_table->configuration_table[i].vendor_table;grub_dprintf ("efi" ,"SMBIOS: %p\n" , smbios);
grub-core/commands/efi/lsefi.c +2 -2
@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+");struct known_protocol { -grub_efi_guid_t guid; +grub_guid_t guid;const char *name; } known_protocols[] = {
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),grub_efi_handle_t handle = handles[i];grub_efi_status_t status;grub_efi_uintn_t num_protocols; -grub_efi_packed_guid_t **protocols; +grub_guid_t **protocols;grub_efi_device_path_t *dp;grub_printf ("Handle %p\n" , handle);
grub-core/commands/efi/lsefisystab.c +2 -2
@@ -29,7 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");struct guid_mapping { -grub_efi_guid_t guid; +grub_guid_t guid;const char *name; };
@@ -104,7 +104,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),for (j =0 ; j <ARRAY_SIZE (guid_mappings); j++)if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid, -sizeof (grub_efi_guid_t)) ==0 ) +sizeof (grub_guid_t)) ==0 )grub_printf (" %s" , guid_mappings[j].name);grub_printf ("\n" );
grub-core/commands/efi/lssal.c +2 -2
@@ -139,12 +139,12 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),const grub_efi_system_table_t *st = grub_efi_system_table;grub_efi_configuration_table_t *t = st->configuration_table;unsigned int i; -grub_efi_packed_guid_t guid =GRUB_EFI_SAL_TABLE_GUID ; +grub_guid_t guid =GRUB_EFI_SAL_TABLE_GUID ;for (i =0 ; i < st->num_table_entries; i++) {if (grub_memcmp (&guid, &t->vendor_guid, -sizeof (grub_efi_packed_guid_t)) ==0 ) +sizeof (grub_guid_t)) ==0 ) {disp_sal (t->vendor_table);return GRUB_ERR_NONE ;
grub-core/commands/efi/smbios.c +6 -6
@@ -26,14 +26,14 @@ struct grub_smbios_eps *grub_machine_smbios_get_eps (void) {unsigned i; -static grub_efi_packed_guid_t smbios_guid =GRUB_EFI_SMBIOS_TABLE_GUID ; +static grub_guid_t smbios_guid =GRUB_EFI_SMBIOS_TABLE_GUID ;for (i =0 ; i < grub_efi_system_table->num_table_entries; i++) { -grub_efi_packed_guid_t *guid = +grub_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; -if (!grub_memcmp (guid, &smbios_guid,sizeof (grub_efi_packed_guid_t))) +if (!grub_memcmp (guid, &smbios_guid,sizeof (grub_guid_t)))return (struct grub_smbios_eps *) grub_efi_system_table->configuration_table[i].vendor_table; }
@@ -45,14 +45,14 @@ struct grub_smbios_eps3 *grub_machine_smbios_get_eps3 (void) {unsigned i; -static grub_efi_packed_guid_t smbios3_guid =GRUB_EFI_SMBIOS3_TABLE_GUID ; +static grub_guid_t smbios3_guid =GRUB_EFI_SMBIOS3_TABLE_GUID ;for (i =0 ; i < grub_efi_system_table->num_table_entries; i++) { -grub_efi_packed_guid_t *guid = +grub_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; -if (!grub_memcmp (guid, &smbios3_guid,sizeof (grub_efi_packed_guid_t))) +if (!grub_memcmp (guid, &smbios3_guid,sizeof (grub_guid_t)))return (struct grub_smbios_eps3 *) grub_efi_system_table->configuration_table[i].vendor_table; }
grub-core/commands/efi/tpm.c +3 -3
@@ -30,9 +30,9 @@typedef TCG_PCR_EVENT grub_tpm_event_t ; -static grub_efi_guid_t tpm_guid =EFI_TPM_GUID ; -static grub_efi_guid_t tpm2_guid =EFI_TPM2_GUID ; -static grub_efi_guid_t cc_measurement_guid =GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID ; +static grub_guid_t tpm_guid =EFI_TPM_GUID ; +static grub_guid_t tpm2_guid =EFI_TPM2_GUID ; +static grub_guid_t cc_measurement_guid =GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID ;static grub_efi_handle_t *grub_tpm_handle;static grub_uint8_t grub_tpm_version;
grub-core/commands/probe.c +1 -1
@@ -119,7 +119,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)if (grub_strcmp (dev->disk->partition->partmap->name,"gpt" ) ==0 ) {struct grub_gpt_partentry entry; -grub_gpt_part_guid_t *guid; +grub_guid_t *guid;if (grub_disk_read (disk, p->offset, p->index,sizeof (entry), &entry)) {
grub-core/disk/efi/efidisk.c +2 -2
@@ -37,7 +37,7 @@ struct grub_efidisk_data };/* GUID. */ -static grub_efi_guid_t block_io_guid =GRUB_EFI_BLOCK_IO_GUID ; +static grub_guid_t block_io_guid =GRUB_EFI_BLOCK_IO_GUID ;static struct grub_efidisk_data *fd_devices;static struct grub_efidisk_data *hd_devices;
@@ -319,7 +319,7 @@ name_devices (struct grub_efidisk_data *devices) == GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE) { grub_efi_vendor_device_path_t *vendor = (grub_efi_vendor_device_path_t *) dp; - const struct grub_efi_guid apple = GRUB_EFI_VENDOR_APPLE_GUID; + const grub_guid_t apple = GRUB_EFI_VENDOR_APPLE_GUID; if (vendor->header.length == sizeof (*vendor) && grub_memcmp (&vendor->vendor_guid, &apple,
grub-core/disk/ldm.c +1 -1
@@ -136,7 +136,7 @@ msdos_has_ldm_partition (grub_disk_t dsk)return has_ldm; } -static const grub_gpt_part_guid_t ldm_type =GRUB_GPT_PARTITION_TYPE_LDM ; +static const grub_guid_t ldm_type =GRUB_GPT_PARTITION_TYPE_LDM ;/* Helper for gpt_ldm_sector. */ static int
grub-core/efiemu/i386/pc/cfgtables.c +3 -3
@@ -29,9 +29,9 @@ grub_machine_efiemu_init_tables (void) {void *table;grub_err_t err; -static grub_efi_guid_t smbios =GRUB_EFI_SMBIOS_TABLE_GUID ; -static grub_efi_guid_t acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ; -static grub_efi_guid_t acpi =GRUB_EFI_ACPI_TABLE_GUID ; +static grub_guid_t smbios =GRUB_EFI_SMBIOS_TABLE_GUID ; +static grub_guid_t acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ; +static grub_guid_t acpi =GRUB_EFI_ACPI_TABLE_GUID ; err =grub_efiemu_unregister_configuration_table (smbios);if (err)
grub-core/efiemu/main.c +2 -2
@@ -80,7 +80,7 @@ grub_efiemu_unload (void)/* Remove previously registered table from the list */ grub_err_t -grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid) +grub_efiemu_unregister_configuration_table (grub_guid_t guid) {struct grub_efiemu_configuration_table *cur, *prev;
@@ -136,7 +136,7 @@ grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),or with a hook */ grub_err_t -grub_efiemu_register_configuration_table (grub_efi_guid_t guid, +grub_efiemu_register_configuration_table (grub_guid_t guid,void * (*get_table) (void *data),void (*unload) (void *data),void *data)
grub-core/efiemu/runtime/efiemu.c +7 -7
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,grub_efi_status_t efiemu_get_variable (grub_efi_char16_t *variable_name, -const grub_efi_guid_t *vendor_guid, +const grub_guid_t *vendor_guid,grub_efi_uint32_t *attributes,grub_efi_uintn_t *data_size,void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,grub_efi_status_t efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,grub_efi_char16_t *variable_name, -grub_efi_guid_t *vendor_guid); +grub_guid_t *vendor_guid);grub_efi_status_t efiemu_set_variable (grub_efi_char16_t *variable_name, -const grub_efi_guid_t *vendor_guid, +const grub_guid_t *vendor_guid,grub_efi_uint32_t attributes,grub_efi_uintn_t data_size,void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,/* Find variable by name and GUID. */ static struct efi_variable * -find_variable (const grub_efi_guid_t *vendor_guid, +find_variable (const grub_guid_t *vendor_guid,grub_efi_char16_t *variable_name) {grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_efi_guid_t *vendor_guid,grub_efi_status_t EFI_FUNC (efiemu_get_variable ) (grub_efi_char16_t *variable_name, -const grub_efi_guid_t *vendor_guid, +const grub_guid_t *vendor_guid,grub_efi_uint32_t *attributes,grub_efi_uintn_t *data_size,void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,grub_efi_status_t EFI_FUNC (efiemu_get_next_variable_name ) (grub_efi_uintn_t *variable_name_size,grub_efi_char16_t *variable_name, -grub_efi_guid_t *vendor_guid) +grub_guid_t *vendor_guid) {struct efi_variable *efivar;LOG ('l' );
@@ -503,7 +503,7 @@ grub_efi_status_t EFI_FUNCgrub_efi_status_t EFI_FUNC (efiemu_set_variable ) (grub_efi_char16_t *variable_name, -const grub_efi_guid_t *vendor_guid, +const grub_guid_t *vendor_guid,grub_efi_uint32_t attributes,grub_efi_uintn_t data_size,void *data)
grub-core/kern/efi/acpi.c +6 -6
@@ -26,14 +26,14 @@ struct grub_acpi_rsdp_v10 *grub_machine_acpi_get_rsdpv1 (void) {unsigned i; -static grub_efi_packed_guid_t acpi_guid =GRUB_EFI_ACPI_TABLE_GUID ; +static grub_guid_t acpi_guid =GRUB_EFI_ACPI_TABLE_GUID ;for (i =0 ; i < grub_efi_system_table->num_table_entries; i++) { -grub_efi_packed_guid_t *guid = +grub_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; -if (!grub_memcmp (guid, &acpi_guid,sizeof (grub_efi_packed_guid_t))) +if (!grub_memcmp (guid, &acpi_guid,sizeof (grub_guid_t)))return (struct grub_acpi_rsdp_v10 *) grub_efi_system_table->configuration_table[i].vendor_table; }
@@ -44,14 +44,14 @@ struct grub_acpi_rsdp_v20 *grub_machine_acpi_get_rsdpv2 (void) {unsigned i; -static grub_efi_packed_guid_t acpi20_guid =GRUB_EFI_ACPI_20_TABLE_GUID ; +static grub_guid_t acpi20_guid =GRUB_EFI_ACPI_20_TABLE_GUID ;for (i =0 ; i < grub_efi_system_table->num_table_entries; i++) { -grub_efi_packed_guid_t *guid = +grub_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; -if (!grub_memcmp (guid, &acpi20_guid,sizeof (grub_efi_packed_guid_t))) +if (!grub_memcmp (guid, &acpi20_guid,sizeof (grub_guid_t)))return (struct grub_acpi_rsdp_v20 *) grub_efi_system_table->configuration_table[i].vendor_table; }
grub-core/kern/efi/efi.c +11 -11
@@ -35,12 +35,12 @@ grub_efi_handle_t grub_efi_image_handle;/* The pointer to a system table. Filled in by the startup code. */ grub_efi_system_table_t *grub_efi_system_table; -static grub_efi_guid_t console_control_guid =GRUB_EFI_CONSOLE_CONTROL_GUID ; -static grub_efi_guid_t loaded_image_guid =GRUB_EFI_LOADED_IMAGE_GUID ; -static grub_efi_guid_t device_path_guid =GRUB_EFI_DEVICE_PATH_GUID ; +static grub_guid_t console_control_guid =GRUB_EFI_CONSOLE_CONTROL_GUID ; +static grub_guid_t loaded_image_guid =GRUB_EFI_LOADED_IMAGE_GUID ; +static grub_guid_t device_path_guid =GRUB_EFI_DEVICE_PATH_GUID ;void * -grub_efi_locate_protocol (grub_efi_guid_t *protocol,void *registration) +grub_efi_locate_protocol (grub_guid_t *protocol,void *registration) {void *interface;grub_efi_status_t status;
@@ -58,7 +58,7 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)from the heap. */ grub_efi_handle_t *grub_efi_locate_handle (grub_efi_locate_search_type_t search_type, -grub_efi_guid_t *protocol, +grub_guid_t *protocol,void *search_key,grub_efi_uintn_t *num_handles) {
@@ -97,7 +97,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,void *grub_efi_open_protocol (grub_efi_handle_t handle, -grub_efi_guid_t *protocol, +grub_guid_t *protocol,grub_efi_uint32_t attributes) {grub_efi_boot_services_t *b;
@@ -118,7 +118,7 @@ grub_efi_open_protocol (grub_efi_handle_t handle, }grub_efi_status_t -grub_efi_close_protocol (grub_efi_handle_t handle,grub_efi_guid_t *protocol) +grub_efi_close_protocol (grub_efi_handle_t handle,grub_guid_t *protocol) {grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
@@ -201,7 +201,7 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size, }grub_err_t -grub_efi_set_variable_with_attributes (const char *var,const grub_efi_guid_t *guid, +grub_efi_set_variable_with_attributes (const char *var,const grub_guid_t *guid,void *data,grub_size_t datasize,grub_efi_uint32_t attributes) {grub_efi_status_t status;
@@ -229,7 +229,7 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *g }grub_err_t -grub_efi_set_variable (const char *var,const grub_efi_guid_t *guid, +grub_efi_set_variable (const char *var,const grub_guid_t *guid,void *data,grub_size_t datasize) { return grub_efi_set_variable_with_attributes (var, guid, data, datasize,
@@ -240,7 +240,7 @@ grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,grub_efi_status_t grub_efi_get_variable_with_attributes (const char *var, -const grub_efi_guid_t *guid, +const grub_guid_t *guid,grub_size_t *datasize_out,void **data_out,grub_efi_uint32_t *attributes)
@@ -295,7 +295,7 @@ grub_efi_get_variable_with_attributes (const char *var, }grub_efi_status_t -grub_efi_get_variable (const char *var,const grub_efi_guid_t *guid, +grub_efi_get_variable (const char *var,const grub_guid_t *guid,grub_size_t *datasize_out,void **data_out) {return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out,NULL );
grub-core/kern/efi/fdt.c +1 -1
@@ -24,7 +24,7 @@ void *grub_efi_get_firmware_fdt (void) {grub_efi_configuration_table_t *tables; -static grub_efi_guid_t fdt_guid =GRUB_EFI_DEVICE_TREE_GUID ; +static grub_guid_t fdt_guid =GRUB_EFI_DEVICE_TREE_GUID ;void *firmware_fdt =NULL ;unsigned int i;
grub-core/kern/efi/init.c +1 -1
@@ -36,7 +36,7 @@ static grub_efi_char16_t stack_chk_fail_msg[] =L"* GRUB: ABORTED!!! *\r\n" L"* GRUB: REBOOTING IN 5 SECONDS... *\r\n" ; -static grub_efi_guid_t rng_protocol_guid =GRUB_EFI_RNG_PROTOCOL_GUID ; +static grub_guid_t rng_protocol_guid =GRUB_EFI_RNG_PROTOCOL_GUID ;/* * Don't put this on grub_efi_init()'s local stack to avoid it
grub-core/kern/efi/sb.c +2 -2
@@ -30,7 +30,7 @@#include <grub/types.h> #include <grub/verify.h> -static grub_efi_guid_t shim_lock_guid =GRUB_EFI_SHIM_LOCK_GUID ; +static grub_guid_t shim_lock_guid =GRUB_EFI_SHIM_LOCK_GUID ;/* * Determine whether we're in secure boot mode.
@@ -41,7 +41,7 @@ static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;grub_uint8_t grub_efi_get_secureboot (void ) { -static grub_efi_guid_t efi_variable_guid =GRUB_EFI_GLOBAL_VARIABLE_GUID ; +static grub_guid_t efi_variable_guid =GRUB_EFI_GLOBAL_VARIABLE_GUID ;grub_efi_status_t status;grub_efi_uint32_t attr =0 ;grub_size_t size =0 ;
grub-core/loader/efi/fdt.c +1 -1
@@ -86,7 +86,7 @@ grub_err_tgrub_fdt_install (void) {grub_efi_boot_services_t *b; -static grub_efi_guid_t fdt_guid =GRUB_EFI_DEVICE_TREE_GUID ; +static grub_guid_t fdt_guid =GRUB_EFI_DEVICE_TREE_GUID ;grub_efi_status_t status;if (fdt ==NULL && loaded_fdt ==NULL )
grub-core/loader/efi/linux.c +2 -2
@@ -51,8 +51,8 @@ static struct grub_linux_initrd_context initrd_ctx = {0, 0, 0};static grub_efi_handle_t initrd_lf2_handle =NULL ;static bool initrd_use_loadfile2 = false; -static grub_efi_guid_t load_file2_guid =GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID ; -static grub_efi_guid_t device_path_guid =GRUB_EFI_DEVICE_PATH_GUID ; +static grub_guid_t load_file2_guid =GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID ; +static grub_guid_t device_path_guid =GRUB_EFI_DEVICE_PATH_GUID ;static initrd_media_device_path_t initrd_lf2_device_path = { {
grub-core/loader/i386/xnu.c +2 -2
@@ -48,7 +48,7 @@ grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;/* Aliases set for some tables. */ struct tbl_alias { -grub_efi_guid_t guid; +grub_guid_t guid;const char *name; };
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out) {void *ptr;struct grub_xnu_devtree_key *curkey; -grub_efi_packed_guid_t guid; +grub_guid_t guid;char guidbuf[64 ];/* Retrieve current key. */
grub-core/loader/ia64/efi/linux.c +1 -1
@@ -106,7 +106,7 @@ query_fpswa (void)grub_efi_boot_services_t *bs;grub_efi_status_t status;grub_efi_uintn_t size; -static const grub_efi_guid_t fpswa_protocol = +static const grub_guid_t fpswa_protocol = {0xc41b6531 ,0x97b9 ,0x11d3 , {0x9a ,0x29 ,0x0 ,0x90 ,0x27 ,0x3f ,0xc1 ,0x4d } };
grub-core/net/drivers/efi/efinet.c +2 -2
@@ -27,8 +27,8 @@GRUB_MOD_LICENSE ("GPLv3+" );/* GUID. */ -static grub_efi_guid_t net_io_guid =GRUB_EFI_SIMPLE_NETWORK_GUID ; -static grub_efi_guid_t pxe_io_guid =GRUB_EFI_PXE_GUID ; +static grub_guid_t net_io_guid =GRUB_EFI_SIMPLE_NETWORK_GUID ; +static grub_guid_t pxe_io_guid =GRUB_EFI_PXE_GUID ; static grub_err_t send_card_buffer (struct grub_net_card *dev,
grub-core/partmap/gpt.c +2 -2
@@ -36,10 +36,10 @@ static grub_uint8_t grub_gpt_magic[8] = 0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54 }; -static const grub_gpt_part_guid_t grub_gpt_partition_type_empty =GRUB_GPT_PARTITION_TYPE_EMPTY ; +static const grub_guid_t grub_gpt_partition_type_empty =GRUB_GPT_PARTITION_TYPE_EMPTY ;#ifdef GRUB_UTIL -static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot =GRUB_GPT_PARTITION_TYPE_BIOS_BOOT ; +static const grub_guid_t grub_gpt_partition_type_bios_boot =GRUB_GPT_PARTITION_TYPE_BIOS_BOOT ;#endif /* 512 << 7 = 65536 byte sectors. */
grub-core/term/efi/console.c +1 -1
@@ -353,7 +353,7 @@ grub_console_getkeystatus (struct grub_term_input *term)static grub_err_t grub_efi_console_input_init (struct grub_term_input *term) { -static grub_efi_guid_t text_input_ex_guid = +static grub_guid_t text_input_ex_guid =GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID ;if (grub_efi_is_finished)
grub-core/term/efi/serial.c +1 -1
@@ -31,7 +31,7 @@#include <grub/i18n.h> /* GUID. */ -static grub_efi_guid_t serial_io_guid =GRUB_EFI_SERIAL_IO_GUID ; +static grub_guid_t serial_io_guid =GRUB_EFI_SERIAL_IO_GUID ;static void do_real_config (struct grub_serial_port *port)
grub-core/video/efi_gop.c +4 -4
@@ -32,10 +32,10 @@GRUB_MOD_LICENSE ("GPLv3+" ); -static grub_efi_guid_t graphics_output_guid =GRUB_EFI_GOP_GUID ; -static grub_efi_guid_t active_edid_guid =GRUB_EFI_EDID_ACTIVE_GUID ; -static grub_efi_guid_t discovered_edid_guid =GRUB_EFI_EDID_DISCOVERED_GUID ; -static grub_efi_guid_t efi_var_guid =GRUB_EFI_GLOBAL_VARIABLE_GUID ; +static grub_guid_t graphics_output_guid =GRUB_EFI_GOP_GUID ; +static grub_guid_t active_edid_guid =GRUB_EFI_EDID_ACTIVE_GUID ; +static grub_guid_t discovered_edid_guid =GRUB_EFI_EDID_DISCOVERED_GUID ; +static grub_guid_t efi_var_guid =GRUB_EFI_GLOBAL_VARIABLE_GUID ;static struct grub_efi_gop *gop;static unsigned old_mode;static int restore_needed;
grub-core/video/efi_uga.c +1 -1
@@ -32,7 +32,7 @@GRUB_MOD_LICENSE ("GPLv3+" ); -static grub_efi_guid_t uga_draw_guid =GRUB_EFI_UGA_DRAW_GUID ; +static grub_guid_t uga_draw_guid =GRUB_EFI_UGA_DRAW_GUID ;static struct grub_efi_uga_draw_protocol *uga;static grub_uint64_t uga_fb;static grub_uint32_t uga_pitch;
include/grub/efi/api.h +23 -41
191 lines not on this page · raw message
include/grub/efi/efi.h +8 -8
@@ -37,18 +37,18 @@ struct linux_arch_kernel_header { };/* Functions. */ -void *EXPORT_FUNC (grub_efi_locate_protocol ) (grub_efi_guid_t *protocol, +void *EXPORT_FUNC (grub_efi_locate_protocol ) (grub_guid_t *protocol,void *registration);grub_efi_handle_t *EXPORT_FUNC (grub_efi_locate_handle ) (grub_efi_locate_search_type_t search_type, -grub_efi_guid_t *protocol, +grub_guid_t *protocol,void *search_key,grub_efi_uintn_t *num_handles);void *EXPORT_FUNC (grub_efi_open_protocol ) (grub_efi_handle_t handle, -grub_efi_guid_t *protocol, +grub_guid_t *protocol,grub_efi_uint32_t attributes);grub_efi_status_t -EXPORT_FUNC (grub_efi_close_protocol ) (grub_efi_handle_t handle,grub_efi_guid_t *protocol); +EXPORT_FUNC (grub_efi_close_protocol ) (grub_efi_handle_t handle,grub_guid_t *protocol);int EXPORT_FUNC (grub_efi_set_text_mode ) (int on);void EXPORT_FUNC (grub_efi_stall ) (grub_efi_uintn_t microseconds); void *
@@ -89,23 +89,23 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memogrub_efi_uint32_t descriptor_version, grub_efi_memory_descriptor_t *virtual_map);grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes ) (const char *variable, -const grub_efi_guid_t *guid, +const grub_guid_t *guid,grub_size_t *datasize_out,void **data_out,grub_efi_uint32_t *attributes);grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable ) (const char *variable, -const grub_efi_guid_t *guid, +const grub_guid_t *guid,grub_size_t *datasize_out,void **data_out);grub_err_t EXPORT_FUNC (grub_efi_set_variable_with_attributes ) (const char *var, -const grub_efi_guid_t *guid, +const grub_guid_t *guid,void *data,grub_size_t datasize,grub_efi_uint32_t attributes);grub_err_t EXPORT_FUNC (grub_efi_set_variable ) (const char *var, -const grub_efi_guid_t *guid, +const grub_guid_t *guid,void *data,grub_size_t datasize);int
include/grub/efiemu/efiemu.h +5 -5
@@ -176,26 +176,26 @@ grub_err_t grub_efiemu_loadcore_load (void);struct grub_efiemu_configuration_table {struct grub_efiemu_configuration_table *next; -grub_efi_guid_t guid; +grub_guid_t guid;void * (*get_table) (void *data);void (*unload) (void *data);void *data; };struct grub_efiemu_configuration_table32 { -grub_efi_packed_guid_t vendor_guid; +grub_guid_t vendor_guid;grub_efi_uint32_t vendor_table; }GRUB_PACKED ;typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t ;struct grub_efiemu_configuration_table64 { -grub_efi_packed_guid_t vendor_guid; +grub_guid_t vendor_guid;grub_efi_uint64_t vendor_table; }GRUB_PACKED ;typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t ; -grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid); +grub_err_t grub_efiemu_unregister_configuration_table (grub_guid_t guid);grub_err_t -grub_efiemu_register_configuration_table (grub_efi_guid_t guid, +grub_efiemu_register_configuration_table (grub_guid_t guid,void * (*get_table) (void *data),void (*unload) (void *data),void *data);
include/grub/efiemu/runtime.h +1 -1
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_relstruct efi_variable { -grub_efi_packed_guid_t guid; +grub_guid_t guid;grub_uint32_t namelen;grub_uint32_t size;grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +2 -11
@@ -22,15 +22,6 @@#include <grub/types.h> #include <grub/partition.h> -struct grub_gpt_part_guid -{ -grub_uint32_t data1; -grub_uint16_t data2; -grub_uint16_t data3; -grub_uint8_t data4[8 ]; -}GRUB_PACKED ; -typedef struct grub_gpt_part_guid grub_gpt_part_guid_t ; -#define GRUB_GPT_PARTITION_TYPE_EMPTY \ { 0x0, 0x0, 0x0, \ { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
@@ -70,8 +61,8 @@ struct grub_gpt_headerstruct grub_gpt_partentry { -grub_gpt_part_guid_t type; -grub_gpt_part_guid_t guid; +grub_guid_t type; +grub_guid_t guid;grub_uint64_t start;grub_uint64_t end;grub_uint64_t attrib;
include/grub/types.h +9 -0
@@ -365,4 +365,13 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)# define grub_absolute_pointer (val) ((void *) (val))#endif +struct grub_guid +{ +grub_uint32_t data1; +grub_uint16_t data2; +grub_uint16_t data3; +grub_uint8_t data4[8 ]; +}GRUB_PACKED ; +typedef struct grub_guid grub_guid_t ; +#endif /* ! GRUB_TYPES_HEADER */
util/grub-install.c +1 -1
@@ -725,7 +725,7 @@ is_prep_partition (grub_device_t dev)if (grub_disk_read (dev->disk, p->offset, p->index,sizeof (gptdata), &gptdata) ==0 ) { -const grub_gpt_part_guid_t template = { +const grub_guid_t template = {grub_cpu_to_le32_compile_time (0x9e1a2d38 ),grub_cpu_to_le16_compile_time (0xc612 ),grub_cpu_to_le16_compile_time (0x4316 ),
util/grub-probe.c +1 -1
@@ -133,7 +133,7 @@ get_targets_string (void) }static int -print_gpt_guid (grub_gpt_part_guid_t guid) +print_gpt_guid (grub_guid_t guid) { guid.data1 =grub_le_to_cpu32 (guid.data1); guid.data2 =grub_le_to_cpu16 (guid.data2);
Signature · 1 line
2.39.2
Re: [PATCH v5 2/8] Unify GUID types
Quoted 7 lines · Oliver Steffen
There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in
types.h.It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.
Signed-off-by Oliver Steffen <[email protected]>
But one nit below...
grub-core/commands/acpi.c grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) · line 763
Quoted 12 lines
grub-core/commands/acpi.c +2
-2@@ -759,8 +759,8 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)#ifdef GRUB_MACHINE_EFI { -struct grub_efi_guid acpi =GRUB_EFI_ACPI_TABLE_GUID ; -struct grub_efi_guid acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ; +grub_guid_t acpi =GRUB_EFI_ACPI_TABLE_GUID ; +grub_guid_t acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ;
I would add static for these two variables.
Daniel
PATCH v5 3/8 kern/misc: Add a format specifier GUIDs.
In reply to Oliver SteffenExtend the printf format specifier for pointers (%p) to accept a suffix specifier G to print GUIDs: %pG can be used to print grub_guid structs. This does not interfere with the -Wformat checking of gcc. Note that the data type is not checked though (%p accepts void*).
--- grub-core/kern/misc.c | 86 ++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 21 deletions(-)
grub-core/kern/misc.c +65 -21
@@ -24,6 +24,7 @@#include <grub/term.h> #include <grub/env.h> #include <grub/i18n.h> +#include <grub/types.h> union printf_arg {
@@ -34,7 +35,8 @@ union printf_arg {INT ,LONG ,LONGLONG ,UNSIGNED_INT =3 ,UNSIGNED_LONG ,UNSIGNED_LONGLONG , - STRING +STRING , + GUID } type;long long ll; };
@@ -772,6 +774,9 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,switch (c) {case 'p' : +if (*(fmt) =='G' ) + ++fmt; +/* Fall through. */ case 'x' :case 'X' :case 'u' :
@@ -885,6 +890,10 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, args->ptr[curn].type =UNSIGNED_LONGLONG ; else args->ptr[curn].type = UNSIGNED_INT; +if (*(fmt) =='G' ) { + args->ptr[curn].type =GUID ; + ++fmt; + }break ;case 's' : args->ptr[curn].type =STRING ;
@@ -931,6 +940,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in)else args->ptr[n].ll = va_arg (args_in, unsigned int);break ; +case GUID : +if (sizeof (void *) ==sizeof (long long )) + args->ptr[n].ll = va_arg (args_in, long long); +else + args->ptr[n].ll = va_arg (args_in, unsigned int); +break ; } }
@@ -943,6 +958,27 @@ write_char (char *str, grub_size_t *count, grub_size_t max_len, unsigned char ch (*count)++; } +static void +write_number (char *str,grub_size_t *count,grub_size_t max_len,grub_size_t format1, +char rightfill,char zerofill,char c,long long value) +{ +char tmp[32 ]; +const char *p = tmp; +grub_size_t len; +grub_size_t fill; + + len =grub_lltoa (tmp, c, value) - tmp; + fill = len < format1 ? format1 - len :0 ; +if (! rightfill) +while (fill--) +write_char (str, count, max_len, zerofill); +while (*p) +write_char (str, count, max_len, *p++); +if (rightfill) +while (fill--) +write_char (str, count, max_len, zerofill); +} +static int grub_vsnprintf_real (char *str,grub_size_t max_len,const char *fmt0,struct printf_args *args)
@@ -1025,31 +1061,39 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,switch (c) {case 'p' : -write_char (str, &count, max_len,'0' ); -write_char (str, &count, max_len,'x' ); - c ='x' ; +if (*(fmt) =='G' ) + { + ++fmt; +grub_guid_t *guid = (grub_guid_t *) curarg; +write_number (str, &count, max_len,8 ,0 ,'0' ,'x' ,grub_le_to_cpu32 (guid->data1)); +write_char (str, &count, max_len,'-' ); +write_number (str, &count, max_len,4 ,0 ,'0' ,'x' ,grub_le_to_cpu16 (guid->data2)); +write_char (str, &count, max_len,'-' ); +write_number (str, &count, max_len,4 ,0 ,'0' ,'x' ,grub_le_to_cpu16 (guid->data3)); +write_char (str, &count, max_len,'-' ); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[0 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[1 ]); +write_char (str, &count, max_len,'-' ); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[2 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[3 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[4 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[5 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[6 ]); +write_number (str, &count, max_len,2 ,0 ,'0' ,'x' , guid->data4[7 ]); +break ; + } +else + { +write_char (str, &count, max_len,'0' ); +write_char (str, &count, max_len,'x' ); + c ='x' ; + }/* Fall through. */ case 'x' :case 'X' :case 'u' :case 'd' : - { -char tmp[32 ]; -const char *p = tmp; -grub_size_t len; -grub_size_t fill; - - len =grub_lltoa (tmp, c, curarg) - tmp; - fill = len < format1 ? format1 - len :0 ; -if (! rightfill) -while (fill--) -write_char (str, &count, max_len, zerofill); -while (*p) -write_char (str, &count, max_len, *p++); -if (rightfill) -while (fill--) -write_char (str, &count, max_len, zerofill); - } +write_number (str, &count, max_len, format1, rightfill, zerofill, c, curarg);break ;case 'c' :
Signature · 1 line
2.39.2
Re: [PATCH v5 3/8] kern/misc: Add a format specifier GUIDs.
Quoted 54 lines · Oliver Steffen
Extend the printf format specifier for pointers (%p) to accept a suffix specifier G to print GUIDs: %pG can be used to print
grub_guidstructs. This does not interfere with the -Wformat checking of gcc. Note that the data type is not checked though (%p accepts void*).Signed-off-by Oliver Steffen <[email protected]>--- grub-core/kern/misc.c | 86 ++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 21 deletions(-)grub-core/kern/misc.c +10
-1@@ -24,6 +24,7 @@#include <grub/term.h> #include <grub/env.h> #include <grub/i18n.h> +#include <grub/types.h> union printf_arg {@@ -34,7 +35,8 @@ union printf_arg {INT ,LONG ,LONGLONG ,UNSIGNED_INT =3 ,UNSIGNED_LONG ,UNSIGNED_LONGLONG , - STRING +STRING , + GUID } type;long long ll; };@@ -772,6 +774,9 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,switch (c) {case 'p' : +if (*(fmt) =='G' ) + ++fmt; +/* Fall through. */ case 'x' :case 'X' :case 'u' :@@ -885,6 +890,10 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args, args->ptr[curn].type =UNSIGNED_LONGLONG ; else args->ptr[curn].type = UNSIGNED_INT; +if (*(fmt) =='G' ) { + args->ptr[curn].type =GUID ; + ++fmt; + }break ;case 's' : args->ptr[curn].type =STRING ;
grub-core/kern/misc.c parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in) · line 948
Quoted 9 lines
grub-core/kern/misc.c +6
-0@@ -931,6 +940,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in)else args->ptr[n].ll = va_arg (args_in, unsigned int);break ; +case GUID : +if (sizeof (void *) ==sizeof (long long )) + args->ptr[n].ll = va_arg (args_in, long long); +else + args->ptr[n].ll = va_arg (args_in, unsigned int); +break ;
You duplicate code for the STRING. Why not
case STRING:
case GUID: ?
Daniel
PATCH v5 4/8 grub-core: Make use of guid printf format specifier
In reply to Oliver SteffenUse the new printf format specifier %pG.
Fixes the text representation of GUIDs in the output of the lsefisystab command.
--- grub-core/commands/efi/lsefi.c | 13 +------------ grub-core/commands/efi/lsefisystab.c | 6 +----- grub-core/commands/probe.c | 9 +-------- grub-core/kern/efi/efi.c | 28 ++-------------------------- grub-core/loader/i386/xnu.c | 9 ++------- 5 files changed, 7 insertions(+), 58 deletions(-)
grub-core/commands/efi/lsefi.c +1 -12
@@ -123,18 +123,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),if (k <ARRAY_SIZE (known_protocols))grub_printf (" %s\n" , known_protocols[k].name);else -grub_printf (" %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n" , - protocols[j]->data1, - protocols[j]->data2, - protocols[j]->data3, - (unsigned ) protocols[j]->data4[0 ], - (unsigned ) protocols[j]->data4[1 ], - (unsigned ) protocols[j]->data4[2 ], - (unsigned ) protocols[j]->data4[3 ], - (unsigned ) protocols[j]->data4[4 ], - (unsigned ) protocols[j]->data4[5 ], - (unsigned ) protocols[j]->data4[6 ], - (unsigned ) protocols[j]->data4[7 ]); +grub_printf (" %pG\n" , protocols[j]); } }
grub-core/commands/efi/lsefisystab.c +1 -5
@@ -96,11 +96,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),grub_printf ("%p " , t->vendor_table); -grub_printf ("%08x-%04x-%04x-" , - t->vendor_guid.data1, t->vendor_guid.data2, - t->vendor_guid.data3); -for (j =0 ; j <8 ; j++) -grub_printf ("%02x" , t->vendor_guid.data4[j]); +grub_printf ("%pG" , &t->vendor_guid);for (j =0 ; j <ARRAY_SIZE (guid_mappings); j++) if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
grub-core/commands/probe.c +1 -8
@@ -130,14 +130,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)return grub_errno; } guid = &entry.guid; -grub_snprintf (val,sizeof (val), -"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" , -grub_le_to_cpu32 (guid->data1), -grub_le_to_cpu16 (guid->data2), -grub_le_to_cpu16 (guid->data3), - guid->data4[0 ], guid->data4[1 ], guid->data4[2 ], - guid->data4[3 ], guid->data4[4 ], guid->data4[5 ], - guid->data4[6 ], guid->data4[7 ]); +grub_snprintf (val,sizeof (val),"%pG" , guid); }else if (grub_strcmp (dev->disk->partition->partmap->name,"msdos" ) ==0 ) {
grub-core/kern/efi/efi.c +2 -26
@@ -544,20 +544,7 @@ static void dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) { grub_uint32_t vendor_data_len = vendor->header.length - sizeof (*vendor); -grub_printf ("/%sVendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)[%x: " , - type, - (unsigned ) vendor->vendor_guid.data1, - (unsigned ) vendor->vendor_guid.data2, - (unsigned ) vendor->vendor_guid.data3, - (unsigned ) vendor->vendor_guid.data4[0 ], - (unsigned ) vendor->vendor_guid.data4[1 ], - (unsigned ) vendor->vendor_guid.data4[2 ], - (unsigned ) vendor->vendor_guid.data4[3 ], - (unsigned ) vendor->vendor_guid.data4[4 ], - (unsigned ) vendor->vendor_guid.data4[5 ], - (unsigned ) vendor->vendor_guid.data4[6 ], - (unsigned ) vendor->vendor_guid.data4[7 ], - vendor_data_len); +grub_printf ("/%sVendor(%pG)[%x: " , type, &vendor->vendor_guid, vendor_data_len);if (vendor->header.length >sizeof (*vendor)) {grub_uint32_t i;
@@ -928,18 +915,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) {grub_efi_protocol_device_path_t *proto = (grub_efi_protocol_device_path_t *) dp; -grub_printf ("/Protocol(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)" , - (unsigned ) proto->guid.data1, - (unsigned ) proto->guid.data2, - (unsigned ) proto->guid.data3, - (unsigned ) proto->guid.data4[0 ], - (unsigned ) proto->guid.data4[1 ], - (unsigned ) proto->guid.data4[2 ], - (unsigned ) proto->guid.data4[3 ], - (unsigned ) proto->guid.data4[4 ], - (unsigned ) proto->guid.data4[5 ], - (unsigned ) proto->guid.data4[6 ], - (unsigned ) proto->guid.data4[7 ]); +grub_printf ("/Protocol(%pG)" ,&proto->guid); }break ;default :
grub-core/loader/i386/xnu.c +2 -7
@@ -726,13 +726,8 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)#endif /* The name of key for new table. */ -grub_snprintf (guidbuf,sizeof (guidbuf),"%08x-%04x-%04x-%02x%02x-" , - guid.data1, guid.data2, guid.data3, guid.data4[0 ], - guid.data4[1 ]); -for (j =2 ; j <8 ; j++) -grub_snprintf (guidbuf +grub_strlen (guidbuf), -sizeof (guidbuf) -grub_strlen (guidbuf), -"%02x" , guid.data4[j]); +grub_snprintf (guidbuf,sizeof (guidbuf),"%pG" , &guid); +/* For some reason GUID has to be in uppercase. */ for (j =0 ; guidbuf[j] ; j++)if (guidbuf[j] >='a' && guidbuf[j] <='f' )
Signature · 1 line
2.39.2
PATCH v5 5/8 types.h: Add GRUB_SSIZE_MAX
In reply to Oliver SteffenIn the same way as GRUB_SIZE_MAX, add GRUB_SSIZE_MAX.
--- include/grub/types.h | 2 ++ 1 file changed, 2 insertions(+)
include/grub/types.h +2 -0
@@ -122,6 +122,7 @@ typedef grub_uint64_t grub_size_t;typedef grub_int64_t grub_ssize_t ;# define GRUB_SIZE_MAX 18446744073709551615UL +# define GRUB_SSIZE_MAX 9223372036854775807L# if GRUB_CPU_SIZEOF_LONG ==8 # define PRIxGRUB_SIZE "lx"
@@ -140,6 +141,7 @@ typedef grub_uint32_t grub_size_t;typedef grub_int32_t grub_ssize_t ;# define GRUB_SIZE_MAX 4294967295UL +# define GRUB_SSIZE_MAX 2147483647L# define PRIxGRUB_SIZE "x"# define PRIxGRUB_ADDR "x"
Signature · 1 line
2.39.2
PATCH v5 6/8 kern/misc, kern/efi: Extract UTF-8 to UTF-16 code
In reply to Oliver SteffenCreate a new function for UTF-8 to UTF-16 conversion called grub_utf8_to_utf16_alloc() in the grub-code/kern/misc.c and replace charset conversion code used in some places in the EFI code. It is modeled after the grub_utf8_to_ucs4_alloc() like functions in charset.h. It can't live in charset.h, because it needs to be reachable from the kern/efi code.
Add a check for integer overflow and remove redundant NUL-termination.
--- grub-core/kern/efi/efi.c | 21 ++++++--------------- grub-core/kern/misc.c | 32 ++++++++++++++++++++++++++++++++ include/grub/misc.h | 3 +++ 3 files changed, 41 insertions(+), 15 deletions(-)
grub-core/kern/efi/efi.c +6 -15
@@ -207,15 +207,11 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,grub_efi_status_t status;grub_efi_runtime_services_t *r;grub_efi_char16_t *var16; -grub_size_t len, len16; - len =grub_strlen (var); - len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; - var16 =grub_calloc (len16 +1 ,sizeof (var16[0 ])); -if (!var16) +grub_utf8_to_utf16_alloc (var, &var16,NULL ); + +if (var16 ==NULL )return grub_errno; - len16 =grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len,NULL ); - var16[len16] =0 ; r = grub_efi_system_table->runtime_services;
@@ -250,18 +246,13 @@ grub_efi_get_variable_with_attributes (const char *var,grub_efi_runtime_services_t *r;grub_efi_char16_t *var16;void *data; -grub_size_t len, len16; *data_out =NULL ; *datasize_out =0 ; - len =grub_strlen (var); - len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; - var16 =grub_calloc (len16 +1 ,sizeof (var16[0 ])); -if (!var16) -return GRUB_EFI_OUT_OF_RESOURCES ; - len16 =grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len,NULL ); - var16[len16] =0 ; +grub_utf8_to_utf16_alloc (var, &var16,NULL ); +if (var16 ==NULL ) +return grub_errno; r = grub_efi_system_table->runtime_services;
grub-core/kern/misc.c +32 -0
@@ -25,6 +25,7 @@#include <grub/env.h> #include <grub/i18n.h> #include <grub/types.h> +#include <grub/charset.h> union printf_arg {
@@ -1323,6 +1324,37 @@ grub_fatal (const char *fmt, ...)grub_abort (); } +grub_ssize_t +grub_utf8_to_utf16_alloc (const char *str8,grub_uint16_t **utf16_msg,grub_uint16_t **last_position) +{ +grub_size_t len; +grub_size_t len16; + + len =grub_strlen (str8); + +/* Check for integer overflow */ +if (len >GRUB_SSIZE_MAX /GRUB_MAX_UTF16_PER_UTF8 -1 ) + { +grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("string too large" )); + *utf16_msg =NULL ; +return -1 ; + } + + len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; + + *utf16_msg =grub_calloc (len16 +1 ,sizeof (*utf16_msg[0 ])); +if (*utf16_msg ==NULL ) +return -1 ; + + len16 =grub_utf8_to_utf16 (*utf16_msg, len16, (grub_uint8_t *) str8, len,NULL ); + +if (last_position) + *last_position = *utf16_msg + len16; + +return len16; +} + +#if BOOT_TIME_STATS #include <grub/time.h>
include/grub/misc.h +3 -0
@@ -529,4 +529,7 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file,#define grub_log2ull (n) (GRUB_TYPE_BITS (grub_uint64_t) - __builtin_clzll (n) - 1) +grub_ssize_t +EXPORT_FUNC (grub_utf8_to_utf16_alloc ) (const char *str8,grub_uint16_t **utf16_msg,grub_uint16_t **last_position); +#endif /* ! GRUB_MISC_HEADER */
Signature · 1 line
2.39.2
Re: [PATCH v5 6/8] kern/misc, kern/efi: Extract UTF-8 to UTF-16 code
Quoted 10 lines · Oliver Steffen
Create a new function for UTF-8 to UTF-16 conversion called
grub_utf8_to_utf16_alloc()in thegrub-code/kern/misc.cand replace charset conversion code used in some places in the EFI code. It is modeled after thegrub_utf8_to_ucs4_alloc()like functions incharset.h. It can't live incharset.h, because it needs to be reachable from the kern/efi code.Add a check for integer overflow and remove redundant NUL-termination.
Signed-off-by Oliver Steffen <[email protected]>
Except two nits below...
Quoted 69 lines
--- grub-core/kern/efi/efi.c | 21 ++++++--------------- grub-core/kern/misc.c | 32 ++++++++++++++++++++++++++++++++ include/grub/misc.h | 3 +++ 3 files changed, 41 insertions(+), 15 deletions(-)grub-core/kern/efi/efi.c +6
-15@@ -207,15 +207,11 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,grub_efi_status_t status;grub_efi_runtime_services_t *r;grub_efi_char16_t *var16; -grub_size_t len, len16; - len =grub_strlen (var); - len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; - var16 =grub_calloc (len16 +1 ,sizeof (var16[0 ])); -if (!var16) +grub_utf8_to_utf16_alloc (var, &var16,NULL ); + +if (var16 ==NULL )return grub_errno; - len16 =grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len,NULL ); - var16[len16] =0 ; r = grub_efi_system_table->runtime_services;@@ -250,18 +246,13 @@ grub_efi_get_variable_with_attributes (const char *var,grub_efi_runtime_services_t *r;grub_efi_char16_t *var16;void *data; -grub_size_t len, len16; *data_out =NULL ; *datasize_out =0 ; - len =grub_strlen (var); - len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; - var16 =grub_calloc (len16 +1 ,sizeof (var16[0 ])); -if (!var16) -return GRUB_EFI_OUT_OF_RESOURCES ; - len16 =grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len,NULL ); - var16[len16] =0 ; +grub_utf8_to_utf16_alloc (var, &var16,NULL ); +if (var16 ==NULL ) +return grub_errno; r = grub_efi_system_table->runtime_services;grub-core/kern/misc.c +3
-0@@ -25,6 +25,7 @@#include <grub/env.h> #include <grub/i18n.h> #include <grub/types.h> +#include <grub/charset.h> union printf_arg {@@ -1323,6 +1324,37 @@ grub_fatal (const char *fmt, ...)grub_abort (); } +grub_ssize_t +grub_utf8_to_utf16_alloc (const char *str8,grub_uint16_t **utf16_msg,grub_uint16_t **last_position)
grub-core/kern/misc.c grub_fatal (const char *fmt, ...) · line 1338
Quoted 10 lines
grub-core/kern/misc.c +10
-0+{ +grub_size_t len; +grub_size_t len16; + + len =grub_strlen (str8); + +/* Check for integer overflow */ +if (len >GRUB_SSIZE_MAX /GRUB_MAX_UTF16_PER_UTF8 -1 ) + { +grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("string too large" ));
s/string too large/string too long/?
grub-core/kern/misc.c grub_fatal (const char *fmt, ...) · line 1351
Quoted 13 lines
grub-core/kern/misc.c +13
-0+ *utf16_msg =NULL ; +return -1 ; + } + + len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; + + *utf16_msg =grub_calloc (len16 +1 ,sizeof (*utf16_msg[0 ])); +if (*utf16_msg ==NULL ) +return -1 ; + + len16 =grub_utf8_to_utf16 (*utf16_msg, len16, (grub_uint8_t *) str8, len,NULL ); + +if (last_position)
s/last_position/last_position != NULL/
Daniel
PATCH v5 7/8 Add a module for the Boot Loader Interface
In reply to Oliver SteffenAdd a new module named boot_loader_interface, which provides a command with the same name. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.
This module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:
- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.
- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2].
This module is only available on EFI platforms.
[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/
--- docs/grub.texi | 22 +++++ grub-core/Makefile.core.def | 6 ++ grub-core/commands/bli.c | 166 ++++++++++++++++++++++++++++++++++++ include/grub/efi/api.h | 5 ++ 4 files changed, 199 insertions(+) create mode 100644 grub-core/commands/bli.c
docs/grub.texi +22 -0
@@ -4291,6 +4291,7 @@ you forget a command, you can run the command @command{help} * background_image:: Load background image for active terminal * badram:: Filter out bad regions of RAM * blocklist:: Print a block list +* bli:: Set Boot Loader Interface EFI variables * boot:: Start up your operating system * cat:: Show the contents of a file * clear:: Clear the screen
@@ -4471,6 +4472,27 @@ Print a block list (@pxref{Block list syntax}) for @var{file}. @end deffn +@node bli +@subsection bli + +@deffn Command bli +Initialize the @url{https://systemd.io/BOOT_LOADER_INTERFACE/, Boot Loader Interface}. + +This command sets two EFI variables under the vendor GUID +@code{4a67b082-0a4c-41cf-b6c7-440b29bb8c4f}: + +@code{LoaderDevicePartUUID} is set to the Partition UUID of the EFI System Partition used during boot. +This is needed for automatic partition discovery as described by the +@url{https://uapi-group.org/specifications/specs/discoverable_partitions_specification/, +Discoverable Partitions Specification}. + +@code{LoaderInfo} is set to the string @code{Grub} followed by the version number. This is used by +user-space tools to identify the boot loader that was used. + +This command is only available on UEFI platforms. +@end deffn + + @node boot @subsection boot
grub-core/Makefile.core.def +6 -0
@@ -2561,3 +2561,9 @@ module = { common = commands/memtools.c; condition = COND_MM_DEBUG; }; + +module = { + name = bli; + efi = commands/bli.c; + enable = efi; +};
grub-core/commands/bli.c new file +166 -0
166 lines not on this page · raw message
include/grub/efi/api.h +5 -0
@@ -374,6 +374,11 @@ { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ } +#define GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID \ + { 0x4a67b082, 0x0a4c, 0x41cf, \ + {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } \ + } +struct grub_efi_sal_system_table {grub_uint32_t signature;
Signature · 1 line
2.39.2
Re: [PATCH v5 7/8] Add a module for the Boot Loader Interface
Quoted 1 line · Oliver Steffen
Add a new module named
boot_loader_interface, which provides a command
s/boot_loader_interface/bli/?
Quoted 55 lines
with the same name. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.
This module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:
- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2].
This module is only available on EFI platforms.
[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/Signed-off-by Oliver Steffen <[email protected]>--- docs/grub.texi | 22 +++++ grub-core/Makefile.core.def | 6 ++ grub-core/commands/bli.c | 166 ++++++++++++++++++++++++++++++++++++ include/grub/efi/api.h | 5 ++ 4 files changed, 199 insertions(+) create mode 100644 grub-core/commands/bli.cdocs/grub.texi +9
-0@@ -4291,6 +4291,7 @@ you forget a command, you can run the command @command{help} * background_image:: Load background image for active terminal * badram:: Filter out bad regions of RAM * blocklist:: Print a block list +* bli:: Set Boot Loader Interface EFI variables * boot:: Start up your operating system * cat:: Show the contents of a file * clear:: Clear the screen@@ -4471,6 +4472,27 @@ Print a block list (@pxref{Block list syntax}) for @var{file}. @end deffn +@node bli +@subsection bli + +@deffn Command bli +Initialize the @url{https://systemd.io/BOOT_LOADER_INTERFACE/, Boot Loader Interface}. + +This command sets two EFI variables under the vendor GUID +@code{4a67b082-0a4c-41cf-b6c7-440b29bb8c4f}:
docs/grub.texi Print a block list (@pxref{Block list syntax}) for @var{file}. · line 4492
Quoted 10 lines
docs/grub.texi +10
-0+ +@code{LoaderDevicePartUUID} is set to the Partition UUID of the EFI System Partition used during boot. +This is needed for automatic partition discovery as described by the +@url{https://uapi-group.org/specifications/specs/discoverable_partitions_specification/, +Discoverable Partitions Specification}. + +@code{LoaderInfo} is set to the string @code{Grub} followed by the version number. This is used by +user-space tools to identify the boot loader that was used. + +This command is only available on UEFI platforms.
Please move "only" to the end of the sentence.
Quoted 66 lines
docs/grub.texi +3
-0+@end deffn + + @node boot @subsection bootgrub-core/Makefile.core.def +6
-0@@ -2561,3 +2561,9 @@ module = { common = commands/memtools.c; condition = COND_MM_DEBUG; }; + +module = { + name = bli; + efi = commands/bli.c; + enable = efi; +};grub-core/commands/bli.c new file +40
-0@@ -0,0 +1,166 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2023 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +* +* Implementation of the Boot Loader Interface. +*/ + +#include <grub/charset.h> +#include <grub/efi/api.h> +#include <grub/efi/disk.h> +#include <grub/efi/efi.h> +#include <grub/err.h> +#include <grub/extcmd.h> +#include <grub/gpt_partition.h> +#include <grub/misc.h> +#include <grub/mm.h> +#include <grub/partition.h> +#include <grub/types.h> + +GRUB_MOD_LICENSE ("GPLv3+" ); + +#define MODNAME "bli" + +static const grub_guid_t bli_vendor_guid =GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID ; + +static grub_err_t +get_part_uuid (const char *device_name,char **part_uuid)
grub-core/commands/bli.c line 50
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+{ +grub_device_t device; +grub_err_t status =GRUB_ERR_NONE ; +grub_disk_t disk =NULL ; +struct grub_gpt_partentry entry; + + device =grub_device_open (device_name); +if (device ==NULL ) + { + status =grub_error (grub_errno,N_ ("error opening device: %s" ), device_name);
s/error opening device/cannot open device/
Otherwise you will see following error message:
error: error opening device: ...
🤔
grub-core/commands/bli.c line 57
Quoted 7 lines
grub-core/commands/bli.c new file +7
-0+ goto fail; + } + + disk =grub_disk_open (device->disk->name); +if (disk ==NULL ) + { + status =grub_error (grub_errno,N_ ("error opening disk: %s" ), device_name);
s/error opening disk/cannot open disk/
Quoted 21 lines
grub-core/commands/bli.c new file +21
-0+return status; + } + +if (grub_strcmp (device->disk->partition->partmap->name,"gpt" ) !=0 ) + { + status =grub_error (GRUB_ERR_BAD_PART_TABLE , +N_ ("this is not a GPT partition table: %s" ), device_name); + goto fail; + } + +if (grub_disk_read (disk, device->disk->partition->offset, + device->disk->partition->index,sizeof (entry), &entry) !=GRUB_ERR_NONE ) + { + status =grub_error (grub_errno,N_ ("read error: %s" ), device_name); + goto fail; + } + + *part_uuid =grub_xasprintf ("%pG" , &entry.guid); +if (*part_uuid ==NULL ) + status = grub_errno; +
grub-core/commands/bli.c line 88
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+ fail: +grub_disk_close (disk); +grub_device_close (device); + +return status; +} + +static grub_err_t +set_efi_str_variable (const char *name,const grub_guid_t *guid, +const char *value)
This function looks pretty generic and I have an itching to move it to the GRUB EFI common code. Could you do that?
Quoted 8 lines
grub-core/commands/bli.c new file +8
-0+{ +grub_efi_char16_t *value_16; +grub_ssize_t len16; +grub_err_t status; + + len16 =grub_utf8_to_utf16_alloc (value, &value_16,NULL ); + +if (len16 <0 )
grub-core/commands/bli.c line 106
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+return grub_errno; + + status =grub_efi_set_variable_with_attributes (name, guid, + (void *) value_16, (len16 +1 ) *sizeof (value_16[0 ]), +GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS |GRUB_EFI_VARIABLE_RUNTIME_ACCESS ); + +grub_free (value_16); + +return status; +}
Daniel
PATCH v5 8/8 util/grub.d: Activate bli module on EFI
In reply to Oliver SteffenAdd a new configuration drop-in file that loads the bli module and runs the command if booting on the EFI platform.
--- Makefile.util.def | 6 ++++++ util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 util/grub.d/25_bli.in
Makefile.util.def +6 -0
@@ -510,6 +510,12 @@ script = { condition = COND_HOST_LINUX; }; +script = { + name = '25_bli'; + common = util/grub.d/25_bli.in; + installdir = grubconf; +}; + script = { name = '30_os-prober'; common = util/grub.d/30_os-prober.in;
util/grub.d/25_bli.in new file +25 -0
@@ -0,0 +1,25 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + insmod bli + bli +fi +EOF
Signature · 1 line
2.39.2
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Quoted 46 lines · Oliver Steffen
Add a new configuration drop-in file that loads the bli module and runs the command if booting on the EFI platform.
Signed-off-by Oliver Steffen <[email protected]>--- Makefile.util.def | 6 ++++++ util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 util/grub.d/25_bli.inMakefile.util.def +6
-0@@ -510,6 +510,12 @@ script = { condition = COND_HOST_LINUX; }; +script = { + name = '25_bli'; + common = util/grub.d/25_bli.in; + installdir = grubconf; +}; + script = { name = '30_os-prober'; common = util/grub.d/30_os-prober.in;util/grub.d/25_bli.in new file +13
-0@@ -0,0 +1,25 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of
util/grub.d/25_bli.in line 23
Quoted 10 lines
util/grub.d/25_bli.in new file +10
-0+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + insmod bli + bli
When I see this I question myself: do we really need a bli command? Why do not simplify things and do what is needed when module is loaded?
Daniel
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Quoted 52 lines · Daniel Kiper
Quoted 51 lines · Oliver Steffen
Add a new configuration drop-in file that loads the bli module and runs the command if booting on the EFI platform.
Signed-off-by Oliver Steffen <[email protected]>--- Makefile.util.def | 6 ++++++ util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 util/grub.d/25_bli.inMakefile.util.def +6
-0@@ -510,6 +510,12 @@ script = { condition = COND_HOST_LINUX; }; +script = { + name = '25_bli'; + common = util/grub.d/25_bli.in; + installdir = grubconf; +}; + script = { name = '30_os-prober'; common = util/grub.d/30_os-prober.in;util/grub.d/25_bli.in new file +18
-0@@ -0,0 +1,25 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
Quoted 10 lines
util/grub.d/25_bli.in line 23
Quoted 5 lines
util/grub.d/25_bli.in new file +5
-0+ +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + insmod bli + bliWhen I see this I question myself: do we really need a bli command? Why do not simplify things and do what is needed when module is loaded?
We could do everything from the module init function. But then this module does not provide a command anymore and probably should not live in grub-core/commands. Where should this go?
-Oliver
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Quoted 64 lines · Oliver Steffen
Quoted 52 lines · Daniel Kiper
Quoted 51 lines · Oliver Steffen
Add a new configuration drop-in file that loads the bli module and runs the command if booting on the EFI platform.
Signed-off-by Oliver Steffen <[email protected]>--- Makefile.util.def | 6 ++++++ util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 util/grub.d/25_bli.inMakefile.util.def +6
-0@@ -510,6 +510,12 @@ script = { condition = COND_HOST_LINUX; }; +script = { + name = '25_bli'; + common = util/grub.d/25_bli.in; + installdir = grubconf; +}; + script = { name = '30_os-prober'; common = util/grub.d/30_os-prober.in;util/grub.d/25_bli.in new file +18
-0@@ -0,0 +1,25 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>.Quoted 10 lines
util/grub.d/25_bli.in line 23
Quoted 5 lines
util/grub.d/25_bli.in new file +5
-0+ +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + insmod bli + bliWhen I see this I question myself: do we really need a bli command? Why do not simplify things and do what is needed when module is loaded?
Quoted 4 lines
We could do everything from the module init function. But then this module does not provide a command anymore and probably should not live in grub-core/commands. Where should this go?
Same for the documentation for it. The manual does not have a "modules" section.
-Oliver
Quoted 2 lines
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Quoted 74 lines · Oliver Steffen
On Tue, Apr 11, 2023 at 4:10 PM Oliver Steffen <[email protected]> wrote:
On Wed, Apr 5, 2023 at 5:57 PM Daniel Kiper <[email protected]> wrote: On Thu, Mar 30, 2023 at 01:18:13PM +0200, Oliver Steffen wrote: > Add a new configuration drop-in file that loads the bli module and runs > the command if booting on the EFI platform. > > Signed-off-by: Oliver Steffen <[email protected]> > --- > Makefile.util.def | 6 ++++++ > util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > create mode 100644 util/grub.d/25_bli.in > > diff --git a/Makefile.util.def b/Makefile.util.def > index beaef1168..d90e59b94 100644 > --- a/Makefile.util.def > +++ b/Makefile.util.def > @@ -510,6 +510,12 @@ script = { > condition = COND_HOST_LINUX; > }; > > +script = { > + name = '25_bli'; > + common = util/grub.d/25_bli.in; > + installdir = grubconf; > +}; > + > script = { > name = '30_os-prober'; > common = util/grub.d/30_os-prober.in; > diff --git a/util/grub.d/25_bli.in b/util/grub.d/ 25_bli.in > new file mode 100644 > index 000000000..ba0f466f0 > --- /dev/null > +++ b/util/grub.d/25_bli.in > @@ -0,0 +1,25 @@ > +#!/usr/bin/sh > +set -e > + > +# grub-mkconfig helper script. > +# Copyright (C) 2023 Free Software Foundation, Inc. > +# > +# GRUB is free software: you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation, either version 3 of the License, or > +# (at your option) any later version. > +# > +# GRUB is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with GRUB. If not, see <http://www.gnu.org/ licenses/>. > + > +cat << EOF > +if [ "\$grub_platform" = "efi" ]; then > + insmod bli > + bli When I see this I question myself: do we really need a bli command?
Quoted 8 lines
Why do not simplify things and do what is needed when
module is loaded?
We could do everything from the module init function. But then this
module
does not provide a command anymore and probably should not live in
grub-core/commands. Where should this go?We do not have separate place for such modules. Everything goes to the grub-core/commands. E.g. the tpm module does not provide any commands and is in the grub-core/commands directory.
Quoted 2 lines
Same for the documentation for it. The manual does not have a "modules" section.
It does not need to be a part of "commands" section. I would just create a separate section for bli module. I expect it will be expanded in the future.
Daniel
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Quoted 80 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen
On Tue, Apr 11, 2023 at 4:10 PM Oliver Steffen <[email protected]>
Quoted 77 lines · wrote:
On Wed, Apr 5, 2023 at 5:57 PM Daniel Kiper <[email protected]> wrote: On Thu, Mar 30, 2023 at 01:18:13PM +0200, Oliver Steffen wrote: > Add a new configuration drop-in file that loads the bli module and runs > the command if booting on the EFI platform. > > Signed-off-by: Oliver Steffen <[email protected]> > --- > Makefile.util.def | 6 ++++++ > util/grub.d/25_bli.in | 25 +++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > create mode 100644 util/grub.d/25_bli.in > > diff --git a/Makefile.util.def b/Makefile.util.def > index beaef1168..d90e59b94 100644 > --- a/Makefile.util.def > +++ b/Makefile.util.def > @@ -510,6 +510,12 @@ script = { > condition = COND_HOST_LINUX; > }; > > +script = { > + name = '25_bli'; > + common = util/grub.d/25_bli.in; > + installdir = grubconf; > +}; > + > script = { > name = '30_os-prober'; > common = util/grub.d/30_os-prober.in; > diff --git a/util/grub.d/25_bli.in b/util/grub.d/ 25_bli.in > new file mode 100644 > index 000000000..ba0f466f0 > --- /dev/null > +++ b/util/grub.d/25_bli.in > @@ -0,0 +1,25 @@ > +#!/usr/bin/sh > +set -e > + > +# grub-mkconfig helper script. > +# Copyright (C) 2023 Free Software Foundation, Inc. > +# > +# GRUB is free software: you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation, either version 3 of the License, or > +# (at your option) any later version. > +# > +# GRUB is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with GRUB. If not, see <http://www.gnu.org/ licenses/>. > + > +cat << EOF > +if [ "\$grub_platform" = "efi" ]; then > + insmod bli > + bli When I see this I question myself: do we really need a bli command? Why do not simplify things and do what is needed when module is loaded?
Quoted 9 lines
Quoted 4 lines
We could do everything from the module init function. But then this module
does not provide a command anymore and probably should not live in grub-core/commands. Where should this go?We do not have separate place for such modules. Everything goes to the grub-core/commands. E.g. the tpm module does not provide any commands and is in the grub-core/commands directory.
Ok.
Quoted 7 lines
Quoted 2 lines
Same for the documentation for it. The manual does not have a "modules" section.
It does not need to be a part of "commands" section. I would just create a separate section for bli module. I expect it will be expanded in the future.
Right now there is section "16 The list of available commands". I could just add a section right after that "17 (The?) list of available modules" and
then below that an entry for bli, explaining what it does. Does this sound ok?
Shall we drop the "the" in the section titles (like it is in the rest of the manual)?
I was a little too quick with the v6 of the series for these changes.. ;-)
- Oliver
Quoted 7 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v5 8/8] util/grub.d: Activate bli module on EFI
Please do not send your emails in html...
On Fri, Apr 14, 2023 at 04:13:58PM +0200, Oliver Steffen wrote:
[...]
Quoted 4 lines
Right now there is section "16 The list of available commands". I could just add a section right after that "17 (The?) list of available modules" and then below that an entry for bli, explaining what it does.
Does this sound ok?
Makes sense for me. But probably list of modules should precede list of commands.
Quoted 2 lines
Shall we drop the "the" in the section titles (like it is in the rest of the manual)?
I would do that.
Quoted 1 line
I was a little too quick with the v6 of the series for these changes.. ;-)
Yeah, you have been fast... :-)
Daniel