From: David Gibson <david@gibson.dropbear.id.au>
To: Simon Glass <sjg@chromium.org>
Cc: Devicetree Compiler <devicetree-compiler@vger.kernel.org>,
Herve Codina <herve.codina@bootlin.com>
Subject: Re: [PATCH v3 15/18] dtc: Merge the fragments of a dts file in main()
Date: Mon, 16 Nov 2026 15:08:27 +1100 [thread overview]
Message-ID: <avqButGgNI9ohbBy@gractus.seuss> (raw)
In-Reply-To: <20261106195159.2623314-16-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 4897 bytes --]
On Fri, Nov 06, 2026 at 12:51:42PM -0700, Simon Glass wrote:
> We would like to run checks on each fragment of a dts file before it is
> merged, but that requires dt_from_source() to return the fragments
> unmerged, so that main() can decide what to do with them. At present
> they are merged at the end of the parse.
>
> Call merge_fragments() from main() instead, once the input is read. It
> does nothing for dtb or fs input, which has no fragments.
>
> When a reference cannot be resolved, dtc now reports 'Unable to merge
> input tree' rather than 'Syntax error parsing input tree', since the
> file was parsed successfully. Check for this message with
> test_label_ref.dts, since no test checks it at present.
>
> If the parser reports an error, dt_from_source() gives up before main()
> can merge the fragments. Merge them first in that case, so that any
> errors in the fragments are still reported. The merge-parse-error.dts
> test checks this, with a fragment which refers to a missing node,
> followed by a division by zero. Also check that dtc still gives up with
> 'Syntax error parsing input tree' in this case.
>
> Suggested-by: David Gibson <david@gibson.dropbear.id.au>
> Link: https://lore.kernel.org/devicetree-compiler/auK0ERvxGCJGSc3p@gractus.seuss/
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
This patch and the last are moving the merge in two stages. Is there
a specific reason for that, or could they be folded together?
> ---
>
> Changes in v3:
> - Check the final message when the parser finds an error
>
> Changes in v2:
> - Update for merge_fragments() returning true on success
>
> dtc-parser.y | 2 --
> dtc.c | 2 ++
> tests/run_tests.sh | 5 ++++-
> treesource.c | 5 ++++-
> 4 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 0ff04c7..33a0078 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -103,8 +103,6 @@ sourcefile:
> headers memreserves devicetree
> {
> parser_output = build_dt_info($1, $2, NULL, $3, 0);
> - if (!merge_fragments(parser_output))
> - treesource_error = true;
> }
> ;
>
> diff --git a/dtc.c b/dtc.c
> index e506837..73e5d76 100644
> --- a/dtc.c
> +++ b/dtc.c
> @@ -299,6 +299,8 @@ int main(int argc, char *argv[])
> else
> die("Unknown input format \"%s\"\n", inform);
>
> + if (!merge_fragments(dti))
> + die("Unable to merge input tree\n");
> dti->outname = outname;
>
> if (depfile) {
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 0aaa29c..8391717 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -741,7 +741,8 @@ dtc_tests () {
> run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb
> run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb "$SRCDIR/test_tree1_merge_path.dts"
> tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
> - run_wrap_error_test $DTC -I dts -O dtb -o /dev/null "$SRCDIR/test_label_ref.dts"
> + run_wrap_error_msg_test "Unable to merge input tree" \
> + $DTC -I dts -O dtb -o /dev/null "$SRCDIR/test_label_ref.dts"
>
> run_dtc_test -I dts -O dtb -o dtc_relref_merge.test.dtb "$SRCDIR/relref_merge.dts"
> run_test relref_merge dtc_relref_merge.test.dtb
> @@ -805,6 +806,8 @@ dtc_tests () {
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-parse-error.dts"
> run_wrap_error_msg_test "merge-parse-error.dts:15.12-15 Division by zero" \
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-parse-error.dts"
> + run_wrap_error_msg_test "Syntax error parsing input tree" \
> + $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-parse-error.dts"
>
> # A labelled reference to a node in a plugin adds the label to it
> run_dtc_test -@ -I dts -O dtb -o merge-labelled-plugin.test.dtb \
> diff --git a/treesource.c b/treesource.c
> index bf648bf..3fb9d83 100644
> --- a/treesource.c
> +++ b/treesource.c
> @@ -25,8 +25,11 @@ struct dt_info *dt_from_source(const char *fname)
> if (yyparse() != 0)
> die("Unable to parse input tree\n");
>
> - if (treesource_error)
> + if (treesource_error) {
> + /* Report any errors in the fragments as well, before giving up */
> + merge_fragments(parser_output);
Not really sure if this is worth it. It's not really *any* errors in
the fragments, just target errors and the like. I'm pretty
comfortable not getting to that if there are more basic syntax errors.
> die("Syntax error parsing input tree\n");
> + }
>
> return parser_output;
> }
> --
> 2.43.0
>
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-11-16 4:34 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 19:51 [PATCH v3 00/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-06 19:51 ` [PATCH v3 01/18] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-13 3:20 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 02/18] srcpos: Allow srcpos_string() to accept NULL Simon Glass
2026-11-11 4:56 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 03/18] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-13 3:46 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 04/18] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-13 3:49 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 05/18] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-13 3:50 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 06/18] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-13 3:55 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 07/18] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-13 3:58 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 08/18] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-13 4:01 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 09/18] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-13 4:09 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 10/18] dtc: Move labelled-reference " Simon Glass
2026-11-13 4:13 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 11/18] dtc: Move first-reference " Simon Glass
2026-11-13 4:19 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 12/18] dtc: Add merge_fragment() to merge any fragment Simon Glass
2026-11-13 4:24 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 13/18] dtc: Add helpers for the errors when merging a fragment Simon Glass
2026-11-16 3:49 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 14/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-16 4:04 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 15/18] dtc: Merge the fragments of a dts file in main() Simon Glass
2026-11-16 4:08 ` David Gibson [this message]
2026-11-06 19:51 ` [PATCH v3 16/18] dtc: Add the overlay fragments from merge_fragments() Simon Glass
2026-11-16 4:12 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 17/18] tests: Check references to a generated overlay fragment Simon Glass
2026-11-16 4:15 ` David Gibson
2026-11-06 19:51 ` [PATCH v3 18/18] dtc: Add the overlay fragments after merging a plugin Simon Glass
2026-11-16 4:34 ` David Gibson
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=avqButGgNI9ohbBy@gractus.seuss \
--to=david@gibson.dropbear.id.au \
--cc=devicetree-compiler@vger.kernel.org \
--cc=herve.codina@bootlin.com \
--cc=sjg@chromium.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