kconfig: Introduce typed dt kconfig functions

Replace:
  dt_chosen_reg_addr
  dt_chosen_reg_size
  dt_node_reg_addr
  dt_node_reg_size

with:
  dt_chosen_reg_addr_int
  dt_chosen_reg_size_int
  dt_chosen_reg_addr_hex
  dt_chosen_reg_size_hex
  dt_node_reg_addr_int
  dt_node_reg_size_int
  dt_node_reg_addr_hex
  dt_node_reg_size_hex

So that we get the proper formatted string for the type of symbol.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-10-23 15:15:59 -05:00 committed by Kumar Gala
commit 22e7449b73
10 changed files with 98 additions and 58 deletions

View file

@ -99,7 +99,7 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
config FLASH_LOAD_OFFSET config FLASH_LOAD_OFFSET
hex "Kernel load offset" hex "Kernel load offset"
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION
default 0 default 0
depends on HAS_FLASH_LOAD_OFFSET depends on HAS_FLASH_LOAD_OFFSET
help help
@ -112,7 +112,7 @@ config FLASH_LOAD_OFFSET
config FLASH_LOAD_SIZE config FLASH_LOAD_SIZE
hex "Kernel load size" hex "Kernel load size"
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION
default 0 default 0
depends on HAS_FLASH_LOAD_OFFSET depends on HAS_FLASH_LOAD_OFFSET
help help

View file

@ -100,7 +100,7 @@ DT_CHOSEN_Z_SRAM := zephyr,sram
config SRAM_SIZE config SRAM_SIZE
int "SRAM Size in kB" int "SRAM Size in kB"
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_SRAM),0,K) default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_SRAM),0,K)
help help
This option specifies the size of the SRAM in kB. It is normally set by This option specifies the size of the SRAM in kB. It is normally set by
the board's defconfig file and the user should generally avoid modifying the board's defconfig file and the user should generally avoid modifying
@ -108,7 +108,7 @@ config SRAM_SIZE
config SRAM_BASE_ADDRESS config SRAM_BASE_ADDRESS
hex "SRAM Base Address" hex "SRAM Base Address"
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_SRAM)) default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM))
help help
This option specifies the base address of the SRAM on the board. It is This option specifies the base address of the SRAM on the board. It is
normally set by the board's defconfig file and the user should generally normally set by the board's defconfig file and the user should generally
@ -119,7 +119,7 @@ DT_CHOSEN_Z_FLASH := zephyr,flash
config FLASH_SIZE config FLASH_SIZE
int "Flash Size in kB" int "Flash Size in kB"
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_FLASH),0,K) if (XIP && ARM) || !ARM default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K) if (XIP && ARM) || !ARM
help help
This option specifies the size of the flash in kB. It is normally set by This option specifies the size of the flash in kB. It is normally set by
the board's defconfig file and the user should generally avoid modifying the board's defconfig file and the user should generally avoid modifying
@ -127,7 +127,7 @@ config FLASH_SIZE
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
hex "Flash Base Address" hex "Flash Base Address"
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_FLASH)) if (XIP && ARM) || !ARM default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH)) if (XIP && ARM) || !ARM
help help
This option specifies the base address of the flash on the board. It is This option specifies the base address of the flash on the board. It is
normally set by the board's defconfig file and the user should generally normally set by the board's defconfig file and the user should generally

View file

@ -53,17 +53,17 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
if BOARD_ACTINIUS_ICARUS && TRUSTED_EXECUTION_SECURE if BOARD_ACTINIUS_ICARUS && TRUSTED_EXECUTION_SECURE
config FLASH_LOAD_SIZE config FLASH_LOAD_SIZE
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
endif # BOARD_ACTINIUS_ICARUS && TRUSTED_EXECUTION_SECURE endif # BOARD_ACTINIUS_ICARUS && TRUSTED_EXECUTION_SECURE
if BOARD_ACTINIUS_ICARUS_NS if BOARD_ACTINIUS_ICARUS_NS
config FLASH_LOAD_OFFSET config FLASH_LOAD_OFFSET
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
config FLASH_LOAD_SIZE config FLASH_LOAD_SIZE
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
endif # BOARD_ACTINIUS_ICARUS_NS endif # BOARD_ACTINIUS_ICARUS_NS

