All of lore.kernel.org
 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>,
	Francois Ozog <francois.ozog@linaro.org>,
	Mark Kettenis <mark.kettenis@xs4all.nl>,
	Masahisa Kojima <masahisa.kojima@linaro.org>
Subject: [PATCH v8 6/9] eficonfig: add "Delete Boot Option" menu entry
Date: Sun, 19 Jun 2022 13:56:04 +0900	[thread overview]
Message-ID: <20220619045607.1669-7-masahisa.kojima@linaro.org> (raw)
In-Reply-To: <20220619045607.1669-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>
---
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 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 0ba70bb10f..b8907f36dc 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1604,6 +1604,67 @@ out:
 	return ret;
 }
 
+static efi_status_t delete_boot_option(u16 *bootorder, u16 index, efi_uintn_t size)
+{
+	u16 varname[9];
+	efi_status_t ret;
+	efi_uintn_t num;
+
+	efi_create_indexed_name(varname, sizeof(varname),
+				"Boot", bootorder[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 */
+	num = size / sizeof(u16);
+	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;
+}
+
+static efi_status_t eficonfig_process_delete_boot_option(void *data)
+{
+	int selected;
+	u16 *bootorder;
+	efi_status_t ret;
+	efi_uintn_t num, size;
+
+	while (1) {
+		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);
+		ret = eficonfig_show_boot_selection(bootorder, num, &selected);
+		if (ret == EFI_SUCCESS)
+			ret = delete_boot_option(bootorder, selected, size);
+
+		if (ret != EFI_SUCCESS)
+			break;
+	}
+
+	free(bootorder);
+
+	/* to stay the parent menu */
+	ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
+
+	return ret;
+}
+
 static efi_status_t eficonfig_init(void)
 {
 	efi_status_t ret;
@@ -1639,6 +1700,7 @@ static const struct eficonfig_item maintenance_menu_items[] = {
 	{"Add Boot Option", eficonfig_process_add_boot_option},
 	{"Edit Boot Option", eficonfig_process_edit_boot_option},
 	{"Change Boot Order", eficonfig_process_change_boot_order},
+	{"Delete Boot Option", eficonfig_process_delete_boot_option},
 	{"Quit", eficonfig_process_quit},
 };
 
-- 
2.17.1


  parent reply	other threads:[~2022-06-19  4:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-19  4:55 [PATCH v8 0/9] enable menu-driven UEFI variable maintenance Masahisa Kojima
2022-06-19  4:55 ` [PATCH v8 1/9] efi_loader: expose END device path node Masahisa Kojima
2022-07-10  9:10   ` Heinrich Schuchardt
2022-07-11 11:32     ` Ilias Apalodimas
2022-06-19  4:56 ` [PATCH v8 2/9] eficonfig: menu-driven addition of UEFI boot option Masahisa Kojima
2022-07-10  9:03   ` Heinrich Schuchardt
2022-07-12  1:55     ` Takahiro Akashi
2022-07-12  6:25       ` Heinrich Schuchardt
2022-07-12 10:59     ` Masahisa Kojima
2022-07-15 14:02       ` Masahisa Kojima
2022-07-14  2:07     ` Takahiro Akashi
2022-06-19  4:56 ` [PATCH v8 3/9] eficonfig: add "Edit Boot Option" menu entry Masahisa Kojima
2022-07-10  9:08   ` Heinrich Schuchardt
2022-07-12  7:04     ` Masahisa Kojima
2022-06-19  4:56 ` [PATCH v8 4/9] menu: add KEY_PLUS and KEY_MINUS handling Masahisa Kojima
2022-07-10  9:09   ` Heinrich Schuchardt
2022-06-19  4:56 ` [PATCH v8 5/9] eficonfig: add "Change Boot Order" menu entry Masahisa Kojima
2022-06-19  4:56 ` Masahisa Kojima [this message]
2022-06-19  4:56 ` [PATCH v8 7/9] bootmenu: add removable media entries Masahisa Kojima
2022-06-19  4:56 ` [PATCH v8 8/9] doc:bootmenu: add description for UEFI boot support Masahisa Kojima
2022-06-19  4:56 ` [PATCH v8 9/9] doc:eficonfig: add documentation for eficonfig command Masahisa Kojima
2022-06-20  4:14 ` [PATCH v8 0/9] enable menu-driven UEFI variable maintenance Takahiro Akashi

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=20220619045607.1669-7-masahisa.kojima@linaro.org \
    --to=masahisa.kojima@linaro.org \
    --cc=francois.ozog@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 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.