Commit graph

366 commits

Author SHA1 Message Date
Bob Badour
8fc610ffc8 Clean up license texts.
Test: m droid dist

Change-Id: Ib37f6a039098c2f934c8f040682703b519043fc5
2022-08-11 11:53:15 -07:00
Tero Tervala
7ad60734b1 Allow static building with meson
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-27 16:38:45 +10:00
Tero Tervala
fd9b8c96c7 Allow static building with make
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-27 16:35:29 +10:00
Tero Tervala
c7c7f17a83 Fix test script to run also on dash shell
/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-26 21:39:07 +10:00
Tero Tervala
01f23ffe16 Add missing relref_merge test to meson test list
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-07-02 16:37:02 +10:00
Luca Weiss
ed310803ea pylibfdt: add FdtRo.get_path()
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-04-20 12:55:14 +10:00
Ahmad Fatoum
26c54f840d tests: add test cases for label-relative path references
Newly added &{label/path} feature doesn't yet have any tests. Add some.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2022-01-25 17:10:47 +11:00
David Gibson
ff5afb96d0 Handle integer overflow in check_property_phandle_args()
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-29 17:04:18 +11:00
Ahmad Fatoum
cd5f69cbc0 tests: setprop_inplace: use xstrdup instead of unchecked strdup
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-28 20:10:57 +11:00
Luca Weiss
a04f690250 pylibfdt: add Property.as_*int*_array()
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-28 15:30:33 +11:00
Luca Weiss
83102717d7 pylibfdt: add Property.as_stringlist()
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-28 15:29:31 +11:00
Rafał Miłecki
17739b7ef5 Support 'r' format for printing raw bytes with fdtget
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-12-09 17:48:58 +11:00
Rob Herring
0a3a9d3449 checks: Add an interrupt-map check
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-21 15:48:41 +11:00
Rob Herring
37fd700685 treesource: Maintain phandle label/path on output
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-10-11 16:20:53 +11:00
David Gibson
d24cc189dc asm: Use assembler macros instead of cpp macros
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-27 11:54:56 +10:00
Rob Herring
ff3a30c115 asm: Use .asciz and .ascii instead of .string
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-09-25 16:11:41 +10:00
Andre Przywara
d966f08fcd tests: Fix signedness comparisons warnings
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-21 15:25:44 +10:00
Rob Herring
0c3fd9b6ac checks: Drop interrupt_cells_is_cell check
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-08 11:58:43 +10:00
Ilya Lipnitskiy
c8bddd1060 tests: add a positive gpio test case
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-04 14:45:20 +10:00
Simon Glass
a2def54799 libfdt: Check that the root-node name is empty
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-23 12:13:06 +11:00
Simon Glass
4ca61f84dc libfdt: Check that there is only one root node
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-23 11:56:34 +11:00
Paul Barker
f7e5737f26 tests: Fix overlay_overlay_nosugar test case
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-22 20:45:42 +11:00
Marc-André Lureau
bab85e48a6 meson: increase default timeout for tests
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-08 15:30:28 +11:00
Marc-André Lureau
f8b4609882 meson: do not assume python is installed, skip tests
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-08 15:30:28 +11:00
Marc-André Lureau
67849a3279 build-sys: add meson build
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-21 14:36:07 +11:00
Andre Przywara
81e0919a3e checks: Add interrupt provider test
An interrupt provider (an actual interrupt-controller node or an
interrupt nexus) should have both #address-cells and #interrupt-cells
properties explicitly defined.

Add an extra test for this. We check for the #interrupt-cells property
already, but this does not cover every controller so far, only those that
get referenced by an interrupts property in some node. Also we miss
interrupt nexus nodes.

A missing #address-cells property is less critical, but creates
ambiguities when used in interrupt-map properties, so warn about this as
well now.
This removes the now redundant warning in the existing interrupts test.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20200515141827.27957-2-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-05-18 14:26:12 +10:00
David Gibson
1f9a417508 tests: Allow running the testsuite on already installed binary / libraries
Currently the test runner script always expects to be run from within the
tests/ subdirectory of a dtc source tree: it looks for dtc and other
binaries in the parent of the current directory and for the libfdt shared
library in ../libfdt.

That works great with make check and for testing a build you've just made.
However, sometimes it's useful to test a dtc & libfdt which have already
been installed on the system, or which for whatever reason are located
somewhere else.

This patch allows the test runner script to do this when TEST_BINDIR and/or
TEST_LIBDIR environment variables are set.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 16:38:04 +11:00
David Gibson
c5995ddf4c tests: Honour NO_YAML make variable
Support for YAML output in dtc is optional (to cover systems that don't
have libyaml).  Currently the tests for yaml output test if the libyaml
package is locally installed.

That duplicates similar logic in the Makefile, and worse it will cause
failed tests if the user explicitly disables YAML support, rather than
simply not having libyaml installed.

