Skip to content
Permalink
Browse files

dts: Add new DTS/binding parser

Add a new DTS/binding parser to scripts/dts/ for generating
generated_dts_board.conf and generated_dts_board_unfixed.h.

The old code is kept to generate some deprecated defines, using the
--deprecated-only flag. It will be removed later.

The new parser is implemented in three files in scripts/dts/:

dtlib.py:
  A low-level .dts parsing library. This is similar to devicetree.py in
  the old code, but is a general robust DTS parser that doesn't rely on
  preprocessing.

edtlib.py (e for extended):
  A library built on top of dtlib.py that brings together data from DTS
  files and bindings and creates Device instances with all the data for
  a device.

gen_defines.py:
  A script that uses edtlib.py to generate generated_dts_board.conf and
  generated_dts_board_unfixed.h. Corresponds to extract_dts_includes.py
  and the files in extract/ in the old code.

testdtlib.py:
  Test suite for dtlib.py. Can be run directly as a script.

testedtlib.py (uses test.dts and test-bindings/):
  Test suite for edtlib.py. Can be run directly as a script.

The test suites will be run automatically in CI.

The new code turns some things that were warnings (or not checked) in
the old code into errors, like missing properties that are specified
with 'category: required' in the binding for the node.

The code includes lots of documentation and tries to give helpful error
messages instead of Python errors.

Co-authored-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
  • Loading branch information...
ulfalizer and galak committed Dec 17, 2018
1 parent a72e451 commit 62d57414762d111b6af65eeeb7a8325d1ba94de4
@@ -311,6 +311,7 @@
/scripts/elf_helper.py @andrewboie
/scripts/sanity_chk/expr_parser.py @nashif
/scripts/gen_app_partitions.py @andrewboie
/scripts/dts/ @ulfalizer @galak
/arch/x86/gen_gdt.py @andrewboie
/arch/x86/gen_idt.py @andrewboie
/scripts/gen_kobject_list.py @andrewboie
@@ -156,16 +156,39 @@ if(SUPPORTS_DTS)
message(FATAL_ERROR "command failed with return code: ${ret}")
endif()

#
# Run gen_defines.py to create a .conf file and a header file
#

set(CMD_NEW_EXTRACT ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/dts/gen_defines.py
--dts ${BOARD}.dts.pre.tmp
--bindings-dir ${DTS_ROOT_BINDINGS}
--conf-out ${GENERATED_DTS_BOARD_CONF}
--header-out ${GENERATED_DTS_BOARD_UNFIXED_H}
)

execute_process(
COMMAND ${CMD_NEW_EXTRACT}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE ret
)
if(NOT "${ret}" STREQUAL "0")
message(FATAL_ERROR "new extractor failed with return code: ${ret}")
endif()

#
# Run extract_dts_includes.py (the older DT/binding parser) to generate some
# legacy identifiers (via --deprecated-only). This will go away later.
#

set(CMD_EXTRACT_DTS_INCLUDES ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/dts/extract_dts_includes.py
--deprecated-only
--dts ${BOARD}.dts_compiled
--yaml ${DTS_ROOT_BINDINGS}
--keyvalue ${GENERATED_DTS_BOARD_CONF}
--include ${GENERATED_DTS_BOARD_UNFIXED_H}
--include ${GENERATED_DTS_BOARD_UNFIXED_H}.deprecated
--old-alias-names
)

# Run extract_dts_includes.py to create a .conf and a header file that can be
# included into the CMake namespace
execute_process(
COMMAND ${CMD_EXTRACT_DTS_INCLUDES}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
@@ -179,4 +202,5 @@ if(SUPPORTS_DTS)

else()
file(WRITE ${GENERATED_DTS_BOARD_UNFIXED_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")
file(WRITE ${GENERATED_DTS_BOARD_UNFIXED_H}.deprecated "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")
endif(SUPPORTS_DTS)
@@ -13,6 +13,8 @@

#include <generated_dts_board_unfixed.h>

#include <generated_dts_board_unfixed.h.deprecated>

/* The following definitions fixup the generated include */

#include <generated_dts_board_fixups.h>

0 comments on commit 62d5741

Please sign in to comment.
You can’t perform that action at this time.