Commit graph

82 commits

Author SHA1 Message Date
Simon Glass
7fcbef2757 fdtget: Add -d to provide a default value
Sometimes the requested node or property is not present in the device
tree. This option provides a way of reporting a default value in this
case, rather than halting with an error.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-03-07 16:40:28 -06:00
Simon Glass
097ec97c1a fdtget: Fix multiple arg bug and add test for it
There is a rather unfortunate bug in fdtget in that if multiple argument
sets are provided, it just repeats displaying the first set ones for
each set.

Fix this bug and add a test for it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-03-07 13:25:03 -06:00
David Gibson
0b3b46e019 Generate test data for fdtput more sensibly
Currently run_tests.sh generates several files of text test data.  The
procedure it uses for this is somewhat torturous and has several problems:
 * Since the test data is derived from a dts file, a cursory glance at the
test output suggests something is wrong with the processing of that dts.
This is misleading since in fact it's just being used as an arbirary
string.
 * Since the base input has linefeeds removed, the head and sort commands
used later have no effect.
 * Although an attempt is made to get rid of characters which the shell
will mangle, it's not thorough enough.  Specifically it leaves in \ which
means that some string escapes found in the input data can get expanded
somewhere along the line in some shells.

This patch, therefore, replaces this generation of test data with a
pre-canned "Lorem ipsum" of approximately 2k.  On my system, where /bin/sh
is dash, this fixes a test failure due to the aforementioned string
escapes being evaluated on one but not the other of the two comparison
paths (I haven't tracked down exactly where the expansion is happening).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03 08:42:50 -06:00
David Gibson
15b23d21a6 Clean up invocation of fdt{get,put} tests
This patch cleans up how the fdtget and fdtput tests are invoked.
Specifically we no longer hide the full command lines with a wrapper
function - this makes it possible to distinguish fdtget from similar
fdtput tests and makes it easier to work out how to manually invoke an
individual failing test.

In addition, we remove the testing for errors from the
fdt{get,put}-runtest.sh script, instead using an internal wrapper
analagous to run_wrap_test which can test for any program invocation
that's expected to return an error.

For a couple of the fdtput tests this would result in printing out
ludicrously large command lines.  Therefore we introduce a new
mechanism to cut those down to something reasonable.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03 08:39:50 -06:00
David Gibson
a90b5b1491 Remove bashism from run_tests.sh
The patches introducing fdtget and fdtput inserted a peculiar bashism to
run_tests.sh using non-portable assignment within an (( )) expression.
This patch fixes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03 08:37:32 -06:00
Simon Glass
1ede50c355 Add fdtput utility to write property values to a device tree
This simple utility allows writing of values into a device tree from the
command line. It aimes to be the opposite of fdtget.

What is it for:
- Updating fdt values when a binary blob already exists
   (even though source may be available it might be easier to use this
    utility rather than sed, etc.)
- Writing machine-specific fdt values within a build system

To use it, specify the fdt binary file on command line followed by the node
and property to set. Then, provide a list of values to put into that
property. Often there will be just one, but fdtput also supports arrays and
string lists.

fdtput does not try to guess the type of the property based on looking at
the arguments. Instead it always assumes that an integer is provided. To
indicate that you want to write a string, use -ts. You can also provide
hex values with -tx.

The command line arguments are joined together into a single value. For
strings, a nul terminator is placed between each string when it is packed
into the property. To avoid this, pass the string as a single argument.

Usage:
	fdtput <options> <dt file> <<node> <property> [<value>...]
Options:
	-t <type>	Type of data
	-v		Verbose: display each value decoded from command line
	-h		Print this help

<type>	s=string, i=int, u=unsigned, x=hex
	Optional modifier prefix:
		hh or b=byte, h=2 byte, l=4 byte (default)

To read from stdin and write to stdout, use - as the file. So you can do:

cat somefile.dtb | fdtput -ts - /node prop "My string value" > newfile.dtb

This commit also adds basic tests to verify the major features.

Signed-off-by: Simon Glass <sjg@chromium.org>
2012-01-21 15:08:39 -06:00
Simon Glass
68d057f20d Add fdtget utility to read property values from a device tree
This simply utility makes it easy for scripts to read values from the device
tree. It is written in C and uses the same libfdt as the rest of the dtc
package.

What is it for:
- Reading fdt values from scripts
- Extracting fdt information within build systems
- Looking at particular values without having to dump the entire tree

To use it, specify the fdt binary file on command line followed by a list of
node, property pairs. The utility then looks up each node, finds the property
and displays the value.

Each value is printed on a new line.

fdtget tries to guess the type of each property based on its contents. This
is not always reliable, so you can use the -t option to force fdtget to decode
the value as a string, or byte, etc.

To read from stdin, use - as the file.

Usage:
	fdtget <options> <dt file> [<node> <property>]...
Options:
	-t <type>	Type of data
	-h		Print this help

<type>	s=string, i=int, u=unsigned, x=hex
	Optional modifier prefix:
		hh or b=byte, h=2 byte, l=4 byte (default)

Signed-off-by: Simon Glass <sjg@chromium.org>
2012-01-21 15:08:36 -06:00
Stephen Warren
69df9f0de2 dtc: Implement -d option to write out a dependency file
This will allow callers to rebuild .dtb files when any of the /include/d
.dtsi files are modified, not just the top-level .dts file.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-01-13 07:23:58 -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
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
37c0b6a091 dtc: Add code to make diffing trees easier
This patch adds a "dtdiff" script to do a useful form diff of two
device trees.  This automatically converts the tree to dts form (if
it's not already) and uses a new "-s" option in dtc to "sort" the
tree.  That is, it sorts the reserve entries, it sorts the properties
within each node by name, and it sorts nodes by name within their
parent.

This gives a pretty sensible diff between the trees, which will ignore
semantically null internal rearrangements (directly diffing the dts
files can give a lot of noise due to the order changes).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-11-13 15:47:29 -06:00
John Bonesio
73ae43ea44 Allow nodes to be referenced by path at the top level.
When nodes are modified by merging device trees, nodes to be updated/merged can
be specified by a label. Specifying nodes by full path (instead of label)
doesn't quite work. This patch fixes that.

Signed-off-by: John Bonesio <bones@secretlab.ca>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2010-11-13 14:44:06 -06:00
David Gibson
8773e12fa9 Add merging of labelled subnodes. This patch allows the following
syntax:

/ {
	child {
		label: subchild {
		};
	};
};

&label {
	prop = "value";
};

which will result in the following tree:

/ {
	child {
		label: subchild {
			prop = "value";
		};
	};
};

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-09-21 10:15:51 -05:00
David Gibson
390635762d Remove another bashism from run_tests.sh
Current we check for various error codes with [ $x == "NN" ].  However
'==' is not actually a correct operator for the [ (test) command.  It
should be either '=' for string comparison or '-eq' for integer
comparison.  It appears that the bash builtin version of test
implements '==' though, so we were getting away with it, as long as
/bin/sh was bash - or the testsuite generated no errors.

This patch fixes the usage of test so that it should work on non-bash
shells.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-09-20 09:32:21 -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
Grant Likely
83da1b2a4e Allow device tree to be modified by additonal device tree sections
This patch allows the following construct:

/ {
	property-a = "old";
	property-b = "does not change";
};

/ {
	property-a = "changed";
	property-c = "new";
	node-a {
	};
};

Where the later device tree overrides the properties found in the
earlier tree.  This is useful for laying down a template device tree
in an include file and modifying it for a specific board without having
to clone the entire tree.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-02-25 11:46:01 -06:00
David Gibson
05898c67c1 dtc: Allow multiple labels on nodes and properties
At present, both the grammar and our internal data structures mean
that there can be only one label on a node or property.  This is a
fairly arbitrary constraint, given that any number of value labels can
appear at the same point, and that in C you can have any number of
labels on the same statement.

This is pretty much a non-issue now, but it may become important with
some of the extensions that Grant and I have in mind.  It's not that
hard to change, so this patch does so, allowing an arbitrary number of
labels on any given node or property.  As usual a testcase is added
too.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
2010-02-24 08:48:51 -06:00
David Gibson
49c2da3085 Remove obsolete references_dts0 test
The only purpose of the dtc_references_dts0 testcase was to check
handling of references in the old dts v0 syntax.  Since we no longer
support the old syntax, and the references_dts0.dts has been converted
to the new format, it's entirely redundant.  This patch removes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-23 09:04:56 -06:00
David Gibson
329055dbbc Disallow re-use of the same label within a dts file
Currently, nothing will stop you from re-using the same label string
multiple times in a dts, e.g.:
	/ {
		samelabel: prop1 = "foo";
		samelabel: prop2 = "bar";
	};

or
	/ {
		samelabel: prop1 = "foo";
		samelabel: subnode {
		};
	};

When using node references by label, this could lead to confusing
results (with no warning), and in -Oasm mode will result in output
which the assembler will complain about (since it too will have
duplicate labels).

This patch, therefore, adds code to checks.c to give errors if you
attempt to re-use the same label.  It treats all labels (node,
property, and value) as residing in the same namespace, since the
assembler will treat them so for -Oasm mode.

Testcases for the new code are also added.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-23 09:04:48 -06:00
David Gibson
15ad6d862e dtc: Automatically pick a sensible boot_cpuid_phys
Currently, when in -Idts -Odtb or -Ifs -Odtb modes, dtc always
defaults to using 0 as the value for the boot_cpuid_phys header field.
That's correct quite often, but there are some systems where there is
no CPU with hardware ID of 0, or where we don't want to use the CPU
with hardware ID 0 at all (e.g. for AMP-style partitioning).  The only
way to override this default currently, is with the -b command line
option.

This patch improves dtc to instead base the default boot_cpuid_phys
value on the reg property of the first listed subnode of /cpus.  This
means that dtc will get boot_cpuid_phys correct by default in a
greater proportion of cases (since the boot cpu is usually listed
first, and this way at least the boot_cpuid_phys default will match
some existing cpu node).  If the node doesn't exist or has an invalid
'reg' property (missing or not 4 bytes in length), then
boot_cpuid_phys is set to 0.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-19 08:36:23 -06: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
f2f6d0f2f0 Don't use echo -e in run_tests.sh
In one section, the run_tests script attempts to use the -e (interpret
escapes) option to echo.  This option is not portable - for example
the echo built into dash, now the default /bin/sh on several
distributions does not support it and will just echo "-e" literally.

Since we don't actually use any of the escapes that -e enables, this
patch simply removes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-11 21:38:38 -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
David Gibson
9878f30f31 dtc: Handle linux,phandle properties which self-reference
Currently, dtc will generate phandles for nodes which are referenced
elsewhere in the tree.  phandles can also be explicitly assigned by
defining the linux,phandle property.  However, there is no way,
currently to tell dtc to generate a phandle for a node if it is not
referenced elsewhere.  This is inconvenient when it's expected that
later processing on the flat tree might add nodes which _will_
the node in question.

One way one might attempt to do this is with the construct:
	mynode: mynode {
		linux,phandle = <&mynode>;
		/* ... */
	};
Though it's a trifle odd, there's really only one sensible meaning
which can be assigned to this construct: allocate a unique phandle to
"mynode" and put that in its linux,phandle property (as always).

Currently, however, dtc will choke on this self-reference.  This patch
corrects this, making the construct above give the expected results.
It also ensures a more meaningful error message is given if you
attempt to process the nonsensical construct:
	mynode: mynode {
		linux,phandle = <&someothernode>;
		/* ... */
	};

The 'references' testcase is extended to cover this case, as well.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-17 14:05:48 -06:00
Jon Loeliger
4e1a0a0129 Remove support for the legacy DTS source file format.
Now that all in-kernel-tree DTS files are properly /dts-v1/,
remove direct support for the older, un-numbered DTS
source file format.

Convert existing tests to /dts-v1/ and remove support
for the conversion tests themselves.

For now, though, the conversion tool still exists.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 16:09:34 -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
4d7bea7873 dtc: Run relevant checks on dtb input as well as dts
This patch adjusts the testsuite to run most of the tests for the tree
checking code on input in dtb form as well as dts form.  Some checks
which only make sense for dts input (like reference handling) are
excluded, as are those which currently take dtb input because they
rely on things which cannot be lexically constructed in a dts file.

This shows up two small bugs in dtc, which are also corrected.

First, the name_properties test which was is supposed to remove
correctly formed 'name' properties (because they can be reconstructed
from tne node name) was instead removing 'name' properties even if
they weren't correct.

Secondly, when using dtb or fs input, the runtime tree in dtc did not
have the parent pointer initialized propertly because.built
internally.  The appropriate initialization is added to the
add_child() function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:36:08 -05:00
David Gibson
cdcb415851 dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD.  This showed up a number of portability problems
in the dtc package which this patch addresses.  Changes are as
follows:

	- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa().  Those
are removed, using slightly longer coding with standard C functions
instead.

	- some other testcases had a #define _GNU_SOURCE for no
particular reason.  This is removed.

	- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh.  This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.

	- convert-dtsv0-lexer.l has some extra #includes added.  These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.

	- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions.  Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.

	- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:21:18 -05:00
David Gibson
f8e52fe6d8 dtc: Testcase for /include/ directive
This patch adds a testcase for the /include/ directive.  It assembles
a sample dts file with many /include/ directives at a variety of
different lexical / grammatical contexts.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:07:14 -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
050e6f0cff dtc: Add a testcase for 'reg' or 'ranges' in /
This patch adds an extra testcase to dtc to ensure that the
"reg_format" and "ranges_format" checks trigger as they should if a
'reg' or 'ranges' property appears in the root node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-02 15:20:08 -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
6c2e4d61f8 dtc: Testcases for input handling
This patch adds some testcases checking corner cases of dtc's input
file handling.  Specifically it checks that dtc works correctly when
given input via stdin, and it checks that dtc fails gracefully if
given a nonexistent input file (or directory, in the case of -Ifs
mode).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
68fe10ba4e dtc: Assorted improvements to test harness
This patch makes several small improvements to the test harness.

* An altered way of invoking shell script testcases from run_tests.sh
  means scripts no longer need to me marked executable in the
  repository to work properly.

* dtc.sh never did anything that was really dtc specific - with the
  exception of messages, it would work equally well for any binary
  that returns 0 in the successful case.  Therefore, generalise dtc.sh
  and fold it into run_tests.sh so we don't need a separate script any
  more.

* Tweak various things so that the valgrind options are properly
  propagated down to invoke dtc under valgrind when called via wrapper
  scripts.

* Tweak the valgrind suppressions to work properly on a wider range of
  systems (this was necessary on my machine running Ubuntu Hardy).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
a266e5c1e1 dtc: Test and fix conversion to/from old dtb versions
This patch adds testcases which test dtc when used to convert between
different dtb versions.  These tests uncovered a couple of bugs
handling old dtb versions, which are also fixed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
fa5b520ccb dtc: Implement checks for the format of node and property names
This patch adds checks to the checking framework to verify that node
and property names contain only legal characters, and in the case of
node names there is at most one '@'.

At present when coming from dts input, this is mostly already ensured
by the grammer, however putting the check later means its easier to
generate helpful error messages rather than just "syntax error".  For
dtb input, these checks replace the older similar check built into
flattree.c.

Testcases for the checks are also implemented.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:32 -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
d8b6942666 dtc: Fold comment handling test into testsuite
For ages dtc has included a sample dts, comment-test.dts, for checking
various lexical corner cases in comment processing.  In fact, it
predates the automated testsuite, and has never been integrated into
it.  This patch addresses this oversight, folding the comment handling
test in with the rest of the testsuite.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-02-15 08:10:14 -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
e4ffc1443d dtc: Convert check for obsolete /chosen property
This converts the test for the obsolete "interrupt-controller"
property in /chosen to the new framework.  That was the only thing
left in the old-style check_chosen() function, so that function is
removed, too.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-07 07:43:53 -06:00
David Gibson
7e089d9473 dtc: Convert #address-cells and #size-cells related checks
This patch converts checks related to #address-cells and #size-cells
to the new framework.  Specifically, it reimplements the check that
"reg" properties have a valid size based on the relevant
#address-cells and #size-cells values.  The new implementation uses
the correct default value, unlike the old-style check which assumed
the values were inherited by default.

It also implements a new, similar test for "ranges" properties.

Finally, since relying on the default values of these variables is
considered not-good-practice these days, it implements a "style" check
which will give a warning if the tree ever relies on the default
values (that is if any node with either "reg" or "ranges" appears
under a parent which has no #address-cells or #size-cells property).
2007-12-07 07:43:45 -06:00
David Gibson
faf037f0ef dtc: Migrate "string property" checks to new framework
This patch converts to the new tree checking framework those checks
which verify that certain properties (device_type, model) have a
string value, when present.

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