aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc/test_dtoc.py
Commit message (Collapse)AuthorAgeFilesLines
* dtoc: Use pathlib to find the test directorySimon Glass2023-03-081-2/+4
| | | | | | | Update this so that the directory being used is declared at the top of the file. Use pathlib as it seems to be more modern. Signed-off-by: Simon Glass <sjg@chromium.org>
* patman: Move library functions into a library directorySimon Glass2023-03-081-2/+2
| | | | | | | | | | | The patman directory has a number of modules which are used by other tools in U-Boot. This makes it hard to package the tools using pypi since the common files must be copied along with the tool that uses them. To address this, move these files into a new u_boot_pylib library. This can be packaged separately and listed as a dependency of each tool. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Add a way to read a phandle with paramsSimon Glass2023-01-181-0/+3
| | | | | | | Add a function to read a phandle and associated name and offset. This is useful for binman. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Support accessing core tagsSimon Glass2022-06-281-0/+4
| | | | | | | | | | | | | | | | | | | At present tag numbers are only allocated for non-core data, meaning that the 'core' data, like priv and plat, are accessed through dedicated functions. For debugging and consistency it is convenient to use tags for this 'core' data too. Add support for this, with new tag numbers and functions to access the pointer and size for each. Update one of the test drivers so that the uclass-private data can be tested here. There is some code duplication with functions like device_alloc_priv() but this is not addressed for now. At some point, some rationalisation may help to reduce code size, but more thought it needed on that. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Switch the testbus driver to use a new structSimon Glass2022-06-281-1/+1
| | | | | | | | At present this driver uses 'priv' struct to hold 'plat' data, which is confusing. The contents of the strct don't matter, since only dtoc is using it. Create a new struct with the correct name. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Correct pylint errorsSimon Glass2022-03-021-3/+3
| | | | | | Fix pylint errors in this directory. Signed-off-by: Simon Glass <sjg@chromium.org>
* patman: Convert camel case in tools.pySimon Glass2022-02-091-38/+38
| | | | | | Convert this file to snake case and update all files which use it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Add support for reading 64-bit intsSimon Glass2021-12-021-0/+2
| | | | | | Add functions to read a 64-bit integer property from the devicetree. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Support widening a bool valueSimon Glass2021-08-011-0/+3
| | | | | | | | | | | | | 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>
* dtoc: Fix widening an int array to an intSimon Glass2021-08-011-3/+3
| | | | | | | | | | | 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>
* dtoc: Check that a parent is not missingSimon Glass2021-07-151-0/+10
| | | | | | | | | | | | | With of-platdata-inst we want to set up a reference to each devices' parent device, if there is one. If we find that the device has a parent (i.e. is not a root node) but it is not in the list of devices being written, then we cannot create the reference. Report an error in this case, since it indicates that the parent node is either missing a compatible string, is disabled, or perhaps does not have any properties because it was not tagged for SPL. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Correct dtoc output when testingSimon Glass2021-04-291-30/+21
| | | | | | | | | | | | | | | | | | | | | At present each invocation of run_steps() updates OUTPUT_FILES_COMMON, since it does not make a copy of the dict. This is fine for a single invocation, but for tests, run_steps() is invoked many times. As a result it may include unwanted items from the previous run, if it happens that a test runs twice on the same CPU. The problem has not been noticied previously, as there are few enough tests and enough CPUs that is is rare for the 'wrong' combination of tests to run together. Fix this by making a copy of the dict, before updating it. Update the tests to suit, taking account of the files that are no-longer generated. With this fix, we no-longer generate files which are not needed for a particular state of OF_PLATDATA_INST, so the check_instantiate() function is not needed anymore. It has become dead code and so fails the code-coverage test (dtoc -T). Remove it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Improve handling of reg propertiesSimon Glass2021-04-061-1/+16
| | | | | | | | | | | | | This existing code assumes that a reg property is larger than one cell, but this is not always the case. Fix this assumption. Also if a node's parent is missing the #address-cells and #size-cells properties we use 2 as a default for each. But this should not happen in practice. More likely the properties were removed for SPL due to there being no 'u-boot,dm-pre-reloc' property, or similar. Add a warning for this as the failure can be very confusing. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Adjust detection of 64-bit propertiesSimon Glass2021-04-061-3/+3
| | | | | | | | At present an empty size is considered to be a 64-bit value. This does not seem useful and wastes space. Limit the 64-bit detection to where one or both of the addr/size is two cells or more. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Show driver warnings once at the endSimon Glass2021-04-061-1/+1
| | | | | | | | | | At present warnings are shown as soon as they are discovered in the source scannner. But the function that detects them may be called multiple times. Collect all the warnings and show them at the end. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Only generate the required filesSimon Glass2021-03-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At present all possible files are generated, even if some of them just have a header and an empty body. It is better to generate only the files that are needed, so that the two types of build (based on the setting of OF_PLATDATA_INST) can be mutually exclusive. This is intended to fix a strange problem sometimes found with CI: Building current source for 1 boards (1 thread, 40 jobs per thread) sandbox: + sandbox_spl +drivers/built-in.o: In function `dm_setup_inst': +drivers/core/root.c:135: undefined reference to `_u_boot_list_2_udevice_2_root' +dts/dt-uclass.o:(.u_boot_list_2_uclass_2_serial+0x10): undefined reference to `_u_boot_list_2_udevice_2_serial' ... This likely happens when switching from !OF_PLATDATA_INST to OF_PLATDATA_INST since running 'make xxx_defconfig" does not currently cause any change in which files are generated. With !OF_PLATDATA_INST the dt-device.c file has no declarations and this is assumed to be the starting state. The error above seems to indicate that, after changing to OF_PLATDATA_INST, the dt-uclass.c file is regenerated but the dt-device.c files is not. This does not seem possible from the relevant Makefile.spl rule: u-boot-spl-platdata := $(obj)/dts/dt-plat.o $(obj)/dts/dt-uclass.o $(obj)/dts/dt-device.o cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all include/generated/dt-structs-gen.h $(u-boot-spl-platdata_c) &: \ $(obj)/$(SPL_BIN).dtb @[ -d $(obj)/dts ] || mkdir -p $(obj)/dts $(call if_changed,dtoc) It seems that this cannot regenerate dt-uclass.c without dt-device.c since 'dtoc all' is used. So here the trail ends for now. In any case it seems better to generate files that are uses and not bother with those that serve no purpose. So update dtoc to do this automatically. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Drop use of DECL() macrosSimon Glass2021-03-221-32/+32
| | | | | | | | We can use extern instead, so let's drop these macros. It adds one more thing to learn about and doesn't make the code any clearer. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Generate device instancesSimon Glass2021-03-221-10/+317
| | | | | | | | | | | | | Add support for generating a file containing udevice instances. This avoids the need to create these at run time. Update a test uclass to include a 'per_device_plat_auto' member, to increase test coverage. Add another tab to the driver_info output so it lines up nicely like the device-instance output. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Generate uclass devicesSimon Glass2021-03-221-13/+151
| | | | | | | | | | Add support for generating a file containing uclass instances. This avoids the need to create these at run time. Update a test uclass to include a 'priv_auto' member, to increase test coverage. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Generate a summary in the dt-plat.c fileSimon Glass2021-03-221-32/+152
| | | | | | | | | Add a summary to the top of the generated code, to make it easier to see what the file contains. Also add a tab to .plat so that its value lines up with the others. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Don't generate platform data with instantiationSimon Glass2021-03-221-10/+43
| | | | | | | | | | | This file is not used when instantiating devices. Update dtoc to skip generating its contents and just add a comment instead. Also it is useful to see the driver name and parent for each device. Update the file to show that information, to avoid updating the same tests twice. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Add support for decl fileSimon Glass2021-03-221-7/+84
| | | | | | | Add an option to generate the declaration file, which declares all drivers and uclasses, so references can be used in the code. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Add an option for device instantiationSimon Glass2021-03-221-15/+22
| | | | | | | Add an option to instantiate devices at build time. For now this just parses the option and sets up a few parameters. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Support processing the root nodeSimon Glass2021-03-221-2/+21
| | | | | | | | | | | The device for the root node is normally bound by driver model on init. With devices being instantiated at build time, we must handle the root device also. Add support for processing the root node, which may not have a compatible string. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Set up the uclasses that are usedSimon Glass2021-03-221-2/+27
| | | | | | | | | | | | | | | | We only care about uclasses that are actually used. This is determined by the drivers that use them. Check all the used drivers and build a list of 'valid' uclasses. Also add references to the uclasses so we can generate C code that uses them. Attach a uclass to each valid driver. For the tests, now that we have uclasses we must create an explicit test for the case where a node does not have one. This should only happen if the source code does not build, or the source-code scanning fails to find it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Assign a sequence number to each nodeSimon Glass2021-03-221-0/+6
| | | | | | | | | | | | Now that we have the alias information we can assign a sequence number to each device in the uclass. Store this in the node associated with each device. This requires renaming the sandbox test drivers to have the right name. Note that test coverage is broken with this patch, but fixed in the next one. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Read aliases for uclassesSimon Glass2021-03-221-2/+54
| | | | | | | Scan the aliases in the device tree to establish the number of devices within each uclass, and the sequence number of each. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Support tracking the phase of U-BootSimon Glass2021-03-221-8/+8
| | | | | | | | | | | | | | | | | | | | U-Boot operates in several phases, typically TPL, SPL and U-Boot proper. The latter does not use dtoc. In some rare cases different drivers are used for two phases. For example, in TPL it may not be necessary to use the full PCI subsystem, so a simple driver can be used instead. This works in the build system simply by compiling in one driver or the other (e.g. PCI driver + uclass for SPL; simple_bus for TPL). But dtoc has no way of knowing which code is compiled in for which phase, since it does not inspect Makefiles or dependency graphs. So to make this work for dtoc, we need to be able to explicitly mark drivers with their phase. This is done by adding an empty macro to the driver. Add support for this in dtoc. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Track nodes which are actually usedSimon Glass2021-03-221-0/+11
| | | | | | | Mark all nodes that are actually used, so we can perform extra checks on them. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Process nodes to set up required propertiesSimon Glass2021-03-221-0/+76
| | | | | | | | | Add logic to assign property values to nodes as required by dtoc. The references allow nodes to refer to each other in C code. The macros used by dtoc are not yet defined in driver model. They will be added along with the actual driver model implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Rename sandbox_i2c_test and sandbox_pmic_testSimon Glass2021-03-221-6/+6
| | | | | | | These have '_test' suffixes which are not present on the drivers in the source code. Drop the suffixes to avoid a mismatch when scanning. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Move test files into a test/ directorySimon Glass2021-03-221-1/+1
| | | | | | | | | | It is confusing to have the test files in the same places as the implementation. Move them into a separate directory. Add a helper function for test_dtoc, to avoid repeating the same path. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Save scan information across test runsSimon Glass2021-03-221-7/+33
| | | | | | | | | | | | | | | 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>
* dtoc: Move src_scan tests to a separate fileSimon Glass2021-01-051-73/+0
| | | | | | | 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>
* dtoc: Split source-code scanning to a separate fileSimon Glass2021-01-051-7/+7
| | | | | | | | | | | | | | | | | 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>
* dtoc: Drop dm_populate_phandle_data()Simon Glass2021-01-051-22/+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>
* dtoc: Output nodes in orderSimon Glass2021-01-051-32/+32
| | | | | | | | | | | | | | | | | 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>
* dtoc: Allow specifying the base directory for testsSimon Glass2021-01-051-0/+34
| | | | | | | | | | | | | 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>
* dtoc: Rename dt-platdata.c to dt-plat.cSimon Glass2021-01-051-2/+2
| | | | | | | 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>
* dtoc: Add a header comment to each generated fileSimon Glass2021-01-051-2/+4
| | | | | | | | | | | 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>
* dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()Simon Glass2021-01-051-33/+33
| | | | | | | | | | | | | | | | | | | | 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>
* dtoc: Add an 'all' commandSimon Glass2021-01-051-3/+37
| | | | | | | | | | | | | 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>
* dtoc: Allow outputing to multiple filesSimon Glass2021-01-051-0/+8
| | | | | | | | 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>
* dtoc: Allow providing a directory to write files toSimon Glass2021-01-051-7/+7
| | | | | | | | | | | | | | 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>
* dtoc: Test the stdout outputSimon Glass2021-01-051-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>
* dtoc: Use None to mean stdoutSimon Glass2021-01-051-1/+1
| | | | | | | 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>
* dtoc: Tidy up pylint warnings in testSimon Glass2021-01-051-71/+85
| | | | | | Tidy up this file to reduce the number of pylint warnings. Signed-off-by: Simon Glass <sjg@chromium.org>
* dtoc: Convert _drivers to a dictSimon Glass2021-01-051-0/+10
| | | | | | | | 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>
* sandbox: Drop unnecessary test nodeSimon Glass2021-01-051-12/+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>
* dm: Rename 'platdata_size' to 'plat_size'Simon Glass2020-12-131-33/+33
| | | | | | Rename this to be consistent with the change from 'platdata'. Signed-off-by: Simon Glass <sjg@chromium.org>