diff --git a/Kconfig.zephyr b/Kconfig.zephyr index f7544759009..11420d6d009 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -99,7 +99,7 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition config FLASH_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 depends on HAS_FLASH_LOAD_OFFSET help @@ -112,7 +112,7 @@ config FLASH_LOAD_OFFSET config FLASH_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 depends on HAS_FLASH_LOAD_OFFSET help diff --git a/arch/Kconfig b/arch/Kconfig index a6cf9d8d24e..75fc830a0eb 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -100,7 +100,7 @@ DT_CHOSEN_Z_SRAM := zephyr,sram config SRAM_SIZE 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 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 @@ -108,7 +108,7 @@ config SRAM_SIZE config 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 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 @@ -119,7 +119,7 @@ DT_CHOSEN_Z_FLASH := zephyr,flash config FLASH_SIZE 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 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 @@ -127,7 +127,7 @@ config FLASH_SIZE config 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 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 diff --git a/boards/arm/actinius_icarus/Kconfig.defconfig b/boards/arm/actinius_icarus/Kconfig.defconfig index 008cb96bada..34df16cd0eb 100644 --- a/boards/arm/actinius_icarus/Kconfig.defconfig +++ b/boards/arm/actinius_icarus/Kconfig.defconfig @@ -53,17 +53,17 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition if BOARD_ACTINIUS_ICARUS && TRUSTED_EXECUTION_SECURE 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 if BOARD_ACTINIUS_ICARUS_NS 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 - 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 diff --git a/boards/arm/nrf9160_pca10090/Kconfig.defconfig b/boards/arm/nrf9160_pca10090/Kconfig.defconfig index d8fea918e3e..ad7324b3ca9 100644 --- a/boards/arm/nrf9160_pca10090/Kconfig.defconfig +++ b/boards/arm/nrf9160_pca10090/Kconfig.defconfig @@ -53,17 +53,17 @@ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition if BOARD_NRF9160_PCA10090 && TRUSTED_EXECUTION_SECURE 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 if BOARD_NRF9160_PCA10090NS 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 - 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 diff --git a/boards/riscv/hifive1_revb/Kconfig.defconfig b/boards/riscv/hifive1_revb/Kconfig.defconfig index afd5e19682d..c80d3607843 100644 --- a/boards/riscv/hifive1_revb/Kconfig.defconfig +++ b/boards/riscv/hifive1_revb/Kconfig.defconfig @@ -9,7 +9,7 @@ config HAS_FLASH_LOAD_OFFSET default y 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 default 0x0 diff --git a/doc/guides/kconfig/index.rst b/doc/guides/kconfig/index.rst index 3ddf0225ec2..e8df8f0f561 100644 --- a/doc/guides/kconfig/index.rst +++ b/doc/guides/kconfig/index.rst @@ -816,21 +816,27 @@ Devicetree Related Functions ============================ 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 - dt_chosen_reg_addr(kconf, _, chosen, index=0, unit=None): - dt_chosen_reg_size(kconf, _, chosen, index=0, unit=None): - dt_node_reg_addr(kconf, _, path, index=0, unit=None): - dt_node_reg_size(kconf, _, path, index=0, unit=None): + dt_chosen_reg_addr_int(kconf, _, chosen, index=0, unit=None): + dt_chosen_reg_addr_hex(kconf, _, chosen, index=0, unit=None): + dt_chosen_reg_size_int(kconf, _, chosen, 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_node_has_bool_prop(kconf, _, path, prop): 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 address of that node: @@ -839,7 +845,7 @@ address of that node: boards/riscv/hifive1_revb/Kconfig.defconfig 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: @@ -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 at the index 1. This effective gets the value of ``0x20010000`` and causes the above to look like: diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py index 14345b637a6..ad3f45b2368 100644 --- a/scripts/kconfig/kconfigfunctions.py +++ b/scripts/kconfig/kconfigfunctions.py @@ -140,31 +140,31 @@ def dt_chosen_label(kconf, _, chosen): def _node_reg_addr(node, index, unit): if not node: - return "0x0" + return 0 if not node.regs: - return "0x0" + return 0 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): if not node: - return "0" + return 0 if not node.regs: - return "0" + return 0 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 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) """ if doc_mode or edt is None: - return "0x0" + return 0 node = edt.chosen_node(chosen) 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 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) """ if doc_mode or edt is None: - return "0" + return 0 node = edt.chosen_node(chosen) 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 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) """ if doc_mode or edt is None: - return "0" + return 0 try: node = edt.get_node(path) except edtlib.EDTError: - return "0" + return 0 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 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) """ if doc_mode or edt is None: - return "0" + return 0 try: node = edt.get_node(path) except edtlib.EDTError: - return "0" + return 0 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): """ 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_compat_enabled": (dt_compat_enabled, 1, 1), "dt_chosen_label": (dt_chosen_label, 1, 1), - "dt_chosen_reg_addr": (dt_chosen_reg_addr, 1, 3), - "dt_chosen_reg_size": (dt_chosen_reg_size, 1, 3), - "dt_node_reg_addr": (dt_node_reg_addr, 1, 3), - "dt_node_reg_size": (dt_node_reg_size, 1, 3), + "dt_chosen_reg_addr_int": (dt_chosen_reg, 1, 4), + "dt_chosen_reg_addr_hex": (dt_chosen_reg, 1, 4), + "dt_chosen_reg_size_int": (dt_chosen_reg, 1, 4), + "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), } diff --git a/soc/arm/nxp_imx/rt/Kconfig.defconfig.series b/soc/arm/nxp_imx/rt/Kconfig.defconfig.series index ac3094794fd..62a84eccd87 100644 --- a/soc/arm/nxp_imx/rt/Kconfig.defconfig.series +++ b/soc/arm/nxp_imx/rt/Kconfig.defconfig.series @@ -101,60 +101,60 @@ endif # SPI if CODE_ITCM 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 - default $(dt_node_reg_addr,/soc/flexram@400b0000/itcm@0) + default $(dt_node_reg_addr_hex,/soc/flexram@400b0000/itcm@0) endif # CODE_ITCM if CODE_FLEXSPI 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 - default $(dt_node_reg_addr,/soc/spi@402a8000,1) + default $(dt_node_reg_addr_hex,/soc/spi@402a8000,1) endif # CODE_FLEXSPI if CODE_FLEXSPI2 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 - default $(dt_node_reg_addr,/soc/spi@402a4000,1) + default $(dt_node_reg_addr_hex,/soc/spi@402a4000,1) endif # CODE_FLEXSPI2 if DATA_DTCM 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 - default $(dt_node_reg_addr,/soc/flexram@400b0000/dtcm@20000000) + default $(dt_node_reg_addr_hex,/soc/flexram@400b0000/dtcm@20000000) endif # DATA_DTCM if DATA_SEMC 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 - default $(dt_node_reg_addr,/memory@80000000) + default $(dt_node_reg_addr_hex,/memory@80000000) endif # DATA_SEMC if DATA_OCRAM 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 - default $(dt_node_reg_addr,/memory@20200000) + default $(dt_node_reg_addr_hex,/memory@20200000) endif # DATA_OCRAM diff --git a/soc/arm/xilinx_zynqmp/Kconfig.defconfig b/soc/arm/xilinx_zynqmp/Kconfig.defconfig index 15c63983781..d18f768f380 100644 --- a/soc/arm/xilinx_zynqmp/Kconfig.defconfig +++ b/soc/arm/xilinx_zynqmp/Kconfig.defconfig @@ -30,9 +30,9 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC DT_CHOSEN_Z_FLASH := zephyr,flash 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 - default $(dt_chosen_reg_addr,$(DT_CHOSEN_Z_FLASH)) + default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH)) endif diff --git a/soc/riscv/openisa_rv32m1/Kconfig.defconfig b/soc/riscv/openisa_rv32m1/Kconfig.defconfig index 7940a1c7b6f..180b175ed73 100644 --- a/soc/riscv/openisa_rv32m1/Kconfig.defconfig +++ b/soc/riscv/openisa_rv32m1/Kconfig.defconfig @@ -182,7 +182,7 @@ config SOC_FLASH_RV32M1 DT_CHOSEN_Z_FLASH := zephyr,flash 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