summaryrefslogtreecommitdiff
path: root/flattree.c
Commit message (Collapse)AuthorAgeFilesLines
* dtc: Add ability to delete nodes and propertiesStephen Warren2012-09-061-0/+3
| | | | | | | | | | | | | | | | | | | dtc currently allows the contents of properties to be changed, and the contents of nodes to be added to. There are situations where removing properties or nodes may be useful. This change implements the following syntax to do that: / { /delete-property/ propname; /delete-node/ nodename; }; or: /delete-node/ &noderef; Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Remove unused variable in flat_read_mem_reserveJosh Boyer2011-07-171-2/+0
| | | | | | | | | | | | | | | | The *p variable is declared and used to save inb->ptr, however p is later never used. This has been the case since commit 6c0f3676 and can lead to build failures with -Werror=unused-but-set-variable: flattree.c: In function 'flat_read_mem_reserve': flattree.c:700:14: error: variable 'p' set but not used [-Werror=unused-but-set-variable] cc1: all warnings being treated as errors make: *** [flattree.o] Error 1 Remove the variable. Signed-off-by: Josh Boyer <jwboyer@linux.vnet.ibm.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Allow multiple labels on nodes and propertiesDavid Gibson2010-02-241-26/+31
| | | | | | | | | | | | | | | | | At present, both the grammar and our internal data structures mean that there can be only one label on a node or property. This is a fairly arbitrary constraint, given that any number of value labels can appear at the same point, and that in C you can have any number of labels on the same statement. This is pretty much a non-issue now, but it may become important with some of the extensions that Grant and I have in mind. It's not that hard to change, so this patch does so, allowing an arbitrary number of labels on any given node or property. As usual a testcase is added too. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Grant Likely <grant.likely@secretlab.ca>
* dtc: Simpler interface to source file managementDavid Gibson2010-01-141-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | This patch cleans up our handling of input files, particularly dts source files, but also (to an extent) other input files such as those used by /incbin/ and those used in -I dtb and -I fs modes. We eliminate the current clunky mechanism which combines search paths (which we don't actually use at present) with the open relative to current source file behaviour, which we do. Instead there's a single srcfile_relative_open() entry point for callers which opens a new input file relative to the current source file (which the srcpos code tracks internally). It doesn't currently do search paths, but we can add that later without messing with the callers, by drawing the search path from a global (which makes sense anyway, rather than shuffling it around the rest of the processing code). That suffices for non-dts input files. For the actual dts files, srcfile_push() and srcfile_pop() wrappers open the file while also keeping track of it as the current source file for future opens. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* Fix dtc bugs for 64-bit compileDavid Gibson2009-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've just tested building dtc as an x86_64 binary on a 32-bit i386 host by using: make CC="gcc -m64" This patch fixes a handful of minor bugs thus discovered: * There is a printf() type mismatch on 64-bit in value-labels.c * For the tests which use libdl, we were using the GNU make feature where it will find libdl.so given a dependency in the form '-ldl'. But this built-in make logic doesn't know we're compiling 64-bit so finds the 32-bit version of the library. We avoid using this and instead explicitly pass -ldl to CC, which being the 64-bit version does know where to look. * To process dtc's asm output into .so files, run_tests.sh was directly invoking the (default instance of) the assembler and linker. Instead invoke these via the CC driver, and allow that to be overriden from the make environment. * The x86_64 assembler doesn't 0 fill with the .balign directive (presumably it is NOP filling). That doesn't produce strictly incorrect trees, but it is confusing and confounds are testcases which do byte-by-byte comparison of the trees produced by asm output with direct dtb output (which does 0 pad where necessary, of course). This patch uses the optional second argument to .balign to force gas to zero-fill instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Make asm output more portable and add testcasesDavid Gibson2009-02-031-37/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds some testcases for dtc's -Oasm mode. Specifically it checks that building the asm will result in the same device tree blob in memory as -Odtb mode would produce, for a variety of trees. This test uncovered two difficulties with our current -Oasm output, both of which are addressed in this patch as well. First, -Oasm output would only be correct if assembled for a big-endian target. Usually that would be the case, when building device trees into a firmware or similar. However this makes life inconvenient for testing on a little-endian target, and one can think up use cases where a program running on a little endian host might want to embed a device tree for a big-endian target. This patch therefore changes -Oasm output to use .byte directives instead of .long throughout in order to generate byte-for-byte identical trees regardless of the endianness of the assembler target. Second, -Oasm output emitted several #define statements which were then used in the innards of the output - i.e. it assumed the output would be processed by cpp before being assembled. That may not be convenient in all build environments, and in any case doesn't work well with the above fix. So, -Oasm output no longer needs to be preprocessed before assembling. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
* dtc: Check return value from fwrite()David Gibson2008-11-171-4/+7
| | | | | | | | | | 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>
* Implement and use an xstrdup() functionJon Loeliger2008-10-031-3/+3
| | | | | | | | | | | | | | | | 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>
* dtc: Use the same endian-conversion functions as libfdtDavid Gibson2008-07-141-36/+30
| | | | | | | | | | | | | | | | 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>
* dtc: Use stdint.h types throughout dtcDavid Gibson2008-07-141-16/+16
| | | | | | | | | 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>
* dtc: Rework handling of boot_cpuid_physDavid Gibson2008-05-191-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* dtc: Make dt_from_blob() open its own input file, like the other input formatsDavid Gibson2008-05-191-10/+16
| | | | | | | | | | | | | | | | | | 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>
* dtc: Make -I dtb mode use fill_fullpaths()David Gibson2008-03-231-39/+16
| | | | | | | | | | | | 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>
* dtc: Use for_each_marker_of_type in asm_emit_data()David Gibson2008-03-231-7/+3
| | | | | | | 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>
* dtc: Test and fix conversion to/from old dtb versionsDavid Gibson2008-03-231-8/+6
| | | | | | | | 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>
* dtc: Implement checks for the format of node and property namesDavid Gibson2008-03-231-23/+5
| | | | | | | | | | | | | | | | 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>
* dtc: Remove header information dumpingDavid Gibson2008-01-031-15/+0
| | | | | | | | | | | | | 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>
* Fix padding optionsKumar Gala2007-12-051-5/+7
| | | | | | | "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>
* dtc: Add many const qualificationsDavid Gibson2007-12-041-22/+22
| | | | | | | | 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>
* Add an option to pad the blob that is generatedKumar Gala2007-12-041-7/+13
| | | | | | | | | 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>
* dtc: Merge refs and labels into single "markers" list (v2)David Gibson2007-11-261-5/+6
| | | | | | | | | | | | | | | | | | | | | 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>
* Quiet a bogus "May be used uninitialized" warning.Jon Loeliger2007-10-231-1/+1
| | | | Signed-off-by: Jon Loeliger <jdl@freescale.com>
* dtc: Use libfdt/fdt.h instead of flat_dt.hDavid Gibson2007-09-271-72/+71
| | | | | | | | | | | | 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>
* dtc: Whitespace cleanupDavid Gibson2007-09-181-13/+13
| | | | | | | | | | | | 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>
* dtc: Assume properties preced subnodes in the flattened treeDavid Gibson2007-09-051-0/+3
| | | | | | | | | | | | | | | | 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>
* dtc: Optimise by default, fix warnings thus uncoveredDavid Gibson2007-08-311-4/+5
| | | | | | 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.
* dtc: format memory reserve as pairs on two linesMilton Miller2007-07-071-2/+2
| | | | | | | | | | 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>
* dtc: align header comments in asm outputMilton Miller2007-07-071-8/+8
| | | | | | | Insert tabs to align the comments describing the fields of the boot parameters header struct. Signed-off-by: Milton Miller <miltonm@bga.com>
* dtc: implement labels on property dataMilton Miller2007-07-071-0/+13
| | | | | | | | | | | | | | | | | | | | | | | 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>
* dtc: implement labels on memory reserve slotsMilton Miller2007-07-071-0/+4
| | | | | | | | 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>
* dtc: fix asm for version 17Milton Miller2007-07-071-0/+4
| | | | | | | 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>
* dtc: Remove bogus break statementDavid Gibson2007-07-021-1/+0
| | | | | | | | | | Commit 0738774fcc34b78a708a127fb4b2f193d08c94ba 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>
* dtc: Accept NOPs in dtb input regardless of versionDavid Gibson2007-06-251-2/+4
| | | | | | | | | | 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>
* dtc: parse NOP in dtb inputMilton Miller2007-06-111-2/+12
| | | | | | | | | | | 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>
* Fix the -S to modify the totalsize properly.Jerry Van Baren2007-04-201-12/+17
| | | | | | | | 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>
* Assemble the blob in memory before writing it out.Jerry Van Baren2007-04-191-35/+48
| | | | | | | | 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>
* Fix reserve map output for asm format.Jerry Van Baren2007-04-191-0/+3
| | | | | | | Add extra reserve map slots output for asm format (previously done for dtb output). Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
* Implement the -R option and add a -S option.Jerry Van Baren2007-04-051-2/+20
| | | | | | | 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>
* Add support for flat device tree format version 17David Gibson2007-03-141-3/+15
| | | | | | | | | | | | | | | | 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>
* dtc: fix endian issue when reading blobsMichael Neuling2006-07-071-0/+2
| | | | | | | 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: add setting of physical boot cpuMichael Neuling2006-06-071-6/+10
| | | | | | | | 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>
* Use .long on high and low halfs of u64s to avoid .quadJon Loeliger2006-04-191-4/+12
| | | | as it appears .quad isn't available in some assemblers.
* Don't generate the mem-reserve entry for the blob itself,Jon Loeliger2006-04-191-7/+0
| | | | | | 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.
* The problem is that asm_emit_cell() was swapping its asm output whenMark A. Greer2006-04-191-1/+1
| | | | | | | | | | | | | 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.
* Use names for output functions in the form dt_to_*() instead ofDavid Gibson2005-10-261-2/+2
| | | | write_dt_*() for consistency with the dt_from_*() input functions.
* Rework tracking of reserve entries during processing. This is initial workDavid Gibson2005-10-241-18/+36
| | | | to allow more powerful handling of reserve entries.
* Fix endian problems with handling of memreserve entries (bug pointed outDavid Gibson2005-08-291-23/+12
| | | | | by Pantelis Antoniou). The rule is that the memreserve data in struct boot_info is always stored big-endian.
* Remove an unused function, mark a bunch of other functions and variablesDavid Gibson2005-08-291-7/+7
| | | | as static. Mostly found by sparse.
* Forgot to realign after emitting auto-generated "name" properties. Oops.David Gibson2005-08-251-1/+2
|
* Add a couple of missing cpu_to_be32() writing the version numbers out.David Gibson2005-08-251-2/+2
|