From patchwork Sun May 29 01:52:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 577061 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8607:0:0:0:0 with SMTP id bb7csp1888154mab; Sat, 28 May 2022 18:52:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk7WVXAr06MnzGGw+jKT/xHBOAEREm6rVYhY1uKze3MPpnhULZf63iCA3Yp1i28jsd6Al0 X-Received: by 2002:a02:6a6b:0:b0:323:fcf9:2227 with SMTP id m43-20020a026a6b000000b00323fcf92227mr24662727jaf.137.1653789143283; Sat, 28 May 2022 18:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653789143; cv=none; d=google.com; s=arc-20160816; b=Q7g+UA+aqUyAQ87JVKsB4tQ8JSSb0Bf0l3tcpU47FzhC6I4oVOHKkMT1eQqQ4W/A9C rTiJ/+BGBtSPUz+2XTTkD/txRUZ1KqNk/JzK+zLZeHO4brgkKJBleycaHUm/ihnXJwWT 8pHcEm919ir9j6SrSi4/S6BYgRX+55F3Ex44ciSAgJRNxwEHT0G19+6G9F3eZd4eLnal pB+H78w3uQNvxzcq7IL01/9vglKJ/ZXA/MAM/SO+50FRbfru7o0XR/qbL8OKeWlM23I/ BYZjXvH7viXqkTnWqO2a96ZmzsmtFgZN18MEr1SZhfyan/Vv9VquBZdfX1W7r1o+J7X3 u4+Q== 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=ZFda4hgYiNQjmTkpnBZgOVOxeC5DaQGMlII8ikmSnJk=; b=QRLzMgfFzpKnPBOe+cnYpqqfwVlXCCKsIFYW6RLA4zUTFxu1MhtcMnEj6F+tCUi/hs 04IxlQVg2jKpIlOhGJl4DmyUf1Ki1ySZi3qR4LChPdKiB5FbrPcep/EjX0B4v7Ikcm0G bu/Js0r0Vcb2f6GWcOEWpIc9sX86qQ5heeUX5gN0/AiqJ1wpr5MfBvPAXB0FHX9ZiUwZ w2y+r8DKM+Hab4ufiZtQDsyA/f8AHr0LYNN5zP0AgJGJVFgfckgZcC6VcmOEUL5h2cMT OsiC/bLr//htSWPt8HN9mYv6yxa+jb91shUoJ753Cu6B30pz0/FRBAgNrfStpi1Yctk/ fK7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W1OR7MPR; 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 a15-20020a6b660f000000b00657cb900c35si8370352ioc.31.2022.05.28.18.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 18:52:23 -0700 (PDT) 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=W1OR7MPR; 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 39E79843AF; Sun, 29 May 2022 03:52:21 +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="W1OR7MPR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C401843A0; Sun, 29 May 2022 03:52:02 +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-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 A11CC84390 for ; Sun, 29 May 2022 03:51:57 +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-x102a.google.com with SMTP id gk22so7892782pjb.1 for ; Sat, 28 May 2022 18:51:57 -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:in-reply-to:references; bh=ZFda4hgYiNQjmTkpnBZgOVOxeC5DaQGMlII8ikmSnJk=; b=W1OR7MPRhBJQi9kkSMVzxUoM7Gd+U0h8VXncUxk52Z4JTZmIecu/1uCfSKKT0MsKz7 4/JvdWZkUYInzCfj2OWXr84wTaAlrsD2LIIp3wwW2CBCwsvcQ4Ly6zfJ4JPrknC6uaDx ZPLp7DSCWpqGvZIBJ3TTvmrFrVly+CLQ3b2BzzvNX1FszkZ+5CYQxVDfkGHqpK4JQGB2 CT9kru1k2GYKeQ7ZzpUdj4PqjsBZELnyZdPe0kXj9DBgINW1FfXSJwjQOBd7EXHGbfzs 2cDK5kXXRavwLjDjCLP65OfLH9p/vbHvV5qktFKH/XgF/geYUr64xVBfjCUfB1Zo7Q9+ VOsQ== 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:in-reply-to :references; bh=ZFda4hgYiNQjmTkpnBZgOVOxeC5DaQGMlII8ikmSnJk=; b=g8oWiSgVryYGmsajaslkUtI3/tyygSwdr8mB/DIdoWbUfGUBebAuuwYZ/fAgwIhUoO O2shKYXSRtWF2utuAQPAq/AqrqxwDTmHaO2kGGl3vA1MmfsaxXXb/d1SU/NdB98X6F9r 0prsy9xf6WQN9QR6PCTm+O+/djsnNYNB8rvoObxMZEYGkArkA6ByRSYy++CJAJYvlnk2 0EbQhBI7RIfED0Ob3NjDMY+Y0wBglzHvihLOGvyv2Xt/qpW514t5r2I/jm8vq4KquQGU 4IB6GFdEEpTbclyiGXzrkx1QLVBF11GOhQZ+PKA+V93eHr1WOTT+XWpVqIw/m5KaW5Rb HyJg== X-Gm-Message-State: AOAM5331Rqs+qob6kzug8KPub9zXNNIv0UvKHVBwYCq+2sr3ilrJlGnH WyXBZ0WTvlufrTFckJdTfriVycdsL7PvUQ== X-Received: by 2002:a17:902:ea57:b0:15a:6173:87dd with SMTP id r23-20020a170902ea5700b0015a617387ddmr50602253plg.147.1653789115927; Sat, 28 May 2022 18:51:55 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id l7-20020a17090270c700b001639f038250sm3791796plt.220.2022.05.28.18.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 18:51:55 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Pali Rohar , Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Mark Kettenis , Masahisa Kojima Subject: [PATCH v3 1/2] bootmenu: use utf-8 for menu title Date: Sun, 29 May 2022 10:52:43 +0900 Message-Id: <20220529015244.3910-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220529015244.3910-1-masahisa.kojima@linaro.org> References: <20220529015244.3910-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.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 changes the type of menu title from u16(UTF16) to utf-8 string and EFI strings is conveted into utf-8. Fixes: a3d0aa87acbe ("bootmenu: update bootmenu_entry structure") Signed-off-by: Masahisa Kojima Tested-by: Pali Rohar --- Changes in v3: - use strdup for bootmenu_x command parameter - add comment for readbility - use proper space no change in v2 cmd/bootmenu.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 8859eebea5..7f776fde59 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -43,7 +43,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 */ + 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 +76,7 @@ static void bootmenu_print_entry(void *data) if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%ls", entry->title); + printf("%s", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -170,8 +170,9 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, struct bootmenu_entry *iter = *current; while ((option = bootmenu_getoption(i))) { - u16 *buf; + char *buf; + /* bootmenu_[num] format is "[title]=[commands]" */ sep = strchr(option, '='); if (!sep) { printf("Invalid bootmenu entry: %s\n", option); @@ -182,24 +183,21 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, if (!entry) return -ENOMEM; - len = sep-option; - buf = calloc(1, (len + 1) * sizeof(u16)); + len = sep - option; + buf = calloc(1, (len + 1)); entry->title = buf; if (!entry->title) { free(entry); return -ENOMEM; } - utf8_utf16_strncpy(&buf, option, len); + strncpy(buf, option, len); - len = strlen(sep + 1); - entry->command = malloc(len + 1); + entry->command = strdup(sep + 1); if (!entry->command) { free(entry->title); free(entry); return -ENOMEM; } - memcpy(entry->command, sep + 1, len); - entry->command[len] = 0; sprintf(entry->key, "%d", i); @@ -227,6 +225,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 * @@ -279,13 +278,17 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, } if (lo.attributes & LOAD_OPTION_ACTIVE) { - entry->title = u16_strdup(lo.label); - if (!entry->title) { + char *buf; + + buf = calloc(1, utf16_utf8_strlen(lo.label) + 1); + if (!buf) { free(load_option); free(entry); free(bootorder); return -ENOMEM; } + entry->title = buf; + utf16_utf8_strncpy(&buf, lo.label, u16_strlen(lo.label)); entry->command = strdup("bootefi bootmgr"); sprintf(entry->key, "%d", i); entry->num = i; @@ -315,6 +318,7 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, return 1; } +#endif static struct bootmenu_data *bootmenu_create(int delay) { @@ -341,13 +345,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) { +#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 +361,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 = strdup("U-Boot console"); else - entry->title = u16_strdup(u"Quit"); + entry->title = strdup("Quit"); if (!entry->title) { free(entry); @@ -461,7 +465,7 @@ static enum bootmenu_ret bootmenu_show(int delay) int cmd_ret; int init = 0; void *choice = NULL; - u16 *title = NULL; + char *title = NULL; char *command = NULL; struct menu *menu; struct bootmenu_entry *iter; @@ -517,7 +521,7 @@ static enum bootmenu_ret bootmenu_show(int delay) if (menu_get_choice(menu, &choice) == 1) { iter = choice; - title = u16_strdup(iter->title); + title = strdup(iter->title); command = strdup(iter->command); /* last entry is U-Boot console or Quit */ @@ -561,7 +565,7 @@ cleanup: } if (title && command) { - debug("Starting entry '%ls'\n", title); + debug("Starting entry '%s'\n", title); free(title); if (efi_ret == EFI_SUCCESS) cmd_ret = run_command(command, 0);