Commit graph

171 commits

Author SHA1 Message Date
Jon Loeliger
7b3fb789d2 DTC: Remove the need for the GLR Parser.
Previously, there were a few shift/reduce and reduce/reduce
errors in the grammar that were being handled by the not-so-popular
GLR Parser technique.

Flip a right-recursive stack-abusing rule into a left-recursive
stack-friendly rule and clear up three messes in one shot: No more
conflicts, no need for the GLR parser, and friendlier stackness.
Compensate by reversing the property list on the node.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-25 11:13:29 -05:00
David Gibson
3bef796b44 libfdt: Test on trees with different block layouts
At present, all the example dtbs we use in the testsuite are version
17 and have reservation map, then structure block then strings block
(the natural ordering based on alignment constraints).  However, all
libfdt's read-only and in-place write functions should also work on
v16 trees, and on trees with other layouts.

This patch adds a testcase / utility function to rearrange the blocks
of a dtb and/or regress a v17 tree to v16, and uses it to run tests on
trees with different layouts and versions.

Signed-off-by: David Gibson <david@tgibson.dropbear.id.au>
2007-10-25 09:50:07 -05:00
David Gibson
9b91134ba3 libfdt: Remove un-const-safe fdt_set_header macro
The fdt_set_header() macro casts an arbitrary pointer into (struct
fdt_header *) to set fdt header fields.  While we need to change the
type, so that we can use this macro on the usual (void *) used to
represent a device tree blob, the current macro also casts away any
const on the input pointer, which loses an important check.

This patch replaces the fdt_set_header() macro with a set of inline
functions, one for each header field which do a similar thing, but
which won't silently remove const from a given pointer.  This approach
is also more in keeping with the individual accessor macros we use for
reading fdt header fields.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-25 09:49:18 -05:00
David Gibson
57f99b7b3f libfdt: Documentation (patch the second)
Add documentation for another handful of libfdt functions to libfdt.h

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-25 09:37:53 -05:00
David Gibson
cec0c384ef libfdt: Add some documenting comments in libfdt.h
This patch adds some internal documentation in libfdt.h, in the form
of comments on the error codes and some functions.  Only a couple of
functions are covered so far, leaving the documentation still woefully
inadequate, but hey, it's a start.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-24 09:57:26 -05:00
David Gibson
3c44c87bde libfdt: Rename and publish _fdt_next_tag()
Although it's a low-level function that shouldn't normally be needed,
there are circumstances where it's useful for users of libfdt to use
the _fdt_next_tag() function.  Therefore, this patch renames it to
fdt_next_tag() and publishes it in libfdt.h.

In addition, this patch adds a new testcase using fdt_next_tag(),
dtbs_equal_ordered.  This testcase tests for structural equality of
two dtbs, including the order of properties and subnodes, but ignoring
NOP tags, the order of the dtb sections and the layout of strings in
the strings block.  This will be useful for testing other dtc
functionality in the future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-24 09:56:27 -05:00
David Gibson
96b5fad3a1 libfdt: Rename and publish _fdt_check_header()
It's potentially useful for users of libfdt to sanity check a device
tree (or, rather, a blob of data which may or may not be a device
tree) before processing it in more detail with libfdt.

This patch renames the libfdt internal function _fdt_check_header() to
fdt_check_header() and makes it a published function, so it can now be
used for this purpose.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-24 07:58:13 -05:00
Jon Loeliger
2d50f8f9dd Quiet a bogus "May be used uninitialized" warning.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-23 10:13:00 -05:00
Jon Loeliger
afa8c2e1d7 Appease the printf() format $Gods with a correct type.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-23 09:43:14 -05:00
Jon Loeliger
7dfba39a23 DTC: Remove an unneeded %token definition.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-23 09:37:09 -05:00
Jon Loeliger
5641289a46 DTC: Minor grammar rule shuffle.
I like to see the basis cases established early in
the rule sets, so place  "empty" reduction first.
Purely cosmetic.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-23 09:35:36 -05:00
Jon Loeliger
30807ca1ce Reformat grammar rules to not mix language syntax and yacc syntax.
Use consistent indenting on all rule actions.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 11:40:51 -05:00
David Gibson
e321e51036 dtc: data.c doesn't need to include dtc-parser.tab.h
Presumably we used this #include once, but it's certainly not
necessary now.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 09:54:16 -05:00
David Gibson
169f0b183d dtc: Disable semantic checks by default
At present, dtc makes a lot of semantic checks on the device tree by
default, and will refuse to produce output if they fail.  This means
people tend to need -f to force output despite failing semantic checks
rather a lot.

