From patchwork Mon Sep 12 08:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 604982 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:2213:b0:1da:4c02:b5e7 with SMTP id z19csp2443033ltw; Mon, 12 Sep 2022 01:32:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR64OlNVMLnRlSIj0D6e9JEw1UuuCuKvW3kz/aZo2PVQ1Is0bw1437ZlfeqmunNR61NQLs/g X-Received: by 2002:a17:907:6d19:b0:779:d662:46be with SMTP id sa25-20020a1709076d1900b00779d66246bemr10304240ejc.478.1662971561493; Mon, 12 Sep 2022 01:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662971561; cv=none; d=google.com; s=arc-20160816; b=ecgcZJazd4BQA+SJiBIODOhNVlUgn2scyS1vvhmdaaiTWZc2qZ2igDxQMee0OiVtYa X3L3Rt2cJdClx+Ajzxk6NPxjBT0LX3rBxvBlYcYAOhxxCD0Bc9K6eucs5TmNy38OdRk6 ChYrKE9CEIMyNGMxZmrCA2PA/shKiB7WZGJKp4obzILTDyy2ZarbZ2ldDyGy3mLoy1Ae A5lQcIjdcza0VT34msJ8+fSCjvAK1yV1e29a6aory7k9yU2uFr3jLPa1jtD6c33Bx4pr SIBEKqDfWSWG9Bu4jg0HAjOBcqQ+MzZae8dnSb4hvQMzv4dAvYlva6LQ1cqdQfm8CL1+ C5CQ== 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=R/8V3VJjuKTU1vaG41E/0HBdu5PIHwkjnkRUlnS5UWQ=; b=ReqwjVNAkNB6SBfqiy24tAF9TIa3GMdtHj2+ulaS6PElaomrjIZcTp5IJClYaqnnOU G8Won17XW0HO6RfRPMKvfolFYJ2NYTVdlnbinJz11BWuWMBzIgiRcX1YJaqBSFzhZX31 xVCZQazMKUT1qs5wOCx7vF/pUF3EQeN35n/PO+FbsrO6J4ha1rOi8yrciq1vXkbCrek1 JKbQvs1deefHrkZOhHO5vuVQkr3/vhw1eBr8unXPlLnfCCMR7e16n4mpvXZjEZV9jhYS 7xSmJ26Ywe/b/QpdYyLmrqpXjLfeEIJRqCSjj58Mb2wWV2nV5j1GuODucLkOzr4IiGOI mUoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=inSZsS6A; 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 i7-20020a1709064fc700b0073dd129cb40si8277769ejw.415.2022.09.12.01.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:32:41 -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=inSZsS6A; 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 7525384B7F; Mon, 12 Sep 2022 10:32: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="inSZsS6A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 498EC84560; Mon, 12 Sep 2022 10:32:11 +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-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 434C584560 for ; Mon, 12 Sep 2022 10:32:01 +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-x42d.google.com with SMTP id 145so7913657pfw.4 for ; Mon, 12 Sep 2022 01:32:01 -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=R/8V3VJjuKTU1vaG41E/0HBdu5PIHwkjnkRUlnS5UWQ=; b=inSZsS6AULbD5/EmRJ6cR29K3V+gpvY/XN5tOdqsUfA4rj9hC1wzKSuTnQQ8e6uXAz H1oMOfhU44fy8jYe2tiJHUMPKzIJB083iITFYPckyH6a838A0vBTncGlSsj6e8PWyFas E0sBs4ekvDvL8BrXFBEqVVE/Y9yRYlqkWtyrQBZuvUwofhkSrszzS4nOfa+EeftxTvPv 0LZ1z08b7Hss0/1vyuoIUyW+VbZrMuLcsIzGjQmGFCxJG/O9x/TsjsM3pTr1gal8vQfX ROO7DcMd45GWtm7I9AntadQmYHWlPxO3K5/rdp+hWnDBIFB9xX0jSoLsedI078F2UF+l MZYA== 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=R/8V3VJjuKTU1vaG41E/0HBdu5PIHwkjnkRUlnS5UWQ=; b=kzvH8+czXUqZLFEuYtEqVzwjzFVi0CZ+fKgRcVwhQNBiL3B22sJbFlC4wNu3mxNf6J NjhH3gs5BFe3w1a/rkd7Tq1n/XYUuf9cY2aeEHYvpwiH157i4ZVBybX7+joeROUrlB8X KcebRkDTpz9juM68Rr7SPWgxAozr1sn9Yr5MO8Y58Jo9E8t5/Xs1lw4EjkgyxHzt4GCr 2g3+YZJAU5tiZjDr9A7x+fj89gCDGJsEK2Pwk0esL8nDfQWREHI/TktJXooXR9oz9oQS JoNZRqQUaKCNcFEKuP8wxJ4M6TZQfFeZfP6frqP5p35ufw2vbcFhKfM6TEeh5QZOr3QO NP+g== X-Gm-Message-State: ACgBeo1Z0iLtcNApvdEsK8h3D386VJgA02ch+oR7tncRKTmHBdhZNfNr jtKc5wJSG0QvEW82Ex1O+ujOsdWQM4PoHg== X-Received: by 2002:a05:6a00:2449:b0:528:3a29:e79d with SMTP id d9-20020a056a00244900b005283a29e79dmr26829681pfj.39.1662971519288; Mon, 12 Sep 2022 01:31:59 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id d15-20020a621d0f000000b00540ad46bc1dsm4698506pfd.157.2022.09.12.01.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:31:58 -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 v17 04/10] eficonfig: add "Delete Boot Option" menu entry Date: Mon, 12 Sep 2022 17:33:53 +0900 Message-Id: <20220912083359.24510-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220912083359.24510-1-masahisa.kojima@linaro.org> References: <20220912083359.24510-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 bd1975895b..5841a3ffe1 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1788,6 +1788,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 * @@ -1818,6 +1888,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}, };