mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andreas Schmidt <mail@schmidt-andreas.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2] blspec: add checking of optional key machine-id
Date: Wed,  2 May 2018 15:23:56 +0200	[thread overview]
Message-ID: <20180502132356.4207-1-mail@schmidt-andreas.de> (raw)
In-Reply-To: <20180502110214.zsdcwbt3qdgy2y7u@pengutronix.de>

For filtering of Bootloader Spec entries, Bootloader Spec
specify an optional key machine-id. By set the
global.boot.machine-id variable the checking of machine-id
key in Bootloader Spec entries will be activate. If the
variable and key match, appropriate boot entry will be
booting. If it not match boot entry will be ignore and
barebox check the next boot entry.

Signed-off-by: Andreas Schmidt <mail@schmidt-andreas.de>
---

Changes since v1:
  - change pr_info to pr_debug in case of missmatching this machine-id
  - print both machine-ids in debug message

Hi Sascha,
yes you are right. The message has to be improve for better understanding.
I oriented me on device-tree compatibility and used the equal message.

While improving I realised, that my decision to use pr_info was not very well.
Because, in case of device-tree compatibility the usual case is matching. 
But in case of Bootloader Spec entries with machine-id only one of X entries
will/shuld match usaully. Bootloader would print some unnecessary info messages
each boot.

I changed the output to pr_debug, to avoid unnecessary outputs while normal
booting. And I add both machine ids to the message to make debuging easier.

Regards,
Andreas
---
 Documentation/user/booting-linux.rst |  6 ++++++
 common/blspec.c                      | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/Documentation/user/booting-linux.rst b/Documentation/user/booting-linux.rst
index b5e4320ef..408f87d8e 100644
--- a/Documentation/user/booting-linux.rst
+++ b/Documentation/user/booting-linux.rst
@@ -212,6 +212,12 @@ The entry can be listed with the -l option:
 When on barebox the SD card shows up as ``mmc1`` then this entry can be booted with
 ``boot mmc1`` or with setting ``global.boot.default`` to ``mmc1``.
 
+``machine-id`` is an optional key. If ``global.boot.machine_id`` variable is set to
+non-empty value, then barebox accepts only Bootloader Spec entries with ``machine-id``
+key. In case if value of global variable and Bootloader Spec key match each other,
+barebox will choose the boot entry for booting. All other Bootloader Spec entries will
+be ignored.
+
 A bootloader spec entry can also reside on an NFS server in which case a RFC2224
 compatible NFS URI string must be passed to the boot command:
 
diff --git a/common/blspec.c b/common/blspec.c
index 6171461a7..2c682e199 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -419,6 +419,30 @@ out:
 	return ret;
 }
 
+/*
+ * entry_is_match_machine_id - check if a bootspec entry is match with
+ *                            the machine id given by global variable.
+ *
+ * returns true if the entry is match, false otherwise
+ */
+
+static bool entry_is_match_machine_id(struct blspec_entry *entry)
+{
+	int ret = true;
+	const char *env_machineid = getenv_nonempty("global.boot.machine_id");
+
+	if (env_machineid) {
+		const char *machineid = blspec_entry_var_get(entry, "machine-id");
+		if (!machineid || strcmp(machineid, env_machineid)) {
+			pr_debug("ignoring entry with missmatched machine-id " \
+				"\"%s\" != \"%s\"\n", env_machineid, machineid);
+			ret = false;
+		}
+	}
+
+	return ret;
+}
+
 /*
  * blspec_scan_directory - scan over a directory
  *
@@ -504,6 +528,11 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
 			continue;
 		}
 
+		if (!entry_is_match_machine_id(entry)) {
+			blspec_entry_free(&entry->entry);
+			continue;
+		}
+
 		found++;
 
 		if (entry->cdev && entry->cdev->dev) {
@@ -756,4 +785,4 @@ static int blspec_init(void)
 {
 	return bootentry_register_provider(blspec_bootentry_provider);
 }
-device_initcall(blspec_init);
\ No newline at end of file
+device_initcall(blspec_init);
-- 
2.14.1


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

  reply	other threads:[~2018-05-02 13:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-29 16:01 [PATCH] " Andreas Schmidt
2018-05-02 11:02 ` Sascha Hauer
2018-05-02 13:23   ` Andreas Schmidt [this message]
2018-05-08  6:13     ` [PATCH v2] " Sascha Hauer
2018-05-02 14:32 ` [PATCH] " Jan Lübbe
2018-05-03  8:42   ` Andreas Schmidt
2018-05-03  9:34     ` Jan Lübbe
2018-05-03 15:31       ` Andreas Schmidt

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=20180502132356.4207-1-mail@schmidt-andreas.de \
    --to=mail@schmidt-andreas.de \
    --cc=barebox@lists.infradead.org \
    /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