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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
"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>
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>
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>
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>
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>
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>
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>
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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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.