From patchwork Mon Oct 24 04:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617834 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483170pvb; Sun, 23 Oct 2022 21:48:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72g7ulsFC17Th/QWstV99c1pvOol11XbEK4C2GiD3QOGMMpF7R4TTa6SJYD9hfvRzJWQrz X-Received: by 2002:a05:6402:42d0:b0:457:d16e:283d with SMTP id i16-20020a05640242d000b00457d16e283dmr28837441edc.395.1666586897566; Sun, 23 Oct 2022 21:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586897; cv=none; d=google.com; s=arc-20160816; b=NptnIw8jUn2gyg9mzQuZIqWbQtSmGBTuSGDhTdP42Dd8Xgya+pXVwWzKpU5FfyUDFd 19PfxVzcsz4URrq3jH611DgPAXUO/LkEDT/ov575dDOE09zAHV5XHoQFUpTdJtcFB5JM TAkzSGmvqLsoMa1zHh4xTq47K1TwefBqzbo+MHVsM/d8DUPVYqQ1FnS5wunzoEcZe2Xj 3kmPptA9rA7ZmERQ71+MdX4jxqEi4boN0xgzmp6AF9eBCHWAgqb/aQOwgf/RnGkr39HI Nlu1ngRi3N6D0vldC1brLPx/02uTtq+fsfWKBhF45/BZrV9z6JVh291ZDipF0fbevmw5 7aTw== 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=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=QaKp+DZM2FQWQL1Yfqi26ByqoBq/Ts+SPpT8BJcm1302p+RzhPXcrPlPLg6yTutzuG 00JG1junJ3b1fOAs5xH47fnlBhWQ5d2PAnkO3Ja35kvPuca6BuzGbHKlXtRaHNBdDL/x JkpZxCcahtDAostBYN7d2/0LOyywDJgTgfCZg2Jyr2mmKqPHrKK78OndwSNdPoPwC5Ir WAt9m+ZmC3oCO8ltLPvkfETyjrs0Y6nF8yEeV1ATqKX8coEVC95iyzjpNQmFBSw5UI/o WLwDkzRm+fh0Mk2KHT5druYnUo3x/7Sp48qHYjIazc97+1MkxI6nrLZyqBVoygI8hzsp G+zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fekqojZV; 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 dd3-20020a1709069b8300b0073ffabc3352si27901535ejc.836.2022.10.23.21.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:48:17 -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=fekqojZV; 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 1142584F52; Mon, 24 Oct 2022 06:47:55 +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="fekqojZV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D7D584F49; Mon, 24 Oct 2022 06:47:48 +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-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 3DFD884F3E for ; Mon, 24 Oct 2022 06:47:43 +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-x102f.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so2557843pji.0 for ; Sun, 23 Oct 2022 21:47:43 -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=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=fekqojZV1ZGmVCAoYP5KD09mirC4StCMf6/W80IBAok7E3A466EF58LM107F0stM16 vFBzcIG6A9a9wEacQQl2l35Dzws87Br/9MPKazdzJHSgM+I8yZ6TBsiCvNo6s96V32GY QvSxXWwNJrxxEhF3RV8MKIqwXDJ3YN5ZKVqm0kfgXz83ZSto9XhQW0J85QhjzfD4p/v2 XSeSNTstc3GpH0GyC6pUGPZ0645ixkW/k2+EuV3fA1GNLvWyYSq1dd71IcKVH0CX0mSL C60eTkOs+KMydZdxXBJraoOagCbNfgHAcVU1dCoW7C+jCcuei+okUasEcMolenTzC5EZ 3GyA== 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=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=ubktLjK3kLQZgxWGBv4VT4qtzhtTrrzM47Hek5JhVAkDRnAgNUl4VXxw2m/1x2hgWC lEBpNzT2nTuYrzbw0Ur/60euxN1EHIMG8y7w51V/KJMRyMgQGNDZ8rFLMUeToe6XrGi4 WC7t9nz4W2vrozdF57fJZ0ncNsqAU8G9uxYpl1RF+GtssZOYs4Xp+DRXFUUUFtrsnR89 QE+s6w8IEIf8eYgVcrZp4HhIgL5ovsKR5CQ1mixiuepDfjXaTBKkXFaK2Kpz6vap9JUT Ak1CKCUJgZ4bImUSNvdwQIifjbq+0DdEDmL/4SGWmSRUKbIRnI7C+TNlSPYgThKCaQKx CMwA== X-Gm-Message-State: ACrzQf1zgQn6e1iixJ/NOcu5k5Vsb1HhjW+Dznp9ZF7f1dCv7bZCpxVb Tb6TCkkO2+vyvdS/agSQ4KA8xnh/SyZ/fQ== X-Received: by 2002:a17:903:2144:b0:182:42ce:5778 with SMTP id s4-20020a170903214400b0018242ce5778mr31258146ple.46.1666586861269; Sun, 23 Oct 2022 21:47:41 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:40 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Stefan Roese Subject: [PATCH v4 3/7] eficonfig: add direct menu entry access mode Date: Mon, 24 Oct 2022 13:48:00 +0900 Message-Id: <20221024044804.3351-4-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 mode. User can select the menu entry by '&' key followed by the menu title name. User input is read in UTF-16, then UTF-16 string is converted into UTF-8 internally because string comparison relies on strncasecmp(). There is no equivalent string comparison function for UTF-16. Signed-off-by: Masahisa Kojima --- Newly added in v4 cmd/eficonfig.c | 120 ++++++++++++++++++++++++++++++++++++++++++- common/menu.c | 3 ++ include/efi_config.h | 3 ++ include/menu.h | 1 + 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0cb0770ac3..56d9268f9f 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -22,6 +22,7 @@ static struct efi_simple_text_input_protocol *cin; +#define EFICONFIG_ACCESSOR_STR_MAX 16 #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -155,7 +156,28 @@ static void eficonfig_print_entry(void *data) if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%s", entry->title); + if (reverse && entry->efi_menu->direct_access_mode) { + size_t len = u16_strlen(entry->efi_menu->accessor_str); + char *accessor_str, *p; + + accessor_str = calloc(1, utf16_utf8_strlen(entry->efi_menu->accessor_str) + 1); + if (!accessor_str) { + printf("%s", entry->title); + return; + } + p = accessor_str; + utf16_utf8_strncpy(&p, entry->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); @@ -182,6 +204,83 @@ static void eficonfig_display_statusline(struct menu *m) entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1); } +/** + * eficonfig_handle_direct_accessor() - handle direct access user input + * + * @efi_menu: pointer to the efimenu structure + * Return: key string to identify the selected entry + */ +static char *eficonfig_handle_direct_accessor(struct efimenu *efi_menu) +{ + efi_status_t ret; + char *accessor_str, *p; + struct efi_input_key key; + struct list_head *pos, *n; + struct eficonfig_entry *entry; + static int len; + + /* Read user input */ + do { + ret = EFI_CALL(cin->read_key_stroke(cin, &key)); + mdelay(10); + } while (ret == EFI_NOT_READY); + + /* If user presses Ctrl+C or ESC, exit direct access mode */ + if (key.unicode_char == 0x3 || key.scan_code == 23) + goto out; + + /* If user presses ENTER, exit direct access mode and return the active entry */ + if (key.unicode_char == u'\r') { + list_for_each_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + if (entry->num == efi_menu->active) { + efi_menu->direct_access_mode = false; + memset(efi_menu->accessor_str, 0, + EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + return entry->key; + } + } + + /* no matching entry */ + goto out; + } + + /* Ignore other control code and efi scan code */ + if (key.unicode_char < 0x20 || key.scan_code != 0) + return NULL; + + len = u16_strlen(efi_menu->accessor_str); + if (len < EFICONFIG_ACCESSOR_STR_MAX - 1) + efi_menu->accessor_str[len] = key.unicode_char; + + accessor_str = calloc(1, utf16_utf8_strlen(efi_menu->accessor_str) + 1); + if (!accessor_str) + return NULL; + + p = accessor_str; + utf16_utf8_strncpy(&p, efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_MAX); + + list_for_each_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + if (!strncasecmp(accessor_str, entry->title, strlen(accessor_str))) { + efi_menu->active = entry->num; + free(accessor_str); + return NULL; + } + } + + /* does not match any entries */ + free(accessor_str); + efi_menu->active = 0; + return NULL; + +out: + efi_menu->direct_access_mode = false; + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + efi_menu->active = 0; + return NULL; +} + /** * eficonfig_choice_entry() - user key input handler * @@ -196,6 +295,9 @@ static char *eficonfig_choice_entry(void *data) enum bootmenu_key key = KEY_NONE; struct efimenu *efi_menu = data; + if (efi_menu->direct_access_mode) + return eficonfig_handle_direct_accessor(efi_menu); + while (1) { bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc); @@ -221,6 +323,10 @@ static char *eficonfig_choice_entry(void *data) /* Quit by choosing the last entry */ entry = list_last_entry(&efi_menu->list, struct eficonfig_entry, list); return entry->key; + case KEY_AMPERSAND: + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + efi_menu->direct_access_mode = true; + return NULL; default: /* Pressed key is not valid, no need to regenerate the menu */ break; @@ -248,6 +354,7 @@ void eficonfig_destroy(struct efimenu *efi_menu) free(entry); } free(efi_menu->menu_header); + free(efi_menu->accessor_str); free(efi_menu); } @@ -385,6 +492,9 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_heade if (!efi_menu->menu_header) return EFI_OUT_OF_RESOURCES; } + efi_menu->accessor_str = calloc(1, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + if (!efi_menu->accessor_str) + return EFI_OUT_OF_RESOURCES; menu = menu_create(NULL, 0, 1, eficonfig_display_statusline, eficonfig_print_entry, eficonfig_choice_entry, @@ -1866,6 +1976,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) enum bootmenu_key key = KEY_NONE; struct eficonfig_boot_order *entry; + if (efi_menu->direct_access_mode) { + eficonfig_handle_direct_accessor(efi_menu); + return EFI_NOT_READY; + } + while (1) { bootmenu_loop(NULL, &key, &esc); @@ -1931,6 +2046,9 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) break; case KEY_QUIT: return EFI_ABORTED; + case KEY_AMPERSAND: + efi_menu->direct_access_mode = true; + return EFI_NOT_READY; default: /* Pressed key is not valid, no need to regenerate the menu */ break; diff --git a/common/menu.c b/common/menu.c index 8fe00965c0..6ea9f5c9b8 100644 --- a/common/menu.c +++ b/common/menu.c @@ -557,4 +557,7 @@ void bootmenu_loop(struct bootmenu_data *menu, if (c == ' ') *key = KEY_SPACE; + + if (c == '&') + *key = KEY_AMPERSAND; } diff --git a/include/efi_config.h b/include/efi_config.h index 86bc801211..1b84e2d579 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -45,6 +45,7 @@ struct eficonfig_entry { * @active: active menu entry index * @count: total count of menu entry * @menu_header: menu header string + * @accessor_str: pointer to the accessor string for entry shortcut * @list: menu entry list structure */ struct efimenu { @@ -52,6 +53,8 @@ struct efimenu { int active; int count; char *menu_header; + bool direct_access_mode; + u16 *accessor_str; struct list_head list; }; diff --git a/include/menu.h b/include/menu.h index 702aacb170..03bf8dc4f5 100644 --- a/include/menu.h +++ b/include/menu.h @@ -51,6 +51,7 @@ enum bootmenu_key { KEY_PLUS, KEY_MINUS, KEY_SPACE, + KEY_AMPERSAND, }; void bootmenu_autoboot_loop(struct bootmenu_data *menu,