summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2022-07-26 07:41:36 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-08-08 15:30:42 +0200
commitd5e8a370e3e8b46c4e713f2f47e0227fee101401 (patch)
treee4acbed21983775c1e8c63361af189ce5332c027 /common
parentf6eccbf5924514087074129dca102f8b632c3f17 (diff)
downloadbarebox-d5e8a370e3e8b46c4e713f2f47e0227fee101401.tar.gz
barebox-d5e8a370e3e8b46c4e713f2f47e0227fee101401.tar.xz
commands: boot: support preselecting boot entry in menu
boot -m -t 3 already opens a boot menu with a countdown of 3 seconds before selecting the first element. So far, only way to influence preselection was shifting around boot entries, so they are iterated over differently. Add a new -M option that works analogously to -m, but takes an integer index of the boot menu entry to preselect. This allows simple customizable interactive boots: #!/bin/sh boot -M "$nv.bootmenu_default" -t 3 mmc0.0 With mmc0.0 containing multiple bootloader spec files that would be iterated over in lexical order. The index is 1-based like the index displayed in the boot menu. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20220726054136.267069-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/boot.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/boot.c b/common/boot.c
index 8220b8d3fb..52b03eb64d 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -313,10 +313,12 @@ int bootentry_create_from_name(struct bootentries *bootentries,
/*
* bootsources_menu - show a menu from an array of names
*/
-void bootsources_menu(struct bootentries *bootentries, int timeout)
+void bootsources_menu(struct bootentries *bootentries,
+ unsigned default_entry, int timeout)
{
struct bootentry *entry;
struct menu_entry *back_entry;
+ int i = 1;
if (!IS_ENABLED(CONFIG_MENU)) {
pr_warn("no menu support available\n");
@@ -328,6 +330,9 @@ void bootsources_menu(struct bootentries *bootentries, int timeout)
entry->me.display = xstrdup(entry->title);
entry->me.action = bootsource_action;
menu_add_entry(bootentries->menu, &entry->me);
+
+ if (i++ == default_entry)
+ bootentries->menu->selected = &entry->me;
}
back_entry = xzalloc(sizeof(*back_entry));
@@ -336,6 +341,9 @@ void bootsources_menu(struct bootentries *bootentries, int timeout)
back_entry->non_re_ent = 1;
menu_add_entry(bootentries->menu, back_entry);
+ if (i == default_entry)
+ bootentries->menu->selected = back_entry;
+
if (timeout >= 0)
bootentries->menu->auto_select = timeout;