From patchwork Thu Jan 5 02:58:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 639241 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp27415pvb; Wed, 4 Jan 2023 18:58:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFZKV0bwehQt26cFIPtN/XCsxbVILfqtqmQsq+tS/XuT1UFiRcntas3xS3f2O3a9elfEah X-Received: by 2002:aca:1918:0:b0:35e:915c:f099 with SMTP id l24-20020aca1918000000b0035e915cf099mr23020695oii.21.1672887532325; Wed, 04 Jan 2023 18:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672887532; cv=none; d=google.com; s=arc-20160816; b=FU9ke/nD+Bh3rJ5/EkJd0NZfza7ko8n1NLSELf+0CSmbYHu++mjOtD+xIjejiI+/Oo MMt0wlmR4ibUSP/GR3E9bPtkbPWbbKReA5Amw6K8zuQklCjC+nGI7qlyCYG3Htqx3O59 zvrxMMidhcTQR4wH/t2cKRVxGYlzXOJplBT3Pqb+L7FUlvGK3VVWxAzdZ9iEx+fbwXhl LbQTq21RT8RGFQe1KSbQEQ/WFHAmrXqRsQHYulKVKO5G+aNOx+j3OG0ExgoK5KJxPoH7 mxJEVHp/OvFhGXqG7CRaXp8XQGRh1WvrZV+Bb8F4YJze4wN9fuP1X9g8yxkijgCgGaeQ mWYw== 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=hKLQGFYb9rXrw9OhT9t5rWH/+kUzOwppvDwomdPIrFk=; b=zHEX97Sg/8PegZ3yYLfBmW0UyONUNCSY/WlkPs1njtyGCjZBr/pveTToz+K/m8s49h XSfdQJG9o1nvqlrN7zf4AGXGkq/1NEf7AWtzEWyeRcYB+K0zL5e32YHRbrpG4VFbRXNi LXH9+tGbY+GWtTdXTZfT+j7nwbGwBXCfVtKORHZNaY9Vl6wEI92cx43ZlZ4bjfjrjITG Xmk4ogAO3t17LEmPLzcVKRdkOL+U/rlFA+OcQ39PwSWfaG+iqlfNohh0+8ja3qJopoZG NsIwCOq58Zxua5ZnXcakrzyvDOp6enH3nQnUzH//SgDHcENf1Oor8f330dvVDdLzPIQY hQNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="l7MVlJ/Y"; 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 a4-20020a9d5c84000000b0067576deda52si26315519oti.278.2023.01.04.18.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:58:52 -0800 (PST) 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="l7MVlJ/Y"; 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 358E685589; Thu, 5 Jan 2023 03:58:39 +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="l7MVlJ/Y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A675485592; Thu, 5 Jan 2023 03:58:35 +0100 (CET) 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-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 B6A3085574 for ; Thu, 5 Jan 2023 03:58:31 +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=masahisa.kojima@linaro.org Received: by mail-pj1-x1036.google.com with SMTP id ge16so34829615pjb.5 for ; Wed, 04 Jan 2023 18:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=hKLQGFYb9rXrw9OhT9t5rWH/+kUzOwppvDwomdPIrFk=; b=l7MVlJ/YYqGjqJPO0LA4lutiU9IvZGmkNKli2IqMyuLDT6qqmu8ZgLPp/Sard4JUBa IST+a8/OQ0GbJCP1/JYJYbsulsP6QpDycab0gTU5aJI9Cf7xxZfkPbv92uBAlWCCKt1D carBeL9FUrQB37s8s04oTavGtYZzXjJl7Bc1K8DLNNfT46EmChyPfgR0FRWmfFtesgpe iP3UVMK95PLvi1PWQo7i3Ppeev2bCnGOtn83vAdVeedVM4PdQOLGb2aXNQrTRh3AvrXi 0Ih0E5oJup6u3RYCNjcmcz3qFrAZ8MB8ry68sa3f9gB1Tlucy/UAZLR6EDKc+ahjFyd+ RnBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hKLQGFYb9rXrw9OhT9t5rWH/+kUzOwppvDwomdPIrFk=; b=mBCFurYIcOAJJiOKA2ZvUcC87PxbF0xeBvS0jaNSRcv4XW6umXVynCuJleIF+HI3M7 ShMuUn3MccW7XpV4Nt4dzqmk54DKtD7kGc/yurAw0nn2jM726IsvqkIpWCcnfrRA1fPh SWw8esKaUuopHRq3VqRRIODi2p+HpbLPvrNQVgIaqE25X1H4kzIYPQQKl48Yv5XbfY5e rwrd1DgVtClYuhis5xI+yaY0yhQNcEUekuxTxh3+mhqkddD9o4pIHkAkvhPWipSEVn1g JAKU+K8oH1GG9e3lFJSSAs2rnCMGGkb/+YdhpWFSstGaGkzHa+sRE5pPrJ/seAsKy6j+ yv9A== X-Gm-Message-State: AFqh2koIM8rzOUvBJF3uIdqil3tKTAZfIZPGxWOz7WuUHokErV0KYz7H pYnN2xP26GMwI6l2jrrBCGn7U8jeLj/7veuQ X-Received: by 2002:a17:902:e742:b0:189:83bb:646f with SMTP id p2-20020a170902e74200b0018983bb646fmr73292960plf.17.1672887509921; Wed, 04 Jan 2023 18:58:29 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id g18-20020a170902869200b00192b23b8451sm10729546plo.108.2023.01.04.18.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:58:29 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v3 1/3] eficonfig: refactor eficonfig_process_common function Date: Thu, 5 Jan 2023 11:58:52 +0900 Message-Id: <20230105025855.16936-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105025855.16936-1-masahisa.kojima@linaro.org> References: <20230105025855.16936-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 Current change boot order implementation does not call eficonfig_process_common() and call own menu functions for display_statusline, item_data_print and item_choice. Change boot order functionality should call eficonfig_process_common() to improve maintenanceability. This commit is a preparation to remove the change boot order specific implementation. The menu functions (display_statusline, item_data_print and item_choice) are added as argument of eficonfig_process_common(). The menu description string displayed at the bottom of the menu is also added as argument. Signed-off-by: Masahisa Kojima --- Changes in v3: - modify "reverse" local variable type to bool Changes in v2: - add const qualifier to eficonfig_menu_desc, change it to pointer cmd/eficonfig.c | 71 +++++++++++++++++++++++++++++++++---------- cmd/eficonfig_sbkey.c | 18 +++++++++-- include/efi_config.h | 13 +++++++- 3 files changed, 82 insertions(+), 20 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index ce7175a566..274526fe20 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -21,6 +21,8 @@ #include static struct efi_simple_text_input_protocol *cin; +const char *eficonfig_menu_desc = + " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"; #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -133,10 +135,10 @@ void eficonfig_print_msg(char *msg) * * @data: pointer to the data associated with each menu entry */ -static void eficonfig_print_entry(void *data) +void eficonfig_print_entry(void *data) { struct eficonfig_entry *entry = data; - int reverse = (entry->efi_menu->active == entry->num); + bool reverse = (entry->efi_menu->active == entry->num); /* TODO: support scroll or page for many entries */ @@ -160,7 +162,7 @@ static void eficonfig_print_entry(void *data) * * @m: pointer to the menu structure */ -static void eficonfig_display_statusline(struct menu *m) +void eficonfig_display_statusline(struct menu *m) { struct eficonfig_entry *entry; @@ -170,10 +172,11 @@ static void eficonfig_display_statusline(struct menu *m) printf(ANSI_CURSOR_POSITION "\n%s\n" ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION - " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit" + "%s" ANSI_CLEAR_LINE_TO_END ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1, - entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1); + entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc, + entry->efi_menu->count + 7, 1); } /** @@ -182,7 +185,7 @@ static void eficonfig_display_statusline(struct menu *m) * @data: pointer to the efimenu structure * Return: key string to identify the selected entry */ -static char *eficonfig_choice_entry(void *data) +char *eficonfig_choice_entry(void *data) { int esc = 0; struct list_head *pos, *n; @@ -358,9 +361,17 @@ out: * * @efi_menu: pointer to the efimenu structure * @menu_header: pointer to the menu header string + * @menu_desc: pointer to the menu description + * @display_statusline: function pointer to draw statusline + * @item_data_print: function pointer to draw the menu item + * @item_choice: function pointer to handle the key press * Return: status code */ -efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header) +efi_status_t eficonfig_process_common(struct efimenu *efi_menu, + char *menu_header, const char *menu_desc, + void (*display_statusline)(struct menu *), + void (*item_data_print)(void *), + char *(*item_choice)(void *)) { struct menu *menu; void *choice = NULL; @@ -379,10 +390,11 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_heade if (!efi_menu->menu_header) return EFI_OUT_OF_RESOURCES; } + if (menu_desc) + efi_menu->menu_desc = menu_desc; - menu = menu_create(NULL, 0, 1, eficonfig_display_statusline, - eficonfig_print_entry, eficonfig_choice_entry, - efi_menu); + menu = menu_create(NULL, 0, 1, display_statusline, item_data_print, + item_choice, efi_menu); if (!menu) return EFI_INVALID_PARAMETER; @@ -641,7 +653,12 @@ static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *f if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, " ** Select Volume **"); + ret = eficonfig_process_common(efi_menu, " ** Select Volume **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + out: efi_free_pool(volume_handles); list_for_each_safe(pos, n, &efi_menu->list) { @@ -816,7 +833,11 @@ static efi_status_t eficonfig_show_file_selection(struct eficonfig_select_file_i if (ret != EFI_SUCCESS) goto err; - ret = eficonfig_process_common(efi_menu, " ** Select File **"); + ret = eficonfig_process_common(efi_menu, " ** Select File **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); err: EFI_CALL(f->close(f)); eficonfig_destroy(efi_menu); @@ -977,7 +998,11 @@ efi_status_t eficonfig_process_show_file_option(void *data) if (!efi_menu) return EFI_OUT_OF_RESOURCES; - ret = eficonfig_process_common(efi_menu, " ** Update File **"); + ret = eficonfig_process_common(efi_menu, " ** Update File **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); if (ret != EFI_SUCCESS) /* User selects "Clear" or "Quit" */ ret = EFI_NOT_READY; @@ -1323,7 +1348,12 @@ static efi_status_t eficonfig_show_boot_option(struct eficonfig_boot_option *bo, if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + out: eficonfig_destroy(efi_menu); @@ -1742,7 +1772,11 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, " ** Select Boot Option **"); + ret = eficonfig_process_common(efi_menu, " ** Select Boot Option **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); out: list_for_each_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); @@ -2563,7 +2597,12 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const a if (!efi_menu) return CMD_RET_FAILURE; - ret = eficonfig_process_common(efi_menu, " ** UEFI Maintenance Menu **"); + ret = eficonfig_process_common(efi_menu, + " ** UEFI Maintenance Menu **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index ed39aab081..caca27495e 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -410,7 +410,10 @@ static efi_status_t enumerate_and_show_signature_database(void *varname) goto out; snprintf(buf, sizeof(buf), " ** Show Signature Database (%ls) **", (u16 *)varname); - ret = eficonfig_process_common(efi_menu, buf); + ret = eficonfig_process_common(efi_menu, buf, eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); out: list_for_each_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); @@ -472,7 +475,11 @@ static efi_status_t eficonfig_process_set_secure_boot_key(void *data) efi_menu = eficonfig_create_fixed_menu(key_config_menu_items, ARRAY_SIZE(key_config_menu_items)); - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) @@ -518,7 +525,12 @@ efi_status_t eficonfig_process_secure_boot_config(void *data) break; } - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) diff --git a/include/efi_config.h b/include/efi_config.h index fd69926343..cec5715f84 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -9,12 +9,14 @@ #define _EFI_CONFIG_H #include +#include #define EFICONFIG_ENTRY_NUM_MAX 99 #define EFICONFIG_VOLUME_PATH_MAX 512 #define EFICONFIG_FILE_PATH_MAX 512 #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16)) +extern const char *eficonfig_menu_desc; typedef efi_status_t (*eficonfig_entry_func)(void *data); /** @@ -45,6 +47,7 @@ struct eficonfig_entry { * @active: active menu entry index * @count: total count of menu entry * @menu_header: menu header string + * @menu_desc: menu description string * @list: menu entry list structure */ struct efimenu { @@ -52,6 +55,7 @@ struct efimenu { int active; int count; char *menu_header; + const char *menu_desc; struct list_head list; }; @@ -86,9 +90,16 @@ struct eficonfig_select_file_info { }; void eficonfig_print_msg(char *msg); +void eficonfig_print_entry(void *data); +void eficonfig_display_statusline(struct menu *m); +char *eficonfig_choice_entry(void *data); void eficonfig_destroy(struct efimenu *efi_menu); efi_status_t eficonfig_process_quit(void *data); -efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header); +efi_status_t eficonfig_process_common(struct efimenu *efi_menu, + char *menu_header, const char *menu_desc, + void (*display_statusline)(struct menu *), + void (*item_data_print)(void *), + char *(*item_choice)(void *)); efi_status_t eficonfig_process_select_file(void *data); efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size, u32 *index); From patchwork Thu Jan 5 02:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 639242 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp27472pvb; Wed, 4 Jan 2023 18:59:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKWDb/8sq5m8trg1efmnGF9yd6cEeELnwPAuObds0EcK7X7X8NywfQioWlrVQ+6q+TiGRO X-Received: by 2002:a9d:738e:0:b0:670:4588:f8c4 with SMTP id j14-20020a9d738e000000b006704588f8c4mr23330118otk.18.1672887543966; Wed, 04 Jan 2023 18:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672887543; cv=none; d=google.com; s=arc-20160816; b=A0jQ4DgSacf0oQb8PLLU21JEVmRudQgGLI9zLBQmPf1gC0XB+oZ6hla5kzRxtlmq4r PdwUZcHshkYCRTa7fske5VLDgGP+7wON/tPheIwHVp3T2kw5SGSkMnYB7SS2OKbl3rCf 024k95bv0d9A3WBsMlW2bDzYIkLNVLzqaJje+8RHcXEhO8wJ4+mMlId/fgSq6PIrQFh0 UA2Iz5WOEi510yPxetumRYvk6Y6WeWzzS71Uh/dHe+y7vQHuphmnHMZA2/BEeObawwen lfB46P7My4SX6PoJM67Kkfp8lFKaEjjnHeme2g0thpvKOz3a3A0tLkCzX4mOs4BBA/DV jiZA== 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=Ue+2ludgY16eB9R1vezjvkjNVOh8bNAds2fkR+vPbiM=; b=Sd+EP1pfp7WcsQbzLmDkIfK8Zdn5O+FwAGtHfRotgzamESvSyWPy1JrtQZY12kyjMt luArx+I8EwyvD9IZ2ikmixOX0UR0qU8XznBvlMW++eVt8FmY60WzE8/G1QcN9Y4MMFXg DKlUlWpjAoqJKN9VqhziAEvLAwO7z4HYyZ66Pam+XcRvMgD0lxiR2Me6anthYTlZWWQe atxohj4LqPLxm52pkpcIRx+TBzQZ9AR+Ss1mD5ZHQnsmozr7i6QBrtQ1r2nf8vzG6KTQ 4I3fv95D0IqAlRsxC1LlM0peI9/ZSydGR+O+dUAZAiUJOAW+jDDeZZaWcQ1RTpeKeg+M HC9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="FpyIXvx/"; 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 ch11-20020a056830638b00b00666a34fdee5si30091072otb.74.2023.01.04.18.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:59:03 -0800 (PST) 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="FpyIXvx/"; 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 3A4798558F; Thu, 5 Jan 2023 03:58:44 +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="FpyIXvx/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 739978557E; Thu, 5 Jan 2023 03:58:38 +0100 (CET) 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-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 24BF585587 for ; Thu, 5 Jan 2023 03:58:34 +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=masahisa.kojima@linaro.org Received: by mail-pl1-x62d.google.com with SMTP id n4so38083774plp.1 for ; Wed, 04 Jan 2023 18:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=Ue+2ludgY16eB9R1vezjvkjNVOh8bNAds2fkR+vPbiM=; b=FpyIXvx/w3Sofhd3TcD9DRm1RePNM76A4YRLg+7woZiQYHvTBBVLazWr9DgLkYQU+f g2tBFb7BjoTtWIgBugP6mFppjp84zhDxm0zx1cxJkF6H3LoAb6A+B0/cUKkCGGlVUAdY OV09WB6hTplVatWtcUhWHLz3D7H3h5JGb+vozau7zHfPXbBUbaoj734YVlQgAoeA3RY+ 2DyK8bl/2R4TyOck3ojNVYEm0i7AaE81a/aozpI6iRcxhpvRoVArXrwWgDdyVWjaxiK/ BsbfsHbCcwTGM7YHqg8OlY4tqEOD30A8N5QOr4kFmhsj+z+qHSArBE0tZhpCWadZDiMF fw2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ue+2ludgY16eB9R1vezjvkjNVOh8bNAds2fkR+vPbiM=; b=GX85/Vw8jho2wiwjM/8WfKJyMlqJPZueDLbBpOVwoeWZdzZWsf7Gpwb7P4PKRS4aK5 ocRNyetX33mb0pQn5jFVWk4/yc3Gx8f1IWv/YL+cdbClaOPgAHSwrwFwjWBoFEIB3f7l JHGRA1wEPkXZZpKi8TQryd1Fs6O6VsAkUhxO3F82sHXJFiqV0ydBlIhcaVk3Dp4QK3OS gxvNW0VTiZlLuSFkMQKSLPbeElfBgl28LPawfxWhe++jSlPfTupek7YbX+0L79nV9+UY 44olCU2TcKkpmr0FTzdTrZb3alorJa4H5ZlzWapEeicRgJL4xfkOuuaEGbhdruh5xFXf K9Pg== X-Gm-Message-State: AFqh2koatKAOkR4QSmdIfnNl/dOER7/VZsJ5t54cySBPG19G+4fMXpLR fzV65A/MhOX9/k32KZXib2zm5n/8Diy9SgGy X-Received: by 2002:a17:902:ab84:b0:192:e555:28e4 with SMTP id f4-20020a170902ab8400b00192e55528e4mr4653285plr.4.1672887511959; Wed, 04 Jan 2023 18:58:31 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id g18-20020a170902869200b00192b23b8451sm10729546plo.108.2023.01.04.18.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:58:31 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v3 2/3] eficonfig: refactor change boot order implementation Date: Thu, 5 Jan 2023 11:58:53 +0900 Message-Id: <20230105025855.16936-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105025855.16936-1-masahisa.kojima@linaro.org> References: <20230105025855.16936-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 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 Acked-by: Ilias Apalodimas --- Changes in v3: - modify "reverse" local variable type to bool Changes in v2: - add comment when the user key press is not valid - add const qualifier to eficonfig_change_boot_order_desc cmd/eficonfig.c | 245 +++++++++++++++++++++++++++++------------------- 1 file changed, 150 insertions(+), 95 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 274526fe20..6d5ebc4055 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -24,6 +24,11 @@ static struct efi_simple_text_input_protocol *cin; const char *eficonfig_menu_desc = " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"; +static const 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"; + #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) { - entry = list_entry(pos, struct eficonfig_entry, list); - reverse = (entry->num == efi_menu->active); + struct eficonfig_entry *entry = data; + bool 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,20 +1934,29 @@ 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; + } + /* Pressed key is not valid, wait next key press */ break; case KEY_SPACE: if (efi_menu->active < efi_menu->count - 2) { @@ -1961,15 +1966,18 @@ 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; } } } + /* Pressed key is not valid, wait next key press */ 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 */ + /* Pressed key is not valid, wait next key press */ break; } } @@ -2034,6 +2042,66 @@ 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; + + /* + * The change boot order menu always has "Save" and "Quit" entries. + * !(efi_menu->count - 2) means there is no user defined boot option. + */ + if (!(efi_menu->count - 2)) + 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; + } + + 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; +} /** * eficonfig_create_change_boot_order_entry() - create boot order entry * @@ -2050,6 +2118,7 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi efi_status_t ret; u16 *var_name16 = NULL; efi_uintn_t size, buf_size; + struct eficonfig_save_boot_order_data *save_data; /* list the load option in the order of BootOrder variable */ for (i = 0; i < num; i++) { @@ -2100,7 +2169,17 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi goto out; } - ret = eficonfig_append_menu_entry(efi_menu, title, NULL, NULL); + save_data = malloc(sizeof(struct eficonfig_save_boot_order_data)); + if (!save_data) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + save_data->efi_menu = efi_menu; + save_data->selected = false; + + ret = eficonfig_append_menu_entry(efi_menu, title, + eficonfig_process_save_boot_order, + save_data); if (ret != EFI_SUCCESS) goto out; @@ -2123,7 +2202,6 @@ out: */ static efi_status_t eficonfig_process_change_boot_order(void *data) { - u32 count; u16 *bootorder; efi_status_t ret; efi_uintn_t num, size; @@ -2144,47 +2222,24 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) goto out; while (1) { - eficonfig_display_change_boot_order(efi_menu); - - ret = eficonfig_choice_change_boot_order(efi_menu); - if (ret == EFI_SUCCESS) { - u16 *new_bootorder; - - 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; - + ret = eficonfig_process_common(efi_menu, + " ** Change Boot Order **", + eficonfig_change_boot_order_desc, + eficonfig_display_statusline, + eficonfig_print_change_boot_order_entry, + eficonfig_choice_change_boot_order); + /* exit from the menu if user selects the "Save" entry. */ + if (ret == EFI_SUCCESS && 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); - /* exit the loop when iteration reaches "Save" */ - if (!strncmp(entry->title, "Save", strlen("Save"))) + if (entry->num == efi_menu->active) break; - - data = entry->data; - if (data->active) - new_bootorder[count++] = data->boot_index; } - - 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); - - free(new_bootorder); - goto out; - } else if (ret == EFI_NOT_READY) { - continue; - } else { - goto out; + if (((struct eficonfig_save_boot_order_data *)entry->data)->selected) + break; } + if (ret != EFI_SUCCESS) + break; } out: free(bootorder); From patchwork Thu Jan 5 02:58:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 639243 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp27517pvb; Wed, 4 Jan 2023 18:59:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXt0nPTM5WOgfRfFiftILWid0ItXw63qZkj2b1qewlIrBfbsNAM584ITu6dwCrOF9CIroBti X-Received: by 2002:a9d:578c:0:b0:670:6b4d:78b5 with SMTP id q12-20020a9d578c000000b006706b4d78b5mr26866742oth.16.1672887556639; Wed, 04 Jan 2023 18:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672887556; cv=none; d=google.com; s=arc-20160816; b=aMDxRRDBJF2mg6uioTMv9DiOyFWrJQDBUH4s1bwejl3KMxL0m++0wKHPjkQM9JMCzt elE3FjXi/SfAKcJyY9TaoIZyCfe4c4NuRa1uHC06ye8NUIWoI1ZNL6B7iMNzBLOYXDaR KM1wS4ydUWHNREoi1sgq1keyrYB0S8ghODAmvugIWlB5lLrUpkIC8juINyOMD3WsiKS5 p7QxoJSUZylr8BhoXSR7yr379b8f3eV426nx+JR50z3YMXaJDn4+DLCn4Iw7djcNilc/ F563qDBtwNr8a2pjvEwSxB5M56dkVUapUUUJs6gv6dppIzaMqyaWakFnA0m4V3BgeB7c 99WQ== 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=OkQgxo/7EcS17JiG033aLF/gAqWLsnYpODzAnK6PgwQ=; b=kgw+5jDK2DHVQAmm0cWsKTlyDMj0OHsmPfVsPbLIwSHM0sTjwSxZHVr8Jt/n7gulp8 ssQDfwBTN8l2U/HG0kG5sSvAWnyIXBJyeBEW2m9nwi+H/BofZjcDyP3+NMXNApqTNNun qG/MLC3PIDH1ePatmn4oB5YHdHY3Qj/uTx3km3KaVoe45Dd0T9esJaWUhEg/0eK6kNwt +1Kh1ufsdzrU55IEmeIwSWCsgREofigKx83fN+jYjKVB0vC+OQt5BnzMJ0MCt/1tAfCR yHtBGd0qG/JECBwRnunJdq+gYcu/F+TN1hba0tscoU7Z1qxVlAu8aSY+1RGGlY1Lj/rr hvMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hCHo+D/a"; 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 v22-20020a544496000000b0035ecf6d61e9si27558986oiv.99.2023.01.04.18.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:59:16 -0800 (PST) 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="hCHo+D/a"; 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 3290B8559E; Thu, 5 Jan 2023 03:58:49 +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="hCHo+D/a"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F299085587; Thu, 5 Jan 2023 03:58:38 +0100 (CET) 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-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (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 BC7B38558E for ; Thu, 5 Jan 2023 03:58:34 +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=masahisa.kojima@linaro.org Received: by mail-pj1-x1031.google.com with SMTP id o21so8347486pjw.0 for ; Wed, 04 Jan 2023 18:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=OkQgxo/7EcS17JiG033aLF/gAqWLsnYpODzAnK6PgwQ=; b=hCHo+D/ao7RFhEDdJ2NhfhepHUd9SbFWKb3X0o9Vho4Kk+h9cmPGPG3vvJp9IzLesA 5aDgGmmoEEC06p1Bf8NcH3yhpfrzbr/lsXzK9fi7o6cY1p3tvhFpdePAsorCiICvLnhw RhezN9OwBIYjBddu0BSuGmOcqrml9hY4unQRHXEiKBe7dvhpVhXNcg4h9VMU3M083vou Jsy6/hLCTWinw40SvDrW/1yhU07D/66oVSty3LOPZe893jIkQcW7QyhoqW8XUXWX+xBa L7WfpHyeWXr004BTA8w2vThwi3cu8uGGEr3SWRcnYWmjMUdK1EizCfLhvaB4mvFBlUmn s+YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OkQgxo/7EcS17JiG033aLF/gAqWLsnYpODzAnK6PgwQ=; b=wDQCZe6mPAcJUNjGpKD7E2MwZXR3ZI+8mF2n8/1fHLROe9az6p9aGLkE6R3F6gL5wQ iPWyCAJ53f1hkvo0pLhtBTvanVS+RO9soORwKnyNiMSO9EVoXxu9fcaX4FIRB50ECcQe Mq3Y52YxbVV/EuxbuZHJV/7AkIvh5svMiRi4IRHN+bhMM+aVXe2iMWQnZquHB4vDdqlM ovwYWHXjYkCv+U+Gk3BPMx7wO15VYwCrkt8kVdpRFpQ+vGikkb88yOh+SlXjk/yFB9Y2 2LI4DzxufuIA95MKLFaomY7QC6J1OZF3kt5KEi9Eh0q2csq+OdPklBuUMSSv+ii2kOJS 4hDQ== X-Gm-Message-State: AFqh2kqHprVprd6eRe6cpSDah8kNB5Sr1coBpiQBypkBiqYRMySsxB5y jlEMMMtH1Gt62XZgL9yljBnCeDsLxk2bmLWe X-Received: by 2002:a17:903:2685:b0:192:bd33:7b59 with SMTP id jf5-20020a170903268500b00192bd337b59mr16246853plb.61.1672887514004; Wed, 04 Jan 2023 18:58:34 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id g18-20020a170902869200b00192b23b8451sm10729546plo.108.2023.01.04.18.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 18:58:33 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v3 3/3] eficonfig: add vertical scroll support Date: Thu, 5 Jan 2023 11:58:54 +0900 Message-Id: <20230105025855.16936-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230105025855.16936-1-masahisa.kojima@linaro.org> References: <20230105025855.16936-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 The current eficonfig menu does not support vertical scroll, so it can not display the menu entries greater than the console row size. This commit add the vertial scroll support. The console size is retrieved by SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode() service, then calculates the row size for menu entry by subtracting menu header and description row size from the console row size. "start" and "end" are added in the efimenu structure. "start" keeps the menu entry index at the top, "end" keeps the bottom menu entry index. item_data_print() menu function only draws the menu entry between "start" and "end". Signed-off-by: Masahisa Kojima --- No update since v1 cmd/eficonfig.c | 79 ++++++++++++++++++++++++++++++++++++-------- include/efi_config.h | 4 +++ include/efi_loader.h | 1 + 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 6d5ebc4055..bf765a239b 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -29,8 +29,13 @@ static const char *eficonfig_change_boot_order_desc = " Press SPACE to activate or deactivate the entry\n" " Select [Save] to complete, ESC/CTRL+C to quit"; +static struct efi_simple_text_output_protocol *cout; +static int avail_row; + #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 +#define EFICONFIG_MENU_HEADER_ROW_NUM 3 +#define EFICONFIG_MENU_DESC_ROW_NUM 5 /** * struct eficonfig_filepath_info - structure to be used to store file path @@ -156,18 +161,16 @@ void eficonfig_print_entry(void *data) struct eficonfig_entry *entry = data; bool reverse = (entry->efi_menu->active == entry->num); - /* TODO: support scroll or page for many entries */ + if (entry->efi_menu->start > entry->num || entry->efi_menu->end < entry->num) + return; - /* - * Move cursor to line where the entry will be drawn (entry->num) - * First 3 lines(menu header) + 1 empty line - */ - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); + printf(ANSI_CURSOR_POSITION, (entry->num - entry->efi_menu->start) + + EFICONFIG_MENU_HEADER_ROW_NUM + 1, 7); if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%s", entry->title); + printf(ANSI_CLEAR_LINE "%s", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -190,8 +193,8 @@ void eficonfig_display_statusline(struct menu *m) ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION "%s" 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); + 1, 1, entry->efi_menu->menu_header, avail_row + 4, 1, + avail_row + 5, 1, entry->efi_menu->menu_desc); } /** @@ -213,13 +216,23 @@ char *eficonfig_choice_entry(void *data) switch (key) { case KEY_UP: - if (efi_menu->active > 0) + if (efi_menu->active > 0) { --efi_menu->active; + if (efi_menu->start > efi_menu->active) { + efi_menu->start--; + efi_menu->end--; + } + } /* no menu key selected, regenerate menu */ return NULL; case KEY_DOWN: - if (efi_menu->active < efi_menu->count - 1) + if (efi_menu->active < efi_menu->count - 1) { ++efi_menu->active; + if (efi_menu->end < efi_menu->active) { + efi_menu->start++; + efi_menu->end++; + } + } /* no menu key selected, regenerate menu */ return NULL; case KEY_SELECT: @@ -399,6 +412,8 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, efi_menu->delay = -1; efi_menu->active = 0; + efi_menu->start = 0; + efi_menu->end = avail_row - 1; if (menu_header) { efi_menu->menu_header = strdup(menu_header); @@ -1865,7 +1880,11 @@ static void eficonfig_print_change_boot_order_entry(void *data) struct eficonfig_entry *entry = data; bool reverse = (entry->efi_menu->active == entry->num); - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); + if (entry->efi_menu->start > entry->num || entry->efi_menu->end < entry->num) + return; + + printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, + (entry->num - entry->efi_menu->start) + EFICONFIG_MENU_HEADER_ROW_NUM + 1, 7); if (reverse) puts(ANSI_COLOR_REVERSE); @@ -1916,8 +1935,13 @@ char *eficonfig_choice_change_boot_order(void *data) } fallthrough; case KEY_UP: - if (efi_menu->active > 0) + if (efi_menu->active > 0) { --efi_menu->active; + if (efi_menu->start > efi_menu->active) { + efi_menu->start--; + efi_menu->end--; + } + } return NULL; case KEY_MINUS: if (efi_menu->active < efi_menu->count - 3) { @@ -1933,11 +1957,20 @@ char *eficonfig_choice_change_boot_order(void *data) list_add(&entry->list, &tmp->list); ++efi_menu->active; + if (efi_menu->end < efi_menu->active) { + efi_menu->start++; + efi_menu->end++; + } } return NULL; case KEY_DOWN: - if (efi_menu->active < efi_menu->count - 1) + if (efi_menu->active < efi_menu->count - 1) { ++efi_menu->active; + if (efi_menu->end < efi_menu->active) { + efi_menu->start++; + efi_menu->end++; + } + } return NULL; case KEY_SELECT: /* "Save" */ @@ -2585,6 +2618,7 @@ static efi_status_t eficonfig_init(void) efi_status_t ret = EFI_SUCCESS; static bool init; struct efi_handler *handler; + unsigned long columns, rows; if (!init) { ret = efi_search_protocol(efi_root, &efi_guid_text_input_protocol, &handler); @@ -2595,6 +2629,23 @@ static efi_status_t eficonfig_init(void) EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (ret != EFI_SUCCESS) return ret; + ret = efi_search_protocol(efi_root, &efi_guid_text_output_protocol, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_protocol_open(handler, (void **)&cout, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + return ret; + + cout->query_mode(cout, cout->mode->mode, &columns, &rows); + avail_row = rows - (EFICONFIG_MENU_HEADER_ROW_NUM + + EFICONFIG_MENU_DESC_ROW_NUM); + if (avail_row <= 0) { + eficonfig_print_msg("Console size is too small!"); + return EFI_INVALID_PARAMETER; + } + /* TODO: Should we check the minimum column size? */ } init = true; diff --git a/include/efi_config.h b/include/efi_config.h index cec5715f84..6a104e4b1d 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -49,6 +49,8 @@ struct eficonfig_entry { * @menu_header: menu header string * @menu_desc: menu description string * @list: menu entry list structure + * @start: top menu index to draw + * @end: bottom menu index to draw */ struct efimenu { int delay; @@ -57,6 +59,8 @@ struct efimenu { char *menu_header; const char *menu_desc; struct list_head list; + int start; + int end; }; /** diff --git a/include/efi_loader.h b/include/efi_loader.h index 699176872d..91d8a5ef0c 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -328,6 +328,7 @@ extern const efi_guid_t efi_esrt_guid; extern const efi_guid_t smbios_guid; /*GUID of console */ extern const efi_guid_t efi_guid_text_input_protocol; +extern const efi_guid_t efi_guid_text_output_protocol; extern char __efi_runtime_start[], __efi_runtime_stop[]; extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[];