Commit graph

53 commits

Author SHA1 Message Date
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
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
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
b2de518b80 dtc: Make -I dtb mode use fill_fullpaths()
At present -I dts and -I fs modes both use the fill_fullpaths() helper
function to fill in the fullpath and basenamelen fields of struct
node, which are useful in later parts of the code.  -I dtb mode,
however, fills these in itself.

This patch simplifies flattree.c by making -I dtb mode use
fill_fullpaths() like the others.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
5ac97df149 dtc: Use for_each_marker_of_type in asm_emit_data()
For no good reason, asm_emit_data() open-codes the equivalent of the
for_each_marker_of_type macro.  Use the macro instead.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
a266e5c1e1 dtc: Test and fix conversion to/from old dtb versions
This patch adds testcases which test dtc when used to convert between
different dtb versions.  These tests uncovered a couple of bugs
handling old dtb versions, which are also fixed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
fa5b520ccb dtc: Implement checks for the format of node and property names
This patch adds checks to the checking framework to verify that node
and property names contain only legal characters, and in the case of
node names there is at most one '@'.

At present when coming from dts input, this is mostly already ensured
by the grammer, however putting the check later means its easier to
generate helpful error messages rather than just "syntax error".  For
dtb input, these checks replace the older similar check built into
flattree.c.

Testcases for the checks are also implemented.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:32 -05:00
David Gibson
3bb78bfd97 dtc: Remove header information dumping
Currently, when used in -Idtb mode, dtc will dump information about
the input blob's header fields to stderr.  This is kind of ugly, and
can get in the way of dtc's real output.

This patch, therefore, removes this.  So that there's still a way of
getting this information for debugging purposes, it places something
similar to the removed code into ftdump, replacing the couple of
header fields it currently prints with a complete header dump.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-01-03 07:46:29 -06:00
Kumar Gala
80c72a81cf Fix padding options
"Add an option to pad the blob that is generated" broke the padding
support.  We were updating the fdt header after writing it.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-12-05 08:27:54 -06:00
David Gibson
92cb9a25b1 dtc: Add many const qualifications
This adds 'const' qualifiers to many variables and functions.  In
particular it's now used for passing names to the tree accesor
functions.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-04 07:54:03 -06:00
Kumar Gala
2b7dc8dce5 Add an option to pad the blob that is generated
There are times when we need extra space in the blob and just want
to have it added on w/o know the exact size to make it.

The padding and min size options are mutually exclusive.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2007-12-04 07:26:47 -06:00
David Gibson
dc941774e2 dtc: Merge refs and labels into single "markers" list (v2)
Currently, every 'data' object, used to represent property values, has
two lists of fixup structures - one for labels and one for references.
Sometimes we want to look at them separately, but other times we need
to consider both types of fixup.

I'm planning to implement string references, where a full path rather
than a phandle is substituted into a property value.  Adding yet
another list of fixups for that would start to get silly.  So, this
patch merges the "refs" and "labels" lists into a single list of
"markers", each of which has a type field indicating if it represents
a label or a phandle reference.  String references or any other new
type of in-data marker will then just need a new type value - merging
data blocks and other common manipulations will just work.

While I was at it I made some cleanups to the handling of fixups which
simplify things further.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-26 16:00:19 -06:00
Jon Loeliger
2d50f8f9dd Quiet a bogus "May be used uninitialized" warning.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-23 10:13:00 -05:00
David Gibson
fb7c7acf5a dtc: Use libfdt/fdt.h instead of flat_dt.h
In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and
constants relating to the flattened device tree format derived from
asm-powerpc/prom.h in the kernel.  The former is used in dtc, the
latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that
throughout, removing flat_dt.h.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-27 08:21:18 -05:00
David Gibson
63dc9c7113 dtc: Whitespace cleanup
This large patch removes all trailing whitespace from dtc (including
libfdt, the testsuite and documentation).  It also removes a handful
of redundant blank lines (at the end of functions, or when there are
two blank lines together for no particular reason).

As well as anything else, this means that quilt won't whinge when I go
to convert the whole of libfdt into a patch to apply to the kernel.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-18 09:43:26 -05:00
David Gibson
592ea5888c dtc: Assume properties preced subnodes in the flattened tree
With kernel commit eff2ebd207af9f501af0ef667a7d14befcb36c1b, we
clarified that in the flattened tree format, a particular nodes
properties are required to precede its subdnodes.

At present however, both dtc and libfdt will process trees which don't
meet this condition.  This patch simplifies the code for
fdt_get_property() based on assuming that constraint.  dtc continues
to be able to handle such an invalid tree - on the grounds that it's
useful for dtc to be able to correct such a broken tree - but this
patch adds a warning when this condition is not met while reading a
flattened tree.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-05 13:17:14 -05:00
David Gibson
bf94497031 dtc: Optimise by default, fix warnings thus uncovered
This patch turns on optimisation in the Makefile by default.  With the
optimizer on, some uninitialized variable warnings (one real, two
bogus) are now generated.  This patch also squashes those again.
2007-08-31 08:34:18 -05:00
Milton Miller
445d55d2cc dtc: format memory reserve as pairs on two lines
When writing the memory reserve table in assembly output,
emit both halves of each 64 bit number on a single .long
statement.  This results in two lines per memory reserve
slot instead of four, each line contains one field (start
or size).

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:14:42 -05:00
Milton Miller
7f45666273 dtc: align header comments in asm output
Insert tabs to align the comments describing the fields of the
boot parameters header struct.

Signed-off-by: Milton Miller <miltonm@bga.com>
2007-07-07 10:14:26 -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
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
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
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
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
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
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
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
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
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
Michael Neuling
38e8f8fd88 dtc: add setting of physical boot cpu
dtc always sets the physical boot CPU to 0xfeedbeef.  Add a -b option to
set this.    Also add warnings when using the wrong property with the
wrong blob version.

Signed-off-by: Michael Neuling <mikey@neuling.org>
2006-06-07 09:42:15 -05:00
Jon Loeliger
05ae3d8eeb Use .long on high and low halfs of u64s to avoid .quad
as it appears .quad isn't available in some assemblers.
2006-04-19 11:58:45 -05:00
Jon Loeliger
f7374f60eb Don't generate the mem-reserve entry for the blob itself,
even for ASM output.  It was inconsistent with the binary
output form, and kernel folks decided to have the early
kernel perform the reservation itself.
2006-04-19 11:34:22 -05:00
Mark A. Greer
7a9f663ac7 The problem is that asm_emit_cell() was swapping its asm output when
it shouldn't be (because the assembler will do the necessary swapping).
The cell values (asm_emit_cell()) are different from the data values
(asm_emit_data()) because the cell values are generated within the
program and don't get swapped like the data values read from the dts file.
They should be left as they are so that the assembler will swap them,
if necessary.  For example, when the property length field was 4,
the asm output contained ".long 0x4000000" and sent the kernel prom.c
dt parsing code into the weeds.

Pointed out by Mark Greer.
2006-04-19 11:16:32 -05:00
David Gibson
712e52e438 Use names for output functions in the form dt_to_*() instead of
write_dt_*() for consistency with the dt_from_*() input functions.
2005-10-26 16:56:26 +10:00
David Gibson
f040d95b84 Rework tracking of reserve entries during processing. This is initial work
to allow more powerful handling of reserve entries.
2005-10-24 18:18:38 +10:00
David Gibson
6c0f36769a Fix endian problems with handling of memreserve entries (bug pointed out
by Pantelis Antoniou).  The rule is that the memreserve data in struct
boot_info is always stored big-endian.
2005-08-29 13:36:15 +10:00
David Gibson
230f253e9b Remove an unused function, mark a bunch of other functions and variables
as static.  Mostly found by sparse.
2005-08-29 12:48:02 +10:00
David Gibson
41916138dd Forgot to realign after emitting auto-generated "name" properties. Oops. 2005-08-25 15:39:09 +10:00
David Gibson
dffc2a8972 Add a couple of missing cpu_to_be32() writing the version numbers out. 2005-08-25 14:47:20 +10:00
David Gibson
4ddf7c020c In flat tree reading, check for (negative) string offsets which underrun
the input blob. (Patch from Michael Ellerman).
2005-08-19 16:11:11 +10:00
David Gibson
f0517db250 Support for specifying memreserve ranges in the source format, based on
a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked
substantially.
2005-07-15 17:14:24 +10:00
David Gibson
586606e35d Oops, fix stupid bug where we emitted padding before, rather than after
the blob header.
2005-07-14 11:27:24 +10:00
David Gibson
47f23dee09 Ensure that the reserve map is doubleword aligned in blob and asm output. 2005-07-11 17:19:26 +10:00
David Gibson
a6c69572a3 Remove inaccurate comment. 2005-07-11 17:09:42 +10:00
David Gibson
7ee3ffd43f Fix bug in error message. 2005-07-11 16:45:57 +10:00
David Gibson
ab870cadb4 First cut at a "libdt" set of routines for extracting things from the
flattened tree.  Could be used in firmware.
2005-06-23 15:45:13 +10:00