Commit Graph

100 Commits

Author SHA1 Message Date
Ulf Magnusson 399c04ce5a scripts/dts: Remove unused variables and imports
Discovered with pylint3.

Use the placeholder name '_' for unproblematic unused variables. It's
what I'm used to, and pylint knows not to flag it.

Also improve the naming a bit in devicetree.py. If a key/value is known
to be a specific thing (like a node), then it's helpful to call it that
instead of something generic like "value".

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-28 11:06:01 -05:00
Ulf Magnusson 958e2d3229 scripts/dts: Refactor Flash code to be less twisty
- Remove DTFlash.extract(), which was just dispatching to either
   _extract_flash() or _extract_code_partition() depending on which
   magic string was passed in. Call them directly instead.

 - Fold constant and globally available parameter values into functions

 - Remove DTFlash._flash_node. It's easy to derive wherever it's needed,
   and it makes it clearer where it comes from (and means functions can
   be called in any order).

 - Remove DTFlash._flash_base_address, which is unused

 - Remove various unused parameters to functions

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson 2a4d8b07aa scripts/dts: Remove weird def_label.split('/') code
def_label is the name used for macros and .conf file values. It can
never have a slash in it.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson f95a230b82 scripts/dts: Clean up/fix extract/interrupts.py a bit
- Fix broken code that was meant to turn the
   'interrupts'/'interrupts-extended' value into a list if it wasn't.
   list(123) will error out instead of creating [123].

 - Remove weird .split('/') on macro name

 - Rename 'props' to 'vals'. It's the value of a single property.

 - Get rid of a bare 'except:'

 - Rename l_fqn to full_name. Accidentally stumbled upon 'fqn' probably
   standing for "fully qualified name", but it's not obvious.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson 3b64e71221 scripts/dts: Simplify extract/interrupts.py and add some helpers
- Have get_parent_path() return None for the root ('/'). This is handy
   when looping over path components.

 - Move _find_parent_irq_node() out of the class, call it
   parent_irq_node(), and use get_parent_path() in it.

 - Add a global err() function for reporting errors. Use it if a node
   unexpectedly has no interrupt-parent.

   Previously, this would give a Python error instead.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson a3d3aa58b8 scripts/dts: Remove redundant empty constructors
It's not obligatory for Python classes to have an __init__().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson 0a3f00ad7c scripts/dts: Rename get_node_label() to node_label()
Just returns a value, with no side effects.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-15 11:09:49 -05:00
Ulf Magnusson d3bf4b432c scripts/dts: Remove dead 'aliases' check in insert_defs()
insert_defs() is the only function that adds keys to 'defs', and they
always get added with an 'aliases' key.

This function could get super simple if the duplicate-removal code could
be removed. It only seems to be needed to prevent duplicates for some
(unfortunately tricky) flash-related stuff now.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 25ff4b72a9 scripts/dts: Remove global 'structs' variable
Unused.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 59a0c4331d scripts/dts: Fix binding_compats/bindings_compat naming mismatch
'binding_compats' makes the most sense, so use that everywhere.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 5999f10ba2 scripts/dts: Get rid of deepcopy() and 'except:' in translate_addr()
- No deep copying is needed. The deepcopy() is just a hack to work
   around that the value might not be a list. That deserves a comment at
   least.

 - A catch-all try/except will hide stuff like misspelled variables as
   well. It's usually a bad idea.

Rewrite things to be more explicit, and add some comments.

reg.py was indirectly using the deepcopy() imported in global.py,
because it does 'from global import *'. Have it import deepcopy() itself
instead. reg.py is the only remaining user of deepcopy().

reg.py relying on the deepcopy() import in global.py was super hard to
discover, due to another catch-all try/except around the deepcopy()
call.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 9d4c2921ee scripts/dts: Remove redundant 'children' check in create_chosen()
All nodes have a 'children' key.

Also simplify a bit. The loop is copying a dictionary verbatim.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 5edeec3dc4 scripts/dts: Simplify and document get_compat()
Get rid of the try/except and the find_parent_prop() call. Also add some
documentation.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson e0f55f17e8 scripts/dts: Fix get_parent_path() for top-level nodes
'/foo' was turned into ''. Turn it into '/' instead. That's how the root
is represented in 'reduced' too.

