From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FF3FECAAD2 for ; Fri, 26 Aug 2022 06:42:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 81441848D5; Fri, 26 Aug 2022 08:41:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="M7PYijlF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DC4A7848B7; Fri, 26 Aug 2022 08:41:37 +0200 (CEST) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EC5D8848C3 for ; Fri, 26 Aug 2022 08:41:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x436.google.com with SMTP id p185so688642pfb.13 for ; Thu, 25 Aug 2022 23:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc; bh=5ThmA0Jx2OkxFdPSCqh/msv0v2PdSeLBU/YI8jky1G4=; b=M7PYijlF/lv3EA5j9VADb8TbzG4MirubMPP8qeuAysZoWNK8q0plxh6+1tLFkoFYOH 7p3QBNkQIQHxg1nQY2qZUCqldUD3oDozRwgXetFiOc2STq/tP8vJ6yNH054nxvPoFBQ6 K6qb6hn/oS1wOKisty2z7ZmIRoBJV8fwsM3xGMun+Fzv4SyISxpoOLGIdPJBoYwJ5JUy OZDl94YEIGtxomSltQPNg33mCYkgWCeNy7APQTwV9dDTKPvH+CJttOqEH2U9zzTAvm37 9p5vW7BLHP6PrqoGcj6zcPepNwk13iOR5kSKob08dcXALg6Oy7Y3qIeorNtGh1XVHR1v brYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc; bh=5ThmA0Jx2OkxFdPSCqh/msv0v2PdSeLBU/YI8jky1G4=; b=1fvzo3yj0+dIZsqlzfduyfDVK09jQybYpEPbsjr6ZeJa7XMT3Kik9Ds3JU/UgjUqNd W3fZgduoeJOo1+pZl9Po3oUYIXv8iHBSofaRa65kHozNkBBUO7gFcBKjuDEGB1FhZSXg uuzzo3iJ+Hi3cRWN2P+w0VH5SuUxDGS86F9Ps/p6kNegbP6eOacW38niNEzlv/W4Ms9T lWhe3GD3wbWA8xEvOCuh+jD3gSjFPIyca4Ile8zEpybgvkb5CYrssMQUABLO6jNPyBrR h9cgcNK7Fph3RUjzegN3T4MOuX1unt6E1d/+bDV5cCz3/d0ceLLah94JGrd89m454tvP FXiA== X-Gm-Message-State: ACgBeo0iI2tnXPIW3mbJFooVAQf0Ljx5SLBu9Mx+xA/yWOXYqofCsaN4 MWVosoYpffdwrWgweEgcXSThMcnmxHjZ6g== X-Google-Smtp-Source: AA6agR7LP0uU2ruSfBFU+k+gwmtW137njkbBGTU/kAGuubn17oSnNSctvXf/jBhSchiv3ld4BuMw+Q== X-Received: by 2002:a05:6a00:2282:b0:536:72d0:d01 with SMTP id f2-20020a056a00228200b0053672d00d01mr2516408pfe.79.1661496091962; Thu, 25 Aug 2022 23:41:31 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id f8-20020a170902ce8800b0016d62ba5665sm694641plg.254.2022.08.25.23.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 23:41:31 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Mark Kettenis , Masahisa Kojima Subject: [PATCH v14 04/10] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 26 Aug 2022 15:42:17 +0900 Message-Id: <20220826064223.23288-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220826064223.23288-1-masahisa.kojima@linaro.org> References: <20220826064223.23288-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 --- 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