summaryrefslogtreecommitdiff
path: root/tools/dtoc
AgeCommit message (Collapse)AuthorFilesLines
2021-03-22dtoc: Ignore unwanted files when scanning for driversSimon Glass2-1/+9
We should ignore anything in the .git directory or any of the build-sandbox, etc. directories created by 'make check'. These can confuse dtoc. Update the code to ignore these. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Save scan information across test runsSimon Glass3-10/+43
At present most of the tests scan the U-Boot source tree as part of their run. This information does not change across tests, so we can save time by remembering it. Add a way to set up this information and use it for each test, taking a copy first, so as not to mess up the original. This reduces the run time from about 1.6 seconds to 1.5 seconds on my machine. For code coverage (which cannot run in parallel), it reduces from 33 seconds to 5. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Scan drivers for available informationSimon Glass2-14/+311
At present we simply record the name of a driver parsed from its implementation file. We also need to get the uclass and a few other things so we can instantiate devices at build time. Add support for collecting this information. This requires parsing each driver file. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-31binman: Support alignment of filesSimon Glass2-0/+18
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-31dtoc: binman: Drop Python 2 codeSimon Glass1-2/+1
Drop a few more Python 2 relics that are no-longer needed. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Tidy up src_scan testsSimon Glass1-6/+22
Some of these tests don't actually check anything. Add a few more checks to complete the tests. Also add a simple scan test that does the basics. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Move src_scan tests to a separate fileSimon Glass5-78/+97
Move the tests related to scanning into their own class, updating them to avoid using dtb_platdata as a pass-through. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Split source-code scanning to a separate fileSimon Glass3-169/+204
Before expanding the scanning features any more, move this into a separate file. This will make it easier to maintain in the future. In particular, it reduces the size of dtb_platdata.py and allows us to add tests specifically for scanning, without going through that file. The pieces moved are the Driver class, the scanning code and the various naming functions, since they mostly depend on the scanning results. So far there is are no separate tests for src_scan. These will be added as new functionality appears. This introduces no functional change. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Drop dm_populate_phandle_data()Simon Glass2-28/+7
This has not been needed since parent information was added and we started using indicies for references to other drivers instead of pointers. It was kept around in the expectation that it might be needed later. However with the latest updates, it doesn't seem likely that we'll need this in the foreseeable future. Drop dm_populate_phandle_data() from dtoc and driver model. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Output nodes in orderSimon Glass2-43/+34
Previously we had to worry about nodes being output before those that they depended on, thus causing build errors. So the current algorithm is careful to output nodes in the right order. We now use a different method for outputting phandles that does not involve pointers. Also we plan to add a 'declarations' header file to declare all drivers as 'extern'. Update the code to drop the dependency checking and output in a simple loop. This makes the output easier to follow since drivers are in order of thier indices (0, 1, ...), which is also the order it appears in in the linker list. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Allow specifying the base directory for testsSimon Glass2-6/+46
The base directory of U-Boot, where the source is, it currently calculated from the directory of the dtb_platdata.py script. If this is installed elsewhere that will not work. Also it is inconvenient for tests. Add a parameter to allow specifying this base directory. To test this, pass a temporary directory with some files in it and check that they are passed to scan_driver(). Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Add the method for each command to OutputFileSimon Glass1-26/+16
Rather than the if/else construct, update OutputFile with the method to call to process each command. This is easier to maintain as the number of commands increases. Rename generate_tables to generate_plat since it better describes what is being generated ('plat' is the U-Boot name for platform data). With this, each output method needs to have the same signature. Store the output structures in a member variable instead of using parameters, to accomplish this. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Rename dt-platdata.c to dt-plat.cSimon Glass2-4/+4
Use this new name to be consistent with the rest of U-Boot, which talks about 'plat' for the platform data, which is what this file holds. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Add a header comment to each generated fileSimon Glass2-12/+24
It is currently fairly obvious what the two generated files are for, but this will change as more are added. It is helpful for readers to describe the purpose of each file. Add a header commment field to OutputFile and use it to generate a comment at the top of each file. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Run tests using test_utilSimon Glass1-21/+10
Use the standard function for running tests and reported results. This allows the tests to run in parallel, which is a significant speed-up on most machines (e.g. 4.5 seconds -> 1.5s on mine). Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIASSimon Glass2-4/+4
We use the U_BOOT_ prefix (i.e. U_BOOT_DRIVER) to declare a driver but in every other case we just use DM_. Update the alias macros to use the DM_ prefix. We could perhaps rename U_BOOT_DRIVER() to DM_DRIVER(), but this macro is widely used and there is at least some benefit to indicating it us a U-Boot driver, particularly for code ported from Linux. So for now, let's keep that name. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET()Simon Glass1-2/+2
This does not get a device (struct udevice *) but a struct driver_info * so the name is confusing. Rename it accordingly. Since we plan to have several various of these macros, put GET at the end instead of the middle, so it is easier to spot the related macros. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()Simon Glass2-37/+37
The current macro is a misnomer since it does not declare a device directly. Instead, it declares driver_info record which U-Boot uses at runtime to create a device. The distinction seems somewhat minor most of the time, but is becomes quite confusing when we actually want to declare a device, with of-platdata. We are left trying to distinguish between a device which isn't actually device, and a device that is (perhaps an 'instance'?) It seems better to rename this macro to describe what it actually is. The macros is not widely used, since boards should use devicetree to declare devices. Rename it to U_BOOT_DRVINFO(), which indicates clearly that this is declaring a new driver_info record, not a device. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Add an 'all' commandSimon Glass3-10/+43
With upcoming changes, dtoc will output several files for different of-platdata components. Add a way to output all ava!ilable files at once ('all'), to the appropriate directories, without needing to specify each one invidually. This puts the commands in alphabetical order, so update the tests accordingly. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Allow outputing to multiple filesSimon Glass2-10/+94
Implement the 'output directory' feature, allowing dtoc to write the output files separately to the supplied directories. This allows us to handle the struct and platdata output in one run of dtoc. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Allow providing a directory to write files toSimon Glass3-10/+19
At present dtoc writes only a single file on each invocation. U-Boot writes the two files it needs by separate invocations of dtoc. Since dtoc now scans all U-Boot driver source, this is fairly slow (about 1 second per file). It would be better if dtoc could write all the files at once. In preparation for this, add a way to specify an output directory for the files. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Test the stdout outputSimon Glass1-15/+22
Normally dtoc outputs to a file but it also offers a way to write output to stdout. At present the test for that does not actually check that the output is correct. Add this to the test. This uses a member variable to hold the expected text, so it can be used in muitiple places. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Use None to mean stdoutSimon Glass3-7/+7
At present dtoc uses '-' internally to mean that output should go to stdout. This is not necessary and None is more convenient. Update it. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Tidy up pylint warnings in testSimon Glass1-71/+85
Tidy up this file to reduce the number of pylint warnings. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Convert _drivers to a dictSimon Glass2-4/+32
At present this member holds a simple list of driver names. Update it to be a dict of DriverInfo, with the name being the key. This will allow more information to be added about each driver, in future patches. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Output the struct values in a separate functionSimon Glass1-16/+34
Reduce the length of output_node() futher by moving the struct-output functionality into a two separate functions. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Output the device in a separate functionSimon Glass1-11/+22
Reduce the length of output_node() by moving the device-output functionality into a separate function. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Make _output_list a top-level functionSimon Glass1-40/+40
It is annoying to have this function inside its parent since it makes the parent longer and hard to read. Move it to the top level. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dtoc: Fix a few pylint warnings in dtb_platdataSimon Glass1-15/+16
These have crept in again. Update the file to fix all but these ones: dtb_platdata.py:143:0: R0902: Too many instance attributes (10/7) (too-many-instance-attributes) dtb_platdata.py:713:0: R0913: Too many arguments (6/5) (too-many-arguments) Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05sandbox: Drop unnecessary test nodeSimon Glass2-17/+0
The spl-test4 node deliberately has an invalid compatible string. This causes a warning from dtoc and the check it does is not really necessary. Drop it, to avoid the warning and associated confusion. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-14dm: Rename 'platdata_size' to 'plat_size'Simon Glass2-34/+34
Rename this to be consistent with the change from 'platdata'. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-14dm: treewide: Rename 'platdata' variables to just 'plat'Simon Glass2-34/+34
We use 'priv' for private data but often use 'platdata' for platform data. We can't really use 'pdata' since that is ambiguous (it could mean private or platform data). Rename some of the latter variables to end with 'plat' for consistency. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13dtoc: Tidy up more Python style in dtb_platdataSimon Glass1-45/+46
Update this file to reduce the number of pylint warnings. Also add a few missing comments while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13dtoc: Tidy up Python style in dtb_platdataSimon Glass1-29/+42
Update this, mostly to add comments for argument and return types. It is probably still too early to use type hinting since it was introduced in 3.5. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13patman: Drop tools.ToChar() and ToChars()Simon Glass2-5/+5
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-13patman: Drop tools.ToByte()Simon Glass1-1/+1
This is not needed in Python 3. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13patman: Drop unicode helper functionsSimon Glass1-1/+2
We don't need these now that everything uses Python 3. Remove them and the extra code in GetBytes() and ToBytes() too. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13fdt: Use an Enum for the data typeSimon Glass4-52/+70
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-29dm: Don't allow U_BOOT_DEVICE() when of-platdata is usedSimon Glass2-0/+6
With of-platdata, the devicetree is supposed to specify all the devices in the system. So far this hasn't really mattered since of-platdata still works correctly. However, new of-platdata features rely on numbering the devices in a particular order so that they can be referenced by a single integer. It is tricky to implement this efficiently when other devices are present in the build. To address this, disable use of U_BOOT_DEVICE() when of-platdata is enabled. This seems acceptable as it is not supposed to be used at all, except in SPL/TPL, where of-platdata is the recommended approach. This breaks one non-compliant boards at present: mx6cuboxi Signed-off-by: Simon Glass <sjg@chromium.org> (disable CONFIG_IMX_THERMAL for mx6cuboxi to avoid a build error)
2020-10-29dm: Use driver_info index instead of pointerSimon Glass2-38/+15
At present we use a 'node' pointer in the of-platadata phandle_n_arg structs. This is a pointer to the struct driver_info for a particular device, and we can use it to obtain the struct udevice pointer itself. Since we don't know the struct udevice pointer until it is allocated in memory, we have to fix up the phandle_n_arg.node at runtime. This is annoying since it requires that SPL's data is writable and adds a small amount of extra (generated) code in the dm_populate_phandle_data() function. Now that we can find a driver_info by its index, it is easier to put the index in the phandle_n_arg structures. Update dtoc to do this, add a new device_get_by_driver_info_idx() to look up a device by drive_info index and update the tests to match. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dm: Support parent devices with of-platdataSimon Glass2-0/+37
At present of-platdata does not provide parent information. But this is useful for I2C devices, for example, since it allows them to determine which bus they are on. Add support for setting the parent correctly, by storing the parent driver_info index in dtoc and reading this in lists_bind_drivers(). This needs multiple passes since we must process children after their parents already have been bound. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dtoc: Fix widening of int to bytesSimon Glass4-1/+23
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-10-29dtoc: Order the structures internally by nameSimon Glass2-43/+83
At present the structures are written in name order, but parents have to be written before their children, so the file does not end up being in order. The order of nodes in _valid_nodes matches the order of the devicetree. Update the code so that _valid_nodes is in sorted order, by C name of the structure. This allows us to assign a sequential ordering to each U_BOOT_DEVICE() declaration. U-Boot's linker lists are also ordered alphabetically, which means that the order in the driver_info list will match the order used by dtoc. This defines an index ('idx') for the U_BOOT_DEVICE declarations. They appear in alphabetical order, numbered from 0 in _valid_nodes and in the driver_info linker list. Add a comment against each declaration, showing the idx value. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dtoc: Document the return value of scan_structs()Simon Glass1-0/+15
Add documentation to this function as well as generate_structs(), where the return value is ultimately passed in. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dtoc: Use a namedtuple for _linksSimon Glass1-4/+12
The use of strings to access a dict is a bit ugly. Use a namedtuple for this instead. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-29dtoc: Extract inner loop from output_node()Simon Glass1-40/+49
This function is very long. Put the inner loop in a separate function to enhance readability. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-09-22binman: Use target-specific tools when cross-compilingAlper Nebi Yasak1-4/+5
Currently, binman always runs the compile tools like cc, objcopy, strip, etc. using their literal name. Instead, this patch makes it use the target-specific versions by default, derived from the tool-specific environment variables (CC, OBJCOPY, STRIP, etc.) or from the CROSS_COMPILE environment variable. For example, the u-boot-elf etype directly uses 'strip'. Trying to run the tests with 'CROSS_COMPILE=i686-linux-gnu- binman test' on an arm64 host results in the '097_elf_strip.dts' test to fail as the arm64 version of 'strip' can't understand the format of the x86 ELF file. This also adjusts some command.Output() calls that caused test errors or failures to use the target versions of the tools they call. After this, patch, an arm64 host can run all tests with no errors or failures using a correct CROSS_COMPILE value. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-08-22dtoc: Add a setup script for PythonSimon Glass1-0/+12
Allow dtoc to be installed by adding a suitable setup.py script. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-29dtoc: remove compatible string aliases supportWalter Lozano2-56/+0
After latest improvements in dtoc, compatible strings are checked against driver and driver alias list to get a valid driver name. With this new feature the list of compatible string aliases seems not useful any more. Signed-off-by: Walter Lozano <walter.lozano@collabora.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-29dtoc: look for compatible string aliases in driver listWalter Lozano3-26/+44
Currently dtoc checks if the first compatible string in a dtb node matches either a driver o driver alias name, without taking into account any other compatible string in the list. In the case that no driver matches the first compatible string a warning is printed and the U_BOOT_DEVICE is not being declared correctly. This patch adds dtoc's support for try all the compatible strings in the dtb node, in an effort to find the correct driver. Signed-off-by: Walter Lozano <walter.lozano@collabora.com> Reviewed-by: Simon Glass <sjg@chromium.org>