mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] blspec: allow devicetree-overlay to be specified multiple times
@ 2026-10-15 14:06 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2026-10-15 14:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-15 14:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15 14:06 [PATCH] blspec: allow devicetree-overlay to be specified multiple times Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox