Commit graph

496 commits

Author SHA1 Message Date
Wang Long
1e5ddb1f39 dtc: Update the usage helper message
if #define DEFAULT_FDT_VERSION     17
The message
	Blob version to produce, defaults to %d (for dtb and asm output)
should be
	Blob version to produce, defaults to 17 (for dtb and asm output)

This patch fix it, and delete the redundant 't'.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
2014-09-11 23:27:41 +10:00
Jack Miller
5d4a8b9c4c Properly handle embedded nul delimited string lists
For example:

reserved-names="res1\0res2\0res3";

Where \0 is an actual embedded NUL in the source instead of a string
escape. To achieve this, use the len given by the lexer instead of
strlen.

Without this patch dtc will mangle the output and possibly hang on
realloc.
2014-08-08 19:17:31 +10:00
Andrei Errapart
f9e91a48ba Work around MSVC limitations
1) No variadic macros in the form "args..."; this is a GCC extension.
2) No empty struct initializers. In any case, there is very little to win:
   { } vs. { 0 }.

Signed-off-by: Andrei Errapart <andrei@errapartengineering.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-19 21:12:38 +10:00
Andrei Errapart
83e606a64d Open binary files in binary mode
The "b" flag to fopen() is generally a no-op on Unix-like systems, but may
be important on other systems, including Windows.

Signed-off-by: Andrei Errapart <andrei@errapartengineering.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-19 21:12:31 +10:00
Andrei Errapart
25a9bd6267 Correct write_propval_bytes() for platforms with signed char by default
Some platforms (including the Microsoft C compiler) have char defaulting
to signed.  write_propval_bytes() in the -O dts code will not behave
correctly in this case, due to sign extension.

Signed-off-by: Andrei Errapart <andrei@errapartengineering.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-19 21:05:34 +10:00
David Gibson
fa928fba7e Fix an off-by-2 error in the source output code
This has been there for ages, but the assertion makes no sense in the
context of the test immediately preceding it.  This caused an abort()
when in -I dts -O dts mode with the right sort of internal labels in a
string property value.

Add a testcase for this and another candidate edge case (though this one
we already get right).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-18 22:49:43 +10:00
Simon Glass
76a65b14d1 Add a basic test for fdtdump
We can test fdtdump by comparing its output with the source file that was
compiled by dtc. Add a simple test that should at least catch regressions
in basic functionality.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-18 21:24:48 +10:00
Simon Glass
c78ca72e1e Tweak code to display cell values
Move the division out of the loop; this seems slightly cleaner.

Signed-off-by: Simon Glass <sjg@chromium.org>
2014-06-18 21:02:51 +10:00
Simon Glass
dfcfb7f169 Correct output from memreserve in fdtdump
This currently displays a hex value without the 0x prefix. Add the prefix
as dtc requires it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2014-06-18 21:02:51 +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
David Gibson
f240527e54 Fix bug with references to root node
At present, the lexer token for references to a path doesn't permit a
reference to the root node &{/}.  Fixing the lexer exposes another bug
handling this case.

This patch fixes both bugs and adds testcases.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-05-09 20:48:49 +10:00
Heinrich Schuchardt
55a3a8823d Update source code location for dtc in manual.txt
The information about the location of the source code of the
device tree compiler was inaccurate.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-03-03 10:51:24 +11:00
Heinrich Schuchardt
9bf20d3896 Remove duplicate assignment
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-03-03 10:37:30 +11:00
Heinrich Schuchardt
8ce36476ae Consistently use xrealloc instead of realloc
fdtput.c:
Replace the remaining call to realloc by xrealloc.
Some redundant lines in encode_value can be saved.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-03-03 10:37:30 +11:00
Heinrich Schuchardt
821acd4c17 Remove dead code in util.c
xrealloc never returns null

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2014-03-02 11:45:25 +11:00
David Gibson
aba74ddba2 Remove references to unused DT_BASE token
Also remove the cbase bison union member that was only used for it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-02-15 19:47:23 +11:00
Grant Likely
aef4927a70 Add a README file for dtc and libfdt
Add a README file to document the location of the mailing list, the home
page and state who the maintainers are.

Signed-off-by: Grant Likely <grant.likely@linaro.org>
2014-02-12 11:33:42 +11:00
Florian Fainelli
4491ed9f87 Makefile: add a make "dist" target
make dist can be used to produce tarballs directly from the git
repository, which can be useful to automate the release process as well
as shipping custom releases.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-02-04 11:26:19 +11:00
Florian Fainelli
24cb3d0681 dtc: fix some more -Wshadow warnings
Building on a RHEL6 system produced the following -Wshadow warnings in
fstree.c, util.c and checks.c:

cc1: warnings being treated as errors
checks.c: In function 'parse_checks_option':
checks.c:709: error: declaration of 'optarg' shadows a global
declaration
/usr/include/getopt.h:59: error: shadowed declaration is here
make[1]: *** [checks.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** Waiting for unfinished jobs....
cc1: warnings being treated as errors
fstree.c: In function 'read_fstree':
fstree.c:40: error: declaration of 'tmpnam' shadows a global
declaration
/usr/include/stdio.h:208: error: shadowed declaration is here
make[1]: *** [fstree.o] Error 1
cc1: warnings being treated as errors
util.c: In function 'xstrdup':
util.c:42: error: declaration of 'dup' shadows a global declaration
/usr/include/unistd.h:528: error: shadowed declaration is here

Fix all of these -Wshadow warnings by using slightly different variable
names which won't collide with anything else.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-02-01 16:48:19 +11:00
Florian Fainelli
c231d94e0f Makefile: enable -Wshadow by default
Now that all -Wshadow build warnings/errors are fixed, turn on -Wshadow
by default to make sure we would catch new potential shadow warnings.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-01-25 15:11:20 +11:00
Florian Fainelli
3a584d4760 libfdt: avoid shadowing "err" in FDT_RW_CHECK_HEADER
FDT_RW_CHECK_HEADER declares an internal variable named "err" which is
far too generic and will produce the following -Wshadow warnings:

libfdt/fdt_rw.c: In function 'fdt_add_mem_rsv':
libfdt/fdt_rw.c:177:2: error: declaration of 'err' shadows a previous
local [-Werror=shadow]
libfdt/fdt_rw.c:175:6: error: shadowed declaration is here
[-Werror=shadow]
libfdt/fdt_rw.c: In function 'fdt_del_mem_rsv':
libfdt/fdt_rw.c:194:2: error: declaration of 'err' shadows a previous
local [-Werror=shadow]
libfdt/fdt_rw.c:192:6: error: shadowed declaration is here
[-Werror=shadow]
libfdt/fdt_rw.c: In function 'fdt_set_name':
...

Since this variable is only used internally in the macro, rename to
__err which should be prefixed enough not to cause new shadow warnings.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-01-25 15:11:20 +11:00
Florian Fainelli
89c9af5481 libfdt: avoid shadowing "err" in FDT_CHECK_HEADER
FDT_CHECK_HEADER declares an internal variable named "err" whose name is
far too generic and will produce the following -Wshadow warnings:

libfdt/fdt_ro.c: In function 'fdt_node_offset_by_compatible':
libfdt/fdt_ro.c:555:2: error: declaration of 'err' shadows a previous
local [-Werror=shadow]
libfdt/fdt_ro.c:553:14: error: shadowed declaration is here
[-Werror=shadow]
cc1: all warnings being treated as errors

Since this variable is only used internally in the macro, rename to
__err which should be prefixed enough not to cause new shadow warnings.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-01-25 15:11:20 +11:00
Florian Fainelli
6d88934371 dtc: avoid shadowing dirname()
dirname() is declared as a function, and later on try_open() another
variable dirname is used, which shadows the dirname() function
declaration and will produce the following warnings/errors with
-Wshadow turned on:

srcpos.c: In function 'try_open':
srcpos.c:71:35: error: declaration of 'dirname' shadows a global
declaration [-Werror=shadow]
srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow]
srcpos.c: In function 'srcfile_add_search_path':
srcpos.c:183:42: error: declaration of 'dirname' shadows a global
declaration [-Werror=shadow]
srcpos.c:37:14: error: shadowed declaration is here [-Werror=shadow]
cc1: all warnings being treated as errors

Fix this by renaming the function dirname() to get_dirname().

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-01-25 15:11:20 +11:00
David Gibson
fa3f3f0ebd Clean up parser error messages
Generally edit parser error messages for brevity and clarity.  Replace
the print_error() function with a a new macro for brevity and clarity in
the source.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-04 10:04:20 +11:00
David Gibson
c854434dc2 Correct locations in parser error messaes
The print_error() function used in several places in the parser uses the
location information in yylloc to describe the location of the error.
This is not correct in most cases.  yylloc gives the location of the
lookahead token, whereas the error is generally associated with one of
the already parsed non-terminals.

This patch corrects this, adding a location parameter to print_error() and
supplying it with the appropriate bison @N symbols.

This probably breaks yacc compatiblity, but too bad - accurate error
messages are more important.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-04 10:04:20 +11:00
David Gibson
6a15eb2350 Die on failed /incbin/ seeks
Failing to open an input file, with /include/ or /incbin/ is treated as
immediately fatal inside srcfile_relative_open().  However, filing to
seek() to the requested offset in an /incbin/ is not.  This is a bit oddly
inconsistent, and leaves us with a strange case that's awkward to deal with
down the line.

So, get rid of it and have failed seeks on an /incbin/ be immediately
fatal.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-04 10:04:19 +11:00
David Gibson
cfc6523619 Move character literal processing to the lexer
To match the processing of integer literals, character literals are passed
as a string from lexer to parser then interpreted there.  This is just as
awkward as it was for integer literals, without the excuse that we used to
need the information about the dts version to process them correctly.

So, move character literal processing back to the lexer as well, cleaning
things up.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-04 10:03:55 +11:00
David Gibson
b82b977614 Move integer literal processing back to the lexer
At the moment integer literals are passed from the lexer to the parser as
a string, where it's evaluated into an integer by eval_literal().  That
strange approach happened because we needed to know whether we were
processing dts-v0 or dts-v1 - only known at the parser level - to know
how to interpret the literal properly.

dts-v0 support has been gone for some time now, and the base and bits
parameters to eval_literal() are essentially useless.

So, clean things up by moving the literal interpretation back to the lexer.
This also introduces a new lexical_error() function to report malformed
literals and set the treesource_error flag so that they'll cause a parse
failure at the top level.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-03 20:00:01 +11:00
David Gibson
0e2d399225 Make srcpos_{v,}error() more widely useful
Allow them to take a prefix argument giving the general type of error,
which will be useful in future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01 23:27:31 +11:00
David Gibson
0c0bf8519a Fix memory leak in srcpos_verror()
Since dtc runs are short, we don't care that much about memory leaks.
Still, leaking the source position string every time we print an error
messages is pretty nasty.  Fix it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01 23:23:54 +11:00
David Gibson
e19d3b1d6d Fix indentation of srcpos_verror()
Somehow this function ended up with a 7 space indent, instead of the usual
8 space (1 tab) indent.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01 23:21:15 +11:00
David Gibson
a1e6da8aed Fix typo in type of srcpos_verror() et al.
The srcpos_verror() and srcpos_error() functions declare the format
string as 'char const *' instead of 'const char *'.  Fix it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01 23:20:55 +11:00
David Gibson
6efd9065e6 Remove unused srcpos_warn() function
This function has no users, and we can replace it more generally later.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-01-01 23:20:25 +11:00
David Gibson
a7ecdb4e75 Fix valgrind errors in sw_tree1
The sw_tree1 testcase has accumulated some valgrind errors, at least in
the "realloc" mode.
  * It had both a realloc_fdt() and explicit xmalloc() for the initial
allocation which was redundant and caused errors.
  * It doesn't make sense to call fdt_resize() until after we've created
the initial stub tree
  * Alignment gaps inserted into the tree contain uninitialized data, which
trips an error when we write it out.  We could zero the buffer, but that
would make it easier to miss real bugs, so we add suppressions for the
valgrind warnings instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-12-31 22:34:05 +11:00
David Gibson
edb10bcf1c Add option to run_tests.sh to stop immediately on a failing test
This is a debugging convenience option, which makes it much easier to find
the failing tests and fix them one by one.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-12-30 22:42:41 +11:00
Serge Lamikhov-Center
17119ab0a5 Pass 'unsigned char' type to isdigit()/isspace()/isprint() functions
The isdigit(), isprint(), etc. functions take an int, whose value is
required to be in the range of an _unsigned_ char, or EOF.  This, horribly,
means that systems which have a signed char by default need casts to pass
a char variable safely to these functions.

We can't do this more nicely by making the variables themselves 'unsigned
char *' because then we'll get warnings passing them to the strchr() etc.
functions.

At least the cygwin version of these functions, are designed to generate
warnings if this isn't done, as explained by this comment from ctype.h:
   These macros are intentionally written in a manner that will trigger
   a gcc -Wall warning if the user mistakenly passes a 'char' instead
   of an int containing an 'unsigned char'.

Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-12-25 15:27:22 +11:00
David Gibson
17625371ee Use stdbool more widely
We already use the C99 bool type from stdbool.h in a few places.  However
there are many other places we represent boolean values as plain ints.
This patch changes that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-28 21:06:53 +11:00
David Gibson
79eebb23db libfdt: Add function to resize the buffer for a sequential write tree
At present, when using sequential write mode, there's no straightforward
means of resizing the buffer the fdt is being built into.  This patch
adds an fdt_resize() function for this purpose.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-26 00:17:37 +11:00
Serge Lamikhov-Center
883238dc50 util: Fix out of bounds memory access
The change also fixes numeric values output produced by fdtdump.

Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov@gmail.com>
2013-10-01 14:21:18 +10:00
Stephen Warren
b290428d71 Ensure all tests have matching reg and unit address
ePAPR 1.1 section 2.2.1.1 "Node Name Requirements" specifies that any
node that has a reg property must include a unit address in its name
with value matching the first entry in its reg property. Conversely, if
a node does not have a reg property, the node name must not include a
unit address.

