Re: [PATCH v8 3/9] eficonfig: add "Edit Boot Option" menu entry

2022-07-12 Thread Masahisa Kojima
On Sun, 10 Jul 2022 at 18:08, Heinrich Schuchardt  wrote:
>
> On 6/19/22 06:56, Masahisa Kojima wrote:
> > This commit adds the menu entry to edit the existing
> > BOOT variable contents.
> > User selects the item from the boot option list, then
> > user can edit the description, file path and optional_data.
> >
> > Note that automatically generated boot option entry by bootmenu
> > to suppport the removable media device is filtered out and user
> > can not edit the automatically generated entry.
> >
> > Signed-off-by: Masahisa Kojima 
> > ---
> > Changes in v8:
> > - fix menu header string
> > - fix function and structure prefix to "eficonfig"
> >
> > Newly created in v7
> >
> >   cmd/eficonfig.c | 172 
> >   1 file changed, 172 insertions(+)
> >
> > diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
> > index 20747db115..0a58b83ea3 100644
> > --- a/cmd/eficonfig.c
> > +++ b/cmd/eficonfig.c
> > @@ -1197,6 +1197,177 @@ out:
> >   return ret;
> >   }
> >
>
> Please, provide function descriptions.

OK.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > +static efi_status_t eficonfig_process_boot_selected(void *data)
> > +{
> > + struct eficonfig_boot_selection_data *info = data;
> > +
> > + if (info)
> > + *info->selected = info->bootorder_index;
> > +
> > + return EFI_SUCCESS;
> > +}
> > +
> > +static efi_status_t eficonfig_show_boot_selection(u16 *bootorder, 
> > efi_uintn_t count,
> > +   int *selected)
> > +{
> > + u32 i;
> > + efi_status_t ret;
> > + efi_uintn_t size, actual_count = 0;
> > + void *load_option;
> > + struct efi_load_option lo;
> > + u16 varname[] = u"Boot";
> > + struct eficonfig_item *menu_item, *iter;
> > +
> > + menu_item = calloc(count + 1, sizeof(struct eficonfig_item));
> > + if (!menu_item) {
> > + ret = EFI_OUT_OF_RESOURCES;
> > + goto out;
> > + }
> > +
> > + iter = menu_item;
> > + for (i = 0; i < count; i++) {
> > + efi_create_indexed_name(varname, sizeof(varname),
> > + "Boot", bootorder[i]);
> > + load_option = efi_get_var(varname, _global_variable_guid, 
> > );
> > + if (!load_option)
> > + continue;
> > +
> > + ret = efi_deserialize_load_option(, load_option, );
> > + if (ret != EFI_SUCCESS) {
> > + log_warning("Invalid load option for %ls\n", varname);
> > + free(load_option);
> > + continue;
> > + }
> > +
> > + if (size >= sizeof(efi_guid_t) &&
> > + !guidcmp(lo.optional_data, 
> > _guid_bootmenu_auto_generated)) {
> > + /*
> > +  * auto generated entry has GUID in optional_data,
> > +  * skip auto generated entry because it will be 
> > generated
> > +  * again even if it is edited or deleted.
> > +  */
> > + free(load_option);
> > + continue;
> > + }
> > +
> > + if (lo.attributes & LOAD_OPTION_ACTIVE) {
> > + char *buf, *p;
> > + struct eficonfig_boot_selection_data *info;
> > +
> > + info = calloc(1, sizeof(struct 
> > eficonfig_boot_selection_data));
> > + if (!info) {
> > + free(load_option);
> > + ret = EFI_OUT_OF_RESOURCES;
> > + goto out;
> > + }
> > +
> > + buf = calloc(1, utf16_utf8_strlen(lo.label) + 1);
> > + if (!buf) {
> > + free(load_option);
> > + free(info);
> > + ret = EFI_OUT_OF_RESOURCES;
> > + goto out;
> > + }
> > + p = buf;
> > + utf16_utf8_strcpy(, lo.label);
> > + info->bootorder_index = i;
> > + info->selected = selected;
> > + iter->title = buf;
> > + iter->func = eficonfig_process_boot_selected;
> > + iter->data = info;
> > + iter++;
> > + actual_count++;
> > + }
> > + free(load_option);
> > + }
> > +
> > + /* add "Quit" entry */
> > + iter->title = strdup("Quit");
> > + iter->func = eficonfig_process_quit;
> > + iter->data = NULL;
> > + actual_count += 1;
> > +
> > + ret = eficonfig_process_common(menu_item, actual_count, "  ** Select 
> > Boot Option **");
> > +
> > +out:
> > + iter = menu_item;
> > + for (i = 0; i < actual_count; i++, iter++) {
> > + 

Re: [PATCH v8 3/9] eficonfig: add "Edit Boot Option" menu entry

2022-07-10 Thread Heinrich Schuchardt

On 6/19/22 06:56, Masahisa Kojima wrote:

This commit adds the menu entry to edit the existing
BOOT variable contents.
User selects the item from the boot option list, then
user can edit the description, file path and optional_data.

Note that automatically generated boot option entry by bootmenu
to suppport the removable media device is filtered out and user
can not edit the automatically generated entry.

Signed-off-by: Masahisa Kojima 
---
Changes in v8:
- fix menu header string
- fix function and structure prefix to "eficonfig"

Newly created in v7

  cmd/eficonfig.c | 172 
  1 file changed, 172 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 20747db115..0a58b83ea3 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1197,6 +1197,177 @@ out:
return ret;
  }



Please, provide function descriptions.

Best regards

Heinrich


+static efi_status_t eficonfig_process_boot_selected(void *data)
+{
+   struct eficonfig_boot_selection_data *info = data;
+
+   if (info)
+   *info->selected = info->bootorder_index;
+
+   return EFI_SUCCESS;
+}
+
+static efi_status_t eficonfig_show_boot_selection(u16 *bootorder, efi_uintn_t 
count,
+ int *selected)
+{
+   u32 i;
+   efi_status_t ret;
+   efi_uintn_t size, actual_count = 0;
+   void *load_option;
+   struct efi_load_option lo;
+   u16 varname[] = u"Boot";
+   struct eficonfig_item *menu_item, *iter;
+
+   menu_item = calloc(count + 1, sizeof(struct eficonfig_item));
+   if (!menu_item) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+
+   iter = menu_item;
+   for (i = 0; i < count; i++) {
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", bootorder[i]);
+   load_option = efi_get_var(varname, _global_variable_guid, 
);
+   if (!load_option)
+   continue;
+
+   ret = efi_deserialize_load_option(, load_option, );
+   if (ret != EFI_SUCCESS) {
+   log_warning("Invalid load option for %ls\n", varname);
+   free(load_option);
+   continue;
+   }
+
+   if (size >= sizeof(efi_guid_t) &&
+   !guidcmp(lo.optional_data, 
_guid_bootmenu_auto_generated)) {
+   /*
+* auto generated entry has GUID in optional_data,
+* skip auto generated entry because it will be 
generated
+* again even if it is edited or deleted.
+*/
+   free(load_option);
+   continue;
+   }
+
+   if (lo.attributes & LOAD_OPTION_ACTIVE) {
+   char *buf, *p;
+   struct eficonfig_boot_selection_data *info;
+
+   info = calloc(1, sizeof(struct 
eficonfig_boot_selection_data));
+   if (!info) {
+   free(load_option);
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+
+   buf = calloc(1, utf16_utf8_strlen(lo.label) + 1);
+   if (!buf) {
+   free(load_option);
+   free(info);
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+   p = buf;
+   utf16_utf8_strcpy(, lo.label);
+   info->bootorder_index = i;
+   info->selected = selected;
+   iter->title = buf;
+   iter->func = eficonfig_process_boot_selected;
+   iter->data = info;
+   iter++;
+   actual_count++;
+   }
+   free(load_option);
+   }
+
+   /* add "Quit" entry */
+   iter->title = strdup("Quit");
+   iter->func = eficonfig_process_quit;
+   iter->data = NULL;
+   actual_count += 1;
+
+   ret = eficonfig_process_common(menu_item, actual_count, "  ** Select Boot 
Option **");
+
+out:
+   iter = menu_item;
+   for (i = 0; i < actual_count; i++, iter++) {
+   free(iter->title);
+   free(iter->data);
+   }
+
+   free(menu_item);
+
+   return ret;
+}
+
+static efi_status_t eficonfig_process_edit_boot_option(void *data)
+{
+   u16 *bootorder;
+   efi_status_t ret;
+   efi_uintn_t num, size;
+   struct eficonfig_boot_option *bo = NULL;
+
+   bootorder = efi_get_var(u"BootOrder", _global_variable_guid, );
+   if (!bootorder) {
+   eficonfig_print_msg("BootOrder is not