From patchwork Tue May 24 03:45:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 575733 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:c603:0:0:0:0 with SMTP id jv3csp1956921mab; Mon, 23 May 2022 20:45:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1felQ1c6JvlaquujcMfqvip/d3l9TwHQxkJtfNsvg0YmbgUYBd17xPABVwLWAcNJsQJTs X-Received: by 2002:a05:6e02:1585:b0:2c2:5b2c:e3e5 with SMTP id m5-20020a056e02158500b002c25b2ce3e5mr7507419ilu.76.1653363910249; Mon, 23 May 2022 20:45:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653363910; cv=none; d=google.com; s=arc-20160816; b=EO0rqs+gx+iVn9iBA0ofl8JQE/vXuYKakEC6lZwQCk3To2ohCcQrNZddpFGcUUuOu+ 6E45XZNEUvK3cSWKMHXavhNJr+6ChopPkgqjJZ4RYaATl1ThSBgoUDWnXgJa4gQuZZGZ MQ6nFPPvyJWBCEPLIwiv5yF9t1T0Rz5ZocAhjksYuAKqY0WQoT75d7lJbRO9KJqmLTLZ 9MyQNx407mjPWDATgigCcI8JM6P0JXtfBawthgPVSKDU6vCHL/EXv7+9mfUbq59X1x5x ZUbyxVKSmA8ev+WhNAtpW3x0oJaAgcYhdqzhhFFp19o/An0pq0ozJqhxQcROOLOiXv81 DZqg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=spos/z1Ghfqpwbk+sGKCsUNLOIPDit/EWbFMEBuUc+I=; b=sUdnfic/R75Ucl2GCYOyi6WwjajpdvW9aix00zAEK0+WilgKitwm7Jjt6BO2ElmXPF oNcHpBAajZDgg+g4xCYJ9ao+yyHUsadqI1kOt84OJ974mrGtzLaUJjGQjfWiVhWpEgoE X0P3Dc5IPs6Hai1DcgP2HoBqFd4lY21V8YXFZWZsXPJzp/6NchJv/G/ALWhHQH4LnTeG v2bfusviakKpDCh3PPMOC5vf+mVAyb2NDUiQaqa989wXbvI5GYNpsBQoZy2Y23CjPKJf YZvXVXbOpi+o7GZhJNjiSVVWB/VTwrtWpMHuhR2dKzrznjQIUcatt6yZIgtketWQDEhK YWJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dy2U0LL7; 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 g13-20020a05660226cd00b00660cfc37884si11854741ioo.8.2022.05.23.20.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 20:45:10 -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=dy2U0LL7; 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 2465583D7D; Tue, 24 May 2022 05:45:05 +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="dy2U0LL7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7C2FB83EB4; Tue, 24 May 2022 05:45:03 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (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 2922183C96 for ; Tue, 24 May 2022 05:45:00 +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-pf1-x42a.google.com with SMTP id f21so3008705pfa.3 for ; Mon, 23 May 2022 20:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=spos/z1Ghfqpwbk+sGKCsUNLOIPDit/EWbFMEBuUc+I=; b=dy2U0LL7BmgosmI4yeG+Jabla69ib4+SrsJdJKcb6IYO9qAJn9lk1kTfkURJnAPvt1 F5e/WpLMccE5i+68yp1b5lc5aRtOULxr3D75TBfVafBWr34BPETbhjamfqV+Ejbiedow 5LOamTu+Htse3bNK+jyidSho2iprEImdN6jPyeDGwHiTb/4A2MrntqLQbeU9Ytc0SSKv YJmnZeqQzHOUrSWaWNZZcwqsrnsONf5rVmuMlNSnbxCkgf6mMSKi0LBLFPbFBpqpuw9x cg9WA5BUyCZ8CBgHwx8S7ECXzRLZ3g/tnTF9/mdUUOBHul2L/yBThBTF7wRkjdvY3SLS 7TKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=spos/z1Ghfqpwbk+sGKCsUNLOIPDit/EWbFMEBuUc+I=; b=ZgP/4qXmqpW2bMdvXU5uZ/nYxCxW+EZAC1/JdNSbmm0PPPb5XF2slX7DdSqxU+cde9 zPJyA7O3kkpfnyoLJHX5/IhnsLcwimsHCEwJgWtjj0AXjvFwmcviyQPMiBLbIjU7IGOa NF90jbuYY3y4udMFuwsSsTjmFlDKzl33cmQ7EW48Fgh/bydk6nrYat+uz66SMrkgUPgJ 9AB6G5Av9c+O4YaTyiMyBcdb3gLP2DolIoGtpNAvk5UUXMqyz0DgJRVcckgDV2rmCKc7 YHxmZqtWsqO67fh9F4bSqCTpGnLf9OM235zx4CAd8k3rZLfBtymuQAVUR7jhoIAO79H/ 5QWw== X-Gm-Message-State: AOAM5305xW6NbLyy8NqdXElci6ZXSnlwyw6Y2UVPnT5mOlv8M20CLpig tyo8x3dWOpRXV7DStK74vx+1UgwoNTaX/g== X-Received: by 2002:a63:e80a:0:b0:3f6:2cc9:63b5 with SMTP id s10-20020a63e80a000000b003f62cc963b5mr22726456pgh.4.1653363898351; Mon, 23 May 2022 20:44:58 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id a3-20020a170902ecc300b0015e8d4eb26dsm5919854plh.183.2022.05.23.20.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 20:44:58 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Pali Rohar , Tom Rini , Masahisa Kojima , Ilias Apalodimas Subject: [PATCH] bootmenu: fix bootmenu title handling Date: Tue, 24 May 2022 12:45:30 +0900 Message-Id: <20220524034531.17611-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 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.5 at phobos.denx.de X-Virus-Status: Clean The commit a3d0aa87acbe ("bootmenu: update bootmenu_entry structure") changes the bootmenu title type from char to u16(UTF16 string) to support EFI based system. If EFI_LOADER is not enabled, printf("%ls") is not supported, so bootmenu does not appear correctly. This commit switches the menu title type from "char" to "u16" only when the EFI_LOADER is enabled. Fixes: a3d0aa87acbe ("bootmenu: update bootmenu_entry structure") Signed-off-by: Masahisa Kojima --- cmd/bootmenu.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 8859eebea5..e422e0b348 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -20,6 +20,20 @@ /* maximum bootmenu entries */ #define MAX_COUNT 99 +#if (CONFIG_IS_ENABLED(EFI_LOADER)) +#define TITLE_CHAR u16 +#define titlefmt "ls" +#define TITLE_STRDUP u16_strdup +#define TITLE_STRNCPY(d, s, l) utf8_utf16_strncpy(&d, s, l) +#define TITLE_STR(x) u##x +#else +#define TITLE_CHAR char +#define titlefmt "s" +#define TITLE_STRDUP strdup +#define TITLE_STRNCPY(d, s, l) strncpy(d, s, l) +#define TITLE_STR(x) x +#endif + /* maximal size of bootmenu env * 9 = strlen("bootmenu_") * 2 = strlen(MAX_COUNT) @@ -43,7 +57,7 @@ enum boot_type { struct bootmenu_entry { unsigned short int num; /* unique number 0 .. MAX_COUNT */ char key[3]; /* key identifier of number */ - u16 *title; /* title of entry */ + TITLE_CHAR *title; /* title of entry */ char *command; /* hush command of entry */ enum boot_type type; /* boot type of entry */ u16 bootorder; /* order for each boot type */ @@ -76,7 +90,7 @@ static void bootmenu_print_entry(void *data) if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%ls", entry->title); + printf("%" titlefmt "", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -170,7 +184,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, struct bootmenu_entry *iter = *current; while ((option = bootmenu_getoption(i))) { - u16 *buf; + TITLE_CHAR *buf; sep = strchr(option, '='); if (!sep) { @@ -183,13 +197,13 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, return -ENOMEM; len = sep-option; - buf = calloc(1, (len + 1) * sizeof(u16)); + buf = calloc(1, (len + 1) * sizeof(TITLE_CHAR)); entry->title = buf; if (!entry->title) { free(entry); return -ENOMEM; } - utf8_utf16_strncpy(&buf, option, len); + TITLE_STRNCPY(buf, option, len); len = strlen(sep + 1); entry->command = malloc(len + 1); @@ -227,6 +241,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, return 1; } +#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) /** * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries * @@ -315,6 +330,7 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, return 1; } +#endif static struct bootmenu_data *bootmenu_create(int delay) { @@ -341,13 +357,13 @@ static struct bootmenu_data *bootmenu_create(int delay) if (ret < 0) goto cleanup; - if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { - if (i < MAX_COUNT - 1) { - ret = prepare_uefi_bootorder_entry(menu, &iter, &i); - if (ret < 0 && ret != -ENOENT) - goto cleanup; - } +#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) + if (i < MAX_COUNT - 1) { + ret = prepare_uefi_bootorder_entry(menu, &iter, &i); + if (ret < 0 && ret != -ENOENT) + goto cleanup; } +#endif /* Add U-Boot console entry at the end */ if (i <= MAX_COUNT - 1) { @@ -357,9 +373,9 @@ static struct bootmenu_data *bootmenu_create(int delay) /* Add Quit entry if entering U-Boot console is disabled */ if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) - entry->title = u16_strdup(u"U-Boot console"); + entry->title = TITLE_STRDUP(TITLE_STR("U-Boot console")); else - entry->title = u16_strdup(u"Quit"); + entry->title = TITLE_STRDUP(TITLE_STR("Quit")); if (!entry->title) { free(entry); @@ -461,7 +477,7 @@ static enum bootmenu_ret bootmenu_show(int delay) int cmd_ret; int init = 0; void *choice = NULL; - u16 *title = NULL; + TITLE_CHAR *title = NULL; char *command = NULL; struct menu *menu; struct bootmenu_entry *iter; @@ -517,7 +533,7 @@ static enum bootmenu_ret bootmenu_show(int delay) if (menu_get_choice(menu, &choice) == 1) { iter = choice; - title = u16_strdup(iter->title); + title = TITLE_STRDUP(iter->title); command = strdup(iter->command); /* last entry is U-Boot console or Quit */ @@ -561,7 +577,7 @@ cleanup: } if (title && command) { - debug("Starting entry '%ls'\n", title); + debug("Starting entry '%" titlefmt "'\n", title); free(title); if (efi_ret == EFI_SUCCESS) cmd_ret = run_command(command, 0);