All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Glass <sjg@chromium.org>,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	Mark Kettenis <mark.kettenis@xs4all.nl>,
	u-boot@lists.denx.de
Subject: Re: [PATCH v10 03/10] eficonfig: add "Edit Boot Option" menu entry
Date: Tue, 2 Aug 2022 09:38:22 +0200	[thread overview]
Message-ID: <2d19f001-a3cb-735e-d615-2f23cb5b254b@gmx.de> (raw)
In-Reply-To: <20220722023919.19676-4-masahisa.kojima@linaro.org>

On 7/22/22 04:39, 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 support the removable media device is filtered out and user
> can not edit the automatically generated entry.
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> ---
> Changes in v10:
> - update eficonfig_edit_boot_option() argument
>
> Changes in v9:
> - add function comment
>
> Changes in v8:
> - fix menu header string
> - fix function and structure prefix to "eficonfig"
>
> Newly created in v7
>
>   cmd/eficonfig.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 193 insertions(+)
>
> diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
> index a58c5a66ff..dc552e7ae1 100644
> --- a/cmd/eficonfig.c
> +++ b/cmd/eficonfig.c
> @@ -81,6 +81,17 @@ struct eficonfig_file_entry_data {
>   	u16 *file_name;
>   };
>
> +/**
> + * struct eficonfig_boot_selection_data - structure to be used to select the boot option entry
> + *
> + * @bootorder_index:	index in the BootOrder variable

I have defined multiple boot options. But the efidebug command does not
allow to edit them. I just get an error message

BootOrder is not defined!

When BootOrder is defined I can only edit the BootOptions defined by
boot order.

Editing boot options *must not* depend on variable BootOrder. The only
BootOptions that shall not be editable are the autogenerated ones media.

Best regards

Heinrich

> + * @selected:		pointer to store the selected index in the BootOrder variable
> + */
> +struct eficonfig_boot_selection_data {
> +	u16 bootorder_index;
> +	int *selected;
> +};
> +
>   /**
>    * eficonfig_print_msg() - print message
>    *
> @@ -1356,6 +1367,187 @@ out:
>   	return ret;
>   }
>
> +/**
> + * eficonfig_process_boot_selected() - handler to select boot option entry
> + *
> + * @data:	pointer to the data for each entry
> + * Return:	status code
> + */
> +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;
> +}
> +
> +/**
> + * eficonfig_show_boot_selection() - construct boot option menu entry
> + *
> + * @bootorder:	pointer to the BootOrder variable
> + * @count:	the number of BootOrder
> + * @selected:	pointer to store the selected index of BootOrder variable
> + * Return:	status code
> + */
> +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 = 1; /* include "Quit" entry */
> +	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, &efi_global_variable_guid, &size);
> +		if (!load_option)
> +			continue;
> +
> +		ret = efi_deserialize_load_option(&lo, load_option, &size);
> +		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, &efi_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(&p, 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;
> +
> +	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;
> +}
> +
> +/**
> + * eficonfig_process_edit_boot_option() - handler to edit boot option
> + *
> + * @data:	pointer to the data for each entry
> + * Return:	status code
> + */
> +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", &efi_global_variable_guid, &size);
> +	if (!bootorder) {
> +		eficonfig_print_msg("BootOrder is not defined!");
> +		ret = EFI_NOT_FOUND;
> +		return ret;
> +	}
> +
> +	num = size / sizeof(u16);
> +	while (1) {
> +		int selected;
> +		void *load_option;
> +		u16 varname[] = u"Boot####";
> +
> +		ret = eficonfig_show_boot_selection(bootorder, num, &selected);
> +		if (ret != EFI_SUCCESS)
> +			break;
> +
> +		bo = calloc(1, sizeof(struct eficonfig_boot_option));
> +		if (!bo) {
> +			ret = EFI_OUT_OF_RESOURCES;
> +			goto out;
> +		}
> +
> +		bo->boot_index = selected;
> +		efi_create_indexed_name(varname, sizeof(varname),
> +					"Boot", bootorder[selected]);
> +		load_option = efi_get_var(varname, &efi_global_variable_guid, &size);
> +		if (!load_option) {
> +			free(bo);
> +			ret = EFI_NOT_FOUND;
> +			goto out;
> +		}
> +
> +		ret = eficonfig_edit_boot_option(varname, bo, load_option, size,
> +						 "  ** Edit Boot Option ** ");
> +
> +		free(load_option);
> +		free(bo);
> +		if (ret != EFI_SUCCESS && ret != EFI_ABORTED)
> +			break;
> +	}
> +
> +out:
> +	free(bootorder);
> +
> +	/* to stay the parent menu */
> +	ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
> +
> +	return ret;
> +}
> +
>   /**
>    * eficonfig_init() - do required initialization for eficonfig command
>    *
> @@ -1385,6 +1577,7 @@ static efi_status_t eficonfig_init(void)
>
>   static const struct eficonfig_item maintenance_menu_items[] = {
>   	{"Add Boot Option", eficonfig_process_add_boot_option},
> +	{"Edit Boot Option", eficonfig_process_edit_boot_option},
>   	{"Quit", eficonfig_process_quit},
>   };
>


  reply	other threads:[~2022-08-02  7:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22  2:39 [PATCH v10 00/10] enable menu-driven UEFI variable maintenance Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 01/10] efi_loader: move udevice pointer into struct efi_object Masahisa Kojima
2022-08-02 14:53   ` Heinrich Schuchardt
2022-07-22  2:39 ` [PATCH v10 02/10] eficonfig: menu-driven addition of UEFI boot option Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 03/10] eficonfig: add "Edit Boot Option" menu entry Masahisa Kojima
2022-08-02  7:38   ` Heinrich Schuchardt [this message]
2022-08-17  9:02     ` Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 04/10] menu: add KEY_PLUS and KEY_MINUS handling Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 05/10] eficonfig: add "Change Boot Order" menu entry Masahisa Kojima
2022-08-02  7:43   ` Heinrich Schuchardt
2022-08-17  8:48     ` Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 06/10] eficonfig: add "Delete Boot Option" " Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 07/10] bootmenu: add removable media entries Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 08/10] doc:bootmenu: add description for UEFI boot support Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 09/10] doc:eficonfig: add documentation for eficonfig command Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 10/10] test: unit test for eficonfig Masahisa Kojima
2022-07-22  8:45 ` [PATCH v10 00/10] enable menu-driven UEFI variable maintenance Ilias Apalodimas
2022-07-27  1:08   ` Takahiro Akashi
2022-07-27  1:56     ` Takahiro Akashi
2022-08-04  8:26       ` Masahisa Kojima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d19f001-a3cb-735e-d615-2f23cb5b254b@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=masahisa.kojima@linaro.org \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.