Also remove some code from get_addr_size_cells() that was only there to
work around the bug.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson bc73ba6fc3 scripts/dts: Remove get_node_compats()
Unused.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson 392587b2a5 scripts/dts: Remove redundant 'children' check in create_aliases()
All nodes have a 'children' key.

Also simplify and improve naming a bit.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 10:02:35 -06:00
Ulf Magnusson f5b17d4138 scripts/dts: Call /foo/bar a "path" instead of an "address"
It's confusing that "address" is often used within the same function to
refer to both node paths and e.g. address cells.

Make things easier to understand by calling /foo/bar a path instead.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-22 12:44:16 -06:00
Ulf Magnusson 50ab1d8e5f scripts/dts: Clean up create_reduced()
- Remove dead "if 'props' in nodes" check

 - Rename the 'nodes' parameter to 'node'. It represents a single node.

 - Use a defaultdict(int) for 'last_used_id' (makes unset keys give 0)

 - Use a global for 'last_used_id'

 - Move some related code so it appears together

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-20 12:17:31 -06:00
Ulf Magnusson 8c3aabb2c2 scripts/dts: Remove find_node_by_path()
Unused.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-20 12:17:31 -06:00
Kumar Gala b814af827d scripts/dts/extract: Fix how we determine DT_FLASH_AREA_<X>_DEV
DT_FLASH_AREA_<X>_DEV should be the label of the flash controller.  For
flashes that are "jedec,spi-nor" the flash itself is considered the
controller.  For "soc-nv-flash" the parent of the flash is assumed to be
the controller.

Rework the logic in how we determined DT_FLASH_AREA_<X>_DEV to handle
both cases.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-14 05:13:35 -06:00
Ulf Magnusson 4e5868f4af scripts/dts: Make all_compats() return a set with all compats
Previously, all_compats() returned a dictionary mapping nodes to their
'compatible' values. This dictionary was then (only) used to generate a
set() of all 'compatible' strings.

Save a step and get rid of some code by having all_compats() return a
set() with all 'compatible' strings directly.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson 4fcdd134c2 scripts/dts: Improve naming in create_phandles()
k, v -> child_name, child_node

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson 8c515b25a3 scripts/dts: Remove unused create_phandles() 'handle' parameter
Unused.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson ace8450040 scripts/dts: Simplify get_all_compatibles()
- Rename to all_compats(). The "compats" part is consistent with
   elsewhere.

 - Don't require an empty dictionary to be passed in. Build the
   result within the function instead.

 - Use more specific names (k, v -> child_name, child_node)

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson b52290fa58 scripts/dts: Rename get_chosen() to create_chosen()
It creates the global 'chosen' dictionary. get_*() makes it sound like
it returns a value.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson 28c76fd3d8 scripts/dts: Rename get_aliases() to create_aliases()
It creates the global 'aliases' dictionary. get_*() makes it sound like
it returns a value.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson 6d824feb69 scripts/dts: Rename get_phandles() to create_phandles()
It creates the global 'phandles' dictionary. get_*() makes it sound like
it returns a value.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Ulf Magnusson ccf7de0306 scripts/dts: Rename get_reduced() to create_reduced()
It creates the global 'reduced' dictionary. get_*() makes it sound like
it returns a value.

Fix a comment that might make people think the global dictionaries are
Python lists too.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-08 22:57:05 -06:00
Kumar Gala ec63dca3ea scripts/dts/extract: Fix producing bogus alias if reg has no size
Its possible that a reg property is address only.  If that's the case we
should produce any alias information for the size.  We should check
nr_size_cells to decide to handle the alias case or not.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Kumar Gala 5a20a418a2 scripts/dts/extract: Remove generation for FLASH_LABEL
FLASH_LABEL define isn't used anywhere so remove it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Kumar Gala 873e4e950a scripts/dts/extract_dts_includes: Add DT_ prefix to FLASH_AREA defines
We generate the following FLASH prefixed defines:

	FLASH_AREA_MCUBOOT_LABEL
	FLASH_AREA_MCUBOOT_OFFSET
	FLASH_AREA_MCUBOOT_OFFSET_0
	FLASH_AREA_MCUBOOT_READ_ONLY
	FLASH_AREA_MCUBOOT_SIZE
	FLASH_AREA_MCUBOOT_SIZE_0

