Commit graph

581 commits

Author SHA1 Message Date
David Gibson
53d6ca639d Trivial style fixup
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>
2012-02-03 08:34:52 -06:00
David Gibson
9cf26ffa4a Add quilt files to .gitignore
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>
2012-02-03 08:34:27 -06:00
David Gibson
81f11f4f10 Update .gitignore for tests
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>
2012-02-03 08:33:29 -06:00
Jon Loeliger
1456da7e2d Introduce ${TESTS_BIN} in Makefiles to identify tested executables. 2012-01-21 15:24:51 -06:00
Simon Glass
1ede50c355 Add fdtput utility to write property values to a device tree
This simple utility allows writing of values into a device tree from the
command line. It aimes to be the opposite of fdtget.

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

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

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

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

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

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

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

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

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

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

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

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

Each value is printed on a new line.

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

To read from stdin, use - as the file.

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

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

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

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-01-13 07:23:58 -06:00
David Gibson
97b909f852 libfdt: Activate testcase for appending properties
Commit a31e3ef83b introduced new libfdt
functions to append to existing properties.  It also included a test case
for this, but neglected to update the Makefile and run_tests.sh script
to actually build and execute this testcase.

This patch corrects the oversight.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-01-11 08:27:40 -06:00
Minghuan Lian
a31e3ef83b libfdt: Add support for appending the values to a existing property
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>
2011-12-05 10:17:58 -06:00
Mike Frysinger
8f459c5d72 fdtdump: rename from ftdump
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>
2011-10-26 08:07:51 -05:00
Anton Staaf
033089f290 dtc: Add support for variable sized elements
Elements of size 8, 16, 32, and 64 bits are supported.  The new
/bits/ syntax was selected so as to not pollute the reserved
keyword space with uint8/uint16/... type names.

With this patch the following property assignment:

    property = /bits/ 16 <0x1234 0x5678 0x0 0xffff>;

is equivalent to:

    property = <0x12345678 0x0000ffff>;

It is now also possible to directly specify a 64 bit literal in a
cell list, also known as an array using:

    property = /bits/ 64 <0xdeadbeef00000000>;

It is an error to attempt to store a literal into an element that is
too small to hold the literal, and the compiler will generate an
error when it detects this.  For instance:

    property = /bits/ 8 <256>;

Will fail to compile.  It is also an error to attempt to place a
reference in a non 32-bit element.

The documentation has been changed to reflect that the cell list
is now an array of elements that can be of sizes other than the
default 32-bit cell size.

The sized_cells test tests the creation and access of 8, 16, 32,
and 64-bit sized elements.  It also tests that the creation of two
properties, one with 16 bit elements and one with 32 bit elements
result in the same property contents.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-10-11 12:58:30 -05:00
Anton Staaf
a4b515c038 dtc: Add data_append_integer function
This function deals with appending integers of various sizes (8, 16
32, and 64 bit currently).  It handles endianess conversions.  If the
integer will not fit in the requested number of bits of storage it
will have it's high bits ignored.

This patch also rewrites data_append_cell and data_append_addr to use
data_append_integer.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-10-11 12:58:03 -05:00
Anton Staaf
2cd4c8d27d libfdt: Add fdt16_to_cpu utility function
This utility routine will be used in the variable size cell literal
append code.  It is a straightforward adaptation of the fdt32_to_cpu
function.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-10-11 12:57:36 -05:00
Simon Glass
07a8691fbb ftdump: use utilfdt to read blob
Now that we have utilfdt_read(), ftdump should use it too.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:50:50 -05:00
Simon Glass
1c25c0d520 Make testutils use utilfdt
The load_blob() and save_blob() functions are very similar to the utilfdt
versions. This removes the duplicated code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:50:34 -05:00
Simon Glass
36204fdf74 Add fdt read/write utility functions
This adds higher-level libfdt operations for reading/writing an fdt
blob from/to a file, as well as a function to decode a data type string
as will be used by fdtget, fdtput.

This also adds a few tests for the simple type argument supported by
utilfdt_decode_type.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 13:49:33 -05:00
Simon Glass
9ebd9b4a56 Create Makefile.utils and move ftdump into it
We want to avoid a separate Makefile include for each utility, so this sets
up a general one for utilities.

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Simon Glass <sjg@chromium.org>
2011-09-22 10:16:28 -05:00
Anton Staaf
a4ea2fa951 dtc: Support character literals in cell lists
With this patch the following property assignment:

    property = <0x12345678 'a' '\r' 100>;

