From patchwork Mon Oct 24 04:48:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617837 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483463pvb; Sun, 23 Oct 2022 21:49:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72+CBLopHCiJGJjMT+XpA8wC7N6IrfjXE8fQ0TKDl+XDhCTUCaS5vgVF56dZGAOm+jDw6k X-Received: by 2002:a17:906:1ec5:b0:78d:b3d1:183b with SMTP id m5-20020a1709061ec500b0078db3d1183bmr25615700ejj.709.1666586959141; Sun, 23 Oct 2022 21:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586959; cv=none; d=google.com; s=arc-20160816; b=I1Dr+ool5NFduVMGKqkFLxTPyn6/8gezgZ7rxhxi+qh39RHcyOEnbnymWH6GYO0RVj E8/WbCB5PFPYQP7VIdsCpgo/HcELQLiBVlxrs9QURhRWEbTx55JMGMlE8OTy46bMC/6D m6YTnuHSbjIip1b39FHJfoW1mtaDf+aWgGz9aXh6rqdXgZ1O8b8cpngVMs4mmJZh+Kuc so6ybQKIUKdWnADSVFgz6uQm2gPhpW88QVkw+UFigvULfZva3Z2+F5R6uilh1mYqe6mj s/lVnBeN0iWDLSSWyphpS5C8ZMgg0B5UlMKwzpyFYjc5rt9KvRnam81kMs3vvRsGP8/0 0IMA== 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=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=Lvd2Tu7SYNCOns2Z3C5jjmRjOCOk6m7gIlHWevMFr80YEWwL4kkbaiDqo0bZQ04HYg sDc4kY1pV/57CGXKZdCENeMvnPmAG0z/HaHzdXJtxKIXg7TdPSIEMjiUEeRok5VgNTFE nGFUCztfcE6byiffvzFw7Wv47ULpIPJ/NCTnmH2Af1JMD04KWEUFleuUTPtc01+nU0/3 ap00xdhcipb2Ak0gNCPGaq+LktCjYnAIbzijXDnQnCmW+YLxY922lWey2ZGTgucb0S2s 7J7ylrjjHyQy1RlabrPoklKvrIIRQ/zk5zr1hpc15xbUVCuR1eWYEas64JeRSswgD8yx vD0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Po+bheMR; 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 bo17-20020a0564020b3100b00461c9edc3a5si1329513edb.77.2022.10.23.21.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:49:19 -0700 (PDT) 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=Po+bheMR; 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 3138084F48; Mon, 24 Oct 2022 06:48:14 +0200 (CEST) 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="Po+bheMR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 638D084F49; Mon, 24 Oct 2022 06:48:06 +0200 (CEST) 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-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 00E2684F58 for ; Mon, 24 Oct 2022 06:47:56 +0200 (CEST) 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-x1030.google.com with SMTP id s22-20020a17090a075600b002130d2ad62aso1383696pje.2 for ; Sun, 23 Oct 2022 21:47:56 -0700 (PDT) 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=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=Po+bheMR/iXLOmAjRq8cwnHPG368YJ6QT8NYCc+jy8ky6lStEIvXXdXwJ/vHwjWuGa W10uxSKqS8rcgkcW/gVGGyRH9lFbrsS4Qfevkq6wCI8OTILhWicusqItG3HZSnL7IIPe 0uXwt48gXmEkWpdvspqfaHF99OJfOpBGKELVYVdiuEjhXXasS5W0dwtwcegPE3ckimek TpDKz3p3LV5xYp/cXSjWjzJHwRfg+VPCIzeuvZ7gQpfwcFF8pyetEXxaY25rysqJFisB +onLiIVxS3DB68fHRdAWDbYQZtPhWnLtLObZYehqUcl2lrE9EV/HNi7jGZskMoKx+Zta Oq9w== 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=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=PG3iSUlHUeblRbRaJUotEyhQbEnUcSepHn5eVQkztcJMa6CJRyOY1nSeF+FB+qltnc ZOLPbAyy/Qcmp1+GdWaAfG25jiememDr5UIDZBErkS26uS4YhfuKBMRDrsDTftNkMOXn 9v4cCIFGLSivG5EmdDYDPOH9oUnCSEpRNMeku95BRXW25MkC/BTRyasf/YTpheYqsco1 /YPeZXS9FIlj1M586qeexUXsIACeittaDD/X8MgQWWivDEFcN7bIc5l6lReR+DVU9r0t /IvWLmYu1CclvYXuiIu0MJ9znrKjXKhEDccTSY7grtGfMKeb8wfpjjTQS01BYMDjova3 0r7Q== X-Gm-Message-State: ACrzQf168mCOYC1hPeqOg896YGc9FIpUhlD5k7IrLT5bNxb0F08SE6IY al3yntO05QTBI+MqMznp8UQN74Xs5uMefQ== X-Received: by 2002:a17:902:9684:b0:17e:71b2:bd16 with SMTP id n4-20020a170902968400b0017e71b2bd16mr31560979plp.163.1666586864286; Sun, 23 Oct 2022 21:47:44 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:43 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 4/7] eficonfig: add direct menu entry access in change boot order Date: Mon, 24 Oct 2022 13:48:01 +0900 Message-Id: <20221024044804.3351-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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 adds the direct menu entry access in change boot order menu. To call eficonfig_handle_direct_accessor() from change boot order menu, refactoring is required to use 'eficonfig_entry' structure in change boot order menu processing. Signed-off-by: Masahisa Kojima --- Newly added in v4 cmd/eficonfig.c | 165 ++++++++++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 63 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 56d9268f9f..8c131849be 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -94,20 +94,14 @@ struct eficonfig_boot_selection_data { }; /** - * struct eficonfig_boot_order - structure to be used to update BootOrder variable + * struct eficonfig_boot_order_data - structure to be used to update BootOrder variable * - * @num: index in the menu entry - * @description: pointer to the description string * @boot_index: boot option index * @active: flag to include the boot option into BootOrder variable - * @list: list structure */ -struct eficonfig_boot_order { - u32 num; - u16 *description; +struct eficonfig_boot_order_data { u32 boot_index; bool active; - struct list_head list; }; /** @@ -1924,7 +1918,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) { bool reverse; struct list_head *pos, *n; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry; printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION "\n ** Change Boot Order **\n" @@ -1940,7 +1934,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) /* draw boot option list */ list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); reverse = (entry->num == efi_menu->active); printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); @@ -1949,13 +1943,34 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) puts(ANSI_COLOR_REVERSE); if (entry->num < efi_menu->count - 2) { - if (entry->active) + if (((struct eficonfig_boot_order_data *)entry->data)->active) printf("[*] "); else printf("[ ] "); } - printf("%ls", entry->description); + if (reverse && efi_menu->direct_access_mode) { + size_t len = u16_strlen(efi_menu->accessor_str); + char *accessor_str, *p; + + accessor_str = calloc(1, utf16_utf8_strlen(efi_menu->accessor_str) + 1); + if (!accessor_str) { + printf("%s", entry->title); + return; + } + p = accessor_str; + utf16_utf8_strncpy(&p, efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_MAX); + len = strlen(accessor_str); + if (!strncasecmp(accessor_str, entry->title, len)) { + printf("%.*s" ANSI_COLOR_RESET "%s", (int)len, entry->title, + &entry->title[len]); + } else { + printf("%s", entry->title); + } + free(accessor_str); + } else { + printf("%s", entry->title); + } if (reverse) puts(ANSI_COLOR_RESET); @@ -1972,12 +1987,18 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) { int esc = 0; struct list_head *pos, *n; - struct eficonfig_boot_order *tmp; enum bootmenu_key key = KEY_NONE; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry, *tmp; if (efi_menu->direct_access_mode) { - eficonfig_handle_direct_accessor(efi_menu); + if (eficonfig_handle_direct_accessor(efi_menu)) { + /* If the selected entry is "Save" or "Quit", complete selection */ + if (efi_menu->active == efi_menu->count - 2) + return EFI_SUCCESS; + + if (efi_menu->active == efi_menu->count - 1) + return EFI_ABORTED; + } return EFI_NOT_READY; } @@ -1988,11 +2009,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_PLUS: if (efi_menu->active > 0) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) break; } - tmp = list_entry(pos->prev, struct eficonfig_boot_order, list); + tmp = list_entry(pos->prev, struct eficonfig_entry, list); entry->num--; tmp->num++; list_del(&tmp->list); @@ -2006,11 +2027,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_MINUS: if (efi_menu->active < efi_menu->count - 3) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) break; } - tmp = list_entry(pos->next, struct eficonfig_boot_order, list); + tmp = list_entry(pos->next, struct eficonfig_entry, list); entry->num++; tmp->num--; list_del(&entry->list); @@ -2036,9 +2057,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_SPACE: if (efi_menu->active < efi_menu->count - 2) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) { - entry->active = entry->active ? false : true; + struct eficonfig_boot_order_data *data = entry->data; + + data->active = data->active ? false : true; return EFI_NOT_READY; } } @@ -2047,6 +2070,8 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_QUIT: return EFI_ABORTED; case KEY_AMPERSAND: + memset(efi_menu->accessor_str, 0, + EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); efi_menu->direct_access_mode = true; return EFI_NOT_READY; default: @@ -2067,12 +2092,13 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) static efi_status_t eficonfig_add_change_boot_order_entry(struct efimenu *efi_menu, u32 boot_index, bool active) { + char *title, *p; efi_status_t ret; efi_uintn_t size; void *load_option; struct efi_load_option lo; u16 varname[] = u"Boot####"; - struct eficonfig_boot_order *entry; + struct eficonfig_boot_order_data *data; efi_create_indexed_name(varname, sizeof(varname), "Boot", boot_index); load_option = efi_get_var(varname, &efi_global_variable_guid, &size); @@ -2080,31 +2106,38 @@ static efi_status_t eficonfig_add_change_boot_order_entry(struct efimenu *efi_me return EFI_SUCCESS; ret = efi_deserialize_load_option(&lo, load_option, &size); - if (ret != EFI_SUCCESS) { - free(load_option); - return ret; + if (ret != EFI_SUCCESS) + goto out; + + data = calloc(1, sizeof(struct eficonfig_boot_order_data)); + if (!data) { + ret = EFI_OUT_OF_RESOURCES; + goto out; } - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) { - free(load_option); - return EFI_OUT_OF_RESOURCES; + title = calloc(1, utf16_utf8_strlen(lo.label) + 1); + if (!title) { + free(data); + ret = EFI_OUT_OF_RESOURCES; + goto out; } + p = title; + utf16_utf8_strcpy(&p, lo.label); - entry->description = u16_strdup(lo.label); - if (!entry->description) { - free(load_option); - free(entry); - return EFI_OUT_OF_RESOURCES; + data->boot_index = boot_index; + data->active = active; + + ret = eficonfig_append_menu_entry(efi_menu, title, NULL, data); + if (ret != EFI_SUCCESS) { + free(data); + free(title); + goto out; } - entry->num = efi_menu->count++; - entry->boot_index = boot_index; - entry->active = active; - list_add_tail(&entry->list, &efi_menu->list); +out: free(load_option); - return EFI_SUCCESS; + return ret; } /** @@ -2119,8 +2152,8 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi u16 *bootorder, efi_uintn_t num) { u32 i; + char *title; efi_status_t ret; - struct eficonfig_boot_order *entry; /* list the load option in the order of BootOrder variable */ for (i = 0; i < num; i++) { @@ -2147,27 +2180,25 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi } /* add "Save" and "Quit" entries */ - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) + title = strdup("Save"); + if (!title) { + ret = EFI_OUT_OF_RESOURCES; goto out; + } - entry->num = efi_menu->count++; - entry->description = u16_strdup(u"Save"); - list_add_tail(&entry->list, &efi_menu->list); - - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) + ret = eficonfig_append_menu_entry(efi_menu, title, NULL, NULL); + if (ret != EFI_SUCCESS) goto out; - entry->num = efi_menu->count++; - entry->description = u16_strdup(u"Quit"); - list_add_tail(&entry->list, &efi_menu->list); + ret = eficonfig_append_quit_entry(efi_menu); + if (ret != EFI_SUCCESS) + goto out; efi_menu->active = 0; return EFI_SUCCESS; out: - return EFI_OUT_OF_RESOURCES; + return ret; } /** @@ -2183,13 +2214,17 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) efi_status_t ret; efi_uintn_t num, size; struct list_head *pos, *n; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry; struct efimenu *efi_menu; efi_menu = calloc(1, sizeof(struct efimenu)); if (!efi_menu) return EFI_OUT_OF_RESOURCES; + efi_menu->accessor_str = calloc(1, 32); + if (!efi_menu->accessor_str) + return EFI_OUT_OF_RESOURCES; + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); INIT_LIST_HEAD(&efi_menu->list); @@ -2214,9 +2249,16 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) /* create new BootOrder */ count = 0; list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); - if (entry->active) - new_bootorder[count++] = entry->boot_index; + 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); @@ -2235,15 +2277,12 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) } } out: + free(bootorder); list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); - list_del(&entry->list); - free(entry->description); - free(entry); + entry = list_entry(pos, struct eficonfig_entry, list); + free(entry->data); } - - free(bootorder); - free(efi_menu); + eficonfig_destroy(efi_menu); /* to stay the parent menu */ ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;