{"action":"created","issue":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9406","repository_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr","labels_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9406/labels{/name}","comments_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9406/comments","events_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9406/events","html_url":"https://github.com/zephyrproject-rtos/zephyr/issues/9406","id":350022977,"node_id":"MDU6SXNzdWUzNTAwMjI5Nzc=","number":9406,"title":"Generate DTS 'compatible' based compilation flags","user":{"login":"erwango","id":18574308,"node_id":"MDQ6VXNlcjE4NTc0MzA4","avatar_url":"https://avatars1.githubusercontent.com/u/18574308?v=4","gravatar_id":"","url":"https://api.github.com/users/erwango","html_url":"https://github.com/erwango","followers_url":"https://api.github.com/users/erwango/followers","following_url":"https://api.github.com/users/erwango/following{/other_user}","gists_url":"https://api.github.com/users/erwango/gists{/gist_id}","starred_url":"https://api.github.com/users/erwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erwango/subscriptions","organizations_url":"https://api.github.com/users/erwango/orgs","repos_url":"https://api.github.com/users/erwango/repos","events_url":"https://api.github.com/users/erwango/events{/privacy}","received_events_url":"https://api.github.com/users/erwango/received_events","type":"User","site_admin":false},"labels":[{"id":700752411,"node_id":"MDU6TGFiZWw3MDA3NTI0MTE=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/area:%20Build%20System","name":"area: Build System","color":"ededed","default":false},{"id":700888967,"node_id":"MDU6TGFiZWw3MDA4ODg5Njc=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/area:%20Configuration%20System","name":"area: Configuration System","color":"ededed","default":false},{"id":700909632,"node_id":"MDU6TGFiZWw3MDA5MDk2MzI=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/area:%20Device%20Tree","name":"area: Device Tree","color":"ededed","default":false},{"id":383053982,"node_id":"MDU6TGFiZWwzODMwNTM5ODI=","url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/labels/enhancement","name":"enhancement","color":"bfdadc","default":true}],"state":"open","locked":false,"assignee":{"login":"SebastianBoe","id":609230,"node_id":"MDQ6VXNlcjYwOTIzMA==","avatar_url":"https://avatars0.githubusercontent.com/u/609230?v=4","gravatar_id":"","url":"https://api.github.com/users/SebastianBoe","html_url":"https://github.com/SebastianBoe","followers_url":"https://api.github.com/users/SebastianBoe/followers","following_url":"https://api.github.com/users/SebastianBoe/following{/other_user}","gists_url":"https://api.github.com/users/SebastianBoe/gists{/gist_id}","starred_url":"https://api.github.com/users/SebastianBoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SebastianBoe/subscriptions","organizations_url":"https://api.github.com/users/SebastianBoe/orgs","repos_url":"https://api.github.com/users/SebastianBoe/repos","events_url":"https://api.github.com/users/SebastianBoe/events{/privacy}","received_events_url":"https://api.github.com/users/SebastianBoe/received_events","type":"User","site_admin":false},"assignees":[{"login":"SebastianBoe","id":609230,"node_id":"MDQ6VXNlcjYwOTIzMA==","avatar_url":"https://avatars0.githubusercontent.com/u/609230?v=4","gravatar_id":"","url":"https://api.github.com/users/SebastianBoe","html_url":"https://github.com/SebastianBoe","followers_url":"https://api.github.com/users/SebastianBoe/followers","following_url":"https://api.github.com/users/SebastianBoe/following{/other_user}","gists_url":"https://api.github.com/users/SebastianBoe/gists{/gist_id}","starred_url":"https://api.github.com/users/SebastianBoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SebastianBoe/subscriptions","organizations_url":"https://api.github.com/users/SebastianBoe/orgs","repos_url":"https://api.github.com/users/SebastianBoe/repos","events_url":"https://api.github.com/users/SebastianBoe/events{/privacy}","received_events_url":"https://api.github.com/users/SebastianBoe/received_events","type":"User","site_admin":false},{"login":"tbursztyka","id":1608406,"node_id":"MDQ6VXNlcjE2MDg0MDY=","avatar_url":"https://avatars2.githubusercontent.com/u/1608406?v=4","gravatar_id":"","url":"https://api.github.com/users/tbursztyka","html_url":"https://github.com/tbursztyka","followers_url":"https://api.github.com/users/tbursztyka/followers","following_url":"https://api.github.com/users/tbursztyka/following{/other_user}","gists_url":"https://api.github.com/users/tbursztyka/gists{/gist_id}","starred_url":"https://api.github.com/users/tbursztyka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbursztyka/subscriptions","organizations_url":"https://api.github.com/users/tbursztyka/orgs","repos_url":"https://api.github.com/users/tbursztyka/repos","events_url":"https://api.github.com/users/tbursztyka/events{/privacy}","received_events_url":"https://api.github.com/users/tbursztyka/received_events","type":"User","site_admin":false},{"login":"b0661","id":5486823,"node_id":"MDQ6VXNlcjU0ODY4MjM=","avatar_url":"https://avatars0.githubusercontent.com/u/5486823?v=4","gravatar_id":"","url":"https://api.github.com/users/b0661","html_url":"https://github.com/b0661","followers_url":"https://api.github.com/users/b0661/followers","following_url":"https://api.github.com/users/b0661/following{/other_user}","gists_url":"https://api.github.com/users/b0661/gists{/gist_id}","starred_url":"https://api.github.com/users/b0661/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b0661/subscriptions","organizations_url":"https://api.github.com/users/b0661/orgs","repos_url":"https://api.github.com/users/b0661/repos","events_url":"https://api.github.com/users/b0661/events{/privacy}","received_events_url":"https://api.github.com/users/b0661/received_events","type":"User","site_admin":false},{"login":"carlescufi","id":12450381,"node_id":"MDQ6VXNlcjEyNDUwMzgx","avatar_url":"https://avatars3.githubusercontent.com/u/12450381?v=4","gravatar_id":"","url":"https://api.github.com/users/carlescufi","html_url":"https://github.com/carlescufi","followers_url":"https://api.github.com/users/carlescufi/followers","following_url":"https://api.github.com/users/carlescufi/following{/other_user}","gists_url":"https://api.github.com/users/carlescufi/gists{/gist_id}","starred_url":"https://api.github.com/users/carlescufi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlescufi/subscriptions","organizations_url":"https://api.github.com/users/carlescufi/orgs","repos_url":"https://api.github.com/users/carlescufi/repos","events_url":"https://api.github.com/users/carlescufi/events{/privacy}","received_events_url":"https://api.github.com/users/carlescufi/received_events","type":"User","site_admin":false},{"login":"galak","id":16417047,"node_id":"MDQ6VXNlcjE2NDE3MDQ3","avatar_url":"https://avatars2.githubusercontent.com/u/16417047?v=4","gravatar_id":"","url":"https://api.github.com/users/galak","html_url":"https://github.com/galak","followers_url":"https://api.github.com/users/galak/followers","following_url":"https://api.github.com/users/galak/following{/other_user}","gists_url":"https://api.github.com/users/galak/gists{/gist_id}","starred_url":"https://api.github.com/users/galak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/galak/subscriptions","organizations_url":"https://api.github.com/users/galak/orgs","repos_url":"https://api.github.com/users/galak/repos","events_url":"https://api.github.com/users/galak/events{/privacy}","received_events_url":"https://api.github.com/users/galak/received_events","type":"User","site_admin":false}],"milestone":null,"comments":11,"created_at":"2018-08-13T13:10:11Z","updated_at":"2018-09-11T11:42:44Z","closed_at":null,"author_association":"COLLABORATOR","body":"This issue aims at proposing a mechanism that could be used to control code generation aside from dts based code generation.\r\n\r\n### Basic idea\r\n\r\nGenerate compilation flags based on device tree 'compatible' property to control drivers compilation\r\n\r\n### Why this is desirable\r\nCode 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).\r\nFor 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.\r\nDriver is made of 4 files:\r\n```\r\ni2c_ll_stm32_v1.c\r\ni2c_ll_stm32_v2.c\r\ni2c_ll_stm32.c\r\ni2c_ll_stm32.h\r\n```\r\nCompilation of one or the other variation is today controlled with CONFIG_I2C_STM32_V1/V2 flags:\r\n\r\nBesides from implementation options in the files:\r\n```\r\n\t/* Send out messages */\r\n#if defined(CONFIG_I2C_STM32_V1)\r\n\tLL_I2C_Enable(i2c);\r\n#endif\r\n```\r\n it will also control which files are compiled:\r\n```\r\nzephyr_library_sources_ifdef(CONFIG_I2C_STM32_V1\r\n\ti2c_ll_stm32_v1.c\r\n\ti2c_ll_stm32.c\r\n\t)\r\nzephyr_library_sources_ifdef(CONFIG_I2C_STM32_V2\r\n\ti2c_ll_stm32_v2.c\r\n\ti2c_ll_stm32.c\r\n\t)\r\n```\r\nThis allows to embed driver code dedicated to the exact IP variation (unlike Linux drivers that will embed\r\nfull code compatible with all the IPs and behave according to the compatible detected at run time).\r\n\r\nSo, 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,\r\nso that we generate matching compile flags depending on the detected devices compatibles. And this \r\nwould not change during the life of the project.\r\n\r\nFor instance, for following node:\r\n```\r\n\ti2c2: i2c@40005800 {\r\n\t\tcompatible = \"st,stm32-i2c-v2\";\r\n```\r\nFollowing flag would be generated:\r\n```\r\n#define CONFIG_ST_STM32_I2C_V2\r\n```\r\nCONFIG_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.\r\n\r\nAlso, if several compatibles are declared, several flags are generated:\r\n```\r\n\tflash-controller@40022000 {\r\n\t\tcompatible = \"st,stm32l4-flash-controller\", \"st,stm32-flash-controller\";\r\n\t\tlabel = \"FLASH_CTRL\";\r\n```\r\n#define CONFIG_ST_STM32L4_FLASH_CONTROLLER\r\n#define CONFIG_ST_STM32_FLASH_CONTROLLER\r\n\r\nSo generic code could be implemented under CONFIG_ST_STM32_FLASH_CONTROLLER while \r\nL4 specific would lie under CONFIG_ST_STM32L4_FLASH_CONTROLLER.\r\n\r\n### Naming/Prefix:\r\nNote: I've used CONFIG_ as flag prefix, but it could be DTS_ if using _CONFIG creates confusion.\r\n\r\n### Dependency with Kconfig settings:\r\nCurrent driver configuration Kconfig flags depends on generic driver type Kconfig symbols (I2C, USB, SPI, ...)\r\nCONFIG_I2C_STM32_V1/V2 depends on I2C_STM32 depending on I2C symbol.\r\nThis way, user could compile out I2C driver by deactivating CONFIG_I2C. \r\nUnless this is no more requested for a good reason, this dependency will have to be reproduced somehow.\r\nCurrent yaml binding property 'id', which provides the generic type of the driver could be used to bind\r\ngenerated CONFIG_/DTS_ symbols with high level Kconfig symbols.\r\n\r\nTo me, this would be quite flexible to use and complementary to what we're trying to do with codegen.\r\nAlso, this would clean Kconfig files from various `depends on` that are spread accross Kconfig files today (for instance [here](https://github.com/zephyrproject-rtos/zephyr/blob/7c487ba04aed36b00e30d4d4e5c0159ab481bb2d/drivers/i2c/Kconfig.stm32#L26))\r\n\r\nGeneration 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."},"comment":{"url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/comments/420244116","html_url":"https://github.com/zephyrproject-rtos/zephyr/issues/9406#issuecomment-420244116","issue_url":"https://api.github.com/repos/zephyrproject-rtos/zephyr/issues/9406","id":420244116,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDI0NDExNg==","user":{"login":"erwango","id":18574308,"node_id":"MDQ6VXNlcjE4NTc0MzA4","avatar_url":"https://avatars1.githubusercontent.com/u/18574308?v=4","gravatar_id":"","url":"https://api.github.com/users/erwango","html_url":"https://github.com/erwango","followers_url":"https://api.github.com/users/erwango/followers","following_url":"https://api.github.com/users/erwango/following{/other_user}","gists_url":"https://api.github.com/users/erwango/gists{/gist_id}","starred_url":"https://api.github.com/users/erwango/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erwango/subscriptions","organizations_url":"https://api.github.com/users/erwango/orgs","repos_url":"https://api.github.com/users/erwango/repos","events_url":"https://api.github.com/users/erwango/events{/privacy}","received_events_url":"https://api.github.com/users/erwango/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T11:42:44Z","updated_at":"2018-09-11T11:42:44Z","author_association":"COLLABORATOR","body":"Implementation of the current feature could use the edts database proposed in #9876\r\n\r\nGenerated edts.json file contains, among others, following structures:\r\n\r\n   'compatibles':  dict(compatible : sorted list(device-id)),\r\n   'device-types': dict(device-types : sorted list(compatible)),\r\n\r\nThis should be sufficient to generate the list of DTS_<COMPATIBLES> flags and their dependencies\r\non Zephyr generic device types (USB, SPI, ..)"}}
{"actor":{"display_login":"erwango"}}