diff mbox series

[U-Boot] add default-option to bootmenu

Message ID trinity-dd0cdb19-7ecc-42ad-8606-f6d52d1ecbed-1538733519014@3c-app-gmx-bs19
State Accepted
Delegated to: Tom Rini
Headers show
Series [U-Boot] add default-option to bootmenu | expand

Commit Message

Frank Wunderlich Oct. 5, 2018, 9:58 a.m. UTC
From 6304b2ee2d2e9be47672d3559fee8d879b7328ff Mon Sep 17 00:00:00 2001
From: Frank Wunderlich <frank-w@public-files.de>
Date: Fri, 5 Oct 2018 11:41:59 +0200
Subject: [PATCH] add default-option to bootmenu
with this patch the selected Entry in bootmenu can be set by
environment-var bootmenu_default=<number>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 cmd/bootmenu.c   |   5 +++++
 files/u-boot.bin | Bin 278424 -> 278480 bytes
 uEnv.txt         |   2 ++
 3 files changed, 7 insertions(+)

Comments

Tom Rini Nov. 27, 2018, 6:47 p.m. UTC | #1
On Fri, Oct 05, 2018 at 11:58:39AM +0200, Frank Wunderlich wrote:

> >From 6304b2ee2d2e9be47672d3559fee8d879b7328ff Mon Sep 17 00:00:00 2001
> From: Frank Wunderlich <frank-w@public-files.de>
> Date: Fri, 5 Oct 2018 11:41:59 +0200
> Subject: [PATCH] add default-option to bootmenu
> with this patch the selected Entry in bootmenu can be set by
> environment-var bootmenu_default=<number>
> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>

Applied to u-boot/master, thanks!
Frank Wunderlich Dec. 1, 2018, 12:41 p.m. UTC | #2
thank you

as a small improvement (i've recently experienced), menu->active should be checked against menu->count (at the end of bootmenu_create), else it can be "outside" of the menu and selection is not visible till menu->active is below menu->count.

http://git.denx.de/?p=u-boot.git;a=blob;f=cmd/bootmenu.c;h=979ac4a638df48b9552feb82dd80ddbe74e69b8e;hb=f7bb20a53e829ce0b4d3c22c704e80b490d24016#l353

but i'm not 100% sure, how to handle it correctly, so i post it for discussion

because menu->active is initialized with 0 my preferred version is this:

if (menu->active >= menu->count)
  menu->active=0; //or any other value below menu->count (maybe a const set by boardconfig, but this can also be outside the menu, so 0 is imho better)

this is a user-configured environment-var so it is not a big problem :) but a simple check avoids this issue

regards Frank

> Gesendet: Dienstag, 27. November 2018 um 19:47 Uhr
> Von: "Tom Rini" <trini@konsulko.com>
> An: "Frank Wunderlich" <FrankWu@gmx.de>
> Cc: u-boot@lists.denx.de
> Betreff: Re: [U-Boot] add default-option to bootmenu
>
> On Fri, Oct 05, 2018 at 11:58:39AM +0200, Frank Wunderlich wrote:
> 
> > >From 6304b2ee2d2e9be47672d3559fee8d879b7328ff Mon Sep 17 00:00:00 2001
> > From: Frank Wunderlich <frank-w@public-files.de>
> > Date: Fri, 5 Oct 2018 11:41:59 +0200
> > Subject: [PATCH] add default-option to bootmenu
> > with this patch the selected Entry in bootmenu can be set by
> > environment-var bootmenu_default=<number>
> > Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> 
> Applied to u-boot/master, thanks!
> 
> -- 
> Tom
>
Frank Wunderlich Dec. 2, 2018, 7:16 p.m. UTC | #3
attached Patch to check if active menuitem is inside menu

regards Frank

> Gesendet: Samstag, 01. Dezember 2018 um 13:41 Uhr
> Von: "Frank Wunderlich" <frank-w@public-files.de>
> An: "Tom Rini" <trini@konsulko.com>
> Cc: u-boot@lists.denx.de
> Betreff: Re: [U-Boot] add default-option to bootmenu
>
> thank you
> 
> as a small improvement (i've recently experienced), menu->active should be checked against menu->count (at the end of bootmenu_create), else it can be "outside" of the menu and selection is not visible till menu->active is below menu->count.
> 
> http://git.denx.de/?p=u-boot.git;a=blob;f=cmd/bootmenu.c;h=979ac4a638df48b9552feb82dd80ddbe74e69b8e;hb=f7bb20a53e829ce0b4d3c22c704e80b490d24016#l353
> 
> but i'm not 100% sure, how to handle it correctly, so i post it for discussion
> 
> because menu->active is initialized with 0 my preferred version is this:
> 
> if (menu->active >= menu->count)
>   menu->active=0; //or any other value below menu->count (maybe a const set by boardconfig, but this can also be outside the menu, so 0 is imho better)
> 
> this is a user-configured environment-var so it is not a big problem :) but a simple check avoids this issue
> 
> regards Frank
> 
> > Gesendet: Dienstag, 27. November 2018 um 19:47 Uhr
> > Von: "Tom Rini" <trini@konsulko.com>
> > An: "Frank Wunderlich" <FrankWu@gmx.de>
> > Cc: u-boot@lists.denx.de
> > Betreff: Re: [U-Boot] add default-option to bootmenu
> >
> > On Fri, Oct 05, 2018 at 11:58:39AM +0200, Frank Wunderlich wrote:
> > 
> > > >From 6304b2ee2d2e9be47672d3559fee8d879b7328ff Mon Sep 17 00:00:00 2001
> > > From: Frank Wunderlich <frank-w@public-files.de>
> > > Date: Fri, 5 Oct 2018 11:41:59 +0200
> > > Subject: [PATCH] add default-option to bootmenu
> > > with this patch the selected Entry in bootmenu can be set by
> > > environment-var bootmenu_default=<number>
> > > Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> > 
> > Applied to u-boot/master, thanks!
> > 
> > -- 
> > Tom
> > 
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
>
From f07d0645ee14668b91f9a6b8da1eb42785a7ba7e Mon Sep 17 00:00:00 2001
From: Frank Wunderlich <frank-w@public-files.de>
Date: Sun, 2 Dec 2018 11:23:53 +0100
Subject: [PATCH] ensure active menuitem is inside menu

if active menuitem is defined via environment var it can be outside the menu (>=menuitem-count)

this patch resets this definition back to 0

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 cmd/bootmenu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 979ac4a638..5d4dfdf6bf 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -351,6 +351,10 @@ static struct bootmenu_data *bootmenu_create(int delay)
 	}
 
 	menu->count = i;
+
+	if (menu->active >= menu->count) //ensure active menuitem is inside menu
+		menu->active=0;
+	
 	return menu;
 
 cleanup:
diff mbox series

Patch

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 21f353ffd3..979ac4a638 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -253,6 +253,7 @@  static struct bootmenu_data *bootmenu_create(int delay)
 
        int len;
        char *sep;
+       char *default_str;
        struct bootmenu_entry *entry;
 
        menu = malloc(sizeof(struct bootmenu_data));
@@ -263,6 +264,10 @@  static struct bootmenu_data *bootmenu_create(int 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);
+
        while ((option = bootmenu_getoption(i))) {
                sep = strchr(option, '=');
                if (!sep) {