From patchwork Wed May 25 08:18:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 575994 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:c603:0:0:0:0 with SMTP id jv3csp2985798mab; Wed, 25 May 2022 01:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylv7BD7a0NP8zjkjHLMT7e+6W8/w9XO+Ieq84B0KMApdQCpG7srn+WjZKFuSGtIrAOFAvi X-Received: by 2002:a05:6638:dc7:b0:32e:bee0:f62b with SMTP id m7-20020a0566380dc700b0032ebee0f62bmr8191221jaj.285.1653466657211; Wed, 25 May 2022 01:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653466657; cv=none; d=google.com; s=arc-20160816; b=Q5VWsI9glV8mNoB2MvBRo2ZAYFxnZINqgjKMFQNSWrXsSA1FZWc4K8mAdwyVDyAe9R sWMcJZoJXitx82Mwr33hMHuNWBtIhMHVnlhvWn0vP3AJHGEosqwnLk/A8acmVduOpzle E3zcWFe5xBK2tfOirYVYrRXBazaVyZ2MOjPowbRo6iGny2hyMyz56aSPhriH0dAfWwFj iOuOVS2kzKytC8Y0/lgqHXKYZRZ+OvO2jnsbabVw83SDeED/45HGuH1TvNfYwBl3rCLW vn4Z4J8ZjyC4eIyIj8Pdvrc1PdR+PJa3GodI0aOx10ARwtln9JFTXtPPlqXZJpVfKI3f caJg== 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=h7IxxUDRDMAL5ylXDSH+dEZKWgkYPPQgIPV+0xwqDAU=; b=lWz06iGil8vxP4Zo3yCoKpReuvBZDWUNQ6o93ECF/Ro/XdDGmQ/FwLb1EYWV0uI0Rb 71zJNb69izsdna0HMTWT0pMfvDxTrsxRw9syndlKG+bCHeHCMmdheZ5i8pMZUK5JL+Kk AO2QFa4LszZWUFFj0q4h+Avmg+DZsmcSkKy5jJ4muHX/xL/dqUVUZ9lz4Dam65Q4EK7a EPB/SXKPO9YWnTPTdr5JzsNnk+my9/+a/lGryhH2IyRAVu2HVs/wTkIpuFwBtDHPwPmO gkqXOerDwwoXUh8IRlIH18qJLw0utn5vAWNfQqdrKtCAeC2+GuCwlJw4fA/M3/atOIYH VedA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sq9X7Cee; 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 z12-20020a05660229cc00b0065aa0cb4250si20161017ioq.4.2022.05.25.01.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 01:17:37 -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=Sq9X7Cee; 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 B4B7E8431F; Wed, 25 May 2022 10:17:33 +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="Sq9X7Cee"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C99D1842FB; Wed, 25 May 2022 10:17:25 +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-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 A62598430F for ; Wed, 25 May 2022 10:17: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=masahisa.kojima@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id gk22so601873pjb.1 for ; Wed, 25 May 2022 01:17:21 -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=h7IxxUDRDMAL5ylXDSH+dEZKWgkYPPQgIPV+0xwqDAU=; b=Sq9X7CeeAVAK6p92WgvJqm8TiTVOIVnxr/BvkQl2FLHzbmudwPlB7L1VEawx10bzma DE8Ds9aqOA6AmAcVFh5/ljD2YxuNxvxtYjxBm6O1hkhsjCHzQTMs4QoFwjp32+OUgbTk eUk33xbZx0ecCDRyzavrY/VtTMA1N2Q5Wjxkt/h/fSPlyH5++d2R86Yz6Ycg08o6ExKs hR91M/exXCSVxNa6qh7PL/vxT/wzlW2zeu3u0qhLA8ie3iBEAmJpN3/QgINekEdyv8Vh O/abgS3g4U2MXcaX/pYkeHQD3S/EvCRwVUDYcX77LGr6P+kWyNv3DIa0bS7VTinyXb3u SlQQ== 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=h7IxxUDRDMAL5ylXDSH+dEZKWgkYPPQgIPV+0xwqDAU=; b=TZmBuwUwxzAy3roLg/Y6jU//IjUeLI9IwYjGIKmDTGPWh4TzHmILfu3CMmY4Vpv47e GXhh3pJluUPm+5ixKX1SPfIdCPSdJKx9KUe6tTVUTzWqt/xTH2yENl8vbddOmqQgg8uI GoV+bzz2/kF9ox+55ps6oAFa5Ctl0YfuFpcfJ/otoppbyEZaZvuAVxcT5skxfE9tS3Xm GvzZkrybP4RL7TvFPSS5Pl8BWv0+qKc2X3bjRRcKAcxeSJfTFD4rFel9eX9cC2MDryIa 5/VDVJ4uSs3EH1yhgfn9k/YOQ+n7bBypKci5jlj5FX62D11UAcQKXUL2JSaqJFR0y6pk F1ow== X-Gm-Message-State: AOAM531w8cUALg6i8JXbAEjnCbmCEABeBqsvj/kPsNEOs/1NNkfeRtfW mk6qUdtYGawcJbJgfWtPxMA/S49CAVjWNw== X-Received: by 2002:a17:902:f552:b0:163:5058:f16a with SMTP id h18-20020a170902f55200b001635058f16amr3401287plf.119.1653466639859; Wed, 25 May 2022 01:17:19 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id a8-20020a1709027d8800b00162529828aesm2021225plm.109.2022.05.25.01.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 01:17:19 -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 1/2] bootmenu: use utf-8 for menu title Date: Wed, 25 May 2022 17:18:12 +0900 Message-Id: <20220525081813.26214-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220525081813.26214-1-masahisa.kojima@linaro.org> References: <20220525081813.26214-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 --- 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);