From patchwork Fri Sep 2 14:23:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 602174 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp1509129mae; Fri, 2 Sep 2022 07:22:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR51lCbmCZ2jReYAPlPmtkw6n+B0pPpxuaQglX1rQPTEdCOICcnn0BXxHtZ0X+QiXAe9LUMf X-Received: by 2002:a17:906:7310:b0:741:85de:ead0 with SMTP id di16-20020a170906731000b0074185deead0mr17945353ejc.441.1662128577643; Fri, 02 Sep 2022 07:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662128577; cv=none; d=google.com; s=arc-20160816; b=hJNSXRbslmDzXOc0X4DO7bn4FVJkQLj6ZiG6JLyIDFaciETl5rrU08dEnOKynSCNtm JP9tHdYd/7F6EG//gp6gKCw2K2cCQd4sMMpcQ8Sa1KhODmehhF4KS3mAFOnLOkKG/B3U iXEpWRc9wtMYpJ9xkGtJokhtYyv1cO/6U4IYFzCRl1nkl/5U8UHwDtVjVJTLjBupONSE krvWi/mGrUJrjuTRy6vs8NqIATFIBW/Tvs9KJTxr0zo1eiln9Scw+CgS2fufwTYhh3JH pGjPgINkJ/TqMiljGNGiDXUA9d+nCxYLYo92IE85E8xVOITK04OLRykj4DIdzi4+zsFf zDbA== 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=hrT5WD5+if1LnpwmVem0WDNtR2ddBgJitz9l8qDJBNU=; b=IxO0i0H+wqp+gymxCLjQrqvxWfLmZ4qK7rsO+S3fN20fAJMsQ21s/Wk4AtMTVV/kUm ODHsc+wWsHdDA2w39tGM7Df1HG6LQa0V4mHMZx3l+FMzUzHUYFWnXxjxP4ow+xE7h4lB I19/dWf0wEmYsIwxoU3JEga2CHFXK5oow5ySTbsm2j5sIcKpsMq/6FOUqd1qdIAlQx/H xAaf2fRIUmbUBuAKNEcHdP++8Sk5vb+HkBAdy1HZyj583EUlVCj3Mh3bWnYoDxTkH55t T7QE/alJQHyC+sdQpjKlOUUyO5BwIX4OLZrmFcaCU2u0XgcSoi0mv61/0AU/J+VzsyU+ iuSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v6vjMdOP; 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 h16-20020a056402281000b00446cacdaba2si2381802ede.331.2022.09.02.07.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 07:22:57 -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=v6vjMdOP; 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 B224C84ADF; Fri, 2 Sep 2022 16:22:24 +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="v6vjMdOP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AD6884AD2; Fri, 2 Sep 2022 16:22:19 +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-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 75EF484ACA for ; Fri, 2 Sep 2022 16:22:16 +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-pl1-x632.google.com with SMTP id jm11so1968256plb.13 for ; Fri, 02 Sep 2022 07:22:16 -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=hrT5WD5+if1LnpwmVem0WDNtR2ddBgJitz9l8qDJBNU=; b=v6vjMdOPtJirATON23c5/FzIwtskG9ZUQruyX/NA9rYtYtbrWh5Wy0epb4qKQU+66c QbAojb7U90oMxdFkAX6atADpQYAGy0ahATHU7/QnplgOKnUdkFwrHjpKHf3F4PPfu5V6 E2ZCdhQmJi4aLa/5na3I+b7c47mOVXPOyUmsCnPi750dB7SBjApY5iIZUegYHkrHmkT3 xDqPlJXKQ0hwtjEo0Oofucqhlw0xuEkboIXuGCuHcQwBJ1HQRAyG6LWAyzIqjAhq0NLj dcHxBsqt3Ce0MlTlko9hvD8C3eLbWsnD0p1eZk2orPaTnRqU93+TWxWz5k0Tw6d4cC5p adiQ== 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=hrT5WD5+if1LnpwmVem0WDNtR2ddBgJitz9l8qDJBNU=; b=ZAyWcqlrSzomTLj3aXV94SdjSMusQLtfoz2atdhLMnXwaahHbx1AyHo6BPGQzOtvP7 Dwj0uV6zdtG5ubMnBBy+iOezmxzvpIbw+l9Lo+9FmVxWt393MjsH7pL/Te3XvUo6G2X/ ui6NXnrDm87CSBSRoxmxzGxHMB5XR4oazqWOCb3V3ZWqLUGXTICCkyseuKBnyeMS/MzY Ftd91f7OwupfyWD1rbD9HiHVr/ri1gYU3IISN5pG6lhfdZxVsce1EyM4a1nnOTmnL2td UBXJ4NO2UznX9mViMbAR6CP4CDvC1WDQlm1y9/pvCr25xNw5zC8TxGvw/Ndx23JFtByh QKuw== X-Gm-Message-State: ACgBeo08/55yJYulAAEnY/dOm3CPgFCqRuF3vKuX06FhQJW8xtBg3odf lOa25MRKiRYc2GUsAjGOKFlOsoqNBxSlVA== X-Received: by 2002:a17:90b:3b4d:b0:1fe:4d47:76ed with SMTP id ot13-20020a17090b3b4d00b001fe4d4776edmr5258974pjb.150.1662128534643; Fri, 02 Sep 2022 07:22:14 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i8-20020a17090332c800b0017272667a56sm1678485plr.196.2022.09.02.07.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 07:22: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 v15 04/10] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 2 Sep 2022 23:23:43 +0900 Message-Id: <20220902142349.16722-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220902142349.16722-1-masahisa.kojima@linaro.org> References: <20220902142349.16722-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 bba83579a3..c9713acdda 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1748,6 +1748,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 * @@ -1778,6 +1848,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}, };