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>
- 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>
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>
- 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>
- 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>
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>
- 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>
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>
'/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>
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>
- 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>
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>
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>
- 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>
It creates the global 'phandles' dictionary. get_*() makes it sound like
it returns a value.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
- 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>
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>
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>
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>
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>
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>
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>
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>