Add basic Boot Loader Interface support
v3 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.
Some comments from v2 where not fully addressed, see "commands/bli:
Extract uft8 to utf16 conversion" patch.
[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/
v3:
- 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 (10):
efi: Add grub_efi_set_variable_with_attributes
efi: Check for integer overflow in string conversion Unify GUID types
kern/misc: Add a format specifier GUIDs.
grub-core: Make use of guid printf format specifier Add a module for the Boot Loader Interface grub-core/kern/efi: Remove redundant null-termination types.h: Add GRUB_SSIZE_MAX
commands/bli: Extract uft8 to utf16 conversion util/grub.d: Activate bli module on EFI
grub-core/Makefile.core.def | 6 + grub-core/commands/acpi.c | 4 +- grub-core/commands/bli.c | 222 ++++++++++++++++++++++++ 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 | 9 +- grub-core/disk/efi/efidisk.c | 4 +- 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 | 73 ++++---- 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 | 86 ++++++--- grub-core/loader/arm64/linux.c | 4 +- grub-core/loader/efi/fdt.c | 2 +- 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/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/types.h | 11 ++ util/grub.d/25_boot_loader_interface.in | 34 ++++ 36 files changed, 485 insertions(+), 215 deletions(-) create mode 100644 grub-core/commands/bli.c create mode 100644 util/grub.d/25_boot_loader_interface.in
Signature · 1 line
2.39.2
PATCH v3 1/10 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
@@ -86,6 +86,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 v3 2/10 efi: Check for integer overflow in string conversion
In reply to Oliver SteffenCheck for integer overflow when converting the name of the EFI variable to UTF16 in grub_efi_set_variable_with_attributes().
--- grub-core/kern/efi/efi.c | 6 ++++++ 1 file changed, 6 insertions(+)
grub-core/kern/efi/efi.c +6 -0
@@ -25,6 +25,7 @@#include <grub/efi/pe32.h> #include <grub/time.h> #include <grub/term.h> +#include <grub/types.h> #include <grub/kernel.h> #include <grub/mm.h> #include <grub/loader.h>
@@ -210,6 +211,11 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *ggrub_size_t len, len16; len =grub_strlen (var); + +/* Check for integer overflow */ +if (len >GRUB_SIZE_MAX /GRUB_MAX_UTF16_PER_UTF8 -1 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("variable name too long" )); + len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; var16 =grub_calloc (len16 +1 ,sizeof (var16[0 ]));if (!var16)
Signature · 1 line
2.39.2
PATCH v3 3/10 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/disk/efi/efidisk.c | 4 +- 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/arm64/linux.c | 4 +- grub-core/loader/efi/fdt.c | 2 +- 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/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/types.h | 9 ++++ 31 files changed, 122 insertions(+), 131 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 ; +struct grub_guid acpi =GRUB_EFI_ACPI_TABLE_GUID ; +struct grub_guid 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/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 struct grub_guid apple = GRUB_EFI_VENDOR_APPLE_GUID; if (vendor->header.length == sizeof (*vendor) && grub_memcmp (&vendor->vendor_guid, &apple,
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
@@ -36,12 +36,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;
@@ -59,7 +59,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) {
@@ -98,7 +98,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;
@@ -119,7 +119,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;
@@ -202,7 +202,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;
@@ -235,7 +235,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,
@@ -246,7 +246,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)
@@ -301,7 +301,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/arm64/linux.c +2 -2
@@ -52,8 +52,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/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/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/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
@@ -25,18 +25,18 @@#include <grub/efi/api.h> /* 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 *
@@ -77,23 +77,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/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 */
Signature · 1 line
2.39.2
Re: [PATCH v3 03/10] Unify GUID types
Quoted 46 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]>--- 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/disk/efi/efidisk.c | 4 +- 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/arm64/linux.c | 4 +- grub-core/loader/efi/fdt.c | 2 +- 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/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/types.h | 9 ++++ 31 files changed, 122 insertions(+), 131 deletions(-)grub-core/commands/acpi.c +0
-0
grub-core/commands/acpi.c grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) · line 763
Quoted 7 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 ; +struct grub_guid acpi =GRUB_EFI_ACPI_TABLE_GUID ; +struct grub_guid acpi20 =GRUB_EFI_ACPI_20_TABLE_GUID ;
I would be more consistent and use grub_guid_t instead of "struct grub_guid" everywhere. Otherwise the patch LGTM...
Daniel
PATCH v3 4/10 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
PATCH v3 5/10 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
@@ -550,20 +550,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;
@@ -934,18 +921,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
Re: [PATCH v3 05/10] grub-core: Make use of guid printf format specifier
Quoted 6 lines · Oliver Steffen
Use the new printf format specifier %pG.
Fixes the text representation of GUIDs in the output of the lsefisystab command.
Signed-off-by Oliver Steffen <[email protected]>
Daniel
PATCH v3 6/10 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/
--- grub-core/Makefile.core.def | 6 ++ grub-core/commands/bli.c | 199 ++++++++++++++++++++++++++++++++++++ include/grub/efi/api.h | 5 + 3 files changed, 210 insertions(+) create mode 100644 grub-core/commands/bli.c
grub-core/Makefile.core.def +6 -0
@@ -2548,3 +2548,9 @@ module = { common = commands/i386/wrmsr.c; enable = x86; }; + +module = { + name = bli; + efi = commands/bli.c; + enable = efi; +};
grub-core/commands/bli.c new file +199 -0
199 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 v3 06/10] Add a module for the Boot Loader Interface
Quoted 94 lines · Oliver Steffen
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 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]>--- grub-core/Makefile.core.def | 6 ++ grub-core/commands/bli.c | 199 ++++++++++++++++++++++++++++++++++++ include/grub/efi/api.h | 5 + 3 files changed, 210 insertions(+) create mode 100644 grub-core/commands/bli.cgrub-core/Makefile.core.def +6
-0@@ -2548,3 +2548,9 @@ module = { common = commands/i386/wrmsr.c; enable = x86; }; + +module = { + name = bli; + efi = commands/bli.c; + enable = efi; +};grub-core/commands/bli.c new file +43
-0@@ -0,0 +1,199 @@ +/* +* 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 (grub_device_t dev,char **part_uuid) +{ +grub_err_t status =GRUB_ERR_NONE ; +grub_disk_t disk;
grub-core/commands/bli.c line 53
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+struct grub_gpt_partentry entry; + +if (dev ==NULL || dev->disk ==NULL || dev->disk->partition ==NULL ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("invalid device" )); + + disk =grub_disk_open (dev->disk->name); +if (disk ==NULL ) + { + status = grub_errno; +char *part =grub_partition_get_name (dev->disk->partition);
I would define "char *part = NULL;" at the beginning of the get_part_uuid() function and move most of the grub_free() calls behind "fail" label.
grub-core/commands/bli.c line 57
Quoted 4 lines
grub-core/commands/bli.c new file +4
-0+grub_dprintf (MODNAME ,"error opening disk: %s%s%s\n" , dev->disk->name, + dev->disk->partition !=NULL ?"," :"" , + part !=NULL ? part :"UNKNOWN" ); +grub_free (part);
Except this one...
grub-core/commands/bli.c line 65
Quoted 8 lines
grub-core/commands/bli.c new file +8
-0+return status; + } + +if (grub_strcmp (dev->disk->partition->partmap->name,"gpt" ) !=0 ) + { +char *part =grub_partition_get_name (dev->disk->partition); + status = grub_error (GRUB_ERR_BAD_PART_TABLE, + "this is not a GPT partition table: %s%s%s", dev->disk->name,
N_("this is not a GPT partition table: %s%s%s")
grub-core/commands/bli.c line 77
Quoted 12 lines
grub-core/commands/bli.c new file +12
-0+ dev->disk->partition !=NULL ?"," :"" , + part != NULL ? part : "UNKNOWN"); +grub_free (part); + goto fail; + } + +if (grub_disk_read (disk, dev->disk->partition->offset, + dev->disk->partition->index,sizeof (entry), &entry) !=GRUB_ERR_NONE ) + { + status = grub_errno; +char *part =grub_partition_get_name (dev->disk->partition); + grub_dprintf (MODNAME, "read error: %s%s%s\n", dev->disk->name,
Why do not you use grub_error() here? In general I think we should use grub_error() instead of grub_dprintf() for printing errors in this function.
Quoted 32 lines
grub-core/commands/bli.c new file +32
-0+ dev->disk->partition !=NULL ?"," :"" , + part != NULL ? part : "UNKNOWN"); +grub_free (part); + goto fail; + } + + *part_uuid =grub_xasprintf ("%pG" , &entry.guid); +if (*part_uuid ==NULL ) + status = grub_errno; + + fail: +grub_disk_close (disk); + +return status; +} + +static grub_err_t +set_efi_str_variable (const char *name,const grub_guid_t *guid, +const char *value) +{ +grub_size_t len, len16; +grub_efi_char16_t *value_16; +grub_err_t status; + + len =grub_strlen (value); + +/* Check for integer overflow */ +if (len >GRUB_SIZE_MAX /GRUB_MAX_UTF16_PER_UTF8 -1 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("data too large" )); + + len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; +
grub-core/commands/bli.c line 119
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+ value_16 =grub_calloc (len16 +1 ,sizeof (value_16[0 ])); +if (value_16 ==NULL ) +return grub_errno; + + len16 =grub_utf8_to_utf16 (value_16, len16, (grub_uint8_t *) value, len,NULL ); + + 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_EFI_VARIABLE_BOOTSERVICE_ACCESS | GRUB_EFI_VARIABLE_RUNTIME_ACCESS);
I cannot see any reason to wrap this line.
Quoted 20 lines
grub-core/commands/bli.c new file +20
-0+if (status !=GRUB_ERR_NONE ) +grub_dprintf (MODNAME ,"Error setting EFI variable %s: %d\n" , name, status); + +grub_free (value_16); + +return status; +} + +static grub_err_t +set_loader_device_part_uuid (void ) +{ +grub_efi_loaded_image_t *image; +char *device_name; +grub_err_t status =GRUB_ERR_NONE ; +grub_device_t device; +char *part_uuid =NULL ; + + image =grub_efi_get_loaded_image (grub_efi_image_handle); +if (image ==NULL ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("unable to find boot device" ));
grub-core/commands/bli.c line 149
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+ + device_name =grub_efidisk_get_device_name (image->device_handle); +if (device_name ==NULL ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("unable to find boot device" )); + + device =grub_device_open (device_name); +if (device ==NULL ) + { + status = grub_errno; +grub_dprintf (MODNAME ,"Error opening device: %s" , device_name);
Again, why do not use grub_error() here?
grub-core/commands/bli.c line 160
Quoted 11 lines
grub-core/commands/bli.c new file +11
-0+ goto fail; + } + + status =get_part_uuid (device, &part_uuid); + +grub_device_close (device); + +if (status ==GRUB_ERR_NONE ) + status =set_efi_str_variable ("LoaderDevicePartUUID" , + &bli_vendor_guid, + part_uuid);
set_efi_str_variable ("LoaderDevicePartUUID", &bli_vendor_guid, part_uuid);
You do not need to wrap this line here.
Quoted 22 lines
grub-core/commands/bli.c new file +22
-0+ + fail: +grub_free (part_uuid); +grub_free (device_name); +return status; +} + +static grub_err_t +grub_cmd_bli (grub_extcmd_context_t ctxt __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char **args __attribute__ ((unused))) +{ +grub_err_t status; + + status =set_efi_str_variable ("LoaderInfo" , &bli_vendor_guid,PACKAGE_STRING ); +if (status !=GRUB_ERR_NONE ) +return status; + + status =set_loader_device_part_uuid (); +if (status !=GRUB_ERR_NONE ) +return status; +
grub-core/commands/bli.c line 192
Quoted 10 lines
grub-core/commands/bli.c new file +10
-0+return GRUB_ERR_NONE ; +} + +static grub_extcmd_t cmd; + +GRUB_MOD_INIT (bli) +{ +grub_dprintf (MODNAME ,"%s got here\n" , __func__); + cmd =grub_register_extcmd ("bli" , grub_cmd_bli,0 ,NULL , +N_ ("Set EFI variables according to Boot Loader Interface spec." ),NULL );
Please add a section about this command to the docs/grub.texi. I think it would be nice to add links to the specs there too.
Daniel
PATCH v3 7/10 grub-core/kern/efi: Remove redundant null-termination
In reply to Oliver Steffengrub_calloc already initializes the buffer with \0, no need to set the null-terminator at the end.
--- grub-core/kern/efi/efi.c | 2 -- 1 file changed, 2 deletions(-)
grub-core/kern/efi/efi.c +0 -2
@@ -221,7 +221,6 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,if (!var16)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;
@@ -267,7 +266,6 @@ grub_efi_get_variable_with_attributes (const char *var,if (!var16)return GRUB_EFI_OUT_OF_RESOURCES ; len16 =grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len,NULL ); - var16[len16] =0 ; r = grub_efi_system_table->runtime_services;
Signature · 1 line
2.39.2
Re: [PATCH v3 07/10] grub-core/kern/efi: Remove redundant null-termination
Quoted 1 line · Oliver Steffen
grub_callocalready initializes the buffer with \0, no
Nit, s/grub_calloc/grub_calloc()/...
Quoted 1 line
need to set the null-terminator at the end.
s/null-terminator/NUL-terminator/
Quoted 2 lines
Signed-off-by Oliver Steffen <[email protected]>
Otherwise Reviewed-by: Daniel Kiper <[email protected]>...
Daniel
PATCH v3 8/10 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
Re: [PATCH v3 08/10] types.h: Add GRUB_SSIZE_MAX
Quoted 3 lines · Oliver Steffen
In the same way as
GRUB_SIZE_MAX, addGRUB_SSIZE_MAX.Signed-off-by Oliver Steffen <[email protected]>
Daniel
PATCH v3 9/10 commands/bli: Extract uft8 to utf16 conversion
In reply to Oliver SteffenCreate a new function for utf-8 to utf-16 conversion called grub_utf8_to_utf16_alloc in the bli module. It is modeled after the grub_utf8_to_ucs4_alloc like functions in charset.h. The goal is to move this to a central place so that it can help reduce code duplication.
Please comment: Where should this go?
--- grub-core/commands/bli.c | 47 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-)
grub-core/commands/bli.c +35 -12
@@ -36,6 +36,37 @@ GRUB_MOD_LICENSE ("GPLv3+");static const grub_guid_t bli_vendor_guid =GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID ; +/* To be moved to a central place */ +static 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; +} +static grub_err_t get_part_uuid (grub_device_t dev,char **part_uuid) {
@@ -91,28 +122,20 @@ get_part_uuid (grub_device_t dev, char **part_uuid)return status; } +static grub_err_t set_efi_str_variable (const char *name,const grub_guid_t *guid,const char *value) { -grub_size_t len, len16;grub_efi_char16_t *value_16; +grub_ssize_t len16;grub_err_t status; - len =grub_strlen (value); + len16 =grub_utf8_to_utf16_alloc (value, &value_16,NULL ); -/* Check for integer overflow */ -if (len >GRUB_SIZE_MAX /GRUB_MAX_UTF16_PER_UTF8 -1 ) -return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("data too large" )); - - len16 = len *GRUB_MAX_UTF16_PER_UTF8 ; - - value_16 =grub_calloc (len16 +1 ,sizeof (value_16[0 ])); -if (value_16 ==NULL ) +if (len16 <0 )return grub_errno; - len16 =grub_utf8_to_utf16 (value_16, len16, (grub_uint8_t *) value, len,NULL ); - status =grub_efi_set_variable_with_attributes (name, guid, (void *) value_16, (len16 +1 ) *sizeof (value_16[0 ]), GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
Signature · 1 line
2.39.2
Re: [PATCH v3 09/10] commands/bli: Extract uft8 to utf16 conversion
Quoted 2 lines · Oliver Steffen
Create a new function for utf-8 to utf-16 conversion called
grub_utf8_to_utf16_allocin the bli module. It is modeled after the
s/grub_utf8_to_utf16_alloc/grub_utf8_to_utf16_alloc()/
Quoted 1 line
grub_utf8_to_ucs4_alloclike functions incharset.h. The goal is to
s/grub_utf8_to_ucs4_alloc/grub_utf8_to_ucs4_alloc()/
Quoted 4 lines
move this to a central place so that it can help reduce code duplication.
Please comment: Where should this go?
I would put it in grub-core/normal/charset.c. If not then grub-core/kern/misc.c.
Daniel
PATCH v3 10/10 util/grub.d: Activate bli module on EFI
In reply to Oliver SteffenAdd a new configuration drop-in file that loads the boot-loader-interface (bli) module and runs the command in case we are booting on the EFI platform.
--- util/grub.d/25_boot_loader_interface.in | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 util/grub.d/25_boot_loader_interface.in
util/grub.d/25_boot_loader_interface.in new file +34 -0
@@ -0,0 +1,34 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2020 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/>. + +prefix="/usr" +exec_prefix="/usr" +datarootdir="/usr/share" + +export TEXTDOMAIN=grub +export TEXTDOMAINDIR="${datarootdir}/locale" + +. "$pkgdatadir/grub-mkconfig_lib" + +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + insmod bli + bli +fi +EOF
Signature · 1 line
2.39.2
Re: [PATCH v3 10/10] util/grub.d: Activate bli module on EFI
Quoted 16 lines · Oliver Steffen
Add a new configuration drop-in file that loads the boot-loader-interface (bli) module and runs the command in case we are booting on the EFI platform.
Signed-off-by Oliver Steffen <[email protected]>--- util/grub.d/25_boot_loader_interface.in | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 util/grub.d/25_boot_loader_interface.inutil/grub.d/25_boot_loader_interface.in new file +0
-0
util/grub.d/25_boot_loader_interface.in line 5
Quoted 5 lines
util/grub.d/25_boot_loader_interface.in new file +5
-0@@ -0,0 +1,34 @@ +#!/usr/bin/sh +set -e + +# grub-mkconfig helper script. +# Copyright (C) 2020 Free Software Foundation, Inc.
s/2020/2023/
Quoted 7 lines
util/grub.d/25_boot_loader_interface.in new file +7
-0+# +# 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,
util/grub.d/25_boot_loader_interface.in line 22
Quoted 10 lines
util/grub.d/25_boot_loader_interface.in new file +10
-0+# 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/>. + +prefix="/usr" +exec_prefix="/usr" +datarootdir="/usr/share"
This assumptions can be wrong. Please get relevant values from the configure...
Daniel