lopper: generate Zephyr board.overlay from SDT folder - #790
Conversation
|
@kedareswararao: please review the changes |
| Scenario 2: board + user DTS -> filter board, append user unchanged | ||
| Scenario 3: user DTS only -> copy user content unchanged | ||
| """ | ||
| sdt_folder = resolve_sdt_folder(options, sdt) |
There was a problem hiding this comment.
Here we should support legacy use case as well where users pass the board dts instead of sdt folder
There was a problem hiding this comment.
Acknowledged. I will add backward compatibility
| print(f"[INFO] Generated board.overlay from filtered '{os.path.basename(board_dtsi)}' and user '{os.path.basename(user_zephyr_dtsi)}'.") | ||
| elif board_dtsi: | ||
| overlay_parts.append( | ||
| process_overlay_with_lopper_api( |
There was a problem hiding this comment.
This process_overlay_with_lopper_api() uses pure python calls recently Bruce added support for handling this kind of use cases in lopper frontend can you see whether we can remove the python API's and replace it with lopper API's
There was a problem hiding this comment.
I reviewed the Lopper overlay frontend APIs, but they are designed for true Device Tree overlays that are merged into the SDT tree. In contrast, our Zephyr board use cases rely on .dtsi include fragments containing both root-level blocks and node-specific sections. The reference validation logic already uses the Lopper tree APIs, and the remaining text-filtering functionality does not have a direct equivalent in the overlay frontend APIs. Therefore, we chose to retain this helper implementation.
790a565 to
a20f706
Compare
kedareswararao
left a comment
There was a problem hiding this comment.
Changes looks fine to me
|
Thanks for the work here. Before this lands I'd like to redirect the overlay handling, because the current approach re-implements a large amount of what lopper core (and dtc) already do, with text processing that will be fragile to maintain. What lopper core already does with A
In fact a Where this PR duplicates that
That's several hundred lines duplicating the compiler and lopper's resolver, and text/brace/regex handling of DTS will break on the first fragment that doesn't match the assumed formatting. The root problem is that these Path forward — step 1: include + compile Keep taking the fragment as an assist argument — the invocation doesn't need to change. The fix is what the assist does with it: hand it to the compiler instead of parsing it. Compose the base + fragment and compile (note import os, shutil
from lopper import Lopper
from lopper.tree import LopperTree
system_top = os.path.join(sdt_folder, "system-top.dts")
# compose base + fragment into one source, then compile it
combined_src = os.path.join(sdt.outdir, "_board_combined.dts")
with open(combined_src, "wb") as out:
for src in (system_top, board_dtsi):
with open(src, "rb") as f:
shutil.copyfileobj(f, out)
compiled, _ = Lopper.dt_compile(combined_src, "", "", True,
sdt.outdir, sdt.save_temps)
combined = LopperTree()
combined.load(Lopper.export(Lopper.dt_to_fdt(compiled)))
# combined = base + fragment, fully resolved by core:
# &label refs resolved, unresolved phandle refs dropped on write,
# an undefined label is a hard compile error. No regex, no
# __symbols__ walking, no brace-counting.(Equivalently, register the fragment into the SDT's input files so Step 2 depends on one question about the Zephyr side What consumes
Could you confirm the Zephyr consumption? That decides between "emit the combined tree" and "emit a computed delta," and either way the hand-rolled parsing should come out. (+1 to keeping the legacy single-file path working.) |
|
@zeddii : Thanks for the suggestion combined dt also works for zephyr consumption |
Merge board and user Zephyr DTSI content into the domain tree instead of emitting a separate board.overlay file. Use lopper plugin compile for &label fragments and merge root /aliases and /chosen nodes with fragment path rewriting so board aliases such as eeprom-0 appear in the final DTS. Signed-off-by: Bingi Dinesh kumar <dineshkumar.bingi@amd.com>
Add pytest coverage for SDT-folder board/user DTSI discovery and combined domain-tree merge paths in zephyr_board_dt. Signed-off-by: Bingi Dinesh kumar <dineshkumar.bingi@amd.com>
a20f706 to
01ae994
Compare
|
@zeddii, Step 1: I switched to the lopper compile/include path instead of regex.
Step 2: I split out overlay vs. combined board DT.
|
|
Thanks -- good progress, and glad the combined DT works for the Zephyr side. On the missing-label question: default should be an error. dtc won't build a plain If we do want lopper to tolerate an unresolved label in the include/compile path, wire it to the existing Net: default = hard error; intentional optional refs = overlay; |
|
A clarification / correction to my
And that conversion has a hard cost, because the two dtc models are complementary, not superset/subset:
So the two capabilities are mutually exclusive:
No single fragment gets both. So the real per-fragment question is: does it need to remove base content, or reference optional IP that may be absent? It can't do both, and |
|
@zeddii : The board dts contains all possible board-related information, such as the Ethernet node, flash info, eeprom info, and similar details. The purpose of passing this file to lopper assist is that, if a given design does not include Ethernet, the assist logic should remove the Ethernet node references from the user-provided board dts and, if needed, return an informational or warning message indicating that the relevant nodes were deleted because they are not mapped in the design. I hope this clarifies the use case; if not, please let me know and I’ll be happy to clarify further. CC: @sivadur @dbingi-amd |
SDTGEN now copies Zephyr board fragments into the SDT output folder as sidecar .dtsi files ({board}_zephyr.dtsi and optional user input via -user_zephyr_dts), instead of passing a single board .dts file to lopper.
This PR adds SDT-folder-based discovery and board.overlay generation in lopper, and replaces the old single-file overlay handling in gen_domain_dts. A follow-up commit adds pytest unit tests to validate discovery rules and all three overlay flows
• Add discover_zephyr_board_files() to find {board}_zephyr.dtsi and user .dtsi files.
• Treat user DTSI as any other .dtsi not #included from system-top.dts.
• Add generate_board_overlay_from_sdt() for board-only, board+user, and user-only flows.
• Filter board overlay against the SDT tree; append user overlay unchanged when present.
• Update gen_domain_dts.py to call the new helper instead of reading one board file.
• Add tests/test_zephyr_board_overlay.py for discovery and overlay generation unit tests