Commit graph

17 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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