aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc
AgeCommit message (Collapse)AuthorFilesLines
2021-04-29dtoc: Correct dtoc output when testingSimon Glass2-53/+22
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>
2021-04-06dtoc: Improve handling of reg propertiesSimon Glass4-3/+73
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>
2021-04-06dtoc: Adjust detection of 64-bit propertiesSimon Glass2-6/+6
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>
2021-04-06dtoc: Show driver warnings once at the endSimon Glass4-28/+33
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>
2021-03-27dtoc: Add new check that offsets are correctSimon Glass2-3/+40
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 Glass2-9/+51
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: Add a subnode test for multiple nodesSimon Glass2-12/+34
Add a new test that adds a subnode alongside an existing one, as well as adding properties to a subnode. This will expand to adding multiple subnodes in future patches. Put a node after the one we are adding to so we can check that things sync correctly. The testAddNode() test should be in the TestNode class since it is a node test, so move it. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27dtoc: Tweak ordering of fdt-offsets refreshingSimon Glass1-3/+4
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 Glass1-3/+7
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 Glass2-3/+3
Add the node name too so it is easy to see which node failed. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-26dtoc: Only generate the required filesSimon Glass2-5/+20
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>
2021-03-22dtoc: Drop use of DECL() macrosSimon Glass2-36/+36
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>
2021-03-22dtoc: Generate device instancesSimon Glass2-15/+480
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>
2021-03-22dtoc: Generate uclass devicesSimon Glass2-13/+244
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>
2021-03-22dtoc: Generate a summary in the dt-plat.c fileSimon Glass2-35/+169
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>
2021-03-22dtoc: Tidy up the list of supported phandle propertiesSimon Glass1-7/+21
For now dtoc only supports a hard-coded list of phandle properties, to avoid any situation where it makes a mistake in its determination. Make this into a constant dict, recording both the phandle property name and the associated #cells property in the target node. This makes it easier to find and modify. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Don't generate platform data with instantiationSimon Glass2-13/+75
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>
2021-03-22dtoc: Add support for decl fileSimon Glass2-7/+120
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>
2021-03-22dtoc: Add an option for device instantiationSimon Glass3-22/+36
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>
2021-03-22dtoc: Support processing the root nodeSimon Glass4-20/+59
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>
2021-03-22dtoc: Set up the uclasses that are usedSimon Glass4-18/+119
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>
2021-03-22dtoc: Assign a sequence number to each nodeSimon Glass2-15/+46
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>
2021-03-22dtoc: Detect drivers only at the start of start of lineSimon Glass1-2/+2
If a driver declaration is included in a comment, dtoc currently gets confused. Update the parser to only consider declarations that begin at the start of a line. Since multi-line comments begin with an asterisk, this avoids the problem. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Read aliases for uclassesSimon Glass7-3/+345
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>
2021-03-22dtoc: Warn of duplicate driversSimon Glass2-1/+122
If drivers have the same name then we cannot distinguish them. This only matters if the driver is actually used by dtoc, but in that case, issue a warning. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Process driver aliases along with driversSimon Glass2-11/+9
Instead of using a separate step for this processing, handle it while scanning its associated driver. This allows us to drop the code coverage exception in this case. Note that only files containing drivers are scanned by dtoc, so aliases declared in a file that doesn't hold a driver will not be noticed. It would be confusing to put them anywhere other than in the driver that they relate to, but update the documentation to say this explicitly, just in case. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Support headers needed for driversSimon Glass2-0/+11
Typically dtoc can detect the header file needed for a driver by looking for the structs that it uses. For example, if a driver as a .priv_auto that uses 'struct serial_priv', then dtoc can search header files for the definition of that struct and use the file. In some cases, enums are used in drivers, typically with the .data field of struct udevice_id. Since dtoc does not support searching for these, add a way to tell dtoc which header to use. This works as a macro included in the driver definition. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Support tracking the phase of U-BootSimon Glass5-12/+31
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>
2021-03-22dtoc: Track nodes which are actually usedSimon Glass4-4/+37
Mark all nodes that are actually used, so we can perform extra checks on them. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Process nodes to set up required propertiesSimon Glass3-0/+124
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>
2021-03-22dtoc: Make use of node propertiesSimon Glass1-26/+19
Now that we have these available, use them instead of recalculating things each time. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Add some extra properties to nodesSimon Glass1-0/+37
It is convenient to attach drivers, etc. to nodes so that we can use the Node object as the main data structure in this module. Add a function which adds the new properties, along with documentation. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Rename sandbox_i2c_test and sandbox_pmic_testSimon Glass2-8/+8
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>
2021-03-22dtoc: Move test files into a test/ directorySimon Glass23-12/+24
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>
2021-03-22dtoc: Support scanning of structs in header filesSimon Glass2-3/+128
Drivers can have private / platform data contained in structs and these struct definitions are generally kept in header files. In order to generate build-time devices, dtoc needs to generate code that declares the data contained in those structs. This generated code must include the relevant header file, to avoid a build error. We need a way for dtoc to scan header files for struct definitions. Then, when it wants to generate code that uses a struct, it can make sure it includes the correct header file, first. Add a parser for struct information, similar to drivers. Keep a dict of the structs that were found. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Support scanning of uclassesSimon Glass2-0/+177
Uclasses can have per-device private / platform data so dtoc needs to scan these drivers. This allows it to find out the size of this data so it can be allocated a build time. Add a parser for uclass information, similar to drivers. Keep a dict of the uclasses that were found. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dtoc: Collect priv/plat struct info from driversSimon Glass2-2/+55
In order to output variables to hold the priv/plat information used by each device, dtoc needs to know the struct for each. With this, it can declare this at build time: u8 xxx_priv [sizeof(struct <name>)]; Collect the various struct names from the drivers. Signed-off-by: Simon Glass <sjg@chromium.org>
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-30binman: 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-30dtoc: 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>