From patchwork Thu Apr 28 08:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 567133 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp5233092map; Thu, 28 Apr 2022 01:12:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI6nSgSdeVpMnEbnsBzTz/HtoUmeD29TkhTPsU8HlfggAjnSARZdwtmHhRyKCNDHHYrIQd X-Received: by 2002:a17:906:cb09:b0:6f3:87ca:1351 with SMTP id lk9-20020a170906cb0900b006f387ca1351mr21164251ejb.674.1651133551833; Thu, 28 Apr 2022 01:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651133551; cv=none; d=google.com; s=arc-20160816; b=wGkogo9r0iHIcBAgBYF7acBQ6NW2GCk2j8ez+37Y8KaAfsVwGr5ZBRslDywmkeVGy8 eAERnZtIJhjF5p2j904qZgNNsk4dBV2zYlN6FiHQrUAbQhCpCk/0mHnvmqK0R2AElV4Z Lc5jYZAlug/v1WypdvGBzl54E2S1TtCc/QGPvakYsaTYfCaNGCFouPEbh7ASHEH+or1U aY3/iGwXYZPa92tmvgVMxxkepa2JKXQT9lc1JbabOuANC8fuby7drZgWh0f6GkcAOGx0 9xXaYPfgXBp1hnwJkVMpL4sDDdvE2XDoa70CfEs3A/T0o5kdISVWTZvurNWD41KVP8j8 TS/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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n4W36B8jOo8JDupeTyquxGIwlG2fL+m3SorYvvl2pzE=; b=0LdeJNuEDgd53kJ4X+tVyGFHBLjDUjjlB80rq0/C/DEQsZrqRG6HZIHV3tijr/n1aa D5xXQBTR2+/lQ/knXKt4ulXqzYgb2urNwS2Nn2lYCG3ktdG+KVbWTVeMXK05AGZ3+G3G o5WfDSDXjDye9VhHPXtvN8Rh5UDYSyXy4apMoZxjSC+5oXEdiY84W2VB4RQQaRaDhkxh yBTf/0FZah7GWf19t6mX4WwUofiZvB75EdhAq6KsUbTZFD+yu6dIgac0hPBZNQWBcQ4q xgTldgkLAVxsVgim6ikLcRdDGw9lAdHaETniWcujO72YxTgtlx47iDi5gfJDZYHZ+oJE qXsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OhCHj73p; 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 lz4-20020a170906fb0400b006e8a89825fesi3053319ejb.768.2022.04.28.01.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:12:31 -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=OhCHj73p; 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 E29F083EDF; Thu, 28 Apr 2022 10:11:40 +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="OhCHj73p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D00B8393F; Thu, 28 Apr 2022 10:11:10 +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-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 318B783565 for ; Thu, 28 Apr 2022 10:11: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-pl1-x632.google.com with SMTP id k4so3685962plk.7 for ; Thu, 28 Apr 2022 01:11: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=n4W36B8jOo8JDupeTyquxGIwlG2fL+m3SorYvvl2pzE=; b=OhCHj73ppHQTHoS3OIOwF2+0NUMmlTwQ3uWdyrMcDExeVJWPJ/LWzyUTszzeAfFmxs tKwRpMTPaJSmc4uapr8HZ+uOmR0gic1RbULuqpNQwyRmSBFdCmaCV4C0XtQfTtwkTErX flOvUx8T0/O4SUnUAgG9KKdw9uFAy05PAPgBteNC/uklpgEN3PyRZ+8pU+BOzR/Bnf3P O0eYPi41ZUVBuBRqLRAKmyG2R8zr339Yp7WN1mUlR5zV41gbqLmaEKNhfHnFKJFmdioT 8IMUEO424M964pgL/N9gP60OO6IP6uSgA7YO88u1xCd0o453VfY5kg0QCgSzP8CaJvmm UHpg== 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:mime-version:content-transfer-encoding; bh=n4W36B8jOo8JDupeTyquxGIwlG2fL+m3SorYvvl2pzE=; b=JMeKm9pQzN0LxPdIHYqTCTAC02hudDlzenYrBA91pPp9D3JD5vA9g/v/vJbUPEkHDO avi6jjqHLpo4m2xcCpzLpiKOHU7FGe7FBzlXEVfH0l6CDtpAxfC3ifvnxS93TiFviSsw c7vs+rCS4usdkzfRWI5+F8yA//qd/H+egIt9OcBN8eZsPBZeDSuZ6NZILpNrfBch16rF JQ6xqt10dyTTxjhaADBqGJYMHNwYp2l0Ess/H2vi1vHs4lcJjkD+EcETS4UJVH0k9XXT 3UUZVEfwJTCwDvb/yQs4KOHiEP9mVRIUmm9RS+4pT9IEN9nHWHa6Se9A+zTBeqShGpHU 0oXA== X-Gm-Message-State: AOAM533499clcUlbMVL2MTLfWPzU0KgmvuIRWMdq6q23FicwX3DE375G /Im2+ls+MPDZ+HPAs22twaKnJq4G5l+8Xg== X-Received: by 2002:a17:902:820f:b0:158:c308:d4c5 with SMTP id x15-20020a170902820f00b00158c308d4c5mr32167147pln.155.1651133458423; Thu, 28 Apr 2022 01:10:58 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id b15-20020a17090a7acf00b001cd4989ff5fsm5684259pjl.38.2022.04.28.01.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:10:57 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v5 08/17] bootmenu: update bootmenu_entry structure Date: Thu, 28 Apr 2022 17:09:41 +0900 Message-Id: <20220428080950.23509-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220428080950.23509-1-masahisa.kojima@linaro.org> References: <20220428080950.23509-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 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 This is a preparation for succeeding addition of uefi boot and distro boot menu entries into bootmenu. The bootmenu_entry title is updated to u16 string because uefi use u16 string. This commit also factors out the function to prepare the entries generated by "bootmenu_x" U-Boot environment variable. This commit also updates the bootmenu entry title. The entry derived from "bootmenu_x" U-Boot environment variable has the "bootmenu_xx" prefix as below. *** U-Boot Boot Menu *** bootmenu_00 : Boot 1. kernel bootmenu_01 : Boot 2. kernel bootmenu_02 : Reset board Signed-off-by: Masahisa Kojima --- Changes in v5: - split into the separate patch - add function description comment cmd/bootmenu.c | 110 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 9a32a18b19..15ad621c9f 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -3,6 +3,7 @@ * (C) Copyright 2011-2013 Pali Rohár */ +#include #include #include #include @@ -24,11 +25,18 @@ */ #define MAX_ENV_SIZE (9 + 2 + 1) +enum boot_type { + BOOTMENU_TYPE_NONE = 0, + BOOTMENU_TYPE_BOOTMENU, +}; + struct bootmenu_entry { unsigned short int num; /* unique number 0 .. MAX_COUNT */ char key[3]; /* key identifier of number */ - char *title; /* title of entry */ + u16 *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 */ struct bootmenu_data *menu; /* this bootmenu */ struct bootmenu_entry *next; /* next menu entry (num+1) */ }; @@ -75,7 +83,10 @@ static void bootmenu_print_entry(void *data) if (reverse) puts(ANSI_COLOR_REVERSE); - puts(entry->title); + if (entry->type == BOOTMENU_TYPE_BOOTMENU) + printf("bootmenu_%02d : %ls", entry->bootorder, entry->title); + else + printf("%ls", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -279,31 +290,32 @@ static void bootmenu_destroy(struct bootmenu_data *menu) free(menu); } -static struct bootmenu_data *bootmenu_create(int delay) +/** + * prepare_bootmenu_entry() - generate the bootmenu_xx entries + * + * This function read the "bootmenu_x" U-Boot environment variable + * and generate the bootmenu entries. + * + * @menu: pointer to the bootmenu structure + * @current: pointer to the last bootmenu entry list + * @index: pointer to the index of the last bootmenu entry, + * the number of bootmenu entry is added by this function + * Return: 1 on success, negative value on error + */ +static int prepare_bootmenu_entry(struct bootmenu_data *menu, + struct bootmenu_entry **current, + unsigned short int *index) { - unsigned short int i = 0; - const char *option; - struct bootmenu_data *menu; - struct bootmenu_entry *iter = NULL; - int len; char *sep; - char *default_str; - struct bootmenu_entry *entry; - - menu = malloc(sizeof(struct bootmenu_data)); - if (!menu) - return NULL; - - menu->delay = delay; - menu->active = 0; - menu->first = NULL; - - default_str = env_get("bootmenu_default"); - if (default_str) - menu->active = (int)simple_strtol(default_str, NULL, 10); + const char *option; + unsigned short int i = *index; + struct bootmenu_entry *entry = NULL; + struct bootmenu_entry *iter = *current; while ((option = bootmenu_getoption(i))) { + u16 *buf; + sep = strchr(option, '='); if (!sep) { printf("Invalid bootmenu entry: %s\n", option); @@ -312,23 +324,23 @@ static struct bootmenu_data *bootmenu_create(int delay) entry = malloc(sizeof(struct bootmenu_entry)); if (!entry) - goto cleanup; + return -ENOMEM; len = sep-option; - entry->title = malloc(len + 1); + buf = calloc(1, (len + 1) * sizeof(u16)); + entry->title = buf; if (!entry->title) { free(entry); - goto cleanup; + return -ENOMEM; } - memcpy(entry->title, option, len); - entry->title[len] = 0; + utf8_utf16_strncpy(&buf, option, len); len = strlen(sep + 1); entry->command = malloc(len + 1); if (!entry->command) { free(entry->title); free(entry); - goto cleanup; + return -ENOMEM; } memcpy(entry->command, sep + 1, len); entry->command[len] = 0; @@ -337,6 +349,8 @@ static struct bootmenu_data *bootmenu_create(int delay) entry->num = i; entry->menu = menu; + entry->type = BOOTMENU_TYPE_BOOTMENU; + entry->bootorder = i; entry->next = NULL; if (!iter) @@ -351,13 +365,44 @@ static struct bootmenu_data *bootmenu_create(int delay) break; } + *index = i; + *current = iter; + + return 1; +} + +static struct bootmenu_data *bootmenu_create(int delay) +{ + int ret; + unsigned short int i = 0; + struct bootmenu_data *menu; + struct bootmenu_entry *iter = NULL; + struct bootmenu_entry *entry; + char *default_str; + + menu = malloc(sizeof(struct bootmenu_data)); + if (!menu) + return NULL; + + menu->delay = delay; + menu->active = 0; + menu->first = NULL; + + default_str = env_get("bootmenu_default"); + if (default_str) + menu->active = (int)simple_strtol(default_str, NULL, 10); + + ret = prepare_bootmenu_entry(menu, &iter, &i); + if (ret < 0) + goto cleanup; + /* Add U-Boot console entry at the end */ if (i <= MAX_COUNT - 1) { entry = malloc(sizeof(struct bootmenu_entry)); if (!entry) goto cleanup; - entry->title = strdup("U-Boot console"); + entry->title = u16_strdup(u"U-Boot console"); if (!entry->title) { free(entry); goto cleanup; @@ -374,6 +419,7 @@ static struct bootmenu_data *bootmenu_create(int delay) entry->num = i; entry->menu = menu; + entry->type = BOOTMENU_TYPE_NONE; entry->next = NULL; if (!iter) @@ -431,7 +477,7 @@ static void bootmenu_show(int delay) { int init = 0; void *choice = NULL; - char *title = NULL; + u16 *title = NULL; char *command = NULL; struct menu *menu; struct bootmenu_data *bootmenu; @@ -482,7 +528,7 @@ static void bootmenu_show(int delay) if (menu_get_choice(menu, &choice) == 1) { iter = choice; - title = strdup(iter->title); + title = u16_strdup(iter->title); command = strdup(iter->command); } @@ -497,7 +543,7 @@ cleanup: } if (title && command) { - debug("Starting entry '%s'\n", title); + debug("Starting entry '%ls'\n", title); free(title); run_command(command, 0); free(command);