* [PATCH 1/4] boot: Allow to register boot entry providers
@ 2017-04-06 8:49 Sascha Hauer
2017-04-06 8:49 ` [PATCH 2/4] blspec: register as bootentry provider Sascha Hauer
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-04-06 8:49 UTC (permalink / raw)
To: Barebox List
bootentry_create_from_name() takes a name and creates bootentries
for it. It tries different providers that interpret the name:
blspec, bootchooser or script pathes. Instead of hardcoding the
different providers in the function, allow the providers to register
themselves.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/boot.c | 26 ++++++++++++++++++++++++++
include/boot.h | 2 ++
2 files changed, 28 insertions(+)
diff --git a/common/boot.c b/common/boot.c
index 4306319331..f0359cff38 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -244,6 +244,25 @@ static int bootscript_scan_path(struct bootentries *bootentries, const char *pat
return ret;
}
+static LIST_HEAD(bootentry_providers);
+
+struct bootentry_provider {
+ int (*fn)(struct bootentries *bootentries, const char *name);
+ struct list_head list;
+};
+
+int bootentry_register_provider(int (*fn)(struct bootentries *bootentries, const char *name))
+{
+ struct bootentry_provider *p;
+
+ p = xzalloc(sizeof(*p));
+ p->fn = fn;
+
+ list_add_tail(&p->list, &bootentry_providers);
+
+ return 0;
+}
+
/*
* bootentry_create_from_name - create boot entries from a name
*
@@ -261,6 +280,7 @@ static int bootscript_scan_path(struct bootentries *bootentries, const char *pat
int bootentry_create_from_name(struct bootentries *bootentries,
const char *name)
{
+ struct bootentry_provider *p;
int found = 0, ret;
if (IS_ENABLED(CONFIG_BLSPEC)) {
@@ -275,6 +295,12 @@ int bootentry_create_from_name(struct bootentries *bootentries,
}
}
+ list_for_each_entry(p, &bootentry_providers, list) {
+ ret = p->fn(bootentries, name);
+ if (ret > 0)
+ found += ret;
+ }
+
if (IS_ENABLED(CONFIG_BOOTCHOOSER) && !strcmp(name, "bootchooser")) {
ret = bootchooser_create_bootentry(bootentries);
if (ret > 0)
diff --git a/include/boot.h b/include/boot.h
index a855cbe1e5..4f7612ab80 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -36,6 +36,8 @@ struct bootentry {
int bootentries_add_entry(struct bootentries *entries, struct bootentry *entry);
+int bootentry_register_provider(int (*fn)(struct bootentries *bootentries, const char *name));
+
#define bootentries_for_each_entry(bootentries, entry) \
list_for_each_entry(entry, &bootentries->entries, list)
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/4] blspec: register as bootentry provider
2017-04-06 8:49 [PATCH 1/4] boot: Allow to register boot entry providers Sascha Hauer
@ 2017-04-06 8:49 ` Sascha Hauer
2017-04-06 8:49 ` [PATCH 3/4] bootchooser: " Sascha Hauer
2017-04-06 8:49 ` [PATCH 4/4] bootchooser: export bootchooser_boot Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-04-06 8:49 UTC (permalink / raw)
To: Barebox List
Instead of using a global function called by
bootentry_create_from_name(), register blspec as bootentry
provider.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/blspec.c | 24 ++++++++++++++++++++++++
common/boot.c | 12 ------------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/common/blspec.c b/common/blspec.c
index ec63ddb407..8132d141ab 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -732,3 +732,27 @@ int blspec_scan_devicename(struct bootentries *bootentries, const char *devname)
return blspec_scan_device(bootentries, dev);
}
+
+static int blspec_bootentry_provider(struct bootentries *bootentries,
+ const char *name)
+{
+ int ret, found = 0;
+
+ ret = blspec_scan_devicename(bootentries, name);
+ if (ret > 0)
+ found += ret;
+
+ if (*name == '/' || !strncmp(name, "nfs://", 6)) {
+ ret = blspec_scan_directory(bootentries, name);
+ if (ret > 0)
+ found += ret;
+ }
+
+ return found;
+}
+
+static int blspec_init(void)
+{
+ return bootentry_register_provider(blspec_bootentry_provider);
+}
+device_initcall(blspec_init);
\ No newline at end of file
diff --git a/common/boot.c b/common/boot.c
index f0359cff38..3280ac4f54 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -283,18 +283,6 @@ int bootentry_create_from_name(struct bootentries *bootentries,
struct bootentry_provider *p;
int found = 0, ret;
- if (IS_ENABLED(CONFIG_BLSPEC)) {
- ret = blspec_scan_devicename(bootentries, name);
- if (ret > 0)
- found += ret;
-
- if (*name == '/' || !strncmp(name, "nfs://", 6)) {
- ret = blspec_scan_directory(bootentries, name);
- if (ret > 0)
- found += ret;
- }
- }
-
list_for_each_entry(p, &bootentry_providers, list) {
ret = p->fn(bootentries, name);
if (ret > 0)
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/4] bootchooser: register as bootentry provider
2017-04-06 8:49 [PATCH 1/4] boot: Allow to register boot entry providers Sascha Hauer
2017-04-06 8:49 ` [PATCH 2/4] blspec: register as bootentry provider Sascha Hauer
@ 2017-04-06 8:49 ` Sascha Hauer
2017-04-06 8:49 ` [PATCH 4/4] bootchooser: export bootchooser_boot Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-04-06 8:49 UTC (permalink / raw)
To: Barebox List
Instead of using a global function called by
bootentry_create_from_name(), register the bootchooser as bootentry
provider.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/boot.c | 6 ------
common/bootchooser.c | 11 +++++++++--
include/bootchooser.h | 2 --
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/common/boot.c b/common/boot.c
index 3280ac4f54..cef3d5e514 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -289,12 +289,6 @@ int bootentry_create_from_name(struct bootentries *bootentries,
found += ret;
}
- if (IS_ENABLED(CONFIG_BOOTCHOOSER) && !strcmp(name, "bootchooser")) {
- ret = bootchooser_create_bootentry(bootentries);
- if (ret > 0)
- found += ret;
- }
-
if (!found) {
char *path;
diff --git a/common/bootchooser.c b/common/bootchooser.c
index 9c110f267e..f2174a1348 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -863,10 +863,14 @@ static void bootchooser_release(struct bootentry *entry)
*
* Return: The number of entries added to the list
*/
-int bootchooser_create_bootentry(struct bootentries *entries)
+static int bootchooser_add_entry(struct bootentries *entries, const char *name)
{
- struct bootchooser *bc = bootchooser_get();
+ struct bootchooser *bc;
+
+ if (strcmp(name, "bootchooser"))
+ return 0;
+ bc = bootchooser_get();
if (IS_ERR(bc))
return PTR_ERR(bc);
@@ -904,6 +908,9 @@ static int bootchooser_init(void)
reset_attempts_names, ARRAY_SIZE(reset_attempts_names));
globalvar_add_simple_bitmask("bootchooser.reset_priorities", &reset_priorities,
reset_priorities_names, ARRAY_SIZE(reset_priorities_names));
+
+ bootentry_register_provider(bootchooser_add_entry);
+
return 0;
}
device_initcall(bootchooser_init);
diff --git a/include/bootchooser.h b/include/bootchooser.h
index c948247722..246258e8c9 100644
--- a/include/bootchooser.h
+++ b/include/bootchooser.h
@@ -19,8 +19,6 @@ struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootch
const char *name);
void bootchooser_target_force_boot(struct bootchooser_target *target);
-int bootchooser_create_bootentry(struct bootentries *entries);
-
int bootchooser_target_set_attempts(struct bootchooser_target *target, int attempts);
int bootchooser_target_set_priority(struct bootchooser_target *target, int priority);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 4/4] bootchooser: export bootchooser_boot
2017-04-06 8:49 [PATCH 1/4] boot: Allow to register boot entry providers Sascha Hauer
2017-04-06 8:49 ` [PATCH 2/4] blspec: register as bootentry provider Sascha Hauer
2017-04-06 8:49 ` [PATCH 3/4] bootchooser: " Sascha Hauer
@ 2017-04-06 8:49 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-04-06 8:49 UTC (permalink / raw)
To: Barebox List
Some boards that boot directly from C code do already know that
they want to boot from bootchooser and nothing else. For these
it's easiest to call bootchooser_boot directly, so export this
function.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/bootchooser.c | 19 ++++++++++++-------
include/bootchooser.h | 2 ++
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/common/bootchooser.c b/common/bootchooser.c
index f2174a1348..455f290fa2 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -827,15 +827,10 @@ out:
return ret;
}
-static int bootchooser_boot(struct bootentry *entry, int verbose, int dryrun)
+int bootchooser_boot(struct bootchooser *bc)
{
- struct bootchooser *bc = container_of(entry, struct bootchooser,
- entry);
int ret, tryagain;
- bc->verbose = verbose;
- bc->dryrun = dryrun;
-
do {
ret = bootchooser_boot_one(bc, &tryagain);
@@ -846,6 +841,16 @@ static int bootchooser_boot(struct bootentry *entry, int verbose, int dryrun)
return ret;
}
+static int bootchooser_entry_boot(struct bootentry *entry, int verbose, int dryrun)
+{
+ struct bootchooser *bc = container_of(entry, struct bootchooser,
+ entry);
+ bc->verbose = verbose;
+ bc->dryrun = dryrun;
+
+ return bootchooser_boot(bc);
+}
+
static void bootchooser_release(struct bootentry *entry)
{
struct bootchooser *bc = container_of(entry, struct bootchooser,
@@ -874,7 +879,7 @@ static int bootchooser_add_entry(struct bootentries *entries, const char *name)
if (IS_ERR(bc))
return PTR_ERR(bc);
- bc->entry.boot = bootchooser_boot;
+ bc->entry.boot = bootchooser_entry_boot;
bc->entry.release = bootchooser_release;
bc->entry.title = xstrdup("bootchooser");
bc->entry.description = xstrdup("bootchooser");
diff --git a/include/bootchooser.h b/include/bootchooser.h
index 246258e8c9..7822c01459 100644
--- a/include/bootchooser.h
+++ b/include/bootchooser.h
@@ -13,6 +13,8 @@ int bootchooser_put(struct bootchooser *bootchooser);
void bootchooser_info(struct bootchooser *bootchooser);
+int bootchooser_boot(struct bootchooser *bc);
+
struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bootchooser);
const char *bootchooser_target_name(struct bootchooser_target *target);
struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootchooser,
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-04-06 8:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 8:49 [PATCH 1/4] boot: Allow to register boot entry providers Sascha Hauer
2017-04-06 8:49 ` [PATCH 2/4] blspec: register as bootentry provider Sascha Hauer
2017-04-06 8:49 ` [PATCH 3/4] bootchooser: " Sascha Hauer
2017-04-06 8:49 ` [PATCH 4/4] bootchooser: export bootchooser_boot Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox