mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Christian Eggers <ceggers@arri.de>
To: barebox@lists.infradead.org
Cc: Christian Eggers <ceggers@arri.de>, ceggers@gmx.de
Subject: [RFC PATCH] bootm: Register as bootentry provider
Date: Mon, 27 Jan 2020 11:18:31 +0100	[thread overview]
Message-ID: <20200127101831.27601-1-ceggers@arri.de> (raw)
In-Reply-To: <20200127100711.wo2fwdq4o3cax3jl@pengutronix.de>

> Obviously anything involving shell scripts cannot work when no shell is
> enabled. I suggest using bootloader spec (CONFIG_BLSPEC) to boot a
> kernel. This works without shell support.

I would like to avoid using bootloader spec. The patch below works fine
for me. Do you think that this (or something similar) can be added to
barebox?


Support for "boot <device>". This is required for using bootchooser with
CONFIG_SHELL_NONE. In this case no boot scripts can be used, so the
device name of the flash partition containing the kernel image has to
provided.

Only enabled if CONFIG_BLSPEC is disabled.

Example: bootchooser.system0.boot=nand0.root.ubi.kernel0

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 common/bootm.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 366f31455..e880d3cab 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <boot.h>
 #include <bootm.h>
 #include <fs.h>
 #include <malloc.h>
@@ -721,6 +722,74 @@ err_out:
 	return ret;
 }
 
+#ifndef CONFIG_BLSPEC
+static int bootm_entry_boot(struct bootentry *entry, int verbose, int dryrun)
+{
+	struct bootm_data data = {};
+
+	bootm_data_init_defaults(&data);
+	data.os_file = entry->title;
+
+	return bootm_boot(&data);
+}
+
+static void bootm_release(struct bootentry *entry)
+{
+	free(entry);
+}
+
+/*
+ * bootm_scan_devicename - scan a hardware device for child cdevs
+ *
+ * Given a name of a hardware device this functions checks whether the device
+ * exists and add one booentries entry.
+ * Returns the number of entries found or a negative error code if some unexpected
+ * error occured.
+ */
+static int bootm_scan_devicename(struct bootentries *bootentries, const char *devname)
+{
+	struct cdev *cdev;
+
+	pr_debug("%s: %s\n", __func__, devname);
+
+	device_detect_by_name(devname);
+
+	cdev = cdev_by_name(devname);
+	if (cdev || get_device_by_name(devname)) {
+		struct bootentry *entry = xzalloc(sizeof(*entry));
+
+		entry->boot = bootm_entry_boot;
+		entry->release = bootm_release;
+		entry->title = basprintf("/dev/%s", devname);
+		entry->description = xstrdup(entry->title);
+
+		bootentries_add_entry(bootentries, entry);
+
+		return 1;
+	}
+
+	return -ENODEV;
+}
+
+static int bootm_bootentry_provider(struct bootentries *bootentries,
+				     const char *name)
+{
+	int ret, found = 0;
+
+	ret = bootm_scan_devicename(bootentries, name);
+	if (ret > 0)
+		found += ret;
+
+	return found;
+}
+#else   /* CONFIG_BLSPEC */
+static int bootm_bootentry_provider(struct bootentries *bootentries,
+				     const char *name)
+{
+	return 0;
+}
+#endif  /* CONFIG_BLSPEC */
+
 static int bootm_init(void)
 {
 	globalvar_add_simple("bootm.image", NULL);
@@ -742,7 +811,7 @@ static int bootm_init(void)
 	globalvar_add_simple_enum("bootm.verify", (unsigned int *)&bootm_verify_mode,
 				  bootm_verify_names, ARRAY_SIZE(bootm_verify_names));
 
-	return 0;
+	return bootentry_register_provider(bootm_bootentry_provider);
 }
 late_initcall(bootm_init);
 
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-01-27 10:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-20 16:38 Configuring for secure boot Christian Eggers
2020-01-20 19:53 ` Sascha Hauer
2020-01-21 10:52   ` Ahmad Fatoum
2020-01-21 11:11     ` Sascha Hauer
2020-01-23 10:29   ` Configuring for secure boot / Using bootchooser Christian Eggers
2020-01-27 10:07     ` Sascha Hauer
2020-01-27 10:18       ` Christian Eggers [this message]
2020-01-27 12:49         ` [RFC PATCH] bootm: Register as bootentry provider Sascha Hauer
2020-01-27 19:26           ` Christian Eggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200127101831.27601-1-ceggers@arri.de \
    --to=ceggers@arri.de \
    --cc=barebox@lists.infradead.org \
    --cc=ceggers@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox