* (no subject)
@ 2016-07-22 12:44 Sascha Hauer
2016-07-22 12:44 ` [PATCH 01/18] blspec: remove unused blspec_boot_devicename Sascha Hauer
` (17 more replies)
0 siblings, 18 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
From Sascha Hauer <s.hauer@pengutronix.de> # This line is ignored.
From: Sascha Hauer <s.hauer@pengutronix.de>
Subject: rework boot/blspec code
In-Reply-To:
The boot command code is for converting a list of strings into boot
entries and iterating over the boot entries starting one after the
other until one succeeds. boot entries can be boot scripts or bootloader
spec entries, nevertheless the boot code uses a "struct blspec" for
both. This series separated this properly, puts the bootloader spec
specific data into its own struct leaving the generic data for the boot
code.
As a central component the boot code should also have a C API, which it
currently does not have as the it's implemented in the boot command
code, so this series move the bulk of the code to a place under common/
where it can be called by C code aswell.
Also several other cleanups are done like (hopefully) more consistent
message printing.
Sascha
----------------------------------------------------------------
Sascha Hauer (18):
blspec: remove unused blspec_boot_devicename
blspec: Remove once/default handling
blspec: remove unused function prototype
boot: Call blspec_scan_directory() only on strings containing an absolute path
include: Move bulk of boot.h to bootm.h
blpec: rename struct lspec -> bootentries
blspec: factor out a struct bootentry
bootentries: Add title/description
blspec: separate bootentries from blspec entries
blspec: Make blspec_boot static
bootentries: Move menu display string allocation to bootentries_alloc()
bootentries: Move struct bootentries to include/boot.h
boot: Use struct bootentries to pass around data
boot: Move code to common/
boot: add single quotes when printing boot target names
boot command: Explicitly complain when boot target list is empty
blspec: Turn message back to debug level
boot: Print a message when a boot target string does not lead to a boot target
arch/arm/boards/archosg9/archos_features.c | 1 -
arch/arm/lib/bootm.c | 1 +
commands/Kconfig | 1 +
commands/boot.c | 415 ++---------------------------
commands/bootm.c | 2 +-
common/Kconfig | 3 +
common/Makefile | 1 +
common/blspec.c | 343 ++++++++++--------------
common/boot.c | 339 +++++++++++++++++++++++
common/bootm.c | 3 +-
common/image-fit.c | 2 +-
drivers/usb/gadget/f_fastboot.c | 2 +-
include/blspec.h | 91 +------
include/boot.h | 139 ++--------
include/bootm.h | 125 +++++++++
include/image-fit.h | 2 +-
16 files changed, 676 insertions(+), 794 deletions(-)
create mode 100644 common/boot.c
create mode 100644 include/bootm.h
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 01/18] blspec: remove unused blspec_boot_devicename
2016-07-22 12:44 Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 02/18] blspec: Remove once/default handling Sascha Hauer
` (16 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 30 ------------------------------
include/blspec.h | 2 --
2 files changed, 32 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index bf98e6b..2e9d87b 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -758,33 +758,3 @@ struct blspec_entry *blspec_entry_default(struct blspec *l)
return entry_default;
return entry_first;
}
-
-/*
- * blspec_boot_devicename - scan hardware device for blspec entries and
- * start the best one.
- */
-int blspec_boot_devicename(const char *devname, int verbose, int dryrun)
-{
- struct blspec *blspec;
- struct blspec_entry *e;
- int ret;
-
- blspec = blspec_alloc();
-
- ret = blspec_scan_devicename(blspec, devname);
- if (ret)
- return ret;
-
- e = blspec_entry_default(blspec);
- if (!e) {
- printf("No bootspec entry found on %s\n", devname);
- ret = -ENOENT;
- goto out;
- }
-
- ret = blspec_boot(e, verbose, dryrun);
-out:
- blspec_free(blspec);
-
- return ret;
-}
diff --git a/include/blspec.h b/include/blspec.h
index e22e9be..9fc42df 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -31,8 +31,6 @@ int blspec_entry_save(struct blspec_entry *entry, const char *path);
int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun);
-int blspec_boot_devicename(const char *devname, int verbose, int dryrun);
-
int blspec_scan_devices(struct blspec *blspec);
int blspec_scan_device(struct blspec *blspec, struct device_d *dev);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 02/18] blspec: Remove once/default handling
2016-07-22 12:44 Sascha Hauer
2016-07-22 12:44 ` [PATCH 01/18] blspec: remove unused blspec_boot_devicename Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 03/18] blspec: remove unused function prototype Sascha Hauer
` (15 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
This is widely unused and in the way of subsequent cleanups. If you are
indeed using it please complain on the list, we'll find a solution to
add it back in a different way.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 33 +++++---------------------------
common/blspec.c | 57 +-------------------------------------------------------
include/blspec.h | 11 -----------
3 files changed, 6 insertions(+), 95 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index c091b2e..152615f 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -256,7 +256,7 @@ static struct blspec *bootentries_collect(char *entries[], int num_entries)
static void bootsources_menu(char *entries[], int num_entries)
{
struct blspec *blspec = NULL;
- struct blspec_entry *entry, *entry_default;
+ struct blspec_entry *entry;
struct menu_entry *back_entry;
if (!IS_ENABLED(CONFIG_MENU)) {
@@ -268,13 +268,9 @@ static void bootsources_menu(char *entries[], int num_entries)
if (!blspec)
return;
- entry_default = blspec_entry_default(blspec);
-
blspec_for_each_entry(blspec, entry) {
entry->me.action = bootsource_action;
menu_add_entry(blspec->menu, &entry->me);
- if (entry == entry_default)
- menu_set_selected_entry(blspec->menu, &entry->me);
}
back_entry = xzalloc(sizeof(*back_entry));
@@ -299,23 +295,16 @@ static void bootsources_menu(char *entries[], int num_entries)
static void bootsources_list(char *entries[], int num_entries)
{
struct blspec *blspec;
- struct blspec_entry *entry, *entry_default;
+ struct blspec_entry *entry;
blspec = bootentries_collect(entries, num_entries);
if (!blspec)
return;
- entry_default = blspec_entry_default(blspec);
-
- printf(" %-20s %-20s %s\n", "device", "hwdevice", "title");
- printf(" %-20s %-20s %s\n", "------", "--------", "-----");
+ printf("%-20s %-20s %s\n", "device", "hwdevice", "title");
+ printf("%-20s %-20s %s\n", "------", "--------", "-----");
blspec_for_each_entry(blspec, entry) {
- if (entry == entry_default)
- printf("* ");
- else
- printf(" ");
-
if (entry->scriptpath)
printf("%-40s %s\n", basename(entry->scriptpath), entry->me.display);
else
@@ -340,7 +329,7 @@ static void bootsources_list(char *entries[], int num_entries)
static int boot(const char *name)
{
struct blspec *blspec;
- struct blspec_entry *entry, *entry_default;
+ struct blspec_entry *entry;
int ret;
blspec = blspec_alloc();
@@ -353,19 +342,7 @@ static int boot(const char *name)
return -ENOENT;
}
- entry_default = blspec_entry_default(blspec);
- if (entry_default) {
- ret = boot_entry(entry_default);
- if (!ret)
- return ret;
- printf("booting %s failed: %s\n", entry_default->me.display,
- strerror(-ret));
- }
-
blspec_for_each_entry(blspec, entry) {
- if (entry == entry_default)
- continue;
-
printf("booting %s\n", entry->me.display);
ret = boot_entry(entry);
if (!ret)
diff --git a/common/blspec.c b/common/blspec.c
index 2e9d87b..b964155 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -329,7 +329,7 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
char *abspath;
int ret, found = 0;
const char *dirname = "loader/entries";
- char *entry_default = NULL, *entry_once = NULL, *name, *nfspath = NULL;
+ char *nfspath = NULL;
nfspath = parse_nfs_url(root);
if (!IS_ERR(nfspath))
@@ -337,9 +337,6 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
pr_info("%s: %s %s\n", __func__, root, dirname);
- entry_default = read_file_line("%s/default", root);
- entry_once = read_file_line("%s/once", root);
-
abspath = basprintf("%s/%s", root, dirname);
dir = opendir(abspath);
@@ -404,13 +401,6 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
found++;
- name = basprintf("%s/%s", dirname, d->d_name);
- if (entry_default && !strcmp(name, entry_default))
- entry->boot_default = true;
- if (entry_once && !strcmp(name, entry_once))
- entry->boot_once = true;
- free(name);
-
if (entry->cdev) {
devname = xstrdup(dev_name(entry->cdev->dev));
if (entry->cdev->dev->parent)
@@ -435,8 +425,6 @@ err_out:
if (!IS_ERR(nfspath))
free(nfspath);
free(abspath);
- free(entry_default);
- free(entry_once);
return ret;
}
@@ -705,18 +693,6 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
entry->cdev ? dev_name(entry->cdev->dev) : "none");
- if (entry->boot_once) {
- char *s = basprintf("%s/once", abspath);
-
- ret = unlink(s);
- if (ret)
- pr_err("unable to unlink 'once': %s\n", strerror(-ret));
- else
- pr_info("removed 'once'\n");
-
- free(s);
- }
-
ret = bootm_boot(&data);
if (ret)
pr_err("Booting failed\n");
@@ -727,34 +703,3 @@ err_out:
return ret;
}
-
-/*
- * blspec_entry_default - find the entry to load.
- *
- * return in the order of precendence:
- * - The entry specified in the 'once' file
- * - The entry specified in the 'default' file
- * - The first entry
- */
-struct blspec_entry *blspec_entry_default(struct blspec *l)
-{
- struct blspec_entry *entry_once = NULL;
- struct blspec_entry *entry_default = NULL;
- struct blspec_entry *entry_first = NULL;
- struct blspec_entry *e;
-
- list_for_each_entry(e, &l->entries, list) {
- if (!entry_first)
- entry_first = e;
- if (e->boot_once)
- entry_once = e;
- if (e->boot_default)
- entry_default = e;
- }
-
- if (entry_once)
- return entry_once;
- if (entry_default)
- return entry_default;
- return entry_first;
-}
diff --git a/include/blspec.h b/include/blspec.h
index 9fc42df..4b61ef8 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -15,8 +15,6 @@ struct blspec_entry {
struct cdev *cdev;
char *rootpath;
char *configpath;
- bool boot_default;
- bool boot_once;
struct menu_entry me;
@@ -89,13 +87,4 @@ static inline void blspec_free(struct blspec *blspec)
free(blspec);
}
-#ifdef CONFIG_BLSPEC
-struct blspec_entry *blspec_entry_default(struct blspec *l);
-#else
-static inline struct blspec_entry *blspec_entry_default(struct blspec *l)
-{
- return NULL;
-}
-#endif
-
#endif /* __LOADER_H__ */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 03/18] blspec: remove unused function prototype
2016-07-22 12:44 Sascha Hauer
2016-07-22 12:44 ` [PATCH 01/18] blspec: remove unused blspec_boot_devicename Sascha Hauer
2016-07-22 12:44 ` [PATCH 02/18] blspec: Remove once/default handling Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 04/18] boot: Call blspec_scan_directory() only on strings containing an absolute path Sascha Hauer
` (14 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/blspec.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/include/blspec.h b/include/blspec.h
index 4b61ef8..a73dd72 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -25,8 +25,6 @@ int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
const char *val);
const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name);
-int blspec_entry_save(struct blspec_entry *entry, const char *path);
-
int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun);
int blspec_scan_devices(struct blspec *blspec);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 04/18] boot: Call blspec_scan_directory() only on strings containing an absolute path
2016-07-22 12:44 Sascha Hauer
` (2 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 03/18] blspec: remove unused function prototype Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 05/18] include: Move bulk of boot.h to bootm.h Sascha Hauer
` (13 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Avoids an unnecessary "Nothing bootable found on..." warning.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index 152615f..719ad95 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -202,9 +202,12 @@ static int bootentry_parse_one(struct blspec *blspec, const char *name)
ret = blspec_scan_devicename(blspec, name);
if (ret > 0)
found += ret;
- ret = blspec_scan_directory(blspec, name);
- if (ret > 0)
- found += ret;
+
+ if (*name == '/') {
+ ret = blspec_scan_directory(blspec, name);
+ if (ret > 0)
+ found += ret;
+ }
}
if (!found) {
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 05/18] include: Move bulk of boot.h to bootm.h
2016-07-22 12:44 Sascha Hauer
` (3 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 04/18] boot: Call blspec_scan_directory() only on strings containing an absolute path Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 06/18] blpec: rename struct lspec -> bootentries Sascha Hauer
` (12 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
The majority of the stuff currently in include/boot.h is about bootm
code implemented common/bootm.c. To be more consistent move it to a
new file include/bootm.h.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/archosg9/archos_features.c | 1 -
arch/arm/lib/bootm.c | 1 +
commands/boot.c | 2 +-
commands/bootm.c | 2 +-
common/blspec.c | 2 +-
common/bootm.c | 3 +-
common/image-fit.c | 2 +-
drivers/usb/gadget/f_fastboot.c | 2 +-
include/boot.h | 120 ---------------------------
include/bootm.h | 125 +++++++++++++++++++++++++++++
include/image-fit.h | 2 +-
11 files changed, 134 insertions(+), 128 deletions(-)
create mode 100644 include/bootm.h
diff --git a/arch/arm/boards/archosg9/archos_features.c b/arch/arm/boards/archosg9/archos_features.c
index b396734..62ce7b4 100644
--- a/arch/arm/boards/archosg9/archos_features.c
+++ b/arch/arm/boards/archosg9/archos_features.c
@@ -10,7 +10,6 @@
* GNU General Public License for more details.
*/
-#include <boot.h>
#include <asm/setup.h>
#include "archos_features.h"
#include "feature_list.h"
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 252946c..404a6ae 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -1,3 +1,4 @@
+#include <bootm.h>
#include <boot.h>
#include <common.h>
#include <command.h>
diff --git a/commands/boot.c b/commands/boot.c
index 719ad95..baf2740 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -23,7 +23,7 @@
#include <libgen.h>
#include <malloc.h>
#include <clock.h>
-#include <boot.h>
+#include <bootm.h>
#include <glob.h>
#include <init.h>
#include <menu.h>
diff --git a/commands/bootm.c b/commands/bootm.c
index 6bedb00..61b9086 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -32,7 +32,7 @@
#include <fcntl.h>
#include <fs.h>
#include <errno.h>
-#include <boot.h>
+#include <bootm.h>
#include <of.h>
#include <rtc.h>
#include <init.h>
diff --git a/common/blspec.c b/common/blspec.c
index b964155..de65038 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -24,7 +24,7 @@
#include <libfile.h>
#include <libbb.h>
#include <init.h>
-#include <boot.h>
+#include <bootm.h>
#include <net.h>
#include <fs.h>
#include <of.h>
diff --git a/common/bootm.c b/common/bootm.c
index 27d20f2..78d04d5 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -12,7 +12,7 @@
*/
#include <common.h>
-#include <boot.h>
+#include <bootm.h>
#include <fs.h>
#include <malloc.h>
#include <memory.h>
@@ -20,6 +20,7 @@
#include <image-fit.h>
#include <globalvar.h>
#include <init.h>
+#include <environment.h>
#include <linux/stat.h>
#include <magicvar.h>
diff --git a/common/image-fit.c b/common/image-fit.c
index 9b6c40f..6a01c61 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -20,7 +20,7 @@
#define pr_fmt(fmt) "FIT: " fmt
#include <common.h>
#include <init.h>
-#include <boot.h>
+#include <bootm.h>
#include <libfile.h>
#include <fdt.h>
#include <digest.h>
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 6db7daf..a6192b9 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -25,7 +25,7 @@
#include <ioctl.h>
#include <libbb.h>
#include <bbu.h>
-#include <boot.h>
+#include <bootm.h>
#include <dma.h>
#include <fs.h>
#include <libfile.h>
diff --git a/include/boot.h b/include/boot.h
index 8e7a9f1..da40ac2 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -1,115 +1,9 @@
#ifndef __BOOT_H
#define __BOOT_H
-#include <image.h>
-#include <filetype.h>
#include <of.h>
-#include <linux/list.h>
#include <environment.h>
-enum bootm_verify {
- BOOTM_VERIFY_NONE,
- BOOTM_VERIFY_HASH,
- BOOTM_VERIFY_SIGNATURE,
- BOOTM_VERIFY_AVAILABLE,
-};
-
-struct bootm_data {
- const char *os_file;
- const char *initrd_file;
- const char *oftree_file;
- int verbose;
- enum bootm_verify verify;
- bool force;
- bool dryrun;
- /*
- * appendroot - if true, try to add a suitable root= Kernel option to
- * mount the rootfs from the same device as the Kernel comes from.
- */
- bool appendroot;
- unsigned long initrd_address;
- unsigned long os_address;
- unsigned long os_entry;
-};
-
-int bootm_boot(struct bootm_data *data);
-
-struct image_data {
- /* simplest case. barebox has already loaded the os here */
- struct resource *os_res;
-
- /* if os is an uImage this will be provided */
- struct uimage_handle *os;
-
- /* if os is a FIT image this will be provided */
- struct fit_handle *os_fit;
-
- char *os_part;
-
- /* otherwise only the filename will be provided */
- char *os_file;
-
- /*
- * The address the user wants to load the os image to.
- * May be UIMAGE_INVALID_ADDRESS to indicate that the
- * user has not specified any address. In this case the
- * handler may choose a suitable address
- */
- unsigned long os_address;
-
- /* entry point to the os. relative to the start of the image */
- unsigned long os_entry;
-
- /* if initrd is already loaded this resource will be !NULL */
- struct resource *initrd_res;
-
- /* if initrd is an uImage this will be provided */
- struct uimage_handle *initrd;
- char *initrd_part;
-
- /* otherwise only the filename will be provided */
- char *initrd_file;
-
- unsigned long initrd_address;
-
- char *oftree_file;
- char *oftree_part;
-
- struct device_node *of_root_node;
- struct fdt_header *oftree;
- struct resource *oftree_res;
-
- enum bootm_verify verify;
- int verbose;
- int force;
- int dryrun;
-};
-
-struct image_handler {
- const char *name;
-
- struct list_head list;
-
- int ih_os;
-
- enum filetype filetype;
- int (*bootm)(struct image_data *data);
-};
-
-int register_image_handler(struct image_handler *handle);
-
-#ifdef CONFIG_BOOTM_VERBOSE
-static inline int bootm_verbose(struct image_data *data)
-{
- return data->verbose;
-}
-#else
-static inline int bootm_verbose(struct image_data *data)
-{
- return 0;
-}
-#endif
-
#ifdef CONFIG_FLEXIBLE_BOOTARGS
const char *linux_bootargs_get(void);
int linux_bootargs_overwrite(const char *bootargs);
@@ -125,18 +19,4 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
}
#endif
-void bootm_data_init_defaults(struct bootm_data *data);
-
-int bootm_load_os(struct image_data *data, unsigned long load_address);
-
-bool bootm_has_initrd(struct image_data *data);
-int bootm_load_initrd(struct image_data *data, unsigned long load_address);
-
-int bootm_load_devicetree(struct image_data *data, unsigned long load_address);
-int bootm_get_os_size(struct image_data *data);
-
-enum bootm_verify bootm_get_verify_mode(void);
-
-#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
-
#endif /* __BOOT_H */
diff --git a/include/bootm.h b/include/bootm.h
new file mode 100644
index 0000000..6e9777a
--- /dev/null
+++ b/include/bootm.h
@@ -0,0 +1,125 @@
+#ifndef __BOOTM_H
+#define __BOOTM_H
+
+#include <image.h>
+#include <filetype.h>
+#include <linux/list.h>
+
+enum bootm_verify {
+ BOOTM_VERIFY_NONE,
+ BOOTM_VERIFY_HASH,
+ BOOTM_VERIFY_SIGNATURE,
+ BOOTM_VERIFY_AVAILABLE,
+};
+
+struct bootm_data {
+ const char *os_file;
+ const char *initrd_file;
+ const char *oftree_file;
+ int verbose;
+ enum bootm_verify verify;
+ bool force;
+ bool dryrun;
+ /*
+ * appendroot - if true, try to add a suitable root= Kernel option to
+ * mount the rootfs from the same device as the Kernel comes from.
+ */
+ bool appendroot;
+ unsigned long initrd_address;
+ unsigned long os_address;
+ unsigned long os_entry;
+};
+
+int bootm_boot(struct bootm_data *data);
+
+struct image_data {
+ /* simplest case. barebox has already loaded the os here */
+ struct resource *os_res;
+
+ /* if os is an uImage this will be provided */
+ struct uimage_handle *os;
+
+ /* if os is a FIT image this will be provided */
+ struct fit_handle *os_fit;
+
+ char *os_part;
+
+ /* otherwise only the filename will be provided */
+ char *os_file;
+
+ /*
+ * The address the user wants to load the os image to.
+ * May be UIMAGE_INVALID_ADDRESS to indicate that the
+ * user has not specified any address. In this case the
+ * handler may choose a suitable address
+ */
+ unsigned long os_address;
+
+ /* entry point to the os. relative to the start of the image */
+ unsigned long os_entry;
+
+ /* if initrd is already loaded this resource will be !NULL */
+ struct resource *initrd_res;
+
+ /* if initrd is an uImage this will be provided */
+ struct uimage_handle *initrd;
+ char *initrd_part;
+
+ /* otherwise only the filename will be provided */
+ char *initrd_file;
+
+ unsigned long initrd_address;
+
+ char *oftree_file;
+ char *oftree_part;
+
+ struct device_node *of_root_node;
+ struct fdt_header *oftree;
+ struct resource *oftree_res;
+
+ enum bootm_verify verify;
+ int verbose;
+ int force;
+ int dryrun;
+};
+
+struct image_handler {
+ const char *name;
+
+ struct list_head list;
+
+ int ih_os;
+
+ enum filetype filetype;
+ int (*bootm)(struct image_data *data);
+};
+
+int register_image_handler(struct image_handler *handle);
+
+#ifdef CONFIG_BOOTM_VERBOSE
+static inline int bootm_verbose(struct image_data *data)
+{
+ return data->verbose;
+}
+#else
+static inline int bootm_verbose(struct image_data *data)
+{
+ return 0;
+}
+#endif
+
+void bootm_data_init_defaults(struct bootm_data *data);
+
+int bootm_load_os(struct image_data *data, unsigned long load_address);
+
+bool bootm_has_initrd(struct image_data *data);
+int bootm_load_initrd(struct image_data *data, unsigned long load_address);
+
+int bootm_load_devicetree(struct image_data *data, unsigned long load_address);
+int bootm_get_os_size(struct image_data *data);
+
+enum bootm_verify bootm_get_verify_mode(void);
+
+#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
+
+#endif /* __BOOTM_H */
diff --git a/include/image-fit.h b/include/image-fit.h
index c9d6911..c49f958 100644
--- a/include/image-fit.h
+++ b/include/image-fit.h
@@ -19,7 +19,7 @@
#define __IMAGE_FIT_H__
#include <linux/types.h>
-#include <boot.h>
+#include <bootm.h>
struct fit_handle {
void *fit;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 06/18] blpec: rename struct lspec -> bootentries
2016-07-22 12:44 Sascha Hauer
` (4 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 05/18] include: Move bulk of boot.h to bootm.h Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 07/18] blspec: factor out a struct bootentry Sascha Hauer
` (11 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
The code in common/boot.c collects the different boot entries in
lists of type struct blspec, eventhough many of them may not be
bootloader spec entries but for example boot scripts. This is the first
step of separating the data structures from boot entries and bootloader
spec: As struct blspec is merely a container for collecting boot entries
We simply rename struct blspec to struct bootentries. No functional change.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 74 ++++++++++++++++++++++++++++----------------------------
common/blspec.c | 58 ++++++++++++++++++++++----------------------
include/blspec.h | 38 ++++++++++++++---------------
3 files changed, 85 insertions(+), 85 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index baf2740..0dc0c86 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -117,7 +117,7 @@ static void bootsource_action(struct menu *m, struct menu_entry *me)
/*
* bootscript_create_entry - create a boot entry from a script name
*/
-static int bootscript_create_entry(struct blspec *blspec, const char *name)
+static int bootscript_create_entry(struct bootentries *bootentries, const char *name)
{
struct blspec_entry *be;
enum filetype type;
@@ -126,7 +126,7 @@ static int bootscript_create_entry(struct blspec *blspec, const char *name)
if (type != filetype_sh)
return -EINVAL;
- be = blspec_entry_alloc(blspec);
+ be = blspec_entry_alloc(bootentries);
be->me.type = MENU_ENTRY_NORMAL;
be->scriptpath = xstrdup(name);
be->me.display = xstrdup(basename(be->scriptpath));
@@ -140,7 +140,7 @@ static int bootscript_create_entry(struct blspec *blspec, const char *name)
* path can either be a full path to a bootscript or a full path to a diretory
* containing bootscripts.
*/
-static int bootscript_scan_path(struct blspec *blspec, const char *path)
+static int bootscript_scan_path(struct bootentries *bootentries, const char *path)
{
struct stat s;
char *files;
@@ -153,7 +153,7 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path)
return ret;
if (!S_ISDIR(s.st_mode)) {
- ret = bootscript_create_entry(blspec, path);
+ ret = bootscript_create_entry(bootentries, path);
if (ret)
return ret;
return 1;
@@ -169,7 +169,7 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path)
if (*basename(bootscript_path) == '.')
continue;
- bootscript_create_entry(blspec, bootscript_path);
+ bootscript_create_entry(bootentries, bootscript_path);
found++;
}
@@ -194,17 +194,17 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path)
*
* Returns the number of entries found or a negative error code.
*/
-static int bootentry_parse_one(struct blspec *blspec, const char *name)
+static int bootentry_parse_one(struct bootentries *bootentries, const char *name)
{
int found = 0, ret;
if (IS_ENABLED(CONFIG_BLSPEC)) {
- ret = blspec_scan_devicename(blspec, name);
+ ret = blspec_scan_devicename(bootentries, name);
if (ret > 0)
found += ret;
if (*name == '/') {
- ret = blspec_scan_directory(blspec, name);
+ ret = blspec_scan_directory(bootentries, name);
if (ret > 0)
found += ret;
}
@@ -218,7 +218,7 @@ static int bootentry_parse_one(struct blspec *blspec, const char *name)
else
path = xstrdup(name);
- ret = bootscript_scan_path(blspec, path);
+ ret = bootscript_scan_path(bootentries, path);
if (ret > 0)
found += ret;
@@ -231,26 +231,26 @@ static int bootentry_parse_one(struct blspec *blspec, const char *name)
/*
* bootentries_collect - collect bootentries from an array of names
*/
-static struct blspec *bootentries_collect(char *entries[], int num_entries)
+static struct bootentries *bootentries_collect(char *entries[], int num_entries)
{
- struct blspec *blspec;
+ struct bootentries *bootentries;
int i;
- blspec = blspec_alloc();
+ bootentries = blspec_alloc();
if (IS_ENABLED(CONFIG_MENU))
- blspec->menu->display = basprintf("boot");
+ bootentries->menu->display = basprintf("boot");
if (!num_entries)
- bootscript_scan_path(blspec, "/env/boot");
+ bootscript_scan_path(bootentries, "/env/boot");
if (IS_ENABLED(CONFIG_BLSPEC) && !num_entries)
- blspec_scan_devices(blspec);
+ blspec_scan_devices(bootentries);
for (i = 0; i < num_entries; i++)
- bootentry_parse_one(blspec, entries[i]);
+ bootentry_parse_one(bootentries, entries[i]);
- return blspec;
+ return bootentries;
}
/*
@@ -258,7 +258,7 @@ static struct blspec *bootentries_collect(char *entries[], int num_entries)
*/
static void bootsources_menu(char *entries[], int num_entries)
{
- struct blspec *blspec = NULL;
+ struct bootentries *bootentries = NULL;
struct blspec_entry *entry;
struct menu_entry *back_entry;
@@ -267,29 +267,29 @@ static void bootsources_menu(char *entries[], int num_entries)
return;
}
- blspec = bootentries_collect(entries, num_entries);
- if (!blspec)
+ bootentries = bootentries_collect(entries, num_entries);
+ if (!bootentries)
return;
- blspec_for_each_entry(blspec, entry) {
+ blspec_for_each_entry(bootentries, entry) {
entry->me.action = bootsource_action;
- menu_add_entry(blspec->menu, &entry->me);
+ menu_add_entry(bootentries->menu, &entry->me);
}
back_entry = xzalloc(sizeof(*back_entry));
back_entry->display = "back";
back_entry->type = MENU_ENTRY_NORMAL;
back_entry->non_re_ent = 1;
- menu_add_entry(blspec->menu, back_entry);
+ menu_add_entry(bootentries->menu, back_entry);
if (timeout >= 0)
- blspec->menu->auto_select = timeout;
+ bootentries->menu->auto_select = timeout;
- menu_show(blspec->menu);
+ menu_show(bootentries->menu);
free(back_entry);
- blspec_free(blspec);
+ blspec_free(bootentries);
}
/*
@@ -297,24 +297,24 @@ static void bootsources_menu(char *entries[], int num_entries)
*/
static void bootsources_list(char *entries[], int num_entries)
{
- struct blspec *blspec;
+ struct bootentries *bootentries;
struct blspec_entry *entry;
- blspec = bootentries_collect(entries, num_entries);
- if (!blspec)
+ bootentries = bootentries_collect(entries, num_entries);
+ if (!bootentries)
return;
- printf("%-20s %-20s %s\n", "device", "hwdevice", "title");
- printf("%-20s %-20s %s\n", "------", "--------", "-----");
+ printf(" %-20s %-20s %s\n", "device", "hwdevice", "title");
+ printf(" %-20s %-20s %s\n", "------", "--------", "-----");
- blspec_for_each_entry(blspec, entry) {
+ blspec_for_each_entry(bootentries, entry) {
if (entry->scriptpath)
printf("%-40s %s\n", basename(entry->scriptpath), entry->me.display);
else
printf("%s\n", entry->me.display);
}
- blspec_free(blspec);
+ blspec_free(bootentries);
}
/*
@@ -331,12 +331,12 @@ static void bootsources_list(char *entries[], int num_entries)
*/
static int boot(const char *name)
{
- struct blspec *blspec;
+ struct bootentries *bootentries;
struct blspec_entry *entry;
int ret;
- blspec = blspec_alloc();
- ret = bootentry_parse_one(blspec, name);
+ bootentries = blspec_alloc();
+ ret = bootentry_parse_one(bootentries, name);
if (ret < 0)
return ret;
@@ -345,7 +345,7 @@ static int boot(const char *name)
return -ENOENT;
}
- blspec_for_each_entry(blspec, entry) {
+ blspec_for_each_entry(bootentries, entry) {
printf("booting %s\n", entry->me.display);
ret = boot_entry(entry);
if (!ret)
diff --git a/common/blspec.c b/common/blspec.c
index de65038..81049a7 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -58,7 +58,7 @@ const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name)
/*
* blspec_entry_open - open an entry given a path
*/
-static struct blspec_entry *blspec_entry_open(struct blspec *blspec,
+static struct blspec_entry *blspec_entry_open(struct bootentries *bootentries,
const char *abspath)
{
struct blspec_entry *entry;
@@ -71,7 +71,7 @@ static struct blspec_entry *blspec_entry_open(struct blspec *blspec,
if (!buf)
return ERR_PTR(-errno);
- entry = blspec_entry_alloc(blspec);
+ entry = blspec_entry_alloc(bootentries);
next = buf;
@@ -126,11 +126,11 @@ static struct blspec_entry *blspec_entry_open(struct blspec *blspec,
* blspec_have_entry - check if we already have an entry with
* a certain path
*/
-static int blspec_have_entry(struct blspec *blspec, const char *path)
+static int blspec_have_entry(struct bootentries *bootentries, const char *path)
{
struct blspec_entry *e;
- list_for_each_entry(e, &blspec->entries, list) {
+ list_for_each_entry(e, &bootentries->entries, list) {
if (e->configpath && !strcmp(e->configpath, path))
return 1;
}
@@ -210,7 +210,7 @@ static char *parse_nfs_url(const char *url)
if (prevpath) {
mountpath = xstrdup(prevpath);
} else {
- mountpath = basprintf("/mnt/nfs-%s-blspec-%08x", host,
+ mountpath = basprintf("/mnt/nfs-%s-bootentries-%08x", host,
rand());
if (port)
options = basprintf("mountport=%s,port=%s", port,
@@ -317,11 +317,11 @@ out:
/*
* blspec_scan_directory - scan over a directory
*
- * Given a root path collects all blspec entries found under /blspec/entries/.
+ * Given a root path collects all bootentries entries found under /bootentries/entries/.
*
* returns the number of entries found or a negative error value otherwise.
*/
-int blspec_scan_directory(struct blspec *blspec, const char *root)
+int blspec_scan_directory(struct bootentries *bootentries, const char *root)
{
struct blspec_entry *entry;
DIR *dir;
@@ -379,12 +379,12 @@ int blspec_scan_directory(struct blspec *blspec, const char *root)
continue;
}
- if (blspec_have_entry(blspec, configname)) {
+ if (blspec_have_entry(bootentries, configname)) {
free(configname);
continue;
}
- entry = blspec_entry_open(blspec, configname);
+ entry = blspec_entry_open(bootentries, configname);
if (IS_ERR(entry)) {
free(configname);
continue;
@@ -432,13 +432,13 @@ err_out:
/*
* blspec_scan_ubi - scan over a cdev containing UBI volumes
*
- * This function attaches a cdev as UBI devices and collects all blspec
+ * This function attaches a cdev as UBI devices and collects all bootentries
* entries found in the UBI volumes
*
* returns the number of entries found or a negative error code if some unexpected
* error occured.
*/
-static int blspec_scan_ubi(struct blspec *blspec, struct cdev *cdev)
+static int blspec_scan_ubi(struct bootentries *bootentries, struct cdev *cdev)
{
struct device_d *child;
int ret, found = 0;
@@ -450,7 +450,7 @@ static int blspec_scan_ubi(struct blspec *blspec, struct cdev *cdev)
return 0;
device_for_each_child(cdev->dev, child) {
- ret = blspec_scan_device(blspec, child);
+ ret = blspec_scan_device(bootentries, child);
if (ret > 0)
found += ret;
}
@@ -461,13 +461,13 @@ static int blspec_scan_ubi(struct blspec *blspec, struct cdev *cdev)
/*
* blspec_scan_cdev - scan over a cdev
*
- * Given a cdev this function mounts the filesystem and collects all blspec
- * entries found under /blspec/entries/.
+ * Given a cdev this function mounts the filesystem and collects all bootentries
+ * entries found under /bootentries/entries/.
*
* returns the number of entries found or a negative error code if some unexpected
* error occured.
*/
-static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
+static int blspec_scan_cdev(struct bootentries *bootentries, struct cdev *cdev)
{
int ret, found = 0;
void *buf = xzalloc(512);
@@ -490,14 +490,14 @@ static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
return -EINVAL;
if (filetype == filetype_ubi && IS_ENABLED(CONFIG_MTD_UBI)) {
- ret = blspec_scan_ubi(blspec, cdev);
+ ret = blspec_scan_ubi(bootentries, cdev);
if (ret > 0)
found += ret;
}
rootpath = cdev_mount_default(cdev, NULL);
if (!IS_ERR(rootpath)) {
- ret = blspec_scan_directory(blspec, rootpath);
+ ret = blspec_scan_directory(bootentries, rootpath);
if (ret > 0)
found += ret;
}
@@ -512,7 +512,7 @@ static int blspec_scan_cdev(struct blspec *blspec, struct cdev *cdev)
* Returns the number of entries found or a negative error code if some unexpected
* error occured.
*/
-int blspec_scan_devices(struct blspec *blspec)
+int blspec_scan_devices(struct bootentries *bootentries)
{
struct device_d *dev;
struct block_device *bdev;
@@ -525,7 +525,7 @@ int blspec_scan_devices(struct blspec *blspec)
struct cdev *cdev = &bdev->cdev;
list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list) {
- ret = blspec_scan_cdev(blspec, cdev);
+ ret = blspec_scan_cdev(bootentries, cdev);
if (ret > 0)
found += ret;
}
@@ -538,11 +538,11 @@ int blspec_scan_devices(struct blspec *blspec)
* blspec_scan_device - scan a device for child cdevs
*
* Given a device this functions scans over all child cdevs looking
- * for blspec entries.
+ * for bootentries entries.
* Returns the number of entries found or a negative error code if some unexpected
* error occured.
*/
-int blspec_scan_device(struct blspec *blspec, struct device_d *dev)
+int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev)
{
struct device_d *child;
struct cdev *cdev;
@@ -559,7 +559,7 @@ int blspec_scan_device(struct blspec *blspec, struct device_d *dev)
* should be used as $BOOT
*/
if (cdev->dos_partition_type == 0xea) {
- ret = blspec_scan_cdev(blspec, cdev);
+ ret = blspec_scan_cdev(bootentries, cdev);
if (ret == 0)
ret = -ENOENT;
@@ -578,7 +578,7 @@ int blspec_scan_device(struct blspec *blspec, struct device_d *dev)
/* Try child devices */
device_for_each_child(dev, child) {
- ret = blspec_scan_device(blspec, child);
+ ret = blspec_scan_device(bootentries, child);
if (ret > 0)
return ret;
}
@@ -588,7 +588,7 @@ int blspec_scan_device(struct blspec *blspec, struct device_d *dev)
* by the bootblspec spec).
*/
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
- ret = blspec_scan_cdev(blspec, cdev);
+ ret = blspec_scan_cdev(bootentries, cdev);
if (ret > 0)
found += ret;
}
@@ -600,11 +600,11 @@ int blspec_scan_device(struct blspec *blspec, struct device_d *dev)
* blspec_scan_devicename - scan a hardware device for child cdevs
*
* Given a name of a hardware device this functions scans over all child
- * cdevs looking for blspec entries.
+ * cdevs looking for bootentries entries.
* Returns the number of entries found or a negative error code if some unexpected
* error occured.
*/
-int blspec_scan_devicename(struct blspec *blspec, const char *devname)
+int blspec_scan_devicename(struct bootentries *bootentries, const char *devname)
{
struct device_d *dev;
struct cdev *cdev;
@@ -615,7 +615,7 @@ int blspec_scan_devicename(struct blspec *blspec, const char *devname)
cdev = cdev_by_name(devname);
if (cdev) {
- int ret = blspec_scan_cdev(blspec, cdev);
+ int ret = blspec_scan_cdev(bootentries, cdev);
if (ret > 0)
return ret;
}
@@ -624,7 +624,7 @@ int blspec_scan_devicename(struct blspec *blspec, const char *devname)
if (!dev)
return -ENODEV;
- return blspec_scan_device(blspec, dev);
+ return blspec_scan_device(bootentries, dev);
}
/*
@@ -675,7 +675,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
if (initrd)
data.initrd_file = basprintf("%s/%s", abspath, initrd);
- globalvar_add_simple("linux.bootargs.dyn.blspec", options);
+ globalvar_add_simple("linux.bootargs.dyn.bootentries", options);
appendroot = blspec_entry_var_get(entry, "linux-appendroot");
if (appendroot) {
diff --git a/include/blspec.h b/include/blspec.h
index a73dd72..cb4adc5 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -4,7 +4,7 @@
#include <linux/list.h>
#include <menu.h>
-struct blspec {
+struct bootentries {
struct list_head entries;
struct menu *menu;
};
@@ -27,16 +27,16 @@ const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name);
int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun);
-int blspec_scan_devices(struct blspec *blspec);
+int blspec_scan_devices(struct bootentries *bootentries);
-int blspec_scan_device(struct blspec *blspec, struct device_d *dev);
-int blspec_scan_devicename(struct blspec *blspec, const char *devname);
-int blspec_scan_directory(struct blspec *blspec, const char *root);
+int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
+int blspec_scan_devicename(struct bootentries *bootentries, const char *devname);
+int blspec_scan_directory(struct bootentries *bootentries, const char *root);
#define blspec_for_each_entry(blspec, entry) \
list_for_each_entry(entry, &blspec->entries, list)
-static inline struct blspec_entry *blspec_entry_alloc(struct blspec *blspec)
+static inline struct blspec_entry *blspec_entry_alloc(struct bootentries *bootentries)
{
struct blspec_entry *entry;
@@ -44,7 +44,7 @@ static inline struct blspec_entry *blspec_entry_alloc(struct blspec *blspec)
entry->node = of_new_node(NULL, NULL);
- list_add_tail(&entry->list, &blspec->entries);
+ list_add_tail(&entry->list, &bootentries->entries);
return entry;
}
@@ -60,29 +60,29 @@ static inline void blspec_entry_free(struct blspec_entry *entry)
free(entry);
}
-static inline struct blspec *blspec_alloc(void)
+static inline struct bootentries *blspec_alloc(void)
{
- struct blspec *blspec;
+ struct bootentries *bootentries;
- blspec = xzalloc(sizeof(*blspec));
- INIT_LIST_HEAD(&blspec->entries);
+ bootentries = xzalloc(sizeof(*bootentries));
+ INIT_LIST_HEAD(&bootentries->entries);
if (IS_ENABLED(CONFIG_MENU))
- blspec->menu = menu_alloc();
+ bootentries->menu = menu_alloc();
- return blspec;
+ return bootentries;
}
-static inline void blspec_free(struct blspec *blspec)
+static inline void blspec_free(struct bootentries *bootentries)
{
struct blspec_entry *entry, *tmp;
- list_for_each_entry_safe(entry, tmp, &blspec->entries, list)
+ list_for_each_entry_safe(entry, tmp, &bootentries->entries, list)
blspec_entry_free(entry);
- if (blspec->menu)
- free(blspec->menu->display);
- free(blspec->menu);
- free(blspec);
+ if (bootentries->menu)
+ free(bootentries->menu->display);
+ free(bootentries->menu);
+ free(bootentries);
}
#endif /* __LOADER_H__ */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 07/18] blspec: factor out a struct bootentry
2016-07-22 12:44 Sascha Hauer
` (5 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 06/18] blpec: rename struct lspec -> bootentries Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 08/18] bootentries: Add title/description Sascha Hauer
` (10 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 31 +++++++++++++++++--------------
common/blspec.c | 11 +++++++----
include/blspec.h | 29 ++++++++++++++++++-----------
3 files changed, 42 insertions(+), 29 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index 0dc0c86..edf9eab 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -78,9 +78,10 @@ late_initcall(init_boot_watchdog_timeout);
BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
"Watchdog enable timeout in seconds before booting");
-static int boot_entry(struct blspec_entry *be)
+static int boot_entry(struct bootentry *be)
{
int ret;
+ struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
ret = watchdog_set_timeout(boot_watchdog_timeout);
@@ -88,8 +89,8 @@ static int boot_entry(struct blspec_entry *be)
pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
}
- if (be->scriptpath) {
- ret = boot_script(be->scriptpath);
+ if (entry->scriptpath) {
+ ret = boot_script(entry->scriptpath);
} else {
if (IS_ENABLED(CONFIG_BLSPEC))
ret = blspec_boot(be, verbose, dryrun);
@@ -102,7 +103,7 @@ static int boot_entry(struct blspec_entry *be)
static void bootsource_action(struct menu *m, struct menu_entry *me)
{
- struct blspec_entry *be = container_of(me, struct blspec_entry, me);
+ struct bootentry *be = container_of(me, struct bootentry, me);
int ret;
ret = boot_entry(be);
@@ -127,9 +128,9 @@ static int bootscript_create_entry(struct bootentries *bootentries, const char *
return -EINVAL;
be = blspec_entry_alloc(bootentries);
- be->me.type = MENU_ENTRY_NORMAL;
+ be->entry.me.type = MENU_ENTRY_NORMAL;
be->scriptpath = xstrdup(name);
- be->me.display = xstrdup(basename(be->scriptpath));
+ be->entry.me.display = xstrdup(basename(be->scriptpath));
return 0;
}
@@ -259,7 +260,7 @@ static struct bootentries *bootentries_collect(char *entries[], int num_entries)
static void bootsources_menu(char *entries[], int num_entries)
{
struct bootentries *bootentries = NULL;
- struct blspec_entry *entry;
+ struct bootentry *entry;
struct menu_entry *back_entry;
if (!IS_ENABLED(CONFIG_MENU)) {
@@ -271,7 +272,7 @@ static void bootsources_menu(char *entries[], int num_entries)
if (!bootentries)
return;
- blspec_for_each_entry(bootentries, entry) {
+ bootentries_for_each_entry(bootentries, entry) {
entry->me.action = bootsource_action;
menu_add_entry(bootentries->menu, &entry->me);
}
@@ -298,7 +299,7 @@ static void bootsources_menu(char *entries[], int num_entries)
static void bootsources_list(char *entries[], int num_entries)
{
struct bootentries *bootentries;
- struct blspec_entry *entry;
+ struct bootentry *entry;
bootentries = bootentries_collect(entries, num_entries);
if (!bootentries)
@@ -307,9 +308,11 @@ static void bootsources_list(char *entries[], int num_entries)
printf(" %-20s %-20s %s\n", "device", "hwdevice", "title");
printf(" %-20s %-20s %s\n", "------", "--------", "-----");
- blspec_for_each_entry(bootentries, entry) {
- if (entry->scriptpath)
- printf("%-40s %s\n", basename(entry->scriptpath), entry->me.display);
+ bootentries_for_each_entry(bootentries, entry) {
+ struct blspec_entry *ble = container_of(entry, struct blspec_entry, entry);
+
+ if (ble->scriptpath)
+ printf("%-40s %s\n", basename(ble->scriptpath), entry->me.display);
else
printf("%s\n", entry->me.display);
}
@@ -332,7 +335,7 @@ static void bootsources_list(char *entries[], int num_entries)
static int boot(const char *name)
{
struct bootentries *bootentries;
- struct blspec_entry *entry;
+ struct bootentry *entry;
int ret;
bootentries = blspec_alloc();
@@ -345,7 +348,7 @@ static int boot(const char *name)
return -ENOENT;
}
- blspec_for_each_entry(bootentries, entry) {
+ bootentries_for_each_entry(bootentries, entry) {
printf("booting %s\n", entry->me.display);
ret = boot_entry(entry);
if (!ret)
diff --git a/common/blspec.c b/common/blspec.c
index 81049a7..d1597f9 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -128,9 +128,11 @@ static struct blspec_entry *blspec_entry_open(struct bootentries *bootentries,
*/
static int blspec_have_entry(struct bootentries *bootentries, const char *path)
{
+ struct bootentry *be;
struct blspec_entry *e;
- list_for_each_entry(e, &bootentries->entries, list) {
+ list_for_each_entry(be, &bootentries->entries, list) {
+ e = container_of(be, struct blspec_entry, entry);
if (e->configpath && !strcmp(e->configpath, path))
return 1;
}
@@ -407,7 +409,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
hwdevname = xstrdup(dev_name(entry->cdev->dev->parent));
}
- entry->me.display = basprintf("%-20s %-20s %s",
+ entry->entry.me.display = basprintf("%-20s %-20s %s",
devname ? devname : "",
hwdevname ? hwdevname : "",
blspec_entry_var_get(entry, "title"));
@@ -415,7 +417,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
free(devname);
free(hwdevname);
- entry->me.type = MENU_ENTRY_NORMAL;
+ entry->entry.me.type = MENU_ENTRY_NORMAL;
}
ret = found;
@@ -634,8 +636,9 @@ int blspec_scan_devicename(struct bootentries *bootentries, const char *devname)
* In case of an error the error code is returned. This function may
* return 0 in case of a succesful dry run.
*/
-int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun)
+int blspec_boot(struct bootentry *be, int verbose, int dryrun)
{
+ struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
int ret;
const char *abspath, *devicetree, *options, *initrd, *linuximage;
const char *appendroot;
diff --git a/include/blspec.h b/include/blspec.h
index cb4adc5..aced246 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -9,15 +9,19 @@ struct bootentries {
struct menu *menu;
};
-struct blspec_entry {
+struct bootentry {
struct list_head list;
+ struct menu_entry me;
+};
+
+struct blspec_entry {
+ struct bootentry entry;
+
struct device_node *node;
struct cdev *cdev;
char *rootpath;
char *configpath;
- struct menu_entry me;
-
char *scriptpath;
};
@@ -25,7 +29,7 @@ int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
const char *val);
const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name);
-int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun);
+int blspec_boot(struct bootentry *entry, int verbose, int dryrun);
int blspec_scan_devices(struct bootentries *bootentries);
@@ -33,8 +37,8 @@ int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
int blspec_scan_devicename(struct bootentries *bootentries, const char *devname);
int blspec_scan_directory(struct bootentries *bootentries, const char *root);
-#define blspec_for_each_entry(blspec, entry) \
- list_for_each_entry(entry, &blspec->entries, list)
+#define bootentries_for_each_entry(bootentries, entry) \
+ list_for_each_entry(entry, &bootentries->entries, list)
static inline struct blspec_entry *blspec_entry_alloc(struct bootentries *bootentries)
{
@@ -44,16 +48,16 @@ static inline struct blspec_entry *blspec_entry_alloc(struct bootentries *booten
entry->node = of_new_node(NULL, NULL);
- list_add_tail(&entry->list, &bootentries->entries);
+ list_add_tail(&entry->entry.list, &bootentries->entries);
return entry;
}
static inline void blspec_entry_free(struct blspec_entry *entry)
{
- list_del(&entry->list);
+ list_del(&entry->entry.list);
of_delete_node(entry->node);
- free(entry->me.display);
+ free(entry->entry.me.display);
free(entry->scriptpath);
free(entry->configpath);
free(entry->rootpath);
@@ -75,10 +79,13 @@ static inline struct bootentries *blspec_alloc(void)
static inline void blspec_free(struct bootentries *bootentries)
{
- struct blspec_entry *entry, *tmp;
+ struct bootentry *be, *tmp;
+ struct blspec_entry *entry;
- list_for_each_entry_safe(entry, tmp, &bootentries->entries, list)
+ list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
+ entry = container_of(be, struct blspec_entry, entry);
blspec_entry_free(entry);
+ }
if (bootentries->menu)
free(bootentries->menu->display);
free(bootentries->menu);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 08/18] bootentries: Add title/description
2016-07-22 12:44 Sascha Hauer
` (6 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 07/18] blspec: factor out a struct bootentry Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 09/18] blspec: separate bootentries from blspec entries Sascha Hauer
` (9 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
We currently have to special case blspec entries vs. boot scripts
in the common boot code since we want to print different informations
about them. This adds a 'title' and 'description' which can be filled
in with different information by bootscripts and blspec entries and
so we get rid of the special handling.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 23 ++++++++++-------------
common/blspec.c | 9 ++++-----
include/blspec.h | 4 ++++
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index edf9eab..19f2fb5 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -130,7 +130,8 @@ static int bootscript_create_entry(struct bootentries *bootentries, const char *
be = blspec_entry_alloc(bootentries);
be->entry.me.type = MENU_ENTRY_NORMAL;
be->scriptpath = xstrdup(name);
- be->entry.me.display = xstrdup(basename(be->scriptpath));
+ be->entry.title = xstrdup(basename(be->scriptpath));
+ be->entry.description = basprintf("script: %s", name);
return 0;
}
@@ -273,6 +274,8 @@ static void bootsources_menu(char *entries[], int num_entries)
return;
bootentries_for_each_entry(bootentries, entry) {
+ if (!entry->me.display)
+ entry->me.display = xstrdup(entry->title);
entry->me.action = bootsource_action;
menu_add_entry(bootentries->menu, &entry->me);
}
@@ -305,17 +308,11 @@ static void bootsources_list(char *entries[], int num_entries)
if (!bootentries)
return;
- printf(" %-20s %-20s %s\n", "device", "hwdevice", "title");
- printf(" %-20s %-20s %s\n", "------", "--------", "-----");
+ printf("%-20s\n", "title");
+ printf("%-20s\n", "------");
- bootentries_for_each_entry(bootentries, entry) {
- struct blspec_entry *ble = container_of(entry, struct blspec_entry, entry);
-
- if (ble->scriptpath)
- printf("%-40s %s\n", basename(ble->scriptpath), entry->me.display);
- else
- printf("%s\n", entry->me.display);
- }
+ bootentries_for_each_entry(bootentries, entry)
+ printf("%-20s %s\n", entry->title, entry->description);
blspec_free(bootentries);
}
@@ -349,11 +346,11 @@ static int boot(const char *name)
}
bootentries_for_each_entry(bootentries, entry) {
- printf("booting %s\n", entry->me.display);
+ printf("booting %s\n", entry->title);
ret = boot_entry(entry);
if (!ret)
break;
- printf("booting %s failed: %s\n", entry->me.display, strerror(-ret));
+ printf("booting %s failed: %s\n", entry->title, strerror(-ret));
}
return ret;
diff --git a/common/blspec.c b/common/blspec.c
index d1597f9..dff0928 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -409,11 +409,10 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
hwdevname = xstrdup(dev_name(entry->cdev->dev->parent));
}
- entry->entry.me.display = basprintf("%-20s %-20s %s",
- devname ? devname : "",
- hwdevname ? hwdevname : "",
- blspec_entry_var_get(entry, "title"));
-
+ entry->entry.title = xstrdup(blspec_entry_var_get(entry, "title"));
+ entry->entry.description = basprintf("blspec entry, device: %s hwdevice: %s",
+ devname ? devname : "none",
+ hwdevname ? hwdevname : "none");
free(devname);
free(hwdevname);
diff --git a/include/blspec.h b/include/blspec.h
index aced246..c956f0d 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -12,6 +12,8 @@ struct bootentries {
struct bootentry {
struct list_head list;
struct menu_entry me;
+ char *title;
+ char *description;
};
struct blspec_entry {
@@ -58,6 +60,8 @@ static inline void blspec_entry_free(struct blspec_entry *entry)
list_del(&entry->entry.list);
of_delete_node(entry->node);
free(entry->entry.me.display);
+ free(entry->entry.title);
+ free(entry->entry.description);
free(entry->scriptpath);
free(entry->configpath);
free(entry->rootpath);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 09/18] blspec: separate bootentries from blspec entries
2016-07-22 12:44 Sascha Hauer
` (7 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 08/18] bootentries: Add title/description Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 10/18] blspec: Make blspec_boot static Sascha Hauer
` (8 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
This completes the separation of the blspec code from the boot
code. With this the boot code only handles generic boot entries
of type struct bootentry which are embedded into the type
(blspec/bootscript) specific structs.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 100 ++++++++++++++++++++++++++++++++++++++++++-------------
common/blspec.c | 28 +++++++++++++++-
include/blspec.h | 60 +++------------------------------
3 files changed, 108 insertions(+), 80 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index 19f2fb5..1ae2745 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -36,19 +36,69 @@ static int verbose;
static int dryrun;
static int timeout;
+int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry)
+{
+ list_add_tail(&entry->list, &entries->entries);
+
+ return 0;
+}
+
+static struct bootentries *bootentries_alloc(void)
+{
+ struct bootentries *bootentries;
+
+ bootentries = xzalloc(sizeof(*bootentries));
+ INIT_LIST_HEAD(&bootentries->entries);
+
+ if (IS_ENABLED(CONFIG_MENU))
+ bootentries->menu = menu_alloc();
+
+ return bootentries;
+}
+
+static void bootentries_free(struct bootentries *bootentries)
+{
+ struct bootentry *be, *tmp;
+
+ list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
+ list_del(&be->list);
+ free(be->title);
+ free(be->description);
+ free(be->me.display);
+ be->release(be);
+ }
+
+ if (bootentries->menu)
+ free(bootentries->menu->display);
+ free(bootentries->menu);
+ free(bootentries);
+}
+
+struct bootentry_script {
+ struct bootentry entry;
+ char *scriptpath;
+};
+
/*
* Start a single boot script. 'path' is a full path to a boot script.
*/
-static int boot_script(char *path)
+static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
{
+ struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
int ret;
+
struct bootm_data data = {};
+ if (dryrun) {
+ printf("Would run %s\n", bs->scriptpath);
+ return 0;
+ }
+
globalvar_set_match("linux.bootargs.dyn.", "");
- ret = run_command(path);
+ ret = run_command(bs->scriptpath);
if (ret) {
- printf("Running %s failed\n", path);
+ printf("Running %s failed\n", bs->scriptpath);
goto out;
}
@@ -61,7 +111,7 @@ static int boot_script(char *path)
ret = bootm_boot(&data);
if (ret)
- pr_err("Booting %s failed: %s\n", basename(path), strerror(-ret));
+ pr_err("Booting %s failed: %s\n", basename(bs->scriptpath), strerror(-ret));
out:
return ret;
}
@@ -81,7 +131,6 @@ BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
static int boot_entry(struct bootentry *be)
{
int ret;
- struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
ret = watchdog_set_timeout(boot_watchdog_timeout);
@@ -89,14 +138,7 @@ static int boot_entry(struct bootentry *be)
pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
}
- if (entry->scriptpath) {
- ret = boot_script(entry->scriptpath);
- } else {
- if (IS_ENABLED(CONFIG_BLSPEC))
- ret = blspec_boot(be, verbose, dryrun);
- else
- ret = -ENOSYS;
- }
+ ret = be->boot(be, verbose, dryrun);
return ret;
}
@@ -115,23 +157,35 @@ static void bootsource_action(struct menu *m, struct menu_entry *me)
read_key();
}
+static void bootscript_entry_release(struct bootentry *entry)
+{
+ struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
+
+ free(bs->scriptpath);
+ free(bs->entry.me.display);
+ free(bs);
+}
+
/*
* bootscript_create_entry - create a boot entry from a script name
*/
static int bootscript_create_entry(struct bootentries *bootentries, const char *name)
{
- struct blspec_entry *be;
+ struct bootentry_script *bs;
enum filetype type;
type = file_name_detect_type(name);
if (type != filetype_sh)
return -EINVAL;
- be = blspec_entry_alloc(bootentries);
- be->entry.me.type = MENU_ENTRY_NORMAL;
- be->scriptpath = xstrdup(name);
- be->entry.title = xstrdup(basename(be->scriptpath));
- be->entry.description = basprintf("script: %s", name);
+ bs = xzalloc(sizeof(*bs));
+ bs->entry.me.type = MENU_ENTRY_NORMAL;
+ bs->entry.release = bootscript_entry_release;
+ bs->entry.boot = bootscript_boot;
+ bs->scriptpath = xstrdup(name);
+ bs->entry.title = xstrdup(basename(bs->scriptpath));
+ bs->entry.description = basprintf("script: %s", name);
+ bootentries_add_entry(bootentries, &bs->entry);
return 0;
}
@@ -238,7 +292,7 @@ static struct bootentries *bootentries_collect(char *entries[], int num_entries)
struct bootentries *bootentries;
int i;
- bootentries = blspec_alloc();
+ bootentries = bootentries_alloc();
if (IS_ENABLED(CONFIG_MENU))
bootentries->menu->display = basprintf("boot");
@@ -293,7 +347,7 @@ static void bootsources_menu(char *entries[], int num_entries)
free(back_entry);
- blspec_free(bootentries);
+ bootentries_free(bootentries);
}
/*
@@ -314,7 +368,7 @@ static void bootsources_list(char *entries[], int num_entries)
bootentries_for_each_entry(bootentries, entry)
printf("%-20s %s\n", entry->title, entry->description);
- blspec_free(bootentries);
+ bootentries_free(bootentries);
}
/*
@@ -335,7 +389,7 @@ static int boot(const char *name)
struct bootentry *entry;
int ret;
- bootentries = blspec_alloc();
+ bootentries = bootentries_alloc();
ret = bootentry_parse_one(bootentries, name);
if (ret < 0)
return ret;
diff --git a/common/blspec.c b/common/blspec.c
index dff0928..aa70685 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -55,6 +55,29 @@ const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name)
return ret ? NULL : str;
}
+static void blspec_entry_free(struct bootentry *be)
+{
+ struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
+
+ of_delete_node(entry->node);
+ free(entry->configpath);
+ free(entry->rootpath);
+ free(entry);
+}
+
+static struct blspec_entry *blspec_entry_alloc(struct bootentries *bootentries)
+{
+ struct blspec_entry *entry;
+
+ entry = xzalloc(sizeof(*entry));
+
+ entry->node = of_new_node(NULL, NULL);
+ entry->entry.release = blspec_entry_free;
+ entry->entry.boot = blspec_boot;
+
+ return entry;
+}
+
/*
* blspec_entry_open - open an entry given a path
*/
@@ -397,7 +420,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
entry->cdev = get_cdev_by_mountpath(root);
if (!entry_is_of_compatible(entry)) {
- blspec_entry_free(entry);
+ blspec_entry_free(&entry->entry);
continue;
}
@@ -417,6 +440,9 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
free(hwdevname);
entry->entry.me.type = MENU_ENTRY_NORMAL;
+ entry->entry.release = blspec_entry_free;
+
+ bootentries_add_entry(bootentries, &entry->entry);
}
ret = found;
diff --git a/include/blspec.h b/include/blspec.h
index c956f0d..7a16ae7 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -14,6 +14,8 @@ struct bootentry {
struct menu_entry me;
char *title;
char *description;
+ int (*boot)(struct bootentry *entry, int verbose, int dryrun);
+ void (*release)(struct bootentry *entry);
};
struct blspec_entry {
@@ -23,8 +25,6 @@ struct blspec_entry {
struct cdev *cdev;
char *rootpath;
char *configpath;
-
- char *scriptpath;
};
int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
@@ -39,61 +39,9 @@ int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
int blspec_scan_devicename(struct bootentries *bootentries, const char *devname);
int blspec_scan_directory(struct bootentries *bootentries, const char *root);
+int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
+
#define bootentries_for_each_entry(bootentries, entry) \
list_for_each_entry(entry, &bootentries->entries, list)
-static inline struct blspec_entry *blspec_entry_alloc(struct bootentries *bootentries)
-{
- struct blspec_entry *entry;
-
- entry = xzalloc(sizeof(*entry));
-
- entry->node = of_new_node(NULL, NULL);
-
- list_add_tail(&entry->entry.list, &bootentries->entries);
-
- return entry;
-}
-
-static inline void blspec_entry_free(struct blspec_entry *entry)
-{
- list_del(&entry->entry.list);
- of_delete_node(entry->node);
- free(entry->entry.me.display);
- free(entry->entry.title);
- free(entry->entry.description);
- free(entry->scriptpath);
- free(entry->configpath);
- free(entry->rootpath);
- free(entry);
-}
-
-static inline struct bootentries *blspec_alloc(void)
-{
- struct bootentries *bootentries;
-
- bootentries = xzalloc(sizeof(*bootentries));
- INIT_LIST_HEAD(&bootentries->entries);
-
- if (IS_ENABLED(CONFIG_MENU))
- bootentries->menu = menu_alloc();
-
- return bootentries;
-}
-
-static inline void blspec_free(struct bootentries *bootentries)
-{
- struct bootentry *be, *tmp;
- struct blspec_entry *entry;
-
- list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
- entry = container_of(be, struct blspec_entry, entry);
- blspec_entry_free(entry);
- }
- if (bootentries->menu)
- free(bootentries->menu->display);
- free(bootentries->menu);
- free(bootentries);
-}
-
#endif /* __LOADER_H__ */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 10/18] blspec: Make blspec_boot static
2016-07-22 12:44 Sascha Hauer
` (8 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 09/18] blspec: separate bootentries from blspec entries Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 11/18] bootentries: Move menu display string allocation to bootentries_alloc() Sascha Hauer
` (7 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Since blspec_boot is now only used locally we can make it static. Move
it up to avoid a static declaration.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 156 +++++++++++++++++++++++++++----------------------------
include/blspec.h | 2 -
2 files changed, 78 insertions(+), 80 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index aa70685..6c963df 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -43,6 +43,84 @@ int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
}
/*
+ * blspec_boot - boot an entry
+ *
+ * This boots an entry. On success this function does not return.
+ * In case of an error the error code is returned. This function may
+ * return 0 in case of a succesful dry run.
+ */
+static int blspec_boot(struct bootentry *be, int verbose, int dryrun)
+{
+ struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
+ int ret;
+ const char *abspath, *devicetree, *options, *initrd, *linuximage;
+ const char *appendroot;
+ struct bootm_data data = {
+ .initrd_address = UIMAGE_INVALID_ADDRESS,
+ .os_address = UIMAGE_SOME_ADDRESS,
+ .verbose = verbose,
+ .dryrun = dryrun,
+ };
+
+ globalvar_set_match("linux.bootargs.dyn.", "");
+ globalvar_set_match("bootm.", "");
+
+ devicetree = blspec_entry_var_get(entry, "devicetree");
+ initrd = blspec_entry_var_get(entry, "initrd");
+ options = blspec_entry_var_get(entry, "options");
+ linuximage = blspec_entry_var_get(entry, "linux");
+
+ if (entry->rootpath)
+ abspath = entry->rootpath;
+ else
+ abspath = "";
+
+ data.os_file = basprintf("%s/%s", abspath, linuximage);
+
+ if (devicetree) {
+ if (!strcmp(devicetree, "none")) {
+ struct device_node *node = of_get_root_node();
+ if (node)
+ of_delete_node(node);
+ } else {
+ data.oftree_file = basprintf("%s/%s", abspath,
+ devicetree);
+ }
+ }
+
+ if (initrd)
+ data.initrd_file = basprintf("%s/%s", abspath, initrd);
+
+ globalvar_add_simple("linux.bootargs.dyn.bootentries", options);
+
+ appendroot = blspec_entry_var_get(entry, "linux-appendroot");
+ if (appendroot) {
+ int val;
+
+ ret = strtobool(appendroot, &val);
+ if (ret) {
+ pr_err("Invalid value \"%s\" for appendroot option\n",
+ appendroot);
+ goto err_out;
+ }
+ data.appendroot = val;
+ }
+
+ pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
+ entry->cdev ? dev_name(entry->cdev->dev) : "none");
+
+ ret = bootm_boot(&data);
+ if (ret)
+ pr_err("Booting failed\n");
+err_out:
+ free((char *)data.oftree_file);
+ free((char *)data.initrd_file);
+ free((char *)data.os_file);
+
+ return ret;
+}
+
+/*
* blspec_entry_var_get - get the value of a variable
*/
const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name)
@@ -653,81 +731,3 @@ int blspec_scan_devicename(struct bootentries *bootentries, const char *devname)
return blspec_scan_device(bootentries, dev);
}
-
-/*
- * blspec_boot - boot an entry
- *
- * This boots an entry. On success this function does not return.
- * In case of an error the error code is returned. This function may
- * return 0 in case of a succesful dry run.
- */
-int blspec_boot(struct bootentry *be, int verbose, int dryrun)
-{
- struct blspec_entry *entry = container_of(be, struct blspec_entry, entry);
- int ret;
- const char *abspath, *devicetree, *options, *initrd, *linuximage;
- const char *appendroot;
- struct bootm_data data = {
- .initrd_address = UIMAGE_INVALID_ADDRESS,
- .os_address = UIMAGE_SOME_ADDRESS,
- .verbose = verbose,
- .dryrun = dryrun,
- };
-
- globalvar_set_match("linux.bootargs.dyn.", "");
- globalvar_set_match("bootm.", "");
-
- devicetree = blspec_entry_var_get(entry, "devicetree");
- initrd = blspec_entry_var_get(entry, "initrd");
- options = blspec_entry_var_get(entry, "options");
- linuximage = blspec_entry_var_get(entry, "linux");
-
- if (entry->rootpath)
- abspath = entry->rootpath;
- else
- abspath = "";
-
- data.os_file = basprintf("%s/%s", abspath, linuximage);
-
- if (devicetree) {
- if (!strcmp(devicetree, "none")) {
- struct device_node *node = of_get_root_node();
- if (node)
- of_delete_node(node);
- } else {
- data.oftree_file = basprintf("%s/%s", abspath,
- devicetree);
- }
- }
-
- if (initrd)
- data.initrd_file = basprintf("%s/%s", abspath, initrd);
-
- globalvar_add_simple("linux.bootargs.dyn.bootentries", options);
-
- appendroot = blspec_entry_var_get(entry, "linux-appendroot");
- if (appendroot) {
- int val;
-
- ret = strtobool(appendroot, &val);
- if (ret) {
- pr_err("Invalid value \"%s\" for appendroot option\n",
- appendroot);
- goto err_out;
- }
- data.appendroot = val;
- }
-
- pr_info("booting %s from %s\n", blspec_entry_var_get(entry, "title"),
- entry->cdev ? dev_name(entry->cdev->dev) : "none");
-
- ret = bootm_boot(&data);
- if (ret)
- pr_err("Booting failed\n");
-err_out:
- free((char *)data.oftree_file);
- free((char *)data.initrd_file);
- free((char *)data.os_file);
-
- return ret;
-}
diff --git a/include/blspec.h b/include/blspec.h
index 7a16ae7..8a79df5 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -31,8 +31,6 @@ int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
const char *val);
const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name);
-int blspec_boot(struct bootentry *entry, int verbose, int dryrun);
-
int blspec_scan_devices(struct bootentries *bootentries);
int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 11/18] bootentries: Move menu display string allocation to bootentries_alloc()
2016-07-22 12:44 Sascha Hauer
` (9 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 10/18] blspec: Make blspec_boot static Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 12/18] bootentries: Move struct bootentries to include/boot.h Sascha Hauer
` (6 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
bootentries_alloc() is the place where the struct bootentries container
is allocated, so allocate the menu entry there aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index 1ae2745..f193c93 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -50,8 +50,10 @@ static struct bootentries *bootentries_alloc(void)
bootentries = xzalloc(sizeof(*bootentries));
INIT_LIST_HEAD(&bootentries->entries);
- if (IS_ENABLED(CONFIG_MENU))
+ if (IS_ENABLED(CONFIG_MENU)) {
bootentries->menu = menu_alloc();
+ bootentries->menu->display = basprintf("boot");
+ }
return bootentries;
}
@@ -294,9 +296,6 @@ static struct bootentries *bootentries_collect(char *entries[], int num_entries)
bootentries = bootentries_alloc();
- if (IS_ENABLED(CONFIG_MENU))
- bootentries->menu->display = basprintf("boot");
-
if (!num_entries)
bootscript_scan_path(bootentries, "/env/boot");
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 12/18] bootentries: Move struct bootentries to include/boot.h
2016-07-22 12:44 Sascha Hauer
` (10 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 11/18] bootentries: Move menu display string allocation to bootentries_alloc() Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 13/18] boot: Use struct bootentries to pass around data Sascha Hauer
` (5 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
The boot function prototypes are declared in include/blspec.h. Move them
to include/boot.h where they belong.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/blspec.h | 21 +--------------------
include/boot.h | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/include/blspec.h b/include/blspec.h
index 8a79df5..7d911f0 100644
--- a/include/blspec.h
+++ b/include/blspec.h
@@ -2,21 +2,7 @@
#define __LOADER_H__
#include <linux/list.h>
-#include <menu.h>
-
-struct bootentries {
- struct list_head entries;
- struct menu *menu;
-};
-
-struct bootentry {
- struct list_head list;
- struct menu_entry me;
- char *title;
- char *description;
- int (*boot)(struct bootentry *entry, int verbose, int dryrun);
- void (*release)(struct bootentry *entry);
-};
+#include <boot.h>
struct blspec_entry {
struct bootentry entry;
@@ -37,9 +23,4 @@ int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
int blspec_scan_devicename(struct bootentries *bootentries, const char *devname);
int blspec_scan_directory(struct bootentries *bootentries, const char *root);
-int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
-
-#define bootentries_for_each_entry(bootentries, entry) \
- list_for_each_entry(entry, &bootentries->entries, list)
-
#endif /* __LOADER_H__ */
diff --git a/include/boot.h b/include/boot.h
index da40ac2..e0a61c5 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -2,6 +2,7 @@
#define __BOOT_H
#include <of.h>
+#include <menu.h>
#include <environment.h>
#ifdef CONFIG_FLEXIBLE_BOOTARGS
@@ -19,4 +20,23 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
}
#endif
+struct bootentries {
+ struct list_head entries;
+ struct menu *menu;
+};
+
+struct bootentry {
+ struct list_head list;
+ struct menu_entry me;
+ char *title;
+ char *description;
+ int (*boot)(struct bootentry *entry, int verbose, int dryrun);
+ void (*release)(struct bootentry *entry);
+};
+
+int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
+
+#define bootentries_for_each_entry(bootentries, entry) \
+ list_for_each_entry(entry, &bootentries->entries, list)
+
#endif /* __BOOT_H */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 13/18] boot: Use struct bootentries to pass around data
2016-07-22 12:44 Sascha Hauer
` (11 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 12/18] bootentries: Move struct bootentries to include/boot.h Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 14/18] boot: Move code to common/ Sascha Hauer
` (4 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
We have a struct bootentries type to collect different boot entries,
so use this to pass around data between functions rather than using
an array of strings. With this we also no longer have to convert a
string to a boot entry multiple times.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 131 ++++++++++----------------------------------------------
1 file changed, 22 insertions(+), 109 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index f193c93..58968a2 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -134,6 +134,8 @@ static int boot_entry(struct bootentry *be)
{
int ret;
+ printf("booting %s\n", be->title);
+
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
ret = watchdog_set_timeout(boot_watchdog_timeout);
if (ret)
@@ -142,6 +144,9 @@ static int boot_entry(struct bootentry *be)
ret = be->boot(be, verbose, dryrun);
+ if (ret)
+ printf("booting %s failed: %s\n", be->title, strerror(-ret));
+
return ret;
}
@@ -287,33 +292,10 @@ static int bootentry_parse_one(struct bootentries *bootentries, const char *name
}
/*
- * bootentries_collect - collect bootentries from an array of names
- */
-static struct bootentries *bootentries_collect(char *entries[], int num_entries)
-{
- struct bootentries *bootentries;
- int i;
-
- bootentries = bootentries_alloc();
-
- if (!num_entries)
- bootscript_scan_path(bootentries, "/env/boot");
-
- if (IS_ENABLED(CONFIG_BLSPEC) && !num_entries)
- blspec_scan_devices(bootentries);
-
- for (i = 0; i < num_entries; i++)
- bootentry_parse_one(bootentries, entries[i]);
-
- return bootentries;
-}
-
-/*
* bootsources_menu - show a menu from an array of names
*/
-static void bootsources_menu(char *entries[], int num_entries)
+static void bootsources_menu(struct bootentries *bootentries)
{
- struct bootentries *bootentries = NULL;
struct bootentry *entry;
struct menu_entry *back_entry;
@@ -322,10 +304,6 @@ static void bootsources_menu(char *entries[], int num_entries)
return;
}
- bootentries = bootentries_collect(entries, num_entries);
- if (!bootentries)
- return;
-
bootentries_for_each_entry(bootentries, entry) {
if (!entry->me.display)
entry->me.display = xstrdup(entry->title);
@@ -345,77 +323,29 @@ static void bootsources_menu(char *entries[], int num_entries)
menu_show(bootentries->menu);
free(back_entry);
-
- bootentries_free(bootentries);
}
/*
* bootsources_list - list boot entries from an array of names
*/
-static void bootsources_list(char *entries[], int num_entries)
+static void bootsources_list(struct bootentries *bootentries)
{
- struct bootentries *bootentries;
struct bootentry *entry;
- bootentries = bootentries_collect(entries, num_entries);
- if (!bootentries)
- return;
-
printf("%-20s\n", "title");
printf("%-20s\n", "------");
bootentries_for_each_entry(bootentries, entry)
printf("%-20s %s\n", entry->title, entry->description);
-
- bootentries_free(bootentries);
-}
-
-/*
- * boot a script or a bootspec entry. 'name' can be:
- * - a filename under /env/boot/
- * - a full path to a boot script
- * - a device name
- * - a partition name under /dev/
- * - a full path to a directory which
- * - contains boot scripts, or
- * - contains a loader/entries/ directory containing bootspec entries
- *
- * Returns a negative error on failure, or 0 on a successful dryrun boot.
- */
-static int boot(const char *name)
-{
- struct bootentries *bootentries;
- struct bootentry *entry;
- int ret;
-
- bootentries = bootentries_alloc();
- ret = bootentry_parse_one(bootentries, name);
- if (ret < 0)
- return ret;
-
- if (!ret) {
- printf("Nothing bootable found on %s\n", name);
- return -ENOENT;
- }
-
- bootentries_for_each_entry(bootentries, entry) {
- printf("booting %s\n", entry->title);
- ret = boot_entry(entry);
- if (!ret)
- break;
- printf("booting %s failed: %s\n", entry->title, strerror(-ret));
- }
-
- return ret;
}
static int do_boot(int argc, char *argv[])
{
char *freep = NULL;
int opt, ret = 0, do_list = 0, do_menu = 0;
- char **sources;
- int num_sources;
int i;
+ struct bootentries *entries;
+ struct bootentry *entry;
verbose = 0;
dryrun = 0;
@@ -444,12 +374,14 @@ static int do_boot(int argc, char *argv[])
}
}
+ entries = bootentries_alloc();
+
if (optind < argc) {
- num_sources = argc - optind;
- sources = xmemdup(&argv[optind], sizeof(char *) * num_sources);
+ for (i = optind; i < argc; i++)
+ bootentry_parse_one(entries, argv[i]);
} else {
const char *def;
- char *sep;
+ char *sep, *name;
def = getenv("global.boot.default");
if (!def)
@@ -457,49 +389,30 @@ static int do_boot(int argc, char *argv[])
sep = freep = xstrdup(def);
- num_sources = 0;
-
- while (1) {
- num_sources++;
+ while ((name = strsep(&sep, " ")) != NULL)
+ bootentry_parse_one(entries, name);
- sep = strchr(sep, ' ');
- if (!sep)
- break;
- sep++;
- }
-
- sources = xmalloc(sizeof(char *) * num_sources);
-
- sep = freep;
-
- for (i = 0; i < num_sources; i++) {
- sources[i] = sep;
- sep = strchr(sep, ' ');
- if (sep)
- *sep = 0;
- sep++;
- }
+ free(freep);
}
if (do_list) {
- bootsources_list(sources, num_sources);
+ bootsources_list(entries);
goto out;
}
if (do_menu) {
- bootsources_menu(sources, num_sources);
+ bootsources_menu(entries);
goto out;
}
- for (i = 0; i < num_sources; i++) {
- ret = boot(sources[i]);
+ bootentries_for_each_entry(entries, entry) {
+ ret = boot_entry(entry);
if (!ret)
break;
}
out:
- free(sources);
- free(freep);
+ bootentries_free(entries);
return ret;
}
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 14/18] boot: Move code to common/
2016-07-22 12:44 Sascha Hauer
` (12 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 13/18] boot: Use struct bootentries to pass around data Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 15/18] boot: add single quotes when printing boot target names Sascha Hauer
` (3 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Normally code in commands/ shall only do the option parsing whereas the
functionality shall be in common/ to make the code usable from C aswell.
Do this in the boot code aswell, move it to common/boot.c and add the
function prototypes to include/boot.h
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 1 +
commands/boot.c | 334 ++----------------------------------------------------
common/Kconfig | 3 +
common/Makefile | 1 +
common/boot.c | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/boot.h | 9 ++
6 files changed, 360 insertions(+), 327 deletions(-)
create mode 100644 common/boot.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 3a0977b..0685664 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -294,6 +294,7 @@ config CMD_BOOT_ORDER
config CMD_BOOT
tristate
depends on BOOTM
+ select BOOT
prompt "boot"
help
Select this for booting based on scripts. Unlike the bootm command which
diff --git a/commands/boot.c b/commands/boot.c
index 58968a2..e757011 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -11,339 +11,21 @@
*
*/
-#include <environment.h>
#include <globalvar.h>
-#include <magicvar.h>
-#include <watchdog.h>
#include <command.h>
-#include <readkey.h>
#include <common.h>
#include <getopt.h>
-#include <blspec.h>
-#include <libgen.h>
#include <malloc.h>
-#include <clock.h>
-#include <bootm.h>
-#include <glob.h>
-#include <init.h>
-#include <menu.h>
-#include <fs.h>
+#include <boot.h>
#include <complete.h>
#include <linux/stat.h>
-static int verbose;
-static int dryrun;
-static int timeout;
-
-int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry)
-{
- list_add_tail(&entry->list, &entries->entries);
-
- return 0;
-}
-
-static struct bootentries *bootentries_alloc(void)
-{
- struct bootentries *bootentries;
-
- bootentries = xzalloc(sizeof(*bootentries));
- INIT_LIST_HEAD(&bootentries->entries);
-
- if (IS_ENABLED(CONFIG_MENU)) {
- bootentries->menu = menu_alloc();
- bootentries->menu->display = basprintf("boot");
- }
-
- return bootentries;
-}
-
-static void bootentries_free(struct bootentries *bootentries)
-{
- struct bootentry *be, *tmp;
-
- list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
- list_del(&be->list);
- free(be->title);
- free(be->description);
- free(be->me.display);
- be->release(be);
- }
-
- if (bootentries->menu)
- free(bootentries->menu->display);
- free(bootentries->menu);
- free(bootentries);
-}
-
-struct bootentry_script {
- struct bootentry entry;
- char *scriptpath;
-};
-
-/*
- * Start a single boot script. 'path' is a full path to a boot script.
- */
-static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
-{
- struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
- int ret;
-
- struct bootm_data data = {};
-
- if (dryrun) {
- printf("Would run %s\n", bs->scriptpath);
- return 0;
- }
-
- globalvar_set_match("linux.bootargs.dyn.", "");
-
- ret = run_command(bs->scriptpath);
- if (ret) {
- printf("Running %s failed\n", bs->scriptpath);
- goto out;
- }
-
- bootm_data_init_defaults(&data);
-
- if (verbose)
- data.verbose = verbose;
- if (dryrun)
- data.dryrun = dryrun;
-
- ret = bootm_boot(&data);
- if (ret)
- pr_err("Booting %s failed: %s\n", basename(bs->scriptpath), strerror(-ret));
-out:
- return ret;
-}
-
-static unsigned int boot_watchdog_timeout;
-
-static int init_boot_watchdog_timeout(void)
-{
- return globalvar_add_simple_int("boot.watchdog_timeout",
- &boot_watchdog_timeout, "%u");
-}
-late_initcall(init_boot_watchdog_timeout);
-
-BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
- "Watchdog enable timeout in seconds before booting");
-
-static int boot_entry(struct bootentry *be)
-{
- int ret;
-
- printf("booting %s\n", be->title);
-
- if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
- ret = watchdog_set_timeout(boot_watchdog_timeout);
- if (ret)
- pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
- }
-
- ret = be->boot(be, verbose, dryrun);
-
- if (ret)
- printf("booting %s failed: %s\n", be->title, strerror(-ret));
-
- return ret;
-}
-
-static void bootsource_action(struct menu *m, struct menu_entry *me)
-{
- struct bootentry *be = container_of(me, struct bootentry, me);
- int ret;
-
- ret = boot_entry(be);
- if (ret)
- printf("Booting failed with: %s\n", strerror(-ret));
-
- printf("Press any key to continue\n");
-
- read_key();
-}
-
-static void bootscript_entry_release(struct bootentry *entry)
-{
- struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
-
- free(bs->scriptpath);
- free(bs->entry.me.display);
- free(bs);
-}
-
-/*
- * bootscript_create_entry - create a boot entry from a script name
- */
-static int bootscript_create_entry(struct bootentries *bootentries, const char *name)
-{
- struct bootentry_script *bs;
- enum filetype type;
-
- type = file_name_detect_type(name);
- if (type != filetype_sh)
- return -EINVAL;
-
- bs = xzalloc(sizeof(*bs));
- bs->entry.me.type = MENU_ENTRY_NORMAL;
- bs->entry.release = bootscript_entry_release;
- bs->entry.boot = bootscript_boot;
- bs->scriptpath = xstrdup(name);
- bs->entry.title = xstrdup(basename(bs->scriptpath));
- bs->entry.description = basprintf("script: %s", name);
- bootentries_add_entry(bootentries, &bs->entry);
-
- return 0;
-}
-
-/*
- * 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
- * containing bootscripts.
- */
-static int bootscript_scan_path(struct bootentries *bootentries, const char *path)
-{
- struct stat s;
- char *files;
- int ret, i;
- int found = 0;
- glob_t globb;
-
- ret = stat(path, &s);
- if (ret)
- return ret;
-
- if (!S_ISDIR(s.st_mode)) {
- ret = bootscript_create_entry(bootentries, path);
- if (ret)
- return ret;
- return 1;
- }
-
- files = basprintf("%s/*", path);
-
- glob(files, 0, NULL, &globb);
-
- for (i = 0; i < globb.gl_pathc; i++) {
- char *bootscript_path = globb.gl_pathv[i];
-
- if (*basename(bootscript_path) == '.')
- continue;
-
- bootscript_create_entry(bootentries, bootscript_path);
- found++;
- }
-
- globfree(&globb);
- free(files);
-
- ret = found;
-
- return ret;
-}
-
-/*
- * bootentry_parse_one - create boot entries from a name
- *
- * name can be:
- * - a name of a boot script under /env/boot
- * - a full path of a boot script
- * - a device name
- * - a cdev name
- * - a full path of a directory containing bootloader spec entries
- * - a full path of a directory containing bootscripts
- *
- * Returns the number of entries found or a negative error code.
- */
-static int bootentry_parse_one(struct bootentries *bootentries, const char *name)
-{
- int found = 0, ret;
-
- if (IS_ENABLED(CONFIG_BLSPEC)) {
- ret = blspec_scan_devicename(bootentries, name);
- if (ret > 0)
- found += ret;
-
- if (*name == '/') {
- ret = blspec_scan_directory(bootentries, name);
- if (ret > 0)
- found += ret;
- }
- }
-
- if (!found) {
- char *path;
-
- if (*name != '/')
- path = basprintf("/env/boot/%s", name);
- else
- path = xstrdup(name);
-
- ret = bootscript_scan_path(bootentries, path);
- if (ret > 0)
- found += ret;
-
- free(path);
- }
-
- return found;
-}
-
-/*
- * bootsources_menu - show a menu from an array of names
- */
-static void bootsources_menu(struct bootentries *bootentries)
-{
- struct bootentry *entry;
- struct menu_entry *back_entry;
-
- if (!IS_ENABLED(CONFIG_MENU)) {
- printf("no menu support available\n");
- return;
- }
-
- bootentries_for_each_entry(bootentries, entry) {
- if (!entry->me.display)
- entry->me.display = xstrdup(entry->title);
- entry->me.action = bootsource_action;
- menu_add_entry(bootentries->menu, &entry->me);
- }
-
- back_entry = xzalloc(sizeof(*back_entry));
- back_entry->display = "back";
- back_entry->type = MENU_ENTRY_NORMAL;
- back_entry->non_re_ent = 1;
- menu_add_entry(bootentries->menu, back_entry);
-
- if (timeout >= 0)
- bootentries->menu->auto_select = timeout;
-
- menu_show(bootentries->menu);
-
- free(back_entry);
-}
-
-/*
- * bootsources_list - list boot entries from an array of names
- */
-static void bootsources_list(struct bootentries *bootentries)
-{
- struct bootentry *entry;
-
- printf("%-20s\n", "title");
- printf("%-20s\n", "------");
-
- bootentries_for_each_entry(bootentries, entry)
- printf("%-20s %s\n", entry->title, entry->description);
-}
-
static int do_boot(int argc, char *argv[])
{
char *freep = NULL;
int opt, ret = 0, do_list = 0, do_menu = 0;
- int i;
+ int i, dryrun = 0, verbose = 0, timeout = -1;
struct bootentries *entries;
struct bootentry *entry;
@@ -369,7 +51,7 @@ static int do_boot(int argc, char *argv[])
timeout = simple_strtoul(optarg, NULL, 0);
break;
case 'w':
- boot_watchdog_timeout = simple_strtoul(optarg, NULL, 0);
+ boot_set_watchdog_timeout(simple_strtoul(optarg, NULL, 0));
break;
}
}
@@ -378,7 +60,7 @@ static int do_boot(int argc, char *argv[])
if (optind < argc) {
for (i = optind; i < argc; i++)
- bootentry_parse_one(entries, argv[i]);
+ bootentry_create_from_name(entries, argv[i]);
} else {
const char *def;
char *sep, *name;
@@ -390,7 +72,7 @@ static int do_boot(int argc, char *argv[])
sep = freep = xstrdup(def);
while ((name = strsep(&sep, " ")) != NULL)
- bootentry_parse_one(entries, name);
+ bootentry_create_from_name(entries, name);
free(freep);
}
@@ -401,12 +83,12 @@ static int do_boot(int argc, char *argv[])
}
if (do_menu) {
- bootsources_menu(entries);
+ bootsources_menu(entries, timeout);
goto out;
}
bootentries_for_each_entry(entries, entry) {
- ret = boot_entry(entry);
+ ret = boot_entry(entry, verbose, dryrun);
if (!ret)
break;
}
@@ -450,5 +132,3 @@ BAREBOX_CMD_START(boot)
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
BAREBOX_CMD_HELP(cmd_boot_help)
BAREBOX_CMD_END
-
-BAREBOX_MAGICVAR_NAMED(global_boot_default, global.boot.default, "default boot order");
diff --git a/common/Kconfig b/common/Kconfig
index 6ce2a76..8326340 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -110,6 +110,9 @@ config UBIFORMAT
depends on MTD_UBI
default y
+config BOOT
+ bool
+
menu "General Settings"
config LOCALVERSION
diff --git a/common/Makefile b/common/Makefile
index 17fcb5f..00bc0e8 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o
obj-$(CONFIG_UBIFORMAT) += ubiformat.o
obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o
obj-$(CONFIG_CONSOLE_RATP) += ratp.o
+obj-$(CONFIG_BOOT) += boot.o
quiet_cmd_pwd_h = PWDH $@
ifdef CONFIG_PASSWORD
diff --git a/common/boot.c b/common/boot.c
new file mode 100644
index 0000000..4d29349
--- /dev/null
+++ b/common/boot.c
@@ -0,0 +1,339 @@
+/*
+ * 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.
+ */
+
+#include <environment.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 <linux/stat.h>
+
+int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry)
+{
+ list_add_tail(&entry->list, &entries->entries);
+
+ return 0;
+}
+
+struct bootentries *bootentries_alloc(void)
+{
+ struct bootentries *bootentries;
+
+ bootentries = xzalloc(sizeof(*bootentries));
+ INIT_LIST_HEAD(&bootentries->entries);
+
+ if (IS_ENABLED(CONFIG_MENU)) {
+ bootentries->menu = menu_alloc();
+ bootentries->menu->display = basprintf("boot");
+ }
+
+ return bootentries;
+}
+
+void bootentries_free(struct bootentries *bootentries)
+{
+ struct bootentry *be, *tmp;
+
+ list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
+ list_del(&be->list);
+ free(be->title);
+ free(be->description);
+ free(be->me.display);
+ be->release(be);
+ }
+
+ if (bootentries->menu)
+ free(bootentries->menu->display);
+ free(bootentries->menu);
+ free(bootentries);
+}
+
+struct bootentry_script {
+ struct bootentry entry;
+ char *scriptpath;
+};
+
+/*
+ * Start a single boot script. 'path' is a full path to a boot script.
+ */
+static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
+{
+ struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
+ int ret;
+
+ struct bootm_data data = {};
+
+ if (dryrun) {
+ printf("Would run %s\n", bs->scriptpath);
+ return 0;
+ }
+
+ globalvar_set_match("linux.bootargs.dyn.", "");
+
+ ret = run_command(bs->scriptpath);
+ if (ret) {
+ printf("Running %s failed\n", bs->scriptpath);
+ goto out;
+ }
+
+ bootm_data_init_defaults(&data);
+
+ if (verbose)
+ data.verbose = verbose;
+ if (dryrun)
+ data.dryrun = dryrun;
+
+ ret = bootm_boot(&data);
+ if (ret)
+ pr_err("Booting %s failed: %s\n", basename(bs->scriptpath), strerror(-ret));
+out:
+ return ret;
+}
+
+static unsigned int boot_watchdog_timeout;
+
+void boot_set_watchdog_timeout(unsigned int timeout)
+{
+ boot_watchdog_timeout = timeout;
+}
+
+static int init_boot_watchdog_timeout(void)
+{
+ return globalvar_add_simple_int("boot.watchdog_timeout",
+ &boot_watchdog_timeout, "%u");
+}
+late_initcall(init_boot_watchdog_timeout);
+
+BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, 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 %s\n", be->title);
+
+ if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
+ ret = watchdog_set_timeout(boot_watchdog_timeout);
+ if (ret)
+ pr_warn("Failed to enable watchdog: %s\n", strerror(-ret));
+ }
+
+ ret = be->boot(be, verbose, dryrun);
+
+ if (ret)
+ printf("booting %s failed: %s\n", be->title, strerror(-ret));
+
+ return ret;
+}
+
+static void bootsource_action(struct menu *m, struct menu_entry *me)
+{
+ struct bootentry *be = container_of(me, struct bootentry, me);
+ int ret;
+
+ ret = boot_entry(be, 0, 0);
+ if (ret)
+ printf("Booting failed with: %s\n", strerror(-ret));
+
+ printf("Press any key to continue\n");
+
+ read_key();
+}
+
+static void bootscript_entry_release(struct bootentry *entry)
+{
+ struct bootentry_script *bs = container_of(entry, struct bootentry_script, entry);
+
+ free(bs->scriptpath);
+ free(bs->entry.me.display);
+ free(bs);
+}
+
+/*
+ * bootscript_create_entry - create a boot entry from a script name
+ */
+static int bootscript_create_entry(struct bootentries *bootentries, const char *name)
+{
+ struct bootentry_script *bs;
+ enum filetype type;
+
+ type = file_name_detect_type(name);
+ if (type != filetype_sh)
+ return -EINVAL;
+
+ bs = xzalloc(sizeof(*bs));
+ bs->entry.me.type = MENU_ENTRY_NORMAL;
+ bs->entry.release = bootscript_entry_release;
+ bs->entry.boot = bootscript_boot;
+ bs->scriptpath = xstrdup(name);
+ bs->entry.title = xstrdup(basename(bs->scriptpath));
+ bs->entry.description = basprintf("script: %s", name);
+ bootentries_add_entry(bootentries, &bs->entry);
+
+ return 0;
+}
+
+/*
+ * 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
+ * containing bootscripts.
+ */
+static int bootscript_scan_path(struct bootentries *bootentries, const char *path)
+{
+ struct stat s;
+ char *files;
+ int ret, i;
+ int found = 0;
+ glob_t globb;
+
+ ret = stat(path, &s);
+ if (ret)
+ return ret;
+
+ if (!S_ISDIR(s.st_mode)) {
+ ret = bootscript_create_entry(bootentries, path);
+ if (ret)
+ return ret;
+ return 1;
+ }
+
+ files = basprintf("%s/*", path);
+
+ glob(files, 0, NULL, &globb);
+
+ for (i = 0; i < globb.gl_pathc; i++) {
+ char *bootscript_path = globb.gl_pathv[i];
+
+ if (*basename(bootscript_path) == '.')
+ continue;
+
+ bootscript_create_entry(bootentries, bootscript_path);
+ found++;
+ }
+
+ globfree(&globb);
+ free(files);
+
+ ret = found;
+
+ return ret;
+}
+
+/*
+ * bootentry_create_from_name - create boot entries from a name
+ *
+ * name can be:
+ * - a name of a boot script under /env/boot
+ * - a full path of a boot script
+ * - a device name
+ * - a cdev name
+ * - a full path of a directory containing bootloader spec entries
+ * - a full path of a directory containing bootscripts
+ *
+ * Returns the number of entries found or a negative error code.
+ */
+int bootentry_create_from_name(struct bootentries *bootentries,
+ const char *name)
+{
+ int found = 0, ret;
+
+ if (IS_ENABLED(CONFIG_BLSPEC)) {
+ ret = blspec_scan_devicename(bootentries, name);
+ if (ret > 0)
+ found += ret;
+
+ if (*name == '/') {
+ ret = blspec_scan_directory(bootentries, name);
+ if (ret > 0)
+ found += ret;
+ }
+ }
+
+ if (!found) {
+ char *path;
+
+ if (*name != '/')
+ path = basprintf("/env/boot/%s", name);
+ else
+ path = xstrdup(name);
+
+ ret = bootscript_scan_path(bootentries, path);
+ if (ret > 0)
+ found += ret;
+
+ free(path);
+ }
+
+ return found;
+}
+
+/*
+ * bootsources_menu - show a menu from an array of names
+ */
+void bootsources_menu(struct bootentries *bootentries, int timeout)
+{
+ struct bootentry *entry;
+ struct menu_entry *back_entry;
+
+ if (!IS_ENABLED(CONFIG_MENU)) {
+ printf("no menu support available\n");
+ return;
+ }
+
+ bootentries_for_each_entry(bootentries, entry) {
+ if (!entry->me.display)
+ entry->me.display = xstrdup(entry->title);
+ entry->me.action = bootsource_action;
+ menu_add_entry(bootentries->menu, &entry->me);
+ }
+
+ back_entry = xzalloc(sizeof(*back_entry));
+ back_entry->display = "back";
+ back_entry->type = MENU_ENTRY_NORMAL;
+ back_entry->non_re_ent = 1;
+ menu_add_entry(bootentries->menu, back_entry);
+
+ if (timeout >= 0)
+ bootentries->menu->auto_select = timeout;
+
+ menu_show(bootentries->menu);
+
+ free(back_entry);
+}
+
+/*
+ * bootsources_list - list boot entries from an array of names
+ */
+void bootsources_list(struct bootentries *bootentries)
+{
+ struct bootentry *entry;
+
+ printf("%-20s\n", "title");
+ printf("%-20s\n", "------");
+
+ bootentries_for_each_entry(bootentries, entry)
+ printf("%-20s %s\n", entry->title, entry->description);
+}
+
+BAREBOX_MAGICVAR_NAMED(global_boot_default, global.boot.default, "default boot order");
diff --git a/include/boot.h b/include/boot.h
index e0a61c5..a855cbe 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -39,4 +39,13 @@ int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
#define bootentries_for_each_entry(bootentries, entry) \
list_for_each_entry(entry, &bootentries->entries, list)
+void boot_set_watchdog_timeout(unsigned int timeout);
+struct bootentries *bootentries_alloc(void);
+void bootentries_free(struct bootentries *bootentries);
+int bootentry_create_from_name(struct bootentries *bootentries,
+ const char *name);
+void bootsources_menu(struct bootentries *bootentries, int timeout);
+void bootsources_list(struct bootentries *bootentries);
+int boot_entry(struct bootentry *be, int verbose, int dryrun);
+
#endif /* __BOOT_H */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 15/18] boot: add single quotes when printing boot target names
2016-07-22 12:44 Sascha Hauer
` (13 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 14/18] boot: Move code to common/ Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 16/18] boot command: Explicitly complain when boot target list is empty Sascha Hauer
` (2 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
It's nicer to read when target names have quotes around them, it
makes it clear that this is a string passed in somewhere.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/boot.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/boot.c b/common/boot.c
index 4d29349..e66bacb 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -104,7 +104,7 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
ret = bootm_boot(&data);
if (ret)
- pr_err("Booting %s failed: %s\n", basename(bs->scriptpath), strerror(-ret));
+ pr_err("Booting '%s' failed: %s\n", basename(bs->scriptpath), strerror(-ret));
out:
return ret;
}
@@ -130,7 +130,7 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
{
int ret;
- printf("booting %s\n", be->title);
+ printf("booting '%s'\n", be->title);
if (IS_ENABLED(CONFIG_WATCHDOG) && boot_watchdog_timeout) {
ret = watchdog_set_timeout(boot_watchdog_timeout);
@@ -141,7 +141,7 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
ret = be->boot(be, verbose, dryrun);
if (ret)
- printf("booting %s failed: %s\n", be->title, strerror(-ret));
+ printf("booting '%s' failed: %s\n", be->title, strerror(-ret));
return ret;
}
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 16/18] boot command: Explicitly complain when boot target list is empty
2016-07-22 12:44 Sascha Hauer
` (14 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 15/18] boot: add single quotes when printing boot target names Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 17/18] blspec: Turn message back to debug level Sascha Hauer
2016-07-22 12:44 ` [PATCH 18/18] boot: Print a message when a boot target string does not lead to a boot target Sascha Hauer
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
When no targets to boot are found it can happen that the boot command
just returns silently. Explicitly print a message in this case to give
a clue what might went wrong.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/commands/boot.c b/commands/boot.c
index e757011..b774ddc 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -77,6 +77,11 @@ static int do_boot(int argc, char *argv[])
free(freep);
}
+ if (list_empty(&entries->entries)) {
+ printf("Nothing bootable found\n");
+ return COMMAND_ERROR;
+ }
+
if (do_list) {
bootsources_list(entries);
goto out;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 17/18] blspec: Turn message back to debug level
2016-07-22 12:44 Sascha Hauer
` (15 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 16/18] boot command: Explicitly complain when boot target list is empty Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
2016-07-22 12:44 ` [PATCH 18/18] boot: Print a message when a boot target string does not lead to a boot target Sascha Hauer
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
Normally one should not be interested that the blspec code scans
a directory. In case blspec is not actively used it might even be
confusing, so lower priority of the message in blspec_scan_directory()
to pr_debug.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/blspec.c b/common/blspec.c
index 6c963df..f02f5e9 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -438,7 +438,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
if (!IS_ERR(nfspath))
root = nfspath;
- pr_info("%s: %s %s\n", __func__, root, dirname);
+ pr_debug("%s: %s %s\n", __func__, root, dirname);
abspath = basprintf("%s/%s", root, dirname);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 18/18] boot: Print a message when a boot target string does not lead to a boot target
2016-07-22 12:44 Sascha Hauer
` (16 preceding siblings ...)
2016-07-22 12:44 ` [PATCH 17/18] blspec: Turn message back to debug level Sascha Hauer
@ 2016-07-22 12:44 ` Sascha Hauer
17 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2016-07-22 12:44 UTC (permalink / raw)
To: Barebox List
When doing a 'boot friesel net' one expects a message when 'friesel'
does not give any bootable results and thus 'net' is booted. This patch
adds this message.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/boot.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/commands/boot.c b/commands/boot.c
index b774ddc..8b3b407 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -59,8 +59,11 @@ static int do_boot(int argc, char *argv[])
entries = bootentries_alloc();
if (optind < argc) {
- for (i = optind; i < argc; i++)
- bootentry_create_from_name(entries, argv[i]);
+ for (i = optind; i < argc; i++) {
+ ret = bootentry_create_from_name(entries, argv[i]);
+ if (ret <= 0)
+ printf("Nothing bootable found on '%s'\n", argv[i]);
+ }
} else {
const char *def;
char *sep, *name;
@@ -71,8 +74,11 @@ static int do_boot(int argc, char *argv[])
sep = freep = xstrdup(def);
- while ((name = strsep(&sep, " ")) != NULL)
- bootentry_create_from_name(entries, name);
+ while ((name = strsep(&sep, " ")) != NULL) {
+ ret = bootentry_create_from_name(entries, name);
+ if (ret <= 0)
+ printf("Nothing bootable found on '%s'\n", name);
+ }
free(freep);
}
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2016-07-22 12:45 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-22 12:44 Sascha Hauer
2016-07-22 12:44 ` [PATCH 01/18] blspec: remove unused blspec_boot_devicename Sascha Hauer
2016-07-22 12:44 ` [PATCH 02/18] blspec: Remove once/default handling Sascha Hauer
2016-07-22 12:44 ` [PATCH 03/18] blspec: remove unused function prototype Sascha Hauer
2016-07-22 12:44 ` [PATCH 04/18] boot: Call blspec_scan_directory() only on strings containing an absolute path Sascha Hauer
2016-07-22 12:44 ` [PATCH 05/18] include: Move bulk of boot.h to bootm.h Sascha Hauer
2016-07-22 12:44 ` [PATCH 06/18] blpec: rename struct lspec -> bootentries Sascha Hauer
2016-07-22 12:44 ` [PATCH 07/18] blspec: factor out a struct bootentry Sascha Hauer
2016-07-22 12:44 ` [PATCH 08/18] bootentries: Add title/description Sascha Hauer
2016-07-22 12:44 ` [PATCH 09/18] blspec: separate bootentries from blspec entries Sascha Hauer
2016-07-22 12:44 ` [PATCH 10/18] blspec: Make blspec_boot static Sascha Hauer
2016-07-22 12:44 ` [PATCH 11/18] bootentries: Move menu display string allocation to bootentries_alloc() Sascha Hauer
2016-07-22 12:44 ` [PATCH 12/18] bootentries: Move struct bootentries to include/boot.h Sascha Hauer
2016-07-22 12:44 ` [PATCH 13/18] boot: Use struct bootentries to pass around data Sascha Hauer
2016-07-22 12:44 ` [PATCH 14/18] boot: Move code to common/ Sascha Hauer
2016-07-22 12:44 ` [PATCH 15/18] boot: add single quotes when printing boot target names Sascha Hauer
2016-07-22 12:44 ` [PATCH 16/18] boot command: Explicitly complain when boot target list is empty Sascha Hauer
2016-07-22 12:44 ` [PATCH 17/18] blspec: Turn message back to debug level Sascha Hauer
2016-07-22 12:44 ` [PATCH 18/18] boot: Print a message when a boot target string does not lead to a boot target Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox