mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] blspec: allow devicetree-overlay to be specified multiple times
Date: Thu, 15 Oct 2026 16:06:06 +0200	[thread overview]
Message-ID: <20261015140606.1181053-1-a.fatoum@pengutronix.de> (raw)

From: Ahmad Fatoum <a.fatoum@barebox.org>

So far, every devicetree-overlay line in a blspec entry replaced the
previous one, so only the overlays on the last line were applied.

The spec only describes a space-separated list on a single line, but
systemd's bootctl accumulates repeated devicetree-overlay keys like it
does for options. Let's do the same and append the overlays of each
line in the order they are listed.

Add a test that chainloads barebox via a blspec entry with overlays
spread over two lines.

Assisted-by: Claude:opus-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/blspec.c        |  8 ++++--
 test/py/test_blspec.py | 65 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 test/py/test_blspec.py

diff --git a/common/blspec.c b/common/blspec.c
index 7802574880b5..ee2cf052f512 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -257,9 +257,11 @@ static struct blspec_entry *blspec_entry_open(struct bootentries *bootentries,
 
 		val = end;
 
-		if (!strcmp(name, "options")) {
-			/* If there was a previous "options" key given, prepend its value
-			 * (as per spec). */
+		if (!strcmp(name, "options") ||
+		    !strcmp(name, "devicetree-overlay")) {
+			/* If there was a previous key of the same name given,
+			 * prepend its value (as per spec for options and like
+			 * systemd's bootctl for overlays). */
 			const char *prev_val = blspec_entry_var_get(entry, name);
 			if (prev_val) {
 				char *opts = xasprintf("%s %s", prev_val, val);
diff --git a/test/py/test_blspec.py b/test/py/test_blspec.py
new file mode 100644
index 000000000000..f1ab693069a0
--- /dev/null
+++ b/test/py/test_blspec.py
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import os
+import shutil
+import subprocess
+import pytest
+from pathlib import Path
+from .helper import of_get_property, skip_disabled
+
+
+OVERLAY = """/dts-v1/;
+/plugin/;
+
+&{{/chosen}} {{
+	barebox,blspec-overlay{n} = <0x1>;
+	barebox,blspec-overlay-last = <{n}>;
+}};
+"""
+
+ENTRY = """title blspec overlay test
+version 1
+linux /barebox-dt-2nd.img
+devicetree-overlay /overlay1.dtbo /overlay2.dtbo
+devicetree-overlay /overlay3.dtbo
+"""
+
+
+@pytest.fixture(scope="module")
+def blspec_entry(barebox_config, testfs):
+    skip_disabled(barebox_config, "CONFIG_BLSPEC", "CONFIG_OF_OVERLAY")
+
+    builddir = Path(os.environ['LG_BUILDDIR'])
+    rootdir = Path(testfs) / "blspec"
+    entries = rootdir / "loader" / "entries"
+    entries.mkdir(parents=True, exist_ok=True)
+
+    dtc = builddir / "scripts" / "dtc" / "dtc"
+    try:
+        shutil.copy(builddir / "images" / "barebox-dt-2nd.img", rootdir)
+
+        for n in range(1, 4):
+            subprocess.run([dtc if dtc.exists() else "dtc",
+                            "-I", "dts", "-O", "dtb",
+                            "-o", str(rootdir / f"overlay{n}.dtbo")],
+                           input=OVERLAY.format(n=n).encode(), check=True)
+    except FileNotFoundError as e:
+        pytest.skip(f"Skip blspec tests due to missing dependency: {e}")
+
+    (entries / "overlays.conf").write_text(ENTRY)
+
+    return "/mnt/9p/testfs/blspec/loader/entries/overlays.conf"
+
+
+def test_blspec_overlays(barebox, strategy, blspec_entry):
+    _, _, returncode = barebox.run(f"ls {blspec_entry}")
+    if returncode != 0:
+        pytest.xfail("skipping test due to missing blspec entry")
+
+    with strategy.boot_barebox(blspec_entry) as barebox:
+        for n in range(1, 4):
+            assert of_get_property(barebox, f"/chosen/barebox,blspec-overlay{n}") == 0x1, \
+                   f"overlay{n}.dtbo listed in the blspec entry was not applied"
+
+        assert of_get_property(barebox, "/chosen/barebox,blspec-overlay-last") == 3, \
+               "overlays were not applied in the order they are listed"
-- 
2.47.3




                 reply	other threads:[~2026-10-15 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261015140606.1181053-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --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