All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] fix issues in bootmenu after adding efi entries
@ 2022-05-26 10:09 Masahisa Kojima
  2022-05-26 10:09 ` [PATCH v2 1/2] bootmenu: use utf-8 for menu title Masahisa Kojima
  2022-05-26 10:09 ` [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default Masahisa Kojima
  0 siblings, 2 replies; 7+ messages in thread
From: Masahisa Kojima @ 2022-05-26 10:09 UTC (permalink / raw)
  To: u-boot
  Cc: Pali Rohar, Heinrich Schuchardt, Ilias Apalodimas,
	Takahiro Akashi, Mark Kettenis, Masahisa Kojima

This series fixes the issue in bootmenu after adding efi entries.

Masahisa Kojima (2):
  bootmenu: use utf-8 for menu title
  bootmenu: U-Boot console is enabled as default

 boot/Kconfig   |  7 +++++++
 cmd/Kconfig    | 10 ----------
 cmd/bootmenu.c | 40 +++++++++++++++++++++++-----------------
 3 files changed, 30 insertions(+), 27 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] bootmenu: use utf-8 for menu title
  2022-05-26 10:09 [PATCH v2 0/2] fix issues in bootmenu after adding efi entries Masahisa Kojima
@ 2022-05-26 10:09 ` Masahisa Kojima
  2022-05-28  8:37   ` Heinrich Schuchardt
  2022-05-26 10:09 ` [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default Masahisa Kojima
  1 sibling, 1 reply; 7+ messages in thread
From: Masahisa Kojima @ 2022-05-26 10:09 UTC (permalink / raw)
  To: u-boot
  Cc: Pali Rohar, Heinrich Schuchardt, Ilias Apalodimas,
	Takahiro Akashi, Mark Kettenis, Masahisa Kojima

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 <masahisa.kojima@linaro.org>
Tested-by: Pali Rohar <pali@kernel.org>
---

(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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default
  2022-05-26 10:09 [PATCH v2 0/2] fix issues in bootmenu after adding efi entries Masahisa Kojima
  2022-05-26 10:09 ` [PATCH v2 1/2] bootmenu: use utf-8 for menu title Masahisa Kojima
@ 2022-05-26 10:09 ` Masahisa Kojima
  2022-05-27  9:59   ` Ilias Apalodimas
  1 sibling, 1 reply; 7+ messages in thread
From: Masahisa Kojima @ 2022-05-26 10:09 UTC (permalink / raw)
  To: u-boot
  Cc: Pali Rohar, Heinrich Schuchardt, Ilias Apalodimas,
	Takahiro Akashi, Mark Kettenis, Masahisa Kojima, Simon Glass,
	Alexandru Gagniuc, Steffen Jaeckel, Michal Simek, Ovidiu Panait,
	Ashok Reddy Soma

The commit 2158b0da220c ("bootmenu: add Kconfig option
not to enter U-Boot console") disables to enter U-Boot
console from bootmenu as default, this change affects the
existing bootmenu users.

This commit reverts the default behavior, the bootmenu can
enter U-Boot console same as before.
CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is renamed
BOOTMENU_DISABLE_UBOOT_CONSOLE and depends on
AUTOBOOT_MENU_SHOW.

Fixes: 2158b0da220c ("bootmenu: add Kconfig option not to enter U-Boot console")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Tested-by: Pali Rohar <pali@kernel.org>
---
Changes in v2:
- remove "default n" since it is default option
- use 80 characters in one line

 boot/Kconfig   |  7 +++++++
 cmd/Kconfig    | 10 ----------
 cmd/bootmenu.c |  4 ++--
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index dff4d23b88..08451c65a5 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -1143,6 +1143,13 @@ config AUTOBOOT_MENU_SHOW
 	  environmnent variable (if enabled) and before handling the boot delay.
 	  See README.bootmenu for more details.
 
+config BOOTMENU_DISABLE_UBOOT_CONSOLE
+	bool "Disallow bootmenu to enter the U-Boot console"
+	depends on AUTOBOOT_MENU_SHOW
+	help
+	  If this option is enabled, user can not enter the U-Boot console from
+	  bootmenu. It increases the system security.
+
 config BOOT_RETRY
 	bool "Boot retry feature"
 	help
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 69c1814d24..09193b61b9 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -357,16 +357,6 @@ config CMD_BOOTMENU
 	help
 	  Add an ANSI terminal boot menu command.
 
-config CMD_BOOTMENU_ENTER_UBOOT_CONSOLE
-	bool "Allow Bootmenu to enter the U-Boot console"
-	depends on CMD_BOOTMENU
-	default n
-	help
-	  Add an entry to enter U-Boot console in bootmenu.
-	  If this option is disabled, user can not enter
-	  the U-Boot console from bootmenu. It increases
-	  the system security.
-
 config CMD_ADTIMG
 	bool "adtimg"
 	help
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index bf88c2127b..1002c6b20a 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -362,7 +362,7 @@ static struct bootmenu_data *bootmenu_create(int delay)
 			goto cleanup;
 
 		/* Add Quit entry if entering U-Boot console is disabled */
-		if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE))
+		if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE))
 			entry->title = strdup("U-Boot console");
 		else
 			entry->title = strdup("Quit");
