Commit graph

68 commits

Author SHA1 Message Date
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
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
David Gibson
5c3513f689 Link tools and tests against libfdt shared library
Currently the libfdt based tools (fdtput, fdtget, etc.) and all the
test binaries using libfdt are linked against the static version of libfdt.
That's made it very easy in the past to forget to properly update the
version.lds file which is needed to make functions publicaly accessible
from the shared library.

To avoid problems like that in future, alter the build so that we link and
run the tests against the shared library version of libfdt.

That immediately points out several important symbols that are still
missing from the version.lds, so fix those as well.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-29 17:20:16 +11:00
AKASHI Takahiro
7fcf8208b8 libfdt: add fdt_append_addrrange()
This function will append an address range property using parent node's
"#address-cells" and "#size-cells" properties.

It will be used in implementing kdump with kexec_file_load system call
at linux kernel for arm64 once it is merged into kernel tree.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Message-Id: <20190327061552.17170-2-takahiro.akashi@linaro.org>
[dwg: Correct a SEGV error in the testcase]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-29 12:12:29 +11:00
Simon Glass
82a52ce457 libfdt: Add a test for fdt_getprop_by_offset()
This function does not have its own test at present. Add one.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-24 23:20:16 +11:00
David Gibson
d45bf1f5f2 Refine make tests_clean target
Remove some redundancy, and also clean up *.test.dt.yaml files generated
during the tests.  Also add the latter to gitignore.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 21:39:57 +11:00
Lumir Balhar
8113c00b99 pylibfdt: Allow switch to Python 3 via environment variable PYTHON
Python 2 is still the default but it can be changed by
setting environment variable PYTHON before build/test.

Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23 17:37:56 +11:00
David Gibson
ca930e20bb tests: Don't lose errors from make checkm
For unclear reasons we had some code to copy a transcript of "make checkm"
runs to a vglog.XXX file.  It's not really clear why this was there, and
it had the nasty side effect of discarding errors from run_tests.sh,
meaning that an error on the valgrind run wouldn't show up clearly in
Travis CI builds.  Remove that logic so that we see errors more clearly.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14 16:37:39 +11:00
David Gibson
b94c056b13 Make valgrind optional
Some platforms don't have valgrind support, and sometimes you simply might
not want to use valgrind.  But at present, dtc, or more specifically its
testsuite, won't compile without valgrind because we use the valgrind
client interface in some places to improve our testing and suppress false
positives.

This adds some Makefile detection to correctly handle the case where
valgrind is not available.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10 16:46:59 +10:00
David Gibson
fd06c54d47 tests: Better testing of dtc -I fs mode
Greg Kurz added a trivial test of the -I fs mode recently, which was
previously basically untested.  This is an oversight, since we
recently had a bug which completely broke it.

This replaces Greg's test with a more thorough test of -I fs mode.  We
use a test helper to create the familiar test_tree1 in "fs" form, then use
dtc -I fs to process it, and check that the results match what they
should.

We only check the content in -I fs -O dtb mode, since that's simplest,
but we do run -I fs -O dts mode as well to make sure it doesn't blow
up (the aforementioned bug caused just such a blow up, specific to -O
dts mode, for example).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10 14:20:51 +10:00
Sebastian Huber
c12b2b0c20 libfdt: fdt_address_cells() and fdt_size_cells()
Add internal fdt_cells() to avoid copy and paste.  Test error cases and
default values.  Fix typo in fdt_size_cells() documentation comment.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-20 11:56:49 +10:00
David Gibson
4b8fcc3d01 libfdt: Add fdt_check_full() function
This new function implements a complete and thorough check of an fdt blob's
structure.  Given a buffer containing an fdt, it should return 0 only if
the fdt within is structurally sound in all regards.  It doesn't check
anything about the blob's contents (i.e. the actual values of the nodes and
properties), of course.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07 11:49:17 +10:00
David Gibson
d5db5382c5 libfdt: Safer access to memory reservations
fdt_num_mem_rsv() and fdt_get_mem_rsv() currently don't sanity check their
parameters, or the memory reserve section offset in the header.  That means
that on a corrupted blob they could access outside of the range of memory
that they should.

