Devicetree Compiler
 help / color / mirror / Atom feed
* [PATCH v4 00/10] dtc: Move the merging of fragments out of the grammar
@ 2026-11-16 23:57 Simon Glass
  2026-11-16 23:57 ` [PATCH v4 01/10] tests: Check how the fragments of a dts file are merged Simon Glass
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Simon Glass @ 2026-11-16 23:57 UTC (permalink / raw)
  To: Devicetree Compiler; +Cc: David Gibson, Herve Codina, Simon Glass

Note: This v4 series now 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 top-level fragment of a dts file into the tree as
soon as it is parsed, so nothing can look at a fragment on its own. Here
a fragment is a top-level part of the source, 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
  fragment, but silently overwrites when it is in a later fragment
- 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 fragment 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 fragment in a new struct
fragment. The next series will have the parser return a list of
fragments 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 fragment which adds a label is reported at
the reference rather than the label.

Most of the merge errors have no tests, so the series starts by adding a
test for each one, checking the message and its position in the source.
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 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 merge-parse-error.dts and merge-overlay-order.dts
- Drop the checks that later fragments are merged after an error
- 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()
- Move the &{label} tests to the patch which changes its behaviour
- Report the label-relative error at the reference, not the label
- Shorten the comment on struct fragment
- Use 0 rather than '\0' in memset()
- Use a label outside the plugin in the label-relative tests

Changes in v3:
- Add merge-overlay-order.dts to check deletes and order with fragments
- Change the subject, since the tests are not only for errors

Changes in v2:
- Add a constructor for each kind of fragment, taking all its fields
- Add merge-label-base.dts to check a label which is not in the plugin
- Add merge-label-braces.dts to check &{label} in a plugin
- Add merge-label-order.dts to check the order of &{label} and &label
- Add merge-root-plugin.dts to check / { ... } against &{/} { ... }
- 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()
- Reword four comments in the test files
- Use a NULL ref for the root node
- Use dt_ref instead of fragment_ref

Simon Glass (10):
  tests: Check how the fragments of a dts file are merged
  dtc: Add a struct for the top-level fragments 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 is_ref_relative() to livetree.c
  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                       |  96 +++++-----------
 dtc.h                              |  37 +++++++
 livetree.c                         | 170 +++++++++++++++++++++++++++++
 tests/merge-delete-missing.dts     |   9 ++
 tests/merge-errors.dts             |  14 +++
 tests/merge-first-ref-relative.dts |   7 ++
 tests/merge-first-ref.dts          |   6 +
 tests/merge-label-base.dts         |  10 ++
 tests/merge-label-braces.dts       |  12 ++
 tests/merge-label-order.dts        |  17 +++
 tests/merge-labelled-plugin.dts    |  12 ++
 tests/merge-labelled-relative.dts  |  10 ++
 tests/merge-omit-missing.dts       |   9 ++
 tests/merge-path-ref-missing.dts   |  11 ++
 tests/merge-path-relative.dts      |  10 ++
 tests/merge-root-plugin.dts        |  12 ++
 tests/run_tests.sh                 |  59 ++++++++++
 17 files changed, 433 insertions(+), 68 deletions(-)
 create mode 100644 tests/merge-delete-missing.dts
 create mode 100644 tests/merge-errors.dts
 create mode 100644 tests/merge-first-ref-relative.dts
 create mode 100644 tests/merge-first-ref.dts
 create mode 100644 tests/merge-label-base.dts
 create mode 100644 tests/merge-label-braces.dts
 create mode 100644 tests/merge-label-order.dts
 create mode 100644 tests/merge-labelled-plugin.dts
 create mode 100644 tests/merge-labelled-relative.dts
 create mode 100644 tests/merge-omit-missing.dts
 create mode 100644 tests/merge-path-ref-missing.dts
 create mode 100644 tests/merge-path-relative.dts
 create mode 100644 tests/merge-root-plugin.dts

---
base-commit: 774adc25940050fb06f241b1a2a98e7421e6ed7b
branch: dt-forest4

-- 
2.43.0


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

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

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 23:57 [PATCH v4 00/10] dtc: Move the merging of fragments out of the grammar Simon Glass
2026-11-16 23:57 ` [PATCH v4 01/10] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-25  0:34   ` David Gibson
2026-11-25  6:42     ` David Gibson
2026-11-16 23:57 ` [PATCH v4 02/10] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-25  0:44   ` David Gibson
2026-11-16 23:57 ` [PATCH v4 03/10] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-25  0:48   ` David Gibson
2026-11-16 23:57 ` [PATCH v4 04/10] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-25  1:15   ` David Gibson
2026-11-16 23:57 ` [PATCH v4 05/10] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-25  1:16   ` David Gibson
2026-11-16 23:58 ` [PATCH v4 06/10] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-25  6:12   ` David Gibson
2026-11-16 23:58 ` [PATCH v4 07/10] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-25  6:16   ` David Gibson
2026-11-16 23:58 ` [PATCH v4 08/10] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-25  6:18   ` David Gibson
2026-11-16 23:58 ` [PATCH v4 09/10] dtc: Move labelled-reference " Simon Glass
2026-11-25  6:21   ` David Gibson
2026-11-16 23:58 ` [PATCH v4 10/10] dtc: Move first-reference " Simon Glass
2026-11-25  6:24   ` David Gibson

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