aboutsummaryrefslogtreecommitdiff
path: root/dtc.h
AgeCommit message (Collapse)AuthorFilesLines
2009-01-07dtc: Move some functions to util.[ch]David Gibson1-30/+0
Now that we have a util.[ch] file shared between dtc and convert-dtsv0, move some functions which are currently duplicated in the two to util files. Specifically we move the die(), xmalloc() and xrealloc() functions. While we're at it, add standard double-include protection to util.h Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-10-03Add conditionalized debug() print macro.Jon Loeliger1-0/+7
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2008-10-03Implement and use an xstrdup() functionJon Loeliger1-0/+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>
2008-07-14dtc: Use the same endian-conversion functions as libfdtDavid Gibson1-16/+1
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-14dtc: Use stdint.h types throughout dtcDavid Gibson1-9/+5
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-05-19dtc: Rework handling of boot_cpuid_physDavid Gibson1-5/+4
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-19dtc: Make dt_from_blob() open its own input file, like the other input formatsDavid Gibson1-1/+1
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-19dtc: Simplify error handling for unparseable inputDavid Gibson1-1/+0
Currently, main() tests if it got a valid input tree from whichever dt_from_*() function it invoked and if not, die()s. For one thing, this test has, for no good reason, three different ways for those functions to communicate a failure to provide input (bi NULL, bi->dt NULL, or bi->error non-zero). For another, in every case save one, if the dt_from_*() functions are unable to provide input they will immediately die() (with a more specific error message) rather than proceeding to the test in main(). Therefore, this patch removes this test, making the one case that could have triggered it (in dt_from_source()) call die() directly instead. With this change, the error field in struct boot_info is now unused, so remove it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23dtc: Abolish asize field of struct dataDavid Gibson1-1/+0
The asize field in struct data is a hangover from the early days when a struct data was sometimes allowed to refer to a static chunk of memory rather than a malloc()ed block. That's long gone, since the lifetime issues were far more trouble than it was worth, so get rid of the asize field. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23dtc: Make -I dtb mode use fill_fullpaths()David Gibson1-1/+0
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-01-04Return a non-zero exit code if an error occurs during dts parsing.Scott Wood1-0/+1
Previously, only failure to parse caused the reading of the tree to fail; semantic errors that called yyerror() but not YYERROR only emitted a message, without signalling make to stop the build. Signed-off-by: Scott Wood <scottwood@freescale.com>
2007-12-18dtc: Remove remaining old-style checksDavid Gibson1-2/+1
The remaining old-style tree checking code: check_root(), check_cpus() and check_memory() really aren't that useful. They mostly check for the presence of particular nodes and properties. That's inherently prone to false-positives, because we could be dealing with an artificial tree (like many of the testcases) or it could be expected that the missing properties are filled in by a bootloader or other agent. If any of these checks really turns out to be useful, we can reimplement them later in a better conceived way on top of the new checking infrastructure. For now, just get rid of them, removing the last vestiges of the old-style checking code (hoorah). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-05dtc: Implement path referencesDavid Gibson1-0/+3
This patch extends dtc syntax to allow references (&label, or &{/full/path}) directly within property definitions, rather than inside a cell list. Such references are expanded to the full path of the referenced node, as a string, instead of to a phandle as references within cell lists are evaluated. A testcase is also included. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-04dtc: Add many const qualificationsDavid Gibson1-12/+12
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-04dtc: Fix uninitialized use of structure_okDavid Gibson1-2/+2
My rework of the tree checking code introduced a potentially nasty bug - it uses the structure_ok variable uninitialized. This patch fixes the problem. It's a fairly ugly bandaid approach, but the ugly will disappear once future patches have folded the semantic checks into the new framework. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-04Add an option to pad the blob that is generatedKumar Gala1-0/+1
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-11-26dtc: Merge refs and labels into single "markers" list (v2)David Gibson1-7/+17
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-26dtc: Flexible tree checking infrastructure (v2)David Gibson1-3/+5
dtc: Flexible tree checking infrastructure Here, at last, is a substantial start on revising dtc's infrastructure for checking the tree; this is the rework I've been saying was necessary practically since dtc was first release. In the new model, we have a table of "check" structures, each with a name, references to checking functions, and status variables. Each check can (in principle) be individually switched off or on (as either a warning or error). Checks have a list of prerequisites, so if checks need to rely on results from earlier checks to make sense (or even to avoid crashing) they just need to list the relevant other checks there. For now, only the "structural" checks and the fixups for phandle references are converted to the new mechanism. The rather more involved semantic checks (which is where this new mechanism will really be useful) will have to be converted in future patches. At present, there's no user interface for turning on/off the checks - the -f option now forces output even if "error" level checks fail. Again, future patches will be needed to add the fine-grained control, but that should be quite straightforward with the infrastructure implemented here. Also adds a testcase for the handling of bad references, which catches a bug encountered while developing this patch. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-01dtc: Move tree checking code to checks.cDavid Gibson1-4/+11
This patch moves the dtc code for checking the device tree its processing into a new checks.c. The tree accessor functions from livetree.c which the checks use are exported and added to dtc.h. Another small step towards a flexible checking architecture. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-10-25DTC: Remove the need for the GLR Parser.Jon Loeliger1-0/+1
Previously, there were a few shift/reduce and reduce/reduce errors in the grammar that were being handled by the not-so-popular GLR Parser technique. Flip a right-recursive stack-abusing rule into a left-recursive stack-friendly rule and clear up three messes in one shot: No more conflicts, no need for the GLR parser, and friendlier stackness. Compensate by reversing the property list on the node. Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-10-22dtc: Disable semantic checks by defaultDavid Gibson1-0/+4
At present, dtc makes a lot of semantic checks on the device tree by default, and will refuse to produce output if they fail. This means people tend to need -f to force output despite failing semantic checks rather a lot. This patch splits the device tree checks into structural checks (no bad or duplicate names or phandles) and semantic checks (everything else). By default, only the structural checks are performed, and are fatal. -f will force output even with structural errors (using this in -Idts mode would essentially always be a bad idea, but it might be useful in -Idtb mode for examining a malformed dtb). Semantic checks are only performed if the new -c command line option is supplied, and are always warnings only. Semantic checks will never be performed on a tree with structural errors. This patch is only a stopgap before implementing proper fine-grained error/warning handling, but it should at least get rid of the far-too-frequent need for -f for the time being. This patch removes the -f from the dtc testcases now that it's no longer necessary. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-09-27dtc: Use libfdt/fdt.h instead of flat_dt.hDavid Gibson1-3/+4
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-18dtc: Whitespace cleanupDavid Gibson1-6/+6
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-08-31dtc: Optimise by default, fix warnings thus uncoveredDavid Gibson1-1/+1
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-07-07dtc: implement labels on property dataMilton Miller1-2/+3
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-04-05Implement the -R option and add a -S option.Jerry Van Baren1-2/+4
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-03-26DTC: Add support for a C-like #include "file" mechanism.Jon Loeliger1-1/+1
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-19Improve options, #define default version.Jerry Van Baren1-0/+5
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-02-16Moved data_convert_cell() out of data.c to the parser.Jon Loeliger1-1/+0
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-15Add support for decimal, octal and binary based cell values.Jon Loeliger1-0/+1
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-08Allow multipart property valuesDavid Gibson1-0/+1
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>
2006-06-07dtc: add setting of physical boot cpuMichael Neuling1-3/+5
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>
2005-10-26Remove no longer used (and already commented) reserve_data field from boot_info.David Gibson1-1/+0
2005-10-26Use names for output functions in the form dt_to_*() instead ofDavid Gibson1-3/+3
write_dt_*() for consistency with the dt_from_*() input functions.
2005-10-24Rework tracking of reserve entries during processing. This is initial workDavid Gibson1-4/+19
to allow more powerful handling of reserve entries.
2005-07-15Remove unused enum from dtc.h.David Gibson1-5/+0
2005-07-15Support for specifying memreserve ranges in the source format, based onDavid Gibson1-8/+30
a patch by Jon Loeliger <jdl AT freescale.com>, although tweaked substantially.
2005-07-11Use u8 instead of uint8_t, as we do with the other size types.David Gibson1-0/+1
2005-06-17Remove build_empty_property(). It wasn't useful.David Gibson1-1/+0
2005-06-16Rudimentary phandle reference support.David Gibson1-1/+14
2005-06-16Initial label support. Also switch to glr-parser mode and get rid ofDavid Gibson1-3/+7
hacks that were necessary without it.
2005-06-08Initial commitDavid Gibson1-0/+181