This patch splits the device tree checks into structural checks (no
bad or duplicate names or phandles) and semantic checks (everything
else).  By default, only the structural checks are performed, and are
fatal.  -f will force output even with structural errors (using this
in -Idts mode would essentially always be a bad idea, but it might be
useful in -Idtb mode for examining a malformed dtb).

Semantic checks are only performed if the new -c command line option
is supplied, and are always warnings only.  Semantic checks will never
be performed on a tree with structural errors.

This patch is only a stopgap before implementing proper fine-grained
error/warning handling, but it should at least get rid of the
far-too-frequent need for -f for the time being.

This patch removes the -f from the dtc testcases now that it's no
longer necessary.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 09:53:15 -05:00
David Gibson
394e47208d libfdt: Add missing RW_CHECK_HEADER to fdt_del_node()
fdt_del_node(), unlike most of the rw functions does not check the
fdt's header with RW_CHECK_HEADER.  However, it could make a mess of
things if the conditions in RW_CHECK_HEADER aren't met.  So, this
patch adds the omitted check.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 09:52:18 -05:00
David Gibson
d7649da4b9 dtc: Make helper macros in trees.S more flexible
This patch makes the helper macros in trees.S use separate labels for
the end of each dt subblock, rather than using only start labels.
This means that the macros can now be used to create trees with the
subblocks in non-standard orders.

In addition, it adds a bunch of extra ; after lines of asm code in
macros, making them safe to use in nested macros.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 09:52:03 -05:00
David Gibson
11d5302021 libfdt: Make fdt_string() return a const pointer
Currently, fdt_string() returns a (non-const) char *, despite taking a
const void *fdt.  This is inconsistent with all the other read-only
functions which all return const pointers into the blob.

This patch fixes that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-22 09:51:55 -05:00
David Gibson
5a98ddd10a dtc: Improve -Odts output
This patch makes improvements to the way properties are printed when
in dtc is producing dts output.
	- Characters which need escaping are now properly handled when
printing properties as strings
	- The heuristics for what format to use for a property are
improved so that 'compatible' properties will be displayed as
expected.
	- escapes.dts is altered to better demonstrate the changes,
and the string_escapes testcase is adjusted accordingly.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-17 07:14:38 -05:00
David Gibson
32b6bd3490 dtc: Restore missing code for testcases
Recent commits 333542fabf and
fd1bf3a5ae added new testcases to dtc.
However, although the testcases were added to the Makefile and
run_tests.sh, one of the .c files for the testcase was omitted from
the patch in each case.

This patch restores the missing testcase code.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-17 07:09:59 -05:00
David Gibson
a756c12bea dtc: Improve support for string escapes
dtc supports the use of C-style escapes (\n, \t and so forth) in
string property definitions via the data_copy_escape_string()
function.  However, while it supports the most common escape
characters, it doesn't support the full set that C does, which is a
potential gotcha.

Worse, a bug in the lexer means that while data_copy_escape_string()
can handle the \" escape, a string with such an escape won't lex
correctly.

This patch fixes both problems, extending data_copy_escape_string() to
support the missing escapes, and fixing the regex for strings in the
lexer to handle internal escaped quotes.

This also adds a testcase for string escape functionality.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-16 08:10:15 -05:00
David Gibson
333542fabf libfdt: Add functions for handling the "compatible" property
This patch adds functions for dealing with the compatible property.
fdt_node_check_compatible() can be used to determine whether a node is
compatible with a given string and fdt_node_offset_by_compatible()
locates nodes with a given compatible string.

Testcases for these functions are also included.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-16 07:41:37 -05:00
David Gibson
121acdec91 dtc: Don't delete *.test.dtb between testgroups
The dtc/libfdt testsuite creates a number of .dtb files during its
run.  To ensure a clean test run, these are currently deleted before
each group of tests.

