Devicetree Compiler
 help / color / mirror / Atom feed
* [PATCH v5 00/10] dtc: Move the merging of source layers out of the grammar
@ 2026-11-26 18:40 Simon Glass
  2026-11-26 18:41 ` [PATCH v5 01/10] tests: Note that &{/} in a plugin is existing behaviour Simon Glass
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Simon Glass @ 2026-11-26 18:40 UTC (permalink / raw)
  To: Devicetree Compiler; +Cc: Herve Codina, David Gibson, Simon Glass

Note: As of v4, this series only moves the merge code. The merge still
happens during parsing, so none of the problems below are fixed yet.
Once this one is sorted out, a new series will be started.

The parser merges each source layer of a dts file into the tree as soon
as it is parsed, so nothing can look at a source layer on its own. Here
a source layer is a top-level part of a dts file, such as
&label { ... }; or /delete-node/ &label;, not an overlay's fragment@N
node.

This causes several problems:

- A repeated node or property name gives a check failure in the first
  source layer, but silently overwrites when it is in a later one
- Deletes cannot be dealt with consistently
- Checks which need the whole tree give false positives for a plugin,
  yet checks which do not need it cannot run before the merge

The ultimate aim is to run most checks on each source layer before it is
merged, and only those which need the whole tree afterwards. For this to
work, we need the merge to come after dt_from_source() and
build_dt_info() have returned.

As a first step, move the merge logic out of the grammar actions into
livetree.c, one action at a time, passing each source layer in a new
struct source_layer. The next series will have the parser return a list
of source layers for main() to merge, then add a plugin's overlay
fragments (fragment@N nodes) after the merge, rather than during it.

The output only changes for &{label} { ... } in a plugin, where label is
in the plugin itself, which is now merged in the same way as
&label { ... }. The only change to the errors is that, in a plugin, a
label-relative reference in a source layer which adds a label is
reported at the reference rather than the label.

The series starts with two small follow-ups to the merge tests, which
are now applied. At each commit, make check passes and dtc gives the
same output and messages for every .dts and .dtso file in Linux
v7.3-12284-g3799eeb906c9.

Changes in v5:
- Add new patch to check a label on a node which is not in a plugin
- Add new patch to comment on &{/} in a plugin
- Drop the merge tests and is_ref_relative() patches, which are applied
- Say that a label on a node outside the plugin is an error
- Use the term 'source layer' rather than 'fragment'

Changes in v4:
- Add the &{label} tests here, rather than in the first patch
- Drop build_fragment_root(), append_fragment() and the next pointer
- Drop label_srcpos, since the position of the reference is enough
- Drop the srcpos patch, which is applied
- Explain why a fragment which adds a label does not go in an overlay
- Free the fragment after merging it
- Leave the merge after parsing and the fragment@N changes for later
- Look up the reference once, at the top of merge_ref()
- Report the label-relative error at the reference, not the label
- Shorten the comment on struct fragment
- Use 0 rather than '\0' in memset()

Changes in v2:
- Add a constructor for each kind of fragment, taking all its fields
- Add new patch for &{label} in a plugin
- Add the list to struct dt_info later, when it is first used
- Build the fragment in one step, with build_fragment_ref()
- Change the subject from 'Add a list' to 'Add a struct'
- Check the fragment type with assert()
- Combine merge_labelled_ref() into merge_ref()
- Combine merge_path_ref() into merge_ref()
- Combine the rules for label and path references, using dt_ref
- Drop path_ref in favour of checking the ref for a leading '/'
- Explain the aim of the series and what it does not do
- Rename merge_label_ref() to merge_ref()
- Replace FRAGMENT_ROOT and FRAGMENT_REF with FRAGMENT_NODE
- Return true on success from merge_delete_node()
- Return true on success from merge_first_ref()
- Return true on success from merge_omit_if_no_ref()
- Return true on success from merge_ref()
- Use a NULL ref for the root node
- Use dt_ref instead of fragment_ref

Simon Glass (10):
  tests: Note that &{/} in a plugin is existing behaviour
  tests: Check a label on a node which is not in a plugin
  dtc: Add a struct for the source layers of a dts file
  dtc: Move the /delete-node/ handling out of the grammar
  dtc: Move the /omit-if-no-ref/ handling out of the grammar
  dtc: Move label-reference handling out of the grammar
  dtc: Merge &{label} in a plugin as with &label
  dtc: Move path-reference handling out of the grammar
  dtc: Move labelled-reference handling out of the grammar
  dtc: Move first-reference handling out of the grammar

 dtc-parser.y                     |  92 ++++++-----------
 dtc.h                            |  39 ++++++-
 livetree.c                       | 171 ++++++++++++++++++++++++++++++-
 tests/merge-label-braces.dts     |  12 +++
 tests/merge-label-order.dts      |  17 +++
 tests/merge-labelled-missing.dts |  14 +++
 tests/merge-root-plugin.dts      |   6 +-
 tests/run_tests.sh               |  18 +++-
 8 files changed, 302 insertions(+), 67 deletions(-)
 create mode 100644 tests/merge-label-braces.dts
 create mode 100644 tests/merge-label-order.dts
 create mode 100644 tests/merge-labelled-missing.dts

---
base-commit: b1816ff6721121d490a0d1d0a1e3743561e9232b
branch: dt-forest5

-- 
2.43.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-26 20:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 18:40 [PATCH v5 00/10] dtc: Move the merging of source layers out of the grammar Simon Glass
2026-11-26 18:41 ` [PATCH v5 01/10] tests: Note that &{/} in a plugin is existing behaviour Simon Glass
2026-11-26 18:41 ` [PATCH v5 02/10] tests: Check a label on a node which is not in a plugin Simon Glass
2026-11-26 18:41 ` [PATCH v5 03/10] dtc: Add a struct for the source layers of a dts file Simon Glass
2026-11-26 20:42   ` Herve Codina
2026-11-26 18:41 ` [PATCH v5 04/10] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-26 18:41 ` [PATCH v5 05/10] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-26 18:41 ` [PATCH v5 06/10] dtc: Move label-reference " Simon Glass
2026-11-26 18:41 ` [PATCH v5 07/10] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-26 18:41 ` [PATCH v5 08/10] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-26 18:41 ` [PATCH v5 09/10] dtc: Move labelled-reference " Simon Glass
2026-11-26 18:41 ` [PATCH v5 10/10] dtc: Move first-reference " Simon Glass

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