From patchwork Fri Jul 15 14:27:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 590841 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp552680max; Fri, 15 Jul 2022 07:26:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfmEgJz0ldQgD+eyGHOitceCSkp0piHyyWPGQ2gL5NkJzCkk8X1YGSwvVV/9CbmtR0yJYU X-Received: by 2002:a02:2a4e:0:b0:33e:e3c8:35c2 with SMTP id w75-20020a022a4e000000b0033ee3c835c2mr7992732jaw.170.1657895206551; Fri, 15 Jul 2022 07:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657895206; cv=none; d=google.com; s=arc-20160816; b=i3rh4k3LwRP8PF/c6pzXH94CsL6Ba8l0deLh0CPo0oboLrOQHGkUBVTj+mvMT+fCSy hJW9FnvSrSGhNWakTKbuSbhuv/5RBwXvtNq5L7Muw11A97fQ0aetR0A3rw7kbPrBh6Sn 5r7zAY9w7yi11tKgfsRi105mAkGn4DvDaRWqJXxbmjAr9WDxQp9Hq07EPAcE5aq8oGhf 0a/K9Q5C6hqbta1LiqeUMGA8GeBlPgtnWxK/8DOGYdo+DFP78VqTcEqOPhrrlZMwDs7z OK4V7DEx7yiHyfmhNYCY7NP8Y+YDwLVOwsTJZK851XWEEMsObrvVzO8ReW0flXg43XoR 2F7g== 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=oIBrTySaJzlZ/PX304+FIQ1DHdTIHBezsK/WkUhJzrI=; b=eCiXPXqLpqZ5nxJ001gi9l9VFBaO7KxiSqb1OKwLm5xXiyvIzqIB9kaGHf17SmkfPY cZPaKfviGVz5hhnmWvkOOCZJT45ptVA2/MRPgnxFYTQ1A5HS2Qw3fNeMcDGJ/QcN+V1l JnOstXg0/4QzNDQLDDuUceZPmFCH/WVYdZ4UJLDORnGe03O0oAG1O6v+y7jjrk6AQNse 97ydhfpRWgqdEcgY6UI/Qw7GbhXpVIMpv2zS26JuC9+0fsqWhLTfmCYW2dJw2M1ONhCB 4Sd+u18L3yH132yNZf/vHMCogs3lOwbXQ27RqPQBlLSKwglGN/90SierIdrWUZ2h35zK mPqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KZlu8maR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id h14-20020a92c26e000000b002dc2dea6bfasi4902637ild.104.2022.07.15.07.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:26:46 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KZlu8maR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 330B78110C; Fri, 15 Jul 2022 16:25:48 +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="KZlu8maR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AD199814BD; Fri, 15 Jul 2022 16:25:25 +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-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 D41D1819B1 for ; Fri, 15 Jul 2022 16:25:15 +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-x430.google.com with SMTP id l124so4778203pfl.8 for ; Fri, 15 Jul 2022 07:25:15 -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=oIBrTySaJzlZ/PX304+FIQ1DHdTIHBezsK/WkUhJzrI=; b=KZlu8maR0Kd2Ed4TLW/E/h30ceyvNL1VLkFcVVbckLlbawrKheoOFIyEfvivRPyfr9 ZFfntu2W+Kiv4PNEGCVsXpyxGDXEFHCAWE9YgGV/bIbGcmjTiOSVmYFyvx2f+4CRp7fe doSgmARxTpFRwuWQz7pYDgIMnitMI6GQzzHrM+pA2p4nQEaBuC7fPP9dJuieiEcgsujB 8bL0ssjCTFEiRT4yGI2XElRQ5NAv7p0FY0xDzYnUc09Ng94Wh+bxZxh/HQFgNqSne/oM 7Egw9cr+G/8Hnrkrvv3RDWSLCtUj/JXLae2AL6iS6sMKLB1Nd2R3/R+U1MKCcUksbUF2 zUEw== 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=oIBrTySaJzlZ/PX304+FIQ1DHdTIHBezsK/WkUhJzrI=; b=5KtWaaZh8dtNsQaoiK6JenSZxw2AA5TBCwcM28jGP/xcPhCQrhLs9kXaRr8EFsK3i/ FW7oIWyQSuGVsoqz4lWwNzzjyDLFe4NmKbRricZ5jw3anMF6YDBsnKlNxnQNp4Sc+VBs te/h5aG8R28L6DO1ou+q6ZMn/fbKwJ0vrxM74eMGa9skWFnMAm9C5iMun+yVapvqymx+ KPNH5K9EqTVDSBK4GRcP1kwOeIuvCwWuuO6IOCwk3+9lztmJvOemeB24Wp89XPyaL5ZB wewq8o8XymEUojvQWC2nvnMiKL/JuUUmgK3gcN5UKSpOwE3QB3YvN5Jzm8+r4w9OH12T uh5g== X-Gm-Message-State: AJIora9wXaeegEvqqor+BMnFCT3zKdKapgKAeZ8Vj2tC5xLx9ElLOApx Af8Gx2hQ+X2O//onFJENqh8PLMABW9djbw== X-Received: by 2002:a05:6a00:4211:b0:52a:c86e:aba3 with SMTP id cd17-20020a056a00421100b0052ac86eaba3mr14548058pfb.41.1657895113422; Fri, 15 Jul 2022 07:25:13 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id d22-20020aa797b6000000b0051c49fb62b7sm3891174pfq.165.2022.07.15.07.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:25:13 -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 6/9] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 15 Jul 2022 23:27:40 +0900 Message-Id: <20220715142743.30137-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220715142743.30137-1-masahisa.kojima@linaro.org> References: <20220715142743.30137-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 --- cmd/eficonfig.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index aeb60f1d09..51d4e36a54 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1711,6 +1711,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 * @@ -1742,6 +1817,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}, };