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);