From patchwork Wed Dec 21 13:50:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635627 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3519938pvb; Wed, 21 Dec 2022 05:51:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXud31qAtVzUyHD/Zv07gOsYF+19QTpzXIW7DxYogDt6YXfEYQYt9yga4JRrvUPG8f3SM783 X-Received: by 2002:a05:6870:8224:b0:143:bef9:14cf with SMTP id n36-20020a056870822400b00143bef914cfmr459960oae.13.1671630684092; Wed, 21 Dec 2022 05:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671630684; cv=none; d=google.com; s=arc-20160816; b=Fx34iHfzV+sk79e8I6QI0YJxZ2FBN5Ym1ys9jKtuqmIypWa0tIOxm0w5OjSEDxP8f2 X9ZzUAD1RQdZlov6hgYe8pBx3ecm+u/OXQ8UM6+6OuL8Oag24ed/qb0PEk4o00mOXdMB IFRCGHCwZHCqpK0vJtSd2LMifjmTaNPie4twe6ChjawcDUZWDYYpVvsf//oTuxOPiBWz rVUUp8jsJUeZdpUOBnHOXwK3RS5AkJUR+Tj374VfLGwKlkfdAbV2Vmdeb8YI4S0KJuwN TjxKv//Ks1iOGRAskmmys8ig7izlMLHN+bJNofEIXTQa2sBGLJacRtPcPlZAscMe4F+z a5dA== 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=LUPUr/RT5hBdidBgSWC5PARLUEakNBNW8Mecn1dJiTg=; b=XZDiocb34bbA3Ir6dxlyHOZuRc7sedwHC9ashMCuBuvhnE3xc99GDlzBGsaPyKk7Wx /em5nL8sJ8Aq9JaDDAqYEqs3Nx7w1DUZLNWuWIF26M2KK3LADetd380TlLdXlBwuY5MZ KdpUBQErsnZj/57jVogiRgarmPEE4czBgvvLc90wUpBwzUvu9fGklkVlvwZZps38wZV8 u0wq9p0A2VmNXBvZup8jIXwuJZ44LMroGrwDvEty1oec1G1G9cGBmd15hV4XIAbZWJkt PjoZnaaCr1GFgKLMh1Qf3Fb6LePUaC1Y6We5txjf5yQk8a/3GpOpJ/UW93leOqAKdJ0u fvIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ykbo4Cj2; 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 pn21-20020a0568704d1500b00132d3152344si10349476oab.163.2022.12.21.05.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:24 -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=Ykbo4Cj2; 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 6E86185406; Wed, 21 Dec 2022 14:51:14 +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="Ykbo4Cj2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 44D4E85422; Wed, 21 Dec 2022 14:51:07 +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-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 3C43985351 for ; Wed, 21 Dec 2022 14:51:03 +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-x102b.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so2136228pjj.4 for ; Wed, 21 Dec 2022 05:51:03 -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=LUPUr/RT5hBdidBgSWC5PARLUEakNBNW8Mecn1dJiTg=; b=Ykbo4Cj2SdbhO4eDBXopHenO7Ud48Lvl1oIIj+UID6c8Ln3RK8yO/0EBJmkhZG7asl Qa7oJM6o4oP0Baz0RXIdDuos/FFoGR44RaJZ6ECI+M8dr2DMkKvdq70yGtJfS9k4dIxg VJofpsiIhTS6WZeSfHR0hOAFEcDaM8ngFuiBQ31WLzMx2WbtWGz8b3oMd0HvI3alzW9F 6XISgYUXYUBbrKr238L0+JB2B0HJ+KW64hAXqUB/VUIJfxrbqXrKWvDDY1Ye68P5kssH Qf745BJZhWL0yEG5W+E55tsp3qRDBVQTh5ZiBkfcveCCL6G5kYXCXLRg7Ve6g8N4nqE4 YxuA== 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=LUPUr/RT5hBdidBgSWC5PARLUEakNBNW8Mecn1dJiTg=; b=AT4IIVgHqAbp9dGf3uJrnB1eJTelDutf1b/f4IM7p423iAW3hwyXu66eNQAEwbQwA3 FEck2N7Il5VGFCXxjTzF49aIoT/E/sZWFqRPaol2f42qP5z0zn8yHa7OCeUx6/yDz1UY rS3TDQ1Uaakdfpis01azEZNrr+FRZJJbKhqJqBT6rxP1i71kTO1UlAVMzUlr6rU60KJu oV33/SkwFy87rUsNpm3qqEhBtDsra6sA2jlIQx26YYiVpQaEwPNi3vU5n9S4rYVQi6xq tYOsRn/pH30VoNNGoZ+7Nm6kjM6HCUOmYIBoDnG0EWLKuWAFD9Phz8z8ajUJ9E/M9xgx 6aBg== X-Gm-Message-State: AFqh2kqgLlprWTQ1anqVPBLlQy9jYsMQ8MAyo5V51YcMIYja2I70fH5e we7SRGx3bOrNETuapjbVxPtgJv3ygFRi+olM X-Received: by 2002:a05:6a20:6d20:b0:ad:dcdf:8c26 with SMTP id fv32-20020a056a206d2000b000addcdf8c26mr2730153pzb.21.1671630661221; Wed, 21 Dec 2022 05:51:01 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h10-20020aa796ca000000b00571cdbd0771sm10618227pfq.102.2022.12.21.05.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:00 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 1/3] eficonfig: refactor eficonfig_process_common function Date: Wed, 21 Dec 2022 22:50:36 +0900 Message-Id: <20221221135039.32349-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221221135039.32349-1-masahisa.kojima@linaro.org> References: <20221221135039.32349-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 --- cmd/eficonfig.c | 69 +++++++++++++++++++++++++++++++++---------- cmd/eficonfig_sbkey.c | 18 +++++++++-- include/efi_config.h | 13 +++++++- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index ce7175a566..39ee766a7b 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -21,6 +21,8 @@ #include 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"; #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -133,7 +135,7 @@ 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); @@ -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, 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..9432d13f2e 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 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; + 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, 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 Wed Dec 21 13:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635628 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3520039pvb; Wed, 21 Dec 2022 05:51:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlchj9DleLys05HOAAvnJuaTVkuUnmpE9UBsk62lauRsVWFtb1e9CQ09T41IOrOejkaeHx X-Received: by 2002:a9d:6c5:0:b0:670:7e0a:e742 with SMTP id 63-20020a9d06c5000000b006707e0ae742mr835114otx.27.1671630697434; Wed, 21 Dec 2022 05:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671630697; cv=none; d=google.com; s=arc-20160816; b=adSSjBSsc0lW07OWk6nAruKbirvLlVljKAwwx+g1hi7XmPlFmbvKHRNPEwEZ1xQetG l6o7HiBlI3OO5pXdnf5h4QWa79IijMd8l2XOpZ65T0hE2D3rBAJAaJhMgJ+l7oYgey/Q WrFtcUJa8+goi5mQDX2BiQjdl+8aT4wLEVwR7FgmNEq3hnJv9nQfwm16IbjKJWdgJTFY CVEK4uJAHgzXdV1HK94+ONOhwBX/bZJLMYmUwdQiocrYuwPKsucE2z9rJFQQ5DnzJPnn 4c+VLCg9SU8ryIiw9uL6w0/Cn9w5qRe5YFAXparH2v7pfOhqd4KJFl8dUa2t3Mf7WGos LLHQ== 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=/CIbhl+PRKJceOmJxmfaChwxczXUrqkztMKU3DvqPqM=; b=awh8eSz2jiUsf8gDfElG3jfL6+Y6NABbQ85d4Di1UgA3KaMkS8Nzq96HyRjkhVadID Kvlivv7Eelq9a5LdwnDT6NfHP1uj8yrXOP35iUKC041nhrjDPlPruA86mh3K0ap4Zojz Kgdsm2VhMxmW9bAWgSEhr+t+byrPZbvFuvkkuRkRYkWRamhH+tkegTdwAsVQf5Ozu6Es PTAd+3OpvEToafi6MmbPF2VwhKlk0wQHDmkC0TaAF/yWljfcu9P+ti9fmf5s6ZXTMdoF fbFjVTl0DHsQqwTsIduADXIncclMOGKccvyst7qsTdmRbxBYQxcH1imTC6C+0jTbBFjh KPYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kpLQR99o; 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 m27-20020a4a241b000000b0049fd55960e3si11851460oof.43.2022.12.21.05.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:37 -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=kpLQR99o; 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 9442285440; Wed, 21 Dec 2022 14:51:17 +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="kpLQR99o"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC0CD85406; Wed, 21 Dec 2022 14:51:10 +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-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 61FD9852F8 for ; Wed, 21 Dec 2022 14:51:05 +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-pf1-x42f.google.com with SMTP id d82so10704302pfd.11 for ; Wed, 21 Dec 2022 05:51:05 -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=/CIbhl+PRKJceOmJxmfaChwxczXUrqkztMKU3DvqPqM=; b=kpLQR99oR1Y3qXExaMUMUeZ2ohrAPsormS2Ucb8WXduNTp1Dldd4csmITFuJRB4QVy HyhiNr4azJgxezORdIpYERjhFmGBFzaenkujMo7lKmZE95l6o86qFEJqgSSxcMMCAMYO vkHwZ/LXp6wp7KiAgT0yri+ij4omaAHTZYA04mtqwQAIoTc574UNjjyat1U5kagMDu7E pGZV6FA6tU5jtMc0xAY3G4kD/oeZaNIPfstEc9G93UBzBIN9duWWioY4iLKh89zfNQYh QG046ObENvqFTHfsB9ogLNMgn7xX41PzEoihgqX5tLxZAqOvDB/qD2pEaRc4h6+GhQcG tFOg== 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=/CIbhl+PRKJceOmJxmfaChwxczXUrqkztMKU3DvqPqM=; b=65r8sKVMXcidHzUmK3ZejdFfx5gAIdnRBOupASsHzhQhBk+UCnAAMb+hm0OWHk8acH S4/2yfT0ZIMfvM1fN5Cy/09eHiFuBffDKtjyyGUEDNCIdCB0FW0MwbIe7WhqdFfBwTW4 tm+wtuz8+Fyu0iW9c+s4UAroh8iwfp1xv4GU2iqkkGmWMYLcELpk1FUI9vKWfcAGL1ur ew3dpBTAGFsapt90QmPCq3ZSgg1nHNRNqe7eR7jwd/NagZcKhbWLl1Y8iKvYlf+MMdaC XPHng/9tPmmfZcTeY18lgryobjv5fwUSe8JsZ+2Psb8zyaE7xItYOUbB6OXUkO+uUojT XkSw== X-Gm-Message-State: AFqh2kr+8uLSxT2IL54EujckMMXxcFwpIQAYY/g8QSa251Ym0d6mqv2K qgnthBa0D77SfF2EpxKUNxxoPPxGJ4w5TvxL X-Received: by 2002:aa7:8eca:0:b0:572:24b7:af17 with SMTP id b10-20020aa78eca000000b0057224b7af17mr2501233pfr.10.1671630663320; Wed, 21 Dec 2022 05:51:03 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h10-20020aa796ca000000b00571cdbd0771sm10618227pfq.102.2022.12.21.05.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:02 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 2/3] eficonfig: refactor change boot order implementation Date: Wed, 21 Dec 2022 22:50:37 +0900 Message-Id: <20221221135039.32349-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221221135039.32349-1-masahisa.kojima@linaro.org> References: <20221221135039.32349-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 --- 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"; + #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; + 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; 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; + } + + 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 +2113,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 +2164,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 +2197,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 +2217,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 Wed Dec 21 13:50:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635629 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3520103pvb; Wed, 21 Dec 2022 05:51:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXufUIYuBzXomip2att/u064+0INoNKDfsVjwx98pnKp4npG1BXHskm/LQxHBU1mu8Jq+X6+ X-Received: by 2002:a05:6808:90b:b0:35e:a9d4:30d6 with SMTP id w11-20020a056808090b00b0035ea9d430d6mr7006828oih.44.1671630709032; Wed, 21 Dec 2022 05:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671630709; cv=none; d=google.com; s=arc-20160816; b=PGOcRnjJzjQIw89fyqVW6KguXsHNzWI7ouHB/BUnDpQ9IJRtmaYtMOQUrYRODLZHNb bOc27nGgF6QFmdufkkdjTyuA0xFEYFwcClu07/GE95RRy2Lw6LeBYp1LKl47hhcfwVzl 0WdLXe/05i6ZTsSVsZ9LZABInQiXsxWYnXb6te/9B0+LV/u1umOvnflYE7RuEnb8MKc1 zR+2/7o99TFWZ9GZVINipwpnYQGwCjDNNe4B4aZagZdjXl1l6O5SRSOVdxnfm8QVGIlK Pb51lajdZVSqJpzNq5XSTzwaySza591hrBzmQIYcGjJoGpJy0Kc/dKx5u/EBEGM6SCfW Udng== 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=9t0XeEqf3kElZBMQa3PEHIDuNsaT6jdsb+D3a+zta9E=; b=VtrK/lNco0LX2z+zmgI98Q+rLYixxo2HdqOtgDUFotKaxoiYmAUrKb/wOhbAdkFBo5 L67uPRyzURclA67AH4sRUl5YNCeXoc/Oowi/fdK2CdP/CXTRCVkomX7lzHPtQWLuekX0 9+XfGpqLENBo+2USX4CgztGiDYmArb9+Dsesc7rnWJVQBQs6UMn1xdmsrIHiOBuPfFnx OIefNFCoekWZSs8FcQ2L9iPF3itHlHmN7wlsYeXkaF/59TU/zm4LBISF6GXo84BU7b2o PY9HOiFvw3W/iLwJ+wiqt2tnH1bZCUUVM7sNV9IiioQwdQC81ruZKcc5YlcoIvh4QHVT ezyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BKXlNKRZ; 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 w10-20020a056830410a00b0066ea531a0c2si13954602ott.327.2022.12.21.05.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:49 -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=BKXlNKRZ; 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 87C3E8543D; Wed, 21 Dec 2022 14:51:25 +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="BKXlNKRZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 94FB4852F8; Wed, 21 Dec 2022 14:51:13 +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-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 6EB7F85236 for ; Wed, 21 Dec 2022 14:51:07 +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-pf1-x42d.google.com with SMTP id t18so10698323pfq.13 for ; Wed, 21 Dec 2022 05:51:07 -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=9t0XeEqf3kElZBMQa3PEHIDuNsaT6jdsb+D3a+zta9E=; b=BKXlNKRZkSwfuIFspk6IHpJB3qgszaY36LjovXlsOnN+ZLoW5WNjy17vaKa3/jOIxa mtXId7H6e9YeM8WkTDmygWGfvynAMGJAaZ9uP5FZMcJF8vxuyHkxPBOowH1RG72y9Bk1 ig3FYGQmkWqFtdK+JmExvfBWI7Znh/WPr8bcnO00FhtaTYOMw2yvJUINZUd7oTWQ3bnH xFVugIopL03KOEjYiWwc3U9ZpFvLoF6yflZem++T48aiWjfSN0vFW0NXQPVThXUe+oaa Rtjjy/qMydKLKesS7zkdGQKaH/qlIq4VVOu3kSL1/HCjJvStn0KZ7/1UcV1QWcwXtEdQ X7HQ== 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=9t0XeEqf3kElZBMQa3PEHIDuNsaT6jdsb+D3a+zta9E=; b=2BHeeaPCUFnQkDsgv1pp/+TWqWtGvKwbgE06L9Xjp1Q/zZahRf9ySqvJTF/tNSXhZM w/CMpwUOOMvk9l7PaY1troVk/xXkPKDFuQSzVnEpeQNKodB+8j1wj1Mnaj0Jw7W6Hb2+ qu/gMYahmTBxLSHo4rToO2ZCExObha92N/S3I2Kb4XUnqaQNt0sfpY93R70itc0gsaIw TmL7DR6z/8v99aWLKm4rO8uWqkRK88FG27Anv0vtHcKaOLMO6LufwOKeMfHsvw/llfqj SN5QLbWGPobbx/KxgSnPDjDBTGRtxMQifLbfpDyNjwWBvenu5Wcw3uFxetLD6JDbBYw4 eQjQ== X-Gm-Message-State: AFqh2kpRaqrAn0rsBrcPvUB6k7HZTAHHgxdB4iwqb2JIJxknZkt1eaKB UZtOAFsmc3KYPMg52QzGjed2xwHISc7j4WIv X-Received: by 2002:a05:6a00:300d:b0:577:b52:4ec3 with SMTP id ay13-20020a056a00300d00b005770b524ec3mr16487554pfb.22.1671630665408; Wed, 21 Dec 2022 05:51:05 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h10-20020aa796ca000000b00571cdbd0771sm10618227pfq.102.2022.12.21.05.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 05:51:04 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH 3/3] eficonfig: add vertical scroll support Date: Wed, 21 Dec 2022 22:50:38 +0900 Message-Id: <20221221135039.32349-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221221135039.32349-1-masahisa.kojima@linaro.org> References: <20221221135039.32349-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 --- 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 c2c6c01c3b..9b64fc4826 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -29,8 +29,13 @@ static 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; int 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; int 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" */ @@ -2580,6 +2613,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); @@ -2590,6 +2624,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 9432d13f2e..fa5f2ce090 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; 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[];