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 6823EC00140 for ; Tue, 2 Aug 2022 07:38:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 96775810F6; Tue, 2 Aug 2022 09:38:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="PzfIrQNI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1AB00840F9; Tue, 2 Aug 2022 09:38:44 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 85E48810E8 for ; Tue, 2 Aug 2022 09:38:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659425920; bh=cturAfEd2CFrE3xmjhKmsZc/XlBx4BQKd69AoskII9M=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=PzfIrQNIbTC3vBvXq8BWQ3oFG2DKacKezxtRQF2ZI6VHB0eoxjLzDz5ICDcTXJEgP Xd90ECYG3ZCcjTLOYKLrQri/u2jpL6tQcY5ibXfj1QnzY9NQqUcVrgJJaUAj4qDkGo SbyCsgckG7bq+7hJTZdeUgQNhsVtNtCi+DceM7wY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([62.143.94.109]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MA7KU-1o8NR41kAE-00BZBS; Tue, 02 Aug 2022 09:38:40 +0200 Message-ID: <2d19f001-a3cb-735e-d615-2f23cb5b254b@gmx.de> Date: Tue, 2 Aug 2022 09:38:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [PATCH v10 03/10] eficonfig: add "Edit Boot Option" menu entry Content-Language: en-US To: Masahisa Kojima Cc: Ilias Apalodimas , Simon Glass , Takahiro Akashi , Mark Kettenis , u-boot@lists.denx.de References: <20220722023919.19676-1-masahisa.kojima@linaro.org> <20220722023919.19676-4-masahisa.kojima@linaro.org> From: Heinrich Schuchardt In-Reply-To: <20220722023919.19676-4-masahisa.kojima@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:WRrHUzmqmsND/pqYERlf7AzEktUGun93vLnq2ypk8Fb02KMwXLQ v5R10aDhnASyBSWt8vbNTAEOFxLjM19dI2P+bEnR2mkt44YKppASScIcLQ7ctrZo3HHFJOp UmbGs05+GTWE/O5o/z9QvjO9eX1U/KchYmHGCVOUyP7mgDKyU3iqqydfB45xi3plOcqNHI0 h5EsoknyyyUJvGPs4mlFw== X-UI-Out-Filterresults: notjunk:1;V03:K0:tRl5Dxe8Wl4=:+OuU5RH4UMgVnlhD+yDaVX Hlj+3ojquXhQkRRT9bp+LKuCtLUP8gOPqAbTSgQfNeonq8ALaPWqg2EzYsHIvwje1PqXjwtxC kybI2XEIVwayR3brGwRhmo2HOm2TnrDKnAIVOFS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.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 On 7/22/22 04:39, Masahisa Kojima wrote: > 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 selec= t the boot option entry > + * > + * @bootorder_index: index in the BootOrder variable I have defined multiple boot options. But the efidebug command does not allow to edit them. I just get an error message BootOrder is not defined! When BootOrder is defined I can only edit the BootOptions defined by boot order. Editing boot options *must not* depend on variable BootOrder. The only BootOptions that shall not be editable are the autogenerated ones media. Best regards Heinrich > + * @selected: pointer to store the selected index in the BootOrder var= iable > + */ > +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 en= try > + * > + * @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 =3D data; > + > + if (info) > + *info->selected =3D 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_u= intn_t count, > + int *selected) > +{ > + u32 i; > + efi_status_t ret; > + efi_uintn_t size, actual_count =3D 1; /* include "Quit" entry */ > + void *load_option; > + struct efi_load_option lo; > + u16 varname[] =3D u"Boot####"; > + struct eficonfig_item *menu_item, *iter; > + > + menu_item =3D calloc(count + 1, sizeof(struct eficonfig_item)); > + if (!menu_item) { > + ret =3D EFI_OUT_OF_RESOURCES; > + goto out; > + } > + > + iter =3D menu_item; > + for (i =3D 0; i < count; i++) { > + efi_create_indexed_name(varname, sizeof(varname), > + "Boot", bootorder[i]); > + load_option =3D efi_get_var(varname, &efi_global_variable_guid, &size= ); > + if (!load_option) > + continue; > + > + ret =3D efi_deserialize_load_option(&lo, load_option, &size); > + if (ret !=3D EFI_SUCCESS) { > + log_warning("Invalid load option for %ls\n", varname); > + free(load_option); > + continue; > + } > + > + if (size >=3D 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 =3D calloc(1, sizeof(struct eficonfig_boot_selection_data)); > + if (!info) { > + free(load_option); > + ret =3D EFI_OUT_OF_RESOURCES; > + goto out; > + } > + > + buf =3D calloc(1, utf16_utf8_strlen(lo.label) + 1); > + if (!buf) { > + free(load_option); > + free(info); > + ret =3D EFI_OUT_OF_RESOURCES; > + goto out; > + } > + p =3D buf; > + utf16_utf8_strcpy(&p, lo.label); > + info->bootorder_index =3D i; > + info->selected =3D selected; > + iter->title =3D buf; > + iter->func =3D eficonfig_process_boot_selected; > + iter->data =3D info; > + iter++; > + actual_count++; > + } > + free(load_option); > + } > + > + /* add "Quit" entry */ > + iter->title =3D strdup("Quit"); > + iter->func =3D eficonfig_process_quit; > + iter->data =3D NULL; > + > + ret =3D eficonfig_process_common(menu_item, actual_count, " ** Select= Boot Option **"); > + > +out: > + iter =3D menu_item; > + for (i =3D 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 =3D NULL; > + > + bootorder =3D efi_get_var(u"BootOrder", &efi_global_variable_guid, &si= ze); > + if (!bootorder) { > + eficonfig_print_msg("BootOrder is not defined!"); > + ret =3D EFI_NOT_FOUND; > + return ret; > + } > + > + num =3D size / sizeof(u16); > + while (1) { > + int selected; > + void *load_option; > + u16 varname[] =3D u"Boot####"; > + > + ret =3D eficonfig_show_boot_selection(bootorder, num, &selected); > + if (ret !=3D EFI_SUCCESS) > + break; > + > + bo =3D calloc(1, sizeof(struct eficonfig_boot_option)); > + if (!bo) { > + ret =3D EFI_OUT_OF_RESOURCES; > + goto out; > + } > + > + bo->boot_index =3D selected; > + efi_create_indexed_name(varname, sizeof(varname), > + "Boot", bootorder[selected]); > + load_option =3D efi_get_var(varname, &efi_global_variable_guid, &size= ); > + if (!load_option) { > + free(bo); > + ret =3D EFI_NOT_FOUND; > + goto out; > + } > + > + ret =3D eficonfig_edit_boot_option(varname, bo, load_option, size, > + " ** Edit Boot Option ** "); > + > + free(load_option); > + free(bo); > + if (ret !=3D EFI_SUCCESS && ret !=3D EFI_ABORTED) > + break; > + } > + > +out: > + free(bootorder); > + > + /* to stay the parent menu */ > + ret =3D (ret =3D=3D 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[] =3D { > {"Add Boot Option", eficonfig_process_add_boot_option}, > + {"Edit Boot Option", eficonfig_process_edit_boot_option}, > {"Quit", eficonfig_process_quit}, > }; >