I find the exact semantics of scanf() always confusing, and mostly we use
strtol() and similar functions instead. Switch fdtput to using strtol and
similar functions instead of sscanf().
As well as being more in keeping with what we do in other places, this
works around a FreeBSD bug[0], where sscanf(), but not strtol() parses
"003" as having value 0.
[0] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288440
Link: https://github.com/dgibson/dtc/issues/165
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Some of our testcases check fdtget retreiving string list properties that
include internal \0 characters. We use printf(1) to generate the expected
value for comparison.
However, on FreeBSD, printf(1)'s %b format option can't handle \0: it will
terminate that argument ignoring it and everything after. Curiously,
internal \0 *is* ok in the main format string. So avoid using %b and use
the format string directly instead.
Link: https:/https://github.com/dgibson/dtc/issues/165
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When a DTS is preprocessed, sometimes the user fails to include the
correct header files, or make a spelling mistake on a macro name. This
leads to a stray identifier in the DTS, like:
property = <1 2 FOO BAR(3, 4)>;
Give a more helpful error message than "syntax error" by recognizing and
reporting the identifier, like this:
Lexical error: <stdin>:2.21-24 Unexpected 'FOO'
Also, treat that identifier as literal, which often helps the parser go
further and may generate more helpful error messages.
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
If an I2C controller has a 'i2c-bus' child node, then the function
check_i2c_bus_bridge() does not detect this as expected and warnings
such as the following are observed:
Warning (i2c_bus_bridge): /example-0/i2c@7000c000: \
incorrect #address-cells for I2C bus
Warning (i2c_bus_bridge): /example-0/i2c@7000c000: \
incorrect #size-cells for I2C bus
These warnings occur because the '#address-cells' and '#size-cells' are
not directly present under the I2C controller node but the 'i2c-bus'
child node. The function check_i2c_bus_bridge() does not detect this
because it is using the parent node's 'basenamelen' and not the child
node's 'basenamelen' when comparing the child node name with 'i2c-bus'.
The parent node's 'basenamelen' is shorter ('i2c') than 'i2c-bus' and so
the strprefixeq() test fails. Fix this by using the child node
'basenamelen' when comparing the child node name.
Fixes: 53a1bd5469 ("checks: add I2C bus checks")
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Message-ID: <20250709142452.249492-1-jonathanh@nvidia.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The add_marker() function is used to create a new marker and add it at
the right spot to the relevant marker list. Use it in the
add_string_markers() helper (which gets slightly quicker by it).
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The documentation claims that `-c` would "Create nodes if they don't
already exist". This is true, but suggests that trying to create a node
that already exists is not an error. fdtput however errors out in that
case. Similar `fdtput -d` errors out when called for a non-existing
node.
Drop the "if they [don't] already exist" to make that clearer.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The file ending .dtbo is typically used for device tree overlays. These
are in the dtb input format, too. So assume this input format for *.dtbo
as is already done for *.dtb.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add helper function to insert a data struct into another.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20250605-previous-value-v3-2-0983d0733a07@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Allow projects that use dtc as a subproject to find the tools and
library via find_program() and dependency(). This way, for those
projects there is no different between system dtc and subproject dtc.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20250612053829.1037412-1-pbonzini@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
srcpos can be chained together using srcpos_extend. However, in such
cases, we need to free all the chained nodes.
srcpos_free is a helper to recursively free all the linked srcpos.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20250605-previous-value-v3-1-0983d0733a07@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
We get full build parallelism and fewer confusing ancient distutils
paths. The python wheels build fully standalone, including linking
libfdt as a static library.
For convenience, when running pip install a meson option is passed that
prevents building tools or installing headers/pkgconfig files.
meson-python would otherwise include them in the wheel itself, in case
they are needed, but this is essentially a bit useless so don't bother.
The old setuptools-based build is now redundant and goes away.
Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
Message-ID: <20250430152601.43554-3-eschwartz@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Building the python bindings is complicated and not very practical to do
in a Makefile. The setuptools invocations previously used are confusing
and don't work very well compared to Meson. Having two build systems
that do different things is also confusing though.
Since Meson can do everything that Make can do, but the reverse is not
true, we deprecate the latter and warn when you use it.
GNU Make can emit a $(warning) on every Makefile run, which is a bit
noisy but means we don't need to have every target depend on a PHONY
target (preventing built targets from being seen as up to date).
Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
Message-ID: <20250430152601.43554-2-eschwartz@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Both, Clang and GCC define __ASSEMBLER__ automatically when
compiling .S files, so this macro is a much better fit for
fdt.h - programs that want to use it from .S files don't have
to manually #define __ASSEMBLY__ that way.
While we're at it, also change it in testdata.h, then we don't
have to define __ASSEMBLY__ in the Makefile / meson.build file
anymore.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250313192718.1561683-1-thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Discovered with the "codespell" utility.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250313191607.1556384-1-thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Let's avoid repeating single words here!
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250313190527.1556019-1-thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Some packaging systems like NixOS don't support compiling static
libraries. However libfdt's meson.build uses `both_library()` which
forces the build to always compile shared and static libraries. Removing
`both_library()` will make packaging easier.
libfdt uses `both_libraries()` to support the 'static-build' option.
But we do not need the 'static-build' option as Meson can natively
build static using
> meson setup builddir/ -Dc_link_args='-static' --prefer-static --default-library=static
So drop 'static-build' and then replace `both_libraries()` with
`library()`.
Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
They are only used when running tests, and are included as depedencies
of the test cases themselves already. Marking them to not build by
default, means that 291 compile edges can be skipped when only running
```
meson setup builddir/
ninja -C builddir/
meson install -C builddir/
```
resulting in an overall much faster build. Instead they will be compiled
on-demand by `meson test`, only for users that actually run the tests.
Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
Message-ID: <20250302222839.2256985-1-eschwartz@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
For certain tests, we take the output from dtc -O asm and build it into
a .so shared library which we then dlopen() for further tests. Because we
don't mark it otherwise, it's treated as requiring an executable stack,
which dlopen() refuses to open as of glibc-2.41.
Of course, the library is pure data, no code, so it certainly doesn't need
an executable stack. Add the -znoexecstack linker option to avoid the
error.
Fixes: https://github.com/dgibson/dtc/issues/163
Reported-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: David Gibson <david@gibson.dropbear.id.a>
When the meta nodes __local_fixups__ and __fixups__ are generated, and
one of these (or both) already exist, the information contained there
is duplicated at best and stale otherwise. So remove the nodes before
starting to fill them.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Both current callers actually don't want deleted nodes returned by
get_subnode(). So change semantics of this function to only return
"live" nodes.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
build_root_node() does error checking (which is good!) but otherwise
behaves exactly as the code replaced here.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When configuring the project, meson fails with:
tests/meson.build:107:27: ERROR: Unknown variable "util_dep"
Declare the util_dep dependency regardless if 'tools' are enabled, so
tests can be built with it.
Fixes: bdc5c8793a ("meson: allow disabling tests")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The device tree specification (v0.4) suggests that #address-cells is
mandatory for interrupt parent nodes. If this property is missing, Linux
will default to the value of 0.
A number of device tree files rely on Linux' fallback and don't specify
an explicit #address-cells as suggested by the specification. This can
cause issues when these device trees are passed to software with a more
pedantic interpretation of the DT spec.
Add a warning when this case is detected so that device tree files can
be fixed.
Reported-by: Brad Griffis <bgriffis@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Message-ID: <20241213141438.3616902-1-thierry.reding@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Macro using fdt_setprop_namelen() internally similar to
`fdt_setprop_string()`.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20241205-setprop-namelen-v2-4-0d85a3d2e7b1@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Allow specifying name length in setprop similar to
`fdt_get_property_namelen` functions.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20241205-setprop-namelen-v2-3-0d85a3d2e7b1@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Similar to the non-namelen variant, it is implemented in terms of
fdt_get_property_namelen()
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20241205-setprop-namelen-v2-1-0d85a3d2e7b1@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add clang-format config based on Linux kernel clang-format config.
Allows for consistent formatting rules for all future contributions.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Message-ID: <20241205-clang-format-v2-1-07d21007bdab@beagleboard.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Do not fail the unnecessary #address-cells/#size-cells check if any
children of the node have a "ranges" property.
Suggested-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/all/CAL_JsqKebRL454poAYZ9i=sCsHqGzmocLy0psQcng-79UWJB-A@mail.gmail.com/
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Message-ID: <20241106130108.852323-1-p.zabel@pengutronix.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Building the dtc tests on the Conda build system results in the
following error.
> In function '__strtok_r_1c', 2024-11-23T19:17:20.7930512Z inlined from 'main' at ../tests/sw_tree1.c:140:17:
> $BUILD_PREFIX/x86_64-conda-linux-gnu/sysroot/usr/include/bits/string2.h:1177:10: error: 'saveptr' may be used uninitialized [-Werror=maybe-uninitialized]
> 1177 | while (*__s == __sep)
> | ^~~~
> ../tests/sw_tree1.c: In function 'main':
> ../tests/sw_tree1.c:137:39: note: 'saveptr' was declared here
> 137 | char *str = argv[2], *saveptr, *tok;
> | ^~~~~~~
> cc1: all warnings being treated as errors
The manpage `strtok(3)` says the following.
> VERSIONS
> On some implementations, *saveptr is required to be NULL on the first call to strtok_r() that is being used to parse str.
So set it to NULL.
Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
When our Python functions wrap `fdt_getprop()` they return a list
containing `[*data, length]`.
In SWIG v4.2 and earlier SWIG would discard `*data` if it is NULL/None.
Causing the return value to just be `length`.
But starting in SWIG v4.3 it no longer discards `*data`. So the return
value is now `[None, length]`.
Handle this compatibility issue in libfdt.i by checking if the return
value looks like the older 4.2 return value, and casting it to the newer
style.
See https://github.com/swig/swig/pull/2907
Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The Ubuntu runner fails with the following message
> E: The repository 'http://security.ubuntu.com/ubuntu mantic-security Release' does not have a Release file.
Ubuntu 23.10 is end-of-life as of July 2024 anyway. So switch to the
latest Ubuntu tag, which is currently 24.04.
See https://discourse.ubuntu.com/t/edubuntu-23-10-has-reached-end-of-life-eol/46325
Signed-off-by: Brandon Maier <brandon.maier@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When compiling with -Wall -Wextra, the unused fdt parameter becomes a
warning. With -Werror, it becomes an error and fails the build.
As the parameter is not used in the function, let's remove it.
Signed-off-by: Bingwu Zhang <xtexchooser@duck.com>
Message-ID: <20241123094814.15504-2-xtex@envs.net>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
I was mistaken, and another maintainer pointed out the author-of-this-file
metadata needs to be in a different place. Apologies for the churn.
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Improve supply chain security by including a SBOM file with substituted values.
This will be used to construct a composite platform SBOM.
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When compiling with -Werror -Wpedantic, both GCC and Clang fails, saying
that these semi-colons are redundant, so remove them.
Signed-off-by: Bingwu Zhang <xtexchooser@duck.com>
Message-ID: <20241116101228.164707-6-xtex@envs.net>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The swig generated code has a heap of warnings with the flags we usually
use. These aren't helpful, since there's nothing we can do about them from
the dtc side. So, just disable the warnings flags when compiling the
Python module.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This was added because trying to apply overlay on dtb without knowing a lot
about the subject can be frustrating with strange error messages.
Before this, it will tell you:
`Failed to apply 'overlay.dtbo': FDT_ERR_BADOFFSET`
This message is similar to what's shown in `u-boot` when
trying to apply overlay
Signed-off-by: Amjad Alsharafi <amjadsharafi10@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Swig has changed language specific AppendOutput functions. The helper
macro SWIG_AppendOutput remains unchanged. Use that instead
of SWIG_Python_AppendOutput, which would require an extra parameter
since swig 4.3.0.
| /home/flk/poky/build-hypr/tmp/work/x86_64-linux/python3-dtc-native/1.7.0/git/pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_next_node’:
| /home/flk/poky/build-hypr/tmp/work/x86_64-linux/python3-dtc-native/1.7.0/git/pylibfdt/libfdt_wrap.c:5598:17: error: too few arguments to function ‘SWIG_Python_AppendOutput’
| 5598 | resultobj = SWIG_Python_AppendOutput(resultobj, val);
Signed-off-by: Markus Volk <f_l_k@t-online.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This matches how Linux escapes spaces in paths.
The same syntax is also used by other build tools that output depfiles,
e.g. edd36eba5e/src/cargo/core/compiler/output_depinfo.rs (L19)
Signed-off-by: Colin Finck <mail@colinfinck.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
In these cases, spaces are used for indentation/alignment while the
surrounding lines use tab. Fix it up for consistency.
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Most of these are plain typos. Exceptions:
- "devicetree" is only used in that form in the grammar and in mailing
list references; all other instances, in particular all in prose,
use "device tree".
- I don't know what "nodeequested" was supposed to be, the sentence
reads just fine without it.
- "inexistant" is a rare form of nonexistent.
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Put this variable assignment next to the others. Pass it to
get_top_builddir() instead of relying on the global variable.
Signed-off-by: Simon Glass <sjg@chromium.org>
Message-ID: <20240811150248.7537-5-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Move most of the top-level code together, with the classes and functions
above, for easier reading.
The srcdir is left where it is for now.
Signed-off-by: Simon Glass <sjg@chromium.org>
Message-ID: <20240811150248.7537-4-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Do this processing in a function and return the result, to reduce the
amount of code at the top level.
Signed-off-by: Simon Glass <sjg@chromium.org>
Message-ID: <20240811150248.7537-3-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Resolve all the pylint warnings currently in setup.py
Signed-off-by: Simon Glass <sjg@chromium.org>
Message-ID: <20240811150248.7537-2-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
We don't need to support Python 2 anymore, so drop the comment and add
the minimum required version. Use version 3.8 since I am not sure that
it works on older versions and 3.7 has reached end-of-life.
Signed-off-by: Simon Glass <sjg@chromium.org>
Message-ID: <20240811150248.7537-1-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>