From patchwork Wed Aug 17 09:36:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 597844 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp3087393maz; Wed, 17 Aug 2022 02:36:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ukE/7frxTBf5HX3A0evA95d6aLgwQmIAI3HOZyJ7e0EwrYm6R5m2VHGx5oTli5jGCbVP1 X-Received: by 2002:a05:6512:260f:b0:492:8e9f:c647 with SMTP id bt15-20020a056512260f00b004928e9fc647mr3796318lfb.443.1660729011937; Wed, 17 Aug 2022 02:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660729011; cv=none; d=google.com; s=arc-20160816; b=I/iuqfdId/hLjWBJ4zSL4yVZLDs8fMaGnIj097GPhx5B6WibX4ppiHYT9muCyeq4kw AsN4OPrahUcYIGYTF0k3el17SbQzEUUkac5X2vGdFdMTvHwkfbql4ldZrbw/uOuaTjc/ Taou1ADzuTCk9aJ5E+XGwWxofHGLL5wjewI3uGNpChseipDMNAJfrq+0YxNYobm1QHrX 4vF/krQwTbDG+/e6GTB9OaxZRl05VNG82Ghycex0umNFAZ7+wRIEzf/jXR1PSQUV6fu8 QB2BJ7fTyQVtILaHWzcZuexJgc5ts8SbwXJiOS8QdlGONEzprxep114qQBwjLnv+IqaH BpHw== 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=pmq/TlAJJgSsjzemnilKJGfIUY7Z67gna2O13j42pNI=; b=XCPJYyeABSS+PmzdCt7LXQ/D53+KqxT2/YpfdJRGjk82dO/b90k2NgUPMj1mbVRTRS 5p56TNKhISdqnhRT7IcxKHriMpN1D/6+1USQP3tFmNXlWi2XgzutL76DXRPUi81opDce sZsFnletoTzgVqB9Kx/Xa5CUwxxB1/+eY49anpdKuNCSQDtCID+xrbD0n/YWqOY46QlU ITMp8uBQUVldxNIPzvmLAYB94umKKdzXF86N910ARM4+On1P9uORwgnd0PLNdpU8LkTM ScG8Dpob+erLkzCpZgXeTrbvXFOhc31UhdF6t4+m8k/EnhQGVaA+kCLEyefC3kIRwsjB pAiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IF3Xw0ML; 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 m15-20020a056512114f00b00488661e548fsi615501lfg.431.2022.08.17.02.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 02:36:51 -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=IF3Xw0ML; 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 1BC3084A16; Wed, 17 Aug 2022 11:36:11 +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="IF3Xw0ML"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0DE9F84242; Wed, 17 Aug 2022 11:35:57 +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-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) (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 D590B84995 for ; Wed, 17 Aug 2022 11:35:53 +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-x52a.google.com with SMTP id f65so11498491pgc.12 for ; Wed, 17 Aug 2022 02:35:53 -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; bh=pmq/TlAJJgSsjzemnilKJGfIUY7Z67gna2O13j42pNI=; b=IF3Xw0MLSH4wZ5jveTJMEjMdm7iP5aWoItfokhLjcez/NAjs5uwu+Fz6sQJFA1Nvpp eGN0hB1CAXfpwZhOrD2uNg/H4m/oBhaj1l9R+nodwJ8mLSJYL88xVDD55oJjkFcyK0Ar XyNYgDuv+UDIUUrJouHy0UZA3sFagziLmusaaaKiMA22imXK1Sxb0f+PlS7v5aEskq4t zJH7bZdQKQFXefREiWe6v3AzeM25PjfBW/0yzRcUVcRMFLNLRv4aBpJxWm3Ou4f/yrRx vBGkSXSXgSvshyoaSx6A3fye5Y23y/jdgkaeTNB19oEaqys5FzTd7Fcha3kGSn+Xo/Gc vCNg== 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; bh=pmq/TlAJJgSsjzemnilKJGfIUY7Z67gna2O13j42pNI=; b=XLA+0cOKGRVZj9Yqxv/Byv0SsrpLgAlrh84p6rO5mjMxVomK230rspyHbyXGAHFCKs xiJQgkJoqszL/VosmYlq/JPb6AsHwaTKcTJL/rGcxK/6MBJPlFTo50y7so18TUUYd+u2 IzKfLBoYr382FPtyE3ij/M4n/VMYb2AYidJVZmkBg5HqesKNeyVs1wKoQvPm0KOmYFqp NuyzlY9XHzXCB/k3o8GxdgESZaXLcfBmo3ZgzarTwc3U1wB+ypyXrUL8r9XH2TV0My5j rljnzUDn3VIRErKB2Mhe93ZAwee1aKwswphuwLwm9ERZYlreHT6E96KWRdnCwDWf5qP5 PebA== X-Gm-Message-State: ACgBeo27ZmnmRZTJXShSWxMcpdqNODNHfkQ4JXEgrC1BQeJSRjz3BWS6 FzpLQa5ov4gnY0PVeAhV8QUOJ6l9AayVlg== X-Received: by 2002:a63:415:0:b0:422:6de7:d9b7 with SMTP id 21-20020a630415000000b004226de7d9b7mr19709127pge.432.1660728951980; Wed, 17 Aug 2022 02:35:51 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q16-20020aa79610000000b00528669a770esm10214285pfg.90.2022.08.17.02.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 02:35:51 -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 v11 5/9] eficonfig: add "Delete Boot Option" menu entry Date: Wed, 17 Aug 2022 18:36:10 +0900 Message-Id: <20220817093614.32266-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220817093614.32266-1-masahisa.kojima@linaro.org> References: <20220817093614.32266-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 --- 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 f6152495c8..6e39c0cd4d 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -2010,6 +2010,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 * @@ -2041,6 +2111,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}, };