[RESEND v9 7/9] bootmenu: add removable media entries

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Jul 20 16:07:04 CEST 2022


Hi Kojima-san

[...]

> +
> +       /* add non-existent boot option */
> +       for (i = 0; i < count; i++) {
> +               u32 boot_index;
> +               u16 var_name[9];
> +
> +               if (!opt[i].exist) {
> +                       ret = eficonfig_get_unused_bootoption(var_name, sizeof(var_name),
> +                                                             &boot_index);
> +                       if (ret != EFI_SUCCESS)
> +                               goto out;
> +
> +                       ret = efi_set_variable_int(var_name, &efi_global_variable_guid,
> +                                                  EFI_VARIABLE_NON_VOLATILE |
> +                                                  EFI_VARIABLE_BOOTSERVICE_ACCESS |
> +                                                  EFI_VARIABLE_RUNTIME_ACCESS,
> +                                                  opt[i].size, opt[i].lo, false);
> +                       if (ret != EFI_SUCCESS)
> +                               goto out;
> +
> +                       ret = eficonfig_append_bootorder(boot_index);
> +                       if (ret != EFI_SUCCESS)
> +                               goto out;
> +               }

Should we got through the trouble on removing the variable we just added?

[...]

>
> diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
> index 51d4e36a54..564ddd02c1 100644
> --- a/cmd/eficonfig.c
> +++ b/cmd/eficonfig.c
> @@ -1786,6 +1786,131 @@ static efi_status_t eficonfig_process_delete_boot_option(void *data)
>         return ret;
>  }
>
> +efi_status_t eficonfig_enumerate_boot_option(struct eficonfig_media_boot_option *opt,
> +                                            efi_handle_t *volume_handles, efi_status_t count)
> +{
> +       u32 i;
> +       struct efi_handler *handler;
> +       efi_status_t ret = EFI_SUCCESS;
> +
> +       for (i = 0; i < count; i++) {
> +               char *optional_data;
> +               u16 *dev_name, *p;
> +               struct efi_load_option lo;
> +               char buf[BOOTMENU_DEVICE_NAME_MAX];
> +               struct efi_device_path *device_path;
> +
> +               ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler);
> +               if (ret != EFI_SUCCESS)
> +                       continue;
> +               ret = efi_protocol_open(handler, (void **)&device_path,
> +                                       efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +               if (ret != EFI_SUCCESS)
> +                       continue;
> +
> +               ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX);
> +               if (ret != EFI_SUCCESS)
> +                       continue;
> +
> +               dev_name = calloc(1, (strlen(buf) + 1) * sizeof(u16));
> +               if (!dev_name) {
> +                       ret = EFI_OUT_OF_RESOURCES;
> +                       goto out;
> +               }

Just allocate an array in the stack

> +               p = dev_name;
> +               utf8_utf16_strncpy(&p, buf, strlen(buf));
> +
> +               lo.label = dev_name;
> +               lo.attributes = LOAD_OPTION_ACTIVE;
> +               lo.file_path = device_path;
> +               lo.file_path_length = efi_dp_size(device_path) + sizeof(END);
> +               /*
> +                * Set the dedicated guid to optional_data, it is used to identify
> +                * the boot option that automatically generated by the bootmenu.
> +                * efi_serialize_load_option() expects optional_data is null-terminated
> +                * utf8 string, so set the "1234567" string to allocate enough space

[...]

Thanks
/Ilias


More information about the U-Boot mailing list