This is, in fact, a mistake, since if something goes wrong in the
first group of tests, deleting the .dtb at the beginning of the second
group of tests makes it harder to figure out what the problem was.

This patch changes the script to only delete the files once, before
the whole test run.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-16 07:38:57 -05:00
Jon Loeliger
9e32930ebc Restore warning message about bison expected output.
It was dropped in ad9593f229.

Signed-off-by: Jon Loeliger <jdl@jdl.com>
2007-10-16 07:36:30 -05:00
David Gibson
6f8b7710c9 libfdt: libfdt_env.h must be included first
libfdt.h currently includes fdt.h, then libfdt_env.h.  This is
incorrect, because depending on the environment into which libfdt is
embedded, libfdt_env.h may be needed to define datatypes used in
fdt.h.  This patch corrects the problem.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-16 07:22:50 -05:00
David Gibson
fd1bf3a5ae libfdt: Add functions to get/add/delete memory reservemap entries
This patch adds functions to libfdt for accessing the memory
reservation map section of a device tree blob.  fdt_num_mem_rsv()
retreives the number of reservation entries in a dtb, and
fdt_get_mem_rsv() retreives a specific reservation entry.
fdt_add_mem_rsv() adds a new entry, and fdt_del_mem_rsv() removes a
specific numbered entry.

Testcases for these new functions are also included.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-15 08:31:52 -05:00
David Gibson
ad9593f229 dtc: Refactor Makefiles
This patch makes a number of Makefile cleanups and improvements:
	- We use more generic rules to invoke flex and bison, which is
useful for some of the other changes.
	- We use the name dtc-lexer.lex.c for the flex output, instead
of the default lex.yy.c.  That means less potential for confusion if
dtc is embedded into other projects (e.g. the kernel).
	- We separate out a Makefile.dtc designed for embedding into
other projects, analagous to Makefile.libfdt.
	- Makefile.libfdt is cleaned up to be more useful based on
some actual trial runs of embedding libfdt in the kernel bootwrapper.
	- Versioning related rules and variables are collected into
one place in the Makefile.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-15 08:28:07 -05:00
David Gibson
d2a9da0458 libfdt: Make unit address optional for finding nodes
At present, the fdt_subnode_offset() and fdt_path_offset() functions
in libfdt require the exact name of the nodes in question be passed,
including unit address.

This is contrary to traditional OF-like finddevice() behaviour, which
allows the unit address to be omitted (which is useful when the device
name is unambiguous without the address).

This patch introduces similar behaviour to
fdt_subnode_offset_namelen(), and hence to fdt_subnode_offset() and
fdt_path_offset() which are implemented in terms of the former.  The
unit address can be omitted from the given node name.  If this is
ambiguous, the first such node in the flattened tree will be selected
(this behaviour is consistent with IEEE1275 which specifies only that
an arbitrary node matching the given information be selected).

This very small change is then followed by many more diffs which
change the test examples and testcases to exercise this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-15 08:27:24 -05:00
David Gibson
02a5556850 libfdt: Test rw functions on more trees
At present, the testcases for read/write functions (setprop,
del_property and del_node) are only invoked on the single
asm-generated tree, not on any of the other tree images which should
be equivalent.  The functions in question will (correctly) not work on
the "unfinished" tree output from sw_tree1, but should work on most of
the others.

This patch extends the run_tests script to invoke the r/w testcases on
more example trees.  The testsuite still passes clean with this
addition.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-15 08:26:11 -05:00
David Gibson
fb7c7acf5a dtc: Use libfdt/fdt.h instead of flat_dt.h
In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and
constants relating to the flattened device tree format derived from
asm-powerpc/prom.h in the kernel.  The former is used in dtc, the
latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that
throughout, removing flat_dt.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-27 08:21:18 -05:00
David Gibson
63dc9c7113 dtc: Whitespace cleanup
This large patch removes all trailing whitespace from dtc (including
libfdt, the testsuite and documentation).  It also removes a handful
of redundant blank lines (at the end of functions, or when there are
two blank lines together for no particular reason).

