Commit graph

344 commits

Author SHA1 Message Date
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
David Gibson
73d60926a0 libfdt: Use void * to refer to device tree blobs
At present, the blob containing a device tree is passed to the various
fdt_*() functions as a (struct fdt_header *) i.e. a pointer to the
header structure at the beginning of the blob.

This patch changes all the functions so that they instead take a (void
*) pointing to the blob.  Under some circumstances can avoid the need
for the caller to cast a blob pointer into a (struct fdt_header *)
before passing it to the fdt_*() functions.

Using a (void *) also reduce the temptation for users of the library
to directly dereference toe (struct fdt_header *) to access header
fields.  Instead they must use the fdt_get_header() or
fdt_set_header() macros, or the fdt_magic(), fdt_totalsize()
etc. wrappers around them which are safer, since they will always
handle endian conversion.

With this change, the whole-tree moving, or manipulating functions:
fdt_move(), fdt_open_into() and fdt_pack() no longer need to return a
pointer to the "new" tree.  The given (void *) buffer pointer they
take can instead be used directly by the caller as the new tree.
Those functions are thus changed to instead return an error code
(which in turn reduces the number of functions using the ugly encoding
of error values into pointers).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-15 15:12:47 +11:00
David Gibson
568b569e89 libfdt: Fixup usage of fdt_offset_ptr() in fdt_rw.c
Several places in fdt_rw.c incorrectly use fdt_offset_ptr(), using it
as if it returned an encoded error code on errors, instead of
returning NULL on error as it actually does.

In fact, however, in these instances the extra checks in
fdt_offset_ptr() are useless anyway, so we introduce a new (internal
use) _fdt_offset_ptr() and use that without checking.
(cherry picked from 3dffb1808dea6aee6158c92e17faa6ced9b183f2 commit)
2006-12-14 15:30:31 +11:00
David Gibson
9825f823eb libfdt: Fix bounds-checking bug in fdt_get_property()
The libfdt functions are supposed to behave tolerably well when practical,
even if given a corrupted device tree as input.  A silly mistake in
fdt_get_property() means we're bounds checking against the size of a pointer
instead of the size of a property header, meaning we can get bogus
behaviour in a corrupted device tree where the structure block ends in
what's supposed to be the middle of a property.

This patch corrects the problem (fdt_get_property() will now return
BADSTRUCTURE in this case), and also adds a testcase to catch the bug.
2006-12-14 15:29:25 +11:00
David Gibson
6ae4de5c81 libfdt: Remove unused _ptr_offset() function
The (internal use) function _ptr_offset() is never used.  Delete it.
2006-12-12 12:48:15 +11:00
David Gibson
94993f4fc4 libfdt: Abolish fdt_property_offset()
fdt_property_offset() is the only function in the library returning a
direct offset to a property, and no function takes such an offset
(they only take offsets to nodes, not properties).  Furthermore the
only client uses for this function I can think of involve immediately
translating the offset into a pointer, effectively duplicating the
internal function _fdt_getprop()

This function abolishes fdt_property_offset(), replacing it with
fdt_get_property(), a renamed and now externally visible version of
_fdt_getprop().
2006-12-11 16:15:34 +11:00
David Gibson
95393db96f dtc: Remove verbose message from get_node_phandle()
get_node_phandle() had a leftover debugging printf(), which could muddy
dtc's output when checking trees.  This patch removes it.
2006-12-11 11:02:59 +11:00
David Gibson
1a765f51a4 libfdt: Fixups for 64-bit machines
The error encoding for pointers is incorrect on machines where
sizeof(int) != sizeof(void *), which includes most 64-bit platforms
(in particular, AMD64 and powerpc64).  This patch fixes it.
2006-12-07 15:24:26 +11:00
David Gibson
e25487db34 libfdt: Fix libfdt for little endian hosts
This patch fixes a number of embarrasing oversights which meant libfdt
did not work correctly on little endian machines.  With this patch the
testsuite now passes on x86.  Device trees are always created
big-endian.
2006-12-04 12:52:45 +11:00
David Gibson
81bdd52c07 libfdt: Add dtb files to .gitignore
Ignores .dtb files in the tests subdirectory.
2006-12-04 11:17:32 +11:00
David Gibson
7ba551f966 libfdt: Read-write support
This patch adds support for random access, read-write support on flat trees.
2006-12-01 16:59:43 +11:00
David Gibson
fe92f6bb75 libfdt: Introduce flat tree format v17
v17 of the blob format adds a field for the size of the structure
block, but is backwards compatible with v16.  This patch introduces
definitions for the new field, and uses it to improve the bounds
checking in the read-only code.  It also cleans up the sequential
write code using it: we no longer need to borrow the version field as
a write pointer.
2006-12-01 16:25:39 +11:00
David Gibson
aeddfe2c34 libfdt: Factor out string search function
This patch pulls out the logic for finding a string in the string table
into _fdt_find_string(), from fdt_sw.c's find_add_string().  This function
will be useful for random-access read-write functions.  In the process
clean up the search logic a little.
2006-12-01 15:11:58 +11:00
David Gibson
423697628a libfdt: Implement fdt_move()
Implement the fdt_move() function for copying/moving device trees
to a new buffer, or within an existing buffer.
2006-12-01 15:07:19 +11:00
David Gibson
ede25deae6 libfdt: Export accessors for header fields
This patch adds exported accessor macros for the various flat device
tree header fields to libfdt.h.  This necessitates moving some of the
byte-swapping functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-01 15:02:10 +11:00
David Gibson
41722c230c libfdt: Fix logic in nop_property testcase
This patch fixes some completely bogus error checking logic from the
nop_property testcase (resulted from a cut-and-paste error).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2006-12-01 13:10:07 +11:00
David Gibson
65380f164c Add a copy of the GPL
Since the file preamples say it's there, we really should include it.
2006-11-29 16:49:27 +11:00
David Gibson
063693a9e4 libfdt: Sequential write support
This patch adds code to libfdt to create flat trees from scratch, writing
sequentially.
2006-11-29 16:45:46 +11:00
David Gibson
3aa4cfd66b Simplify string table access functions
The range sanity checking on the fdt_string_cmp() function causes problems
for the sequential write code (or at least for using RO functions on an
incomplete SW tree).  Plus they didn't really fit with the philosphy for
the RO code of working as widely as possible on weirdly constructed trees.
2006-11-29 16:34:30 +11:00
David Gibson
156649d4f6 Fix building of dumptrees
Without this rather odd constrained pattern rule, make attempts to build
dumptrees using the default %: %.c rule instead of the defined %: %.o and
%.o: %.c rules.
2006-11-29 13:34:22 +11:00
David Gibson
4e6221c171 Have tests read example tree from a generated file, rather than link it in.
This makes the tests more flexible to re-use for testing the output from
the write tests.
2006-11-28 17:20:01 +11:00
David Gibson
3da0f9a10d libfdt - library for manipulating device trees in flattened format
Initial revision, read-only and "in-place" (no memmove() required)
write operations only.
2006-11-27 16:21:28 +11:00
Kim Phillips
f016882f91 Change default output blob version from 3 to 16
Signed-off-by: Kim Phillips <Kim.Phillips@freescale.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2006-11-01 08:15:18 -06:00
Michael Neuling
332c536425 dtc: fix endian issue when reading blobs
The reserve mem regions are screwy if you read a blob on x86.  I'm
guessing there may be a few more of these lurking in the code.

Signed-off-by: Michael Neuling <mikey@neuling.org>
2006-07-07 09:30:44 -05:00