From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED6CAC433EF for ; Fri, 22 Jul 2022 02:37:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8FE9084109; Fri, 22 Jul 2022 04:36:40 +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="j+2RPK2g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F216840B3; Fri, 22 Jul 2022 04:36:34 +0200 (CEST) Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (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 3BB9A84111 for ; Fri, 22 Jul 2022 04:36:30 +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-x533.google.com with SMTP id 6so3284087pgb.13 for ; Thu, 21 Jul 2022 19:36:30 -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=3pEoSi4PZXhVz61rLDB5H4/eHGLWonBNDLdmOD/WlcI=; b=j+2RPK2gc3ypN0DmE/6TW/UuinDuuWTzeGtaIinZVfpLdir29sGlgQ3a5HgAVSbPdj 4saVeP8Bm51AUbZNGRsFmGcLpAYBoZCdvM940BmsScCL6tkzr1yLZv+r6uStgaePwSfo KnJcXCOIiBXTUiK0Tw/GEoeBjgHm7SrtYtLO31ZUAFivWmFTm9cDTDDfNYvQrBUyHEOe DgG/rhmtreCUdpJRSgunoUYKdWKoSUwXb3U5WYPcKRE0lj/1lW6JOOL5YXN+alHYAOPD Qe3jd0xU7L+byvLAWmnF02lF1RS0ikwUHHDF2JW5Izgu08o+nca8daOyO+7FxdELij4L NDzw== 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=3pEoSi4PZXhVz61rLDB5H4/eHGLWonBNDLdmOD/WlcI=; b=EnnA8dqnU25q5fZnRi7XJernHyjIQGhy+Nwdt2TYdQyQQLYdhDmHYx+O3SNtrrwBXD CwgFG/u72LUijitO9HyaVyuApt03LMi6Xi6pADHjC1fydK6sCojloUGNAhnCEY8lW4Vf 0JKl0/NfyD+oidBJIyIVFQMF0bKQOURlzEb3WTY0WFQmaYK48CmgEsynY0aAg4nBuCvA cNqzOy1ADgsIt+9vSRA+1ss2g4PqDCoMJXA5DP40UN9jV9xZMnGdX1c6A16riERl0OX0 0lADc0hVsWDrmPd7k2NQYnmbQN2+H0+Opzrm9ZJGWGMtN/Eel0oAQn9SaJV4Z3ysBqXK 3cLQ== X-Gm-Message-State: AJIora/ZGYqkWQsQaz/pNn9X72E+iMqP9aXIpFD6vX1ucqouR8HYlIUy OdytQF+9b9LBW4DOj3tnYmRcf3+ubNK01Q== X-Google-Smtp-Source: AGRyM1tLYLf30qccJR/OUtfdnFw+8QdSzqH1Rcm43z7tONFLg0ZgqlbEoa+q8SXoL2TMEgd9d9c5wg== X-Received: by 2002:a63:1a4c:0:b0:416:1821:733d with SMTP id a12-20020a631a4c000000b004161821733dmr1182412pgm.444.1658457389395; Thu, 21 Jul 2022 19:36:29 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id k21-20020aa79735000000b0051c758a3957sm2509896pfg.149.2022.07.21.19.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36:29 -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 v10 06/10] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 22 Jul 2022 11:39:15 +0900 Message-Id: <20220722023919.19676-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220722023919.19676-1-masahisa.kojima@linaro.org> References: <20220722023919.19676-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 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 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 482efc33d1..54c5cf8a11 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1812,6 +1812,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 * @@ -1843,6 +1918,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}, }; -- 2.17.1