-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[RFC] Template prototype using jinja2 templating engine #10957
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
Closed
evenl
wants to merge
43
commits into
zephyrproject-rtos:topic-EDTS
from
evenl:template_prototype_with_updated_edts
Closed
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
85d2c5f
dts/bindings: Add yaml field 'type' for generic zephyr type
erwango 09c454a
scripts/dts: Introduce edts.json generation
erwango 05b4673
scripts: extract_dts_includes.py: create EDTS database for codegen
b0661 52bb995
scripts: extract_dts_includes.py: extract compatible to EDTS database
erwango 53c8b4f
scripts: edts: Add api to get device_ids based on compat
galak 8d0103b
scripts: extract_dts_includes.py: extract reg to EDTS database
b0661 1b1e537
scripts: extract_dts_includes.py: extract interrupts to EDTS database
galak ca29ae4
scripts: extract_dts_includes.py: default extract to EDTS database
b0661 d9ed40d
scripts: edts: Add api to get device_id based on label
galak ccbe71d
scripts: extract_dts_includes.py: extract clocks to EDTS database
b0661 fa08574
scripts: extract_dts_includes.py: extract heuristics to EDTS database
erwango 24ac2d7
scripts: extract_dts_includes: extract gpios to EDTS database
galak bee4464
scripts: edts: Add api to get list of compatiables
galak 530e209
scrpits/dts: edts: add alias treatment for edts generation
erwango 942571b
scripts: edts: Add api to get list of aliases
galak 4a608dd
scripts/dts: edts: insert chosen to edts database
erwango 1c04386
scripts: edts: Add api to get list of chosen
galak 59a0a49
scripts/dts: edts: insert 'status' node property
erwango 95632b3
scripts/edts: inject device-type in edts database.
erwango 56cd99c
scripts: edts: Add api to get list of device types
galak 22abc97
scripts: edts: Fill-in 'controllers' views
erwango 5a45184
scripts: edts: Add api to get list of controllers
galak 9bf02ad
scripts/dts: edts: Get children at their parent's
erwango fc77de0
scripts/dts: edts: generate a unique id for each device
erwango b4a978c
dts: bindings: Add basic bindings dedicated to dts validation
erwango 7a11a57
boards: Add refboard dummy board
erwango e683acf
scripts/dts: provide edts sanity check scripts
erwango a00ffd9
edtsdevice: Add Regs upport
galak 2d66ce4
Add EDTSDevice irq support
galak a865c61
Add unique id
galak b09a1a5
simple tests
galak dfae97c
test
galak da1afbc
REG test
galak 8216f39
edts: reg testing - hack
galak 8ab7823
test edtsdevice irq
galak 7473334
Switched from COG to jinja2 based code generation. Ported instantiation
evenl 4cf71f6
Modifying codegen documentation
evenl 7654039
Updated prototype to generate a .h file which is included in a .c file
evenl 6eb8972
Template updates
evenl 2c4b286
Exposing EDTS interfaces
evenl 2410b6e
Moved generation parameters
evenl d23f1db
Obsoleted the meta file
evenl d4c8c5b
Renamed tool to JinjaGen
evenl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| config BOARD_REFBOARD | ||
| bool "Refsoc Board" | ||
| select HAS_DTS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| if BOARD_REFBOARD | ||
|
|
||
| config BOARD | ||
| default "refboard" | ||
|
|
||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright (c) 2018 Linaro Limited | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /dts-v1/; | ||
|
|
||
| #include <refsoc/refsoc.dtsi> | ||
|
|
||
| / { | ||
| model = "Reference SoC board"; | ||
| compatible = "refsoc,refboard"; | ||
|
|
||
| chosen { | ||
| zephyr,console = &uart1; | ||
| }; | ||
|
|
||
| leds { | ||
| compatible = "gpio-leds"; | ||
| green_led_1: led_1 { | ||
| gpios = <&gpioa 1 GPIO_INT_ACTIVE_HIGH>; | ||
| label = "USR1 LED"; | ||
| }; | ||
| green_led_2: led_2 { | ||
| gpios = <&gpioa 2 GPIO_INT_ACTIVE_HIGH>; | ||
| label = "USR2 LED"; | ||
| }; | ||
| }; | ||
|
|
||
| gpio_keys { | ||
| compatible = "gpio-keys"; | ||
| user_button_1: button_1 { | ||
| label = "USR1 SW"; | ||
| gpios = <&gpiob 2 GPIO_INT_ACTIVE_LOW>; | ||
| }; | ||
| user_button_2: button_2 { | ||
| label = "USR2 SW"; | ||
| gpios = <&gpiob 2 GPIO_INT_ACTIVE_LOW>; | ||
| }; | ||
| }; | ||
|
|
||
| aliases { | ||
| led0 = &green_led_1; | ||
| led1 = &green_led_2; | ||
| sw0 = &user_button_1; | ||
| sw1 = &user_button_2; | ||
| }; | ||
| }; | ||
|
|
||
| &gpioa { | ||
| status = "ok"; | ||
| }; | ||
|
|
||
| &gpiob { | ||
| status = "ok"; | ||
| }; | ||
|
|
||
| &uart1 { | ||
| status = "ok"; | ||
| current-speed = <115200>; | ||
| }; | ||
|
|
||
| &uart2 { | ||
| status = "ok"; | ||
| current-speed = <9600>; | ||
| }; | ||
|
|
||
| &i2c1 { | ||
| status = "ok"; | ||
| clock-frequency = <I2C_BITRATE_FAST>; | ||
|
|
||
| refsoc-sensor@1e { | ||
| compatible = "refsoc,sensor-i2c"; | ||
| reg = <0x1e>; | ||
| label = "SENSOR_I2C_1_1E"; | ||
| }; | ||
|
|
||
| refsoc-sensor@1f { | ||
| compatible = "refsoc,sensor-i2c"; | ||
| reg = <0x1f>; | ||
| label = "SENSOR_I2C_1_1F"; | ||
| }; | ||
| }; | ||
|
|
||
| &i2c2 { | ||
| status = "ok"; | ||
| clock-frequency = <I2C_BITRATE_FAST>; | ||
|
|
||
| sensor-i2c@1e { | ||
| compatible = "refsoc,sensor-i2c"; | ||
| reg = <0x1e>; | ||
| label = "SENSOR_I2C_2_1E"; | ||
| }; | ||
|
|
||
| sensor-i2c@1f { | ||
| compatible = "refsoc,sensor-i2c"; | ||
| reg = <0x1f>; | ||
| label = "SENSOR_I2C_2_1F"; | ||
| }; | ||
| }; | ||
|
|
||
| &spi1 { | ||
| status = "ok"; | ||
|
|
||
| cs-gpios = <&gpiob 1 0>; | ||
|
|
||
| sensor-spi@0 { | ||
| compatible = "refsoc,sensor-spi"; | ||
| reg = <0>; | ||
| reset-gpios = <&gpiob 2 0>; | ||
| irq-gpios = <&gpiob 3 0>; | ||
| spi-max-frequency = <2000000>; | ||
| label = "SENSOR_SPI_0"; | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_BOARD_REFBOARD=y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,6 +344,17 @@ function(generate_inc_file_for_gen_target | |
| add_dependencies(${target} ${gen_target}) | ||
| endfunction() | ||
|
|
||
| function(get_unique_generated_target_name | ||
| generated_file # The generated file | ||
| generated_target_name # the unique name | ||
| ) | ||
| string(RANDOM LENGTH 8 random_chars) | ||
| get_filename_component(basename ${generated_file} NAME) | ||
| string(REPLACE "." "_" basename ${basename}) | ||
| string(REPLACE "@" "_" basename ${basename}) | ||
| set(generated_target_name "gen_${basename}_${random_chars}" PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| function(generate_inc_file_for_target | ||
| target # The cmake target that depends on the generated file | ||
| source_file # The source file to be converted to hex | ||
|
|
@@ -353,22 +364,142 @@ function(generate_inc_file_for_target | |
| # Ensure 'generated_file' is generated before 'target' by creating a | ||
| # 'custom_target' for it and setting up a dependency between the two | ||
| # targets | ||
| get_unique_generated_target_name(${generated_file} generated_target_name) | ||
| add_custom_target(${generated_target_name} DEPENDS ${generated_file}) | ||
| generate_inc_file_for_gen_target(${target} ${source_file} ${generated_file} | ||
| ${generated_target_name} ${ARGN}) | ||
| endfunction() | ||
|
|
||
| # But first create a unique name for the custom target | ||
| string( | ||
| RANDOM | ||
| LENGTH 8 | ||
| random_chars | ||
| function(target_sources_jinjagen | ||
|
||
| target # The cmake target that depends on the generated file | ||
| ) | ||
| set(options) | ||
| set(oneValueArgs JINJAGEN_OUTPUT) | ||
| set(multiValueArgs JINJAGEN_DEFINES SEARCH_PATH) | ||
|
|
||
| cmake_parse_arguments(JINJAGEN "${options}" "${oneValueArgs}" | ||
| "${multiValueArgs}" ${ARGN}) | ||
|
|
||
| # prepend -D to all defines | ||
| string(REGEX REPLACE "([^;]+)" "-D;\\1" | ||
| JINJAGEN_JINJAGEN_DEFINES "${JINJAGEN_JINJAGEN_DEFINES}") | ||
|
|
||
| string(REGEX REPLACE "([^;]+)" "-I;\\1" | ||
| JINJAGEN_SEARCH_PATH "${JINJAGEN_SEARCH_PATH}") | ||
|
|
||
| # Get all the files that make up jinjagen for dependency reasons | ||
| file(GLOB JINJAGEN_SOURCES | ||
| ${ZEPHYR_BASE}/scripts/jinjagen/*.py | ||
| ${ZEPHYR_BASE}/scripts/render_template.py) | ||
|
|
||
| message(STATUS "Will generate for target ${target}") | ||
| # Generated file must be generated to the current binary directory. | ||
| # Otherwise this would trigger CMake issue #14633: | ||
| # https://gitlab.kitware.com/cmake/cmake/issues/14633 | ||
| foreach(arg ${JINJAGEN_UNPARSED_ARGUMENTS}) | ||
| string(REGEX REPLACE "\\.[^.]*$" "" FILE_WITHOUT_EXT ${arg}) | ||
| if(IS_ABSOLUTE ${arg}) | ||
| set(template_file ${arg}) | ||
| string(COMPARE EQUAL ${JINJAGEN_JINJAGEN_OUTPUT} "" result) | ||
| if(result) | ||
| set(generated_file ${CMAKE_CURRENT_BINARY_DIR}/${FILE_WITHOUT_EXT}) | ||
| else() | ||
| set(generated_file ${CMAKE_CURRENT_BINARY_DIR}/${JINJAGEN_JINJAGEN_OUTPUT}) | ||
| endif() | ||
| else() | ||
| set(template_file ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) | ||
| set(generated_file ${CMAKE_CURRENT_BINARY_DIR}/${FILE_WITHOUT_EXT}) | ||
| endif() | ||
| get_filename_component(template_dir ${template_file} DIRECTORY) | ||
|
|
||
| get_filename_component(basename ${generated_file} NAME) | ||
| string(REPLACE "." "_" basename ${basename}) | ||
| string(REPLACE "@" "_" basename ${basename}) | ||
| include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) | ||
|
|
||
| set(generated_target_name "gen_${basename}_${random_chars}") | ||
| if(IS_DIRECTORY ${template_file}) | ||
| message(FATAL_ERROR "target_sources_codegen() was called on a directory") | ||
| endif() | ||
|
|
||
| add_custom_target(${generated_target_name} DEPENDS ${generated_file}) | ||
| generate_inc_file_for_gen_target(${target} ${source_file} ${generated_file} ${generated_target_name} ${ARGN}) | ||
| # Generate file from template | ||
| message(STATUS " from '${template_file}'") | ||
| message(STATUS " to '${generated_file}'") | ||
| add_custom_command( | ||
| COMMENT "JinjaGen ${generated_file}" | ||
| OUTPUT ${generated_file} | ||
| MAIN_DEPENDENCY ${template_file} | ||
| DEPENDS | ||
| ${JINJAGEN_SOURCES} | ||
| COMMAND | ||
| ${PYTHON_EXECUTABLE} | ||
| ${ZEPHYR_BASE}/scripts/render_template.py | ||
| ${JINJAGEN_JINJAGEN_DEFINES} | ||
| ${JINJAGEN_SEARCH_PATH} | ||
| -D "PROJECT_NAME=${PROJECT_NAME}" | ||
| -D "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}" | ||
| -D "PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}" | ||
| -D "CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}" | ||
| -D "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" | ||
| -D "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}" | ||
| -D "CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" | ||
| -D "CMAKE_CURRENT_LIST_DIR=${CMAKE_CURRENT_LIST_DIR}" | ||
| -D "CMAKE_FILES_DIRECTORY=${CMAKE_FILES_DIRECTORY}" | ||
| -D "CMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME}" | ||
| -D "CMAKE_SYSTEM=${CMAKE_SYSTEM}" | ||
| -D "CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}" | ||
| -D "CMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}" | ||
| -D "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}" | ||
| -D "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}" | ||
| -D "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" | ||
| -D "CMAKE_COMPILER_IS_GNUCC=${CMAKE_COMPILER_IS_GNUCC}" | ||
| -D "CMAKE_COMPILER_IS_GNUCXX=${CMAKE_COMPILER_IS_GNUCXX}" | ||
| -D "GENERATED_DTS_BOARD_H=${GENERATED_DTS_BOARD_H}" | ||
| -D "GENERATED_DTS_BOARD_CONF=${GENERATED_DTS_BOARD_CONF}" | ||
| -D "GENERATED_EDTS=${GENERATED_EDTS}" | ||
| -I "${ZEPHYR_BASE}/templates" | ||
| --input "${template_file}" | ||
| --output "${generated_file}" | ||
| --log "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/JinjaGen.log" | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ) | ||
| if("${target}" STREQUAL "zephyr") | ||
| # zephyr is special | ||
| get_unique_generated_target_name(${generated_file} generated_target_name) | ||
| add_custom_target(${generated_target_name} DEPENDS ${generated_file}) | ||
| add_dependencies(zephyr ${generated_target_name}) | ||
| # Remember all the files that are generated for zephyr. | ||
| # target_sources(zephyr PRIVATE ${zephyr_generated_sources}) | ||
| # is executed in the top level CMakeFile.txt context. | ||
| get_property(zephyr_generated_sources GLOBAL PROPERTY zephyr_generated_sources_property) | ||
| list(APPEND zephyr_generated_sources ${generated_file}) | ||
| set_property(GLOBAL PROPERTY zephyr_generated_sources_property "${zephyr_generated_sources}") | ||
| # Add template directory to include path to allow includes with | ||
| # relative path in generated file to work | ||
| zephyr_include_directories(${template_dir}) | ||
| else() | ||
| target_sources(${target} PRIVATE ${generated_file}) | ||
| # Add template directory to include path to allow includes with | ||
| # relative path in generated file to work | ||
| target_include_directories(${target} PRIVATE ${template_dir}) | ||
| endif() | ||
| endforeach() | ||
| endfunction() | ||
|
|
||
| function(zephyr_sources_jinjagen) | ||
| target_sources_jinjagen(zephyr ${ARGN}) | ||
| endfunction() | ||
|
|
||
| function(zephyr_sources_jinjagen_ifdef feature_toggle) | ||
| if(${${feature_toggle}}) | ||
| zephyr_sources_jinjagen(${ARGN}) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| function(zephyr_library_sources_jinjagen) | ||
| target_sources_jinjagen(${ZEPHYR_CURRENT_LIBRARY} ${ARGN}) | ||
| endfunction() | ||
|
|
||
| function(zephyr_library_sources_jinjagen_ifdef feature_toggle) | ||
| if(${${feature_toggle}}) | ||
| zephyr_library_sources_jinjagen(${ARGN}) | ||
| endif() | ||
| endfunction() | ||
|
|
||
| # 1.2 zephyr_library_* | ||
|
|
@@ -424,6 +555,13 @@ macro(zephyr_library_named name) | |
| # This is a macro because we need add_library() to be executed | ||
| # within the scope of the caller. | ||
| set(ZEPHYR_CURRENT_LIBRARY ${name}) | ||
|
|
||
| if("${name}" STREQUAL "zephyr") | ||
| # We have to mark all the generated files "GENERATED" in this context | ||
| get_property(zephyr_generated_files GLOBAL PROPERTY zephyr_generated_files_property) | ||
| set_source_files_properties(${zephyr_generated_files} PROPERTIES GENERATED 1) | ||
| endif() | ||
|
|
||
| add_library(${name} STATIC "") | ||
|
|
||
| zephyr_append_cmake_library(${name}) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code like this should be upstreamed early to minimize the size of the PR.
#10969