aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc
AgeCommit message (Collapse)AuthorFilesLines
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini14-29/+14
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-03-05libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>Masahiro Yamada2-2/+2
Thomas reported U-Boot failed to build host tools if libfdt-devel package is installed because tools include libfdt headers from /usr/include/ instead of using internal ones. This commit moves the header code: include/libfdt.h -> include/linux/libfdt.h include/libfdt_env.h -> include/linux/libfdt_env.h and replaces include directives: #include <libfdt.h> -> #include <linux/libfdt.h> #include <libfdt_env.h> -> #include <linux/libfdt_env.h> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-01-28host-tools: use python2 explicitly for shebangMasahiro Yamada1-1/+1
All of these host tools are apparently written for Python2, not Python3. Use 'python2' in the shebang line according to PEP 394 (https://www.python.org/dev/peps/pep-0394/). Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-01-15dtoc: Allow DTC environment variable to provide path to dtcSimon Glass1-1/+2
The system device-tree compiler may not be new enough to run the tests we use in U-Boot (e.g. with binman). Allow use of a DTC environment variable to point to the correct dtc. If not defined, the dtc on the default PATH is used. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-22dtoc: Fix up testsSimon Glass1-45/+37
The tool has changed slightly since it was originally written. Update the tests to suit. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-11-22binman: Disable the no-unit_address_vs_reg warningsSimon Glass1-1/+2
These warnings are not useful for binman tests. Disable them. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-09-15dtoc: Add a header to the generated filesSimon Glass1-0/+12
Add a header that indicates that the files generated by dtoc should not be modified. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Support properties containing multiple phandle valuesSimon Glass3-12/+53
At present dtoc has a very simplistic view of phandles. It assumes that a property has only a single phandle with a single argument (i.e. two cells per property). This is not true in many cases. Enhance the implementation to scan all phandles in a property and to use the correct number of arguments (which can be 0, 1, 2 or more) when generating the C code. For the struct definitions, use a struct which can hold the maximum number of arguments used by the property. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Put phandle args in an arraySimon Glass2-2/+2
We want to support more than one phandle argument. It makes sense to use an array for this rather than discrete struct members. Adjust the code to support this. Rename the member to 'arg' instead of 'id'. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Put each phandle on a separate lineSimon Glass2-6/+9
When writing values from properties which contain phandles, dtoc currently writes 8 phandles per line. Change this to write one phandle per line. This helps reduce line length, since phandles are generally longer and may have arguments. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Rename the phandle structSimon Glass2-2/+3
Rather than naming the phandle struct according to the number of cells it uses (e.g. struct phandle_2_cell) name it according to the number of arguments it has (e.g. struct phandle_1_arg). This is a more intuitive naming. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Rename is_phandle() and adjust it to return more detailSimon Glass2-22/+58
Update this function to return more detail about a property that contains phandles. This will allow (in a future commit) more accurate handling of these properties. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Make is_phandle() a member functionSimon Glass1-18/+18
This function will need to have access to class members once we enhance it to support multiple phandle values. In preparation for that, move it into the class. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Use the Fdt's class's phandle mapSimon Glass1-13/+3
Now that the Fdt class can map phandles to the associated nodes, use that instead of a separate implementation. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Update the Fdt class to record phandlesSimon Glass1-0/+5
Add a map from phandles to nodes. This can be used by clients of the the class instead of maintaining this themselves. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Handle 'reg' properties with unusual sizesSimon Glass2-0/+38
At present dtoc assumes that all 'reg' properties have both an address and a size. For I2C devices we do not have this. Adjust dtoc to cope. Reported-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Add support for 32 or 64-bit addressesSimon Glass7-0/+401
When using 32-bit addresses dtoc works correctly. For 64-bit addresses it does not since it ignores the #address-cells and #size-cells properties. Update the tool to use fdt64_t as the element type for reg properties when either the address or size is larger than one cell. Use the correct value so that C code can obtain the information from the device tree easily. Alos create a new type, fdt_val_t, which is defined to either fdt32_t or fdt64_t depending on the word size of the machine. This type corresponds to fdt_addr_t and fdt_size_t. Unfortunately we cannot just use those types since they are defined to phys_addr_t and phys_size_t which use 'unsigned long' in the 32-bit case, rather than 'unsigned int'. Add tests for the four combinations of address and size values (32/32, 64/64, 32/64, 64/32). Also update existing uses for rk3399 and rk3368 which now need to use the new fdt_val_t type. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Heiko Stuebner <heiko@sntech.de> Reported-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Avoid very long lines in outputSimon Glass2-3/+10
Large arrays can result in lines with hundreds or thousands of characters which is not very editor-friendly. To avoid this, addjust the tool to group values 8 per line. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Add a 64-bit type and a way to convert cells into 64 bitsSimon Glass3-1/+18
When dealing with multi-cell values we need a type that can hold this value. Add this and a function to process it from a list of cell values. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-09-15dtoc: Adjust Node to record its parentSimon Glass1-5/+7
We need to be able to search back up the tree for #address-cells and #size-cells. Record the parent of each node to make this easier. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-08-20Fix 'notes' typosAnatolij Gustschin1-1/+1
s/notes/nodes Signed-off-by: Anatolij Gustschin <agust@denx.de>
2017-07-11dtoc: Add testsSimon Glass7-4/+411
Add some tests of dtoc's functionality to make it easier to expand and enhance the tool. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Add a comment about string replace in conv_name_to_c()Simon Glass1-0/+3
This function uses several separate string replaces where a regular expression might seem more reasonable. Add a comment justifying the way it is currently done. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Move the main logic into the dtb_platdata fileSimon Glass2-17/+31
Collect the main logic of dtoc into a function and put it into dtb_platdata. This will allow tests to use this function instead of duplicating the code themselves. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Move static functions out of the classSimon Glass1-62/+63
Rather than using static functions within the class, move them out of the class. This will make it slightly easier for tests to call them. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Pass include_disabled explicitlySimon Glass2-5/+5
This option is the only one actually used by the dtb_platdata class. Pass it explicitly to avoid needing to pass the whole option object to the constructor. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Don't handle properties with / in themSimon Glass1-1/+0
This conversion appears to not be needed as it does not occur in practice. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Fix pylint warningsSimon Glass2-131/+144
Unfortunately I neglected to run pylint on this tool with its initial submission. Fix the warnings. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Split out the main class into its own fileSimon Glass2-405/+414
To simplify running tests we should move this class into its own file. This allows the tests to import it without having to import dtoc.py, which runs the tests. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Add a comment at the topSimon Glass1-0/+20
Add a description of the dtoc tool at the top of the file. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Use self._options instead of the global optionsSimon Glass1-2/+2
This class should use the options object passed to it rather than finding the global one. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dtoc: Support multiple compatible strings in a nodeSimon Glass1-7/+21
Sometimes a node will have multiple compatible strings. Drivers may use one or the other so the best approach seems to be to #define them to be equivalent. Update dtoc to support this. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-06-02fdt: Drop fdt_select.pySimon Glass3-20/+9
This file was used to select between the normal and fallback libfdt implementations. Now that we only have one, it is not needed. Drop it and fix up all users. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02fdt: Merge fdt_normal with its base classSimon Glass3-253/+157
Since we only have one Fdt implementation now we don't need to have a base class. Merge the implementation and the base class together. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02fdt: Drop fdt_fallback librarySimon Glass3-204/+5
Drop this now-unused library and associated tests. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02fdt: Drop use of the legacy libfdt python moduleSimon Glass1-24/+8
Now that this is no-longer available, stop looking for it. The new module will be used if available. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02fdt: Support use of the new python libfdt librarySimon Glass2-9/+27
Use the new library if available, while retaining backwards compatibility with the old library for now. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02fdt: Rename existing python libfdt moduleSimon Glass1-1/+1
Now that this module has been accepted upstream we should stop using the local U-Boot one. In preparation for this, rename it to indicate it is for legacy use. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-05-10dtoc: Handle nodes with phandles that depend on the sameSimon Glass1-14/+41
At present dtoc assumes that nodes which are phandles do not themselves reference other phandle nodes. Unfortunately this is not necessarilly true. As a result we can currently output C code which does not compile because a node declaration can be referenced before it is declared. Adjust the code to explicitly output all phandle nodes needed by node before the node itself is output. This fixes building with the latest rk3399-firefly.dts from Linux, which has reordered the nodes. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-05-10dtoc: Move the output code into its own functionSimon Glass1-44/+52
The code to generate the tables is quite long. Move the node-output code into its own function. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-04-13dtoc: Decode val if it's a byte stringGeorge McCollister1-0/+2
With Python 3.5.2 encode will throw an exception if val is a byte array. Decode it to a string first. This assumes it's utf-8, if it's not valid utf-8 it will throw an exception. Signed-off-by: George McCollister <george.mccollister@gmail.com> Acked-by: Simon Glass <sjg@chromium.org>
2017-03-22dtoc: make ScanTree recurse into subnodesPhilipp Tomsich1-1/+18
Previously, dtoc could only process the top-level nodes which led to device nodes in hierarchical trees to be ignored. E.g. the mmc0 node in the following example would be ignored, as only the soc node was processed: / { soc { mmc0 { /* ... */ }; }; }; This introduces a recursive helper method ScanNode, which is used by ScanTree to recursively parse the entire tree hierarchy. Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-03-16dm: allow limiting pre-reloc markings to spl or tplHeiko Stübner1-0/+2
Right now the u-boot,dm-pre-reloc flag will make each marked node always appear in both spl and tpl. But systems needing an additional tpl might have special constraints for each, like the spl needing to be very tiny. So introduce two additional flags to mark nodes for only spl or tpl environments and introduce a function dm_fdt_pre_reloc to automate the necessary checks in code instances checking for pre-relocation flags. The behaviour of the original flag stays untouched and still marks a node for both spl and tpl. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
2017-02-08dtoc: Replace dot with underscore to avoid compiler errorsSimon Glass1-0/+1
If there is a '.' in a compatible string, then dtoc will produce a struct with a name containing a '.'. This won't work, so replace it with '_'. Also add a suitable test to the sandbox device tree to catch this. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Make integer division python 3.x safePaul Burton1-1/+1
If we use the '/' operator then python 3.x will produce a float, and refuse to multiply the string sequence in Conv_name_to_c by it with: TypeError: can't multiply sequence by non-int of type 'float' Use the '//' operator instead to enforce that we want integer rather than floating point division. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Acked-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Decode strings for struct.unpack on python 3.xPaul Burton1-0/+3
On python 3.x struct.unpack will complain if we provide it with a string since it expects to operate on a bytes object. In order to satisfy this requirement, encode the string to a bytes object when running on python 3.x. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Acked-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Use items() to iterate over dictionaries in python 3.xPaul Burton2-5/+5
In python 3.x the iteritems() method has been removed from dictionaries, and the items() method does effectively the same thing. On python 2.x using items() is a little less efficient since it involves copying data, but as speed isn't a concern in the affected code switch to using items() anyway for simplicity. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Acked-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Add a way for tests to request the fallback librarySimon Glass1-3/+13
We need to test both the normal (Python libfdt module) and fallback (fdtget) implementations of the Fdt class. Add a way to select which implementation to use. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Adjust GetProps() in fdt_normal to use the node pathSimon Glass1-6/+3
There is no need to pass a node path separately. Instead we should use the path for the node provided. Correct this. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-09dtoc: Fix bug in GetProp()Simon Glass1-1/+1
This does not actually call fdtget correctly when requesting a particular type. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>