Commit graph

117 commits

Author SHA1 Message Date
Milton Miller
43a68c63e4 dtc: store labels in ascending order
When adding a label, walk to the end of the list since the
label reflects the end of the data.

Since merging data buffers already preserved the order, this
will cause the labels to be emitted in order when writing
assembly output.

It should also aid emiting labels when writing dts output
should that be added in the future (data formatting would
need to break at each label).

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:14:12 -05:00
Milton Miller
6a99b13132 dtc: implement labels on property data
Extend the parser grammer to allow labels before or after any
property data (string, cell list, or byte list), and any
byte or cell within the property data.

Store the labels using the same linked list structure as node
references, but using a parallel list.

When writing assembly output emit global labels as offsets from
the start of the definition of the data.

Note that the alignment for a cell list is done as part of the
opening < delimiter, not the = or , before it.  To label a cell
after a string or byte list put the label inside the cell list.

For example,
	prop = zero: [ aa bb ], two: < four: 1234 > eight: ;
will produce labels with offsets 0, 2, 4, and 8 bytes from
the beginning of the data for property prop.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:13:31 -05:00
Milton Miller
ac6a5e26b4 dtc: allow a label: in any dts context
Change the lexer to recognise a label in any context.  Place
before other celldata and bytestrings to avoid the initial
characters being stolen by other matches.

A label is a character sequence starting with an alphabetic
or underscore optinally followed by the same plus digits and
terminating in a colon.

The included terminating colon will prevent matching hex numbers.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:10:12 -05:00
Milton Miller
46779e8f8e dtc: clean up grow_data_for()
Change the grow_data_for function to copy struct data and
modifiy the fields it is updating instead of storing all
fields individually to a stack allocated struct.

This reduces maintence for future enhancements as now all
instances of struct data are created by modifying a copy
of an existing struct data or directly copying empty_data.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:09:36 -05:00
Milton Miller
d429033851 dtc: implement labels on memory reserve slots
Allow a label to be placed on a memory reserve entry.
Change the parser to recognize and store them.  Emit
them when writing assembly output.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:09:31 -05:00
Milton Miller
85ab5cc6ec dtc: complain about unparsed digits in cell lists
Check that strtoul() parsed the complete string.

As with the number overflow case, write a non-fatal error
message to stdout.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:07:44 -05:00
Milton Miller
6d7b222430 dtc: move declaration of yyerror
yyerror() is used by both dtc-parser.y and dtc-lexer.l, so move
the declaration to srcpos.h.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:07:27 -05:00
Milton Miller
81fda8a6f1 dtc: fix asm for version 17
The version 17 flat device tree format added struct size.  When
writing version 17 assembly output the field must be emitted.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:07:04 -05:00
Josh Boyer
8cd4196ee3 dtc: Add install makefile target
Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com>
2007-07-02 08:44:37 -05:00
David Gibson
6936273aa4 dtc: Remove bogus break statement
Commit 0738774fcc introduced some
incorrect indentation / bracketing in unflatten_tree().  By luck, the
extra break statement intended to be within an if block, but actually
afterwards has no semantic effect.  Still, this patch gets rid of it
for cleanliness.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-07-02 08:30:57 -05:00
David Gibson
d9d679fb96 dtc: Improve and better integrate dtc and libfdt Makefiles
This patch substantially revamps the dtc Makefiles, in particular
better integrating the Makefile for dtc proper with the Makefiles
imported from libfdt for libfdt and the shared testsuite.  Notable
changes:
	- No recursive make calls.  Instead subsidiary Makefiles are
included into the top-level Makefile so we get a complete dependency
information.
	- Common pattern rules, CFLAGS etc. shared between dtc, libfdt
and testsuite, rather than separate copies.
	- Vaguely Kbuild-like non-verbose mode used by default, which
makes warnings more prominent.
	- libfdt Makefile consists only of variable definitions and
helper rules, to make it more easily embeddable into other Makefile
systems.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-25 21:50:14 -05:00
David Gibson
6c65eab11e dtc: Remove redundant copy of the GPL
The dtc tree currently includes two copies of the GPL - one which was
there originally, and one imported from the libfdt tree.  This patch
gets rid of the extra copy in the libfdt tree.

