From patchwork Mon Jun 13 09:38:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 581416 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1798357max; Mon, 13 Jun 2022 02:39:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/0Jt32olLbFPB8vabvY+6TxqHM1T1Qfxda+9kY8urAZI5UYy90pup3ucNdn+amQA8mmLi X-Received: by 2002:a05:6602:26d1:b0:669:734a:4c8a with SMTP id g17-20020a05660226d100b00669734a4c8amr16044843ioo.209.1655113185792; Mon, 13 Jun 2022 02:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655113185; cv=none; d=google.com; s=arc-20160816; b=BjnXDPMZ6c99KHCgPUH+lHehAo+af4fQ7Gwxz+/jRCgVygnx0Y3BCngR7ey4PE6+hr RQgwHlXGK54W/pTJGDEe8XN2a289ThJoF7h+AxFuBNKDG39OWr2kIvVdLdX8kSfFmEaI GRxqRqNWvGimHWsbO4HqQJKPZx4asNfnuQhohYIS2YT5augR0DTUhi0PLO6Gyogo2he7 3XzBghKEnd4Ilvx9zHfP3f3WpCy/VJI2jgqLBCyHM5a61DbsRvrEc6gRVaBGdWr2nAZa u/rCTxU7kDXtsbD6XNnfWv1Kh1o9IJ3hTFt9xbJiaTWgkb2V+U5s6qRdzUvTWZjT/VWL lLow== 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=wzS9GCSvOtEaOWH68WUJ5XdcnFyLi3UNyKkWlC/jMmA=; b=TWcLVLPvYtje7Wt4LTpvSAtQ90PxY7K16+ElKMI2YFciDgovBtu+c6Z7GMHRNf3D0Q 5uH5lyc+gxmSrcs15YcWW2jF6/92uSDnZGpwGjlNAtZNZIac4RMQBgqoQn1UxS7esf0c 6baDNOb+hf6vx/AOgyq0/NxbPpy1n0P+BHWZUt4wgbSZEbSjaniQvUyU3l+fNl5qpem9 h9+DNH298wUVQDFxaXxmZDIIHjeaEvbbKDzk6DPT1ZguVhyISP4UMSVzmWiTKpbTVehj /iTjydJbwwcmfAgmIBuorUoXAfjZDtXvDkJf3pWl6TCdr6X7cmhvrODldr/Shv+9a1XG jBRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fgb9rZIn; 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 h5-20020a92c265000000b002d3da8d76cfsi8834202ild.156.2022.06.13.02.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 02:39:45 -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=fgb9rZIn; 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 8AD518444C; Mon, 13 Jun 2022 11:38:44 +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="fgb9rZIn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AF5178443E; Mon, 13 Jun 2022 11:38:38 +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-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 D969A84411 for ; Mon, 13 Jun 2022 11:38:35 +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-pj1-x1032.google.com with SMTP id k12-20020a17090a404c00b001eaabc1fe5dso2431386pjg.1 for ; Mon, 13 Jun 2022 02:38:35 -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=wzS9GCSvOtEaOWH68WUJ5XdcnFyLi3UNyKkWlC/jMmA=; b=fgb9rZInOSUYG5jvGnxsOUiX2sEbeTOh0FRNj+u8JMQVViQ8K7hD1RcZDfEqLz5vSx d/R4sgzHYGwvpihdVcpo/JUZm9f5vKdYx8/Y/i+xXRAt1SNgcQrPqvbMZAwQ8K55TyhX ooWKVVuZFLEw8GpatDTPZWGckDtfZfsQhVvjpYZZH5EyomzQLDbCvwh9l9SKgnZJvMAk ATrEJhF2sA+fRpp9ZkB5x3RAJAsjbMFfiuUwB1QE2pAu8YEB/euWL5mv6wQ4HCWxmhd/ 5rjlNDtXKRI5ZS3GfMcxnT3CGJw34GVgtqWYRaBBhjHTOmwy4npswnOR27uWKGUL0AvJ i2lA== 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=wzS9GCSvOtEaOWH68WUJ5XdcnFyLi3UNyKkWlC/jMmA=; b=tEQ9KMFVkY1gOvEttyudTJs+xp7PoqW5zkV1moSfvd97O7XepWNvJmTuct1yTT8MwR PuPRYE2b3TmBd8EYUSBDDrSVPvMKdtZxbm9aiaktkeSEl6ylaSHftxlDl/KtKeH9MJvw V+J0Ij7ZDixWCJH3cVTLk0eLwgkGjOkVJsPXpLC2yImbqeb/edS8eyAnvXnWO3Iawju5 wmyAULo3DEmqnaV2xTAE7O/rBN6uocjZalXzWBVXDK7VULu06+OJCqgvOgC7dfadvsXx r7IIL8c/9WSis1pTLDQAZ1feuKSu608G0g8C+Gy9tGWwXcBR5usHBQjjFifJixb9/81A n5uQ== X-Gm-Message-State: AOAM533FA+FptKckYJMCRsp+qD8PrTbk1TVNMjd3u8e3l/eJrdh0PgiD UyTY8pMK8hu6/wgo67/AtLiHL/62znry+Q== X-Received: by 2002:a17:902:bd05:b0:15f:19a0:95ed with SMTP id p5-20020a170902bd0500b0015f19a095edmr57540878pls.31.1655113113837; Mon, 13 Jun 2022 02:38:33 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b00163f7935772sm4629227plb.46.2022.06.13.02.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 02:38:33 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v7 6/9] efimenu: add "Delete Boot Option" menu entry Date: Mon, 13 Jun 2022 18:38:50 +0900 Message-Id: <20220613093853.23865-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220613093853.23865-1-masahisa.kojima@linaro.org> References: <20220613093853.23865-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.5 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 v7: - to stay the boot order list after user delete the entry no update in v6: changes in v5: - split into the separate patch cmd/efimenu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/cmd/efimenu.c b/cmd/efimenu.c index 1be483a082..1c97f265ca 100644 --- a/cmd/efimenu.c +++ b/cmd/efimenu.c @@ -1565,6 +1565,66 @@ out: return ret; } +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; +} + +static efi_status_t efimenu_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) { + ret = EFI_NOT_FOUND; + return ret; + } + + num = size / sizeof(u16); + ret = efimenu_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; +} + static efi_status_t efimenu_init(void) { efi_status_t ret; @@ -1600,6 +1660,7 @@ static const struct efimenu_item maintenance_menu_items[] = { {"Add Boot Option", efimenu_process_add_boot_option}, {"Edit Boot Option", efimenu_process_edit_boot_option}, {"Change Boot Order", efimenu_process_change_boot_order}, + {"Delete Boot Option", efimenu_process_delete_boot_option}, {"Quit", efimenu_process_quit}, };