summaryrefslogtreecommitdiff
path: root/tools/dtoc
AgeCommit message (Collapse)Author
2016-10-09dtoc: Make integer division python 3.x safePaul Burton
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 Burton
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 Burton
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 Glass
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 Glass
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 Glass
This does not actually call fdtget correctly when requesting a particular type. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Add methods for reading data from propertiesSimon Glass
Provide easy helpers for reading integer, string and boolean values from device-tree properties. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Correct quotes in fdt_utilSimon Glass
The style is to use single quotes for strings where possible. Adjust this function. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Support finding the offset of a propertySimon Glass
Add a way to find the byte offset of a property within the device tree. This is only supported with the normal libfdt implementation since fdtget does not provide this information. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Support packing the device treeSimon Glass
After any node/property deletion the device tree can be packed to remove spare space. Add a way to perform this operation. Note that for fdt_fallback, fdtput automatically packs the device tree after deletion, so no action is required here. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Support deleting device tree propertiesSimon Glass
Add support for deleting a device tree property. With the fallback implementation this uses fdtput. With libfdt it uses the API call and updates the offsets afterwards. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move to using bytearraySimon Glass
Since we want to be able to change the in-memory device tree using libfdt, use a bytearray instead of a string. This makes interfacing from Python easier. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Prepare for supporting changing of device treesSimon Glass
For binman we need to support deleting properties in the device tree. This will change the offsets of nodes after the deletion. In preparation, add code to keep track of when the offsets are invalid, and regenerate them. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Drop the convert_dash parameter to GetProps()Simon Glass
This is not used anywhere in dtoc, so drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Allow the device tree to be compiled from sourceSimon Glass
If a source device tree is provide to the Fdt() constructors, compile it automatically. This will be used in tests, where we want to build a particular test .dts file and check that it works correctly in binman. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move a few more common functions into fdt.pySimon Glass
Some functions have the same code in the subclasses. Move these into the superclass to avoid duplication. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move Widen() and GetPhandle() into the base classSimon Glass
These functions are identical in both subclasses. Move them into the base class. Note: In fact there is a bug in one version, which was fixed by this patch: https://patchwork.ozlabs.org/patch/651697/ Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move BytesToValue() and GetEmpty() into PropBaseSimon Glass
These functions are currently in a separate fdt_util file. Since they are only used from PropBase and subclasses, it makes sense for them to be in the PropBase class. Move these functions into fdt.py along with the list of types. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Create a base class for FdtSimon Glass
At present we have two separate implementations of the Fdt library, one which uses fdtget/fdtput and one which uses libfdt (via swig). Before adding more functionality it makes sense to create a base class for these. This will allow common functions to be shared, and make the Fdt API a little clearer. Create a new fdt.py file with the base class, and adjust fdt_normal.py and fdt_fallback.py to use it. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Rename fdt.py to fdt_normal.pySimon Glass
In preparation for creating an Fdt base class, rename this file to indicate it is the normal Fdt implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move the fdt library selection into fdt_selectSimon Glass
Rather than have dtc worry about which fdt library to use, move this into a helper file. Add a function which creates a new Fdt object and scans it, regardless of the implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-09-18dtoc: Move the struct import into the correct orderSimon Glass
This should be in with the other system includes. Move it. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-07-25dtoc: Correct the type widening code in fdt_fallbackSimon Glass
This code does not match the fdt version in fdt.py. When dtoc is unable to use the Python libfdt library, it uses the fallback version, which does not widen arrays correctly. Fix this to avoid a warning 'excess elements in array initialize' in dt-platdata.c which happens on some platforms. Reported-by: Tom Rini <trini@konsulko.com> Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Tom Rini <trini@konsulko.com>
2016-07-14dm: core: Expand platdata for of-platdata devicesSimon Glass
Devices which use of-platdata have their own platdata. However, in many cases the driver will have its own auto-alloced platdata, for use with the device tree. The ofdata_to_platdata() method converts the device tree settings to platdata. With of-platdata we would not normally allocate the platdata since it is provided by the U_BOOT_DEVICE() declaration. However this is inconvenient since the of-platdata struct is closely tied to the device tree properties. It is unlikely to exactly match the platdata needed by the driver. In fact a useful approach is to declare platdata in the driver like this: struct r3288_mmc_platdata { struct dtd_rockchip_rk3288_dw_mshc of_platdata; /* the 'normal' fields go here */ }; In this case we have dt_platadata available, but the normal fields are not present, since ofdata_to_platdata() is never called. In fact driver model doesn't allocate any space for the 'normal' fields, since it sees that there is already platform data attached to the device. To make this easier, adjust driver model to allocate the full size of the struct (i.e. platdata_auto_alloc_size from the driver) and copy in the of-platdata. This means that when the driver's bind() method is called, the of-platdata will be present, followed by zero bytes for the empty 'normal field' portion. A new DM_FLAG_OF_PLATDATA flag is available that indicates that the platdata came from of-platdata. When the allocation/copy happens, the DM_FLAG_ALLOC_PDATA flag will be set as well. The dtoc tool is updated to output the platdata_size field, since U-Boot has no other way of knowing the size of the of-platdata struct. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-07-14dtoc: Ignore the u-boot, dm-pre-reloc propertySimon Glass
This property is not useful for of-platdata, so omit it. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-07-14dm: Add a more efficient libfdt librarySimon Glass
Add a Python version of the libfdt library which contains enough features to support the dtoc tool. This is only a very bare-bones implementation. It requires the 'swig' to build. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-07-14dm: Add a tool to generate C code from a device treeSimon Glass
This tool can produce C struct definitions and C platform data tables. This is used to support the of-platdata feature. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-07-14dm: Add a library to provide simple device-tree accessSimon Glass
This Python library provides a way to access the contents of the device tree. It uses fdtget, so is inefficient for larger device tree files. Signed-off-by: Simon Glass <sjg@chromium.org>