From patchwork Fri Jul 22 02:39:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 592452 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp99917mab; Thu, 21 Jul 2022 19:37:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLgDlgLJv3NVlOk0kfTiLa67wEPd9IF4auDlSWtYy0kdFVabM4YlpTrjRdZopsePo4cqg0 X-Received: by 2002:a92:d10a:0:b0:2d9:1332:d339 with SMTP id a10-20020a92d10a000000b002d91332d339mr647049ilb.110.1658457440663; Thu, 21 Jul 2022 19:37:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658457440; cv=none; d=google.com; s=arc-20160816; b=sh4CiBbqdk2wJvC34zJraxUef4ImbGtv66vmmHIEUBogOvKHRXL1PuthwJ//LI7mCA zERoV5LOxNFnfxpurHqkawbBu5aUkrkfq4c8nox0OjQDWstOeHzz1o06zv46w6YU2GK1 C5+aK4OMKiMS4oeYVgmIl7RqYrKwQ+jNjT7XzFelUHWcGEAo+kOogxFumC7uxBxDT6lF CONj42SvtCuAKWjLIRGn334A+WfJtGlCuVKhUTr9sh1+gM0JRSGfDmXzGYkQMSn/6UC/ g9IrEK3fn4Clb1CXEYn3JVUOmRR+hYT4cu7tPMmyWtGnBThzHfNOg89NjZCBp2pXGDvg 7b3w== 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=3pEoSi4PZXhVz61rLDB5H4/eHGLWonBNDLdmOD/WlcI=; b=jMB+v/gwPCLjNUryDS92k5GehKYwt2OK48NDiQ51EZ+25u8emJxbLttl9YZFTcdis+ Pk0KdUGMwj/TMTwqkiEr4VqtTcfJ4HqQJkI/IIY0rmb9VVNTkEHHy7jkMqYpfZfGSNbZ pWvm5/Hjfrvi7CJJziH0d2hDy01RVTTc9B2DYLKMNPHH1BgSMusOt3LRw9jnV85253IT 3+FBc18tG3+Y/Gr3xaITxV5hc3QXQgT8LEUHCMDuqyLKLOwpD8j6m9TIKyeJYCLtg1JP rftzE62+/Dt0vyuLcNJ4ZYxbIySLfpsk3W1KCidrvNKda4aq15oAfc/T/gni9xsPhEdC C79Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j+2RPK2g; 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 y16-20020a056638229000b0033f6c6a0b39si2949716jas.131.2022.07.21.19.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:37:20 -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=j+2RPK2g; 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 8FE9084109; Fri, 22 Jul 2022 04:36:40 +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="j+2RPK2g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F216840B3; Fri, 22 Jul 2022 04:36:34 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (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 3BB9A84111 for ; Fri, 22 Jul 2022 04:36:30 +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-pg1-x533.google.com with SMTP id 6so3284087pgb.13 for ; Thu, 21 Jul 2022 19:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3pEoSi4PZXhVz61rLDB5H4/eHGLWonBNDLdmOD/WlcI=; b=j+2RPK2gc3ypN0DmE/6TW/UuinDuuWTzeGtaIinZVfpLdir29sGlgQ3a5HgAVSbPdj 4saVeP8Bm51AUbZNGRsFmGcLpAYBoZCdvM940BmsScCL6tkzr1yLZv+r6uStgaePwSfo KnJcXCOIiBXTUiK0Tw/GEoeBjgHm7SrtYtLO31ZUAFivWmFTm9cDTDDfNYvQrBUyHEOe DgG/rhmtreCUdpJRSgunoUYKdWKoSUwXb3U5WYPcKRE0lj/1lW6JOOL5YXN+alHYAOPD Qe3jd0xU7L+byvLAWmnF02lF1RS0ikwUHHDF2JW5Izgu08o+nca8daOyO+7FxdELij4L NDzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3pEoSi4PZXhVz61rLDB5H4/eHGLWonBNDLdmOD/WlcI=; b=EnnA8dqnU25q5fZnRi7XJernHyjIQGhy+Nwdt2TYdQyQQLYdhDmHYx+O3SNtrrwBXD CwgFG/u72LUijitO9HyaVyuApt03LMi6Xi6pADHjC1fydK6sCojloUGNAhnCEY8lW4Vf 0JKl0/NfyD+oidBJIyIVFQMF0bKQOURlzEb3WTY0WFQmaYK48CmgEsynY0aAg4nBuCvA cNqzOy1ADgsIt+9vSRA+1ss2g4PqDCoMJXA5DP40UN9jV9xZMnGdX1c6A16riERl0OX0 0lADc0hVsWDrmPd7k2NQYnmbQN2+H0+Opzrm9ZJGWGMtN/Eel0oAQn9SaJV4Z3ysBqXK 3cLQ== X-Gm-Message-State: AJIora/ZGYqkWQsQaz/pNn9X72E+iMqP9aXIpFD6vX1ucqouR8HYlIUy OdytQF+9b9LBW4DOj3tnYmRcf3+ubNK01Q== X-Received: by 2002:a63:1a4c:0:b0:416:1821:733d with SMTP id a12-20020a631a4c000000b004161821733dmr1182412pgm.444.1658457389395; Thu, 21 Jul 2022 19:36:29 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id k21-20020aa79735000000b0051c758a3957sm2509896pfg.149.2022.07.21.19.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36:29 -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 v10 06/10] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 22 Jul 2022 11:39:15 +0900 Message-Id: <20220722023919.19676-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220722023919.19676-1-masahisa.kojima@linaro.org> References: <20220722023919.19676-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 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 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 482efc33d1..54c5cf8a11 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1812,6 +1812,81 @@ out: return ret; } +/** + * delete_boot_option() - delete selected boot option + * + * @bootorder: pointer to the bootorder + * @index: index to delete in the BootOrder variable + * @size: Bootorder variable size + * Return: status code + */ +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; +} + +/** + * 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) +{ + 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; +} + /** * eficonfig_init() - do required initialization for eficonfig command * @@ -1843,6 +1918,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}, };