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

script/dts: Generate Extended Device Tree database #9876

Closed
wants to merge 27 commits into from

Conversation

erwango
Copy link
Member

@erwango erwango commented Sep 10, 2018

This PR is subset of #6762 (Codegen introduction, proposed by @b0661), focused on edts database generation.

Extended Device Tree database is a json file generated by extract_dts_includes.py script, from board device tree (dts) collated with yaml bindings.
Since it is post processed from dtc, information is displayed in an easily accessible 'dict' format:

 _edts dict(
   'devices':  dict(device-id :  device-struct),
   'compatibles':  dict(compatible : sorted list(device-id)),
   'device-types': dict(device-types : sorted list(compatible)),
   ...
 )

 device-struct dict(
   'device-id' : device-id,
   'compatible' : list(compatible) or compatible,
   'label' : label,
   property-name : property-value ...
 )

 device-id: opaque id for a device (do not use for other purposes),
 compatible: any of ['st,stm32-spi-fifo', ...] - 'compatible' from <binding>.yaml
 label: any of ['UART_0', 'SPI_11', ...] - label directive from DTS
 device-type: any of zephyr generic type: usb, spi, i2c, ...

Edit 09/11: Added device-type injection

@codecov-io
Copy link

codecov-io commented Sep 10, 2018

Codecov Report

Merging #9876 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9876   +/-   ##
=======================================
  Coverage   53.29%   53.29%           
=======================================
  Files         215      215           
  Lines       25843    25843           
  Branches     5694     5694           
=======================================
  Hits        13773    13773           
  Misses       9754     9754           
  Partials     2316     2316

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fad97ef...88155ce. Read the comment docs.

