From patchwork Sun Jun 19 04:56:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 582996 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:7814:0:0:0:0 with SMTP id b20csp747890mav; Sat, 18 Jun 2022 21:56:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sVwm2EuhuLr3F85dOMzbpGNakey1+JpuKJnDkwwd8Wl72wX2bHaAALfccSeNB6u7fESk4l X-Received: by 2002:a17:906:7d47:b0:715:7ec3:e3ad with SMTP id l7-20020a1709067d4700b007157ec3e3admr15547795ejp.12.1655614587145; Sat, 18 Jun 2022 21:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655614587; cv=none; d=google.com; s=arc-20160816; b=o4XGpYuTYF/wDfKZXrB7LZVbJFpiSrhzEjVGNzuch9ZoZuZK3Hq2Z7jRiCP3EvNUDW UxG5+2qZMmt+tLlDS0fFBSLL943k1xArLubzSpsfbGA+5j3peRhbvj/qGVLfW1sJlur+ sXpNSK7d+FY2HkOdXsLRca62haSpafwHrnPdPyo6Krpw2xGjLgMYLFlZlTJ+cWeQCcS/ jgyPxgoFyG08DdfyGiZYA2ur3p+C9L5V5WiNjvBidCNDg/pwhNMKSm7tbfEArJxRT731 AFUtUhpgYCaZ3FX+QGc6qKuGQ7TriWZLEcxoMuTDQwKAO7yIniu6BDDg/r3BWMYOqBBh KcbA== 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=iTOxfZlVU0Xa89lgD5gK34/B0lo21WpnQfbNL9AbyVA=; b=1BjC/C7cPIJsiXShtdMNc3immZ8gEM+v6CtRwOczC4uEVcxVaKmK+UhO0wDghL8FlQ 1290bpwiw5CzrwZIZOTb8InNQH8cHleLjUCnLf2Ij+IjpHxZIFgjtto537DcVw5Ei/Gb UFxW38KOXjWIIWUS3QvY0r8kPSMWBDJ6OUk76OHlu1ksropdXMfW9/oNKzjnRKtHt0t1 ZNzYPXUsX93+AiSKeJAX2eHYhVT2K9eYUju7OhZQa9CdvL+kvgH3+6xdzA5fozxHxfMG eeDzC1SA4P36rtGmeFazVhloFTXHPX7cC7fe045NVVGLjL2D2LlTAuNOD59YRLo7mf9b whag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TakptvWb; 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 l25-20020a056402345900b004357fb1ea9bsi5644edc.436.2022.06.18.21.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 21:56:27 -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=TakptvWb; 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 A81E484435; Sun, 19 Jun 2022 06:55:42 +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="TakptvWb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA8ED8442B; Sun, 19 Jun 2022 06:55:40 +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-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 140C3843F0 for ; Sun, 19 Jun 2022 06:55:38 +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-x42e.google.com with SMTP id f18so2156580pfq.9 for ; Sat, 18 Jun 2022 21:55:37 -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=iTOxfZlVU0Xa89lgD5gK34/B0lo21WpnQfbNL9AbyVA=; b=TakptvWbQ6gP7D3G1r9Pu65uDVCU5djQf1b0Nu6qwaAh3twyWlbvdRy6b3v9kCXl16 LTAuXVbFoEjREuJ4x0VCrBemzZSBC9p5IgUG4aha3OmUQPMTe8WFcbC/n7JefETCvm1M aU6+exa69kQGKGnW1ns4JKq84hkUDY9obkLq+n9hxl/dG3HCl7+9uSZq+Rgml7vYl+nJ gcIlS55PA0XKxGeWlhd3Lue5sVtuSDSXGjalNNrqgJtG3ReueFsurpe/DyMunPC8ShhG RVZqvvCxBuOE8+CQl+iywE4fBd9T4zY/24ci4YPh4ZHm3XrOeaWyiZqVF/U5BYXGSCxB XsXg== 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=iTOxfZlVU0Xa89lgD5gK34/B0lo21WpnQfbNL9AbyVA=; b=2nnYoOHaKfdfDjxcmQ6N6NWFpNgl+qbiYGXjuw13KxC4MS/UMIqKqHgGNV5oZQUYWE T8QBXyNn5HnM7so9WjcQGamVQazc+23XB61j9D7ZzZ5TFL4EudMveegKfRC9k+wLaONb kj6Y9kQOXbNeJUZ38InMn3pNsXUshQWYMY+DOhOKwS+c191gboE3LWhwA35Iz5NWCySt HkabMyLpT44Zzq+jLMmsF56NZ4PduOID9Zmp5kSc78CkWqJZwB/2hkmKdmw++TGwBCRs JIEoWmNMFskzNMMIuAZ2wBGw7SiB0cHMqB2tgMATLvqyTUMMJLDwNmnilq1Z3EBV6dbi 2L8A== X-Gm-Message-State: AJIora/ueDXHsPDZI47EZqL9luioTXhaPfpbJY2sSROJ1Y/GYP/b73uP SoDvSlGa9aB1Z910CFTQHNfoFgj8lQAYAQ== X-Received: by 2002:aa7:80c2:0:b0:524:c3c2:5993 with SMTP id a2-20020aa780c2000000b00524c3c25993mr16270654pfn.1.1655614536239; Sat, 18 Jun 2022 21:55:36 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id 9-20020aa79149000000b00518424f8922sm6381848pfi.77.2022.06.18.21.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 21:55:35 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v8 6/9] eficonfig: add "Delete Boot Option" menu entry Date: Sun, 19 Jun 2022 13:56:04 +0900 Message-Id: <20220619045607.1669-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220619045607.1669-1-masahisa.kojima@linaro.org> References: <20220619045607.1669-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.5 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 --- 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 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0ba70bb10f..b8907f36dc 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1604,6 +1604,67 @@ 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 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; +} + static efi_status_t eficonfig_init(void) { efi_status_t ret; @@ -1639,6 +1700,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}, };