[PATCH] bootmenu: fix bootmenu title handling
Pali Rohar
pali at kernel.org
Tue May 24 21:35:58 CEST 2022
On Tuesday 24 May 2022 09:43:56 Pali Rohár wrote:
> On Tuesday 24 May 2022 12:45:30 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 switches the menu title type from "char" to "u16"
> > only when the EFI_LOADER is enabled.
> >
> > Fixes: a3d0aa87acbe ("bootmenu: update bootmenu_entry structure")
> > Signed-off-by: Masahisa Kojima <masahisa.kojima at linaro.org>
> > ---
> > cmd/bootmenu.c | 48 ++++++++++++++++++++++++++++++++----------------
> > 1 file changed, 32 insertions(+), 16 deletions(-)
> >
> > diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> > index 8859eebea5..e422e0b348 100644
> > --- a/cmd/bootmenu.c
> > +++ b/cmd/bootmenu.c
> > @@ -20,6 +20,20 @@
> > /* maximum bootmenu entries */
> > #define MAX_COUNT 99
> >
> > +#if (CONFIG_IS_ENABLED(EFI_LOADER))
> > +#define TITLE_CHAR u16
> > +#define titlefmt "ls"
> > +#define TITLE_STRDUP u16_strdup
> > +#define TITLE_STRNCPY(d, s, l) utf8_utf16_strncpy(&d, s, l)
> > +#define TITLE_STR(x) u##x
> > +#else
> > +#define TITLE_CHAR char
> > +#define titlefmt "s"
> > +#define TITLE_STRDUP strdup
> > +#define TITLE_STRNCPY(d, s, l) strncpy(d, s, l)
> > +#define TITLE_STR(x) x
> > +#endif
>
> This reminds me win98 days with tchar macros when NT systems used UCS-2
> and DOS systems OEM codepage... Do we really have to use these 20 years
> old patterns in new code?
>
> Still, I do not see reason why EFI bloatware code has to be in common
> U-boot code and not in separated parts?
Anyway, now I have tested this patch, menu entries are now printed on
serial console correctly, but still I'm not able to terminate bootmenu
by CTRL+C like before that commit. So bootmenu is still broken on nokia
n900.
> > +
> > /* maximal size of bootmenu env
> > * 9 = strlen("bootmenu_")
> > * 2 = strlen(MAX_COUNT)
> > @@ -43,7 +57,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 */
> > + TITLE_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 +90,7 @@ static void bootmenu_print_entry(void *data)
> > if (reverse)
> > puts(ANSI_COLOR_REVERSE);
> >
> > - printf("%ls", entry->title);
> > + printf("%" titlefmt "", entry->title);
> >
> > if (reverse)
> > puts(ANSI_COLOR_RESET);
> > @@ -170,7 +184,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu,
> > struct bootmenu_entry *iter = *current;
> >
> > while ((option = bootmenu_getoption(i))) {
> > - u16 *buf;
> > + TITLE_CHAR *buf;
> >
> > sep = strchr(option, '=');
> > if (!sep) {
> > @@ -183,13 +197,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) * sizeof(TITLE_CHAR));
> > entry->title = buf;
> > if (!entry->title) {
> > free(entry);
> > return -ENOMEM;
> > }
> > - utf8_utf16_strncpy(&buf, option, len);
> > + TITLE_STRNCPY(buf, option, len);
> >
> > len = strlen(sep + 1);
> > entry->command = malloc(len + 1);
> > @@ -227,6 +241,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
> > *
> > @@ -315,6 +330,7 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu,
> >
> > return 1;
> > }
> > +#endif
> >
> > static struct bootmenu_data *bootmenu_create(int delay)
> > {
> > @@ -341,13 +357,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) {
> > - ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
> > - if (ret < 0 && ret != -ENOENT)
> > - goto cleanup;
> > - }
> > +#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 +373,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 = TITLE_STRDUP(TITLE_STR("U-Boot console"));
> > else
> > - entry->title = u16_strdup(u"Quit");
> > + entry->title = TITLE_STRDUP(TITLE_STR("Quit"));
> >
> > if (!entry->title) {
> > free(entry);
> > @@ -461,7 +477,7 @@ static enum bootmenu_ret bootmenu_show(int delay)
> > int cmd_ret;
> > int init = 0;
> > void *choice = NULL;
> > - u16 *title = NULL;
> > + TITLE_CHAR *title = NULL;
> > char *command = NULL;
> > struct menu *menu;
> > struct bootmenu_entry *iter;
> > @@ -517,7 +533,7 @@ static enum bootmenu_ret bootmenu_show(int delay)
> >
> > if (menu_get_choice(menu, &choice) == 1) {
> > iter = choice;
> > - title = u16_strdup(iter->title);
> > + title = TITLE_STRDUP(iter->title);
> > command = strdup(iter->command);
> >
> > /* last entry is U-Boot console or Quit */
> > @@ -561,7 +577,7 @@ cleanup:
> > }
> >
> > if (title && command) {
> > - debug("Starting entry '%ls'\n", title);
> > + debug("Starting entry '%" titlefmt "'\n", title);
> > free(title);
> > if (efi_ret == EFI_SUCCESS)
> > cmd_ret = run_command(command, 0);
> > --
> > 2.17.1
> >
More information about the U-Boot
mailing list