@erwango erwango force-pushed the push_extract_edts branch 2 times, most recently from 3311a99 to 7f61c4c Compare September 10, 2018 15:34
@erwango erwango added DNM This PR should not be merged (Do Not Merge) RFC Request For Comments: want input from the community labels Sep 11, 2018
@erwango erwango force-pushed the push_extract_edts branch 3 times, most recently from 372afa8 to 9c02e67 Compare September 11, 2018 11:38
scripts/dts/edtsdatabase.py Show resolved Hide resolved
scripts/dts/extract/gpios.py Show resolved Hide resolved
scripts/dts/extract/gpios.py Outdated Show resolved Hide resolved
scripts/dts/extract/gpios.py Outdated Show resolved Hide resolved
# @param none
# @return list of supported device types
def get_device_types(self):
return list(self._edts['device_types'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

'device_types' -> 'device-types'

self._edts['device-types'][device_type].append(device_id)
self._edts['device-types'][device_type].sort()

def insert_device_type(self, compatible, device_type):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove - already accomplished by insert.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've chosen a different device-type dict as the one you proposed.
I've chosen to display: dict(device-type : sorted list(compatible)) instead of a sorted list of device_id.
Aim was to make it easier to access to get device-type information per compatible (for DTS_ #define's generation), as well as device-type list for CI.
So I need to inject (device-type, compatible) couple, which I can't using insert.

if not isinstance(device_types, list):
device_types = [device_types, ]
for j, dev_type in enumerate(device_types):
edts_insert_device_type(comp, dev_type)
Copy link
Collaborator

@b0661 b0661 Sep 11, 2018

Choose a reason for hiding this comment

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

Remove edts_insert_device_type - see above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

After thinking a bit - device type generation should be moved to heuristics.py.

Copy link
Member Author

Choose a reason for hiding this comment

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

See reasonning behind this choice above

Copy link
Member Author

Choose a reason for hiding this comment

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

My last answer was response to first comment.

After thinking a bit - device type generation should be moved to heuristics.py.

Yes, I hesitated indeed. Moved

@@ -23,6 +23,9 @@ def edts_insert_device_property(node_address, property_path, property_value):
device_id = edts_device_id(node_address)
edts.insert_device_property(device_id, property_path, property_value)

def edts_insert_device_type(compatible, device_type):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove - use edts_insert_device_property with 'device-type/{}'.format(device_type) instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm already using edts_insert_device_property with 'device-type/{}'.format(device_type)
in heuristics class.
Aim of edts_insert_device_type is not to fill in device-type sub-node property but dedicated device-type dict. This new dict should be used at least for CI and potentially other purposes related to #9406.

@erwango erwango force-pushed the push_extract_edts branch 3 times, most recently from 4e3fe7a to 40434cf Compare September 12, 2018 09:59
for compatible in compatibles:
for device_id in self._edts['compatibles'].get(compatible, []):
device_ids[device_id] = 1
return list(device_ids.keys())
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to re-use the code between this function and the previous.

E.g. by having a private function that returns a dict. And then have each of these two call that function and extract either the keys or the values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks

@erwango erwango force-pushed the push_extract_edts branch 4 times, most recently from 7c07936 to 0090121 Compare September 13, 2018 09:43
@galak
Copy link
Collaborator

galak commented Sep 13, 2018

Can you update scripts/dts/edtsdatabase.py to do something similar to scripts/dts/devicetree.py w/regards to main, and being able to run it and have it print out the database.

Validate generated etds.json against a reference edts file.
Script first checks edts structure then content of various elements
and finally devices parameters values.
This last step is done using a specific method for ref_edts
parameter extraction so we can verify behavior of
edtsdatabase class extraction function.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
b0661 added a commit to b0661/zephyr that referenced this pull request Nov 27, 2018
The Extended Device Tree Specification database collates
device tree (dts) information with information taken from
the device tree bindings.

The EDTS database may be loaded from a json file, stored
to a json file or extracted from the DTS files and the
bindings yaml files.

The database is integrated into cogeno as a module.

The commit integrates database development done in zephyrproject-rtos#9876
which was based on zephyrproject-rtos#6762.

Major differences/ improvements to zephyrproject-rtos#9876 are:
- the database now has an own extraction function that
  can be used instead of e.g. extract_dts_includes.
  The extraction function follows the design of
  the extract_dts_includes script and the additions that
  were done in zephyrproject-rtos#9876. It is restructured and several globals
  are now classes and objects. All functionality of
  extract_dts_includes related to the generation of defines
  is not part of the database extract function. It's sole
  purpose is to fill the database directly from the compiled
  DTS file.
- the database got itś own directory 'edtsdb' to structure
  all files related to the database.
- The EDTSDevice class from zephyrproject-rtos#9876 was enhanced to allow
  devices to access the database they are taken from.

Mayor compatibility issues to zephyrproject-rtos#9876.
- The consumer, provider API and the internal structure
  of the database is copied from zephyrproject-rtos#9876.
  - API should be fully compatible.
  - Extraction of children was replaced as it broke the
    concept of the devices struct as a list of devices.
    The functions device.get_children() and
    device.get_parent() may be used to acess the
    parent<->child relation.
- The EDTSDevice class is copied from zephyrproject-rtos#9876.
  - The device API should be compatible except for
    - the constructor which now needs the EDTS database and
    - the unique id feature. To ge an unique id the
      device.get_name() function can be used instead.

Signed off from zephyrproject-rtos#9876 added to attribute for the changes done
there and copied.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
b0661 added a commit to b0661/zephyr that referenced this pull request Feb 3, 2019
The Extended Device Tree Specification database collates
device tree (dts) information with information taken from
the device tree bindings.

The EDTS database may be loaded from a json file, stored
to a json file or extracted from the DTS files and the
bindings yaml files.

The database is integrated into cogeno as a module.

The commit integrates database development done in zephyrproject-rtos#9876
which was based on zephyrproject-rtos#6762.

Major differences/ improvements to zephyrproject-rtos#9876 are:
- the database now has an own extraction function that
  can be used instead of e.g. extract_dts_includes.
  The extraction function follows the design of
  the extract_dts_includes script and the additions that
  were done in zephyrproject-rtos#9876. It is restructured and several globals
  are now classes and objects. All functionality of
  extract_dts_includes related to the generation of defines
  is not part of the database extract function. It's sole
  purpose is to fill the database directly from the compiled
  DTS file.
- the database got itś own directory 'edtsdb' to structure
  all files related to the database.
- The EDTSDevice class from zephyrproject-rtos#9876 was enhanced to allow
  devices to access the database they are taken from.

Mayor compatibility issues to zephyrproject-rtos#9876.
- The consumer, provider API and the internal structure
  of the database is copied from zephyrproject-rtos#9876.
  - API should be fully compatible.
  - Extraction of children was replaced as it broke the
    concept of the devices struct as a list of devices.
    The functions device.get_children() and
    device.get_parent() may be used to acess the
    parent<->child relation.
- The EDTSDevice class is copied from zephyrproject-rtos#9876.
  - The device API should be compatible except for
    - the constructor which now needs the EDTS database and
    - the unique id feature. To ge an unique id the
      device.get_name() function can be used instead.

Signed off from zephyrproject-rtos#9876 added to attribute for the changes done
there and copied.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
b0661 added a commit to b0661/zephyr that referenced this pull request Feb 22, 2019
The Extended Device Tree Specification database collates
device tree (dts) information with information taken from
the device tree bindings.

The EDTS database may be loaded from a json file, stored
to a json file or extracted from the DTS files and the
bindings yaml files.

The database is integrated into cogeno as a module.

The commit integrates database development done in zephyrproject-rtos#9876
which was based on zephyrproject-rtos#6762.

Major differences/ improvements to zephyrproject-rtos#9876 are:
- the database now has an own extraction function that
  can be used instead of e.g. extract_dts_includes.
  The extraction function follows the design of
  the extract_dts_includes script and the additions that
  were done in zephyrproject-rtos#9876. It is restructured and several globals
  are now classes and objects. All functionality of
  extract_dts_includes related to the generation of defines
  is not part of the database extract function. It's sole
  purpose is to fill the database directly from the compiled
  DTS file.
- the database got itś own directory 'edtsdb' to structure
  all files related to the database.
- The EDTSDevice class from zephyrproject-rtos#9876 was enhanced to allow
  devices to access the database they are taken from.

Mayor compatibility issues to zephyrproject-rtos#9876.
- The consumer, provider API and the internal structure
  of the database is copied from zephyrproject-rtos#9876.
  - API should be fully compatible.
  - Extraction of children was replaced as it broke the
    concept of the devices struct as a list of devices.
    The functions device.get_children() and
    device.get_parent() may be used to acess the
    parent<->child relation.
- The EDTSDevice class is copied from zephyrproject-rtos#9876.
  - The device API should be compatible except for
    - the constructor which now needs the EDTS database and
    - the unique id feature. To ge an unique id the
      device.get_name() function can be used instead.

Signed off from zephyrproject-rtos#9876 added to attribute for the changes done
there and copied.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
@galak
Copy link
Collaborator

galak commented Jul 26, 2019

Closing, as this should be superceded by PR #17660

@galak galak closed this Jul 26, 2019
@erwango erwango deleted the push_extract_edts branch September 3, 2019 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree RFC Request For Comments: want input from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants