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 8005BC4167B for ; Thu, 22 Dec 2022 11:54:19 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DA04285245; Thu, 22 Dec 2022 12:54:16 +0100 (CET) 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="E6e1vHqS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 90441852AA; Thu, 22 Dec 2022 12:54:15 +0100 (CET) Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 55D6285245 for ; Thu, 22 Dec 2022 12:54:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x536.google.com with SMTP id r26so2561925edc.10 for ; Thu, 22 Dec 2022 03:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Hcq8W/lrTbrNn5GxQH2cU8j2P/aePpRYy81Z3BakfD0=; b=E6e1vHqSC1GUiGBniMmSdDJzGjKXgGSGnEuekjLXqeomB9I28frdMJh1vtL9wtda3D ad60pilnom5zHIYgRuuM8oaVK+5N7pAtX/rPj4q4yEbAF0QEu0uDcPeBO9ymhTozQ16S w2dZjXWTlhzZ3WZcVtsNgz3F1lQvx5CAAcUhzIejubiiyYDemOMLNRiTsEwoGYzeY8lC +S5cgjAfrD0aVaTFugaPE5ywq8AsQ8rpIVgd0BqeXTgOeH5tUFiuuMItY7Al4qNjCBoK WGCvdoE3IPgIVh9t5Q8Q/FEQIY/kK1E+fl4PscOQsZXYzwOYVnTnL4ftsPN93tuSW21A sV1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Hcq8W/lrTbrNn5GxQH2cU8j2P/aePpRYy81Z3BakfD0=; b=2mtPFqXL1LPqcw7CH2YpMyfXH1N7xws33aSdSi+H3B3RhYQFyDnutvhERjl3zvez59 RCf5AhQHVz93LILDXVH/slyOuFk5xrbk9QGe7S/mj2vyaMoqIPdIue0z4q3yjjTOyDne aqOYnZiUTCR7d1q3WTzv2hni2silkXBokQHRU+8aFNUhijRbFEaHptVGm7gPlw39+Q2d cEWKOAa/MVuTM+WoYSiY5zgcWbitlGVujm64tXay+V3FQhG0vsFlv7BJUyTBLKj+2ax6 g1/7+uKIKn+CS0H/Cld3MCeCS7mAMNkSZx+GSk2Bpsb90VABI6Uu4wD2v8XVXDgb1FOT CMKA== X-Gm-Message-State: AFqh2kpRXJI9vlY9VH75SSiaItmwWsp6/aSTY4Njl/kQm6jAaEIdfdhp Z/2JeKOZZ1g0z6YCjLGEUES2uQ== X-Google-Smtp-Source: AMrXdXvu+IKtGhOc3AxvNFMJTxn0KMBMLie4fWYFv9XEGjlxz1lrixPXpTZY2l7HAhj7e6VLNBiuCw== X-Received: by 2002:aa7:db47:0:b0:46d:b89a:de1e with SMTP id n7-20020aa7db47000000b0046db89ade1emr3883197edt.1.1671710051796; Thu, 22 Dec 2022 03:54:11 -0800 (PST) Received: from hera (ppp079167090036.access.hol.gr. [79.167.90.36]) by smtp.gmail.com with ESMTPSA id t4-20020aa7db04000000b0046f73b46c5csm301697eds.23.2022.12.22.03.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 03:54:11 -0800 (PST) Date: Thu, 22 Dec 2022 13:54:09 +0200 From: Ilias Apalodimas To: Masahisa Kojima Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: Re: [PATCH 2/3] eficonfig: refactor change boot order implementation Message-ID: References: <20221221135039.32349-1-masahisa.kojima@linaro.org> <20221221135039.32349-3-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221221135039.32349-3-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 On Wed, Dec 21, 2022 at 10:50:37PM +0900, Masahisa Kojima wrote: > This commit removes the change boot order specific > menu implementation. The change boot order implementation > calls eficonfig_process_common() same as other menus. > > The change boot order menu requires own item_data_print > and item_choice implementation, but display_statusline > function can be a same function as other menus. > > Signed-off-by: Masahisa Kojima > --- > cmd/eficonfig.c | 236 +++++++++++++++++++++++++++++------------------- > 1 file changed, 143 insertions(+), 93 deletions(-) > > diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c > index 39ee766a7b..c2c6c01c3b 100644 > --- a/cmd/eficonfig.c > +++ b/cmd/eficonfig.c > @@ -24,6 +24,11 @@ static struct efi_simple_text_input_protocol *cin; > char eficonfig_menu_desc[] = > " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"; > > +static char eficonfig_change_boot_order_desc[] = > + " Press UP/DOWN to move, +/- to change orde\n" > + " Press SPACE to activate or deactivate the entry\n" > + " Select [Save] to complete, ESC/CTRL+C to quit"; > + static const > #define EFICONFIG_DESCRIPTION_MAX 32 > #define EFICONFIG_OPTIONAL_DATA_MAX 64 > > @@ -105,6 +110,17 @@ struct eficonfig_boot_order_data { > bool active; > }; > > +/** > + * struct eficonfig_save_boot_order_data - structure to be used to change boot order > + * > + * @efi_menu: pointer to efimenu structure > + * @selected: flag to indicate user selects "Save" entry > + */ > +struct eficonfig_save_boot_order_data { > + struct efimenu *efi_menu; > + bool selected; > +}; > + > /** > * eficonfig_print_msg() - print message > * > @@ -173,10 +189,9 @@ void eficonfig_display_statusline(struct menu *m) > "\n%s\n" > ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION > "%s" > - ANSI_CLEAR_LINE_TO_END ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, > + ANSI_CLEAR_LINE_TO_END, > 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1, > - entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc, > - entry->efi_menu->count + 7, 1); > + entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc); > } > > /** > @@ -1841,63 +1856,44 @@ out: > } > > /** > - * eficonfig_display_change_boot_order() - display the BootOrder list > + * eficonfig_print_change_boot_order_entry() - print the boot option entry > * > - * @efi_menu: pointer to the efimenu structure > - * Return: status code > + * @data: pointer to the data associated with each menu entry > */ > -static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) > +static void eficonfig_print_change_boot_order_entry(void *data) > { > - bool reverse; > - struct list_head *pos, *n; > - struct eficonfig_entry *entry; > - > - printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION > - "\n ** Change Boot Order **\n" > - ANSI_CURSOR_POSITION > - " Press UP/DOWN to move, +/- to change order" > - ANSI_CURSOR_POSITION > - " Press SPACE to activate or deactivate the entry" > - ANSI_CURSOR_POSITION > - " Select [Save] to complete, ESC/CTRL+C to quit" > - ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, > - 1, 1, efi_menu->count + 5, 1, efi_menu->count + 6, 1, > - efi_menu->count + 7, 1, efi_menu->count + 8, 1); > - > - /* draw boot option list */ > - list_for_each_safe(pos, n, &efi_menu->list) { So this prints one option every time now instead of all the entries? > - entry = list_entry(pos, struct eficonfig_entry, list); > - reverse = (entry->num == efi_menu->active); > + struct eficonfig_entry *entry = data; > + int reverse = (entry->efi_menu->active == entry->num); > > - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); > + printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); > > - if (reverse) > - puts(ANSI_COLOR_REVERSE); > + if (reverse) > + puts(ANSI_COLOR_REVERSE); > > - if (entry->num < efi_menu->count - 2) { > - if (((struct eficonfig_boot_order_data *)entry->data)->active) > - printf("[*] "); > - else > - printf("[ ] "); > - } > + if (entry->num < entry->efi_menu->count - 2) { > + if (((struct eficonfig_boot_order_data *)entry->data)->active) > + printf("[*] "); > + else > + printf("[ ] "); > + } > > - printf("%s", entry->title); > + printf("%s", entry->title); > > - if (reverse) > - puts(ANSI_COLOR_RESET); > - } > + if (reverse) > + puts(ANSI_COLOR_RESET); > } > > /** > - * eficonfig_choice_change_boot_order() - handle the BootOrder update > + * eficonfig_choice_change_boot_order() - user key input handler > * > - * @efi_menu: pointer to the efimenu structure > - * Return: status code > + * @data: pointer to the menu entry > + * Return: key string to identify the selected entry > */ > -static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) > +char *eficonfig_choice_change_boot_order(void *data) > { > int esc = 0; > struct list_head *pos, *n; > + struct efimenu *efi_menu = data; > enum bootmenu_key key = KEY_NONE; > struct eficonfig_entry *entry, *tmp; > > @@ -1922,7 +1918,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) > case KEY_UP: > if (efi_menu->active > 0) > --efi_menu->active; > - return EFI_NOT_READY; > + return NULL; > case KEY_MINUS: > if (efi_menu->active < efi_menu->count - 3) { > list_for_each_safe(pos, n, &efi_menu->list) { > @@ -1938,19 +1934,28 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) > > ++efi_menu->active; > } > - return EFI_NOT_READY; > + return NULL; > case KEY_DOWN: > if (efi_menu->active < efi_menu->count - 1) > ++efi_menu->active; > - return EFI_NOT_READY; > + return NULL; > case KEY_SELECT: > /* "Save" */ > - if (efi_menu->active == efi_menu->count - 2) > - return EFI_SUCCESS; > - > + if (efi_menu->active == efi_menu->count - 2) { > + list_for_each_prev_safe(pos, n, &efi_menu->list) { > + entry = list_entry(pos, struct eficonfig_entry, list); > + if (entry->num == efi_menu->active) > + break; > + } > + return entry->key; > + } > /* "Quit" */ > - if (efi_menu->active == efi_menu->count - 1) > - return EFI_ABORTED; > + if (efi_menu->active == efi_menu->count - 1) { > + entry = list_last_entry(&efi_menu->list, > + struct eficonfig_entry, > + list); > + return entry->key; > + } > > break; I think I've asked about this in the past, but don't we have to return something here? > case KEY_SPACE: > @@ -1961,13 +1966,15 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) > struct eficonfig_boot_order_data *data = entry->data; > > data->active = !data->active; > - return EFI_NOT_READY; > + return NULL; > } > } > } > break; > case KEY_QUIT: > - return EFI_ABORTED; > + entry = list_last_entry(&efi_menu->list, > + struct eficonfig_entry, list); > + return entry->key; > default: > /* Pressed key is not valid, no need to regenerate the menu */ > break; > @@ -2034,6 +2041,62 @@ out: > return ret; > } > > +/** > + * eficonfig_process_save_boot_order() - callback function for "Save" entry > + * > + * @data: pointer to the data > + * Return: status code > + */ > +static efi_status_t eficonfig_process_save_boot_order(void *data) > +{ > + u32 count = 0; > + efi_status_t ret; > + efi_uintn_t size; > + struct list_head *pos, *n; > + u16 *new_bootorder; > + struct efimenu *efi_menu; > + struct eficonfig_entry *entry; > + struct eficonfig_save_boot_order_data *save_data = data; > + > + efi_menu = save_data->efi_menu; > + > + if (!(efi_menu->count - 2)) /* no user defined boot option */ > + return EFI_SUCCESS; > + > + new_bootorder = calloc(1, (efi_menu->count - 2) * sizeof(u16)); > + if (!new_bootorder) { > + ret = EFI_OUT_OF_RESOURCES; > + goto out; > + } > + > + /* create new BootOrder */ > + count = 0; > + list_for_each_safe(pos, n, &efi_menu->list) { > + struct eficonfig_boot_order_data *data; > + > + entry = list_entry(pos, struct eficonfig_entry, list); > + /* exit the loop when iteration reaches "Save" */ > + if (!strncmp(entry->title, "Save", strlen("Save"))) > + break; > + > + data = entry->data; > + if (data->active) > + new_bootorder[count++] = data->boot_index; The new_bootorder variable is allocated with the size of 'efi_menu->count - 2'. Should we add a check for count < efi_menu->count - 2 or are we always safe? > + } > + > + size = count * 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, new_bootorder, false); > + > + save_data->selected = true; > +out: > + free(new_bootorder); > + > + return ret; > +} [...] Thanks /Ilias