@@ -595,7 +595,7 @@ int menu_show(int bootdelay)
 		if (ret == BOOTMENU_RET_UPDATED)
 			continue;
 
-		if (!IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) {
+		if (IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE)) {
 			if (ret == BOOTMENU_RET_QUIT) {
 				/* default boot process */
 				if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default
  2022-05-26 10:09 ` [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default Masahisa Kojima
@ 2022-05-27  9:59   ` Ilias Apalodimas
  0 siblings, 0 replies; 7+ messages in thread
From: Ilias Apalodimas @ 2022-05-27  9:59 UTC (permalink / raw)
  To: Masahisa Kojima
  Cc: u-boot, Pali Rohar, Heinrich Schuchardt, Takahiro Akashi,
	Mark Kettenis, Simon Glass, Alexandru Gagniuc, Steffen Jaeckel,
	Michal Simek, Ovidiu Panait, Ashok Reddy Soma

On Thu, 26 May 2022 at 13:08, Masahisa Kojima
<masahisa.kojima@linaro.org> wrote:
>
> The commit 2158b0da220c ("bootmenu: add Kconfig option
> not to enter U-Boot console") disables to enter U-Boot
> console from bootmenu as default, this change affects the
> existing bootmenu users.
>
> This commit reverts the default behavior, the bootmenu can
> enter U-Boot console same as before.
> CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is renamed
> BOOTMENU_DISABLE_UBOOT_CONSOLE and depends on
> AUTOBOOT_MENU_SHOW.
>
> Fixes: 2158b0da220c ("bootmenu: add Kconfig option not to enter U-Boot console")
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> Tested-by: Pali Rohar <pali@kernel.org>
> ---
> Changes in v2:
> - remove "default n" since it is default option
> - use 80 characters in one line
>
>  boot/Kconfig   |  7 +++++++
>  cmd/Kconfig    | 10 ----------
>  cmd/bootmenu.c |  4 ++--
>  3 files changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/boot/Kconfig b/boot/Kconfig
> index dff4d23b88..08451c65a5 100644
> --- a/boot/Kconfig
> +++ b/boot/Kconfig
> @@ -1143,6 +1143,13 @@ config AUTOBOOT_MENU_SHOW
>           environmnent variable (if enabled) and before handling the boot delay.
>           See README.bootmenu for more details.
>
> +config BOOTMENU_DISABLE_UBOOT_CONSOLE
> +       bool "Disallow bootmenu to enter the U-Boot console"
> +       depends on AUTOBOOT_MENU_SHOW
> +       help
> +         If this option is enabled, user can not enter the U-Boot console from
> +         bootmenu. It increases the system security.
> +
>  config BOOT_RETRY
>         bool "Boot retry feature"
>         help
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 69c1814d24..09193b61b9 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -357,16 +357,6 @@ config CMD_BOOTMENU
>         help
>           Add an ANSI terminal boot menu command.
>
> -config CMD_BOOTMENU_ENTER_UBOOT_CONSOLE
> -       bool "Allow Bootmenu to enter the U-Boot console"
> -       depends on CMD_BOOTMENU
> -       default n
> -       help
> -         Add an entry to enter U-Boot console in bootmenu.
> -         If this option is disabled, user can not enter
> -         the U-Boot console from bootmenu. It increases
> -         the system security.
> -
>  config CMD_ADTIMG
>         bool "adtimg"
>         help
> diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> index bf88c2127b..1002c6b20a 100644
> --- a/cmd/bootmenu.c
> +++ b/cmd/bootmenu.c
> @@ -362,7 +362,7 @@ static struct bootmenu_data *bootmenu_create(int delay)
>                         goto cleanup;
>
>                 /* Add Quit entry if entering U-Boot console is disabled */
> -               if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE))
> +               if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE))
>                         entry->title = strdup("U-Boot console");
>                 else
>                         entry->title = strdup("Quit");
> @@ -595,7 +595,7 @@ int menu_show(int bootdelay)
>                 if (ret == BOOTMENU_RET_UPDATED)
>                         continue;
>
> -               if (!IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) {
> +               if (IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE)) {
>                         if (ret == BOOTMENU_RET_QUIT) {
>                                 /* default boot process */
>                                 if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
> --
> 2.17.1
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] bootmenu: use utf-8 for menu title
  2022-05-26 10:09 ` [PATCH v2 1/2] bootmenu: use utf-8 for menu title Masahisa Kojima
@ 2022-05-28  8:37   ` Heinrich Schuchardt
  2022-05-29  1:37     ` Masahisa Kojima
  0 siblings, 1 reply; 7+ messages in thread
From: Heinrich Schuchardt @ 2022-05-28  8:37 UTC (permalink / raw)
  To: Masahisa Kojima
  Cc: Pali Rohar, Ilias Apalodimas, Takahiro Akashi, Mark Kettenis, u-boot

On 5/26/22 12:09, Masahisa Kojima wrote:
> 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 <masahisa.kojima@linaro.org>
> Tested-by: Pali Rohar <pali@kernel.org>
> ---
>
> (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;

%s/sep-option/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);

Instead of two function calls (calloc, strncpy) simply use strdup().

>
>   		len = strlen(sep + 1);
>   		entry->command = malloc(len + 1);

Use strdup() here too.

Best regards

Heinrich

> @@ -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);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] bootmenu: use utf-8 for menu title
  2022-05-28  8:37   ` Heinrich Schuchardt
@ 2022-05-29  1:37     ` Masahisa Kojima
  2022-05-29  9:07       ` Pali Rohar
  0 siblings, 1 reply; 7+ messages in thread
From: Masahisa Kojima @ 2022-05-29  1:37 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Pali Rohar, Ilias Apalodimas, Takahiro Akashi, Mark Kettenis, u-boot

On Sat, 28 May 2022 at 17:37, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 5/26/22 12:09, Masahisa Kojima wrote:
> > 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 <masahisa.kojima@linaro.org>
> > Tested-by: Pali Rohar <pali@kernel.org>
> > ---
> >
> > (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;
>
> %s/sep-option/sep - option/

OK.

>
> > -             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);
>
> Instead of two function calls (calloc, strncpy) simply use strdup().

bootmenu_x format is "[title]=[commands]", title is not the
NUL-terminated string, so we can not use strdup here.

>
> >
> >               len = strlen(sep + 1);
> >               entry->command = malloc(len + 1);
>
> Use strdup() here too.

OK, command is NUL-terminated.

Thank you for your comment.

Regards,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > @@ -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);
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] bootmenu: use utf-8 for menu title
  2022-05-29  1:37     ` Masahisa Kojima
@ 2022-05-29  9:07       ` Pali Rohar
  0 siblings, 0 replies; 7+ messages in thread