Fix this by having the test script use the NO_YAML variable exported by
make.  Fall back to the current test if the variable isn't set, such as
when running the script manually.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 16:10:06 +11:00
David Gibson
e4ce227e89 tests: Properly clean up .bak file from tests
One of our testcases creates a .bak file from invoking sed.  Fix that to be
removed by make clean, and also ignore it in git to avoid clutter.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 16:05:31 +11:00
David Gibson
9b75292c33 tests: Honour $(NO_PYTHON) flag from Makefile in run_tests.sh
Currently the test script bases whether to run the Python tests on whether
it can see a built Python module.  That can easily be fooled if there is
a stale module there.

Instead, have it actually look at the NO_PYTHON variable exported from the
Makefile.  If the variable doesn't exist (such as if we're running the
script manually) fall back on the old logic.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 16:03:28 +11:00
David Gibson
95ec8ef706 tests: No need to explicitly pass $PYTHON from Make to run_tests.sh
Make automatically passes its variables through the environment, so
we don't need to explicitly copy this one into the test script.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 15:38:48 +11:00
David Gibson
2b5f62d109 tests: Let run_tests.sh run Python tests without Makefile assistance
Currently run_tests.sh needs the $PYTHON environment variable set to
correctly run pylibfdt tests.  The Makefile does this for make check, but
it breaks if the script is run manually.  Add a fallback to handle that
case.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 15:32:47 +11:00
Rob Herring
76b43dcbd1 checks: Add 'dma-ranges' check
Generalize the existing 'ranges' check to also work for 'dma-ranges'
which has the same parsing requirements.

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20200303193931.1653-1-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04 10:30:12 +11:00
Ed Maste
743000931b tests: default to 'cc' if CC not set
By default FreeBSD does not have 'gcc' in the PATH (on common platforms).
As on Linux 'cc' is available as a link to the default compiler (Clang or
GCC), so just use 'cc'.

Signed-off-by: Ed Maste <emaste@freebsd.org>
Message-Id: <20191115155108.39488-1-emaste@freefall.freebsd.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-16 09:16:28 +11:00
Stefan Mavrodiev
adcd676491 Add test-case for trailing zero
If there is trailing zero, fdtget adds extra chacarter to the
property value. Thus comparing the expected with the actual
value, an error is emitted.

Signed-off-by: Stefan Mavrodiev <stefan@olimex.com>
Message-Id: <20191111080444.9819-3-stefan@olimex.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-15 20:42:47 +11:00
Simon Glass
7a22132c79 pylibfdt: Adjust for deprecated test methods
Python recently deprecated some test methods in favour of others. Adjust
the code to avoid warnings.

Signed-off-by: Simon Glass <sjg@chromium.org>
Message-Id: <20191113012410.62550-1-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-15 20:21:21 +11:00
Ed Maste
dbe80d577e tests: add extension to sed -i for GNU/BSD sed compatibility
BSD sed requires that an extension is provided to the -i (in-place edit)
flag, which may immediately follow the -i or may be separated by a space -
sed -i .bak and sed -i.bak are equivalent.  The extension is optional with
GNU sed, but if provided must immediately follow the -i.  Thus, sed -i.bak
behaves identically with both GNU and BSD sed.

Signed-off-by: Ed Maste <emaste@freebsd.org>
Message-Id: <20191114203615.2866-1-emaste@freefall.freebsd.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-15 20:08:25 +11:00
Simon Glass
fdf3f6d897 pylibfdt: Correct the type for fdt_property_stub()
This function should use a void * type, not char *. This causes an error:

TypeError: in method 'fdt_property_stub', argument 3 of type 'char const *'

Fix it and update the tests.

Signed-off-by: Simon Glass <sjg@chromium.org>
Message-Id: <20191025010226.34378-1-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-10-27 17:50:53 +01:00
Marc-André Lureau
430419c281 tests: fix some python warnings
Fixes:
ResourceWarning: unclosed file <_io.BufferedReader name='test_tree1.dtb'>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191009102025.10179-9-marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-10-14 17:09:13 +11:00
Marc-André Lureau
4c3c4ccb99 dumptrees: pass outputdir as first argument
Instead of outputing files to current directory, allow to specificy an
output directory. This helps with meson build system out-of-tree support.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191009102025.10179-4-marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-10-14 16:20:32 +11:00
Marc-André Lureau
aa522da9ff tests: allow out-of-tree test run
meson runs out-of-tree, add absolute path location where necessary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191009102025.10179-3-marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-10-14 16:19:29 +11:00
David Gibson
b8d6eca782 libfdt: Allow #size-cells of 0
c12b2b0c20 "libfdt: fdt_address_cells() and fdt_size_cells()" introduced
a bug as it consolidated code between the helpers for getting
#address-cells and #size-cells.  Specifically #size-cells is allowed to
be 0, and is frequently found so in practice for /cpus.  IEEE1275 only
requires implementations to handle 1..4 for #address-cells, although one
could make a case for #address-cells == #size-cells == 0 being used to
represent a bridge with a single port.