is equivalent to:

    property = <0x12345678 0x00000061 0x0000000D 0x00000064>

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-22 09:24:31 -05:00
David Gibson
83df28bd39 dtc: Remove gcc 4.6 "set but not used" warnings
A number of the dtc testcases trigger the new "variable set but not
used" warning from gcc 4.6.  That is they have variables which are
assigned, but then never read after that point.

In a couple of cases this is just because the variables aren't needed,
so this patch removes them.  In subnode_offset.c, it's because one
pair of variables we clearly intended to test we don't actually test.
This patch also adds this missing check.

This patch makes the testsuite compile clean with gcc 4.6.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-17 11:46:07 -05:00
Anton Staaf
b43335a238 dtc: Refactor character literal parsing code
Move the parsing of hex, octal and escaped characters from data.c
to util.c where it can be used for character literal parsing within
strings as well as for stand alone C style character literals.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-09-09 16:05:36 -05:00
Simon Glass
ed8fee1a64 Add missing tests to .gitignore
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-07-17 07:44:29 -05:00
Simon Glass
492f9d5de7 Split out is_printable_string() into util.c
This useful function is split out so it will be available to programs
other than ftdump.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-07-17 07:42:26 -05:00
Josh Boyer
d5b3165023 dtc: Remove unused variable in flat_read_mem_reserve
The *p variable is declared and used to save inb->ptr, however p is
later never used.  This has been the case since commit 6c0f3676 and can
lead to build failures with -Werror=unused-but-set-variable:

	flattree.c: In function 'flat_read_mem_reserve':
	flattree.c:700:14: error: variable 'p' set but not used [-Werror=unused-but-set-variable]
	cc1: all warnings being treated as errors
	make: *** [flattree.o] Error 1

Remove the variable.

Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-07-17 07:32:59 -05:00
Josh Boyer
0a5aca98ba dtc: Remove unused check variable
Commit 376ab6f2 removed the old style check functionality from DTC,
however the check option and variable were not removed.  This leads to
build failures when -Werror=unused-but-set-variable is specified:

	dtc.c: In function 'main':
	dtc.c:102:17: error: variable 'check' set but not used [-Werror=unused-but-set-variable]
	cc1: all warnings being treated as errors
	make: *** [dtc.o] Error 1
	make: *** Waiting for unfinished jobs....

Remove the check variable.

Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2011-07-17 07:31:11 -05:00
Jon Loeliger
bc895d6d09 Tag Version 1.3.0
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2011-05-08 14:45:39 -05:00
Paolo Bonzini
99c1db78dc libfdt: include version number in soname
The libfdt shared library is only installed by its unversioned name.
Including it properly in a distribution requires installation of both
the versioned name (used in the binary-only package) and the unversioned
name (used in the development package).  The latter is just a symbolic
link, so you need to change the soname in turn to include the version.