Now we generate DT_ prefixed versions:

	DT_FLASH_AREA_MCUBOOT_LABEL
	DT_FLASH_AREA_MCUBOOT_OFFSET
	DT_FLASH_AREA_MCUBOOT_OFFSET_0
	DT_FLASH_AREA_MCUBOOT_READ_ONLY
	DT_FLASH_AREA_MCUBOOT_SIZE
	DT_FLASH_AREA_MCUBOOT_SIZE_0

And will deprecate the non DT_ prefixed versions in the future.  We keep
them around as aliases for the time being.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Kumar Gala 2024f6b2a0 scripts/dts/extract_dts_includes: Add DT_ prefix to FLASH defines
We generate the following FLASH prefixed defines:
	FLASH_LABEL
	FLASH_ERASE_BLOCK_SIZE
	FLASH_WRITE_BLOCK_SIZE

Now we generate DT_ prefixed versions:
	DT_FLASH_LABEL
	DT_FLASH_ERASE_BLOCK_SIZE
	DT_FLASH_WRITE_BLOCK_SIZE

And will deprecate the non DT_ prefixed versions in the future.  We keep
them around as aliases for the time being.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Kumar Gala ff70b3444f dts: Convert CONFIG_ to DT_ symbols for chosen props
Replace generating CONFIG_ symbols with DT_ symbols for chosen
properties like 'zephyr,console' or 'zephyr,bt-mon-uart'.  We now use a
kconfigfunctions (dt_str_val) to extract the info from dts into Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 11:41:26 -06:00
Kumar Gala bfaaa6bbe9 dts: Convert CONFIG_CCM to DT_CCM
Since we know do DTS before Kconfig we should try and remove dts from
creating Kconfig namespaced symbols and leave that to Kconfig.  So
rename CONFIG_CCM_<FOO> to DT_CCM_<FOO>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 10:29:57 -06:00
Ulf Magnusson 7b0ac7d303 scripts/dts: Simplify get_parent_address()
Returns the empty string for '/foo' and '/', but the old version did
that too, so maybe it's intended.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 21:42:36 -06:00
Ulf Magnusson a776927250 scripts/dts: Simplify find_parent_prop()
Also replace a .get() where the key is known to exist.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 21:42:36 -06:00
Findlay Feng 69c15f0ed1 dts: flash_map: Automatically generate of the list of flash area
This Patch add functionality for automatic generation of the flash map
using DTS description. Automatic generation allows to replace
C-hardcoded flash_map.

We generate a set of defines based on the index of a partiion:
	#define DT_FLASH_AREA_<IDX>_OFFSET	0
	#define DT_FLASH_AREA_<IDX>_SIZE	131072
	#define DT_FLASH_AREA_<IDX>_DEV		"FLASH_CTRL"
	#define DT_FLASH_AREA_<IDX>_LABEL	MCUBOOT

Additionally we also define:
	#define DT_FLASH_AREA_NUM		4

and:
	#define DT_FLASH_AREA_<PARTNAME>_ID	0