While we're there, it's not totally obvious that the existing implicit
cast of a u32 to int will give the correct results according to strict C,
although it does work in practice.  Straighten that up to cast only after
we've made our range checks.

Reported-by: yonghuhaige via https://github.com/dgibson/dtc/issues/28
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-07-28 16:31:44 +10:00
David Gibson
5c715a4477 fdtoverlay: Ignore symbols in overlays which don't apply to the target tree
Symbols from overlays are merged into the target tree, and are required to
have the form:
	/fragment@XXX/__overlay__/...
If any symbols don't have this form, the overlay is rejected.

But there's not really anything wrong with an overlay having "local"
labels referring to a fragment node or some other metadata, that's not
expected to end up in a target tree.

So change our overlay application to simply ignore such symbols rather than
fail.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-07-04 15:10:01 +10:00
David Gibson
b993534748 fdtoverlay: Allow adding labels to __overlay__ nodes in overlays
When applying overlays, we merge symbols from the overlay into the target
tree.  At the moment the logic for this assumes all symbols in the overlay
are attached to a node of the form:
	/fragment@XXX/__overlay__/relative/path

And will end up applied to the relative/path node under the fragment's
target.

However, this disallows the case of a symbol in the form just:
	/fragment@XXX/__overlay__

This does have a pretty obvious sensible meaning: attach the new symbol
directly to the fragment's target, but we don't currently do that.

It's pretty easy to workaround this limitation in one's overlays, but it's
also easy to handle in the overlay applying code, so we might as well
extend it to cover this case.

Reported-by: Christophe Braillon
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-07-04 14:39:02 +10:00
Appana Durga Kedareswara rao
d6de81b81b pylibfdt: Add support for fdt_get_alias()
Add this into the class to simplify use of this function.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.rao@xilinx.com>
Message-Id: <1562130487-27028-1-git-send-email-appana.durga.rao@xilinx.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-07-04 12:56:47 +10:00
Fabrice Gasnier
ad57e4574a tests: Add a failed test case for 'fdtoverlay' with long target path
This adds a test case to demonstrate some issue seen when applying
overlays using 'fdtoverlay'. It fails with FDT_ERR_NOSPACE:
- with long target path
- symbols in order to use these nodes in possible subsequent overlay.

This is seen with this patch, by running:
$ make check # Reports a failed test
$ ./fdtoverlay -i tests/overlay_base.test.dtb -o out.dtb \
  tests/overlay_overlay_long_path.fdoverlay.test.dtb
  Failed to apply tests/overlay_overlay_long_path.fdoverlay.test.dtb (-3)

This overlay fails to apply, because dtb size is close to modulo 1024
bytes chunk: utilfdt_read() -> utilfdt_read_err() -> bufsize = 1024.

As there is not much extra space in the blob to resolve symbols (long
target path), it fails with FDT_ERR_NOSPACE. In fdtoverlay, size is :
 /* grow the blob to worst case */
 blob_len = fdt_totalsize(blob) + total_len;

I can see assumption is made that result should be lower than:
- base fdt size + overlay size. Is there a simple way to find to know
what the final size is?
I'm not sure what the correct fix might be, for such (worst) case?
Similar issue is also seen in u-boot/common/image-fit.c that implements
similar approach (e.g. base fdt size + overlay size).

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Message-Id: <1538553302-1353-1-git-send-email-fabrice.gasnier@st.com>
[dwg: To avoid breaking bisection, I committed this after a fix, so
 the "failed" description is no longer accurate]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-30 15:48:40 +10:00
Rob Herring
c4ffc05574 tests: Replace license boilerplate with SPDX tags
Replace instances in tests of mostly LGPL-2.1 license boilerplate
with SPDX tags.

Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20190620211944.9378-5-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-06-21 21:06:10 +10:00
Thomas Huth
825146d13d Fix typos in various documentation and source files
The typos have been discovered with the "codespell" utility.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20190520081209.20415-1-thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-05-21 10:01:01 +10:00
Nicholas Piggin
ce01b21098 libfdt: Add FDT_CREATE_FLAG_NO_NAME_DEDUP flag that trades size for speed
Searching for duplicate names scales O(n^2) with the number of names
added to a fdt, which can cause a noticable slowdown with larger device
trees and very slow CPU cores.

Add FDT_CREATE_FLAG_NO_NAME_DEDUP that allow the caller to trade fdt size
for speed in the creation process.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-Id: <20190509094122.834-4-npiggin@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-05-10 11:53:10 +10:00
Nicholas Piggin
228a44cce8 libfdt: Ensure fdt_add_property frees allocated name string on failure
If fdt_add_property or fdt_property_placeholder fail after allocating
a string for the name, they return without freeing that string. This
does not change the structure of the tree, but in very specific cases
it could lead to undesirable space consumption.

Fix this by rolling back the string allocation in this situation.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-Id: <20190509094122.834-2-npiggin@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-05-10 11:53:10 +10:00