In addition it renames the file containing the remaining copy from
COPYING to GPL.  Since libfdt is dual-licensed, this seems clearer.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-25 21:43:11 -05:00
David Gibson
0c7cd1a087 dtc: Count testcases and results in the dtc/libfdt testsuite
There are quite a lot of testcases in the dtc testsuite (recently
imported from libfdt).  It can be easy to miss a stray FAIL result in
the midst of all the rest.  To improve this, this patch adds a summary
to the end of the testsuite results giving the total number of tests
along with the number of PASSes FAILs and other results.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-25 21:43:03 -05:00
David Gibson
0738774fcc dtc: Accept NOPs in dtb input regardless of version
Since Milton's patch, dtc will accept (and, correctly, ignore) NOP
tags when given dtb input v16 or later.  However, although NOPs
weren't defined in earlier versions, they're not ambiguous, so should
be accepted there as well.  This patch does so, printing a mere
warning when finding NOPs in a too-early dtb version.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-25 21:39:26 -05:00
David Gibson
12578976fe Merge libfdt into dtc.
Having pulled the libfdt repository into dtc, merge the makefiles and
testsuites so that they build together usefully.
2007-06-14 15:05:55 +10:00
David Gibson
400bd98a3a Merge ../libfdt into dtc-libfdt-merge 2007-06-14 12:21:33 +10:00
David Gibson
23cdf2379f Move everything into a subdirectory in preparation for merge into dtc. 2007-06-14 11:58:35 +10:00
David Gibson
9481605208 libfdt: Switch to dual GPL/BSD license
Change the license information at the top of each file from LGPL to
dual-GPL/BSD.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-13 16:30:48 +10:00
David Gibson
a6c76f923d libfdt: More thorough use of constification
As a read-only functions, which take a const pointer to the fdt, treat
fdt_get_property() and fdt_getprop() as returning const pointers to
within the blob.  fdt_get_property_w() and fdt_getprop_w() versions
are supplied which take a non-const fdt pointer and return a non-const
pointer for the benefit of callers wishing to alter the device tree
contents.

Likewise the lower-level fdt_offset_ptr() and _fdt_offset_ptr()
functions are changed to return const pointers, with *_w() versions
supplied.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-13 14:18:10 +10:00
Milton Miller
ce243227f1 dtc: parse NOP in dtb input
Version 16 and later of the flat device tree format allow NOPs
to be placed in the tree.  When processing dtb input, dtc must
recognise them.

Previously it would produce the error message
FATAL ERROR: Invalid opcode word 00000004 in device tree blob

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-06-11 08:40:00 -05:00
David Gibson
41eecd4c2a dtc: Fix recognition of whitespace characters
At present, the lexer in dtc recognizes only space, tab and newline as
whitespace characters.  This is broken; in particular this means that
dtc will get syntax errors on files with DOS-style (CR-LF) newlines.

This patch fixes the problem, using flex's built-int [:space:]
character class.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-06-06 21:51:49 -05:00
Jerry Van Baren
7ea144f4c0 Fix the -S to modify the totalsize properly.
With the last improvement to pad out the blob, I broke the blob
header totalsize adjustment.  The adjustment was moved up in the
code before the memory image of the blob is created.

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
2007-04-20 08:43:45 -05:00
Jerry Van Baren
86c01ee6df Assemble the blob in memory before writing it out.
This makes padding out the blob if the user requested extra size much
easer.  The assembly and writing to the file is more straight forward too.

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-04-19 17:24:52 -05:00
Jerry Van Baren
ca25e54ddd Fix reserve map output for asm format.
Add extra reserve map slots output for asm format (previously done for dtb
  output).

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
2007-04-19 17:19:57 -05:00
Jerry Van Baren
4f5370a138 Add -o <output file> to the usage message.
Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-04-19 17:17:51 -05:00
Jerry Van Baren
4384b23454 Implement the -R option and add a -S option.
Implement the -R <number> option to add memory reserve slots.
Add a -S <size> option makes the blob at least this number of bytes.

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
2007-04-05 09:57:55 -05:00
Jon Loeliger
ce34ae3b23 DTC: Incorporate some review suggestions.
- Change include syntax to:  /include/ "filename"
    - Move private functions directly into dtc-lexer.l
    - Define YYID for some older parser templates

Also fix a #include ordering problem around YYLTPE.

Signed-off-by; Jon Loeliger <jdl@freescale.com>
Acked-by: Haiying Wang <Haiying.Wang@freescale.com>
2007-03-28 17:07:44 -05:00
Jon Loeliger
e45e6fd274 DTC: Add support for a C-like #include "file" mechanism.
Keeps track of open files in a stack, and assigns
a filenum to source positions for each lexical token.
Modified error reporting to show source file as well.
No policy on file directory basis has been decided.
Still handles stdin.

Tested on all arch/powerpc/boot/dts DTS files

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-03-26 08:36:07 -05:00
Scott Wood
b29597d9a3 Remove bogus errors from check_chosen.
It is not an error for /chosen (or any of its children) to be missing.

It is not a requirement that the output of dtc be a complete, valid
device tree, as it may be intended that the dtb be passed through boot
code that will complete it.  Thus, do not complain.

Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2007-03-26 08:34:23 -05:00
David Gibson
857f54e79f libfdt: Remove #includes from fdt.h
At present fdt.h #includes stdint.h.  This makes some sense, because fdt.h
uses the standard fixed-width integer types.  However, this can make life
difficult when building in different environments which may not have a
stdint.h.  Therefore, this patch removes the #include from fdt.h, instead
requiring that users of fdt.h define the fixed-width integer types before
including fdt.h, either by themselves including stdint.h, or by any other
means.
2007-03-23 15:16:54 +11:00
Ed Swarthout
001430072f ftdump missing be32_to_cpu() on size cell. 2007-03-22 08:30:52 -05:00
Jerry Van Baren
cd1da87116 Improve options, #define default version.
Add -h option for help
Add -q quiet option to reduce or suppress the whining
Create #define for the default version value.

Signed-off-by: vanbaren@cideas.com <vanbaren@cideas.com>
2007-03-19 08:54:40 -05:00
David Gibson
b299ac76a7 Get rid of libdt.c
libdt.c was an attempt at creating a device tree handling library
within the dtc codebase.  However, it was never even close to
completion, and is entirely obsoleted by it's spiritual descendent,
libfdt (currently a separate package).  This patch, therefore, removes
libdt.c entirely, along with its only reference in the Makefile, an
unused variable.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-03-14 15:36:42 -05:00
David Gibson
46c88dfcca Add support for flat device tree format version 17
libfdt defined a new version of the flattened device tree format,
version 17.  It is backwards compatible with version 16, just adding
an extra header field giving the size of the blob's structure blob.

This patch adds support to dtc allowing it to read and write version
17 blobs.  It also makes version 17 the default output version for
blobs.

At the same time we change the code to consistently using decimal
numbers for versions.  Previously we sometimes used 16 and sometimes
0x10 to refer to version 16.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-03-14 15:36:37 -05:00
David Gibson
6ae55f9f9b Fix flat_dt_property structure
The structure in flat_dt.h defining the layout of a proprety within
the flat device tree is incorrect.  It has the offset to the
property's name, then the length when in fact (according to
booting-without-of.txt and the output of dtc) then length should come
first, followed by the name offset.

In fact, this structure is never used so the mistake doesn't break
anything, but it should still be fixed to avoid misleading people.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-02-27 08:46:55 -06:00
David Gibson
07a12a0800 libfdt: Use correct property format
Since its beginning, libfdt has used an incorrect definition of the
format for a property, putting the name offset before length, rather
than the other way around as described in booting-without-of.txt.

This corrects the error, making libfdt actually produce and use trees
which are compatible with the kernel and dtc.

Signed-of-by: David Gibson <david@gibson.dropbear.id.au>
2007-02-23 14:40:14 +11:00
David Gibson
5434fcc7e0 libfdt: Fix fdt_strerror() bugs
This fixes several small bugs related to fdt_strerror().
	- an entry is added to the error table for FDT_ERR_BADLAYOUT.
	- Incorrect usage of fdt_strerror() in check_property() and
check_getprop() is corrected (they were passing a positive error code,
when fdt_strerror() expects a negative code).
	- Add code to properly retreive an error code from
fdt_get_property() in check_property().  With that a check that the
length returned by fdt_get_property() matches that stored in the
retreived property.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-02-23 14:40:10 +11:00
Stuart Yoder
5ae78ad8f8 remove check for interrupt-controller property under /chosen
Remove warning for missing interrupt-controller property
under /chosen.  There is consensus that this
property does not belong here.

Also, add a warning if interrupt-controller _is_ found
under /chosen.

Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-20 11:55:20 -06:00
Jon Loeliger
3948849fd0 Moved data_convert_cell() out of data.c to the parser.
It constructs a cell_t, not data objects.
Renamed it to cell_from_string() as well.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-16 09:33:54 -06:00
Jon Loeliger
fd84d97dee Add some initial test cases.
Add the original simple test case and a case with
different based cell values.  Correct output asm
files as well as stderr is captured.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-15 11:02:44 -06:00
Jon Loeliger
af0278a3a0 Add support for decimal, octal and binary based cell values.
New syntax d#, b#, o# and h# allow for an explicit prefix
on cell values to specify their base.  Eg: <d# 123>

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-15 10:59:27 -06:00
David Gibson
c226ddcabc Allow references to labels
dtc allows nodes to have labels, which at present are just re-emitted
as symbols at the appropriate places when using asm-mode output.  It
also allows "references" where the notation &/path/to/node in a cell
list will be replaced with the phandle of the referenced node.

This patch extends the reference syntax to allow references to labels
instead of just full device paths.  This allows nodes deep within the
tree to be referenced with a shorter more convenient name.  References
to labels are distinguished from reference to paths by the fact that
paths must start with a /, but labels can never start with a /.

Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-08 17:27:12 -06:00
David Gibson
32da475af1 Allow multipart property values
At present each property definition in a dts file must give as the
value either a string ("abc..."), a bytestring ([12abcd...]) or a cell
list (<1 2 3 ...>).  This patch allows a property value to be given as
several of these, comma-separated.  The final property value is just
the components appended together.  So a property could have a list of
cells followed by a string, or a bytestring followed by some cells.
Cells are always aligned, so if cells are given following a string or
bytestring which is not a multiple of 4 bytes long, zero bytes are
inserted to align the following cells.

The primary motivation for this feature, however, is to allow defining
a property as a list of several strings.  This is what's needed for
defining OF 'compatible' properties, and is less ugly and fiddly than
using embedded \0s in the strings.

Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-02-08 17:26:41 -06:00
David Gibson
54382390e4 Bugfix for CHECK_HAVE_WARN_PHANDLE()
At present, the tree checking code in dtc will die with an assertion
failure if given a tree which has the invalid value 0 or -1 in a
property which should contain a phandle.  This patch fixes the check
to die more gracefully with an error message indicating the invalid
phandle value.

Signed-off-by: David Gibson <dwg@au1.ibm.com>
2007-01-31 07:39:57 -06:00
David Gibson
e6dd3f1d3c Remove check for linux,platform property in /chosen
The linux,platform property in /chosen was obsolete almost as soon as
it was invented.  Remove the check for it from dtc, which just tends
to lead to irritating spurious failures.

Signed-off-by: David Gibson <dwg@au1.ibm.com>
2007-01-29 07:47:55 -06:00
David Gibson
5b344f9c5a libfdt: Add fdt_strerror() function to library
This function moves the fdt_strerror() function, currently found in
the test code into the fdt library proper.  This makes life easier for
any library users who want to provide meaningful error messages.  The
function goes into a module of its own, so that users who don't need
the function won't get a copy of it linked in.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-21 09:57:08 +11:00
David Gibson
209c5e56d2 libfdt: Add TODO file
Add a TODO file to keep track of future plans for libfdt.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-21 09:57:02 +11:00
David Gibson
3aea828501 libfdt: Clean up error codes
First, this patch removes several underused error codes:
FDT_ERR_BADPOINTER and FDT_ERR_BADHEADER were not used at all and are
simply removed.  FDT_ERR_SIZE_MISMATCH was very similar in spirit to
FDT_ERR_NOSPACE, and used only in circumstances where there can be no
confusion between the two, so is removed and folded into
FDT_ERR_NOSPACE.  FDT_ERR_INTERAL was used on only one place, on a
"can't happen" check.  It seems of little value so the check and error
code are removed also.

Second, the error codes have been re-numbered and grouped roughly by
severity.  That is codes which can reasonably occur in normal
operation separated from those which indicate bad parameters (and
therefore a bug in the caller) or a bad or corrupted device tree blob.

Third the test function fdt_strerror() is cleaned up a little based on
these changes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-15 15:12:52 +11:00
David Gibson
9a9fdf5991 libfdt: More consistent handling of returned error codes.
At present, libfdt functions returning a structure offset return a
zero-or-positive offset on success, and return a negative error code
on failure.  Functions which only return an error code return a
positive version of the error code, or 0 on success.

This patch improves consistency by always returning negative error
codes on failure, for both types of function.  With this change, we do
away with the special fdt_offset_error() macro for checking whether a
returned offset value is an error and extracting the encoded error
value within.  Instead an explicit (ret_value < 0) is now the
preferred way of checking return values for both offset-returning and
error-code-returning functions.

The fdt_strerror() function in the test code is updated
correspondingly to make more sense with the new conventions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-15 15:12:51 +11:00
David Gibson
a7ee95ded6 libfdt: Abolish encoding of error codes into pointers
This patch abolishes the non-standard and confusing encoding of errors
into pointer return values.  The only functions still returning such a
potentially encoded pointer are fdt_get_property() and fdt_getprop().
Those functions also return a length via an (int *).  With this patch
those functions instead now return NULL on any error, and return the
code indicating the type of error in the length paramater.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-15 15:12:49 +11:00