Skip to content
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

dts: Add new DTS/binding parser #17660

Merged
merged 3 commits into from
Jul 29, 2019
Merged

Conversation

ulfalizer
Copy link
Collaborator

@ulfalizer ulfalizer commented Jul 18, 2019

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.

  Note that dtlib.py and edtlib.py are general libraries (similar to
  Kconfiglib) that could be used for other stuff besides gen_defines.py.

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 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 <[email protected]>
Signed-off-by: Ulf Magnusson <[email protected]>

@zephyrbot
Copy link
Collaborator

zephyrbot commented Jul 18, 2019

Found the following issues, please fix and resubmit:

License issues

In most cases you do not need to do anything here, especially if the files
reported below are going into ext/ and if license was approved for inclusion
into ext/ already. Fix any missing license/copyright issues. The license
exception if a JFYI for the maintainers and can be overriden when merging the
pull request.

  • scripts/dts/dtlib.py is not apache-2.0 licensed: bsd-new
  • scripts/dts/edtlib.py is not apache-2.0 licensed: bsd-new
  • scripts/dts/gen_defines.py is not apache-2.0 licensed: bsd-new
  • scripts/dts/test.dts is not apache-2.0 licensed: bsd-new
  • scripts/dts/testdtlib.py is not apache-2.0 licensed: bsd-new
  • scripts/dts/testedtlib.py is not apache-2.0 licensed: bsd-new


out_comment("/chosen/{} ({})".format(prop_name, dev.path))
out("{}_BASE_ADDRESS".format(prefix), hex(dev.regs[0].addr))
out("SRAM_SIZE", dev.regs[0].size//1024)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this missing prefix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops... fixed

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't build nucleo_f401re board (sample hello_world), due to missing symbol CONFIG_RAM_SIZE
It is defined in arch/Kconfig:

config SRAM_SIZE
	int "SRAM Size in kB"
	default $(dt_int_val,DT_SRAM_SIZE)

DT_SRAM_SIZE is not defined anymore

EDIT: Seems it has been replaced by:

#define DT_SRAM_SRAM_SIZE                           96

Cf fix in scripts/dts/gen_defines.py, line 318:

-    out("{}_SRAM_SIZE".format(prefix), dev.regs[0].size//1024)
+    out("{}_SIZE".format(prefix), dev.regs[0].size//1024)

@ulfalizer
Copy link
Collaborator Author

Can't build nucleo_f401re board (sample hello_world), due to missing symbol CONFIG_RAM_SIZE
It is defined in arch/Kconfig:

config SRAM_SIZE
	int "SRAM Size in kB"
	default $(dt_int_val,DT_SRAM_SIZE)

DT_SRAM_SIZE is not defined anymore

Fixed by the latest force push. Thought I could make a small change without diffing generated_dts_board.conf before and after, but I couldn't. :P

@erwango erwango self-requested a review July 29, 2019 14:52
@erwango
Copy link
Member

erwango commented Jul 29, 2019

(Slack is broken to me so pasting my point here)
Would be nice to introduce nodes sorting at some step.
From experience, this was useful in previous script when trying to debug and comparing 2 versions of generated output

@ulfalizer
Copy link
Collaborator Author

@erwango
Since Slack is dead:

The order in the conf and header file matches the order in the .dts file now, so it should be consistent at least. Would be pretty easy to change though, if you have some case where that order is bad.

@erwango
Copy link
Member

erwango commented Jul 29, 2019

The order in the conf and header file matches the order in the .dts file now, so it should be consistent at least. Would be pretty easy to change though, if you have some case where that order is bad.

This is not that I see, actually. For instance nucleo_f401re board, gpio nodes order:
nucleo_f401re.dts_compiled: A, B, C, D, E, H
generated_dts_board_unfixed.h: A, E, B, D, C, H (Changing at each build)

@ulfalizer
Copy link
Collaborator Author

@erwango
Try this patch and see if it fixes it. set() iteration order can vary between runs in Python.

diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py
index 720c297615..9d8c43a9c7 100755
--- a/scripts/dts/gen_defines.py
+++ b/scripts/dts/gen_defines.py
@@ -72,7 +72,7 @@ def main():
             active_compats.update(dev.compats)
 
     out_comment("Active compatibles (mentioned in DTS + binding found)")
-    for compat in active_compats:
+    for compat in sorted(active_compats):
         #define DT_COMPAT_<COMPAT> 1
         out("COMPAT_{}".format(str2ident(compat)), 1)

@ulfalizer
Copy link
Collaborator Author

@erwango
What's your python3 --version btw? Dictionary iteration order didn't match insertion order before Python 3.6.

@erwango
Copy link
Member

erwango commented Jul 29, 2019

$ python3 --version
Python 3.5.2

Tried your proposal, but it didn't work (didn't help sorting devices). But as I understand, this aims at sorting compatibles and not devices, so this is logical.

@ulfalizer
Copy link
Collaborator Author

ulfalizer commented Jul 29, 2019

@erwango
Yeah, the device-is-there flags use a set(), so they can move around between runs even on Python 3.6+, unless you sort them somehow.

The rest of it is consistent for me, so I'm guessing it's because you have Python 3.5.

Could you post a diff between runs? Would help with figuring out where it's coming from.

ulfalizer and others added 3 commits July 29, 2019 19:36
--deprecate-only sounded like a command to "only deprecate (something)"
to me at first. --deprecated-only might make it clearer that it's about
only generating deprecated stuff.

Signed-off-by: Ulf Magnusson <[email protected]>
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 <[email protected]>
Signed-off-by: Ulf Magnusson <[email protected]>
Makes it easier to understand what's going on.

Signed-off-by: Ulf Magnusson <[email protected]>
@galak galak merged commit 7de2f4d into zephyrproject-rtos:master Jul 29, 2019
@galak galak deleted the new-dt branch July 29, 2019 20:22
@carlescufi carlescufi mentioned this pull request Jul 30, 2019
6 tasks
galak pushed a commit to zephyrproject-rtos/ci-tools that referenced this pull request Aug 2, 2019
zephyrproject-rtos/zephyr#17660 must go in
before this will work.

Piggyback a clarification re. ZEPHYR_BASE being None when not running on
a Zephyr tree (e.g. when running on the ci-tools repo itself).

Signed-off-by: Ulf Magnusson <[email protected]>
@galak galak mentioned this pull request Aug 9, 2019
48 tasks
ulfalizer added a commit to ulfalizer/zephyr that referenced this pull request Oct 23, 2019
zephyrproject-rtos#17660 must go in
before this will work.

Piggyback a clarification re. ZEPHYR_BASE being None when not running on
a Zephyr tree (e.g. when running on the ci-tools repo itself).

Signed-off-by: Ulf Magnusson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants