From patchwork Thu May 26 10:09: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: 576239 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:c603:0:0:0:0 with SMTP id jv3csp426790mab; Thu, 26 May 2022 03:09:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4wovBwMBfns1FjVCPuBkdByykdn5dI1jp+1wwqLIGmjx1cjZQzyPZoI1v4uK12OH2Rkxk X-Received: by 2002:a05:6e02:12c7:b0:2d1:b346:c5aa with SMTP id i7-20020a056e0212c700b002d1b346c5aamr8978329ilm.57.1653559753068; Thu, 26 May 2022 03:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653559753; cv=none; d=google.com; s=arc-20160816; b=0kSNQGIKPLYxuYkJrUeugfxZPiUfBW91icIWNfoPWOe1pGNg18XenDD+UHnbRRnBFh VTkZCRqo6mZqfH7aF8TxfztfL1mED1yb+aLAW9ceuDf2AwNmx4AQFeEhUazSXq60otDs jejr/N9Nyz80rKj4L26IEqTTPBYj9/FyDQxSNfqWZZZA/jMNd390Ub2RbxqkhHEMg7m1 HlFrEu0t6ZvpIkWtwv2GTS1cMbO+0t1DBYuAnQIMCXILeX87bYPgN19y0Vx7dKA3pgZh OkhcJ9DGP3uWYwnQzCSm6+8ouv4RhmcHwUCt5dqiGBnz1XRNhxHYgnRdEtcpo6QHuffQ 7oog== 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=q/aMoAwe7SA6xsIkX4v+i1irvmyeYHcCvItJ2S1L+j0=; b=naBwXVm45V8pvQDfqXToKkNV0Q7dvf9o8e570njJYaDz2ycCxWEccFJwgu27ANIzxJ RZnWGrbanJtZLtFIokbc1WGqN28qMujtk9rckbL/5l7ndW1UmBRzWWLEmKnODxE1MBT5 ovwcV+3/lfyzVfcW8x3noGTk4fLIg98IRJDHh/tgZJj2Lq+ZCy0P3Xhgl9jEcGgkg7Dh PINXIjmENH46pQmCRuQyzwTFblZ4ao6XtcSV0QRHHIJzsJrwWd/V9Knp30wxB/x227OB RraXga0jvZ7eF4qQv1l8Nl0twqu3tqOOZkkML2sLqibheIOPDXqooxBRjfSqXyDTEwVJ vi/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V8x8DApu; 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 p17-20020a056e0206d100b002d1b63b4b49si942419ils.136.2022.05.26.03.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 03:09:13 -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=V8x8DApu; 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 E0ABA84347; Thu, 26 May 2022 12:09:10 +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="V8x8DApu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4C39084322; Thu, 26 May 2022 12:08:56 +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-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 AFF0283DFE for ; Thu, 26 May 2022 12:08:52 +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-pl1-x62b.google.com with SMTP id a13so1058112plh.6 for ; Thu, 26 May 2022 03:08:52 -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=q/aMoAwe7SA6xsIkX4v+i1irvmyeYHcCvItJ2S1L+j0=; b=V8x8DApu9Qfqy2hLDU/WXB9TW5zzZBUyfzqvw0iKYhi4pGAGwgMN3VlQUsacELq+qz sv1n/1lmJWMn/7JHzWNEIr8CSKmea6P+zYKbBFRquAAeepAdvdAB0b67agG6jEu5Ijvk EPpLhO9tH9EiB1sPqHYmhK3MIjLMII8I6LGE5eGB4fuXhfbUHZdj99AtPk0Y5bOYsudw kx0VKKN89M9/kr+v/w0Yg5ZTvUGGwId5JZCHA8jFs62x7E1LHQXJPmwEaLNMFC0G1qQW XxnpWkH/0yGvwZJXrDFK0K0RET5pfcJoY9K+Mwm4nYJmnTizKDoETCN/IPxrfJNEag/S Lo3Q== 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=q/aMoAwe7SA6xsIkX4v+i1irvmyeYHcCvItJ2S1L+j0=; b=1KiIbvYQywHWN5+TG2oHiDi/vjlmQ/qVBvAa840JVfqIsZ1FrIS+G0LN5N3ttYIDLt hD8pO2ZRqVJOBTujh02zNAECaTHrVAcauxejiWHkm11vvb/rTNwbrKV8xS/TmLNPhlYR FxdUjoM3JfbZIdfLalIB6eEedbNBCC7LNcd4g9KH4h/+vJW+HGOpp8Hi7vSi+5YKSb01 5Dd8Pp2kl1cDnmjvZQLLw7z1s3oHsFyuaF6+GA4hswKcPtatfBh1b6DhnNrOvVqR7SH2 PK+MXJZNSVDrg/AetW7snBbxKnpbhacp6QMTCwWU2MoDmchpuWURY4hBPwTMz25GYk6S b50g== X-Gm-Message-State: AOAM5318HkKOuP8GI4CCeuvBO0zOcogshN61OlspzOoo8o0sn6T1z04b 2S4M2VjbWBq6Y1thQCaJQEhOo8QkPxbgog== X-Received: by 2002:a17:90a:778c:b0:1df:56a5:8474 with SMTP id v12-20020a17090a778c00b001df56a58474mr1819327pjk.63.1653559730900; Thu, 26 May 2022 03:08:50 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id x1-20020a633101000000b003f60a8d7dadsm1141288pgx.15.2022.05.26.03.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 03:08:50 -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 v2 1/2] bootmenu: use utf-8 for menu title Date: Thu, 26 May 2022 19:09:37 +0900 Message-Id: <20220526100938.9558-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220526100938.9558-1-masahisa.kojima@linaro.org> References: <20220526100938.9558-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 --- (no change since v1) cmd/bootmenu.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 8859eebea5..bf88c2127b 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,7 +170,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, struct bootmenu_entry *iter = *current; while ((option = bootmenu_getoption(i))) { - u16 *buf; + char *buf; sep = strchr(option, '='); if (!sep) { @@ -183,13 +183,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)); 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); @@ -227,6 +227,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 +280,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 +320,7 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, return 1; } +#endif static struct bootmenu_data *bootmenu_create(int delay) { @@ -341,13 +347,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 +363,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 +467,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 +523,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 +567,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);