Commit graph

468 commits

Author SHA1 Message Date
David Gibson
b2b4990bbf dtc: Move some functions to util.[ch]
Now that we have a util.[ch] file shared between dtc and
convert-dtsv0, move some functions which are currently duplicated in
the two to util files.  Specifically we move the die(), xmalloc() and
xrealloc() functions.

While we're at it, add standard double-include protection to util.h

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-01-07 09:46:04 -06:00
David Gibson
75bdd849dc libfdt: Fix error in documentation for fdt_get_alias_namelen()
Oops, screwed up the function name in the documenting comment for this
function.  Trivial correction in this patch.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2009-01-07 09:43:23 -06:00
Josh Boyer
6272182b41 libfdt: Introduce libfdt shared library
Build a libfdt shared library in addition to the existing .a that is
created.  Symbol versioning is used from the libfdt/version.lds script.

Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
2009-01-02 09:00:52 -06:00
Josh Boyer
787b599c81 libfdt: Add version.lds file
Add the initial symbol versioning file as groundwork for creating
a libfdt shared library

Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
2009-01-02 08:56:42 -06:00
David Gibson
9878f30f31 dtc: Handle linux,phandle properties which self-reference
Currently, dtc will generate phandles for nodes which are referenced
elsewhere in the tree.  phandles can also be explicitly assigned by
defining the linux,phandle property.  However, there is no way,
currently to tell dtc to generate a phandle for a node if it is not
referenced elsewhere.  This is inconvenient when it's expected that
later processing on the flat tree might add nodes which _will_
the node in question.

One way one might attempt to do this is with the construct:
	mynode: mynode {
		linux,phandle = <&mynode>;
		/* ... */
	};
Though it's a trifle odd, there's really only one sensible meaning
which can be assigned to this construct: allocate a unique phandle to
"mynode" and put that in its linux,phandle property (as always).

Currently, however, dtc will choke on this self-reference.  This patch
corrects this, making the construct above give the expected results.
It also ensures a more meaningful error message is given if you
attempt to process the nonsensical construct:
	mynode: mynode {
		linux,phandle = <&someothernode>;
		/* ... */
	};

The 'references' testcase is extended to cover this case, as well.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-17 14:05:48 -06:00
David Gibson
2f766233c2 dtc: Use noinput flex option for convert-dtsv0 to remove warning
The convert-dtsv0 lexer doesn't use lex's input() macro/function.
This can result in "defined but not used" warnings.  This patch uses
flex's noinput option to prevent this warning (as we already do for
dtc-lexer.l).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-17 14:05:24 -06:00
David Gibson
0783d7e705 dtc: Check return value from fwrite()
There's one place in flattree.c where we currently ignore the return
value from fwrite().  On some gcc/glibc versions, where fwrite() is
declared with attribute warn_unused_result, this causes a warning.

This patch fixes the warning, by checking the fwrite() result.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-17 14:04:35 -06:00
David Gibson
f99cd158a9 libfdt: Fix bug in fdt_subnode_offset_namelen()
There's currently an off-by-one bug in fdt_subnode_offset_namelen()
which causes it to keep searching after it's finished the subnodes of
the given parent, and into the subnodes of siblings of the original
node which come after it in the tree.

This patch fixes the bug.  It also extends the subnode_offset testcase
(updating all of the 'test_tree1' example trees in the process) to
catch it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-11-05 08:12:10 -06:00
Jon Loeliger
2ebe88df69 Add conditionalized debug() print macro.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 16:09:37 -05:00
Jon Loeliger
4e1a0a0129 Remove support for the legacy DTS source file format.
Now that all in-kernel-tree DTS files are properly /dts-v1/,
remove direct support for the older, un-numbered DTS
source file format.

Convert existing tests to /dts-v1/ and remove support
for the conversion tests themselves.

For now, though, the conversion tool still exists.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 16:09:34 -05:00
Jon Loeliger
e5c8e1dcd7 Enhance source position implementation.
Implemented some print and copy routines.
Made empty srcpos objects that will be used later.
Protected .h file from multiple #include's.
Added srcpos_error() and srcpos_warn().

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 15:38:08 -05:00
Jon Loeliger
83ac55d9c4 Use flex's YY_USER_ACTION feature to avoid code duplication
Current, every lexer rule starts with some boiler plate to update the
yylloc value for use by the parser.  One of the rules, even mistakenly
has a redundant allocation to one of the members.

This patch uses the flex YY_USER_ACTION macro hook, which is executed
before every rule to avoid this duplication.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-03 11:46:43 -05:00
Jon Loeliger
879e4d2590 Implement and use an xstrdup() function
Many places in dtc use strdup(), but none of them actually check the
return value to see if the implied allocation succeeded.  This is a
potential bug, which we fix in the patch below by replacing strdup()
with an xstrdup() which in analogy to xmalloc() will quit with a fatal
error if the allocation fails.

I felt the introduciton of util.[ch] was a better choice
for utility oriented code than directly using srcpos.c
for the new string function.

This patch is a re-factoring of Dave Gibson's similar patch.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 11:12:33 -05:00
Jon Loeliger
68f98d7b8a Rearrange ftdump and convert-dtsv0 into sub-Makefiles.
Follows the model of the existing sub-Makefiles for dtc.

Adjust $(BIN) definition to represent installable bin programs
and use it as the list of installed programs rather than using
an enumerated list in the install target.

Adjust the tests/Makefile to clean up properly still.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03 10:50:28 -05:00
Jon Loeliger
e8903fe225 Some Documentation fixes and generalizations.
Updated a jdl.com URL reference.

Generalized the new section IV to be "Utility Tools"
and added a small blurb about ftdump as well.

Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-10-03 09:42:26 -05:00
Niklaus Giger
3a90ce6d75 Install & document convert-dtsv0
Signed-off-by: Niklaus Giger <niklaus.giger@member.fsf.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-03 09:24:05 -05:00
David Gibson
9c83115351 libfdt: Add function to explicitly expand aliases
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias.  This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-02 08:49:51 -05:00
Jon Loeliger
b236893fc4 Fix an overflow case in fdt_offset_ptr() detected by GCC 4.3.
Using Gcc 4.3 detected this problem:

    ../dtc/libfdt/fdt.c: In function 'fdt_next_tag':
    ../dtc/libfdt/fdt.c:82: error: assuming signed overflow does not
    occur when assuming that (X + c) < X is always false

To fix the problem, treat the offset as an unsigned int.

The problem report and proposed fix were provided
by Steve Papacharalambous <stevep@freescale.com>.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-09-25 15:45:48 -05:00
David Gibson
8daae14b74 libfdt: Fix bugs in fdt_get_path()
The current implementation of fdt_get_path() has a couple of bugs,
fixed by this patch.

First, contrary to its documentation, on success it returns the length
of the node's path, rather than 0.  The testcase is correspondingly
wrong, and the patch fixes this as well.

Second, in some circumstances, it will return -FDT_ERR_BADOFFSET
instead of -FDT_ERR_NOSPACE when given insufficient buffer space.
Specifically this happens when there is insufficient space even to
hold the path's second last component.  This behaviour is corrected,
and the testcase updated to check it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-09-25 09:34:27 -05:00
Kumar Gala
02cc83540b libfdt: Add support for using aliases in fdt_path_offset()
If the path doesn't start with '/' check to see if it matches some alias
under "/aliases" and substitute the matching alias value in the path
and retry the lookup.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-14 10:24:58 -05:00
David Gibson
cb650ae143 libfdt: Implement fdt_get_property_namelen() and fdt_getprop_namelen()
As well as fdt_subnode_offset(), libfdt includes an
fdt_subnode_offset_namelen() function that takes the subnode name to
look up not as a NUL-terminated string, but as a string with an
explicit length.  This can be useful when the caller has the name as
part of a longer string, such as a full path.

However, we don't have corresponding 'namelen' versions for
fdt_get_property() and fdt_getprop().  There are less obvious use
cases for these variants on property names, but there are
circumstances where they can be useful e.g. looking up property names
which need to be parsed from a longer string buffer such as user input
or a configuration file, or looking up an alias in a path with
IEEE1275 style aliases.

So, since it's very easy to implement such variants, this patch does
so.  The original NUL-terminated variants are, of course, implemented
in terms of the namelen versions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-13 13:06:01 -05:00
David Gibson
01a2d8a3e9 dtc: Make many functions 'static'
This patch marks various functions not shared between c files
'static', as they should be.  There are a couple of functions in dtc,
and many in the testsuite.

This is *almost* enough to enable the -Wmissing-prototypes warning.
It's not quite enough, because there's a mess of junk in the flex
generated code which triggers that warning which I'm not yet sure how
to deal with.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-08-13 13:04:39 -05:00
Paul Gortmaker
315c5d095e dtc: give advance warning that "-S" is going away.
The "-S" option allowed the specification of a minimum size for
the blob, however the main reason for caring about the size is
so there is enough padding to add a chosen node by u-boot or
whoever.  In which case, folks don't really care about the absolute
size, but rather the size of the padding added for this -- which
is what the "-p" option does.  Having the "-S" just confuses people.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2008-07-31 10:38:10 -05:00
David Gibson
a1db0749fd dtc: Remove unused lexer function
dtc does not use the input() function in flex.  Apparently on some gcc
versions the unused function will cause warnings.  Therefore, this
patch removes the function by using the 'noinput' option to flex.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-31 10:37:45 -05:00
David Gibson
d5653618d2 libfdt: Forgot one function when cleaning the namespace
In commit b6d80a20fc, we renamed all
libfdt functions to be prefixed with fdt_ or _fdt_ to minimise the
chance of collisions with things from whatever package libfdt is
embedded in, pulled into the libfdt build via that environment's
libfdt_env.h.

Except... I missed one.  This patch applies the same treatment to
_stringlist_contains().  While we're at it, also make it static since
it's only used in the same file.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-31 10:37:20 -05:00
Jon Loeliger
52c356d81b Tag Version 1.2.0
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-07-25 16:17:04 -05:00
Jon Loeliger
a653228522 libfdt: Fix 'make install' target handling of .h files.
The definition of LIBFDT_INCLUDES was accidentally dropped.
Put it back and add srcdir prefix handling for it.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-07-23 12:12:34 -05:00
Jon Loeliger
17773b0e51 Tag Version 1.2.0-rc2
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-07-14 13:45:08 -05:00
Wolfram Sang
08309aa1a4 libfdt: Improve documentation in libfdt.h
Fix a few typos and mistakes.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 13:34:25 -05:00
David Gibson
b6d80a20fc libfdt: Increase namespace-pollution paranoia
libfdt is supposed to easy to embed in projects all and sundry.
Often, it won't be practical to separate the embedded libfdt's
namespace from that of the surrounding project.  Which means there can
be namespace conflicts between even libfdt's internal/static functions
and functions or macros coming from the surrounding project's headers
via libfdt_env.h.

This patch, therefore, renames a bunch of libfdt internal functions
and macros and makes a few other chances to reduce the chances of
namespace collisions with embedding projects.  Specifically:
	- Internal functions (even static ones) are now named _fdt_*()

	- The type and (static) global for the error table in
          fdt_strerror() gain an fdt_ prefix

	- The unused macro PALIGN is removed

	- The memeq and streq macros are removed and open-coded in the
          users (they were only used once each)

	- Other macros gain an FDT_ prefix

	- To save some of the bulk from the previous change, an
          FDT_TAGALIGN() macro is introduced, where FDT_TAGALIGN(x) ==
          FDT_ALIGN(x, FDT_TAGSIZE)

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:36:27 -05:00
David Gibson
4d7bea7873 dtc: Run relevant checks on dtb input as well as dts
This patch adjusts the testsuite to run most of the tests for the tree
checking code on input in dtb form as well as dts form.  Some checks
which only make sense for dts input (like reference handling) are
excluded, as are those which currently take dtb input because they
rely on things which cannot be lexically constructed in a dts file.

This shows up two small bugs in dtc, which are also corrected.

First, the name_properties test which was is supposed to remove
correctly formed 'name' properties (because they can be reconstructed
from tne node name) was instead removing 'name' properties even if
they weren't correct.

Secondly, when using dtb or fs input, the runtime tree in dtc did not
have the parent pointer initialized propertly because.built
internally.  The appropriate initialization is added to the
add_child() function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:36:08 -05:00
David Gibson
1409097db8 dtc: Enable and fix -Wcast-qual warnings
Enabling -Wcast-qual warnings in dtc shows up a number of places where
we are incorrectly discarding a const qualification.  There are also
some places where we are intentionally discarding the 'const', and we
need an ugly cast through uintptr_t to suppress the warning.  However,
most of these are pretty well isolated with the *_w() functions.  So
in the interests of maximum safety with const qualifications, this
patch enables the warnings and fixes the existing complaints.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:36:08 -05:00
David Gibson
36786db615 dtc: Enable and fix -Wpointer-arith warnings
This patch turns on the -Wpointer-arith option in the dtc Makefile,
and fixes the resulting warnings due to using (void *) in pointer
arithmetic.  While convenient, pointer arithmetic on void * is not
portable, so it's better that we avoid it, particularly in libfdt.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:36:08 -05:00
David Gibson
76e0622b68 dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include.  We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.

This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code.  This is mildly irritating.

However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE.  For
example the following strange dts file:

	/include/ /dts-v1/;
	/ {
		 /* ... */
	};

Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack.  Or
for another example this construct:
	foo /include/ = "somefile.dts"
will be parsed as though it were:
	foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.

And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.

This patch, therefore, cleans up the lexical handling of the /include/
directive.  Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token.  This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above.  It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-07-14 12:21:24 -05:00
David Gibson
cdcb415851 dtc: Address an assortment of portability problems
I've recently worked with a FreeBSD developer, getting dtc and libfdt
working on FreeBSD.  This showed up a number of portability problems
in the dtc package which this patch addresses.  Changes are as
follows:

	- the parent_offset and supernode_atdepth_offset testcases
used the glibc extension functions strchrnul() and strndupa().  Those
are removed, using slightly longer coding with standard C functions
instead.

	- some other testcases had a #define _GNU_SOURCE for no
particular reason.  This is removed.

	- run_tests.sh has bash specific constructs removed, and the
interpreter changed to /bin/sh.  This apparently now runs fine on
FreeBSD's /bin/sh, and I've also tested it with both ash and dash.

	- convert-dtsv0-lexer.l has some extra #includes added.  These
must have been included indirectly with Linux and glibc, but aren't on
FreeBSD.

	- the endian handling functions in libfdt_env.h, based on
endian.h and byteswap.h are replaced with some portable open-coded
versions.  Unfortunately, these result in fairly crappy code when
compiled, but as far as I can determine there doesn't seem to be any
POSIX, SUS or de facto standard way of determining endianness at
compile time, nor standard names for byteswapping functions.

	- some more endian handling, from testdata.h using the
problematic endian.h is simply removed, since it wasn't actually being
used anyway.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:21:18 -05:00
David Gibson
11d7100ee5 dtc: Use libfdt endian conversion functions in libfdt
Following on from the last patch, which made dtc use the same endian
conversion functions as libfdt, this patch makes ftdump use these
functions as well.  This brings us down to a single set of endian
handling functions in all of dtc and libfdt, so just one place to fix
things.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:07:25 -05:00
David Gibson
c8c374b856 dtc: Use the same endian-conversion functions as libfdt
Currently both libfdt and dtc define a set of endian conversion macros
for accessing the device tree blob which is always big-endian.  libfdt
uses names like cpu_to_fdt32() and dtc uses names like cpu_to_be32 (as
the Linux kernel).  This patch switches dtc over to using the libfdt
macros (including libfdt_env.h to supply them).  This has a couple of
small advantages:
	- Removes some code duplication
	- Will make conversion a bit easier if we ever need to produce
          little-endian device tree blobs.
	- dtc no longer needs to pull in netinet/in.h simply for the
          ntohs() and ntohl() functions

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:07:22 -05:00
David Gibson
53359016ca dtc: Use stdint.h types throughout dtc
Currently, dtc defines Linux-like names for various fixed-size integer
types.  There's no good reason to do this; even Linux itself doesn't
use these names for externally visible things any more.  This patch
replaces these with the C99 standardized type names from stdint.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:07:19 -05:00
David Gibson
f8e52fe6d8 dtc: Testcase for /include/ directive
This patch adds a testcase for the /include/ directive.  It assembles
a sample dts file with many /include/ directives at a variety of
different lexical / grammatical contexts.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-07-14 12:07:14 -05:00
Jon Loeliger
f8bf4bfc87 Tag Version 1.2.0-rc1
Signed-off-by: Jon Loeliger <jdl@jdl.com>
2008-06-19 11:33:20 -05:00
David Gibson
e37ec7d588 dtc: Add support for binary includes.
On Wed, Jun 04, 2008 at 09:26:23AM -0500, Jon Loeliger wrote:
> David Gibson wrote:
>
>> But as I said that can be dealt with in the future without breaking
>> compatibility.  Objection withdrawn.
>>
>
> And on that note, I officially implore Scott to
> re-submit his binary include patch!

Scott's original patch does still have some implementation details I
didn't like.  So in the interests of saving time, I've addressed some
of those, added a testcase, and and now resubmitting my revised
version of Scott's patch.

dtc: Add support for binary includes.

A property's data can be populated with a file's contents
as follows:

node {
	prop = /incbin/("path/to/data");
};

A subset of a file can be included by passing start and size parameters.
For example, to include bytes 8 through 23:

node {
	prop = /incbin/("path/to/data", 8, 16);
};

As with /include/, non-absolute paths are looked for in the directory
of the source file that includes them.

Implementation revised, and a testcase added by David Gibson

Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Scott Wood <scottwood@freescale.com>
2008-06-19 10:01:14 -05:00
David Gibson
050e6f0cff dtc: Add a testcase for 'reg' or 'ranges' in /
This patch adds an extra testcase to dtc to ensure that the
"reg_format" and "ranges_format" checks trigger as they should if a
'reg' or 'ranges' property appears in the root node.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-02 15:20:08 -05:00
David Gibson
6aaee513dd dtc: Fix some printf() format warnings when compiling 64-bit
Currently, dtc generates a few gcc build warnings if built for a
64-bit target, due to the altered type of uint64_t and size_t.  This
patch fixes the warnings (without generating new warnings for 32-bit).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-06-02 15:18:48 -05:00
David Gibson
fc6e6f8d91 dtc: Remove some small bashisms from test scripts
Some of the helper scripts used to run testcases contain some
constructs that are bashisms.  Or at least which don't work on dash,
the minimal shell used as /bin/sh on recent Ubuntu systems.

This patch removes these constructs so that the testsuite will pass
"out of the box" on systems where /bin/sh is dash.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-29 08:16:03 -05:00
David Gibson
aa1baab3cc libfdt: Several cleanups to parameter checking
This patch makes a couple of small cleanups to parameter checking of
libfdt functions.

	- In several functions which take a node offset, we use an
idiom involving fdt_next_tag() first to check that we have indeed been
given a node offset.  This patch adds a helper function
_fdt_check_node_offset() to encapsulate this usage of fdt_next_tag().

	- In fdt_rw.c in several places we have the expanded version
of the RW_CHECK_HEADER() macro for no particular reason.  This patch
replaces those instances with an invocation of the macro; that's what
it's for.

	- In fdt_sw.c we rename the check_header_sw() function to
sw_check_header() to match the analgous function in fdt_rw.c, and we
provide an SW_CHECK_HEADER() wrapper macro as RW_CHECK_HEADER()
functions in fdt_rw.c

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-29 08:15:53 -05:00
David Gibson
e4a64a8cd0 dtc: Remove reference to dead Makefile variables
Previous cleanups have removed the LIBFDT_CLEANFILES and
DTC_CLEANFILES variables from the Makefiles.  However, they're still
referenced by the Makefile.  This patch gets rid of these last
vestiges.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-29 08:12:08 -05:00
David Gibson
a84c065f44 dtc: Add program to convert dts files from v0 to v1
This patch adds a new utility program, convert-dtsv0, to the dtc
sources.  This program will convert dts files from v0 to v1,
preserving comments and spacing.  It also includes some heuristics to
guess an appropriate base to use in the v1 output (so it will use hex
for the contents of reg properties and decimal for clock-frequency
properties, for example).  They're limited and imperfect, but not
terrible.

The guts of the converter program is a modified version of the lexer
from dtc itself.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 21:18:47 -05:00
David Gibson
548767f42e dtc: Rework handling of boot_cpuid_phys
Currently, dtc will put the nonsense value 0xfeedbeef into the
boot_cpuid_phys field of an output blob, unless explicitly given
another value with the -b command line option.  As well as being a
totally unuseful default value, this also means that dtc won't
properly preserve the boot_cpuid_phys field in -I dtb -O dtb mode.

This patch reworks things to improve the boot_cpuid handling.  The new
semantics are that the output's boot_cpuid_phys value is:
	the value given on the command line if -b is used
otherwise
	the value from the input, if in -I dtb mode
otherwise
	0

Implementation-wise we do the following:
	- boot_cpuid_phys is added to struct boot_info, so that
structure now contains all of the blob's semantic information.
	- dt_to_blob() and dt_to_asm() output the cpuid given in
boot_info
	- dt_from_blob() fills in boot_info based on the input blob
	- The other dt_from_*() functions just record 0, but we can
change this easily if e.g. we invent a way of specifying the boot cpu
in the source format.
	- main() overrides the cpuid in the boot_info between input
and output if -b is given

We add some testcases to check this new behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 14:12:15 -05:00
David Gibson
a742aade6a dtc: Make dt_from_blob() open its own input file, like the other input formats
Currently, main() has a variable for the input file.  It used to be
that main() would open the input based on command line arguments
before passing it to the dt_from_*() function.  However, only
dt_from_blob() uses this.  dt_from_source() opens its own file, and
dt_from_fs() interprets the argument as as a directory and does its
own opendir() call.

Furthermore, main() opened the file with dtc_open_file() but closed it
with a direct call to fclose().

Therefore, to improve the interface consistency between the
dt_from_*() functions, make dt_from_blob() open and close its own
files like the other dt_from_*() functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-05-19 14:12:01 -05:00
David Gibson
c26015443a dtc: Trivial formatting fixes
This patch fixes some trivial indentation and brace/bracket style
problems.
2008-05-19 14:11:03 -05:00