The previous definition of for_each_*() would always include the very
first object within the list, irrespective of whether it was marked
deleted, since the deleted flag was not checked on the first object,
but only on any "next" object.
Fix for_each_*() to check the deleted flag in the loop body every
iteration to correct this.
Incidentally, this change is why commit 45013d8 dtc: "Add ability to
delete nodes and properties" only caused two "make checkm" failures;
only two tests actually use multiple labels on the same property or
node. With this current change applied, but commit 317a5d9 "dtc: zero
out new label objects" reverted, "make checkm" fails 29 times; i.e.
for every test that uses any labels at all.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Some API function symbols were set as 'local' causing linking errors,
now they are set as global (external).
Signed-off-by: Anders Hedlund <anders.hedlund@windriver.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Without this, new->deleted may be left set to some random value, which
may then cause future label references to fail to locate the label. The
code that allocates properties and nodes already contains the equivalent
memset().
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Line control directives of the following formats are supported:
#line LINE "FILE"
# LINE "FILE" [FLAGS]
This allows dtc to consume the output of pre-processors, and to provide
error messages that refer to the original filename, including taking
into account any #include directives that the pre-processor may have
performed.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
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>
dtc currently allows the contents of properties to be changed, and the
contents of nodes to be added to. There are situations where removing
properties or nodes may be useful. This change implements the following
syntax to do that:
/ {
/delete-property/ propname;
/delete-node/ nodename;
};
or:
/delete-node/ &noderef;
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Previously, only two headers were installed: libfdt.h and fdt.h.
But libfdt.h also #includes libfdt_env.h, which was not installed.
Install this missing header too.
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This option mimics mkdir's -p option. It automatically creates nodes
as needed along the path provided. If the node already exists, no
error is given.
Signed-off-by: Simon Glass <sjg@chromium.org>
As with many fdt functions, report_error() should permit a namelen to
be specified, thus obviating the need for nul termination in strings
passed to it.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This option allows the creation of new nodes in a dtb file. The syntax
is:
fdtput -c <dtb_file> <node_path>
The node_path contains the path of the node to be created. All path
components up to the final one must exist already. The final one must
not exist already.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
We want to add new options to this tool. In preparation for this, add
the concept of a current operation.
Signed-off-by: Simon Glass <sjg@chromium.org>
There was an extra < in the help message, so fix it.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This patch adds -W and -E options to dtc which allow toggling on and off
of the various built in semantic checks on the tree.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently each of the semantic checks in checks.c has a "level" between
IGNORE and ERROR. This single level makes it awkward to implement the
semantics we want for toggling the checks on the command line.
This patch reworks the code to instead have separate boolean flags for
warning and error. At present having both flags set will have the same
effect as having just the error flag set, but this can change in the
future.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When merging one device tree over the top of a previous tree, it is
possible to define a duplicate label that has the same name and points
to the same property or node. This is currently allowed by the duplicate
label checking code. However, alternative duplicate label checking
algorithms might not allow this. Add an explicit test to ensure this
capability is maintained.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
When compiling the current code-base with gcc 4.6.1, the following warning
is raised, which is interpreted as an error:
cc1: warnings being treated as errors
tests/setprop_inplace.c: In function ‘main’:
tests/setprop_inplace.c:62: error: format ‘%016llx’ expects type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’
tests/setprop_inplace.c:68: error: format ‘%016llx’ expects type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’
Use printf format specifiers from <inttypes.h> to solve this.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
The libfdt read/write functions are now usable enough that it's become a
moderately common pattern to use them to build and manipulate a device
tree from scratch. For example, we do so ourself in our rw_tree1 testcase,
and qemu is starting to use this model when building device trees for some
targets such as e500.
However, the read/write functions require some sort of valid tree to begin
with, so this necessitates either having a trivial canned dtb to begin with
or, more commonly, creating an empty tree using the serial-write functions
first.
This patch adds a helper function which uses the serial-write functions to
create a trivial, empty but complete and valid tree in a supplied buffer,
ready for manipulation with the read/write functions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
In device trees in the world, properties consisting of a single 64-bit
integer are not as common as those consisting of a single 32-bit, cell
sized integer, but they're common enough that they're worth including
convenience functions for.
This patch adds helper wrappers of fdt_setprop_inplace(), fdt_setprop() and
fdt_appendprop() for handling 64-bit integer quantities in properties. For
better consistency with the names of these new *_u64() functions we also
add *_u32() functions as alternative names for the existing *_cell()
functions handling 32-bit integers.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The testcases based on test_tree1_dts0.dts were added purely to test dtc's
backwards compatibility handling of the old dts-v0 format. Since that
support has been removed, the dts has been updated to use the current
dts-v1 syntax, which makes the testcases pass, but be completely useless.
This patch removes the now obsolete testcases.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Several files were added, and should be in .gitignore. The *.test.dts
pattern should catch future source files which are generated by tests.
It also subsumes the old *.dtb.test.dts pattern.
Signed-off-by: Simon Glass <sjg@chromium.org>
Outputing to stderr is best avoided unless there is an error or warning to
display. At present dtc always displays the name of the file it is compiling
and the input/output formats. For example:
DTC: dts->dts on file "-"
This can cause problems in some build systems. For example, U-Boot shows
build errors for any boards which use dtc at present. It is typically the
only message output during such a build. The C compiler does not output
anything in general. The current dtc behaviour makes it difficult to
provide a silent build in the normal case where nothing went wrong.
Remove the message entirely.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
libfdt_env.h in the device tree compiler currently defines a _B() macro. This is in the
namespace reserved for the implementation, and Cygwin's ctype.h actually defines a macro
with this name. This renames _B to EXTRACT_BYTE.
Signed-off-by: Bert Kenward <bert.kenward@broadcom.com>
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>
On Ubuntu, /bin/sh is dash (at least by default), and dash's echo doesn't
accept the -e option. This means that fdtget-runtest.sh's EXPECT file will
contain "-e foo" rather than just "foo", which causes a test failure.
To work around this, run /bin/echo instead of (builtin) echo, which has
more chance of supporting the -e option.
Another possible fix is to change all the #! lines to /bin/bash rather
than /bin/sh, and change run_tests.sh to invoke sub-scripts using $SHELL
instead of just "sh". However, that would require bash specifically, which
may not be desirable.
Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
It is often inconvenient to place device tree files in the same directory
as their includes, or to specify the full path to include files.
An example of this is in U-Boot where we have a .dtsi file for each SOC
type, and this is included by the board .dts file. We need to either use
a mechanism like:
/include/ ARCH_CPU_DTS
with sed or cpp to perform the replacement with the correct path, or
we must specify the full path in the file:
/include/ "../../arch/arm/dts/tegra20.dtsi"
The first option is not desirable since it requires anyone compiling the
file to first pre-process it. The second is not desirable since it
introduces a path which is project-specific into a file which is supposed
to be a hardware description. For example Linux and U-Boot are unlikely to
put these include files in the same place.
It is much more convenient to specify the search patch on the command line
as is done with C pre-processors, for example.
Introduce a -i option to add to the list of search paths used to find
source and include files.
We cannot use -I as it is already in use. Other suggestions welcome.
Signed-off-by: Simon Glass <sjg@chromium.org>
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>
This option lists the subnodes of each node given as a parameter, one
subnode per line.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This option lists the properties of each node given as a parameter, one
property per line.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
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>
This patch fixes a segmentation fault caused by dereferencing a NULL
pointer (pos->file aka yylloc.file) in srcpos_string when the input
length is 0 (fe 'dtc </dev/null'.) Reason: yylloc.file is initialized
with 0 and the tokenizer, which updates yylloc.file via srcpos_update
doesn't get a chance to run on zero-length input.
Signed-off-by: Horst Kronstorfer <hkronsto@frequentis.com>
I just found this little bug with valgrind. strchr() will return true
if the given character is '\0'. This meant that utilfdt_decode_type()
could take a path which accesses uninitialized data when given the
(invalid) format string "L".
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
Currently the fdt{get,put}-runtest.sh scripts invoke diff to check if
fdt{get,put} did the right thing. This isn't great though: it's not
obvious from the diff output which is the expected and which is the
actual result; diff's line by line behaviour is useless here, since all
the results are a single line and finally, when there is a difference
it always prints information even when the tests are supposed to be
running in quiet mode.
This patch uses cmp instead, and explicitly prints the expected results,
when running in verbose mode (the invocation of fdtget itself will have
already displayed the actual results in this mode.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
Several test scripts now have some code to check for a program returning
a signal, and reporting a suitable failure. This patch moves this
duplicated code into a helper function in tests.sh. At the same time we
remove a bashism found in the current copies (using the non portablr $[ ]
construct for arithmetic).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
Some of the test scripts create temporary files, which we remove at the
end. Except that we usually forgot to remove them on some exit paths. To
avoid this problem in future, this modifies the scripts to use the shell's
trap 0 functionality to automatically remove the temporaries on any exit.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Several of the test scripts remove $TMPFILE, without ever having set
the TMPFILE variable. This patch fixes it.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Having braces on an if branch but not the else branch, or vice
versa is ugly and can trick you when reading the code.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
For the benefit of quilt users (such as myself, sometimes) have git
ignore the quilt control and patches files.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
We've add some test (generated) binaries that aren't currently listed in
.gitignore, in addition more scripts now generate various tmp.* files
during operation. This adds them all to .gitignore.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
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>
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>
Some properties may contain multiple values, these values may need
to be added to the property respectively. this patch provides this
functionality. The main purpose of fdt_append_prop() is to append
the values to a existing property, or create a new property if it
dose not exist.
Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The freetype package already installs a binary named "ftdump", so the dtc
package conflicts with that. So rename the newer dtc tool to "fdtdump".
This even makes a bit more sense:
ftdump: [F]lat device [T]ree [dump]
fdtdump: [F]lat [D]evice [T]ree [dump]
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>