From patchwork Fri Jul 22 02:39:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 592449 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp99630mab; Thu, 21 Jul 2022 19:36:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ul1ZI9Dt2GnaY8nH1wW8U5IisSquPNKC7RAmI/Ew7JPpyBqNaEVchULTDsKjuxB3sC4XeP X-Received: by 2002:a05:6602:1653:b0:67c:22b0:8ba6 with SMTP id y19-20020a056602165300b0067c22b08ba6mr553591iow.157.1658457404985; Thu, 21 Jul 2022 19:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658457404; cv=none; d=google.com; s=arc-20160816; b=jO0RnRjSIL9X90yCf2sEdxVXqrXJDWjDLwTu95lAn1oiNsyDO3abhczAPd8+5xkgQn 1ThajGc2ZVmsYBcqSLpv2eBMdv5/tYH9CPMWd2Kgh04iYD6utz9YUneZUC6SkQ4Rolqx +f33wRDK87P51G6lMnfdYeZF2GOzXfaY0KYKOI9sL9k2ytezPwm9ThpyI3IV5l0LftCv KSe2BHPdqYphWCTnkhBMbSIheAzw4zN7mRQJBmeS3yCBXbAA7c2F7O5so+ia5Ie73Em1 VL17xzqDzf2TC+YQPScyeqVkUBMs2p834O/sVlTUX5aM6x5K+7YGIJACc59oErobXtFz sh9Q== 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=byVaoMAXnWSk1zL3aFGfuMXB718lgZu3Igdp7L8crB8=; b=UIIYajTPpWgZt3e7OpT1QsQdxZMoyIAHOIOuvIIaGh3SDP+u0bHo4ZjvD+w5JLg0nK 3lBBP/CGtlhjoqIVBIJ8kqePppzwg1665K54MO9zrCLaIafRXT0mDO38q/7xtbl48jE3 2ilPHS/bpBrCrlMPx7tZdARWYRGeH2EJQ8LNDrbD/I1H82xgGftFP37kKgDqQnkvYPiO BFTGcfeYCxIu98R5Q8LwmmvR2JCe54anbuOW9fNYci7djFElFmfXHtO0KTMN9K9jqg7X zjEDt4B5DMBSMrXgbdY27IJGPx2cEEkIuGK/+oRmGtsFGXA3y5hxlqW3VvkZkF9MpAXD hX1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qCb6Q3EI; 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 m7-20020a023c07000000b0033f4146e014si2637412jaa.5.2022.07.21.19.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36:44 -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=qCb6Q3EI; 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 516C28410F; 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=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="qCb6Q3EI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D98E084106; Fri, 22 Jul 2022 04:36:27 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 D372F840E6 for ; Fri, 22 Jul 2022 04:36:22 +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-x52b.google.com with SMTP id o18so3302906pgu.9 for ; Thu, 21 Jul 2022 19:36:22 -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=byVaoMAXnWSk1zL3aFGfuMXB718lgZu3Igdp7L8crB8=; b=qCb6Q3EI1kyF02+FhgKoBHx+dCjxoWPnw3W8d1oOm7QYnBSED3ej7Yw5ORubWAVMtD Js2N6btyl6c6RAD0z8NwgbOe13vn1KaWD36UHAB4K7GY7TQQdBYUt7vEPd/WrgvNdxhT qTFla+f1jea2rfWMvZFZZRVVbIZvm3wv6BkJGi/JiIJAVqAjObCfUPvhIjalDXMkH8Pv qT3Jx1ZmoG/qJyErpG13/JL584QF3YorPDRXsPtySZX3xI3OuigiO6boHVf1vNR5SfXA lWDKl9EuLUU0XVPbai74aeRIk/u/iPksQh6tpl7/rKhXO8+B2a+T2dNLqrzJL7xtbJHS piSQ== 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=byVaoMAXnWSk1zL3aFGfuMXB718lgZu3Igdp7L8crB8=; b=dF58X4nXuM0VRmwTOeAHzsAPwa1zsM6LThktjxwVz3rzhe5NgKnBz1EGBempCAumbJ xgIsygJnE4hUK61B7AfHNCWxkaxKEtgTz1aqY8oRzEt4YN7weQyibFfmtnqLfRrZ5FOH bA+o9HRkwe7ryUgHfvBFfyQoQ2MBiKPf2L5VbkJOUJslq6lGwFyyxQ4jZDGpk3Z/Pm0d 5K4BesHROmaMzl7zsw6gjSVu7RENZj2gfYJ9fWXTSr6WT55dN3+hJ4xN24AXQBEk51l2 P2yuicuigwxNxovAWkQePTuXvBRH/0RF9vN43iX7kbWknvWc5RRM3gYIu5gAlPbBHhU/ 5X9Q== X-Gm-Message-State: AJIora9yRBqCHBHwdzS7OYkaDmp+0yPggX2fOlkUsRj9XEIVbXuVBSpL h+F/UbVDZEAbAkr+boIjCfY2aDtZGneJLg== X-Received: by 2002:a65:6d1a:0:b0:3fb:2109:7b87 with SMTP id bf26-20020a656d1a000000b003fb21097b87mr1163176pgb.127.1658457380530; Thu, 21 Jul 2022 19:36:20 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 19:36:20 -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 03/10] eficonfig: add "Edit Boot Option" menu entry Date: Fri, 22 Jul 2022 11:39:12 +0900 Message-Id: <20220722023919.19676-4-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 edit the existing BOOT#### variable contents. User selects the item from the boot option list, then user can edit the description, file path and optional_data. Note that automatically generated boot option entry by bootmenu to support the removable media device is filtered out and user can not edit the automatically generated entry. Signed-off-by: Masahisa Kojima --- Changes in v10: - update eficonfig_edit_boot_option() argument Changes in v9: - add function comment Changes in v8: - fix menu header string - fix function and structure prefix to "eficonfig" Newly created in v7 cmd/eficonfig.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index a58c5a66ff..dc552e7ae1 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -81,6 +81,17 @@ struct eficonfig_file_entry_data { u16 *file_name; }; +/** + * struct eficonfig_boot_selection_data - structure to be used to select the boot option entry + * + * @bootorder_index: index in the BootOrder variable + * @selected: pointer to store the selected index in the BootOrder variable + */ +struct eficonfig_boot_selection_data { + u16 bootorder_index; + int *selected; +}; + /** * eficonfig_print_msg() - print message * @@ -1356,6 +1367,187 @@ out: return ret; } +/** + * eficonfig_process_boot_selected() - handler to select boot option entry + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_boot_selected(void *data) +{ + struct eficonfig_boot_selection_data *info = data; + + if (info) + *info->selected = info->bootorder_index; + + return EFI_SUCCESS; +} + +/** + * eficonfig_show_boot_selection() - construct boot option menu entry + * + * @bootorder: pointer to the BootOrder variable + * @count: the number of BootOrder + * @selected: pointer to store the selected index of BootOrder variable + * Return: status code + */ +static efi_status_t eficonfig_show_boot_selection(u16 *bootorder, efi_uintn_t count, + int *selected) +{ + u32 i; + efi_status_t ret; + efi_uintn_t size, actual_count = 1; /* include "Quit" entry */ + void *load_option; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + struct eficonfig_item *menu_item, *iter; + + menu_item = calloc(count + 1, sizeof(struct eficonfig_item)); + if (!menu_item) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + iter = menu_item; + for (i = 0; i < count; i++) { + efi_create_indexed_name(varname, sizeof(varname), + "Boot", bootorder[i]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + log_warning("Invalid load option for %ls\n", varname); + free(load_option); + continue; + } + + if (size >= sizeof(efi_guid_t) && + !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + /* + * auto generated entry has GUID in optional_data, + * skip auto generated entry because it will be generated + * again even if it is edited or deleted. + */ + free(load_option); + continue; + } + + if (lo.attributes & LOAD_OPTION_ACTIVE) { + char *buf, *p; + struct eficonfig_boot_selection_data *info; + + info = calloc(1, sizeof(struct eficonfig_boot_selection_data)); + if (!info) { + free(load_option); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + buf = calloc(1, utf16_utf8_strlen(lo.label) + 1); + if (!buf) { + free(load_option); + free(info); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + p = buf; + utf16_utf8_strcpy(&p, lo.label); + info->bootorder_index = i; + info->selected = selected; + iter->title = buf; + iter->func = eficonfig_process_boot_selected; + iter->data = info; + iter++; + actual_count++; + } + free(load_option); + } + + /* add "Quit" entry */ + iter->title = strdup("Quit"); + iter->func = eficonfig_process_quit; + iter->data = NULL; + + ret = eficonfig_process_common(menu_item, actual_count, " ** Select Boot Option **"); + +out: + iter = menu_item; + for (i = 0; i < actual_count; i++, iter++) { + free(iter->title); + free(iter->data); + } + + free(menu_item); + + return ret; +} + +/** + * eficonfig_process_edit_boot_option() - handler to edit boot option + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_edit_boot_option(void *data) +{ + u16 *bootorder; + efi_status_t ret; + efi_uintn_t num, size; + struct eficonfig_boot_option *bo = NULL; + + 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); + while (1) { + int selected; + void *load_option; + u16 varname[] = u"Boot####"; + + ret = eficonfig_show_boot_selection(bootorder, num, &selected); + if (ret != EFI_SUCCESS) + break; + + bo = calloc(1, sizeof(struct eficonfig_boot_option)); + if (!bo) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + bo->boot_index = selected; + efi_create_indexed_name(varname, sizeof(varname), + "Boot", bootorder[selected]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) { + free(bo); + ret = EFI_NOT_FOUND; + goto out; + } + + ret = eficonfig_edit_boot_option(varname, bo, load_option, size, + " ** Edit Boot Option ** "); + + free(load_option); + free(bo); + if (ret != EFI_SUCCESS && ret != EFI_ABORTED) + break; + } + +out: + 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 * @@ -1385,6 +1577,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}, {"Quit", eficonfig_process_quit}, };