Add basic Boot Loader Interface support
v6 cover Add basic Boot Loader Interface support
This is a step towards supporting unified kernel images (UKI) in Grub.
Add a new module named bli. 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/
v6:
- Initialize the Boot Loader Interface on module load and remove the bli command.
- Extract code for grub_efi_set_variable_to_string()
- Improve error messages in the bli module
- Improve GUID printing code
v5:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00120.html
- 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 (9):
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
efi: Add grub_efi_set_variable_to_string() Add a module for the Boot Loader Interface util/grub.d: Activate bli module on EFI
Makefile.util.def | 6 ++ grub-core/Makefile.core.def | 6 ++ grub-core/commands/acpi.c | 4 +- grub-core/commands/bli.c | 122 +++++++++++++++++++++++++++ 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 | 108 ++++++++++++------------ 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 | 113 ++++++++++++++++++++----- 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 | 23 +++-- 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 | 24 ++++++ 43 files changed, 444 insertions(+), 245 deletions(-) create mode 100644 grub-core/commands/bli.c create mode 100644 util/grub.d/25_bli.in
Signature · 1 line
2.40.0
PATCH v6 1/9 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.40.0
PATCH v6 2/9 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 ; +static grub_guid_t acpi =GRUB_EFI_ACPI_TABLE_GUID ; +static 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.40.0
PATCH v6 3/9 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 | 81 ++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 21 deletions(-)
grub-core/kern/misc.c +60 -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 ;
@@ -926,6 +935,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in) args->ptr[n].ll = va_arg (args_in, long long);break ;case STRING : +case GUID :if (sizeof (void *) ==sizeof (long long )) args->ptr[n].ll = va_arg (args_in, long long);else
@@ -943,6 +953,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 +1056,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.40.0
PATCH v6 4/9 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.40.0
PATCH v6 5/9 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.40.0
PATCH v6 6/9 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 {
@@ -1318,6 +1319,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 long" )); + *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 !=NULL ) + *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.40.0
PATCH v6 7/9 efi: Add grub_efi_set_variable_to_string()
In reply to Oliver SteffenAdd a function that sets an EFI variable to a string value. The string is converted from UTF-8 to UTF-16.
--- grub-core/kern/efi/efi.c | 22 ++++++++++++++++++++++ include/grub/efi/efi.h | 3 +++ 2 files changed, 25 insertions(+)
grub-core/kern/efi/efi.c +22 -0
@@ -285,6 +285,28 @@ grub_efi_get_variable_with_attributes (const char *var,return status; } +grub_err_t +grub_efi_set_variable_to_string (const char *name,const grub_guid_t *guid, +const char *value,grub_efi_uint32_t attributes) +{ +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 ) +return grub_errno; + + status =grub_efi_set_variable_with_attributes (name, guid, + (void *) value_16, (len16 +1 ) *sizeof (value_16[0 ]), + attributes); + +grub_free (value_16); + +return status; +} +grub_efi_status_t grub_efi_get_variable (const char *var,const grub_guid_t *guid,grub_size_t *datasize_out,void **data_out)
include/grub/efi/efi.h +3 -0
@@ -108,6 +108,9 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,const grub_guid_t *guid, void *data, grub_size_t datasize); +grub_err_t +EXPORT_FUNC (grub_efi_set_variable_to_string ) (const char *name,const grub_guid_t *guid, +const char *value,grub_efi_uint32_t attributes);int EXPORT_FUNC (grub_efi_compare_device_paths ) (const grub_efi_device_path_t *dp1,const grub_efi_device_path_t *dp2);
Signature · 1 line
2.40.0
PATCH v6 8/9 Add a module for the Boot Loader Interface
In reply to Oliver SteffenAdd a new module named bli. 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.
When loaded, 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 available on EFI platforms only. bli relies on the part_gpt module which has to be loaded beforehand to make the GPT partitions discoverable.
[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/
--- grub-core/Makefile.core.def | 6 ++ grub-core/commands/bli.c | 122 ++++++++++++++++++++++++++++++++++++ include/grub/efi/api.h | 5 ++ 3 files changed, 133 insertions(+) create mode 100644 grub-core/commands/bli.c
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 +122 -0
122 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.40.0
PATCH v6 9/9 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 | 24 ++++++++++++++++++++++++ 2 files changed, 30 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 +24 -0
@@ -0,0 +1,24 @@ +#!/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 +fi +EOF
Signature · 1 line
2.40.0