While at it, use Makefile variables to shorten some lines and avoid
cut-and-paste typos; and clean up remnants of when shared libraries were
not supported on Darwin.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2011-04-29 08:40:31 -05:00
David Gibson
37c0b6a091 dtc: Add code to make diffing trees easier
This patch adds a "dtdiff" script to do a useful form diff of two
device trees.  This automatically converts the tree to dts form (if
it's not already) and uses a new "-s" option in dtc to "sort" the
tree.  That is, it sorts the reserve entries, it sorts the properties
within each node by name, and it sorts nodes by name within their
parent.

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

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

Signed-off-by: John Bonesio <bones@secretlab.ca>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2010-11-13 14:44:06 -06:00
John Bonesio
c0fa2e6d4e Create new and use new print_error that uses printf style formatting.
yyerror is meant to be called by the parser internal code, and it's interface
is limited. Instead create and call a new error message routine that allows
formatted strings to be used.

yyerror uses the new routine so error formatting remains consistent.

Signed-of-by: John Bonesio <bones@secretlab.ca>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-10-20 22:36:53 -06:00
David Gibson
8773e12fa9 Add merging of labelled subnodes. This patch allows the following
syntax:

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

&label {
	prop = "value";
};

which will result in the following tree:

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

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

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

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-09-20 09:32:21 -05:00
Martin Ettl
0e89e8c5a0 Fix a filehandle leak
During a check of the current git head of the linux kernel with the
static code analysis tool cppcheck
(http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page)
the tool discovered a resource leak in linux-2.6/scripts/dtc/fstree.c.

Please refer the attached patch, that fixes the issue.

Fixes https://bugzilla.kernel.org/show_bug.cgi?id=15363

Signed-off-by: Martin Ettl <ettl.martin@gmx.de>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-07-14 17:29:19 -05:00
David Gibson
e3b32b75b5 dtc: Extend and better test dtbs_equal utility programs (resend)
The dtbs_equal_ordered test program is used to implement a number of
testcases.  However, the test program itself has never been
particularly well tested.  In addition there are testcases coming in
future for which it would be useful to have a corresponding
"dtbs_equal_unordered" which checks for equality of device trees, not
considering the internal ordering of elements.  Finally, for some
tests we may want it would be useful to check trees for equality with
the PASS case being when they are *not* equal.

This patch addresses all of the above.  A dtbs_equal_unordered is
added, and both it and the existing dtbs_equal_ordered program now
take a -n option to make the PASS case be where the trees are not
equal.  A number of example trees with slight modifications from
test_tree1 are used to verify that both these programs correctly
identify when the tree is altered, and a dtb_reverse program is used
to verify that the unordered version does not depend on internal
ordering.  These new testcases for the equality testing programs are
split out into a new test group in run_tests.sh.

dtbs_equal_unordered uses the new property iteration functions, and so
this also acts as further testing for those functions.
dtbs_equal_unordered will be useful for further testing the recently
added tree-merging code and its upcoming extensions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-04-30 08:36:54 -05:00
David Gibson
341df2bdc3 dtc: Add -Wredundant-decls (resend)
We are almost clean already with the -Wredundant-decls warning.  The
only exception is a declaration for isatty() inside the flex-generated
code.  This can be removed by using flex's "never-interactive" option,
which we probably should be using anyway, since we never parse
interactively in the sense that this option implies.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-04-30 08:36:47 -05:00
David Gibson
73dca9ae0b libfdt: Implement property iteration functions
For ages, we've been talking about adding functions to libfdt to allow
iteration through properties.  So, finally, here are some.

I got bogged down on this for a long time because I didn't want to
expose offsets directly to properties to the callers.  But without
that, attempting to make reasonable iteration functions just became
horrible.  So eventually, I settled on an interface which does now
expose property offsets.  fdt_first_property_offset() and
fdt_next_property_offset() are used to step through the offsets of the
properties starting from a particularly node offset.  The details of
the property at each offset can then be retrieved with either
fdt_get_property_by_offset() or fdt_getprop_by_offset() which have
interfaces similar to fdt_get_property() and fdt_getprop()
respectively.

No explicit testcases are included, but we do use the new functions to
reimplement the existing fdt_get_property() function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-03-10 08:13:00 -06:00
David Gibson
74f6a51b1f dtc: Enable more warnings
This patch turns on a bunch of extra gcc warnings, most of which are
probably a good idea.  Of the new warnings -Wnested-externs and
-Wstrict-prototypes need no code changes, we're already warning-clean.
The remaining one, -Wmissing-prototypes requires trivial changes in
some of the tests (making functions local).

This patch also rearranges the warnings flags into a separate make
variable for convenience, and turns on -Werror, to really encourage
people to keep the code warning-clean.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-03-10 08:12:28 -06:00
David Gibson
8765874963 dtc: Correct headers in util.c
Since util.c is used in programs other than full dtc, it shouldn't
include the full dtc.h, just util.h which has prototypes directly
relevant to it.  This patch makes the change, and also adds includes
of the necessary system headers which were previously included
indirectly by dtc.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-03-03 07:55:54 -06:00
Grant Likely
9dfb495f80 Update .gitignore files
Filter out all the generated bits from git revision control

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-02-25 11:47:58 -06:00
Grant Likely
83da1b2a4e Allow device tree to be modified by additonal device tree sections
This patch allows the following construct:

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

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

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

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
2010-02-25 11:46:01 -06:00
David Gibson
716418849a dtc: Audit and fix valgrind errors
The somewhat embarrasing bug in the first version of my previous patch
would have been detected by valgrind.  Thus reminded, I've run the
testsuite under valgrind and fixed any errors I found.  This turned
out to be just some uninitialized buffers in test programs.  The
fragments of uninitialized data aren't particularly important, but we
might as well squash the valgrind warnings, so that future valgrind
errors will stand out.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-24 08:50:25 -06:00
David Gibson
05898c67c1 dtc: Allow multiple labels on nodes and properties
At present, both the grammar and our internal data structures mean
that there can be only one label on a node or property.  This is a
fairly arbitrary constraint, given that any number of value labels can
appear at the same point, and that in C you can have any number of
labels on the same statement.

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

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

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

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

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

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

Testcases for the new code are also added.

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

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

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-19 08:36:23 -06:00
Lukasz Wojcik
5c8d2e2b57 Modification of lexer and parser, improving dtc portability.
This mod allows successful build of dtc using both bison/flex and yacc/lex.

Signed-off-by: Lukasz Wojcik <zbr@semihalf.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2010-02-08 09:29:52 -06:00
David Gibson
c6225f86fd dtc: Cleanup YYLTYPE and YYLLOC_DEFAULT declarations
This patch makes some small cleanups to the declaration of YYLTYPE,
YYLLOC_DEFAULT and related things.

	- We used to use undocumented magic #defines for bison,
          YYLTYPE_IS_DECLARED and YYLTYPE_IS_TRIVIAL.  This may not be
          portable across bison versions.  Instead define YYLTYPE as a
          macro in terms of struct srcpos, as the info pages suggest.

	- Our kernel-derived coding style discourages typedefed
          structures.  So use 'struct srcpos' instead of 'srcpos'
          throughout'.

	- Indent the YYLLOC_DEFAULT macro according to our coding
          style (it was in GNU indent style, since it was taken from
          the example in the bison info).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14 07:53:00 -06:00
David Gibson
e1fee329e2 dtc: Cleanup srcpos_string()
There are several small problems with the current srcpos_string().

	- The code unnecessarily uses a temp buffer and two rounds of
	  *printf(); a single asprintf() will suffice.

	- With previous changes, pos->file->name can never be NULL,
          and the name field for a srcfile bound to stdin is already
          set to something sensible.

	- On allocation failure in asprintf() it returns a bogus
          result, instead of causing a fatal error like every other
          failed allocation.

	- The format for representing file/line/column is gratuitously
          different from the file/line format we used to use, and the
          format used by gcc and bison.

This patch addresses all of these.  There remains the problem that
asprintf() is not portable, but that can wait until another patch.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14 07:52:56 -06:00
David Gibson
728c5e87c6 dtc: Cleanup line number tracking, add column number tracking
Our YYLTYPE current carries around first and last line and first and
last column information.  However, of these, on the first line
information is actually filled in properly.

Furthermore, filling in the line number information from yylineno is
kind of clunky: we have to copy its value to the srcfile stack and
back to handle include file positioning correctly.

This patch cleans this up.  We turn off flex's yylineno option and
instead track the line and column number ourselves from
YY_USER_ACTION.  The line and column number are stored directly inside
the srcfile_state structure, so it's automatically a per-file
quantity.  We now also fill in all the yylloc from YY_USER_ACTION.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14 07:52:48 -06:00
David Gibson
d68cb36b0b dtc: Simpler interface to source file management
This patch cleans up our handling of input files, particularly dts
source files, but also (to an extent) other input files such as those
used by /incbin/ and those used in -I dtb and -I fs modes.

We eliminate the current clunky mechanism which combines search paths
(which we don't actually use at present) with the open relative to
current source file behaviour, which we do.

Instead there's a single srcfile_relative_open() entry point for
callers which opens a new input file relative to the current source
file (which the srcpos code tracks internally).  It doesn't currently
do search paths, but we can add that later without messing with the
callers, by drawing the search path from a global (which makes sense
anyway, rather than shuffling it around the rest of the processing
code).

That suffices for non-dts input files.  For the actual dts files,
srcfile_push() and srcfile_pop() wrappers open the file while also
keeping track of it as the current source file for future opens.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2010-01-14 07:52:25 -06:00
David Gibson
d75b33af67 Support ePAPR compliant phandle properties
Currently, the Linux kernel, libfdt and dtc, when using flattened
device trees encode a node's phandle into a property named
"linux,phandle".  The ePAPR specification, however - aiming as it is
to not be a Linux specific spec - requires that phandles be encoded in
a property named simply "phandle".

This patch adds support for this newer approach to dtc and libfdt.
Specifically:

	- fdt_get_phandle() will now return the correct phandle if it
          is supplied in either of these properties

	- fdt_node_offset_by_phandle() will correctly find a node with
          the given phandle encoded in either property.

	- By default, when auto-generating phandles, dtc will encode
          it into both properties for maximum compatibility.  A new -H
          option allows either only old-style or only new-style
          properties to be generated.

	- If phandle properties are explicitly supplied in the dts
	  file, dtc will not auto-generate ones in the alternate format.

	- If both properties are supplied, dtc will check that they
          have the same value.

	- Some existing testcases are updated to use a mix of old and
          new-style phandles, partially testing the changes.

	- A new phandle_format test further tests the libfdt support,
          and the -H option.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-11-26 15:06:17 -06:00