This improves their safety checking, meaning they shouldn't access outside
the blob's bounds, even if its contents are badly corrupted.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07 11:48:20 +10:00
David Gibson
70166d62a2 libfdt: Safer access to strings section
fdt_string() is used to retrieve strings from a DT blob's strings section.
It's rarely used directly, but is widely used internally.

However, it doesn't do any bounds checking, which means in the case of a
corrupted blob it could access bad memory, which libfdt is supposed to
avoid.

This write a safe alternative to fdt_string, fdt_get_string().  It checks
both that the given offset is within the string section and that the string
it points to is properly \0 terminated within the section.  It also returns
the string's length as a convenience (since it needs to determine to do the
checks anyway).

fdt_string() is rewritten in terms of fdt_get_string() for compatibility.

Most of the diff here is actually testing infrastructure.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-06-07 11:48:20 +10:00
David Gibson
eb890c0f77 libfdt: Make fdt_check_header() more thorough
Currently fdt_check_header() performs only some rudimentary checks, which
is not really what the name suggests.  This strengthens fdt_check_header()
to check as much about the blob as is possible from the header alone:  as
well as checking the magic number and version, it checks that the total
size is sane, and that all the sub-blocks within the blob lie within the
total size.

 * This broadens the meaning of FDT_ERR_TRUNCATED to cover all sorts of
   improperly terminated blocks as well as just a structure block without
   FDT_END.

 * This makes fdt_check_header() only succeed on "complete" blobs, not
   in-progress sequential write blobs.  The only reason this didn't fail
   before was that this function used to be called by many RO functions
   which are supposed to also work on incomplete SW blobs.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07 11:47:59 +10:00
David Gibson
899d6fad93 libfdt: Improve sequential write state checking
When creating a tree with the sequential write functions, certain things
have to be done in a certain order.  You must create the memory reserve map
and only then can you create the actual tree structure.

The -FDT_ERR_BADSTATE return code is for if you try to do things out of
order.  However, we weren't checking that very thoroughly, so it was
possible to generate a corrupted blob if, for example, you started calling
fdt_begin_node() etc. before calling fdt_finish_reservemap().

This makes the state checking more thorough disallow that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07 11:45:48 +10:00
kevans@FreeBSD.org
51b3a16338 Makefile.tests: Add LIBDL make(1) variable for portability sake
Some platforms (many, if not all, of the *BSD projects) do not provide a libdl,
and instead provide the same functionality in libc. Instead of forcing these
platforms to patch out the link against libdl, add a LIBDL make(1) variable to
allow the -ldl argument to be excluded easily via make(1) arguments.

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-01-04 15:36:44 +11:00
Simon Glass
90db6d9989 pylibfdt: Allow setup.py to operate stand-alone
At present we require that setup.py is executed from the Makefile, which
sets up various important things like the list of files to build and the
version number.

However many installation systems expect to be able to change to the
directory containing setup.py and run it. This allows them to support (for
example) building/installing for multiple Python versions, varying
installation paths, particular C flags, etc.

The problem in implementing this is that we don't want to duplicate the
information in the Makefile. A common solution (so I am told) is to parse
the Makefile to obtain the required information.

