aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2024-05-01libfdt: overlay: Refactor overlay_fixup_phandleHEADmastermainZheng Guangyuan1-20/+20
Refactored overlay_fixup_phandle to optimize efficiency by moving the phandle lookup logic based on label outside the overlay_fixup_one_phandle call. This avoids redundant phandle lookups when a single label is associated with multiple modifications. Signed-off-by: Zheng Guangyuan <1628513611@qq.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-05-01libfdt: tests: Update test case for overlay_bad_fixupZheng Guangyuan1-1/+1
Changed the target DTS from overlay_base_no_symbols.test.dtb to overlay_base_manual_symbols.test.dtb. This ensures that the test case doesn't exit prematurely due to the absence of label-linked phandle in the symbols node. The update guarantees that the test case appropriately checks the validity of the fixup string linked to the label, as intended. Signed-off-by: Zheng Guangyuan <1628513611@qq.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-04-29tests: Remove two_roots and named_root from LIBTREE_TESTS_L and add all dtb ↵Zheng Guangyuan1-3/+4
filenames generated by dumptrees to TESTS_TREES_L in Makefile.tests These two binaries are not produced; two_roots.dtb and named_root.dtb are instead generated in TESTS_TREES. Redundant file entries eliminated and Ensures that all dtb filenames generated by dumptrees are now accounted for in the TEST_TREES, addressing previous omissions Signed-off-by: Zheng Guangyuan <1628513611@qq.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-22tests: fix tests broken under MesonBrandon Maier1-7/+7
Tests running under Meson run from a different working directory then under Makefile. Some of these tests had not been fixed to work from a different directory because the tests were testing for an error condition which is indistinguishable from a missing file. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-19github: enforce testing pylibfdt and yaml supportBrandon Maier1-3/+3
The Ubuntu runner was not building the yaml support as it's using Ubuntu 22 (jammy) which uses libyaml 0.2.2, but the build requires libyaml 0.2.3. Switch to Ubuntu 23 which has libyaml 0.2.5. This was not detected by the runner as the Yaml feature defaults to "auto" which turns off if it fails to find the dependency. In the runner force yaml to enabled so if it fails to build it will trigger a build failure. We also force python support for the same reason. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-19meson: split run-tests by typeBrandon Maier1-8/+23
Instead of running run-tests on all tests, split them down into the 9 separate run-tests test types. This provides better granularity of test results from the Meson test harness. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-19meson: fix dependencies of testsBrandon Maier3-10/+17
If the tests are run without a full compile they will fail. For example with the following. > rm -rf build/ > meson setup build/ > meson test -C build/ This is because the tests rely on the devicetree tools and test executables. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-19meson: fix pylibfdt missing dependency on libfdtBrandon Maier1-0/+1
The python library requires libfdt to build. This would intermittently fail depending on what order targets compiled. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-19pylibfdt: fix get_mem_rsv for newer Python versionsBrandon Maier1-7/+4
The test for get_mem_rsv fails on newer versions of Python with the following error. > Traceback (most recent call last): > File "/__w/dtc/dtc/tests/pylibfdt_tests.py", line 421, in testReserveMap > self.assertEqual([ 0xdeadbeef00000000, 0x100000], > AssertionError: Lists differ: [16045690981097406464, 1048576] != [0, 16045690981097406464, 1048576] > > First differing element 0: > 16045690981097406464 > 0 > > Second list contains 1 additional elements. > First extra element 2: > 1048576 > > - [16045690981097406464, 1048576] > + [0, 16045690981097406464, 1048576] > ? +++ It appears this is because the PyTuple_GET_SIZE() function that was used to build the fdt_get_mem_rsv() return value has changed. It now is returning a non-zero value when it's passed an integer, which causes the SWIG wrapper to append the returned arguments to the return error rather then ignore them. This is valid behaviour per Python's documentation, which says it will "Return the size of the tuple p, which must be non-NULL and point to a tuple; no error checking is performed"[1]. As passing an integer is not a tuple, its return value is undefined. Fix this issue on older and newer versions by avoiding PyTuple_GET_SIZE() entirely. Always append the arguments to the list, and instead use the wrapper python function to check the first argument and then splice the last two arguments as the return value. [1] https://docs.python.org/3/c-api/tuple.html#c.PyTuple_GET_SIZE Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-14libfdt: overlay: ensure that existing phandles are not overwrittenUwe Kleine-König4-0/+334
A phandle in an overlay is not supposed to overwrite a phandle that already exists in the base dtb as this breaks references to the respective node in the base. So add another iteration over the fdto that checks for such overwrites and fixes the fdto phandle's value to match the fdt's. A test is added that checks that newly added phandles and existing phandles work as expected. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Message-ID: <20240225175422.156393-2-u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06github: add windows/msys CI buildMarc-André Lureau1-0/+48
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06github: Don't accidentally suppress test errorsDavid Gibson1-1/+1
The last commit, displaying the meson testlog if we fail tests had the accidentaly side effect of not propagating the failure to show up properly in github's dashboard. Fix that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06github: Display meson test logs on failureDavid Gibson1-1/+1
Currently the way we integrate the existing tests into meson means meson test itself doesn't show any detailed logs of the failures, those just go to the meson testlog file. As a hack to see what's failing in CI builds, display that file if the tests fail. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06pylibfdt: Remove some apparently deprecated options from setup.pyDavid Gibson1-6/+0
We seem to get deprecation warnings because of these. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06github: Update to newer checkout actionDavid Gibson1-2/+2
We're getting deprecation warnings about the v3 one. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-03-06fix MinGW format attributeRosen Penev2-8/+3
Setting -D__USE_MINGW_ANSI_STDIO=1 is wrong and should not be used. MinGW internally uses a macro to select between gnu_printf and printf. Just use that instead of using a wrong format under clang backends. Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-02-23libfdt: Simplify adjustment of values for local fixupsDavid Gibson1-37/+15
In a couple of places in fdt_overlay.c we need to adjust a phandle value in a property (either a node's phandle itself or a reference) by some delta. Currently this is done if a fairly convoluted way, open-coding loading the value and handling of a non-aligned reference, and then using fdt_setprop_inplace_partial() to replace the value. This becomes much simpler if we use fdt_getprop_w() to get a writable pointer to the value then we can just load/store it with fdt32_{ld,st}(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-02-22libfdt: rework shared/static librariesRosen Penev1-12/+5
Instead of creating 2 libraries manualy, just call both_libraries and link to the appropriate one as requested. Fixes compilation when passing -Ddefault_libraries=both as the static_library name is duplicated. Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-02-14Makefile: do not hardcode the `install` program pathSamuel Tardieu1-1/+1
On systems that do not use the FHS, such as NixOS, the `install` program is not located in `/usr/bin/` as its location is dynamic. `dtc` can be easily installed on such systems by using the `install` program available in the `$PATH` with: make PREFIX=… INSTALL=install However, this becomes more difficult when `dtc` is being compiled as part of a larger toolchain, as the toolchain build scripts will not spontaneously pass such an argument on the command line. This happens for example when `dtc` is build as a part of the RTEMS build system. By not hardcoding a predefined path for `install`, as is done for other executables, `dtc` will allow the one in the `$PATH` to be used. Signed-off-by: Samuel Tardieu <sam@rfc1149.net> Message-ID: <20240208191405.1597654-1-sam@rfc1149.net> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-01-25libfdt: fix duplicate meson targetAlyssa Ross1-9/+11
If default_library is set to static, the libfdt target (which just uses library()) is already static, so we should just use that. This fixes this Meson error: libfdt/meson.build:37:11: ERROR: Tried to create target "fdt", but a target of that name already exists. Signed-off-by: Alyssa Ross <hi@alyssa.is> Message-ID: <20240123130742.185409-1-hi@alyssa.is> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2024-01-25tests: use correct pkg-config when cross compilingAlyssa Ross1-1/+1
By convention, the PKG_CONFIG environment variable is used to tell build systems which pkg-config executable should be used. This is often used when cross compiling, where it might be set to something like "aarch64-unknown-linux-gnu-pkg-config". Signed-off-by: Alyssa Ross <hi@alyssa.is> Message-ID: <20240123130409.181128-2-hi@alyssa.is> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-12-18meson: allow building from shallow clonesPeter Marko1-0/+1
When building from shallow clone, tag is not available and version defaults to git hash. Problem is that some builds check DTC version and fail the comparison. Example is https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git Which fails to build with following error: dtc version too old (039a994), you need at least version 1.4.4 Drop --always from git describe command, see https://github.com/mesonbuild/meson/blob/1.3.0/mesonbuild/utils/universal.py#L773 This will make it more closer to build via Makefile. Signed-off-by: Peter Marko <peter.marko@siemens.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-11-04treesource: Restore string list output when no type markersRob Herring3-2/+30
When the DTS output has no type markers, we have to guess the type. Prior to commit 32b9c6130762 ("Preserve datatype markers when emitting dts format"), instances of string lists would be delimited. Since then, a single string with embedded "\0"s are emitted. An embedded "\0" is valid for DTS files, but that's a rare exception and lists of strings are the overwhelming majority. Restore the prior behavior. stringlist.dts is reused for testing this, but needs a couple of tweaks in order to match the dts output. Reported-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Rob Herring <robh@kernel.org> Message-ID: <20231027142901.2536622-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-10-11libfdt: fdt_path_offset_namelen: Reject empty pathPierre-Clément Tosi2-1/+10
Reject empty paths and negative lengths, according to the DT spec v0.4: The convention for specifying a device path is: /node-name-1/node-name-2/node-name-N The path to the root node is /. This prevents the access to path[0] from ever being out-of-bounds. Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Message-ID: <20231010092822.qo2nxc3g47t26dqs@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-10-11libfdt: fdt_get_alias_namelen: Validate aliasesPierre-Clément Tosi3-2/+27
Ensure that the alias found matches the device tree specification v0.4: Each property of the /aliases node defines an alias. The property name specifies the alias name. The property value specifies the full path to a node in the devicetree. This protects against a stack overflow caused by fdt_path_offset_namelen(fdt, path, namelen) calling fdt_path_offset(fdt, fdt_get_alias_namelen(fdt, path, namelen)) leading to infinite recursion on DTs with "circular" aliases. This fix was originally written by Mike McTernan for Android in [1]. [1]: https://android.googlesource.com/platform/external/dtc/+/9308e7f9772bd226fea9925b1fc4d53c127ed4d5 Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Acked-by: Mike McTernan <mikemcternan@google.com> Message-ID: <20231010092725.63h7c45p2fnmj577@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-09-15pylibfdt: Support boolean propertiesSimon Glass3-0/+89
Boolean properties are unusual in that their presense or absence indicates the value of the property. This makes them a little painful to support using the existing getprop() support. Add new methods to deal with booleans specifically. Signed-off-by: Simon Glass <sjg@chromium.org> Message-ID: <20230912182716.248253-1-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-09-05dtc: fix missing string in usage_opts_helpCharles Perry1-0/+1
This fixes the output of the `dtc --help` command as the last few entries were offset by one. Signed-off-by: Charles Perry <charles.perry@savoirfairelinux.com> Message-ID: <20230904143104.1941715-1-charles.perry@savoirfairelinux.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-09-04libfdt: Fix fdt_appendprop_addrrange documentationPierre-Clément Tosi1-1/+1
According to the documentation, the function should default to the very common property name <reg> when none is "specified". However, neither passing NULL (ends up calling strlen(NULL) and segfaults) nor "" (appends a property with an empty name) implements this behavior. Furthermore, the test case supposed to cover this default value actually passes the value to the function, somewhat defeating its own purpose: /* 2. default property name */ // ... err = fdt_appendprop_addrrange(fdt, 0, offset, "reg", addr, size); if (err) FAIL("Failed to set \"reg\": %s", fdt_strerror(err)); check_getprop_addrrange(fdt, 0, offset, "reg", 1); Finally, nothing in the implementation of the function seems to attempt to cover that use-case. As the feature can't ever have been used by clients and as the resulting reduced readability of the caller seems (IMO) to outweigh any potential benefit this API would bring, remove the erroneous documentation instead of trying to fix the function. Reported-by: Mostafa Saleh <smostafa@google.com> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Message-ID: <20230831123918.rf54emwkzgtcb7aw@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-09-03github: add workflow for Meson buildsBrandon Maier2-5/+33
Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-06libfdt: rename libfdt-X.Y.Z.so to libfdt.so.X.Y.ZBrandon Maier3-1/+7
The Meson build system requires that the generated shared library uses the libfdt.so.X.Y.Z naming scheme. But the Makefile is generating libfdt-X.Y.Z.so. We want to keep the output of both systems the same to avoid issues, so we rename the Makefile to match Meson. Additionally, Meson generates the base "libfdt.so -> libfdt.so.1" symlink which the Makefile hasn't been doing, add that as well. This shouldn't impact existing users as the linker should be looking for libfdt.so.1 which won't change and will still point to the correct file. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-06workflows: build: remove setuptools_scm hackBrandon Maier1-2/+2
The SETUPTOOLS_SCM_PRETEND_VERSION was needed as ./setup.py would fail without it. As setuptools_scm will fail if there is not git repo, and the github workflow container does not include the source code git repo. A previous commit added "fallback_version" to setuptools_scm which instructs it to use the version from VERSION.txt when the git repo is missing. So this hack is no longer needed. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-06pylibfdt: use fallback version in tarballsBrandon Maier1-0/+5
When building pylibfdt from the released tarballs[1] setup.py will fail with the following. > LookupError: setuptools-scm was unable to detect version for dtc. > Make sure you're either building from a fully intact git repository or > PyPI tarballs. Most other sources (such as GitHub's tarballs, a git > checkout without the .git folder) don't contain the necessary metadata > and will not work. seutptools_scm supports a 'fallback_version' that will use the provided string as the version when the git repo is not available. [1] https://www.kernel.org/pub/software/utils/dtc/dtc-1.7.0.tar.xz Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-06move release version into VERSION.txtBrandon Maier3-8/+5
To synchronize the release version of the Makefile and Meson build systems, pull the version info from a shared file. Meson requires that the shared library version follow the X.Y.Z numbering scheme. But the Makefile supported building shared libraries with an EXTRAVERSION appended, for example X.Y.Z-rc1. We want to keep the output of both systems the same to avoid issues, so we drop support for the Makefile EXTRAVERSION. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-04libfdt: add missing version symbolsBrandon Maier1-0/+2
These symbols were not added to the version script when they were added to libfdt. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-04editorconfig: use tab indentation for version.ldsBrandon Maier2-1/+4
This file is indented with tabs, but editorconfig defaults all files to spaces. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-04tests: generate dtbs in Meson build directoryBrandon Maier1-2/+3
When running under Meson, check_tests() is generating dtb build files in the source directory. This is because dtb is named by appending ".test.dtb" to the full source file name. Use basename to extract just the source filename and write it to the working directory which is the build directory. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-03tests: fix use of deprecated meson methodsBrandon Maier1-2/+2
Fixes the following warnings > tests/meson.build:123: WARNING: Project targets '>=0.56.0' but uses feature deprecated since '0.55.0': ExternalProgram.path. use ExternalProgram.full_path() instead > tests/meson.build:124: WARNING: Project targets '>=0.56.0' but uses feature deprecated since '0.56.0': meson.source_root. use meson.project_source_root() or meson.global_source_root() instead. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-03pylibtfdt: fix use of deprecated meson methodBrandon Maier1-1/+1
Fixes the following warning > pylibfdt/meson.build:2: WARNING: Project targets '>=0.56.0' but uses feature deprecated since '0.55.0': ExternalProgram.path. use ExternalProgram.full_path() instead Do not use full_path() as suggested. setup_py is being called as a command by custom_target() which understands how to properly inherit the object returned by find_program(). Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-02meson: set minimum Meson version to 0.56.0Brandon Maier1-0/+1
Set the minimum required version of Meson based on the highest version feature used, as detected by meson-setup. * 0.56.0: {'meson.project_build_root'} Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-01libfdt: fix library version to match project versionBrandon Maier1-1/+1
Build the libfdt with the correct version number by pulling the version from the top-level project. Change as suggested from https://github.com/dgibson/dtc/pull/95#issuecomment-1546933095 Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-07-29meson: allow disabling testsOtavio Salvador2-3/+5
The new meson build system support diverges from former build system where the tests were not built until required. This has caused an issue in NixOS[1] due to broken build of tests in Darwin platform, so this patch allows the control if tests should be build or not. 1. https://github.com/NixOS/nixpkgs/pull/235210 Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-07-29Makefile: allow to install libfdt without building executablesNicolas Escande1-1/+1
When we only need the libfdt calling the target install-lib also builds the executables listed in $(BINS) because this target depends on all Instead lets make install-lib only depend on libfdt. Signed-off-by: Nicolas Escande <nico.escande@gmail.com> Message-ID: <20230726144336.677135-1-nico.escande@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-07-28Fix use of <ctype.h> functionsSebastian Huber2-2/+2
The value passed to the <ctype.h> functions shall be the value of an unsigned char or EOF. It is implementation-defined if the char type is signed or unsigned. Cast to unsigned char to avoid undefined behaviour on systems where char is signed. This cast is already present in other parts of the code base. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-06-08libfdt: Fix a typo in libfdt.hYan-Jie Wang1-1/+1
The function mentioned in the comment, fdt_finished(), should be changed to fdt_finish(). Signed-off-by: Yan-Jie Wang <yanjiewtw@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-06-01libfdt: meson: Fix linking on macOS linkerOtavio Salvador1-1/+11
-undefined error is the equivalent of --no-undefined for the macOS linker, but -undefined would also be understood as a valid argument for GNU ld so we use the supported linker variant. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-26dtc: Add an option to generate __local_fixups__ and __fixups__Uwe Kleine-König2-1/+21
This records detailed usage of labels in a dtb. This is needed in overlays (and enabled implicitly for these). For ordinary device trees it can be used to restore labels when compiling back to dts format. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Message-Id: <20230523080941.419330-1-u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-16CI: Add build matrix with multiple Linux distributionsBiswapriyo Nath2-12/+48
set SETUPTOOLS_SCM_PRETEND_VERSION="0" variable because GitHub Actions does not copy the .git directory into the container. Without that, the build fails with the following error LookupError: setuptools-scm was unable to detect version for /__w/dtc/dtc. Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14dtc: Correct invalid dts output with mixed phandles and integersDavid Gibson3-0/+4
The handling of "type preservation" dts output is based on the idea of "phandles with arguments" in properties, which isn't really a thing, other than a fairly common convention about how bindings are written. There's nothing preventing a binding which freely mixes phandles and other integers in an array of cells. Currently write_propval() handles this incorrectly: specifically the case of a phandle which follows a regular integer in a 32-bit cell array, but without a new '< >' delimited causing an extra TYPE_UINT32 marker to be inserted. In this case it omits the necessary space between the integer and the phandle reference, leading to output which can't be sent back into dtc and parsed. Correct this, and update tests to match. I think this is more or less correct for now, but really write_propval() is a big mess :(. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14tests: Add additional tests for device graph checksJohannes Beisswenger3-0/+61
* bad-graph-child-address.dts: additional child address test since the one in bad-graph.dts is now shadowed by its prerequisites also failing. * bad-graph-reg-cells.dts: test warnings produced by check_graph_reg(). Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14checks: Fix crash in graph_child_address if 'reg' cell size != 1Johannes Beisswenger1-25/+25
If an endpoint node has a 'reg' property which consists of more than one cell (4 bytes) and given that matching '#address-cells' and '#size-cells' properties are specified on the port node an assertion is triggered in check_graph_child_address() before the relevant diagnostic checks in check_graph_reg() (called by check_graph_port() and check_graph_endpoint()) are executed. The issue is fixed by making graph_child_address depend on the graph_port and graph_endpoint checks. Additionally the assertion can also be triggered if the length of the 'reg' property is less than 4 bytes e.g. by specifying 'reg = "a";'. In that case however other warnings are produced highlighting the malformed property before dtc crashes. Example dts file triggering the issue: /dts-v1/; / { bar: bar { port { bar_con: endpoint { remote-endpoint = <&foo_con>; }; }; }; foo { port { #address-cells = <1>; #size-cells = <1>; // should always be 0 foo_con: endpoint@1 { reg = <1 2>; // causes assertion failure instead of diagnostic remote-endpoint = <&bar_con>; }; }; }; }; Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14livetree: fix off-by-one in propval_cell_n() bounds checkJohannes Beisswenger1-1/+1
Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14Add definition for a GitHub Actions CI jobUwe Kleine-König1-0/+33
The job just builds the full configuration on latest Ubuntu Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2023-05-14Drop obsolete/broken CI definitionsUwe Kleine-König2-88/+0
(Free) Travis-ci is gone since November 2020, cirrus seems to be unreliable showing build breakages unrelated to changes. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2023-05-14yaml: Depend on libyaml >= 0.2.3Uwe Kleine-König3-3/+7
libyaml before 0.2.3 expects non-const string parameters. Supporting both variants would require either cpp magic or ignoring "discarded-qualifiers" compiler warnings. For the sake of simplicity just support libyaml 0.2.3 and newer. Note that NO_YAML can be overwritten on the make command line. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2023-05-07tests: Add test cases for bad endpoint node and remote-endpoint prop checksJohannes Beisswenger5-0/+46
Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-07checks: Fix segmentation fault in check_graph_nodeJohannes Beisswenger1-0/+5
Dts files which contain an 'endpoint' node as a direct child of the root node cause a segmentation fault inside check_graph_node(). This type of error can easily happen when a 'remote-endpoint' property is accidentally placed outside the corresponding endpoint and port nodes. Example with 'endpoint' node: /dts-v1/; / { endpoint {}; }; Example with remote-endpoint property: /dts-v1/; / { foo { remote-endpoint = <0xdeadbeef>; }; }; Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-03improve documentation for fdt_path_offset()Rasmus Villemoes1-1/+26
The current documentation doesn't mention the possibility of passing a non-absolute path and having that treated as an alias. Add that information, along with an example (which will further be expanded in a subsequent patch), and clarify when -FDT_ERR_BADPATH can be returned. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-03add fdt_get_symbol() and fdt_get_symbol_namelen() functionsRasmus Villemoes2-0/+47
The fdt_get_symbol_namelen() function will be used in a subsequent patch. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-03use fdt_path_getprop_namelen() in fdt_get_alias_namelen()Rasmus Villemoes1-7/+1
Simplify the code by making use of the new helper. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-03add fdt_path_getprop_namelen() helperRasmus Villemoes1-0/+12
Add a wrapper for fdt_getprop_namelen() allowing one to specify the node by path instead of offset. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-04-29doc: dt-object-internal: Fix a typoUwe Kleine-König1-1/+1
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Message-Id: <20230428163034.775288-1-u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-04-28fdtoverlay: Drop a a repeated articleUwe Kleine-König1-1/+1
Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-04-28manual: Fix and improve documentation about -@Uwe Kleine-König1-5/+3
Device trees with a /plugin/ tag ("overlays") generate a __fixups__ node when needed and independent of -q being given or not. The same is true for __local__fixups__. So don't mention these two nodes in the paragraph about -@. To not shorten the description too much, describe the semantic of the properties contained in the generated __symbols__ node. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-18fdtoverlay: Fix usage string to not mention "<type>"Uwe Kleine-König1-3/+1
fdtoverlay doesn't have a -t option, so explaining the type formats and modifier prefixes doesn't make much sense. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Message-Id: <20230315100819.13387-1-u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01build-sys: add -Wwrite-stringsMarc-André Lureau2-1/+2
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01tests: fix leaks spotted by ASANMarc-André Lureau10-21/+25
Always allocate from open_blob_rw(), to simplify memory management. The fixes are not exhaustive. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01livetree: fix leak spotted by ASANMarc-André Lureau1-11/+18
./dtc -I dts -O dtb -o overlay_base_manual_symbols.test.dtb /home/elmarco/src/dtc/tests/overlay_base_manual_symbols.dts ../data.c:109:2: runtime error: null pointer passed as argument 2, which is declared to never be null ================================================================= ==933317==ERROR: LeakSanitizer: detected memory leaks Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f49a2aba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af) #1 0x43183d in xmalloc ../util.h:45 #2 0x43482f in data_add_marker ../data.c:230 #3 0x449bb8 in get_node_phandle ../livetree.c:632 #4 0x421058 in fixup_phandle_references ../checks.c:627 #5 0x41b0ba in check_nodes_props ../checks.c:141 #6 0x41b1c8 in check_nodes_props ../checks.c:144 #7 0x41b9f1 in run_check ../checks.c:181 #8 0x430a68 in process_checks ../checks.c:2057 #9 0x436abd in main ../dtc.c:327 #10 0x7f49a30d850f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) Only create data when necessary, and do not alias it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> [dwg: Small fixup for a slightly different approach to adjacent cleanups] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01Make name_node() xstrdup its name argumentDavid Gibson3-12/+15
The name field of 'struct node' was really always supposed to be a malloc()ed string, that is owned by the structure. To avoid an extra strdup() for strings coming up from the lexer, name_node() expects to take uch an already malloc()ed string, which means it's not correct to pass it a static string literal. That's a pretty non-obvious constraint, so a bunch of incorrect uses have crept in. Really, avoiding the extra dup from the lexer isn't a big enough benefit for this demonstrably dangerous interface. So change it to do the xstrdup() itself, removing the burden from callers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01Delay xstrdup() of node and property names coming from a flat treeDavid Gibson1-12/+9
The 'name' field of 'struct node' is supposed to be an (individually) malloc()ed string. So, when taking a name from a flattened blob we need to strdup() it. Currently that happens in flat_read_string() as we take it from the flattened structure itself. That obscures what's going on because it's several steps removed from actually inserting it into node->name. It also means we need an additional strdup() and free() for the case of old dtb formats where we need to extract just the final path component from the blob for the name. While we're scanning the blob, we're doing so read-only, so it's fine to have pointers into it. Therefore simplify things a bit by delaying the xstrdup() to the point where we're actually inserting into node->name. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01Make build_property() xstrdup its name argumentDavid Gibson4-7/+10
The name field of 'struct property' was really always supposed to be a malloc()ed string, that is owned by the structure. To avoid an extra strdup() for strings coming up from the lexer, build_property() and build_property_delete() expect to take such an already malloc()ed string, which means it's not correct to pass it a static string literal. That's a pretty non-obvious constraint, so a bunch of incorrect uses have crept in. Really, avoiding the extra dup from the lexer isn't a big enough benefit for this demonstrably dangerous interface. So change it to do the xstrdup() itself, removing the burden from callers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01checks: correct I2C 10-bit address checkMatt Ranostay1-3/+4
Currently if there is a valid 10-bit address the following warning is always displayed due to the 7-bit check failing due to reg > 0x7f "I2C address must be less than 7-bits, got "0x800000a6". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property" Fix this issue by checking if a 10-bit address is expected, and is valid in separate if statements. Fixes: 8259d59f ("checks: Improve i2c reg property checking") Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01yamltree.c: fix -Werror=discarded-qualifiers & -Werror=cast-qualMarc-André Lureau1-13/+13
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01checks: make check.data constMarc-André Lureau1-5/+5
Fixes: ../checks.c:47:25: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01checks.c: fix check_msg() leakMarc-André Lureau1-0/+1
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01checks.c: fix heap-buffer-overflowMarc-André Lureau1-1/+1
./dtc -I dts -O dtb -o aliases.dtb /home/elmarco/src/dtc/tests/aliases.dts ================================================================= ==882911==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000113 at pc 0x7f34ba0abf50 bp 0x7ffc8db22450 sp 0x7ffc8db21c00 READ of size 4 at 0x602000000113 thread T0 #0 0x7f34ba0abf4f in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) (/lib64/libasan.so.8+0xabf4f) #1 0x7f34ba0ac5e8 in memcmp (/lib64/libasan.so.8+0xac5e8) #2 0x4282dc in check_spi_bus_bridge ../checks.c:1110 #3 0x41b08d in check_nodes_props ../checks.c:140 #4 0x41b9c4 in run_check ../checks.c:180 #5 0x430a3b in process_checks ../checks.c:2056 #6 0x436a90 in main ../dtc.c:327 #7 0x7f34b964a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f) #8 0x7f34b964a5c8 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x275c8) #9 0x4025c4 in _start (/home/elmarco/src/dtc/build/dtc+0x4025c4) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01tests: fix -Wwrite-stringsMarc-André Lureau2-3/+3
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01srcpos.c: fix -Wwrite-stringsMarc-André Lureau1-6/+6
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-28meson: Fix cell overflow tests when running from mesonDavid Gibson1-2/+2
Because meson always builds out-of-tree we need to reference things in the original source tree via $SRCDIR from run_tests.sh. We forgot a couple of cases for the cell overflow tests. Fix them. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-28meson.build: bump version to 1.7.0Nikolay Letov1-1/+1
[This was botched in the actual 1.7.0 release :( - David Gibson] Signed-off-by: Nikolay Letov <letov.nikolay@gmail.com>
2023-02-27Add -Wsuggest-attribute=format warning, correct warnings thus generatedDavid Gibson3-3/+5
Add this new warning to the default build flags. It suggests adding a ((format)) attribute to xavsprintf_append(), so do that. Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-27Use #ifdef NO_VALGRINDMarc-André Lureau1-1/+1
Using simply #if will fail when NO_VALGRIND is undefined. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-02-27Do not redefine _GNU_SOURCE if already setMarc-André Lureau2-0/+4
Or else, compilation will fail. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-02-09Bump version to v1.7.0v1.7.0David Gibson1-2/+2
It's been rather too long since the last release, and quite a lot of changes have accumulated. Finally get around to rolling a release. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-05Merge remote-tracking branch 'gitlab/main'David Gibson1-2/+2
2023-02-05pylibfdt: add size_hint parameter for get_pathLuca Weiss2-4/+5
This also enables us to test the -NOSPACE condition by adding a test setting size_hint=1 so this path is taken. Message-Id: <20230201181112.1644842-1-luca@z3ntu.xyz> Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-02checks: Update #{size,address}-cells check for 'dma-ranges'Qun-Wei Lin1-2/+2
The "dma-ranges" property value is a sequence of child-address parent-address child-size The size of each field is determined by taking the child's "#address-cells" value, the parent's "#address-cells" value, and the child's "#size-cells" value. However, in the following example, it gives a false alarm: +-----------------------------------+---------------------------------------+ | ranges.dts | dma-ranges.dts | +-----------------------------------+---------------------------------------+ | /dts-v1/; | /dts-v1/; | | | | | /{ | /{ | | #address-cells = <1>; | #address-cells = <1>; | | | | | parent { | parent { | | #address-cells = <1>; | #address-cells = <1>; | | #size-cells = <1>; | #size-cells = <1>; | | ranges = <0x0 0xe000 0x1000>; | dma-ranges = <0x0 0xe000 0x1000>; | | child { | child { | | ... | ... | | }; | }; | | }; | }; | | }; | }; | +-----------------------------------+---------------------------------------+ | no warning | Warning (avoid_unnecessary_addr_size) | +-----------------------------------+---------------------------------------+ Same as "ranges", it should not be reported in this check. Signed-off-by: Qun-Wei Lin <qun-wei.lin@mediatek.com> Message-Id: <20230112125654.13390-1-qun-wei.lin@mediatek.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-02pylibfdt: Work-around SWIG limitations with flexible arraysRob Herring1-0/+3
Commit a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with proper flexible arrays") fails to build pylibfdt: ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_node_header_name_set’: ./pylibfdt/libfdt_wrap.c:4350:18: error: cast specifies array type 4350 | arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size)); | ^ ./pylibfdt/libfdt_wrap.c:4350:16: error: invalid use of flexible array member 4350 | arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size)); | ^ ./pylibfdt/libfdt_wrap.c:4352:16: error: invalid use of flexible array member 4352 | arg1->name = 0; | ^ ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_property_data_set’: ./pylibfdt/libfdt_wrap.c:4613:18: error: cast specifies array type 4613 | arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size)); | ^ ./pylibfdt/libfdt_wrap.c:4613:16: error: invalid use of flexible array member 4613 | arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size)); | ^ ./pylibfdt/libfdt_wrap.c:4615:16: error: invalid use of flexible array member 4615 | arg1->data = 0; | ^ Turns out this is known issue with SWIG: https://github.com/swig/swig/issues/1699 Implement the work-around to ignore the flexible array member. Fixes: a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with proper flexible arrays") Cc: Kees Cook <keescook@chromium.org> Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20230201224441.305757-1-robh@kernel.org> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-01-29libfdt: Replace deprecated 0-length arrays with proper flexible arraysKees Cook1-2/+2
Replace the 0-length arrays in structures with proper flexible arrays. This will avoid warnings when building under GCC 13 with -fstrict-flex-arrays, which the Linux kernel will be doing soon: In file included from ../lib/fdt_ro.c:2: ../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name': ../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread] 319 | leaf = strrchr(nameptr, '/'); | ^~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-11-21dtc: Warning rather than error on possible truncation of cell valuesDavid Gibson4-3/+27
We always evaluate integer values in cell arrays as 64-bit quantities, then truncate to the size of the array cells (32-bit by default). However to detect accidental truncation of meaningful values, we give an error if the truncated portion isn't either all 0 or all 1 bits. However, this can still give counterintuitive errors. For if the user is thinking in 2's complement 32-bit arithmetic (which would be quite natural), then they'd expect the expression (-0xffffffff-2) to evaluate to -1 (0xffffffff). However in 64-bit it evaluates to 0xfffffffeffffffff which does truncate to the expected value but trips this error message. Because of this reduce the error to only a warnings, with a somewhat more helpful message. Fixes: https://github.com/dgibson/dtc/issues/74 Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-10-12libfdt: tests: add get_next_tag_invalid_prop_lenTadeusz Struk5-1/+104
Add a new test get_next_tag_invalid_prop_len, which covers fdt_next_tag(), when it is passed an corrupted blob, with invalid property len values. The test runs twice, on a blob in sw and finished state. Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org> Message-Id: <20221011182611.116011-2-tadeusz.struk@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-10-12libfdt: prevent integer overflow in fdt_next_tagTadeusz Struk1-5/+12
Since fdt_next_tag() in a public API function all input parameters, including the fdt blob should not be trusted. It is possible to forge a blob with invalid property length that will cause integer overflow during offset calculation. To prevent that, validate the property length read from the blob before doing calculations. Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org> Message-Id: <20221005232931.3016047-1-tadeusz.struk@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-10-12libfdt: add fdt_get_property_by_offset_w helperTadeusz Struk1-0/+7
Add a new fdt_get_property_by_offset_w helper function. It is a wrapper on fdt_get_property_by_offset that returns a writable pointer to a property at a given offset. Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org> Message-Id: <20221011182611.116011-1-tadeusz.struk@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-09-26Makefile: fix infinite recursion by dropping non-existent `%.output`Sergei Trofimovich1-1/+1
Without the change GNU `make-4.4` falls into infinite recursion of trying to generate %.output files (bison is not passed flags to generate debug output). This happens on GNU `make-4.4` only after GNU make change to more eagerly rebuild all target outputs in multiple targets: https://savannah.gnu.org/bugs/index.php?63098 The recursion here is the following: - Makefile depends on *.d files - *.d files depend on *.c files - *.c files are generated by bison - bison is triggered whenever some of it's multiple targets are missing In our case `%.output` is always missing and bison is always reran. *.d files are always regenerated on `make` run. And make is always restarted as *.d files are always regenerated. The fix removes infeasible `%.output`. Signed-off-by: Sergei Trofimovich <slyich@gmail.com> Message-Id: <20220925104203.648449-2-slyich@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-09-26Makefile: limit make re-execution to avoid infinite spinSergei Trofimovich1-0/+4
make-4.4 became intentionally more eager at rebuilding outdated Makefile includes. Currently this causes `dtc` to spin infinitely in parser/dependency loop: $ make ... CHK version_gen.h BISON dtc-parser.tab.h DEP dtc-lexer.lex.c DEP dtc-parser.tab.c CHK version_gen.h BISON dtc-parser.tab.h DEP dtc-lexer.lex.c DEP dtc-parser.tab.c ... # never stops After the change build eventually fails when gets into this state: $ make ... CHK version_gen.h UPD version_gen.h DEP util.c BISON dtc-parser.tab.h DEP dtc-lexer.lex.c DEP dtc-parser.tab.c CHK version_gen.h BISON dtc-parser.tab.h DEP dtc-lexer.lex.c DEP dtc-parser.tab.c Makefile:394: *** "Make re-executed itself 10 times. Infinite recursion?". Stop. The actual recursion will be fixed separately. Signed-off-by: Sergei Trofimovich <slyich@gmail.com> Message-Id: <20220925104203.648449-1-slyich@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-09-16libdtc: remove duplicate judgmentsJia Xianhua1-3/+0
There is no need to check the VALID_DTB repeatedly, and can be combined into one if statement. Signed-off-by: Jia Xianhua <jiaxianhua@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-31Don't generate erroneous fixups from reference to pathDavid Gibson3-0/+13
The dtb overlay format only permits (non local) fixups to reference labels, not paths. That's because the fixup target goes into the property name in the overlay, and property names aren't permitted to include '/' characters. Stop erroneously generating such fixups, because we didn't check for this case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-30libfdt: Don't mask fdt_get_name() returned errorPierre-Clément Tosi1-1/+4
Return the error code from fdt_get_name() (contained in len when the result is NULL) instead of masking it with FDT_ERR_BADSTRUCTURE. Fixes: fda71da26e7f ("libfdt: Handle failed get_name() on BEGIN_NODE") Reported-by: Mike McTernan <mikemcternan@google.com> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Message-Id: <20220729130019.804288-1-ptosi@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-30manual.txt: Follow README.md and remove JonPierre-Clément Tosi1-2/+1
Following 0ee1d479b23a ("Remove Jon Loeliger from maintainers list"), make the "Submitting Patches" section of the manual.txt consistent with the README by requesting patches to only be sent to David. Cc: Jon Loeliger <loeliger@gmail.com> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Message-Id: <20220729131019.806164-1-ptosi@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-30Update README in MANIFEST.in and setup.py to README.mdSaad Waheed2-2/+2
Signed-off-by: Saad Waheed <saad.waheed@10xengineers.ai>
2022-07-29Add description of Signed-off-by linesDavid Gibson1-0/+54
dtc and libfdt have been using Signed-off-by lines (as used in the Linux kernel) for some time, like a lot of open source projects. However Uwe Kleine-König pointed out we never really stated what they mean in our context. Add information on what the S-o-b line means in CONTRIBUTING.md - this is essentially a quote of the same information from the kernel documentation, with some tweaks to make sense in the new context. Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2022-07-28Split out information for contributors to CONTRIBUTING.mdDavid Gibson2-19/+25
README.md covers both general information for people using and building the software, and more specific information for people contributing to either dtc or libfdt. Split out the latter information into its own file for easier reference. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-28Remove Jon Loeliger from maintainers listDavid Gibson1-1/+0
Jon hasn't been actively working on dtc maintenance for some years. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-28Convert README to README.mdDavid Gibson2-106/+120
Let's move vaguely into the twenty-first century by converting our old plain text README file to Markdown. While we're updating the formatting, make some small polish changes to the content. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-27Allow static building with mesonTero Tervala4-5/+28
Added "static-build" option in the meson_options.txt. Setting it to "true" allows static building. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163557.932298-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-27Allow static building with makeTero Tervala3-11/+24
Set STATIC_BUILD=1 environment variable to enable static building when using makefiles. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163531.932281-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-26libfdt: Handle failed get_name() on BEGIN_NODEPierre-Clément Tosi1-1/+1
Validate the return value of fdt_get_name() as an ill-formed DT, causing it to fail, could result in fdt_check_full() dereferencing NULL. fixes: a2def5479950 ("libfdt: Check that the root-node name is empty") Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Message-Id: <20220714083848.958492-1-ptosi@google.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-26Fix test script to run also on dash shellTero Tervala1-2/+2
/bin/sh points to dash instead of bash in some linux distros. One test would fail if dash was used, this fix will allow all tests to run properly on dash too. dash built-in printf does not support "\xNN" -hex escape format. "\NNN" -octal escape format is supported by both bash and dash printf. Replaced "$(echo "$expect")" because this actually runs /bin/echo instead of shell internal echo and in some cases causes "\NNN" escapes to be printed as the actual characters they represent instead of the escape sequence itself. Cosmetic quotes added to make printout a bit clearer. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220704073722.1075849-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-02Add missing relref_merge test to meson test listTero Tervala1-0/+1
Will remove one "Strange test result" when running tests with meson Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163114.932175-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-04-20pylibfdt: add FdtRo.get_path()Luca Weiss2-0/+41
Add a new Python method wrapping fdt_get_path() from the C API. Also add a test for the new method. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20220419194537.63170-1-luca@z3ntu.xyz> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-02-04pylibfdt: fix swig build in installRob Herring2-1/+8
A 'pip install' is silently broken unless the tree is dirty and contains pylibfdt/libfdt.py. The problem is a known issue[1] with SWIG and setuptools where the 'build_py' stage needing module.py runs before the 'build_ext' stage which generates it. The work-around is to override 'build_py' to run 'build_ext' first. [1] https://stackoverflow.com/questions/50239473/building-a-module-with-setuptools-and-swig Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20220203180408.611645-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-01-25tests: add test cases for label-relative path referencesAhmad Fatoum7-2/+112
Newly added &{label/path} feature doesn't yet have any tests. Add some. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2022-01-25dtc: introduce label relative path referencesAhmad Fatoum3-4/+44
Reference via label allows extending nodes with compile-time checking of whether the node being extended exists. This is useful to catch renamed/removed nodes after an update of the device trees to be extended. In absence of labels in the original device trees, new style path references can be used: /* upstream device tree */ / { leds: some-non-standard-led-controller-name { led-0 { default-state = "off"; }; }; }; /* downstream device tree */ &{/some-non-standard-led-controller-name/led-0} { default-state = "on"; }; This is a common theme within the barebox bootloader[0], which extends the upstream (Linux) device trees in that manner. The downside is that, especially for deep nodes, these references can get quite long and tend to break often due to upstream rework (e.g. rename to adhere to bindings). Often there is a label a level or two higher that could be used. This patch allows combining both a label and a new style path reference to get a compile-time-checked reference, which allows rewriting the previous downstream device tree snippet to: &{leds/led-0} { default-state = "on"; }; This won't be broken when /some-non-standard-led-controller-name is renamed or moved while keeping the label. And if led-0 is renamed, we will get the expected compile-time error. Overlay support is skipped for now as they require special support: The label and relative path parts need to be resolved at overlay apply-time, not at compile-time. [0]: https://www.barebox.org/doc/latest/devicetree/index.html Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2022-01-25util: introduce xstrndup helperAhmad Fatoum2-0/+12
We already have xstrdup, add xstrndup as well to make it straight-forward to clone part of a string. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2022-01-04setup.py: fix out of tree buildMarc-André Lureau1-1/+1
Fixes: commit 1cc41b1c9 ("pylibfdt: Add packaging metadata") Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220103073855.1468799-3-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-29Handle integer overflow in check_property_phandle_args()David Gibson3-6/+30
If the corresponding '#xxx-cells' value is much too large, an integer overflow can prevent the checks in check_property_phandle_args() from correctly determining that the checked property is too short for the given cells value. This leads to an infinite loops. This patch fixes the bug, and adds a testcase for it. Further information in https://github.com/dgibson/dtc/issues/64 Reported-by: Anciety <anciety@pku.edu.cn> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28README: Explain how to add a new API functionSimon Glass1-0/+9
This is not obvious so add a little note about it. Signed-off-by: Simon Glass <sjg@chromium.org> Message-Id: <20211107224346.3181320-2-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28Fix a UB when fdt_get_string return nullLoveSy1-1/+1
When fdt_get_string return null, `namep` is not correctly reset. From the document of `fdt_getprop_by_offset`, the parameter `namep` will be always overwritten (that is, it will be overwritten without exception of error occurance). As for the caller (like https://github.com/topjohnwu/Magisk/blob/e097c097feb881f6097b6d1dc346f310bc92f5d6/native/jni/magiskboot/dtb.cpp#L42), the code may be like: ```cpp size_t size; const char *name; auto *value = fdt_getprop_by_offset(fdt, prop, &name, &size); ``` and if `value == nullptr`, `size` is also be overwritten correctly but `name` is not, which is quite inconsistent. This commit makes sure `name` and `size` behavior consistently (reset to reasonable value) when error occurs. Signed-off-by: LoveSy <shana@zju.edu.cn> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28tests: setprop_inplace: use xstrdup instead of unchecked strdupAhmad Fatoum1-1/+1
This is the only strdup instance we have, all others are xstrdup. As strdup is _POSIX_C_SOURCE >= v200809L, which we don't require and we don't check strdup error return here, switch to xstrdup instead. This aligns the test with others that call xfuncs, mainly xmalloc(). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28pylibfdt: add Property.as_*int*_array()Luca Weiss3-0/+30
Add new methods to handle decoding of int32, uint32, int64 and uint64 arrays. Also add tests for the new methods. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-3-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28pylibfdt: add Property.as_stringlist()Luca Weiss2-0/+15
Add a new method for decoding a string list property, useful for e.g. the "reg-names" property. Also add a test for the new method. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-2-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-26Fix Python crash on getprop deallocationLuca Weiss1-2/+4
Fatal Python error: none_dealloc: deallocating None Python runtime state: finalizing (tstate=0x000055c9bac70920) Current thread 0x00007fbe34e47740 (most recent call first): <no Python frame> Aborted (core dumped) This is caused by a missing Py_INCREF on the returned Py_None, as demonstrated e.g. in https://github.com/mythosil/swig-python-incref or described at https://edcjones.tripod.com/refcount.html ("Remember to INCREF Py_None!") A PoC for triggering this crash is uploaded to https://github.com/z3ntu/pylibfdt-crash . With this patch applied to pylibfdt the crash does not happen. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211224102811.70695-1-luca@z3ntu.xyz> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-09Support 'r' format for printing raw bytes with fdtgetRafał Miłecki7-5/+18
FT is sometimes used for storing raw data. That is quite common for U-Boot FIT images. Extracting such data is not trivial currently. Using type 's' (string) will replace every 0x00 (NUL) with 0x20 (space). Using type 'x' will print bytes but in xxd incompatible format. This commit adds support for 'r' (raw) format. Example usage: fdtget -t r firmware.itb /images/foo data > image.raw Support for encoding isn't added as there isn't any clean way of passing binary data as command line argument. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Message-Id: <20211209061420.29466-1-zajec5@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-18libfdt: overlay: make overlay_get_target() publicVikram Garhwal3-22/+26
This is done to get the target path for the overlay nodes which is very useful in many cases. For example, Xen hypervisor needs it when applying overlays because Xen needs to do further processing of the overlay nodes, e.g. mapping of resources(IRQs and IOMMUs) to other VMs, creation of SMMU pagetables, etc. Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com> Message-Id: <1637204036-382159-2-git-send-email-fnu.vikram@xilinx.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-17libfdt: fix an incorrect integer promotionElvira Khabirova1-1/+1
UINT32_MAX is an integer of type unsigned int. UINT32_MAX + 1 overflows unless explicitly computed as unsigned long long. This led to some invalid addresses being treated as valid. Cast UINT32_MAX to uint64_t explicitly. Signed-off-by: Elvira Khabirova <e.khabirova@omp.ru>
2021-11-12pylibfdt: Add packaging metadataRob Herring2-0/+20
PyPI expects to have various package metadata including long description, license, and classifiers. Add them. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211112041633.741598-3-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-12README: Update pylibfdt install instructionsRob Herring1-7/+13
Now that pip is supported for installs, update the install instructions to use it. Using pip over setup.py is generally recommended and simpler. Also, drop 'SETUP_PREFIX' as it doesn't exist anywhere. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211112041633.741598-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-12pylibfdt: fix with Python 3.10Ross Burton2-2/+3
Since Python 2.5 the argument parsing functions when parsing expressions such as s# (string plus length) expect the length to be an int or a ssize_t, depending on whether PY_SSIZE_T_CLEAN is defined or not. Python 3.8 deprecated the use of int, and with Python 3.10 this symbol must be defined and ssize_t used[1]. Define the magic symbol when building the extension, and cast the ints from the libfdt API to ssize_t as appropriate. [1] https://docs.python.org/3.10/whatsnew/3.10.html#id2 Signed-off-by: Ross Burton <ross.burton@arm.com> Message-Id: <20211111160536.2516573-1-ross.burton@arm.com> [dwg: Adjust for new location of setup.py] Tested-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11pylibfdt: Move setup.py to the top levelRob Herring5-11/+24
Using 'pip' and several setup.py sub-commands currently don't work with pylibfdt. The primary reason is Python packaging has opinions on the directory structure of repositories and one of those appears to be the inability to reference source files outside of setup.py's subtree. This means a sdist cannot be created with all necessary source components (i.e. libfdt headers). Moving setup.py to the top-level solves these problems. With this change. the following commands now work: Creating packages for pypi.org: ./setup.py sdist bdist_wheel Using pip for installs: pip install . pip install git+http://github.com/robherring/dtc.git@pypi-v2 Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211111011135.2386773-5-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11pylibfdt: Split setup.py author name and emailRob Herring1-1/+2
The 'author' field in setup.py is supposed to be just the name. The email address goes in 'author_email' field. Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211111011135.2386773-4-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11pylibfdt: Use setuptools_scm for the versionRob Herring3-16/+5
The DTC version in version_gen.h causes a warning with setuptools: setuptools/dist.py:501: UserWarning: The version specified ('1.6.1-g5454474d') \ is an invalid version, this may not work as expected with newer versions of \ setuptools, pip, and PyPI. Please see PEP 440 for more details. It also creates an unnecessary dependency on the rest of the build system(s). Switch to use setuptools_scm instead to get the version for pylibfdt. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211111011135.2386773-3-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11pylibfdt: Use setuptools instead of distutilsRob Herring1-1/+1
The use of setuptools is favored over distutils. setuptools is needed to support building Python 'wheels' and for pip support. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211111011135.2386773-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-11libfdt: Add static lib to meson buildRob Herring1-0/+5
The meson build is not building the static libfdt, so add it. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211111003329.2347536-1-robh@kernel.org> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-11-01CI: Cirrus: bump used FreeBSD from 12.1 to 13.0Ahmad Fatoum1-2/+2
CI freebsd_12 job currently fails to build PRs, because of: ``` ld-elf.so.1: /usr/local/bin/bison: Undefined symbol "fread_unlocked@FBSD_1.6" ``` According to FreeBSD issue tracker[1], the proper solution is to upgrade to a supported release, so do that for our CI. [1]: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=253452 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2021-10-21checks: Add an interrupt-map checkRob Herring5-0/+144
Add a check for parsing 'interrupt-map' properties. The check primarily tests parsing 'interrupt-map' properties which depends on and the parent interrupt controller (or another map) node. Note that this does not require '#address-cells' in the interrupt-map parent, but treats missing '#address-cells' as 0 which is how the Linux kernel parses it. There's numerous cases that expect this behavior. Cc: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211015213527.2237774-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-14checks: Ensure '#interrupt-cells' only exists in interrupt providersRob Herring1-4/+10
The interrupt provider check currently checks if an interrupt provider has #interrupt-cells, but not whether #interrupt-cells is present outside of interrupt-providers. Rework the check to cover the latter case. Cc: Andre Przywara <andre.przywara@arm.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211011191245.1009682-4-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-14checks: Drop interrupt provider '#address-cells' checkRob Herring1-5/+0
'#address-cells' is only needed when parsing 'interrupt-map' properties, so remove it from the common interrupt-provider test. Cc: Andre Przywara <andre.przywara@arm.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211011191245.1009682-3-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-14checks: Make interrupt_provider check dependent on interrupts_extended_is_cellRob Herring1-1/+1
If '#interrupt-cells' doesn't pass checks, no reason to run interrupt provider check. Cc: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211011191245.1009682-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-11treesource: Maintain phandle label/path on outputRob Herring3-6/+25
The dts output will just output phandle integer values, but often the necessary markers are present with path or label references. Improve the output and maintain phandle label or path references when present in dts output. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210727183023.3212077-6-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-09-27flattree: Use '\n', not ';' to separate asm pseudo-opsDavid Gibson1-1/+2
The output of -Oasm is peculiar for assembler in that we want its output to be portable across targets (it consists entirely of pseudo-ops and labels, no actual instructions). It turns out that while ';' is a valid instruction/pseudo-op separator on most targets, it's not correct for all of them - e.g. HP PA-RISC. So, switch to using an actual \n instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-09-27asm: Use assembler macros instead of cpp macrosDavid Gibson1-194/+207
tests/trees.S is a weird thing: a portable aseembler file, used to produce a specific binary output. Currently it uses CPP macros quite heavily to construct the dtbs we want (including some partial and broken trees). Using cpp has the side effect that we need to use ; separators between instructions (or, rather, pseudo-ops), because cpp won't expand newlines. However, it turns out that while ; is a suitable separator on most targets, it doesn't work for all of them (e.g. HP PA-RISC). Switch to using the assembler's inbuilt macros rather than CPP, so that we can use genuine newlines. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-09-25asm: Use .asciz and .ascii instead of .stringRob Herring6-77/+75
We use the .string pseudo-op both in some of our test assembly files and in our -Oasm output. We expect this to emit a \0 terminated string into the .o file. However for certain targets (e.g. HP PA-RISC) it doesn't include the \0. Use .asciz instead, which explicitly does what we want. There's also one place we can use .ascii (which explicitly emits a string *without* \0 termination) instead of multiple .byte directives. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-08-26fdtdump: fix -Werror=int-to-pointer-castMarc-André Lureau1-1/+1
With mingw64-gcc, the compiler complains with various warnings: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210825121350.213551-1-marcandre.lureau@redhat.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-08-02libfdt: Add ALIGNMENT error stringGeorg Kotheimer1-0/+1
The ALIGNMENT error was missing a string, leading to <unknown error> being returned. Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-30checks: Fix bus-range checkThierry Reding1-1/+1
The upper limit of the bus-range is specified by the second cell of the bus-range property. Signed-off-by: Thierry Reding <treding@nvidia.com> Message-Id: <20210629114304.2451114-1-thierry.reding@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21Makefile: add -Wsign-compare to warning optionsAndre Przywara1-1/+1
Now that all signedness comparison warnings in the source tree have been fixed, let's enable the warning option, to avoid them creeping in again. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-6-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21checks: Fix signedness comparisons warningsAndre Przywara1-10/+10
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various parts in checks.c. Fix those by making all affected variables unsigned. This covers return values of the (unsigned) size_t type, phandles, variables holding sizes in general and loop counters only ever counting positives values. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-5-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21dtc: Wrap phandle validity checkAndre Przywara3-7/+12
In several places we check for a returned phandle value to be valid, for that it must not be 0 or "-1". Wrap this check in a static inline function in dtc.h, and use ~0U instead of -1 on the way, to keep everything in the unsigned realm. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-4-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21fdtget: Fix signedness comparisons warningsAndre Przywara2-2/+15
With -Wsign-compare, compilers warn about a mismatching signedness in the different legs of the conditional operator, in fdtget.c. In the questionable expression, we are constructing a 16-bit value out of two unsigned 8-bit values, however are relying on the compiler's automatic expansion of the uint8_t to a larger type, to survive the left shift. This larger type happens to be an "int", so this part of the expression becomes signed. Fix this by explicitly blowing up the uint8_t to a larger *unsigned* type, before doing the left shift. And while we are at it, convert the hardly readable conditional operator usage into a sane switch/case expression. This fixes "make fdtget", when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-3-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21tests: Fix signedness comparisons warningsAndre Przywara13-16/+35
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various files in the tests/ directory. For about half of the cases we can simply change the signed variable to be of an unsigned type, because they will never need to store negative values (which is the best fix of the problem). In the remaining cases we can cast the signed variable to an unsigned type, provided we know for sure it is not negative. We see two different scenarios here: - We either just explicitly checked for this variable to be positive (if (rc < 0) FAIL();), or - We rely on a function returning only positive values in the "length" pointer if the function returned successfully: which we just checked. At two occassions we compare with a constant "-1" (even though the variable is unsigned), so we just change this to ~0U to create an unsigned comparison value. Since this is about the tests, let's also add explicit tests for those values really not being negative. This fixes "make tests" (but not "make check" yet), when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-2-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-15dtc: Fix signedness comparisons warnings: pointer diffAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in the function get_node_by_path(). Taking the difference between two pointers results in a signed ptrdiff_t type, which mismatches the unsigned type returned by strlen(). Since "p" has been returned by a call to strchr() with "path" as its argument, we know for sure that it's bigger than "path", so the difference must be positive. So a cast to an unsigned type is valid. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210611171040.25524-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-15dtc: Fix signedness comparisons warnings: reservednumAndre Przywara3-4/+4
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in code using the "reservednum" variable. There is obviously little sense in having a negative number of reserved memory entries, so let's make this variable and all its users unsigned. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210611171040.25524-6-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-15fdtdump: Fix signedness comparisons warningsAndre Przywara1-3/+3
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in fdtdump.c. The "len" parameter to valid_header() refers to a memory size, not a file offset, so the (unsigned) size_t is better fit, and fixes the warning nicely. In the main function we compare the difference between two pointers, which produces a signed ptrdiff_t type. However the while loop above the comparison makes sure that "p" always points before "endp" (by virtue of the limit in the memchr() call). This means "endp - p" is never negative, so we can safely cast this expression to an unsigned type. This fixes "make fdtdump", when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210611171040.25524-3-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08Bump version to v1.6.1v1.6.1David Gibson1-1/+1
A number of fixes have accumulated, so rolling up another release. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08Fix CID 1461557David Gibson1-5/+8
Coverity gets a bit confused by loading fdt_size_dt_strings() and using it in a memmove(). In fact this is safe because the callers have verified this information (via FDT_RW_PROBE() in fdt_pack() or construction in fdt_open_into()). Passing in strings_size like we already do struct_size seems to get Coverity to follow what's going on here. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08checks: Introduce is_multiple_of()David Gibson1-5/+13
In a number of places we check if one number is a multiple of another, using a modulus. In some of those cases the divisor is potentially zero, which needs special handling or we could trigger a divide by zero. Introduce an is_multiple_of() helper to safely handle this case, and use it in a bunch of places. This should close Coverity issue 1501687, maybe others as well. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08Make handling of cpp line information more tolerantDavid Gibson1-1/+1
At least some cpp implementations, in at least some circumstances place multiple numbers after the file name when they put line number information into the output. We don't really care what the content of these is, but we want the dtc lexer not to choke on this, so adjust the rule for handling cpp line number information accordingly. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08checks: Drop interrupt_cells_is_cell checkRob Herring2-4/+3
With the prior commit, this check is now redundant. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210526010335.860787-4-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08checks: Add check_is_cell() for all phandle+arg propertiesRob Herring1-1/+18
There's already a check for '#.*-cells' properties, so let's enable it for all the ones we already know about. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210526010335.860787-3-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08yamltree: Remove marker ordering dependencyRob Herring1-7/+9
The check for phandle markers is fragile because the phandle marker must be after a type marker. The only guarantee for markers is they are in offset order. The order at a specific offset is undefined. Rework yaml_propval_int() to get the full marker list, so it can find a phandle marker no matter the ordering. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210526010335.860787-2-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-25pylibfdt: Rework "avoid unused variable warning" linesTom Rini1-2/+2
Clang has -Wself-assign enabled by default under -Wall and so when building with -Werror we would get an error here. Inspired by Linux kernel git commit a21151b9d81a ("tools/build: tweak unused value workaround") make use of the fact that both Clang and GCC support casting to `void` as the method to note that something is intentionally unused. Signed-off-by: Tom Rini <trini@konsulko.com> Message-Id: <20210524154910.30523-1-trini@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-04tests: add a positive gpio test caseIlya Lipnitskiy2-0/+14
Ensure that properly named properties don't trigger warnings Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com> Message-Id: <20210504035944.8453-5-ilya.lipnitskiy@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-04checks: replace strstr and strrchr with strendsIlya Lipnitskiy1-18/+7
Makes the logic more clear Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com> Message-Id: <20210504035944.8453-4-ilya.lipnitskiy@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-04dtc.h: add strends for suffix matchingIlya Lipnitskiy1-0/+10
Logic is similar to strcmp_suffix in <kernel>/drivers/of/property.c with the exception that strends allows string length to equal suffix length. Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com> Message-Id: <20210504035944.8453-3-ilya.lipnitskiy@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-04checks: tigthen up nr-gpios prop exceptionIlya Lipnitskiy1-1/+1
There are no instances of nr-gpio in the Linux kernel tree, only "[<vendor>,]nr-gpios", so make the check stricter. nr-gpios without a "vendor," prefix is also invalid, according to the DT spec[0], and there are no DT files in the Linux kernel tree with non-vendor nr-gpios. There are some drivers, but they are not DT spec compliant, so don't suppress the check for them. [0]: Link: https://github.com/devicetree-org/dt-schema/blob/cb53a16a1eb3e2169ce170c071e47940845ec26e/schemas/gpio/gpio-consumer.yaml#L20 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com> Cc: Rob Herring <robh+dt@kernel.org> Message-Id: <20210504035944.8453-2-ilya.lipnitskiy@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-04-07libfdt: Add FDT alignment check to fdt_check_header()Rob Herring1-0/+4
Only checking the FDT alignment in fdt_ro_probe_() means that fdt_check_header() can pass, but then subsequent API calls fail on alignment checks. Let's add an alignment check to fdt_check_header() so alignment errors are found up front. Cc: Tom Rini <trini@konsulko.com> Cc: Frank Rowand <frowand.list@gmail.com> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210406190712.2118098-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-23libfdt: Check that the root-node name is emptySimon Glass6-3/+30
The root node is supposed to have an empty name, but at present this is not checked. The behaviour of such a tree is not well defined. Most software rightly assumes that the root node is at offset 0 and does not check the name. This oddity was discovered as part of a security investigation into U-Boot verified boot. Add a check for this to fdt_check_full(). Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Arie Haenel <arie.haenel@intel.com> Reported-by: Julien Lenoir <julien.lenoir@intel.com> Message-Id: <20210323010410.3222701-2-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-23libfdt: Check that there is only one root nodeSimon Glass6-2/+32
At present it is possible to have two root nodes and even access nodes in the 'second' root. Such trees should not be considered valid. This was discovered as part of a security investigation into U-Boot verified boot. Add a check for this to fdt_check_full(). Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Arie Haenel <arie.haenel@intel.com> Reported-by: Julien Lenoir <julien.lenoir@intel.com> Message-Id: <20210323000926.3210733-1-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-12dtc: Remove -O dtbo supportMasahiro Yamada1-2/+0
This partially reverts 163f0469bf2e ("dtc: Allow overlays to have .dtbo extension"). I think accepting "dtbo" as --out-format is strange. This is not shown by --help, at least. *.dtb and *.dtbo should have the same format, "dtb". Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Message-Id: <20210311094956.924310-1-masahiroy@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-09libfdt: Fix a possible "unchecked return value" warningDavid Gibson1-1/+4
Apparently the unchecked return value of the first fdt_next_tag() call in fdt_add_subnode_namelen() is tripping Coverity Scan in some circumstances, although it appears not to for the scan on our project itself. This fdt_next_tag() should always return FDT_BEGIN_NODE, since otherwise the fdt_subnode_offset_namelen() above would have returned BADOFFSET or BADSTRUCTURE. Still, add a check to shut Coverity up, gated by a can_assume() to avoid bloat in small builds. Reported-by: Ryan Long <ryan.long@oarcorp.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-02-15checks: Warn on node-name and property name being the sameKumar Gala1-1/+15
Treat a node-name and property name at the same level of tree as a warning Signed-off-by: Kumar Gala <kumar.gala@linaro.org> Message-Id: <20210210193912.799544-1-kumar.gala@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-02-10checks: Change node-name check to match devicetree specKumar Gala1-3/+4
The devicetree spec limits the valid character set to: A-Z a-z 0-9 ,._+- while property can additionally have '?#'. Change the check to match the spec. Signed-off-by: Kumar Gala <kumar.gala@linaro.org> Message-Id: <20210209184641.63052-1-kumar.gala@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-02-07util: limit gnu_printf format attribute to gcc >= 4.4.0Jonathan Gray1-3/+3
The gnu_printf format attribute was introduced in gcc 4.4.0 https://gcc.gnu.org/legacy-ml/gcc-help/2012-02/msg00225.html. Use the printf format attribute on earlier versions of gcc and clang (which claims to be gcc 4.2.1 in builtin defines) to fix the build with gcc 4.2.1. Fixes: 588a29f ("util: use gnu_printf format attribute") Signed-off-by: Jonathan Gray <jsg@jsg.id.au> Message-Id: <20210206100110.75228-1-jsg@jsg.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-02-03gitignore: Ignore the swp filesViresh Kumar1-0/+1
Ignore the temporary .*.swp files. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Message-Id: <15496f8669ac2bb3b4b61a1a7c978947623cb7c3.1612346186.git.viresh.kumar@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-02-03gitignore: Add cscope filesViresh Kumar1-0/+4
Add cscope files in gitignore. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Message-Id: <3c39a6324ef2be64f839e6e6205f4afc63486216.1612338199.git.viresh.kumar@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-01-28Update Jon Loeliger's emailDavid Gibson2-2/+2
At Jon's request update to a more current address. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-01-15fdtdump: Fix gcc11 warningDavid Gibson1-1/+1
In one place, fdtdump abuses fdt_set_magic(), passing it just a small char array instead of the full fdt header it expects. That's relying on the fact that in fact fdt_set_magic() will only actually access the first 4 bytes of the buffer. This trips a new warning in GCC 11 - and it's entirely possible it was always UB. So, don't do that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-01-13srcpos: increase MAX_SRCFILE_DEPTHIgnacy Kuchciński1-1/+1
Some kernels require the MAX_SRCFILE_DEPTH to be bigger than 100, and since it's just a sanity check to detect infinite recursion it shouldn't hurt increasing it to 200. Signed-off-by: Ignacy Kuchciński <ignacykuchcinski@gmail.com> Message-Id: <CAJq_QG0BHBQYT4RnVi0QSxM_vFK2K-5k1eTpJnwZQtWbKnCBJA@mail.gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-01-11dtc: Allow overlays to have .dtbo extensionViresh Kumar1-0/+4
Allow the overlays to have .dtbo extension instead of just .dtb. This allows them to be identified easily by tools as well as humans. Allow the dtbo outform in dtc.c for the same. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Message-Id: <30fd0e5f2156665c713cf191c5fea9a5548360c0.1609926856.git.viresh.kumar@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-01-04Set last_comp_version correctly in new dtb and fix potential version issues ↵Justin Covell3-2/+5
in fdt_open_into Changes in v3: - Remove noop version sets - Set version correctly on loaded fdt in fdt_open_into Fixes: f1879e1a50eb ("Add limited read-only support for older (V2 and V3) device tree to libfdt.") Signed-off-by: Justin Covell <jujugoboom@gmail.com> Message-Id: <20201229041749.2187-1-jujugoboom@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-22tests: Fix overlay_overlay_nosugar test casePaul Barker2-5/+5
This test was accidentally skipped as the wrong test dts file was built. The fragment numbering in this sugar-free test case needed adjusting to match the numbering generated by dtc for overlay_overlay.dts. Signed-off-by: Paul Barker <pbarker@konsulko.com> Message-Id: <20201219143521.2118-1-pbarker@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-16libfdt: Tweak description of assume-aligned load helpersDavid Gibson1-7/+7
There's a small inaccuracy in the comment describing these new helpers. This corrects it, and reformats while we're there. Fixes: f98f28ab ("libfdt: Internally perform potentially unaligned loads") Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-16libfdt: Internally perform potentially unaligned loadsTom Rini3-15/+32
Commits 6dcb8ba4 "libfdt: Add helpers for accessing unaligned words" introduced changes to support unaligned reads for ARM platforms and 11738cf01f15 "libfdt: Don't use memcpy to handle unaligned reads on ARM" improved the performance of these helpers. On further discussion, while there are potential cases where we could be used on platforms that do not fixup unaligned reads for us, making this choice the default is very expensive in terms of binary size and access time. To address this, introduce and use new fdt{32,64}_ld_ functions that call fdt{32,64}_to_cpu() as was done prior to the above mentioned commits. Leave the existing load functions as unaligned-safe and include comments in both cases. Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Tom Rini <trini@konsulko.com> Message-Id: <20201211022736.31657-1-trini@konsulko.com> Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-08meson: increase default timeout for testsMarc-André Lureau1-0/+1
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201207130055.462734-4-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-08meson: do not assume python is installed, skip testsMarc-André Lureau1-6/+6
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201207130055.462734-3-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-08meson: fix -Wall warningMarc-André Lureau1-10/+12
Meson already handles Wall via the built-in warning_level option. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201207130055.462734-2-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-11-24libfdt: Check for 8-byte address alignment in fdt_ro_probe_()Tom Rini2-1/+9
The device tree must be loaded in to memory at an 8-byte aligned address. Add a check for this condition in fdt_ro_probe_() and a new error code to return if we are not. Signed-off-by: Tom Rini <trini@konsulko.com> Message-Id: <20201104130605.28874-1-trini@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-21build-sys: add meson buildMarc-André Lureau6-0/+331
The meson build system allows projects to "vendor" dtc easily, thanks to subproject(). QEMU has recently switched to meson, and adding meson support to dtc will help to handle the QEMU submodule. meson rules are arguably simpler to write and maintain than the hand-crafted/custom Makefile. meson support various backends, and default build options (including coverage, sanitizer, debug/release etc, see: https://mesonbuild.com/Builtin-options.html) Compare to the Makefiles, the same build targets should be built and installed and the same tests should be run ("meson test" can be provided extra test arguments for running the equivalent of checkm/checkv). There is no support EXTRAVERSION/LOCAL_VERSION/CONFIG_LOCALVERSION, instead the version is simply set with project(), and vcs_tag() is used for git/dirty version reporting (This is most common and is hopefully enough. If necessary, configure-time options could be added for extra versioning.). libfdt shared library is build following regular naming conventions: instead of libfdt.so.1 -> libfdt-1.6.0.so (with current build-sys), libfdt.so.1 -> libfdt.so.1.6.0. I am not sure why the current build system use an uncommon naming pattern. I also included a libfdt.pc pkg-config file, as convenience. Both Linux native build and mingw cross-build pass. CI pass. Tests are only run on native build. The current Makefiles are left in-tree, and make/check still work. Eventually, the Makefiles could be marked as deprecated, to start a transition period and avoid having to maintain 2 build systems in the near future. (run_tests.sh could eventually be replaced by the meson test runner, which would have several advantages in term of flexibility/features, but this is left for another day) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201012073405.1682782-3-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-21pylibfdt: allow build out of treeMarc-André Lureau2-10/+21
With meson, we have to support out-of-tree build. Introduce a --top-builddir option, which will default to the current directory to lookup generated filed such as version_gen.h and output directories. Other source paths are derived from the location of the setup.py script in the source tree. --build-lib is changed to be relative to the current directory, instead of relative to setup.py. This has less surprising results! Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201012073405.1682782-2-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13dtc: Fix signedness comparisons warnings: Wrap (-1)Andre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in dtc's data_copy_file(). Even though maxlen is of an unsigned type, we compare against "-1", which is passed in from the parser to indicate an unknown size. Cast the "-1" to an unsigned size to make the comparison match. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-9-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13dtc: Fix signedness comparisons warnings: change typesAndre Przywara5-14/+14
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various parts of dtc. Many variables are using signed types unnecessarily, as we never use negative value in them. Change their types to be unsigned, to prevent issues with comparisons. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13convert-dtsv0: Fix signedness comparisons warningAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in the generated lexer code. In this case we walk over an array, and never use negative indicies, so we can change the loop counter variable to be unsigned. This fixes "make convert-dtsv0", when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201012161948.23994-3-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-13libfdt: Fix kernel-doc commentsAndre Przywara1-36/+75
The API documentation in libfdt.h seems to follow the Linux kernel's kernel-doc format[1]. Running "scripts/kernel-doc -v -none" on the file reports some problems, mostly missing return values and missing parameter descriptions. Fix those up by providing the missing bits, and fixing the other small issues reported by the script. Signed-off-by: Andre Przywara <andre.przywara@arm.com> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/doc-guide/kernel-doc.rst Message-Id: <20201012165331.25016-1-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02checks: Allow PCI bridge child nodes without an addressRob Herring1-3/+1
Some PCI bridge nodes have child nodes such as an interrupt controller which are not PCI devices. Allow these nodes which don't have a unit-address. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20200928201942.3242124-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: fdt_strerror(): Fix comparison warningAndre Przywara1-2/+2
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in fdt_strerror(). Force FDT_ERRTABSIZE to be signed (it's surely small enough to fit), so that the types match. Also move the minus sign to errval, as this is actually what we use in the next line. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-7-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: fdt_get_string(): Fix sequential write comparison warningsAndre Przywara1-4/+6
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in fdt_get_string(). Introduce a new usigned variable, which holds the actual (negated) stroffset value, so we avoid negating all the other variables and have proper types everywhere. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-6-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: libfdt_wip: Fix comparison warningAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in fdt_setprop_inplace_namelen_partial(). fdt_getprop_namelen() will only return negative error values in "proplen" if the return value is NULL. So we can rely on "proplen" being positive in our case and can safely cast it to an unsigned type. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-5-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: fdt_create_with_flags(): Fix comparison warningAndre Przywara1-2/+2
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in fdt_create_with_flags(). By making hdrsize a signed integer (we are sure it's a very small number), we avoid all the casts and have matching types. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-4-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: fdt_move(): Fix comparison warningsAndre Przywara1-1/+4
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in fdt_move(). This stems from "bufsize" being passed in as a signed integer, even though we would expect a buffer size to be positive. Short of changing the prototype, check that bufsize is not negative, and cast it to an unsigned type in the comparison. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-3-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-02libfdt: fdt_add_string_(): Fix comparison warningAndre Przywara1-7/+7
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in fdt_add_string_(). Make all variables unsigned, and express the negative offset trick via subtractions in the code. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20201001164630.4980-2-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-09-25libfdt: fdt_node_offset_by_phandle(): Fix comparison warningAndre Przywara1-1/+1
With -Wsign-compare, compilers warn about a mismatching signedness in a comparison in fdt_node_offset_by_phandle(). Uses a better suited bitwise NOT operator to denote the special value of -1, which automatically results in an unsigned type. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20200921165303.9115-14-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>