-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate DTS 'compatible' based compilation flags #9406
Comments
I think DTS_ is the better choice as this is status information from the DTS. I would expect CONFIG_ to name something a dev can choose on. By the way 'compatible' is available in codegen/edts:
You may access it within device_declare template by |
There are at least two usage scenarios you are adressing:
Waht scenario is your primary target? You can get rid of 1) if you always include all files of a driver and do some guarding by the codegen generated #ifdef mechanism. Not really nice. If you go for 1) the Kconfig vars should be updated to make the available devices known to the Kconfig user configuration process. This should generate the appropriate CONFIG_ for driver file inclusion/exclusion. |
I intend to replace the use of existing flags such as CONFIG_I2C_STM32_V1 which are currently used
Indeed, I prefer to avoid generating code under ifdef and compile it out afterwards.
Well I guess this is not far away from #7302. About 2)
Yes, but I don't want to have codegen bit across the driver core code. To me this should be limited to driver instantiation and configuration. I remind of the "Don't do thing with codegen that could be done by preprocessor"
I don't want to add too much complexity. If 1) and 2) could be solved by the same set of flags (as done today with CONFIG flag) let's go with this. Things could be done in a different ways for sure. Though I think this solution is simple enough to
|
DTS_xxxx describes a hardware characteristic. CONFIG_xxxx describes a choice made by the dev/ user. |
You may add the compatible defines definition in scripts/extract/compatible.py the usual way. |
Hello, It would be nice if some other prefix than Don't know how it's set up at the moment, but what about |
Flags dependency was missing in the initial idea. Dependency with Kconfig settings:Current driver configuration Kconfig flags depends on generic driver type Kconfig symbols (I2C, USB, SPI, ...) |
Thanks for feedbacks and hints. Generated DTS_ flags will have to keep the existing dependency links with existing Kconfig generic symbols (I2C, SPI, USB, ..).
Or an equivalent definitions that allow to reproduce the depedency, a 'C' equivalent being:
Generation should be equivalent in complexity, but this second version should be easier to integrate in build system, and allows the use of DTS_ prefix. |
@carlescufi , @SebastianBoe , this proposal is one possible solution to a) in #7302 (comment) |
@carlescufi, if you have some cycles, your feedback would be welcome. |
I think the proposal here, essentially going back to using DT to decide which driver is built, which was, as @erwango mentions, one of the points I made in here. The reason I think this proposal and @erwango's currently suggested solution makes sense is that it is very unlikely that users will want to select a particular driver for a hardware resource in Kconfig. They might want to enable or disable at the Kconfig level, but not select which driver they want. I think it's much more logical, as this solution proposes, to define this at the DTS level, and the proposal here seems sound to me. A couple of tidbits:
All in all this sounds good to me @erwango |
Implementation of the current feature could use the edts database proposed in #9876 Generated edts.json file contains, among others, following structures: 'compatibles': dict(compatible : sorted list(device-id)), This should be sufficient to generate the list of DTS_ flags and their dependencies |
Is this resolved with merging of #9974 |
Not entirely:
|
Once edts database generation is available, I propose to implement the following approach: In edts, we'll get the following struct:
We should then be able to generate the following:
Then, we'll also need to provide default settings to Kconfig for UART and SPI:
This should be provided in a @ulfalizer @SebastianBoe : any feedback on this proposition? |
Well, my hope is that |
Output of discussion on slack https://zephyrproject.slack.com/archives/C18PLHN8H/p1541680753156800 Proposal: Do not generate #define DT_COMPAT or #define CONFIG_DT_COMPAT Depending on node 'compatible' field: if it's ON, we write the line If it's OFF, we do not write |
Is this issue able to cover adding support for something like this in CMake?
We have confusion from the users about how compatibles bind to drivers and why grep doesn't work. |
I chatted with @tejlmand about doing something like this. I hacked up something that would take the |
@erwango do you still think this is needed? Thinking about this a bit more, Kconfig options whose values can be determined from the devicetree can do this with the features in kconfigfunctions.py.
You can do this with:
Any other features we need can similarly be implemented with kconfigfunctions. Do you have any features covered in this issue that are not already supported in this way? |
This is exactly what we're doing right now :-) I think this point can be closed and new requests should be made on the new base we have today. |
This issue aims at proposing a mechanism that could be used to control code generation aside from dts based code generation.
Basic idea
Generate compilation flags based on device tree 'compatible' property to control drivers compilation
Why this is desirable
Code generation gating was removed from codegen proposal (#6762) as this was not fulfilling buid system expectations. I think a mechanism linked to dts based generation is anyway required (since now removed from pure codegen part).
For example, looking to STM32 I2C drivers (SPI would be another example), we have currently 2 compatibles. Each compatible matches with a variation of the driver made to match different versions of the HW IP.
Driver is made of 4 files:
Compilation of one or the other variation is today controlled with CONFIG_I2C_STM32_V1/V2 flags:
Besides from implementation options in the files:
it will also control which files are compiled:
This allows to embed driver code dedicated to the exact IP variation (unlike Linux drivers that will embed
full code compatible with all the IPs and behave according to the compatible detected at run time).
So, even if device instantiation information is filled from dts, we still need the information of which variation of one driver should be compiled. And it would make sense this is generated at dts parsing,
so that we generate matching compile flags depending on the detected devices compatibles. And this
would not change during the life of the project.
For instance, for following node:
Following flag would be generated:
CONFIG_ST_STM32_I2C_V2 replacing current CONFIG_I2C_STM32_V2, for i2c_stm32 driver compilation (to control which files are compiled and also implementation speficics inside driver code.
Also, if several compatibles are declared, several flags are generated:
#define CONFIG_ST_STM32L4_FLASH_CONTROLLER
#define CONFIG_ST_STM32_FLASH_CONTROLLER
So generic code could be implemented under CONFIG_ST_STM32_FLASH_CONTROLLER while
L4 specific would lie under CONFIG_ST_STM32L4_FLASH_CONTROLLER.
Naming/Prefix:
Note: I've used CONFIG_ as flag prefix, but it could be DTS_ if using _CONFIG creates confusion.
Dependency with Kconfig settings:
Current driver configuration Kconfig flags depends on generic driver type Kconfig symbols (I2C, USB, SPI, ...)
CONFIG_I2C_STM32_V1/V2 depends on I2C_STM32 depending on I2C symbol.
This way, user could compile out I2C driver by deactivating CONFIG_I2C.
Unless this is no more requested for a good reason, this dependency will have to be reproduced somehow.
Current yaml binding property 'id', which provides the generic type of the driver could be used to bind
generated CONFIG_/DTS_ symbols with high level Kconfig symbols.
To me, this would be quite flexible to use and complementary to what we're trying to do with codegen.
Also, this would clean Kconfig files from various
depends on
that are spread accross Kconfig files today (for instance here)Generation of the flags would be done after board dts computation and before compilation (obviously), but could be done before or after code generation by codegen, this is fully independant.
The text was updated successfully, but these errors were encountered: