Commit graph

447 commits

Author SHA1 Message Date
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
fc9769ac2b libfdt: Add and use a node iteration helper function.
This patch adds an fdt_next_node() function which can be used to
iterate through nodes of the tree while keeping track of depth.  This
function is used to simplify the iteration code in a lot of other
functions, and is also exported for use by library users.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-02-12 09:11:40 -06:00
Jon Loeliger
202863e4dd Tag Version 1.1.0
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-01-24 10:16:07 -06:00
Scott Wood
0f635df874 Remove const from dtc_file::dir.
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-11 13:23:37 -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
Jon Loeliger
7364cc79b5 Tag Version 1.1.0-rc1
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-01-10 09:09:44 -06:00
Scott Wood
b1a6719aa6 Preserve scanner state when /include/ing.
This allows /include/s to work when in non-default states,
such as PROPNODECHAR.

We may want to use state stacks to get rid of BEGIN_DEFAULT() altogether...

Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-10 07:43:33 -06:00
Scott Wood
42107f8bba Convert malloc() uses to xmalloc().
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-07 14:36:41 -06:00
Scott Wood
3c3ecaacda Remove \n from yyerror() call.
The \n is provided by yyerror().

Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-07 09:20:29 -06:00
Scott Wood
5695e99d5f Handle absolute pathnames correctly in dtc_open_file.
Also, free file->dir when freeing file.

Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-07 09:20:21 -06:00
David Gibson
7d24bd0a72 dtc/libfdt: Add README clarifying licensing
The fact that the dtc and libfdt are distributed together, but have
different licenses, can be a bit confusing.  Several people have
enquired as to what the deal is with the libfdt licensing, so this
patch adds a README clarifying the situation with a rationale.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-01-04 08:37:36 -06:00
Scott Wood
ad4f54ae2b Return a non-zero exit code if an error occurs during dts parsing.
Previously, only failure to parse caused the reading of the tree to fail;
semantic errors that called yyerror() but not YYERROR only emitted a message,
without signalling make to stop the build.

Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04 08:21:54 -06:00
Scott Wood
910efac4b4 Look for include files in the directory of the including file.
Looking in the diretory dtc is invoked from is not very useful behavior.

As part of the code reorganization to implement this, I removed the
uniquifying of name storage -- it seemed a rather dubious optimization
given likely usage, and some aspects of it would have been mildly awkward
to integrate with the new code.

Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04 08:20:10 -06:00
Scott Wood
f77fe6a20e Add yyerrorf() for formatted error messages.
Signed-off-by: Scott Wood <scottwood@freescale.com>
2008-01-04 08:04:15 -06:00
David Gibson
3bb78bfd97 dtc: Remove header information dumping
Currently, when used in -Idtb mode, dtc will dump information about
the input blob's header fields to stderr.  This is kind of ugly, and
can get in the way of dtc's real output.

This patch, therefore, removes this.  So that there's still a way of
getting this information for debugging purposes, it places something
similar to the removed code into ftdump, replacing the couple of
header fields it currently prints with a complete header dump.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-03 07:46:29 -06:00
David Gibson
3e516d961a dtc: Update TODO files
This patch makes a bunch of updates to the TODO files for dtc and
libfdt, some of them rather overdue.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-19 08:20:26 -06:00
David Gibson
08c0be206d dtc: Add missing copyright notice for dumptrees.c
When I released libfdt, I forgot to add a copyright notice to
dumptrees.c (probably because the program is so trivial).  Apparently
the lack causes trouble for Debian, so this patch adds one.  I've gone
through the git history and double checked that no-one has touched
this file except me (and I barely have myself since its initial
commit).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-19 08:18:08 -06:00
David Gibson
376ab6f2ed dtc: Remove remaining old-style checks
The remaining old-style tree checking code: check_root(), check_cpus()
and check_memory() really aren't that useful.  They mostly check for
the presence of particular nodes and properties.  That's inherently
prone to false-positives, because we could be dealing with an
artificial tree (like many of the testcases) or it could be expected
that the missing properties are filled in by a bootloader or other
agent.

If any of these checks really turns out to be useful, we can
reimplement them later in a better conceived way on top of the new
checking infrastructure.  For now, just get rid of them, removing the
last vestiges of the old-style checking code (hoorah).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-18 07:54:30 -06:00
David Gibson
d6f9b62fe1 dtc: Don't build tests as part of "all"
Currently "make all" for dtc will build (but not run) the testcase
binaries.  This is a problem for cross compiles, because building the
tests will attempt to run the dumptrees utility on the host system,
which won't work if it's cross-compiled of course.

Although it would be possible to separately build host binaries,
there's not a lot of value in doing so since we don't have a facility
for cross-executing the testsuite anyway.

Therefore, remove the tests from the "all" target.  It will still, of
course, be build as a prerequisite to "make check" which will run the
testsuite.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-17 07:41:13 -06:00
David Gibson
30f7fbfbe9 libfdt: Add more documentation (patch the seventh)
This patch adds more documenting comments to libfdt.h.  Specifically,
these document the read/write functions (not including fdt_open_into()
and fdt_pack(), for now).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-17 07:39:33 -06:00
David Gibson
f819a4e21d libfdt: Add more documentation (patch the sixth)
This patch adds some more documenting comments to libfdt.h.
Specifically this documents all the write-in-place functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-17 07:38:42 -06:00
David Gibson
a68cbc09ff dtc: Fix silly typo in dtc-checkfails.sh
Too much C coding makes for dumb errors in shell.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-07 07:47:45 -06:00
David Gibson
b7c5eaf3ee dtc: Allow gcc format warnings for check_msg()
check_msg() takes printf() like arguments, so tell gcc to produce
printf() like warnings for it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-07 07:47:15 -06:00
David Gibson
0d9d10184b dtc: Make dtc-checfails.sh script catch deaths-by-signal
Since commit 5ba0086bfd, the
dtc-checkfails.sh script does not check the return code from dtc.
That's reasonable, since depending on the checks we're testing, dtc
could either complete succesfully or return an error.

However, it's never right for dtc to SEGV or otherwise be killed by a
signal.  So the script should catch that, and fail the testcase if it
happens.  This patch implements this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-07 07:45:44 -06:00
David Gibson
3476f9608b dtc: Reinstate full old-style reference-to-path for v0 dts files
Commit 7c44c2f9cb broke backwards
compatibility more badly than I realised.  Contrary to what I thought
there are in-kernel, in-use dts files which relied on
references-to-path with paths including a comma, which no longer
compile after that commit.

So, this patch reinstates full support for bare references-to-path in
dts-v0 input.  This means there will be some rather surprising lexical
corner cases when using path-expanded references in v0 files.  But,
since path-expanded references are new, v0 files shouldn't typically
be using them anyway.  If the corner cases cause a problem, you can
always convert to dts-v1 which handles the lexical issues here more
nicely.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-07 07:44:45 -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
e110920707 dtc: Remove obsolete check_properties() function
After the last couple of patches converting various old-style semantic
checks to the new framework, the only thing that the old-style
check_properties() function still checks is that the size of "reg"
properties is a multiple of the cell size.

This patch removes check_properties() and all related code and data.
The check on the size of reg properties is folded into the existing
check for the format of "reg" properties (still old-style for the time
being).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-06 09:17:24 -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
David Gibson
c21acabc40 dtc: Migrate "one cell" checks to new framework
This patch converts to the new tree checking framework those checks
which verify that certain properties (#address-cells and #size-cells)
are exactly one cell in size, when present.

We also drop the old-style check for "linux,phandle" being one cell,
since that is already implied in the the existing new-style checks on
the linux,phandle property.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-06 09:15:56 -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
David Gibson
d6060bd231 dtc: Remove space from flex command line
Author: Geoff Levand <geoffrey.levand@am.sony.com>

Apparently some versions of flex don't correctly parse the -o
parameter, if there's a space between the -o and its argument.  So,
this patch removes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-06 09:14:12 -06:00
David Gibson
efbbef8e4f dtc: Implement path references
This patch extends dtc syntax to allow references (&label, or
&{/full/path}) directly within property definitions, rather than
inside a cell list.  Such references are expanded to the full path of
the referenced node, as a string, instead of to a phandle as
references within cell lists are evaluated.

A testcase is also included.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05 08:28:44 -06:00
Kumar Gala
80c72a81cf Fix padding options
"Add an option to pad the blob that is generated" broke the padding
support.  We were updating the fdt header after writing it.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-12-05 08:27:54 -06:00
David Gibson
c048102f5b dtc: Generate useful error message for properties after subnodes
On several occasions, I've accidentally put properties after subnodes
in a dts file.  I've then spent ages thinking that the resulting
syntax error was because of something else.

This patch arranges for this specific syntax error to generate a more
specific and useful error message.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05 08:27:46 -06:00
David Gibson
2b67c632df dtc: Trivial lexer cleanups
This patch applies a couple of tiny cleanups to the lexer.  The
not-very-useful 'WS' named pattern is removed, and the debugging
printf() for single character tokens is moved to the top of the
action, which results in less confusing output when LEXDEBUG is
switched on (because it goes before the printf()s for possible
resulting lexer state changes).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05 08:27:37 -06:00
David Gibson
459c955cca dtc: Convert "name" property checking to new infrastructure
This patch removes the old-style checking code for the "name" property
- i.e. verifying that the "name" property, if present, matches the
node name.  It replaces it with a pair of more-or-less equivalent
checks in the new checking framework.

This also promotes this check to a "structural" check, or at least an
error-rather-than-warning test, since the structural/semantic
distinction doesn't really apply in the new framework.

A testcase for the check is also added.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05 08:27:28 -06:00
David Gibson
d06cda32f6 dtc: Fix FAIL() macro varargs
The way the checking subsystem FAIL() macro is currently implemented
it must take at least one paramater after the format string.  This
patch corrects the problem.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05 08:27:22 -06:00
Kumar Gala
501e21cc6f Print out the total size as part of ftdump
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-12-05 08:27:00 -06:00
David Gibson
92cb9a25b1 dtc: Add many const qualifications
This adds 'const' qualifiers to many variables and functions.  In
particular it's now used for passing names to the tree accesor
functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-04 07:54:03 -06:00
David Gibson
2d72816ccf dtc: Fix uninitialized use of structure_ok
My rework of the tree checking code introduced a potentially nasty bug
- it uses the structure_ok variable uninitialized.  This patch fixes
the problem.  It's a fairly ugly bandaid approach, but the ugly will
disappear once future patches have folded the semantic checks into the
new framework.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-04 07:27:08 -06:00
Kumar Gala
2b7dc8dce5 Add an option to pad the blob that is generated
There are times when we need extra space in the blob and just want
to have it added on w/o know the exact size to make it.

The padding and min size options are mutually exclusive.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-12-04 07:26:47 -06:00
David Gibson
7c44c2f9cb dtc: Fix some lexical problems with references
The recent change to the lexer to only recognize property and node
names in the appropriate context removed a number of lexical warts in
our language that would have gotten ugly as we add expression support
and so forth.

But there's one nasty one remaining: references can contain a full
path, including the various problematic node name characters (',', '+'
and '-', for example).  This would cause trouble with expressions, and
it also causes trouble with the patch I'm working on to allow
expanding references to paths rather than phandles.  This patch
therefore reworks the lexer to mitigate these problems.

	- References to labels cause no problems.  These are now
recognized separately from references to full paths.  No syntax change
here.

	- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}.  The braces protect any internal
problematic characters from being confused with operators or whatever.

	- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but
*only* if the path contains no troublesome characters.  Specifically
only [a-zA-Z0-9_@/] are allowed.

This is an incompatible change to the dts-v1 format, but since AFAIK
no-one has yet switched to dts-v1 files, I think we can get away with
it.  Better to make the transition when people to convert to v1, and
get rid of the problematic old syntax.

Strictly speaking, it's also an incompatible change to the v0 format,
since some path references that were allowed before are no longer
allowed.  I suspect no-one has been using the no-longer-supported
forms (certainly none of the kernel dts files will cause trouble).
We might need to think about this harder, though.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-28 13:51:38 -06:00
Kumar Gala
f29454eb7e Fix whitespace in libfdt/fdt.h
Take from u-boot whitespace fixup of the file

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-11-28 09:44:27 -06:00
David Gibson
dc941774e2 dtc: Merge refs and labels into single "markers" list (v2)
Currently, every 'data' object, used to represent property values, has
two lists of fixup structures - one for labels and one for references.
Sometimes we want to look at them separately, but other times we need
to consider both types of fixup.

I'm planning to implement string references, where a full path rather
than a phandle is substituted into a property value.  Adding yet
another list of fixups for that would start to get silly.  So, this
patch merges the "refs" and "labels" lists into a single list of
"markers", each of which has a type field indicating if it represents
a label or a phandle reference.  String references or any other new
type of in-data marker will then just need a new type value - merging
data blocks and other common manipulations will just work.

While I was at it I made some cleanups to the handling of fixups which
simplify things further.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-26 16:00:19 -06:00
David Gibson
b16a2bd89d dtc: Flexible tree checking infrastructure (v2)
dtc: Flexible tree checking infrastructure

Here, at last, is a substantial start on revising dtc's infrastructure
for checking the tree; this is the rework I've been saying was
necessary practically since dtc was first release.

In the new model, we have a table of "check" structures, each with a
name, references to checking functions, and status variables.  Each
check can (in principle) be individually switched off or on (as either
a warning or error).  Checks have a list of prerequisites, so if
checks need to rely on results from earlier checks to make sense (or
even to avoid crashing) they just need to list the relevant other
checks there.

For now, only the "structural" checks and the fixups for phandle
references are converted to the new mechanism.  The rather more
involved semantic checks (which is where this new mechanism will
really be useful) will have to be converted in future patches.

At present, there's no user interface for turning on/off the checks -
the -f option now forces output even if "error" level checks fail.
Again, future patches will be needed to add the fine-grained control,
but that should be quite straightforward with the infrastructure
implemented here.

Also adds a testcase for the handling of bad references, which catches
a bug encountered while developing this patch.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-26 16:00:08 -06:00
David Gibson
67b6b33b9b dtc: Add valgrind support to testsuite
This patch adds some options to the run_tests.sh script allowing it to
run all the testcases under valgrind to check for pointer corruption
bugs and memory leaks.  Invoking "make checkm" will run the testsuite
with valgrind.

It include a mechanism for specifying valgrind errors to be suppressed
on a per-testcase basis, and adds a couple of such suppression files
for the mangle-layout and open_pack testcases which dump for use by
other testcases a buffer which may contain uninitialized sections.  We
use suppressions rather than initializing the buffer so that valgrind
will catch any internal access s to the uninitialized data, which
would be a bug.

The patch also fixes one genuine bug caught by valgrind -
_packblocks() in fdt_rw.c was using memcpy() where it should have been
using memmove().

At present the valgrinding won't do anything useful for testcases
invoked via a shell script - which includes all the dtc testcases.  I
plan to fix that later.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-26 15:57:58 -06:00
David Gibson
3ce5363387 dtc: Remove some redundant testcases
This patch removes a number of testcases from the testsuite that are
extremely unlikely to find any bugs that won't be found by the other
tests.  This speeds up the testsuite.

	- Both loops across the various tree block layouts run the
tree1_tests on the basic mangled tree.  This is completely redundant,
so remove the second copy. This removes 456 testcases.

	- We currently run tree1_tests on various trees manipulated by
move_and_save.  We replace those with just a dtbs_equal_ordered test
to check that the manipulated tree is equal to the original.  What
we're testing here is that fdt_move() operates correctly - it's very
unlikely it would succeed well enough for the ordered_equal test to
succeed, but the tree1_tests would fail on the result.  This removes
162 testcases.

	- Currently we re-ordered with mangle-layout both the basic
test_tree1.dtb and sw_tree1.test.dtb.  Since we've already checked
that these dtbs are equivalent with dtbs_ordered_equal, it's very
unlikely that the tests would fail on one but not the other.
Therefore reduce this to only using test_tree1.dtb.  This removes 828
testcases.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-26 15:19:33 -06:00
Jon Loeliger
8eaf5e3583 Add a script that compares an "old" and "new" dtc results.
Lots of room for improvement here.  Command line options, etc.
The script iterates over a hard-coded list of kernel DTS files.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-11-20 09:14:03 -06:00