From patchwork Mon Sep 5 12:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 602740 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp3642102mae; Mon, 5 Sep 2022 05:46:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR79h3Hc8ZHJhDJtScnDXR9Q9Hz1TRhRl33KqkkcbgsY2yBJdd4YeUfDPFQDWbp/IZa6g+Ch X-Received: by 2002:aa7:c74c:0:b0:44e:a7b9:d5c9 with SMTP id c12-20020aa7c74c000000b0044ea7b9d5c9mr1732739eds.19.1662381993554; Mon, 05 Sep 2022 05:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662381993; cv=none; d=google.com; s=arc-20160816; b=KQ5fyf2HoAlhrd+r3EhAcy/1ZQR2DteAW+M0w3iUvvA4KUz6Bauq8QS0mCIODbffmu KOfNpyyNxYgXmuzfIXtowhlUxSEnadWxc1e8ejV8EJumPL9pwffwmcg20IMlqrcVgwNu FrC2hYGfiwLay0jevaJE8k8+CPZ0r2q69BtT67WFt4eZcB1dRPDrYUQuXP31CNTFuLlH LIW0Daz/M2Lrj7rAlNkdl5YNVpedYdHC0CfLz4bYaWwnz4mKNYKKoYMMmxFS5HJXtj9T jpEsr76z2aOMyV08Rh5SDtauEGZdFOuXLk+Vf9RkT5vfxcxPpzjks99pksTCsLMPbfDs Q2dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=5uvYMER4+KvmH6PuwI/KNp7qjCWhBPFVsuUPP5Vi/Z0=; b=nD6Pup+1CjvyYWoJX7kduvNC+lrr1tmnCf+uhypJlIswyR0qlY8BJcI1yGoHd9GPhR WeSAz0JwaVI5oWIpgTPZLFqoC08nP8N6o+UprmwKhAPzSU0S9ZetrCLH/kBtcQXj82Q0 iCkxSkjTaM8y3k/DUs5K70JKqHZodkJbefVuyHmgSOA7rAYzkP70K+8+RS5wZ7FL3NrR N0SJRD7kM70V061rBxqJXoOctzal+Zr9qTnyKx7WjyLAuzQLNTmvtPNOL26627Ki1TuZ u0K2M2M6t6Bj5xHAN0CEpYUfjNFRhWWXDxUlb8KyJY7Bc3EYNRTQf4EyTCsGbD3M0X6h a4bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mIBHT+7C; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id q29-20020a056402249d00b00446ce49ddf6si7118874eda.96.2022.09.05.05.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 05:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mIBHT+7C; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BFCCC8490A; Mon, 5 Sep 2022 14:46:25 +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="mIBHT+7C"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CB3C58490A; Mon, 5 Sep 2022 14:46:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (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 6D67384927 for ; Mon, 5 Sep 2022 14:46:17 +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-pj1-x1031.google.com with SMTP id u9-20020a17090a1f0900b001fde6477464so12096340pja.4 for ; Mon, 05 Sep 2022 05:46:17 -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:subject:date; bh=5uvYMER4+KvmH6PuwI/KNp7qjCWhBPFVsuUPP5Vi/Z0=; b=mIBHT+7CghlvABqu8DkXdnONt0edpTmkYQ2ItdFYgROyUm4LmsyC+kE1nRdC7iE6St 17IJYbdMuK9vKY8Gxm1aQYZiBgCy+DB9pnhJOx8FCYkOBrtBjWgY+s4Pq50C73W8QlZ3 XIFSoEdwOFQ2pUh+qb36rbs/5Z8dzwWThViAIMDOLe/+7wY1TeLvFfKppZEZ3Wa9oEmu aS6MSj9ZegPcyDgXdpF7kr1D336OcBAoZyAbx5vU+hZ5Z7IcAT82jwQuEu30jcTnZt/y yA+IqAXYJD/BC4XrUhgv01L8INOwJJ8egokxAsIAnP6STXte+vEIfABiCUAmNxpzgw5h S8WA== 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:subject:date; bh=5uvYMER4+KvmH6PuwI/KNp7qjCWhBPFVsuUPP5Vi/Z0=; b=JW+BNQp13L7KtiV5HtWzyTVCrMbDtc9vrrvHdt5h4DgD9QSncV4mjTYCtlLwN/SI+V hBGca0Xnx5Q9Jjo1nzotmkVB4PIN7d2OsOKK2s9mFh0UpbcgHvBsdqxeKebbWHEIbUUM 30aeua9vVKl6IAGC1RFfz3VJdzcIe6vd9+y5O9YBGir7LOWLZz0qz9atchU58TOxIFuH FGmwgzVqpis9ewB1iQQvmSpzYX0B7ZYlbubP6V1VGpkEA30SuiU3oph1anUaLUkXYTi7 GQUPEKA3kAml2j1xoFZZc1wZD8Gw1tq3yd1KmBQQZoS//JLyLn80Fs7oxJKqRRiTva3V RmXA== X-Gm-Message-State: ACgBeo3cHb6wC+ml/2GOW6++cteBf+gMXBgfMeL9uftcDqZUjA7Kz58n SOSNEp8Rrg2wb4NYouWqkhFE0MTtWVIs7Q== X-Received: by 2002:a17:903:186:b0:176:6615:cb8d with SMTP id z6-20020a170903018600b001766615cb8dmr17397418plg.135.1662381975382; Mon, 05 Sep 2022 05:46:15 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id y64-20020a623243000000b0053639773ad8sm7660949pfy.119.2022.09.05.05.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 05:46:14 -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 v16 04/10] eficonfig: add "Delete Boot Option" menu entry Date: Mon, 5 Sep 2022 21:47:56 +0900 Message-Id: <20220905124803.2909-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220905124803.2909-1-masahisa.kojima@linaro.org> References: <20220905124803.2909-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 1f1846de9a..f4d9652628 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1744,6 +1744,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 * @@ -1774,6 +1844,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}, };