From: David Gibson <david@gibson.dropbear.id.au>
To: Simon Glass <sjg@chromium.org>
Cc: Devicetree Compiler <devicetree-compiler@vger.kernel.org>
Subject: Re: [PATCH 3/5] fdtput: Suggest -p when a node is missing
Date: Wed, 28 Oct 2026 12:39:39 +1100 [thread overview]
Message-ID: <auFST7UJccNIHAIU@gractus.seuss> (raw)
In-Reply-To: <20261027120126.2613353-4-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 3311 bytes --]
On Tue, Oct 27, 2026 at 06:01:17AM -0600, Simon Glass wrote:
> When the node being written to does not exist, fdtput just prints
> FDT_ERR_NOTFOUND - nothing points to -p, which creates missing nodes, so
> it is easy to conclude that fdtput cannot add nodes at all.
>
> When creating a node with -c, the error also names the full path, even
> though it is the parent which is missing.
>
> Add a hint to use -p when a node is missing, both when writing a
> property and when creating a node. Report the parent path when it is
> the parent which is missing.
>
> Add tests that writing a property or creating a node fails when a parent
> node is missing and -p is not given.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>
> fdtput.c | 20 ++++++++++++++++++--
> tests/run_tests.sh | 4 ++++
> 2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/fdtput.c b/fdtput.c
> index 4094015..c9973d5 100644
> --- a/fdtput.c
> +++ b/fdtput.c
> @@ -47,6 +47,22 @@ static void report_error(const char *name, int namelen, int err)
> fdt_strerror(err));
> }
>
> +/**
> + * Report an error looking up a node which must exist before writing to it.
> + *
> + * If the node is missing, suggest -p, since it creates missing nodes.
> + *
> + * @param name Node name to report error on
> + * @param namelen Length of node name, or -1 to use entire string
> + * @param err Error number to report (-FDT_ERR_...)
> + */
> +static void report_node_error(const char *name, int namelen, int err)
> +{
> + report_error(name, namelen, err);
> + if (err == -FDT_ERR_NOTFOUND)
> + fprintf(stderr, "Use -p to create missing nodes\n");
> +}
> +
> /**
> * Encode a series of arguments in a property value.
> *
> @@ -182,7 +198,7 @@ static int store_key_value(char **blob, const char *node_name,
>
> node = fdt_path_offset(*blob, node_name);
> if (node < 0) {
> - report_error(node_name, -1, node);
> + report_node_error(node_name, -1, node);
> return -1;
> }
>
> @@ -284,7 +300,7 @@ static int create_node(char **blob, const char *node_name)
> node = fdt_path_offset(*blob, path);
> free(path);
> if (node < 0) {
> - report_error(node_name, -1, node);
> + report_node_error(node_name, p - node_name, node);
> return -1;
> }
> }
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 77f0a81..7254e53 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -962,6 +962,10 @@ fdtput_tests () {
> run_wrap_error_test $DTPUT $dtb -c /chosen
> run_wrap_error_test $DTPUT $dtb -c /chosen/son
>
> + # Missing nodes are not created without -p
> + run_wrap_error_test $DTPUT $dtb -c /blackadder/the-second
> + run_wrap_error_test $DTPUT $dtb /blackadder/the-second cost -ts high
> +
> # Automatic node creation
> run_wrap_test $DTPUT $dtb -cp /blackadder/the-second/turnip \
> /blackadder/the-second/potato
> --
> 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-10-28 1:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 12:01 [PATCH 0/5] fdtput: Make it clearer how to create nodes Simon Glass
2026-10-27 12:01 ` [PATCH 1/5] fdtput: Explain " Simon Glass
2026-10-27 12:01 ` [PATCH 2/5] fdtput: Follow an alias when creating nodes with -p Simon Glass
2026-10-28 1:34 ` David Gibson
2026-10-27 12:01 ` [PATCH 3/5] fdtput: Suggest -p when a node is missing Simon Glass
2026-10-28 1:39 ` David Gibson [this message]
2026-10-28 7:39 ` Simon Glass
2026-10-27 12:01 ` [PATCH 4/5] fdtput: Name the property when it cannot be deleted Simon Glass
2026-10-28 1:43 ` David Gibson
2026-10-27 12:01 ` [PATCH 5/5] fdtput: Correct the description of -t in the manual Simon Glass
2026-10-28 1:58 ` [PATCH 0/5] fdtput: Make it clearer how to create nodes 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=auFST7UJccNIHAIU@gractus.seuss \
--to=david@gibson.dropbear.id.au \
--cc=devicetree-compiler@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.