From: Pali Rohar @ 2022-05-29  9:07 UTC (permalink / raw)
  To: Masahisa Kojima
  Cc: Heinrich Schuchardt, Ilias Apalodimas, Takahiro Akashi,
	Mark Kettenis, u-boot

On Sunday 29 May 2022 10:37:23 Masahisa Kojima wrote:
> On Sat, 28 May 2022 at 17:37, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> > On 5/26/22 12:09, Masahisa Kojima wrote:
> > > @@ -183,13 +183,13 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu,
> > >                       return -ENOMEM;
> > >
> > >               len = sep-option;
> >
> > %s/sep-option/sep - option/
> 
> OK.
> 
> >
> > > -             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);
> >
> > Instead of two function calls (calloc, strncpy) simply use strdup().
> 
> bootmenu_x format is "[title]=[commands]", title is not the
> NUL-terminated string, so we can not use strdup here.

Usage of C's strncpy() function should be in most cases avoided as when
target buffer does not have enough space this function does not fill
nul-term byte. (Anyway, I do not know if U-Boot implements strncpy()
according to C standard with this trap or not)

But if you already have length of string then you should use memcpy().

> >
> > >
> > >               len = strlen(sep + 1);
> > >               entry->command = malloc(len + 1);
> >
> > Use strdup() here too.
> 
> OK, command is NUL-terminated.
> 
> Thank you for your comment.
> 
> Regards,
> Masahisa Kojima

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-29  9:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 10:09 [PATCH v2 0/2] fix issues in bootmenu after adding efi entries Masahisa Kojima
2022-05-26 10:09 ` [PATCH v2 1/2] bootmenu: use utf-8 for menu title Masahisa Kojima
2022-05-28  8:37   ` Heinrich Schuchardt
2022-05-29  1:37     ` Masahisa Kojima
2022-05-29  9:07       ` Pali Rohar
2022-05-26 10:09 ` [PATCH v2 2/2] bootmenu: U-Boot console is enabled as default Masahisa Kojima
2022-05-27  9:59   ` Ilias Apalodimas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.