summaryrefslogtreecommitdiff
path: root/tools/dtoc
Commit message (Collapse)AuthorAgeLines
* dtoc: Replace dot with underscore to avoid compiler errorsSimon Glass2017-02-08-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>
* dtoc: Make integer division python 3.x safePaul Burton2016-10-09-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>
* dtoc: Decode strings for struct.unpack on python 3.xPaul Burton2016-10-09-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>
* dtoc: Use items() to iterate over dictionaries in python 3.xPaul Burton2016-10-09-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>
* dtoc: Add a way for tests to request the fallback librarySimon Glass2016-10-09-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>
* dtoc: Adjust GetProps() in fdt_normal to use the node pathSimon Glass2016-10-09-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>
* dtoc: Fix bug in GetProp()Simon Glass2016-10-09-1/+1
| | | | | | | This does not actually call fdtget correctly when requesting a particular type. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Add methods for reading data from propertiesSimon Glass2016-09-18-0/+25
| | | | | | | Provide easy helpers for reading integer, string and boolean values from device-tree properties. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Correct quotes in fdt_utilSimon Glass2016-09-18-1/+1
| | | | | | | The style is to use single quotes for strings where possible. Adjust this function. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Support finding the offset of a propertySimon Glass2016-09-18-0/+29
| | | | | | | | 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>
* dtoc: Support packing the device treeSimon Glass2016-09-18-0/+27
| | | | | | | | | | 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>
* dtoc: Support deleting device tree propertiesSimon Glass2016-09-18-0/+43
| | | | | | | | 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>
* dtoc: Move to using bytearraySimon Glass2016-09-18-1/+1
| | | | | | | | 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>
* dtoc: Prepare for supporting changing of device treesSimon Glass2016-09-18-4/+42
| | | | | | | | 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>
* dtoc: Drop the convert_dash parameter to GetProps()Simon Glass2016-09-18-4/+1
| | | | | | This is not used anywhere in dtoc, so drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Allow the device tree to be compiled from sourceSimon Glass2016-09-18-2/+48
| | | | | | | | 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>
* dtoc: Move a few more common functions into fdt.pySimon Glass2016-09-18-32/+57
| | | | | | | 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>
* dtoc: Move Widen() and GetPhandle() into the base classSimon Glass2016-09-18-83/+41
| | | | | | | | | | | 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>
* dtoc: Move BytesToValue() and GetEmpty() into PropBaseSimon Glass2016-09-18-79/+80
| | | | | | | | | | 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>
* dtoc: Create a base class for FdtSimon Glass2016-09-18-48/+148
| | | | | | | | | | | | | | 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>
* dtoc: Rename fdt.py to fdt_normal.pySimon Glass2016-09-18-1/+1
| | | | | | | 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>
* dtoc: Move the fdt library selection into fdt_selectSimon Glass2016-09-18-15/+26
| | | | | | | | 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>
* dtoc: Move the struct import into the correct orderSimon Glass2016-09-18-2/+1
| | | | | | This should be in with the other system includes. Move it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Correct the type widening code in fdt_fallbackSimon Glass2016-07-25-0/+6
| | | | | | | | | | | | | 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>
* dm: core: Expand platdata for of-platdata devicesSimon Glass2016-07-14-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* dtoc: Ignore the u-boot, dm-pre-reloc propertySimon Glass2016-07-14-0/+1
| | | | | | This property is not useful for of-platdata, so omit it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: Add a more efficient libfdt librarySimon Glass2016-07-14-0/+180
| | | | | | | | 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>
* dm: Add a tool to generate C code from a device treeSimon Glass2016-07-14-0/+392
| | | | | | | 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>
* dm: Add a library to provide simple device-tree accessSimon Glass2016-07-14-0/+294
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>