From patchwork Fri Jul 15 14:47:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 590849 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp570357max; Fri, 15 Jul 2022 07:46:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uIlXYB77uL0KaYNir2gDnITD2ShKheTBv57cLVpZng8HC1um1mS3lYFvSW/YXR12wPbHqE X-Received: by 2002:a05:6e02:1a2c:b0:2dc:79f0:41ae with SMTP id g12-20020a056e021a2c00b002dc79f041aemr7586525ile.108.1657896385753; Fri, 15 Jul 2022 07:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657896385; cv=none; d=google.com; s=arc-20160816; b=vc1sHyGErF5TtotiP54covtk7295CdSoFxCMK6eajcSfdWcUJ0La/HVcsKPHKF2jRX h6yDGpFxiPt1+H3bcFbeoRwB7KpVuDKB1/JGIjjDtb/B/cB2Jd0fTV+aRUXzCJY1ach4 yi+v4VQHOIBFxDSY0JvWiLWEdgZ0TU9MRsWExYOrmd7TFmstwMBXJUFZsi36m5BYPG7s vVA5hvBYE/dqqB+1HQ3/1SyzOdv0tq9Wjzq7ZNEZqnrd9tez206YtPeHceCPe1W/h+BL H1naxQwUp9sd9Fqpa8lDWbOBpgDNOU/dm3kh//51EmePzdyMYmkqoEOfHs+v79+yx/GR QVFQ== 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=+9zNreIx61ijwM9bTzD6Eyh3UNLNUdokSgBpEfNxtKo=; b=fO1q76ujCTf0HD09fGPKztU6aDoQsTE8Rmkh2USa3Sf48UFnT68aBHAseHLBpKRD1x J9Z194MTnw2+1t6tCV1FYX+Ahv3T6yHUz/Vdg5OIXPlM+awBJn46Xizo/j3b7Rm3HY5F T2u4ub6cEYXxuesmszGjlIlFQdnfgFjr5QzpwJGF0xm8RguwtYUoocAnvbjpF9dlojh9 dM1eQqMahvPP3ow3CUuV12u6yVFYYba1pe6edNfoOa8un36MtzEiuBAfBYNb0VM+KMYd tXLtk5UI3UBlEliFARspr9iDfk/EwLJTXOz13fggjr5bPoWnh6YSk/cj+UYN781TZ5AJ PJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qEilnvl1; 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 t8-20020a056602140800b0067536a57498si6330677iov.60.2022.07.15.07.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:46:25 -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=qEilnvl1; 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 729F181872; Fri, 15 Jul 2022 16:45:46 +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="qEilnvl1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 805CC817E6; Fri, 15 Jul 2022 16:45:37 +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-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (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 3D5938156B for ; Fri, 15 Jul 2022 16:45:29 +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-x52f.google.com with SMTP id r186so4602498pgr.2 for ; Fri, 15 Jul 2022 07:45:29 -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=+9zNreIx61ijwM9bTzD6Eyh3UNLNUdokSgBpEfNxtKo=; b=qEilnvl1XnvLDldqv88inorVnJsTAmSdM1HLdUVTIHKG0bBgzQUzF4eVVVMcMiWqAe c0L02Ol165PAzWInQhv7+ihDxwQTv+OIDdEcp/93CLB+bruSJ3tYwztumRV3smsQlCfq vuauXDwhFbwFO0xM9jKH/SKvRd7l+VTA8NOpoS9C9xhi60GI6KOaZpQTaIfL9bDNcslX P00RbuyNfbw1toTN6bfkY+Ys/uWZ5YjYWn4bQMfbqQG+1eK8Rj2wq7A6z8elgwEh4roj nIHow8BhFjUiqobMRj6hQN2ugFRPWuWR7JY2b85cxxGBQObMFb+8sEJLitQu3z4IbC1q Pptw== 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=+9zNreIx61ijwM9bTzD6Eyh3UNLNUdokSgBpEfNxtKo=; b=RZNIi1JtlQ0vP54UzVso/Qx4rGfpKZSPfMAQ9nBTR3pNHJ8Aalzxxh+Z/a+yPKHGGC Is1lqjzzk9ufJDbuhA9vjKNp5iy9aZp2zsjDq8ZrWgizJwMktCQwPO2wbeEBGt52ed7l u0lmRPVM5zF+JHTJPYFvpzuF38bKKREhGknSR3cZNzTgLf3J2qhJbG5Ex0D+d4CUR8/Q FMothR0PcPnBd0cUXU6VBTf1aWoPOEE4gDZIMs0CK3swU9S/AgoXhtI3yFWGOa+aYz9J Z9MRemad+rpngpyPMEyTwrgv6aNV52Ekm90Mi1IrEdjidKuMfn8zCVrerd87PvEH/5AV tZhw== X-Gm-Message-State: AJIora8Q7UVzofNKZ7YBD2E4eyvHIjNZyLuEmU+iT+NY/I8e+SU1Oh2V 31PFn6RfWDv3WNWWSjgd3CmYERDZF5AMfg== X-Received: by 2002:a65:49c5:0:b0:412:6e3e:bd91 with SMTP id t5-20020a6549c5000000b004126e3ebd91mr12616404pgs.221.1657896327385; Fri, 15 Jul 2022 07:45:27 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id u16-20020a170903125000b001690d398401sm3719923plh.88.2022.07.15.07.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 07:45:27 -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: [RESEND v9 6/9] eficonfig: add "Delete Boot Option" menu entry Date: Fri, 15 Jul 2022 23:47:46 +0900 Message-Id: <20220715144749.30564-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220715144749.30564-1-masahisa.kojima@linaro.org> References: <20220715144749.30564-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 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 aeb60f1d09..51d4e36a54 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1711,6 +1711,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 * @@ -1742,6 +1817,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}, };