View file

@ -53,17 +53,17 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
if BOARD_NRF9160_PCA10090 && TRUSTED_EXECUTION_SECURE if BOARD_NRF9160_PCA10090 && TRUSTED_EXECUTION_SECURE
config FLASH_LOAD_SIZE config FLASH_LOAD_SIZE
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
endif # BOARD_NRF9160_PCA10090 && TRUSTED_EXECUTION_SECURE endif # BOARD_NRF9160_PCA10090 && TRUSTED_EXECUTION_SECURE
if BOARD_NRF9160_PCA10090NS if BOARD_NRF9160_PCA10090NS
config FLASH_LOAD_OFFSET config FLASH_LOAD_OFFSET
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
config FLASH_LOAD_SIZE config FLASH_LOAD_SIZE
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_CODE_PARTITION)) default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
endif # BOARD_NRF9160_PCA10090NS endif # BOARD_NRF9160_PCA10090NS

View file

@ -9,7 +9,7 @@ config HAS_FLASH_LOAD_OFFSET
default y default y
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/spi@10014000,1) default $(dt_node_reg_addr_hex,/soc/spi@10014000,1)
config FLASH_LOAD_OFFSET config FLASH_LOAD_OFFSET
default 0x0 default 0x0

View file

@ -816,21 +816,27 @@ Devicetree Related Functions
============================ ============================
See the Python docstrings in ``scripts/kconfig/kconfigfunctions.py`` for more See the Python docstrings in ``scripts/kconfig/kconfigfunctions.py`` for more
details on the functions. details on the functions. The ``*_int`` version of each function returns the
value as a decimal integer, while the ``*_hex`` version returns a hexidecimal
value starting with ``0x``.
.. code-block:: none .. code-block:: none
dt_chosen_reg_addr(kconf, _, chosen, index=0, unit=None): dt_chosen_reg_addr_int(kconf, _, chosen, index=0, unit=None):
dt_chosen_reg_size(kconf, _, chosen, index=0, unit=None): dt_chosen_reg_addr_hex(kconf, _, chosen, index=0, unit=None):
dt_node_reg_addr(kconf, _, path, index=0, unit=None): dt_chosen_reg_size_int(kconf, _, chosen, index=0, unit=None):
dt_node_reg_size(kconf, _, path, index=0, unit=None): dt_chosen_reg_size_hex(kconf, _, chosen, index=0, unit=None):
dt_node_reg_addr_int(kconf, _, path, index=0, unit=None):
dt_node_reg_addr_hex(kconf, _, path, index=0, unit=None):
dt_node_reg_size_int(kconf, _, path, index=0, unit=None):
dt_node_reg_size_hex(kconf, _, path, index=0, unit=None):
dt_compat_enabled(kconf, _, compat): dt_compat_enabled(kconf, _, compat):
dt_node_has_bool_prop(kconf, _, path, prop): dt_node_has_bool_prop(kconf, _, path, prop):
Example Usage Example Usage
------------- -------------
The following example shows the usage of the ``dt_node_reg_addr`` function. The following example shows the usage of the ``dt_node_reg_addr_hex`` function.
This function will take a path to a devicetree node and register the register This function will take a path to a devicetree node and register the register
address of that node: address of that node:
@ -839,7 +845,7 @@ address of that node:
boards/riscv/hifive1_revb/Kconfig.defconfig boards/riscv/hifive1_revb/Kconfig.defconfig
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/spi@10014000,1) default $(dt_node_reg_addr_hex,/soc/spi@10014000,1)
In this example if we examine the dts file for the board: In this example if we examine the dts file for the board:
@ -852,7 +858,7 @@ In this example if we examine the dts file for the board:
... ...
}; };
The ``dt_node_reg_addr`` will search the dts file for a node at the path The ``dt_node_reg_addr_hex`` will search the dts file for a node at the path
``/soc/spi@10014000``. The function than will extract the register address ``/soc/spi@10014000``. The function than will extract the register address
at the index 1. This effective gets the value of ``0x20010000`` and causes at the index 1. This effective gets the value of ``0x20010000`` and causes
the above to look like: the above to look like:

View file

@ -140,31 +140,31 @@ def dt_chosen_label(kconf, _, chosen):
def _node_reg_addr(node, index, unit): def _node_reg_addr(node, index, unit):
if not node: if not node:
return "0x0" return 0
if not node.regs: if not node.regs:
return "0x0" return 0
if int(index) >= len(node.regs): if int(index) >= len(node.regs):
return "0x0" return 0
return hex(node.regs[int(index)].addr >> _dt_units_to_scale(unit)) return node.regs[int(index)].addr >> _dt_units_to_scale(unit)
def _node_reg_size(node, index, unit): def _node_reg_size(node, index, unit):
if not node: if not node:
return "0" return 0
if not node.regs: if not node.regs:
return "0" return 0
if int(index) >= len(node.regs): if int(index) >= len(node.regs):
return "0" return 0
return str(node.regs[int(index)].size >> _dt_units_to_scale(unit)) return node.regs[int(index)].size >> _dt_units_to_scale(unit)
def dt_chosen_reg_addr(kconf, _, chosen, index=0, unit=None): def _dt_chosen_reg_addr(kconf, chosen, index=0, unit=None):
""" """
This function takes a 'chosen' property and treats that property as a path This function takes a 'chosen' property and treats that property as a path
to an EDT node. If it finds an EDT node, it will look to see if that to an EDT node. If it finds an EDT node, it will look to see if that
@ -178,14 +178,14 @@ def dt_chosen_reg_addr(kconf, _, chosen, index=0, unit=None):
'g' or 'G' divide by 1,073,741,824 (1 << 30) 'g' or 'G' divide by 1,073,741,824 (1 << 30)
""" """
if doc_mode or edt is None: if doc_mode or edt is None:
return "0x0" return 0
node = edt.chosen_node(chosen) node = edt.chosen_node(chosen)
return _node_reg_addr(node, index, unit) return _node_reg_addr(node, index, unit)
def dt_chosen_reg_size(kconf, _, chosen, index=0, unit=None): def _dt_chosen_reg_size(kconf, chosen, index=0, unit=None):
""" """
This function takes a 'chosen' property and treats that property as a path This function takes a 'chosen' property and treats that property as a path
to an EDT node. If it finds an EDT node, it will look to see if that node to an EDT node. If it finds an EDT node, it will look to see if that node
@ -199,14 +199,29 @@ def dt_chosen_reg_size(kconf, _, chosen, index=0, unit=None):
'g' or 'G' divide by 1,073,741,824 (1 << 30) 'g' or 'G' divide by 1,073,741,824 (1 << 30)
""" """
if doc_mode or edt is None: if doc_mode or edt is None:
return "0" return 0
node = edt.chosen_node(chosen) node = edt.chosen_node(chosen)
return _node_reg_size(node, index, unit) return _node_reg_size(node, index, unit)
def dt_node_reg_addr(kconf, _, path, index=0, unit=None): def dt_chosen_reg(kconf, name, chosen, index=0, unit=None):
"""
This function just routes to the proper function and converts
the result to either a string int or string hex value.
"""
if name == "dt_chosen_reg_size_int":
return str(_dt_chosen_reg_size(kconf, chosen, index, unit))
if name == "dt_chosen_reg_size_hex":
return hex(_dt_chosen_reg_size(kconf, chosen, index, unit))
if name == "dt_chosen_reg_addr_int":
return str(_dt_chosen_reg_addr(kconf, chosen, index, unit))
if name == "dt_chosen_reg_addr_hex":
return hex(_dt_chosen_reg_addr(kconf, chosen, index, unit))
def _dt_node_reg_addr(kconf, path, index=0, unit=None):
""" """
This function takes a 'path' and looks for an EDT node at that path. If it This function takes a 'path' and looks for an EDT node at that path. If it
finds an EDT node, it will look to see if that node has a register at the finds an EDT node, it will look to see if that node has a register at the
@ -219,17 +234,17 @@ def dt_node_reg_addr(kconf, _, path, index=0, unit=None):
'g' or 'G' divide by 1,073,741,824 (1 << 30) 'g' or 'G' divide by 1,073,741,824 (1 << 30)
""" """
if doc_mode or edt is None: if doc_mode or edt is None:
return "0" return 0
try: try:
node = edt.get_node(path) node = edt.get_node(path)
except edtlib.EDTError: except edtlib.EDTError:
return "0" return 0
return _node_reg_addr(node, index, unit) return _node_reg_addr(node, index, unit)
def dt_node_reg_size(kconf, _, path, index=0, unit=None): def _dt_node_reg_size(kconf, path, index=0, unit=None):
""" """
This function takes a 'path' and looks for an EDT node at that path. If it This function takes a 'path' and looks for an EDT node at that path. If it
finds an EDT node, it will look to see if that node has a register at the finds an EDT node, it will look to see if that node has a register at the
@ -242,16 +257,31 @@ def dt_node_reg_size(kconf, _, path, index=0, unit=None):
'g' or 'G' divide by 1,073,741,824 (1 << 30) 'g' or 'G' divide by 1,073,741,824 (1 << 30)
""" """
if doc_mode or edt is None: if doc_mode or edt is None:
return "0" return 0
try: try:
node = edt.get_node(path) node = edt.get_node(path)
except edtlib.EDTError: except edtlib.EDTError:
return "0" return 0
return _node_reg_size(node, index, unit) return _node_reg_size(node, index, unit)
def dt_node_reg(kconf, name, path, index=0, unit=None):
"""
This function just routes to the proper function and converts
the result to either a string int or string hex value.
"""
if name == "dt_node_reg_size_int":
return str(_dt_node_reg_size(kconf, path, index, unit))
if name == "dt_node_reg_size_hex":
return hex(_dt_node_reg_size(kconf, path, index, unit))
if name == "dt_node_reg_addr_int":
return str(_dt_node_reg_addr(kconf, path, index, unit))
if name == "dt_node_reg_addr_hex":
return hex(_dt_node_reg_addr(kconf, path, index, unit))
def dt_node_has_bool_prop(kconf, _, path, prop): def dt_node_has_bool_prop(kconf, _, path, prop):
""" """
This function takes a 'path' and looks for an EDT node at that path. If it This function takes a 'path' and looks for an EDT node at that path. If it
@ -300,9 +330,13 @@ functions = {
"dt_str_val": (dt_str_val, 1, 1), "dt_str_val": (dt_str_val, 1, 1),
"dt_compat_enabled": (dt_compat_enabled, 1, 1), "dt_compat_enabled": (dt_compat_enabled, 1, 1),
"dt_chosen_label": (dt_chosen_label, 1, 1), "dt_chosen_label": (dt_chosen_label, 1, 1),
"dt_chosen_reg_addr": (dt_chosen_reg_addr, 1, 3), "dt_chosen_reg_addr_int": (dt_chosen_reg, 1, 4),
"dt_chosen_reg_size": (dt_chosen_reg_size, 1, 3), "dt_chosen_reg_addr_hex": (dt_chosen_reg, 1, 4),
"dt_node_reg_addr": (dt_node_reg_addr, 1, 3), "dt_chosen_reg_size_int": (dt_chosen_reg, 1, 4),
"dt_node_reg_size": (dt_node_reg_size, 1, 3), "dt_chosen_reg_size_hex": (dt_chosen_reg, 1, 4),
"dt_node_reg_addr_int": (dt_node_reg, 1, 4),
"dt_node_reg_addr_hex": (dt_node_reg, 1, 4),
"dt_node_reg_size_int": (dt_node_reg, 1, 4),
"dt_node_reg_size_hex": (dt_node_reg, 1, 4),
"dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2), "dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2),
} }