Adjust all the dtc test-cases to conform to this rule.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-09-20 08:49:31 +10:00
David Gibson
9476db68b6 Makefile: provide separate install targets
Currently `make install` will install the binaries, libraries and
includes.

This change separates the install target into install-bin, install-lib
and install-includes, so we have more flexibility, particularly when
we're just using libfdt.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-08-15 15:49:24 +10:00
Jon Loeliger
65cc4d2748 Tag Version 1.4.0
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2013-06-22 12:54:28 -05:00
Stephen Warren
a1ee6f068e dtc: ensure #line directives don't consume data from the next line
Previously, the #line parsing regex ended with ({WS}+[0-9]+)?. The {WS}
could match line-break characters. If the #line directive did not contain
the optional flags field at the end, this could cause any integer data on
the next line to be consumed as part of the #line directive parsing. This
could cause syntax errors (i.e. #line parsing consuming the leading 0
from a hex literal 0x1234, leaving x1234 to be parsed as cell data,
which is a syntax error), or invalid compilation results (i.e. simply
consuming literal 1234 as part of the #line processing, thus removing it
from the cell data).

Fix this by replacing {WS} with [ \t] so that it can't match line-breaks.

Convert all instances of {WS}, even though the other instances should be
irrelevant for any well-formed #line directive. This is done for
consistency and ultimate safety.

Reported-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-06-03 08:28:58 -05:00
David Gibson
2e3fc7e9b3 Add missing test binary to .gitignore
The subnode_iterate test binary was missing from .gitignore, this fixes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29 12:48:20 +10:00
Srinivas Kandagatla
d214655904 fdtput: expand fdt if value does not fit
If you try to insert a new node or extend a property with large value,
using fdtput you will notice that it always fails.

example:
fdtput -v -p -ts ./tst.dtb "/node-1" "property-1" "value-1
Error at 'node-1': FDT_ERR_NOSPACE

or

fdtput -v -c ./tst.dtb "/node-1"
Error at 'node-1': FDT_ERR_NOSPACE

or

fdtput -v  -ts ./tst.dtb "/node" "property" "very big value"
Decoding value:
	string: 'very big value'
Value size 15
Error at 'property': FDT_ERR_NOSPACE

All these error are returned from libfdt, as the size of the fdt passed
has no space to accomdate these new properties.
This patch adds realloc functions in fdtput to allocate new space in fdt
when it detects a shortage in space for new value or node. With this
patch, fdtput can insert a new node or property or extend a property
with new value greater than original size. Also it packs the final blob
to clean up any extra padding.

Without this patch fdtput tool complains with FDT_ERR_NOSPACE when we
try to add a node/property or extend the value of a property.

Testcases for the new behaviour added by David Gibson.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29 12:48:16 +10:00
David Gibson
a58afe2eb2 Remove some tests for misfeatures
There are a couple of fdtput related tests which are rather pointless -
they explicitly test for the presence of an undesirable limitation in
fdtput, which will cause test failures when we fix it.  This patch removes
the tests.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29 12:44:18 +10:00
David Gibson
1c76ec3c09 Use shorten_echo for wrap_tests
We have certain tests which generate extremely long command lines, which
are shortened in the testsuite output with the 'shorten_echo' function.
Currently that is used in run_fdtput_test and run_wrap_test, this patch
uses it for run_wrap_test as well, allowing more general tests with long
command lines.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29 12:40:00 +10:00
Mike Frysinger
8ec013ae63 fdtdump: add a debug mode
When hacking raw fdt files, it's useful to know the actual offsets into
the file each node appears.  Add a --debug mode that includes this.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-24 18:20:53 +10:00
Mike Frysinger
4ad49c3a9c util: add common ARRAY_SIZE define
I want to use this in more places, so put it in util.h rather than
copying & pasting it into another file.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-24 18:20:53 +10:00
Mike Frysinger
b9e80656f2 util: drop "long" from usage helpers
Now that all utils have converted to the new usage framework, we can
rename to just plain "usage()" and avoid naming conflicts.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-24 18:20:53 +10:00