Update the setup.py script to read a few Makefiles when it does not see
the required information in its environment. This allows installation
using:

   ./pylibfdt/setup.py install

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Pantelis Antoniou
9637e3f772 tests: Add check_path test
Add a test that checks for existence or not of a node.
It is useful for testing the various cases when generating
symbols and fixups for dynamic device tree objects.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09 13:26:39 +11:00
Maxime Ripard
aea8860d83 tests: Add tests cases for the overlay code
Add some test infrastructure to test that the overlay can be merged, but
also that poorly formatted fixups would fail as expected.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[dwg: Don't execute bad overlay tests without overlay aware dtc]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-06 20:20:02 +11:00
Maxime Ripard
d29126c90a libfdt: Add iterator over properties
Implement a macro based on fdt_first_property_offset and
fdt_next_property_offset that provides a convenience to iterate over all
the properties of a given node.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
[dwg: Removed a stray trailing blank line]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-28 15:29:13 +10:00
Thierry Reding
2218387a8c fdt: Add a function to count strings
Given a device tree node and a property name, the fdt_stringlist_count()
function counts the number of strings found in the property value.

This also adds a new error code, FDT_ERR_BADVALUE, that the function
returns when it encounters a non-NUL-terminated string list.

Signed-off-by: Thierry Reding <treding@nvidia.com>
[Changed testcase name --dwg]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-30 13:16:35 +10:00
David Gibson
40f7f576c8 libfdt: Add helpers to read #address-cells and #size-cells
This patch makes a small start on libfdt functions which actually help to
parse the contents of device trees, rather than purely manipulating the
tree's structure.

We add simple helpers to read and sanity check the #address-cells and
#size-cells values for a given node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-05-12 16:01:09 +10:00
Simon Glass
4e76ec796c libfdt: Add fdt_next_subnode() to permit easy subnode iteration
Iterating through subnodes with libfdt is a little painful to write as we
need something like this:

for (depth = 0, count = 0,
	offset = fdt_next_node(fdt, parent_offset, &depth);
     (offset >= 0) && (depth > 0);
     offset = fdt_next_node(fdt, offset, &depth)) {
	if (depth == 1) {
		/* code body */
	}
}

Using fdt_next_subnode() we can instead write this, which is shorter and
easier to get right:

for (offset = fdt_first_subnode(fdt, parent_offset);
     offset >= 0;
     offset = fdt_next_subnode(fdt, offset)) {
	/* code body */
}

Also, it doesn't require two levels of indentation for the loop body.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-04-28 07:30:49 -05:00
Stephen Warren
1ff3d3f8de dtc: cpp co-existence: allow names starting with # to be escaped
The device tree language as currently defined conflicts with the C pre-
processor in one aspect - when a property or node name begins with a #
character, a pre-processor would attempt to interpret it as a directive,
fail, and most likely error out.

This change allows a property/node name to be prefixed with \. This
prevents a pre-processor from seeing # as the first non-whitespace
character on the line, and hence prevents the conflict. \ was previously
an illegal character in property/node names, so this change is
backwards compatible. The \ is stripped from the name during parsing
by dtc.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-28 09:23:43 -05:00
Stephen Warren
5f0c3b2d62 dtc: Basic integer expressions
Written by David Gibson <david@gibson.dropbear.id.au>. Additions by me:
* Ported to ToT dtc.
* Renamed cell to integer throughout.
* Implemented value range checks.
* Allow U/L/UL/LL/ULL suffix on literals.
* Enabled the commented test.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
2012-04-09 08:42:05 -05:00
Jon Loeliger
1456da7e2d Introduce ${TESTS_BIN} in Makefiles to identify tested executables. 2012-01-21 15:24:51 -06:00
David Gibson
97b909f852 libfdt: Activate testcase for appending properties
Commit a31e3ef83b introduced new libfdt
functions to append to existing properties.  It also included a test case
for this, but neglected to update the Makefile and run_tests.sh script
to actually build and execute this testcase.

This patch corrects the oversight.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-01-11 08:27:40 -06:00
Anton Staaf
033089f290 dtc: Add support for variable sized elements
Elements of size 8, 16, 32, and 64 bits are supported.  The new
/bits/ syntax was selected so as to not pollute the reserved
keyword space with uint8/uint16/... type names.

With this patch the following property assignment:

    property = /bits/ 16 <0x1234 0x5678 0x0 0xffff>;

is equivalent to:

    property = <0x12345678 0x0000ffff>;

It is now also possible to directly specify a 64 bit literal in a
cell list, also known as an array using:

    property = /bits/ 64 <0xdeadbeef00000000>;

It is an error to attempt to store a literal into an element that is
too small to hold the literal, and the compiler will generate an
error when it detects this.  For instance:

    property = /bits/ 8 <256>;

Will fail to compile.  It is also an error to attempt to place a
reference in a non 32-bit element.

The documentation has been changed to reflect that the cell list
is now an array of elements that can be of sizes other than the
default 32-bit cell size.

The sized_cells test tests the creation and access of 8, 16, 32,
and 64-bit sized elements.  It also tests that the creation of two
properties, one with 16 bit elements and one with 32 bit elements
result in the same property contents.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-10-11 12:58:30 -05:00
Simon Glass
1c25c0d520 Make testutils use utilfdt
The load_blob() and save_blob() functions are very similar to the utilfdt
versions. This removes the duplicated code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:50:34 -05:00
Simon Glass
36204fdf74 Add fdt read/write utility functions
This adds higher-level libfdt operations for reading/writing an fdt
blob from/to a file, as well as a function to decode a data type string
as will be used by fdtget, fdtput.

This also adds a few tests for the simple type argument supported by
utilfdt_decode_type.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:49:33 -05:00
Anton Staaf
a4ea2fa951 dtc: Support character literals in cell lists
With this patch the following property assignment:

    property = <0x12345678 'a' '\r' 100>;

is equivalent to:

    property = <0x12345678 0x00000061 0x0000000D 0x00000064>

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 09:24:31 -05:00
David Gibson
e3b32b75b5 dtc: Extend and better test dtbs_equal utility programs (resend)
The dtbs_equal_ordered test program is used to implement a number of
testcases.  However, the test program itself has never been
particularly well tested.  In addition there are testcases coming in
future for which it would be useful to have a corresponding
"dtbs_equal_unordered" which checks for equality of device trees, not
considering the internal ordering of elements.  Finally, for some
tests we may want it would be useful to check trees for equality with
the PASS case being when they are *not* equal.

This patch addresses all of the above.  A dtbs_equal_unordered is
added, and both it and the existing dtbs_equal_ordered program now
take a -n option to make the PASS case be where the trees are not
equal.  A number of example trees with slight modifications from
test_tree1 are used to verify that both these programs correctly
identify when the tree is altered, and a dtb_reverse program is used
to verify that the unordered version does not depend on internal
ordering.  These new testcases for the equality testing programs are
split out into a new test group in run_tests.sh.

dtbs_equal_unordered uses the new property iteration functions, and so
this also acts as further testing for those functions.
dtbs_equal_unordered will be useful for further testing the recently
added tree-merging code and its upcoming extensions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-04-30 08:36:54 -05:00
David Gibson
d75b33af67 Support ePAPR compliant phandle properties
Currently, the Linux kernel, libfdt and dtc, when using flattened
device trees encode a node's phandle into a property named
"linux,phandle".  The ePAPR specification, however - aiming as it is
to not be a Linux specific spec - requires that phandles be encoded in
a property named simply "phandle".

This patch adds support for this newer approach to dtc and libfdt.
Specifically:

	- fdt_get_phandle() will now return the correct phandle if it
          is supplied in either of these properties

	- fdt_node_offset_by_phandle() will correctly find a node with
          the given phandle encoded in either property.

	- By default, when auto-generating phandles, dtc will encode
          it into both properties for maximum compatibility.  A new -H
          option allows either only old-style or only new-style
          properties to be generated.

	- If phandle properties are explicitly supplied in the dts
	  file, dtc will not auto-generate ones in the alternate format.

	- If both properties are supplied, dtc will check that they
          have the same value.

	- Some existing testcases are updated to use a mix of old and
          new-style phandles, partially testing the changes.

	- A new phandle_format test further tests the libfdt support,
          and the -H option.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-26 15:06:17 -06:00
David Gibson
b31b271f91 Fix dtc bugs for 64-bit compile
I've just tested building dtc as an x86_64 binary on a 32-bit i386
host by using:
	make CC="gcc -m64"
This patch fixes a handful of minor bugs thus discovered:

 * There is a printf() type mismatch on 64-bit in value-labels.c

 * For the tests which use libdl, we were using the GNU make feature
where it will find libdl.so given a dependency in the form '-ldl'.
But this built-in make logic doesn't know we're compiling 64-bit so
finds the 32-bit version of the library.  We avoid using this and
instead explicitly pass -ldl to CC, which being the 64-bit version
does know where to look.

 * To process dtc's asm output into .so files, run_tests.sh was
directly invoking the (default instance of) the assembler and linker.
Instead invoke these via the CC driver, and allow that to be overriden
from the make environment.

 * The x86_64 assembler doesn't 0 fill with the .balign directive
(presumably it is NOP filling).  That doesn't produce strictly
incorrect trees, but it is confusing and confounds are testcases which
do byte-by-byte comparison of the trees produced by asm output with
direct dtb output (which does 0 pad where necessary, of course).  This
patch uses the optional second argument to .balign to force gas to
zero-fill instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-11 21:41:14 -06:00
David Gibson
c623fe5c21 Fix bug in -Odts with properties containing multiple terminating nulls
When in -Odts mode, dtc will not produce correct output for
string-like properties which have more than one \0 character at the
end of the property's bytestring.  In fact, it generates output which
is not syntactically correct.  This patch fixes the bug, and adds a
testcase for future regressions here.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-11 07:34:01 -06:00
David Gibson
bae93e8992 dtc: Add testcases for labels within values
This patch adds a testcase using asm output mode to check that labels
within property values are correctly processed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-02-03 08:38:05 -06:00
David Gibson
26d93f6c92 dtc: Make asm output more portable and add testcases
This patch adds some testcases for dtc's -Oasm mode.  Specifically it
checks that building the asm will result in the same device tree blob
in memory as -Odtb mode would produce, for a variety of trees.  This
test uncovered two difficulties with our current -Oasm output, both of
which are addressed in this patch as well.

First, -Oasm output would only be correct if assembled for a
big-endian target.  Usually that would be the case, when building
device trees into a firmware or similar.  However this makes life
inconvenient for testing on a little-endian target, and one can think
up use cases where a program running on a little endian host might
want to embed a device tree for a big-endian target.  This patch
therefore changes -Oasm output to use .byte directives instead of
.long throughout in order to generate byte-for-byte identical trees
regardless of the endianness of the assembler target.

Second, -Oasm output emitted several #define statements which were
then used in the innards of the output - i.e. it assumed the output
would be processed by cpp before being assembled.  That may not be
convenient in all build environments, and in any case doesn't work
well with the above fix.  So, -Oasm output no longer needs to be
preprocessed before assembling.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-02-03 08:38:01 -06:00
Josh Boyer
6272182b41 libfdt: Introduce libfdt shared library
Build a libfdt shared library in addition to the existing .a that is
created.  Symbol versioning is used from the libfdt/version.lds script.

Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
2009-01-02 09:00:52 -06:00
Jon Loeliger
68f98d7b8a Rearrange ftdump and convert-dtsv0 into sub-Makefiles.
Follows the model of the existing sub-Makefiles for dtc.

Adjust $(BIN) definition to represent installable bin programs
and use it as the list of installed programs rather than using
an enumerated list in the install target.

Adjust the tests/Makefile to clean up properly still.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 10:50:28 -05:00
David Gibson
9c83115351 libfdt: Add function to explicitly expand aliases
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias.  This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-02 08:49:51 -05:00
Kumar Gala
02cc83540b libfdt: Add support for using aliases in fdt_path_offset()
If the path doesn't start with '/' check to see if it matches some alias
under "/aliases" and substitute the matching alias value in the path
and retry the lookup.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-14 10:24:58 -05:00
David Gibson
e37ec7d588 dtc: Add support for binary includes.
On Wed, Jun 04, 2008 at 09:26:23AM -0500, Jon Loeliger wrote:
> David Gibson wrote:
>
>> But as I said that can be dealt with in the future without breaking
>> compatibility.  Objection withdrawn.
>>
>
> And on that note, I officially implore Scott to
> re-submit his binary include patch!

Scott's original patch does still have some implementation details I
didn't like.  So in the interests of saving time, I've addressed some
of those, added a testcase, and and now resubmitting my revised
version of Scott's patch.

dtc: Add support for binary includes.

A property's data can be populated with a file's contents
as follows:

node {
	prop = /incbin/("path/to/data");
};

A subset of a file can be included by passing start and size parameters.
For example, to include bytes 8 through 23:

node {
	prop = /incbin/("path/to/data", 8, 16);
};

As with /include/, non-absolute paths are looked for in the directory
of the source file that includes them.

Implementation revised, and a testcase added by David Gibson

Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Scott Wood <scottwood@freescale.com>
2008-06-19 10:01:14 -05:00
David Gibson
a84c065f44 dtc: Add program to convert dts files from v0 to v1
This patch adds a new utility program, convert-dtsv0, to the dtc
sources.  This program will convert dts files from v0 to v1,
preserving comments and spacing.  It also includes some heuristics to
guess an appropriate base to use in the v1 output (so it will use hex
for the contents of reg properties and decimal for clock-frequency
properties, for example).  They're limited and imperfect, but not
terrible.

The guts of the converter program is a modified version of the lexer
from dtc itself.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 21:18:47 -05:00
David Gibson
548767f42e dtc: Rework handling of boot_cpuid_phys
Currently, dtc will put the nonsense value 0xfeedbeef into the
boot_cpuid_phys field of an output blob, unless explicitly given
another value with the -b command line option.  As well as being a
totally unuseful default value, this also means that dtc won't
properly preserve the boot_cpuid_phys field in -I dtb -O dtb mode.

This patch reworks things to improve the boot_cpuid handling.  The new
semantics are that the output's boot_cpuid_phys value is:
	the value given on the command line if -b is used
otherwise
	the value from the input, if in -I dtb mode
otherwise
	0

Implementation-wise we do the following:
	- boot_cpuid_phys is added to struct boot_info, so that
structure now contains all of the blob's semantic information.
	- dt_to_blob() and dt_to_asm() output the cpuid given in
boot_info
	- dt_from_blob() fills in boot_info based on the input blob
	- The other dt_from_*() functions just record 0, but we can
change this easily if e.g. we invent a way of specifying the boot cpu
in the source format.
	- main() overrides the cpuid in the boot_info between input
and output if -b is given

We add some testcases to check this new behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 14:12:15 -05:00
David Gibson
6a6c972cdf dtc: Clean up included Makefile fragments
Currently the Makefile.dtc and Makefile.libfdt fragments include a
number of things that seemed like they might be useful for other
projects embedding the pieces, or for a make dist target.

Well, we have no make dist target, it's become fairly unclear that
these things would actually be useful to embedders (the kernel
certainly doesn't use them), and it's a bunch of stuff with no current
users.

This patch, therefore, removes a bunch of unused definitions from the
Makefile fragments.  It also removes a dependency declared in
Makefile.libfdt (of libfdt.a on the constituent .o files) which was
incorrect (wrong path), and if corrected would be redundant with the
similar dependency in the top-level makefile.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 14:07:53 -05:00
David Gibson
a90b5905fe libfdt: More tests of NOP handling behaviour
In light of the recently discovered bug with NOP handling, this adds
some more testcases for NOP handling.  Specifically, it adds a helper
program which will add a NOP tag after every existing tag in a dtb,
and runs the standard battery of tests over trees mangled in this way.

For now, this does not add a NOP at the very beginning of the
structure block.  This causes problems for libfdt at present, because
we assume in many places that the root node's BEGIN_NODE tag is at
offset 0.  I'm still contemplating what to do about this (with one
option being simply to declare such dtbs invalid).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-02-18 08:21:52 -06:00
David Gibson
089adb9964 libfdt: Fix NOP handling bug in fdt_add_subnode_namelen()
fdt_add_subnode_namelen() has a bug if asked to add a subnode to a
node which has NOP tags interspersed with its properties.  In this
case fdt_add_subnode_namelen() will put the new subnode before the
first NOP tag, even if there are properties after it, which will
result in an invalid blob.

This patch fixes the bug, and adds a testcase for it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-02-14 08:02:41 -06:00
David Gibson
82b327d380 libfdt: Add fdt_set_name() function
This patch adds an fdt_set_name() function to libfdt, mirroring
fdt_get_name().  This is a r/w function which alters the name of a
given device tree node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-11 07:40:40 -06:00
David Gibson
5ba0086bfd dtc: More detailed testing of tree checks
This patch modifies the dtc-checkfails.sh testcase wrapper so that
instead of testing just that dtc fails with a particular error code on
the sample input, it scans dtc's stderr output looking for a message
that dtc failed a specific check or checks.  This has several advantages:
	- It means we more precisely check dtc's checking behaviour
	- It means we can check for generation of warnings using the
same script
	- It means we can test cases where dtc should generate
multiple errors or warnings from different checks

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-06 09:15:19 -06:00