summaryrefslogtreecommitdiffstats
path: root/common/boot.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/boot.c')
-rw-r--r--common/boot.c85
1 files changed, 51 insertions, 34 deletions
diff --git a/common/boot.c b/common/boot.c
index dcbe5cc2ec..cbfe6649b3 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -1,30 +1,18 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; version 2.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0-only
-#include <environment.h>
-#include <bootchooser.h>
+#include <boot.h>
#include <globalvar.h>
#include <magicvar.h>
#include <watchdog.h>
#include <command.h>
#include <readkey.h>
#include <common.h>
-#include <blspec.h>
#include <libgen.h>
-#include <malloc.h>
#include <bootm.h>
#include <glob.h>
#include <init.h>
#include <menu.h>
-#include <fs.h>
+#include <unistd.h>
#include <linux/stat.h>
@@ -87,7 +75,7 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
struct bootm_data data = {};
- if (dryrun) {
+ if (dryrun == 1) {
printf("Would run %s\n", bs->scriptpath);
return 0;
}
@@ -106,8 +94,8 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
if (verbose)
data.verbose = verbose;
- if (dryrun)
- data.dryrun = dryrun;
+ if (dryrun >= 2)
+ data.dryrun = dryrun - 1;
return bootm_boot(&data);
}
@@ -119,12 +107,26 @@ void boot_set_watchdog_timeout(unsigned int timeout)
boot_watchdog_timeout = timeout;
}
+static struct watchdog *boot_enabled_watchdog;
+
+struct watchdog *boot_get_enabled_watchdog(void)
+{
+ return boot_enabled_watchdog;
+}
+
static char *global_boot_default;
+
+void boot_set_default(const char *boot_default)
+{
+ free(global_boot_default);
+ global_boot_default = xstrdup(boot_default);
+}
+
static char *global_user;
static int init_boot(void)
{
- global_boot_default = xstrdup("net");
+ global_boot_default = global_boot_default ? : xstrdup("net");
globalvar_add_simple_string("boot.default", &global_boot_default);
globalvar_add_simple_int("boot.watchdog_timeout",
&boot_watchdog_timeout, "%u");
@@ -136,25 +138,28 @@ static int init_boot(void)
}
late_initcall(init_boot);
-BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
+BAREBOX_MAGICVAR(global.boot.watchdog_timeout,
"Watchdog enable timeout in seconds before booting");
int boot_entry(struct bootentry *be, int verbose, int dryrun)
{
int ret;
- printf("Booting entry '%s'\n", be->title);
+ pr_info("Booting entry '%s'\n", be->title);
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
- ret = watchdog_set_timeout(watchdog_get_default(),
- boot_watchdog_timeout);
- if (ret)
+ boot_enabled_watchdog = watchdog_get_default();
+
+ ret = watchdog_set_timeout(boot_enabled_watchdog, boot_watchdog_timeout);
+ if (ret) {
pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
+ boot_enabled_watchdog = NULL;
+ }
}
ret = be->boot(be, verbose, dryrun);
- if (ret)
- pr_err("Booting entry '%s' failed\n", be->title);
+ if (ret && ret != -ENOMEDIUM)
+ pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
return ret;
}
@@ -185,8 +190,12 @@ static int bootscript_create_entry(struct bootentries *bootentries, const char *
{
struct bootentry_script *bs;
enum filetype type;
+ int ret;
+
+ ret = file_name_detect_type(name, &type);
+ if (ret)
+ return ret;
- type = file_name_detect_type(name);
if (type != filetype_sh)
return -EINVAL;
@@ -205,7 +214,7 @@ static int bootscript_create_entry(struct bootentries *bootentries, const char *
/*
* bootscript_scan_path - create boot entries from a path
*
- * path can either be a full path to a bootscript or a full path to a diretory
+ * path can either be a full path to a bootscript or a full path to a directory
* containing bootscripts.
*/
static int bootscript_scan_path(struct bootentries *bootentries, const char *path)
@@ -274,6 +283,7 @@ int bootentry_register_provider(int (*fn)(struct bootentries *bootentries, const
* name can be:
* - a name of a boot script under /env/boot
* - a full path of a boot script
+ * - a full path of a bootloader spec entry
* - a device name
* - a cdev name
* - a full path of a directory containing bootloader spec entries
@@ -315,13 +325,15 @@ 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)) {
- printf("no menu support available\n");
+ pr_warn("no menu support available\n");
return;
}
@@ -330,6 +342,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));
@@ -338,6 +353,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;
@@ -354,11 +372,10 @@ void bootsources_list(struct bootentries *bootentries)
{
struct bootentry *entry;
- printf("%-20s\n", "title");
- printf("%-20s\n", "------");
+ printf("title\n------\n");
bootentries_for_each_entry(bootentries, entry)
- printf("%-20s %s\n", entry->title, entry->description);
+ printf("%s\n\t%s\n", entry->title, entry->description);
}
-BAREBOX_MAGICVAR_NAMED(global_boot_default, global.boot.default, "default boot order");
+BAREBOX_MAGICVAR(global.boot.default, "default boot order");