As well as anything else, this means that quilt won't whinge when I go
to convert the whole of libfdt into a patch to apply to the kernel.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-18 09:43:26 -05:00
David Gibson
8d59bd3b17 dtc: Add basic testcases for dtc
This patch adds a handful of simple testcases for dtc.  It adds a dts
file which should generate the same sample tree as is used for the
libfdt testcases, and tests invoking dtc on this dts, plus the
standard batch of libfdt cases on the resulting dtb, which effectively
checks that the dtb is correct.

Because the test framework assumes each testcase is an executable with
the right output conventions, we use a little shell script, dtc.sh, as
a wrapper around dtc itself.  It simply invokes dtc and returns a PASS
or FAIL depending on whether dtc returned an error.

It's not much, but it's a start.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-18 08:40:36 -05:00
David Gibson
ef90baa0c6 dtc: Cleanup testsuite organization
run_tests.sh from the dtc testsuite currently has a facility ro run
just "functional" or just "stress" tests.  This distinction is carried
over from libhugetlbfs where the test framework originated, and where
it made sense.

In dtc, we have no stress tests, so running these subsections isn't
particularly interesting.  This patch removes these test subsets,
instead defining a single "libfdt" test subset for testcases related
to libfdt (and not dtc proper only.  Currently that's all of the
testcases, but with any luck we'll have some dtc testcases in the
future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-17 14:18:27 -05:00
David Gibson
874ff219af libfdt: Consistently use big-endian property data in testcases
Flat device trees always have integers in their structure stored as
big-endian.  From this point of view, property values are
bags-of-bytes and any endianness is up to users of the device tree to
determine.

The libfdt testcases which use properties with integer values,
currently use native endian format for the architecture on which the
testcases are run.  This works ok for now, since both the creation and
checking of the example device trees happen in the same endianness.

This will become a problem, however, for tests of dtc which we want to
add in the nearish future.  dtc always uses big-endian format for
'cell' format data in properties; as it needs to in order to produce
powerpc-usable device trees when hosted on a little-endian
architecture.

This patch, therefore, changes the libfdt testsuite to use big-endian
format always for integer format data, in order to interoperate sanely
with future dtc testcases.  This also means that the example trees
created by the testsuite should now be byte-for-byte identical
regardless of dtc and libfdt's host platform, which is arguably an
advantage.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-17 14:18:19 -05:00
David Gibson
ae1454b311 libfdt: Add fdt_node_offset_by_prop_value()
This patch adds a function to libfdt to locate nodes containing a
property with a specific value.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-17 13:18:09 -05:00
David Gibson
592ea5888c dtc: Assume properties preced subnodes in the flattened tree
With kernel commit eff2ebd207af9f501af0ef667a7d14befcb36c1b, we
clarified that in the flattened tree format, a particular nodes
properties are required to precede its subdnodes.

At present however, both dtc and libfdt will process trees which don't
meet this condition.  This patch simplifies the code for
fdt_get_property() based on assuming that constraint.  dtc continues
to be able to handle such an invalid tree - on the grounds that it's
useful for dtc to be able to correct such a broken tree - but this
patch adds a warning when this condition is not met while reading a
flattened tree.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-05 13:17:14 -05:00
David Gibson
bf94497031 dtc: Optimise by default, fix warnings thus uncovered
This patch turns on optimisation in the Makefile by default.  With the
optimizer on, some uninitialized variable warnings (one real, two
bogus) are now generated.  This patch also squashes those again.
2007-08-31 08:34:18 -05:00
David Gibson
ed0117a0c0 dtc: Make make print a message when linking testcases
Currently, dtc relies on make's implicit rule to build the testcases.
This means that when not making verbosely (V=0, the default) there is
no message at all while relinking the testsuites.  This can be very
confusing when updating libfdt.a (upon which the testcases depend) and
make appears to do nothing.

This patch corrects the situation, borrowing the rule used to link dtc
itself to link all the testcases as well.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-31 08:34:15 -05:00
David Gibson
e2b3bb3227 libfdt: Fix use of uninitialized variable in fdt_get_path()
My recent implemenetation of fdt_get_path() had a bug - the while loop
tested offset which was unitialized on the first iteration.  Depending
on code surrounding the call, this could cause fdt_get_path() to
return incorrect results.

This patch corrects the problem by applying some more correct thinking
to the loop condition.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-31 08:34:09 -05:00
David Gibson
7ca330865e dtc: Fix summary calculation in testsuite
The bookkeeping for producing the testsuite summary (total number of
tests passed, failed and so forth) is broken.  It uses $? across
several tests, but for checks after the first, the value of $? will no
longer contain the original return code, but just that from the
previous test.  This patch fixes the problem.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-30 08:43:40 -05:00
David Gibson
1248237c7e libfdt: Add fdt_parent_offset() and supporting functions
This patch adds an fdt_parent_offset() function which returns an
offset to the parent node of a given node.  It also adds two helper
functions which are used to implement fdt_parent_offset() but are also
exported: fdt_supernode_atdepth_offset() which returns the ancestor of
a given node at a specified depth from the root of the tree, and
fdt_node_depth() which returns the depth of a given node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-30 08:43:12 -05:00
David Gibson
037db263e0 libfdt: Add fdt_get_path() function
This patch adds an fdt_get_path() function to libfdt, which returns
the full path of a given node in a caller supplied buffer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-30 08:43:06 -05:00
David Gibson
9d26eabdc6 libfdt: Add fdt_get_name() to retrieve a node's name
This patch adds a new fdt_get_name() function to libfdt which will
return a node's name string (including unit address, if any).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-30 08:42:59 -05:00
David Gibson
bd2ae2f41c libfdt: Fix handling of trailing / in fdt_path_offset()
Currently, fdt_path_offset() returns FDL_ERR_BADOFFSET if given a path
with a trailing '/'.  In particular this means that
fdt_path_offset("/") returns FDT_ERR_BADOFFSET rather than 0 as one
would expect.

This patch fixes the function to accept and ignore trailing '/'
characters.  As well as allowing fdt_path_offset("/") this means that
fdt_path_offset("/foo/") will return the same as
fdt_path_offset("/foo") which seems in keeping with the principle of
least surprise.

This also adds a testcase to ensure that fdt_path_offset("/") returns
0 as it should.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-08-30 08:42:45 -05:00
Jon Loeliger
5cb1fbdd7c DTC 1.0.0
For better or worse, it's about damned time!

Signed-off-by: Jon Loeliger <jdl@jdl.com>
2007-08-09 19:31:32 -05:00
Jon Loeliger
9d7e7380ac Merge branch 'doc' 2007-08-09 16:01:07 -05:00
Jon Loeliger
1dc6ca5edc Add initial Device Tree Compiler manual
This is the new location for technical descriptions of the DTC.
Derived from the kernel's Documentation/powerpc/booting-without-of.txt.
The booting-without-of.txt that was here was very old and out of date.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-08-09 15:58:47 -05:00
Jon Loeliger
74ce242bf3 Make release 1.0.0-rc1!
Signed-off-by: Jon Loeliger
2007-07-25 10:53:42 -05:00
David Gibson
4f61ae1627 dtc: Improve the make install target
This patch makes various improvements to dtc's make install target:
	- libfdt is also installed.  Specifically, libfdt.a and the
two export relevant header files, fdt.h and libfdt.h are installed.
	- ftdump is no longer installed.  It was only ever a
development debugging tool and may well go away at some point.
	- In keeping with normal conventions, there is now a PREFIX
variable, allowing control of where things are installed (in /usr,
/usr/local, /opt, etc.).
	- By default, installed into the user's home directory,
instead of /usr.  This is friendlier for self-installers, package
builders can easily override PREFIX to restore the old behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-07-25 10:26:36 -05:00
Jon Loeliger
fdd2e6f945 Reorganized Makefile into better top-down structure.
Also removed a generic "LD" target that wasn't actually used.

Signed-off-by: Jon Loeliger <jdl@jdl.com>
2007-07-07 14:18:02 -05:00
Jon Loeliger
a657ce8fb7 Add DTC release version information.
Adopted the version information and implementation
from of the Linux Kernel Makefiles.

Signed-off-by: Jon Loeliger <jdl@jdl.com>
2007-07-07 13:52:25 -05:00