mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [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

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