Signed-off-by: Findlay Feng <i@fengch.me>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-07 10:31:27 -06:00
Ulf Magnusson 7df60372c2 scripts/dts: Rename convert_string_to_label() to str_to_label()
Less spammy and as easy to understand ("label" seems a bit confusing
though, but it's consistent with other code).

Also simplify some surrounding code, and clean up the implementation of
str_to_label() a bit.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson 9c1274b6e8 scripts/dts: Simplify code around insert_defs() calls
Pass the dictionary of definitions directly. Shorter and clearer.

Also get rid of some other temporary variables, a redundant str() call,
and some mysterious commented-out code in _extract_flash().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson e8a077b6a3 scripts/dts: Remove redundant parentheses around 'if' conditions
Not needed in Python.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson d2985b31d8 scripts/dts: Remove dead and confusing code in get_phandles()
- The 'props' key is known to exist (and 'if enabled == ...:' would
    crash if it ever was missing)

  - 'd' is always a dictionary

  - There's no need to test if d['children'] is non-empty before looping
    through it

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson 23afd94704 scripts/dts: Remove dead and confusing code in get_all_compatibles()
- The 'props' key is known to exist (and 'if enabled == ...:' would
   crash if it ever was missing)

 - 'd' is always a dictionary

 - There's no need to test if d['children'] is non-empty before looping
   through it

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson d26cb1fb55 scripts/dts: Remove redundant and confusing dict.get() calls
dict.get(key) signals to people reading the code that you're not sure
whether the key exists. It returns None if it doesn't.

When the key is known to exist, dict[key] should be used. This also
helps catch bugs by raising an exception if the key is missing.

Similarly, whether a key in a dict should be tested with

    if key in dict:

instead of with

    if dict.get(key):

The second version signals that you both want to make sure that the
exists and that it's truthy (e.g., non-empty). That's confusing if a
simple existence check was meant.

There seems to be a bug in output_keyvalue_lines() where

    fd.write("%s=%s\n" % (entry, defs[node].get(a)))

can end up writing '...=None'. Removing the .get() makes it throw an
exception instead. Keep the .get() for now and don't attempt to fix the
bug.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Ulf Magnusson 01db6469ca scripts/dts: Remove redundant dict.keys() calls
'x in dict' and 'for x in dict' in Python always uses the keys.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-07 10:39:37 +01:00
Kumar Gala ce7ed18989 dts: Move CONFIG_SRAM_* & CONFIG_FLASH_* back to Kconfig
dts will now generate DT_SRAM_BASE_ADDRESS, DT_SRAM_SIZE,
DT_FLASH_BASE_ADDRESS, and DT_FLASH_SIZE defines.  Kconfig can utilize
these defines to set defaults for the CONFIG_ variants.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 10:16:06 -06:00
Kumar Gala 87915cd36f dts: stop generating CONFIG_FLASH_LOAD_{OFFSET,SIZE}
As a step to completing removing use of Kconfig defines in dts files we
need to change how we configure/set CONFIG_FLASH_LOAD_{OFFSET,SIZE}.

Previously we would set them based on how the chosen property
'zephyr,code-partition' was set to.  If 'zephyr,code-partition' wasn't
set we would default the values to 0.  We had some generic overlay logic
which would define 'zephyr,code-partition' based on
CONFIG_BOOTLOADER_MCUBOOT.

Going forward if the DTS has 'zephyr,code-partition' set we will
generate DT_CODE_PARTITION_OFFSET & DT_CODE_PARTITION_SIZE defines.  We
will leave it to Kconfig to set CONFIG_FLASH_LOAD_OFFSET &
CONFIG_FLASH_LOAD_SIZE.

We introduce a python script that allows Kconfig to extract data from
the DTS and thus we can utilize DT_CODE_PARTITION_OFFSET and
DT_CODE_PARTITION_SIZE values to set defaults for
CONFIG_FLASH_LOAD_OFFSET & CONFIG_FLASH_LOAD_SIZE.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-02-01 10:16:06 -06:00
Kumar Gala 7d52cb7d4a scripts/dts/extract: Rework to extract_{controller,cells}
Rework extract_{controller,cells} so they aren't recursive.  As part of
this change we take the flat cell array property and build a proper list
based on what the number of cells each element would represent.

Fixes #12724

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-30 09:41:10 -06:00
Kumar Gala d5b58e1655 scripts/dts/extract: Move flattening of list to one place
Because of differents in dtc versions the output of a list property may
vary.  We would flatten the list of lists to a single list to match how
older dtc versions did things.  Rather than doing that flattening in
multiple places, move it to get_reduced() so we do it just once.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-30 09:41:10 -06:00
Kumar Gala f592c528f4 scripts/dts/extract: Add support for generating SPI GPIO CS defines
Add support to generation script to generate defines for GPIO CS
[WIP], need to clarify some issues on how CS's look when we mix GPIO-CS
and HW CS.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-23 18:12:24 -06:00
Kumar Gala 4bd4185a2c scripts/dts/extract: Add single extract to extract_{controller,cells}
Add the ability to extract just a single instance from extract_cells and
extract_controller.  This lets us pass in a prop_values like:

cs-gpios =  < 0x02 0x11 0x00 >, < 0x03 0x05 0x00 >;

and extract just index = 1 if we want < 0x03 0x05 0x00 >.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-23 18:12:24 -06:00