[PATCH v7 6/9] efimenu: add "Delete Boot Option" menu entry

Masahisa Kojima masahisa.kojima at linaro.org
Mon Jun 13 11:38:50 CEST 2022


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 at linaro.org>
---
Changes in v7:
- to stay the boot order list after user delete the entry

no update in v6:

changes in v5:

- split into the separate patch
 cmd/efimenu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/cmd/efimenu.c b/cmd/efimenu.c
index 1be483a082..1c97f265ca 100644
--- a/cmd/efimenu.c
+++ b/cmd/efimenu.c
@@ -1565,6 +1565,66 @@ 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 efimenu_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) {
+			ret = EFI_NOT_FOUND;
+			return ret;
+		}
+
+		num = size / sizeof(u16);
+		ret = efimenu_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 efimenu_init(void)
 {
 	efi_status_t ret;
@@ -1600,6 +1660,7 @@ static const struct efimenu_item maintenance_menu_items[] = {
 	{"Add Boot Option", efimenu_process_add_boot_option},
 	{"Edit Boot Option", efimenu_process_edit_boot_option},
 	{"Change Boot Order", efimenu_process_change_boot_order},
+	{"Delete Boot Option", efimenu_process_delete_boot_option},
 	{"Quit", efimenu_process_quit},
 };
 
-- 
2.17.1



More information about the U-Boot mailing list