summaryrefslogtreecommitdiff
path: root/tools/dtoc/fdt.py
AgeCommit message (Collapse)Author
2022-02-22dtoc: Allow deleting nodes and adding them in the same syncSimon Glass
This does not work at present, since the current algorithm assumes that either there are no nodes or all nodes have an offset. If a node is new, but an old node is still in the tree, then syncing fails due to this assumption. Fix it and add a test. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-02-22dtoc: Support deleting a nodeSimon Glass
Add a function to delete a node. This is synced to the tree when requested. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-02-22dtoc: Support adding a string list to a device treeSimon Glass
Add a new function to add a string list. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-02-09patman: Convert camel case in tools.pySimon Glass
Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-08-01dtoc: Support widening a bool valueSimon Glass
At present if we see 'ranges' property (with no value) we assume it is a boolean, as per the devicetree spec. But another node may define 'ranges' with a value, forcing us to widen it to an int array. At present this is not supported and causes an error. Fix this and add some test cases. Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Tom Rini <trini@konsulko.com>
2021-08-01dtoc: Fix widening an int array to an intSimon Glass
An int array can hold a single int so we should not need to do anything in the widening operation. However due to a quirk in the code, an int[3] widened with an int produced an int[4]. Fix this and add a test. Fix a comment typo while we are here. Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Tom Rini <trini@konsulko.com>
2021-08-01dtoc: Rename is_wider_than() to reduce confusionSimon Glass
The current name is confusing because the logic is actually backwards from what you might expect. Rename it to needs_widening() and update the comments. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Add new check that offsets are correctSimon Glass
Add a few more internal checks to make sure offsets are correct, before updating the dtb. To make this easier, update the functions which add a property to return that property,. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Support adding subnodes alongside existing onesSimon Glass
So far we have only needed to add subnodes to empty notds, so have not had to deal with ordering. However this feature is needed for binman's expanded nodes, since there may be another node in the same section. While libfdt adds new properties after existing properties, it adds new subnodes before existing subnodes. This means that we must reorder the nodes in the cached version, so that the ordering remains consistent. Update the sync implementation to sync existing subnodes first, then add new ones, then tidy up the ordering in the cached version. Update the test to cover this behaviour. Also improve the comment about property syncing while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Tweak ordering of fdt-offsets refreshingSimon Glass
Once the tree has been synced, thus potentially moving things around in the fdt, we set _cached_offsets to False so that a refresh will happen next time a property is accessed. This 'lazy' refresh doesn't really save much time, since refresh is a very fast operation, just a single walk of the tree. Also, having the refresh happen in the bowels of property access it makes it harder to figure out what is going on. Simplify the code by always doing a refresh before and after a sync. Set _cached_offsets to True immediately after this, in the Refresh() function, since this makes more sense than doing it in the caller. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Tidy up property-offset handlingSimon Glass
If a property does not yet have an offset, then that means it exists in the cache'd fdt but has not yet been synced back to the flat tree. Use the dirty flag for this so we don't need to check the offset too. Improve the comments for Prop and Node to make it clear what an offset of None means. Also clear the dirty flag after the property is synced. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Improve internal error for Refresh()Simon Glass
Add the node name too so it is easy to see which node failed. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-30binman: Support alignment of filesSimon Glass
When packing files it is sometimes useful to align the start of each file, e.g. if the flash driver can only access 32-bit-aligned data. Provides a new property to support this. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-30dtoc: binman: Drop Python 2 codeSimon Glass
Drop a few more Python 2 relics that are no-longer needed. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13patman: Drop tools.ToChar() and ToChars()Simon Glass
This is useful anymore, since we always want to call chr() in Python 3. Drop it and adjust callers to use chr(). Also drop ToChars() which is no-longer used. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13fdt: Use an Enum for the data typeSimon Glass
Use an Enum instead of the current ad-hoc constants, so that there is a data type associated with each 'type' value. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dtoc: Fix widening of int to bytesSimon Glass
At present an integer is converted to bytes incorrectly. The whole 32-bit integer is inserted as the first element of the byte array, and the other three bytes are skipped. This was not noticed because the unit test did not check it, and the functional test was checking for wrong values. Update the code to handle this as a special case. Add one more test to cover all code paths. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-25dtoc: Allow adding variable-sized data to a dtbSimon Glass
Add a method for adding a property containing arbitrary bytes. Make sure that the tree can expand as needed in this case. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-24Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"Tom Rini
This reverts commit 5d3a21df6694ebd66d5c34c9d62a26edc7456fc7, reversing changes made to 56d37f1c564107e27d873181d838571b7d7860e7. Unfortunately this is causing CI failures: https://travis-ci.org/github/trini/u-boot/jobs/711313649 Signed-off-by: Tom Rini <trini@konsulko.com>
2020-07-20dtoc: Allow adding variable-sized data to a dtbSimon Glass
Add a method for adding a property containing arbitrary bytes. Make sure that the tree can expand as needed in this case. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-26patman: Move to absolute importsSimon Glass
At present patman sets the python path on startup so that it can access the libraries it needs. If we convert to use absolute imports this is not necessary. Move patman to use absolute imports. This requires changes in tools which use the patman libraries (which is most of them). Signed-off-by: Simon Glass <sjg@chromium.org>
2019-11-04dtoc: Convert fdt.py to Python 3Simon Glass
Drop the now-unused Python 2 code to keep code coverage at 100%. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29binman: Update state when replacing device-tree entriesSimon Glass
Since the state module holds references to all the device trees used by binman, it must be updated when the device trees are updated. Add support for this. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29dtoc: Update Fdt.GetNode() to handle the root nodeSimon Glass
This function currently fails if the root node is requested. Requesting the root node is sometimes useful, so fix the bug. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29dtoc: Update Fdt.FromData() to allow a nameSimon Glass
It is confusing when something goes wrong with a device tree which was created from data rather than a file, since there is no identifying filename. Add an option to provide this. Use the filename as the name, where available Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29binman: Show a helpful error when a DT property is missingSimon Glass
At present a Python exception is raised which does not show the node information. Add a more helpful exception in this case. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Convert the Fdt.Node class to Python 3Simon Glass
Update this class to work correctly on Python 3 and to pass its unit tests. The only required change is to deal with a difference in the behaviour of sorting with a None value. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Convert the Fdt.Prop class to Python 3Simon Glass
Update this class to work correctly on Python 3 and to pass its unit tests. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Use byte type instead of str in fdtSimon Glass
In Python 3 bytes and str are separate types. Use bytes to ensure that the code functions correctly with Python 3. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Updates BytesToValue() for Python 3Simon Glass
The difference between the bytes and str types in Python 3 requires a number of minor changes to this function. Update it to handle the input data using the 'bytes' type. Create two useful helper functions which can be used by other modules too. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Move BytesToValue() out of the Prop classSimon Glass
This method does not actually use any members of the Prop class. Move it out of the class so that it is easier to add unit tests. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10dtoc: Use GetBytes() to obtain repeating bytesSimon Glass
Use this helper function which works on both Python 2 and Python 3. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10tools: dtoc: Open all binary files in binary modeSimon Glass
Fix an open() statement to use binary mode, so that it works as expected with Python 3. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-10-09dtoc: Fix the value of SetInt()Simon Glass
This does not set the correct value at present. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-09-28dtoc: Add a way to create an Fdt object from a data blockSimon Glass
Support creating an Fdt object without having to write the data to a file first. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-09-28dtoc: Add methods for adding and updating propertiesSimon Glass
Add a few more functions which allow creating and modifying property values. If only we could do this so easily in the real world. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-09-28dtoc: Support adding new nodesSimon Glass
Add a way to add new nodes and sync them back to the blob. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-09-28dtoc: Fixed endianness in Prop.GetEmpty()Simon Glass
This should be big endian, since that is what device tree uses. Fix it. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-09-28dtoc: Allow syncing of the device tree back to a fileSimon Glass
At present we require the caller to manually update the device tree using individual calls to libfdt functions. This is not ideal. It would be better if we could make changes using the Python structure and then call a Sync() function to write them back. Add this feature to the Fdt class. Update binman and the tests to match. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-08-08libfdt: Update to latest pylibfdt implementationSimon Glass
The enhanced pylibfdt support in U-Boot needed for binman was a placeholder while upstreaming of this work continued. This is now complete, so bring in the changes and update the tools as needed. There are quite a few changes since we decided to split the implementation into three fdt classes instead of two. The Fdt.del_node() method was unfortunately missed in this process and will be dealt with later. It exists in U-Boot but not upstream. Further syncing of libfdt probably needs to wait until we assess the code-size impact of all the new checking code on SPL and possibly provide a way to disable it. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-08-01dtoc: Add a function to obtain a list of phandlesSimon Glass
Add a function which can decode a property containing a list of phandles. This is useful for finding nodes linked to a property. Also provide a way to look up a single phandle and get the Fdt object from a Node. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-08-01dtoc: Export the _FindNode() functionSimon Glass
This is useful for clients that want to find a node. Export it so it can be used by others. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Add functions to add integer propertiesSimon Glass
Add a few simple functions to add a placeholder integer property, and set its value. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Fix some minor errorsSimon Glass
Fix some comments and a printf string which is incorrect. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Fix Fdt.GetNode() to handle a missing nodeSimon Glass
At present the algortihm is not correct since it will return the root node if the requested node is not found and there are no slashes in the requested node name. Fix this and add a test. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Keep track of property offsetsSimon Glass
At present the Fdt class does not keep track of property offsets if they change due to removal of properties. Update the code to handle this, and add a test. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Update fdt tests to increase code coverageSimon Glass
At present only some of the fdt functionality is tested. Add more tests to cover the rest of it. Also turn on test coverage, which is now 100% with a small exclusion for a Python 3 feature. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Drop use of a local dtb bufferSimon Glass
At present the Fdt class has its own copy of the device tree. This is confusing an unnecessary now that pylibfdt has its own. Drop it and provide access functions to the buffer. This allows us to move the rest of the implementation to use pylibfdt methods instead of directly calling libfdt stubs. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Make use of the new pylibfdt methodsSimon Glass
Now that pylibfdt supports a fuller API we don't need to directly call the libfdt stubs. Update the code to use the Fdt methods instead. Some other cases remain which will be tidied up in a later commit, since they need larger changes. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-07-09dtoc: Add some tests for the fdt moduleSimon Glass
At present this module is tested via the dtoc tests. This is a bit painful since the tests are at a higher level and so failures are more difficult to diagnose. Add some tests that exercise the fdt module directly. Signed-off-by: Simon Glass <sjg@chromium.org>