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 Reviewed-by: David Gibson > --- > > 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