View file

@ -101,60 +101,60 @@ endif # SPI
if CODE_ITCM if CODE_ITCM
config FLASH_SIZE config FLASH_SIZE
default $(dt_node_reg_size,/soc/flexram@400b0000/itcm@0,0,K) default $(dt_node_reg_size_int,/soc/flexram@400b0000/itcm@0,0,K)
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/flexram@400b0000/itcm@0) default $(dt_node_reg_addr_hex,/soc/flexram@400b0000/itcm@0)
endif # CODE_ITCM endif # CODE_ITCM
if CODE_FLEXSPI if CODE_FLEXSPI
config FLASH_SIZE config FLASH_SIZE
default $(dt_node_reg_size,/soc/spi@402a8000,1,K) default $(dt_node_reg_size_int,/soc/spi@402a8000,1,K)
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/spi@402a8000,1) default $(dt_node_reg_addr_hex,/soc/spi@402a8000,1)
endif # CODE_FLEXSPI endif # CODE_FLEXSPI
if CODE_FLEXSPI2 if CODE_FLEXSPI2
config FLASH_SIZE config FLASH_SIZE
default $(dt_node_reg_size,/soc/spi@402a4000,1,K) default $(dt_node_reg_size_int,/soc/spi@402a4000,1,K)
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/spi@402a4000,1) default $(dt_node_reg_addr_hex,/soc/spi@402a4000,1)
endif # CODE_FLEXSPI2 endif # CODE_FLEXSPI2
if DATA_DTCM if DATA_DTCM
config SRAM_SIZE config SRAM_SIZE
default $(dt_node_reg_size,/soc/flexram@400b0000/dtcm@20000000,0,K) default $(dt_node_reg_size_int,/soc/flexram@400b0000/dtcm@20000000,0,K)
config SRAM_BASE_ADDRESS config SRAM_BASE_ADDRESS
default $(dt_node_reg_addr,/soc/flexram@400b0000/dtcm@20000000) default $(dt_node_reg_addr_hex,/soc/flexram@400b0000/dtcm@20000000)
endif # DATA_DTCM endif # DATA_DTCM
if DATA_SEMC if DATA_SEMC
config SRAM_SIZE config SRAM_SIZE
default $(dt_node_reg_size,/memory@80000000,0,K) default $(dt_node_reg_size_int,/memory@80000000,0,K)
config SRAM_BASE_ADDRESS config SRAM_BASE_ADDRESS
default $(dt_node_reg_addr,/memory@80000000) default $(dt_node_reg_addr_hex,/memory@80000000)
endif # DATA_SEMC endif # DATA_SEMC
if DATA_OCRAM if DATA_OCRAM
config SRAM_SIZE config SRAM_SIZE
default $(dt_node_reg_size,/memory@20200000,0,K) default $(dt_node_reg_size_int,/memory@20200000,0,K)
config SRAM_BASE_ADDRESS config SRAM_BASE_ADDRESS
default $(dt_node_reg_addr,/memory@20200000) default $(dt_node_reg_addr_hex,/memory@20200000)
endif # DATA_OCRAM endif # DATA_OCRAM

View file

@ -30,9 +30,9 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC
DT_CHOSEN_Z_FLASH := zephyr,flash DT_CHOSEN_Z_FLASH := zephyr,flash
config FLASH_SIZE config FLASH_SIZE
default $(dt_chosen_reg_size,$(DT_CHOSEN_Z_FLASH),0,K) default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K)
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_FLASH)) default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
endif endif

View file

@ -182,7 +182,7 @@ config SOC_FLASH_RV32M1
DT_CHOSEN_Z_FLASH := zephyr,flash DT_CHOSEN_Z_FLASH := zephyr,flash
config FLASH_BASE_ADDRESS config FLASH_BASE_ADDRESS
default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_FLASH)) default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
endif # FLASH endif # FLASH