u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Masahisa Kojima <masahisa.kojima@linaro.org>
To: u-boot@lists.denx.de
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Glass <sjg@chromium.org>,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	Mark Kettenis <mark.kettenis@xs4all.nl>,
	Masahisa Kojima <masahisa.kojima@linaro.org>
Subject: [PATCH v14 04/10] eficonfig: add "Delete Boot Option" menu entry
Date: Fri, 26 Aug 2022 15:42:17 +0900	[thread overview]
Message-ID: <20220826064223.23288-5-masahisa.kojima@linaro.org> (raw)
In-Reply-To: <20220826064223.23288-1-masahisa.kojima@linaro.org>

This commit adds the menu entry to delete the UEFI boot option.
User moves the entry with UP/DOWN key, changes, then presses
ENTER key to delete the selected boot option.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
---
No update since v11

Changes in v11:
- update function interface to show boot selection menu
- support to delete the load option is not included in BootOrder

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- to stay the boot order list after user delete the entry

no update in v6:

changes in v5:

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

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 74c51a09e0..9e4a5cd83f 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1718,6 +1718,76 @@ out:
 	return ret;
 }
 
+/**
+ * delete_boot_option() - delete selected boot option
+ *
+ * @boot_index:	boot option index to delete
+ * Return:	status code
+ */
+static efi_status_t delete_boot_option(u16 boot_index)
+{
+	u16 *bootorder;
+	u16 varname[9];
+	efi_status_t ret;
+	unsigned int index;
+	efi_uintn_t num, size;
+
+	efi_create_indexed_name(varname, sizeof(varname),
+				"Boot", boot_index);
+	ret = efi_set_variable_int(varname, &efi_global_variable_guid,
+				   0, 0, NULL, false);
+	if (ret != EFI_SUCCESS) {
+		log_err("delete boot option(%ls) failed\n", varname);
+		return ret;
+	}
+
+	/* update BootOrder if necessary */
+	bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
+	if (!bootorder)
+		return EFI_SUCCESS;
+
+	num = size / sizeof(u16);
+	if (!search_bootorder(bootorder, num, boot_index, &index))
+		return EFI_SUCCESS;
+
+	memmove(&bootorder[index], &bootorder[index + 1],
+		(num - index - 1) * sizeof(u16));
+	size -= sizeof(u16);
+	ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
+				   EFI_VARIABLE_NON_VOLATILE |
+				   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+				   EFI_VARIABLE_RUNTIME_ACCESS,
+				   size, bootorder, false);
+
+	return ret;
+}
+
+/**
+ * eficonfig_process_delete_boot_option() - handler to delete boot option
+ *
+ * @data:	pointer to the data for each entry
+ * Return:	status code
+ */
+static efi_status_t eficonfig_process_delete_boot_option(void *data)
+{
+	efi_status_t ret;
+	unsigned int selected;
+
+	while (1) {
+		ret = eficonfig_show_boot_selection(&selected);
+		if (ret == EFI_SUCCESS)
+			ret = delete_boot_option(selected);
+
+		if (ret != EFI_SUCCESS)
+			break;
+	}
+
+	/* to stay the parent menu */
+	ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
+
+	return ret;
+}
+
 /**
  * eficonfig_init() - do required initialization for eficonfig command
  *
@@ -1748,6 +1818,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},
+	{"Delete Boot Option", eficonfig_process_delete_boot_option},
 	{"Quit", eficonfig_process_quit},
 };
 
-- 
2.17.1


  parent reply	other threads:[~2022-08-26  6:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26  6:42 [PATCH v14 00/10] enable menu-driven UEFI variable maintenance Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 01/10] eficonfig: menu-driven addition of UEFI boot option Masahisa Kojima
2022-08-30 11:53   ` Ilias Apalodimas
2022-08-30 12:56     ` Ilias Apalodimas
2022-08-26  6:42 ` [PATCH v14 02/10] eficonfig: add "Edit Boot Option" menu entry Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 03/10] menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling Masahisa Kojima
2022-08-26  6:42 ` Masahisa Kojima [this message]
2022-08-26  6:42 ` [PATCH v14 05/10] bootmenu: add removable media entries Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 06/10] eficonfig: scan media device in eficonfig startup Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 07/10] eficonfig: add "Change Boot Order" menu entry Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 08/10] doc:bootmenu: add description for UEFI boot support Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 09/10] doc:eficonfig: add documentation for eficonfig command Masahisa Kojima
2022-08-26  6:42 ` [PATCH v14 10/10] test: unit test for eficonfig 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=20220826064223.23288-5-masahisa.kojima@linaro.org \
    --to=masahisa.kojima@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).