All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D)
@ 2020-12-29  3:34 Simon Glass
  2020-12-29  3:34 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
                   ` (68 more replies)
  0 siblings, 69 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

By way of background, in May[1] and July[2] two 'tiny-dm' series were
sent out, showing a possible way to reduce the overhead of driver model in
SPL. The potential impact of that work was described in the cover
letter[3].

While this was a successful demonstration, all but eliminating the
overhead of driver model, it was not very practical, since it would have
required substantial effort to adapt drivers used in SPL to what was
effectively a parallel driver model.

Instead, after much discussion [4], it was decided to try to use the
tiny-dm methods to adapt the existing of-platdata infrastructure. This is
considerably more work up front but should result in much less effort for
maintainers, along with a single, more consistent driver model.

Of the options mentioned in [3], the following are implemented (in dtoc
only, not driver model) as part of this series (CS=reduces code size,
DS=reduces data size):

   CS - drop driver_bind() and create devices (struct udevice) at
        build-time
   CS - allocate all device- and uclass-private data at build-time

In addition the following was largely completed in an earlier series:

   CS / DS - Combine req_seq and seq and calculate the new value at
        build-time

So this series updates dtoc to support generating devices and uclasses
that are ready for use when SPL starts and don't need to be bound.

This 'build-time' instantiation helps to reduce the code-size overhead of
driver model in SPL.

As part of this series, a new -i option is added to dtoc. This changes it
to emit build-time-instantiated devices. Separate Kconfig options control
instantiation and whether run-time binding is supported.

Several corner cases have come up in making this work on sandbox_spl and
chromebook_coral. It is possible that others will come up in the future,
but it should be possible to adapt things to address these, based on the
work here.

A small tree-wide rename is included to make the naming more consistent.
Without that, the new terminology would be hard to follow.

This is part D of the overall effort. The next series will focus on the
the driver model implementation, as well as updating the documentation.

To find out what the new generated files look like, see the last four
patches of this series.

It is available at u-boot-dm/prepd-working

The final result (WIP, not reviewable) is available at
u-boot-dm/tin-working but note this only works for sandbox_spl and
chromebook_coral

[1] http://patchwork.ozlabs.org/project/uboot/list/?series=179128&state=*
[2] http://patchwork.ozlabs.org/project/uboot/list/?series=187295&state=*
[3] https://lists.denx.de/pipermail/u-boot/2020-July/418433.html
[4] http://patchwork.ozlabs.org/project/uboot/patch/20200525093539.1.Ibf2d19439cde35e39192a9d4a8dad23539fae2e6 at changeid/


Simon Glass (49):
  dtoc: Tidy up pylint warnings in test
  dtoc: Use None to mean stdout
  dtoc: Test the stdout output
  dtoc: Allow providing a directory to write files to
  dtoc: Allow outputing to multiple files
  dtoc: Add an 'all' command
  Makefile: Invoke dtoc only once
  dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()
  dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET()
  dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET()
  dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS
  concurrencytest: Fix Python3 warning
  dtoc: Run tests using test_util
  dtoc: Add a header comment to each generated file
  dtoc: Rename dt-platdata.c to dt-plat.c
  dtoc: Add the method for each command to OutputFile
  dtoc: Allow specifying the base directory for tests
  dtoc: Output nodes in order
  dtoc: Drop dm_populate_phandle_data()
  dtoc: Split source-code scanning to a separate file
  dtoc: Move src_scan tests to a separate file
  dtoc: Tidy up src_scan tests
  dtoc: Scan drivers for available information
  dtoc: Save scan information across test runs
  dtoc: Ignore unwanted files when scanning for drivers
  dtoc: Collect priv/plat struct info from drivers
  dtoc: Support scanning of uclasses
  dtoc: Support scanning of structs in header files
  dtoc: Move test files into a test/ directory
  dtoc: Rename sandbox_i2c_test and sandbox_pmic_test
  dtoc: Add some extra properties to nodes
  dtoc: Make use of node properties
  dtoc: Process nodes to set up required properties
  dtoc: Track nodes which are actually used
  dtoc: Support tracking the phase of U-Boot
  Makefile: Pass the U-Boot phase to dtoc
  dtoc: Support headers needed for drivers
  dtoc: Process driver aliases along with drivers
  dtoc: Warn of duplicate drivers
  dtoc: Read aliases for uclasses
  dtoc: Assign a sequence number to each node
  dtoc: Set up the uclasses that are used
  dtoc: Support processing the root node
  dtoc: Add an option for device instantiation
  dm: of-platadata: Add option for device instantiation
  dtoc: Add support for decl file
  dtoc: Don't generate platform data with instantiation
  dtoc: Generate uclass devices
  dtoc: Generate device instances

 arch/arm/lib/gic-v3-its.c                     |   10 +-
 arch/arm/mach-aspeed/ast2500/clk_ast2500.c    |    2 +-
 .../mach-at91/arm926ejs/at91sam9260_devices.c |    2 +-
 .../arm926ejs/at91sam9m10g45_devices.c        |    2 +-
 arch/arm/mach-imx/mx6/soc.c                   |    2 +-
 arch/arm/mach-imx/mx7/soc.c                   |    2 +-
 arch/arm/mach-k3/am6_init.c                   |    2 +-
 arch/arm/mach-k3/common.c                     |    2 +-
 arch/arm/mach-k3/j721e_init.c                 |    2 +-
 arch/arm/mach-lpc32xx/devices.c               |    4 +-
 arch/arm/mach-mediatek/mt7629/init.c          |    4 +-
 arch/arm/mach-mediatek/mt8516/init.c          |    2 +-
 arch/arm/mach-omap2/am33xx/board.c            |   10 +-
 arch/arm/mach-omap2/omap3/board.c             |    2 +-
 arch/arm/mach-rockchip/misc.c                 |    4 +-
 arch/arm/mach-rockchip/px30/clk_px30.c        |    2 +-
 arch/arm/mach-rockchip/rk3036/clk_rk3036.c    |    2 +-
 arch/arm/mach-rockchip/rk3128/clk_rk3128.c    |    2 +-
 arch/arm/mach-rockchip/rk3188/clk_rk3188.c    |    2 +-
 arch/arm/mach-rockchip/rk322x/clk_rk322x.c    |    2 +-
 arch/arm/mach-rockchip/rk3288/clk_rk3288.c    |    2 +-
 arch/arm/mach-rockchip/rk3308/clk_rk3308.c    |    2 +-
 arch/arm/mach-rockchip/rk3328/clk_rk3328.c    |    2 +-
 arch/arm/mach-rockchip/rk3368/clk_rk3368.c    |    2 +-
 arch/arm/mach-rockchip/rk3399/clk_rk3399.c    |    4 +-
 arch/arm/mach-rockchip/rv1108/clk_rv1108.c    |    2 +-
 arch/arm/mach-socfpga/clock_manager_agilex.c  |    2 +-
 arch/arm/mach-stm32mp/bsec.c                  |    2 +-
 arch/arm/mach-stm32mp/cmd_stm32key.c          |    2 +-
 .../mach-stm32mp/cmd_stm32prog/stm32prog.c    |    6 +-
 arch/arm/mach-stm32mp/cpu.c                   |    6 +-
 arch/arm/mach-tegra/board.c                   |    2 +-
 arch/arm/mach-tegra/board2.c                  |    2 +-
 arch/arm/mach-uniphier/micro-support-card.c   |    2 +-
 arch/arm/mach-zynq/clk.c                      |    4 +-
 arch/arm/mach-zynq/timer.c                    |    2 +-
 arch/mips/mach-mtmips/mt7628/init.c           |    2 +-
 arch/riscv/lib/sifive_clint.c                 |    2 +-
 board/armltd/integrator/integrator.c          |    2 +-
 board/armltd/total_compute/total_compute.c    |    2 +-
 board/armltd/vexpress64/vexpress64.c          |    2 +-
 board/bluewater/gurnard/gurnard.c             |    2 +-
 board/bluewater/snapper9260/snapper9260.c     |    2 +-
 board/cadence/xtfpga/xtfpga.c                 |    4 +-
 board/cavium/thunderx/thunderx.c              |    4 +-
 board/compulab/cm_fx6/cm_fx6.c                |    2 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |    4 +-
 board/dhelectronics/dh_stm32mp1/board.c       |    6 +-
 board/freescale/ls1012afrdm/eth.c             |    4 +-
 board/freescale/ls1012aqds/eth.c              |    4 +-
 board/freescale/ls1012ardb/eth.c              |    4 +-
 board/freescale/lx2160a/lx2160a.c             |    4 +-
 board/gateworks/gw_ventana/gw_ventana.c       |    2 +-
 board/google/gru/gru.c                        |    2 +-
 board/hisilicon/hikey/hikey.c                 |    4 +-
 board/hisilicon/hikey960/hikey960.c           |    2 +-
 board/hisilicon/poplar/poplar.c               |    2 +-
 board/isee/igep00x0/igep00x0.c                |    2 +-
 board/lg/sniper/sniper.c                      |    2 +-
 board/nokia/rx51/rx51.c                       |    2 +-
 board/nvidia/jetson-tk1/jetson-tk1.c          |    2 +-
 board/nvidia/nyan-big/nyan-big.c              |    2 +-
 board/renesas/ulcb/cpld.c                     |    2 +-
 board/sandbox/sandbox.c                       |    2 +-
 board/siemens/corvus/board.c                  |    2 +-
 board/sifive/fu540/fu540.c                    |    2 +-
 board/st/common/cmd_stboard.c                 |    2 +-
 board/st/common/stm32mp_dfu.c                 |    4 +-
 board/st/common/stpmic1.c                     |    4 +-
 board/st/common/stusb160x.c                   |    2 +-
 board/st/stm32mp1/stm32mp1.c                  |   12 +-
 board/st/stv0991/stv0991.c                    |    2 +-
 board/sysam/amcore/amcore.c                   |    2 +-
 board/ti/am335x/board.c                       |    6 +-
 board/ti/j721e/evm.c                          |    4 +-
 board/timll/devkit8000/devkit8000.c           |    2 +-
 board/toradex/apalis-tk1/apalis-tk1.c         |    4 +-
 board/toradex/apalis_imx6/apalis_imx6.c       |    2 +-
 .../toradex/colibri-imx6ull/colibri-imx6ull.c |    2 +-
 board/toradex/colibri_imx6/colibri_imx6.c     |    2 +-
 board/toradex/colibri_pxa270/colibri_pxa270.c |    4 +-
 doc/driver-model/design.rst                   |   18 +-
 doc/driver-model/of-plat.rst                  |   35 +-
 doc/driver-model/remoteproc-framework.rst     |    2 +-
 doc/driver-model/spi-howto.rst                |    4 +-
 drivers/clk/clk_stm32mp1.c                    |    2 +-
 drivers/clk/clk_zynqmp.c                      |    2 +-
 drivers/clk/imx/clk-imx8.c                    |    2 +-
 drivers/clk/mediatek/clk-mtk.c                |    6 +-
 drivers/clk/sifive/fu540-prci.c               |    2 +-
 drivers/core/root.c                           |    3 -
 drivers/crypto/fsl/fsl_rsa.c                  |    2 +-
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c       |    2 +-
 drivers/demo/demo-pdata.c                     |   10 +-
 drivers/firmware/scmi/scmi_agent-uclass.c     |    4 +-
 drivers/gpio/gpio-uclass.c                    |    2 +-
 drivers/gpio/imx_rgpio2p.c                    |    4 +-
 drivers/gpio/mxc_gpio.c                       |    4 +-
 drivers/gpio/mxs_gpio.c                       |    2 +-
 drivers/gpio/sandbox.c                        |    2 +-
 drivers/i2c/rk_i2c.c                          |    2 +-
 drivers/misc/i2c_eeprom.c                     |    2 +-
 drivers/misc/rockchip-efuse.c                 |    2 +-
 drivers/misc/stm32mp_fuse.c                   |   16 +-
 drivers/misc/test_drv.c                       |   11 +-
 drivers/mmc/fsl_esdhc_imx.c                   |    2 +-
 drivers/mmc/mxsmmc.c                          |    2 +-
 drivers/mmc/rockchip_dw_mmc.c                 |    4 +-
 drivers/mtd/nand/raw/arasan_nfc.c             |    2 +-
 drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c |    2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c  |    2 +-
 drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c |    2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c  |    2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c  |    2 +-
 drivers/mtd/nand/raw/davinci_nand.c           |    2 +-
 drivers/mtd/nand/raw/denali_dt.c              |    2 +-
 drivers/mtd/nand/raw/mxs_nand_dt.c            |    2 +-
 drivers/mtd/nand/raw/octeontx_nand.c          |    6 +-
 drivers/mtd/nand/raw/pxa3xx_nand.c            |    2 +-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c        |    2 +-
 drivers/mtd/nand/raw/tegra_nand.c             |    2 +-
 drivers/mtd/nand/raw/vf610_nfc.c              |    2 +-
 drivers/mtd/nand/raw/zynq_nand.c              |    2 +-
 drivers/mtd/spi/sf_probe.c                    |    2 +-
 drivers/pinctrl/nxp/pinctrl-imx6.c            |    2 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c             |    2 +-
 drivers/pinctrl/pinctrl-at91.c                |    2 +-
 drivers/power/pmic/rk8xx.c                    |    2 +-
 drivers/remoteproc/sandbox_testproc.c         |    2 +-
 drivers/reset/reset-ast2500.c                 |    2 +-
 drivers/rtc/emul_rtc.c                        |    2 +-
 drivers/serial/ns16550.c                      |    6 +-
 drivers/serial/sandbox.c                      |    2 +-
 drivers/spi/mxs_spi.c                         |    2 +-
 drivers/spi/rk_spi.c                          |    2 +-
 drivers/sysreset/sysreset_sandbox.c           |    4 +-
 drivers/timer/sandbox_timer.c                 |    2 +-
 drivers/video/lg4573.c                        |    2 +-
 drivers/video/sunxi/sunxi_de2.c               |    2 +-
 drivers/video/sunxi/sunxi_dw_hdmi.c           |    2 +-
 drivers/video/sunxi/sunxi_lcd.c               |    2 +-
 dts/Kconfig                                   |   31 +-
 include/dm/device.h                           |   42 +-
 include/dm/lists.h                            |    2 +-
 include/dm/platdata.h                         |   28 +-
 include/dm/platform_data/spi_pl022.h          |    2 +-
 include/dm/test.h                             |    5 +
 include/dm/uclass.h                           |    2 +-
 include/linux/mtd/spi-nor.h                   |    2 +-
 scripts/Makefile.spl                          |   27 +-
 test/dm/core.c                                |    8 +-
 test/dm/test-fdt.c                            |    6 +-
 tools/concurrencytest/concurrencytest.py      |    4 +-
 tools/dtoc/dtb_platdata.py                    |  911 +++++++++----
 tools/dtoc/dtoc_test_scan_drivers.cxx         |    1 -
 tools/dtoc/main.py                            |   56 +-
 tools/dtoc/src_scan.py                        |  736 ++++++++++
 tools/dtoc/{ => test}/dtoc_test.dts           |    0
 tools/dtoc/{ => test}/dtoc_test_add_prop.dts  |    0
 tools/dtoc/{ => test}/dtoc_test_addr32.dts    |    0
 tools/dtoc/{ => test}/dtoc_test_addr32_64.dts |    0
 tools/dtoc/{ => test}/dtoc_test_addr64.dts    |    0
 tools/dtoc/{ => test}/dtoc_test_addr64_32.dts |    0
 tools/dtoc/test/dtoc_test_alias_bad.dts       |   58 +
 tools/dtoc/test/dtoc_test_alias_bad_path.dts  |   58 +
 tools/dtoc/test/dtoc_test_alias_bad_uc.dts    |   58 +
 tools/dtoc/{ => test}/dtoc_test_aliases.dts   |    0
 tools/dtoc/{ => test}/dtoc_test_bad_reg.dts   |    0
 tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts  |    0
 .../{ => test}/dtoc_test_driver_alias.dts     |    0
 tools/dtoc/{ => test}/dtoc_test_empty.dts     |    0
 tools/dtoc/test/dtoc_test_inst.dts            |   58 +
 .../{ => test}/dtoc_test_invalid_driver.dts   |    0
 tools/dtoc/{ => test}/dtoc_test_phandle.dts   |    0
 .../dtoc/{ => test}/dtoc_test_phandle_bad.dts |    0
 .../{ => test}/dtoc_test_phandle_bad2.dts     |    0
 .../{ => test}/dtoc_test_phandle_cd_gpios.dts |    0
 .../{ => test}/dtoc_test_phandle_reorder.dts  |    0
 .../{ => test}/dtoc_test_phandle_single.dts   |    0
 tools/dtoc/test/dtoc_test_scan_drivers.cxx    |    5 +
 tools/dtoc/{ => test}/dtoc_test_simple.dts    |    4 +-
 tools/dtoc/test_dtoc.py                       | 1190 ++++++++++++++---
 tools/dtoc/test_fdt.py                        |   31 +-
 tools/dtoc/test_src_scan.py                   |  492 +++++++
 tools/patman/tools.py                         |    8 +
 185 files changed, 3482 insertions(+), 808 deletions(-)
 delete mode 100644 tools/dtoc/dtoc_test_scan_drivers.cxx
 create mode 100644 tools/dtoc/src_scan.py
 rename tools/dtoc/{ => test}/dtoc_test.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_add_prop.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32_64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64_32.dts (100%)
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_path.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_uc.dts
 rename tools/dtoc/{ => test}/dtoc_test_aliases.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_driver_alias.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_empty.dts (100%)
 create mode 100644 tools/dtoc/test/dtoc_test_inst.dts
 rename tools/dtoc/{ => test}/dtoc_test_invalid_driver.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_cd_gpios.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_reorder.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_single.dts (100%)
 create mode 100644 tools/dtoc/test/dtoc_test_scan_drivers.cxx
 rename tools/dtoc/{ => test}/dtoc_test_simple.dts (93%)
 create mode 100644 tools/dtoc/test_src_scan.py

-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 01/49] dtoc: Tidy up pylint warnings in test
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
                   ` (67 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

Tidy up this file to reduce the number of pylint warnings.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_dtoc.py | 156 ++++++++++++++++++++++------------------
 1 file changed, 85 insertions(+), 71 deletions(-)

diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c76942c9e2d..4bf90444e14 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -12,21 +12,20 @@ tool.
 import collections
 import os
 import struct
-import sys
 import tempfile
 import unittest
 
-from dtoc import dtb_platdata
 from dtb_platdata import conv_name_to_c
 from dtb_platdata import get_compat_name
 from dtb_platdata import get_value
 from dtb_platdata import tab_to
+from dtoc import dtb_platdata
 from dtoc import fdt
 from dtoc import fdt_util
 from patman import test_util
 from patman import tools
 
-our_path = os.path.dirname(os.path.realpath(__file__))
+OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 
 
 HEADER = '''/*
@@ -56,18 +55,21 @@ C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
 }
 '''
 
+# This is a test so is allowed to access private things in the module it is
+# testing
+# pylint: disable=W0212
 
 def get_dtb_file(dts_fname, capture_stderr=False):
     """Compile a .dts file to a .dtb
 
     Args:
-        dts_fname: Filename of .dts file in the current directory
-        capture_stderr: True to capture and discard stderr output
+        dts_fname (str): Filename of .dts file in the current directory
+        capture_stderr (bool): True to capture and discard stderr output
 
     Returns:
-        Filename of compiled file in output directory
+        str: Filename of compiled file in output directory
     """
-    return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname),
+    return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname),
                                    capture_stderr=capture_stderr)
 
 
@@ -80,20 +82,21 @@ class TestDtoc(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        tools._RemoveOutputDir()
+        tools.FinaliseOutputDir()
 
-    def _WritePythonString(self, fname, data):
+    @staticmethod
+    def _write_python_string(fname, data):
         """Write a string with tabs expanded as done in this Python file
 
         Args:
-            fname: Filename to write to
-            data: Raw string to convert
+            fname (str): Filename to write to
+            data (str): Raw string to convert
         """
         data = data.replace('\t', '\\t')
-        with open(fname, 'w') as fd:
-            fd.write(data)
+        with open(fname, 'w') as fout:
+            fout.write(data)
 
-    def _CheckStrings(self, expected, actual):
+    def _check_strings(self, expected, actual):
         """Check that a string matches its expected value
 
         If the strings do not match, they are written to the /tmp directory in
@@ -101,17 +104,24 @@ class TestDtoc(unittest.TestCase):
         easy comparison and update of the tests.
 
         Args:
-            expected: Expected string
-            actual: Actual string
+            expected (str): Expected string
+            actual (str): Actual string
         """
         if expected != actual:
-            self._WritePythonString('/tmp/binman.expected', expected)
-            self._WritePythonString('/tmp/binman.actual', actual)
+            self._write_python_string('/tmp/binman.expected', expected)
+            self._write_python_string('/tmp/binman.actual', actual)
             print('Failures written to /tmp/binman.{expected,actual}')
-        self.assertEquals(expected, actual)
+        self.assertEqual(expected, actual)
 
+    @staticmethod
+    def run_test(args, dtb_file, output):
+        """Run a test using dtoc
 
-    def run_test(self, args, dtb_file, output):
+        Args:
+            args (list of str): List of arguments for dtoc
+            dtb_file (str): Filename of .dtb file
+            output (str): Filename of output file
+        """
         dtb_platdata.run_steps(args, dtb_file, False, output, True)
 
     def test_name(self):
@@ -160,7 +170,7 @@ class TestDtoc(unittest.TestCase):
         prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third'])
         node = Node({'compatible': prop})
         self.assertEqual((['rockchip_rk3399_sdhci_5_1',
-                          'arasan_sdhci_5_1', 'third']),
+                           'arasan_sdhci_5_1', 'third']),
                          get_compat_name(node))
 
     def test_empty_file(self):
@@ -185,7 +195,7 @@ class TestDtoc(unittest.TestCase):
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_sandbox_i2c_test {
 };
 struct dtd_sandbox_pmic_test {
@@ -209,7 +219,7 @@ struct dtd_sandbox_spl_test {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /i2c at 0 index 0 */
 static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
 };
@@ -293,7 +303,7 @@ U_BOOT_DEVICE(spl_test3) = {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_sandbox_gpio {
 \tconst char *\tgpio_bank_name;
 \tbool\t\tgpio_controller;
@@ -304,7 +314,7 @@ struct dtd_sandbox_gpio {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /gpios at 0 index 0 */
 static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
 \t.gpio_bank_name\t\t= "a",
@@ -326,20 +336,20 @@ void dm_populate_phandle_data(void) {
         """Test output from a device tree file with an invalid driver"""
         dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
         output = tools.GetOutputFilename('output')
-        with test_util.capture_sys_output() as (stdout, stderr):
+        with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(['struct'], dtb_file, False, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_invalid {
 };
 ''', data)
 
-        with test_util.capture_sys_output() as (stdout, stderr):
+        with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /spl-test index 0 */
 static struct dtd_invalid dtv_spl_test = {
 };
@@ -361,7 +371,7 @@ void dm_populate_phandle_data(void) {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_source {
 \tstruct phandle_2_arg clocks[4];
 };
@@ -373,7 +383,7 @@ struct dtd_target {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /phandle2-target index 0 */
 static struct dtd_target dtv_phandle2_target = {
 \t.intval\t\t\t= 0x1,
@@ -445,7 +455,7 @@ void dm_populate_phandle_data(void) {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_source {
 \tstruct phandle_0_arg clocks[1];
 };
@@ -461,7 +471,7 @@ struct dtd_target {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /phandle-target index 1 */
 static struct dtd_target dtv_phandle_target = {
 };
@@ -495,7 +505,7 @@ void dm_populate_phandle_data(void) {
         dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /phandle2-target index 0 */
 static struct dtd_target dtv_phandle2_target = {
 \t.intval\t\t\t= 0x1,
@@ -565,20 +575,20 @@ void dm_populate_phandle_data(void) {
         dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts',
                                 capture_stderr=True)
         output = tools.GetOutputFilename('output')
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test(['struct'], dtb_file, output)
         self.assertIn("Cannot parse 'clocks' in node 'phandle-source'",
-                      str(e.exception))
+                      str(exc.exception))
 
     def test_phandle_bad2(self):
         """Test a phandle target missing its #*-cells property"""
         dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts',
                                 capture_stderr=True)
         output = tools.GetOutputFilename('output')
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test(['struct'], dtb_file, output)
         self.assertIn("Node 'phandle-target' has no cells property",
-                      str(e.exception))
+                      str(exc.exception))
 
     def test_addresses64(self):
         """Test output from a node with a 'reg' property with na=2, ns=2"""
@@ -587,7 +597,7 @@ void dm_populate_phandle_data(void) {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_test1 {
 \tfdt64_t\t\treg[2];
 };
@@ -602,7 +612,7 @@ struct dtd_test3 {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /test1 index 0 */
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
@@ -645,7 +655,7 @@ U_BOOT_DEVICE(test3) = {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_test1 {
 \tfdt32_t\t\treg[2];
 };
@@ -657,7 +667,7 @@ struct dtd_test2 {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /test1 index 0 */
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
@@ -689,7 +699,7 @@ U_BOOT_DEVICE(test2) = {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_test1 {
 \tfdt64_t\t\treg[2];
 };
@@ -704,7 +714,7 @@ struct dtd_test3 {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /test1 index 0 */
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x123400000000, 0x5678},
@@ -747,7 +757,7 @@ U_BOOT_DEVICE(test3) = {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_test1 {
 \tfdt64_t\t\treg[2];
 };
@@ -762,7 +772,7 @@ struct dtd_test3 {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /test1 index 0 */
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x567800000000},
@@ -803,20 +813,21 @@ U_BOOT_DEVICE(test3) = {
         # Capture stderr since dtc will emit warnings for this file
         dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True)
         output = tools.GetOutputFilename('output')
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test(['struct'], dtb_file, output)
         self.assertIn("Node 'spl-test' reg property is not an int",
-                      str(e.exception))
+                      str(exc.exception))
 
     def test_bad_reg2(self):
         """Test that a reg property with an invalid cell count is detected"""
         # Capture stderr since dtc will emit warnings for this file
         dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True)
         output = tools.GetOutputFilename('output')
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test(['struct'], dtb_file, output)
-        self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
-                      str(e.exception))
+        self.assertIn(
+            "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
+            str(exc.exception))
 
     def test_add_prop(self):
         """Test that a subequent node can add a new property to a struct"""
@@ -825,7 +836,7 @@ U_BOOT_DEVICE(test3) = {
         self.run_test(['struct'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(HEADER + '''
+        self._check_strings(HEADER + '''
 struct dtd_sandbox_spl_test {
 \tfdt32_t\t\tintarray;
 \tfdt32_t\t\tintval;
@@ -835,7 +846,7 @@ struct dtd_sandbox_spl_test {
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             data = infile.read()
-        self._CheckStrings(C_HEADER + '''
+        self._check_strings(C_HEADER + '''
 /* Node /spl-test index 0 */
 static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.intval\t\t\t= 0x1,
@@ -860,37 +871,40 @@ U_BOOT_DEVICE(spl_test2) = {
 
 ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
-    def testStdout(self):
+    def test_stdout(self):
         """Test output to stdout"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
-        with test_util.capture_sys_output() as (stdout, stderr):
+        with test_util.capture_sys_output() as _:
             self.run_test(['struct'], dtb_file, '-')
 
-    def testNoCommand(self):
+    def test_no_command(self):
         """Test running dtoc without a command"""
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test([], '', '')
         self.assertIn("Please specify a command: struct, platdata",
-                      str(e.exception))
+                      str(exc.exception))
 
-    def testBadCommand(self):
+    def test_bad_command(self):
         """Test running dtoc with an invalid command"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
-        with self.assertRaises(ValueError) as e:
+        with self.assertRaises(ValueError) as exc:
             self.run_test(['invalid-cmd'], dtb_file, output)
         self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
-                      str(e.exception))
+                      str(exc.exception))
 
-    def testScanDrivers(self):
+    @staticmethod
+    def test_scan_drivers():
         """Test running dtoc with additional drivers to scan"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
-        with test_util.capture_sys_output() as (stdout, stderr):
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
-                               [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+        with test_util.capture_sys_output() as _:
+            dtb_platdata.run_steps(
+                ['struct'], dtb_file, False, output, True,
+                [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
 
-    def testUnicodeError(self):
+    @staticmethod
+    def test_unicode_error():
         """Test running dtoc with an invalid unicode file
 
         To be able to perform this test without adding a weird text file which
@@ -900,14 +914,14 @@ U_BOOT_DEVICE(spl_test2) = {
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
         driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
-        with open(driver_fn, 'wb+') as df:
-            df.write(b'\x81')
+        with open(driver_fn, 'wb+') as fout:
+            fout.write(b'\x81')
 
-        with test_util.capture_sys_output() as (stdout, stderr):
+        with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
-                               [driver_fn])
+                                   [driver_fn])
 
-    def testDriver(self):
+    def test_driver(self):
         """Test the Driver class"""
         drv1 = dtb_platdata.Driver('fred')
         drv2 = dtb_platdata.Driver('mary')
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 02/49] dtoc: Use None to mean stdout
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
  2020-12-29  3:34 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
                   ` (66 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

At present dtoc uses '-' internally to mean that output should go to
stdout. This is not necessary and None is more convenient. Update it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 10 +++++-----
 tools/dtoc/main.py         |  2 +-
 tools/dtoc/test_dtoc.py    |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 5b1bb7e5fd9..118b1a5f432 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -237,12 +237,12 @@ class DtbPlatdata():
         file.
 
         Args:
-            fname (str): Filename to send output to, or '-' for stdout
+            fname (str): Filename to send output to, or None for stdout
         """
-        if fname == '-':
-            self._outfile = sys.stdout
-        else:
+        if fname:
             self._outfile = open(fname, 'w')
+        else:
+            self._outfile = sys.stdout
 
     def out(self, line):
         """Output a string to the output file
@@ -765,7 +765,7 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
         args (list): List of non-option arguments provided to the problem
         dtb_file (str): Filename of dtb file to process
         include_disabled (bool): True to include disabled nodes
-        output (str): Name of output file
+        output (str): Name of output file (None for stdout)
         warning_disabled (bool): True to avoid showing warnings about missing
             drivers
         drivers_additional (list): List of additional drivers to use during
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index b94d9c301f4..7686c8784d8 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -91,7 +91,7 @@ parser.add_option('-d', '--dtb-file', action='store',
                   help='Specify the .dtb input file')
 parser.add_option('--include-disabled', action='store_true',
                   help='Include disabled nodes')
-parser.add_option('-o', '--output', action='store', default='-',
+parser.add_option('-o', '--output', action='store',
                   help='Select output filename')
 parser.add_option('-P', '--processes', type=int,
                   help='set number of processes to use for running tests')
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 4bf90444e14..41a10eb4004 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -875,7 +875,7 @@ U_BOOT_DEVICE(spl_test2) = {
         """Test output to stdout"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         with test_util.capture_sys_output() as _:
-            self.run_test(['struct'], dtb_file, '-')
+            self.run_test(['struct'], dtb_file, None)
 
     def test_no_command(self):
         """Test running dtoc without a command"""
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 03/49] dtoc: Test the stdout output
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
  2020-12-29  3:34 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
  2020-12-29  3:34 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
                   ` (65 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

Normally dtoc outputs to a file but it also offers a way to write output
to stdout. At present the test for that does not actually check that the
output is correct. Add this to the test.

This uses a member variable to hold the expected text, so it can be used
in muitiple places.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_dtoc.py | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 41a10eb4004..7cf2a5187c6 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -188,14 +188,7 @@ class TestDtoc(unittest.TestCase):
         self.assertEqual(C_HEADER.splitlines() + [''] +
                          C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
 
-    def test_simple(self):
-        """Test output from some simple nodes with various types of data"""
-        dtb_file = get_dtb_file('dtoc_test_simple.dts')
-        output = tools.GetOutputFilename('output')
-        self.run_test(['struct'], dtb_file, output)
-        with open(output) as infile:
-            data = infile.read()
-        self._check_strings(HEADER + '''
+    struct_text = HEADER + '''
 struct dtd_sandbox_i2c_test {
 };
 struct dtd_sandbox_pmic_test {
@@ -214,12 +207,9 @@ struct dtd_sandbox_spl_test {
 \tconst char *\tstringarray[3];
 \tconst char *\tstringval;
 };
-''', data)
+'''
 
-        self.run_test(['platdata'], dtb_file, output)
-        with open(output) as infile:
-            data = infile.read()
-        self._check_strings(C_HEADER + '''
+    platdata_text = C_HEADER + '''
 /* Node /i2c at 0 index 0 */
 static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
 };
@@ -294,7 +284,23 @@ U_BOOT_DEVICE(spl_test3) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA
+
+    def test_simple(self):
+        """Test output from some simple nodes with various types of data"""
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        output = tools.GetOutputFilename('output')
+        self.run_test(['struct'], dtb_file, output)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(self.struct_text, data)
+
+        self.run_test(['platdata'], dtb_file, output)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(self.platdata_text, data)
 
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
@@ -874,8 +880,9 @@ U_BOOT_DEVICE(spl_test2) = {
     def test_stdout(self):
         """Test output to stdout"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
-        with test_util.capture_sys_output() as _:
+        with test_util.capture_sys_output() as (stdout, _):
             self.run_test(['struct'], dtb_file, None)
+        self._check_strings(self.struct_text, stdout.getvalue())
 
     def test_no_command(self):
         """Test running dtoc without a command"""
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 04/49] dtoc: Allow providing a directory to write files to
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (2 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
                   ` (64 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

At present dtoc writes only a single file on each invocation. U-Boot
writes the two files it needs by separate invocations of dtoc. Since dtoc
now scans all U-Boot driver source, this is fairly slow (about 1 second
per file).

It would be better if dtoc could write all the files at once.

In preparation for this, add a way to specify an output directory for the
files.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py |  8 ++++++--
 tools/dtoc/main.py         |  7 ++++++-
 tools/dtoc/test_dtoc.py    | 14 +++++++-------
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 118b1a5f432..62a65d6214a 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -757,8 +757,9 @@ class DtbPlatdata():
 
         self.out(''.join(self.get_buf()))
 
-def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
-              drivers_additional=None):
+
+def run_steps(args, dtb_file, include_disabled, output, output_dirs,
+              warning_disabled=False, drivers_additional=None):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -766,6 +767,9 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
         dtb_file (str): Filename of dtb file to process
         include_disabled (bool): True to include disabled nodes
         output (str): Name of output file (None for stdout)
+        output_dirs (tuple of str):
+            Directory to put C output files
+            Directory to put H output files
         warning_disabled (bool): True to avoid showing warnings about missing
             drivers
         drivers_additional (list): List of additional drivers to use during
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 7686c8784d8..244c184cedd 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -87,6 +87,10 @@ if __name__ != '__main__':
 parser = OptionParser()
 parser.add_option('-B', '--build-dir', type='string', default='b',
         help='Directory containing the build output')
+parser.add_option('-c', '--c-output-dir', action='store',
+                  help='Select output directory for C files')
+parser.add_option('-C', '--h-output-dir', action='store',
+                  help='Select output directory for H files (defaults to --c-output-di)')
 parser.add_option('-d', '--dtb-file', action='store',
                   help='Specify the .dtb input file')
 parser.add_option('--include-disabled', action='store_true',
@@ -111,4 +115,5 @@ elif options.test_coverage:
 
 else:
     dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
-                           options.output)
+                           options.output,
+                           [options.c_output_dir, options.h_output_dir])
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 7cf2a5187c6..b023a1e14a5 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -122,7 +122,7 @@ class TestDtoc(unittest.TestCase):
             dtb_file (str): Filename of .dtb file
             output (str): Filename of output file
         """
-        dtb_platdata.run_steps(args, dtb_file, False, output, True)
+        dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -343,7 +343,7 @@ void dm_populate_phandle_data(void) {
         dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output)
+            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
         with open(output) as infile:
             data = infile.read()
         self._check_strings(HEADER + '''
@@ -352,7 +352,7 @@ struct dtd_invalid {
 ''', data)
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
+            dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -508,7 +508,7 @@ void dm_populate_phandle_data(void) {
         """Test that phandle targets are generated when unsing cd-gpios"""
         dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
         output = tools.GetOutputFilename('output')
-        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)
+        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -907,7 +907,7 @@ U_BOOT_DEVICE(spl_test2) = {
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(
-                ['struct'], dtb_file, False, output, True,
+                ['struct'], dtb_file, False, output, [], True,
                 [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
 
     @staticmethod
@@ -925,8 +925,8 @@ U_BOOT_DEVICE(spl_test2) = {
             fout.write(b'\x81')
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
-                                   [driver_fn])
+            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
+                                   True, [driver_fn])
 
     def test_driver(self):
         """Test the Driver class"""
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 05/49] dtoc: Allow outputing to multiple files
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (3 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
                   ` (63 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

Implement the 'output directory' feature, allowing dtoc to write the
output files separately to the supplied directories. This allows us to
handle the struct and platdata output in one run of dtoc.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 96 ++++++++++++++++++++++++++++++++++----
 tools/dtoc/test_dtoc.py    |  8 ++++
 2 files changed, 94 insertions(+), 10 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 62a65d6214a..e2fddfd3018 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -15,6 +15,7 @@ See doc/driver-model/of-plat.rst for more informaiton
 
 import collections
 import copy
+from enum import IntEnum
 import os
 import re
 import sys
@@ -49,6 +50,15 @@ TYPE_NAMES = {
 STRUCT_PREFIX = 'dtd_'
 VAL_PREFIX = 'dtv_'
 
+class Ftype(IntEnum):
+    SOURCE, HEADER = range(2)
+
+
+# This holds information about each type of output file dtoc can create
+# type: Type of file (Ftype)
+# fname: Filename excluding directory, e.g. 'dt-platdata.c'
+OutputFile = collections.namedtuple('OutputFile', ['ftype', 'fname'])
+
 # This holds information about a property which includes phandles.
 #
 # max_args: integer: Maximum number or arguments that any phandle uses (int).
@@ -180,6 +190,8 @@ class DtbPlatdata():
                 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
         _drivers_additional: List of additional drivers to use during scanning
+        _dirname: Directory to hold output files, or None for none (all files
+            go to stdout)
     """
     def __init__(self, dtb_fname, include_disabled, warning_disabled,
                  drivers_additional=None):
@@ -193,6 +205,7 @@ class DtbPlatdata():
         self._drivers = {}
         self._driver_aliases = {}
         self._drivers_additional = drivers_additional or []
+        self._dirnames = [None] * len(Ftype)
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -230,20 +243,68 @@ class DtbPlatdata():
 
         return compat_list_c[0], compat_list_c[1:]
 
-    def setup_output(self, fname):
+    def setup_output_dirs(self, output_dirs):
+        """Set up the output directories
+
+        This should be done before setup_output() is called
+
+        Args:
+            output_dirs (tuple of str):
+                Directory to use for C output files.
+                    Use None to write files relative current directory
+                Directory to use for H output files.
+                    Defaults to the C output dir
+        """
+        def process_dir(ftype, dirname):
+            if dirname:
+                os.makedirs(dirname, exist_ok=True)
+                self._dirnames[ftype] = dirname
+
+        if output_dirs:
+            c_dirname = output_dirs[0]
+            h_dirname = output_dirs[1] if len(output_dirs) > 1 else c_dirname
+            process_dir(Ftype.SOURCE, c_dirname)
+            process_dir(Ftype.HEADER, h_dirname)
+
+    def setup_output(self, ftype, fname):
         """Set up the output destination
 
         Once this is done, future calls to self.out() will output to this
-        file.
+        file. The file used is as follows:
+
+        self._dirnames[ftype] is None: output to fname, or stdout if None
+        self._dirnames[ftype] is not None: output to fname in that directory
+
+        Calling this function multiple times will close the old file and open
+        the new one. If they are the same file, nothing happens and output will
+        continue to the same file.
 
         Args:
-            fname (str): Filename to send output to, or None for stdout
+            ftype (str): Type of file to create ('c' or 'h')
+            fname (str): Filename to send output to. If there is a directory in
+                self._dirnames for this file type, it will be put in that
+                directory
         """
-        if fname:
-            self._outfile = open(fname, 'w')
+        dirname = self._dirnames[ftype]
+        if dirname:
+            pathname = os.path.join(dirname, fname)
+            if self._outfile:
+                self._outfile.close()
+            self._outfile = open(pathname, 'w')
+        elif fname:
+            if not self._outfile:
+                self._outfile = open(fname, 'w')
         else:
             self._outfile = sys.stdout
 
+    def finish_output(self):
+        """Finish outputing to a file
+
+        This closes the output file, if one is in use
+        """
+        if self._outfile != sys.stdout:
+            self._outfile.close()
+
     def out(self, line):
         """Output a string to the output file
 
@@ -758,6 +819,15 @@ class DtbPlatdata():
         self.out(''.join(self.get_buf()))
 
 
+# Types of output file we understand
+# key: Command used to generate this file
+# value: OutputFile for this command
+OUTPUT_FILES = {
+    'struct': OutputFile(Ftype.HEADER, 'dt-structs-gen.h'),
+    'platdata': OutputFile(Ftype.SOURCE, 'dt-platdata.c'),
+    }
+
+
 def run_steps(args, dtb_file, include_disabled, output, output_dirs,
               warning_disabled=False, drivers_additional=None):
     """Run all the steps of the dtoc tool
@@ -778,7 +848,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
         ValueError: if args has no command, or an unknown command
     """
     if not args:
-        raise ValueError('Please specify a command: struct, platdata')
+        raise ValueError('Please specify a command: struct, platdata, all')
+    if output and output_dirs and any(output_dirs):
+        raise ValueError('Must specify either output or output_dirs, not both')
 
     plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled,
                        drivers_additional)
@@ -786,15 +858,19 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     plat.scan_dtb()
     plat.scan_tree()
     plat.scan_reg_sizes()
-    plat.setup_output(output)
+    plat.setup_output_dirs(output_dirs)
     structs = plat.scan_structs()
     plat.scan_phandles()
 
     for cmd in args[0].split(','):
+        outfile = OUTPUT_FILES.get(cmd)
+        if not outfile:
+            raise ValueError("Unknown command '%s': (use: %s)" %
+                             (cmd, ', '.join(OUTPUT_FILES.keys())))
+        plat.setup_output(outfile.ftype,
+                          outfile.fname if output_dirs else output)
         if cmd == 'struct':
             plat.generate_structs(structs)
         elif cmd == 'platdata':
             plat.generate_tables()
-        else:
-            raise ValueError("Unknown command '%s': (use: struct, platdata)" %
-                             cmd)
+    plat.finish_output()
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index b023a1e14a5..6f9af905e82 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -884,6 +884,14 @@ U_BOOT_DEVICE(spl_test2) = {
             self.run_test(['struct'], dtb_file, None)
         self._check_strings(self.struct_text, stdout.getvalue())
 
+    def test_multi_to_file(self):
+        """Test output of multiple pieces to a single file"""
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        output = tools.GetOutputFilename('output')
+        self.run_test(['struct,platdata'], dtb_file, output)
+        data = tools.ReadFile(output, binary=False)
+        self._check_strings(self.struct_text + self.platdata_text, data)
+
     def test_no_command(self):
         """Test running dtoc without a command"""
         with self.assertRaises(ValueError) as exc:
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 06/49] dtoc: Add an 'all' command
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (4 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
                   ` (62 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

With upcoming changes, dtoc will output several files for different
of-platdata components.

Add a way to output all ava!ilable files at once ('all'), to the
appropriate directories, without needing to specify each one invidually.

This puts the commands in alphabetical order, so update the tests
accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py |  7 +++++--
 tools/dtoc/main.py         |  6 +-----
 tools/dtoc/test_dtoc.py    | 40 +++++++++++++++++++++++++++++++++++---
 tools/patman/tools.py      |  8 ++++++++
 4 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index e2fddfd3018..7bd19891139 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -862,11 +862,14 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     structs = plat.scan_structs()
     plat.scan_phandles()
 
-    for cmd in args[0].split(','):
+    cmds = args[0].split(',')
+    if 'all' in cmds:
+        cmds = sorted(OUTPUT_FILES.keys())
+    for cmd in cmds:
         outfile = OUTPUT_FILES.get(cmd)
         if not outfile:
             raise ValueError("Unknown command '%s': (use: %s)" %
-                             (cmd, ', '.join(OUTPUT_FILES.keys())))
+                             (cmd, ', '.join(sorted(OUTPUT_FILES.keys()))))
         plat.setup_output(outfile.ftype,
                           outfile.fname if output_dirs else output)
         if cmd == 'struct':
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 244c184cedd..f82ee782682 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -13,11 +13,7 @@ having to link against libfdt. By putting the data from the device tree into
 C structures, normal C code can be used. This helps to reduce the size of the
 compiled program.
 
-Dtoc produces two output files:
-
-   dt-structs.h  - contains struct definitions
-   dt-platdata.c - contains data from the device tree using the struct
-                      definitions, as well as U-Boot driver definitions.
+Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py
 
 This tool is used in U-Boot to provide device tree data to SPL without
 increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 6f9af905e82..fb65f284ceb 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -10,6 +10,7 @@ tool.
 """
 
 import collections
+import glob
 import os
 import struct
 import tempfile
@@ -302,6 +303,11 @@ U_BOOT_DEVICE(spl_test3) = {
 
         self._check_strings(self.platdata_text, data)
 
+        # Try the 'all' command
+        self.run_test(['all'], dtb_file, output)
+        data = tools.ReadFile(output, binary=False)
+        self._check_strings(self.platdata_text + self.struct_text, data)
+
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
         dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
@@ -888,9 +894,9 @@ U_BOOT_DEVICE(spl_test2) = {
         """Test output of multiple pieces to a single file"""
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
-        self.run_test(['struct,platdata'], dtb_file, output)
+        self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
-        self._check_strings(self.struct_text + self.platdata_text, data)
+        self._check_strings(self.platdata_text + self.struct_text, data)
 
     def test_no_command(self):
         """Test running dtoc without a command"""
@@ -905,7 +911,7 @@ U_BOOT_DEVICE(spl_test2) = {
         output = tools.GetOutputFilename('output')
         with self.assertRaises(ValueError) as exc:
             self.run_test(['invalid-cmd'], dtb_file, output)
-        self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
+        self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
                       str(exc.exception))
 
     @staticmethod
@@ -945,3 +951,31 @@ U_BOOT_DEVICE(spl_test2) = {
         self.assertEqual(drv1, drv3)
         self.assertNotEqual(drv1, drv2)
         self.assertNotEqual(drv2, drv3)
+
+    def test_output_conflict(self):
+        """Test a conflict between and output dirs and output file"""
+        with self.assertRaises(ValueError) as exc:
+            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True)
+        self.assertIn("Must specify either output or output_dirs, not both",
+                      str(exc.exception))
+
+    def test_output_dirs(self):
+        """Test outputting files to a directory"""
+        # Remove the directory so that files from other tests are not there
+        tools._RemoveOutputDir()
+        tools.PrepareOutputDir(None)
+
+        # This should create the .dts and .dtb in the output directory
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        outdir = tools.GetOutputDir()
+        fnames = glob.glob(outdir + '/*')
+        self.assertEqual(2, len(fnames))
+
+        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
+        fnames = glob.glob(outdir + '/*')
+        self.assertEqual(4, len(fnames))
+
+        leafs = set(os.path.basename(fname) for fname in fnames)
+        self.assertEqual(
+            {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'},
+            leafs)
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 00c7013924d..ba8b67f3ee1 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -94,6 +94,14 @@ def GetOutputFilename(fname):
     """
     return os.path.join(outdir, fname)
 
+def GetOutputDir():
+    """Return the current output directory
+
+    Returns:
+        str: The output directory
+    """
+    return outdir
+
 def _FinaliseForTest():
     """Remove the output directory (for use by tests)"""
     global outdir
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 07/49] Makefile: Invoke dtoc only once
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (5 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() Simon Glass
                   ` (61 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

Update the Makefile to run dtoc only once, generating all required files.
This saves time since there is a lot of processing in each invocation of
dtoc.

We already have a variable for the object files to build, so use that
instead of repeating the same filenames. Add a C version of this also,
for the same reason.

This makes it easier to add new C files (generated by dtoc) to the build
later, as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 scripts/Makefile.spl | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 161c15b200e..3d60cf5120e 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -121,6 +121,7 @@ u-boot-spl-init := $(head-y)
 u-boot-spl-main := $(libs-y)
 ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
 u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
+u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
 endif
 
 # Linker Script
@@ -310,17 +311,15 @@ pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
 	-d $(obj)/$(SPL_BIN).dtb
 
-quiet_cmd_dtocc = DTOC C  $@
-cmd_dtocc = $(DTOC_ARGS) -o $@ platdata
-
-quiet_cmd_dtoch = DTOC H  $@
-cmd_dtoch = $(DTOC_ARGS) -o $@ struct
+quiet_cmd_dtoc = DTOC    $@
+cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
 
 quiet_cmd_plat = PLAT    $@
 cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@)
 
-targets += $(obj)/dts/dt-platdata.o
-$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \
+targets += $(u-boot-spl-platdata)
+
+$(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c \
 		include/generated/dt-structs-gen.h prepare FORCE
 	$(call if_changed,plat)
 
@@ -328,11 +327,9 @@ PHONY += dts_dir
 dts_dir:
 	$(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts)
 
-include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
-	$(call if_changed,dtoch)
-
-$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE
-	$(call if_changed,dtocc)
+include/generated/dt-structs-gen.h $(u-boot-spl-platdata_c) &: \
+		$(obj)/$(SPL_BIN).dtb dts_dir FORCE
+	$(call if_changed,dtoc)
 
 ifdef CONFIG_SAMSUNG
 ifdef CONFIG_VAR_SIZE_SPL
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (6 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2021-01-06  3:40   ` Walter Lozano
  2021-01-06 15:13   ` Simon Glass
  2020-12-29  3:34 ` [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() Simon Glass
                   ` (60 subsequent siblings)
  68 siblings, 2 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

The current macro is a misnomer since it does not declare a device
directly. Instead, it declares driver_info record which U-Boot uses at
runtime to create a device.

The distinction seems somewhat minor most of the time, but is becomes
quite confusing when we actually want to declare a device, with
of-platdata. We are left trying to distinguish between a device which
isn't actually device, and a device that is (perhaps an 'instance'?)

It seems better to rename this macro to describe what it actually is. The
macros is not widely used, since boards should use devicetree to declare
devices.

Rename it to U_BOOT_DRVINFO(), which indicates clearly that this is
declaring a new driver_info record, not a device.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 .../mach-at91/arm926ejs/at91sam9260_devices.c |  2 +-
 .../arm926ejs/at91sam9m10g45_devices.c        |  2 +-
 arch/arm/mach-imx/mx6/soc.c                   |  2 +-
 arch/arm/mach-imx/mx7/soc.c                   |  2 +-
 arch/arm/mach-lpc32xx/devices.c               |  4 +-
 arch/arm/mach-omap2/am33xx/board.c            | 10 +--
 arch/arm/mach-omap2/omap3/board.c             |  2 +-
 arch/arm/mach-tegra/board.c                   |  2 +-
 arch/arm/mach-tegra/board2.c                  |  2 +-
 board/armltd/integrator/integrator.c          |  2 +-
 board/armltd/total_compute/total_compute.c    |  2 +-
 board/armltd/vexpress64/vexpress64.c          |  2 +-
 board/bluewater/gurnard/gurnard.c             |  2 +-
 board/bluewater/snapper9260/snapper9260.c     |  2 +-
 board/cadence/xtfpga/xtfpga.c                 |  4 +-
 board/cavium/thunderx/thunderx.c              |  4 +-
 board/compulab/cm_fx6/cm_fx6.c                |  2 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |  4 +-
 board/freescale/ls1012afrdm/eth.c             |  4 +-
 board/freescale/ls1012aqds/eth.c              |  4 +-
 board/freescale/ls1012ardb/eth.c              |  4 +-
 board/freescale/lx2160a/lx2160a.c             |  4 +-
 board/gateworks/gw_ventana/gw_ventana.c       |  2 +-
 board/hisilicon/hikey/hikey.c                 |  4 +-
 board/hisilicon/hikey960/hikey960.c           |  2 +-
 board/hisilicon/poplar/poplar.c               |  2 +-
 board/isee/igep00x0/igep00x0.c                |  2 +-
 board/lg/sniper/sniper.c                      |  2 +-
 board/nokia/rx51/rx51.c                       |  2 +-
 board/sandbox/sandbox.c                       |  2 +-
 board/siemens/corvus/board.c                  |  2 +-
 board/st/stv0991/stv0991.c                    |  2 +-
 board/sysam/amcore/amcore.c                   |  2 +-
 board/ti/am335x/board.c                       |  6 +-
 board/timll/devkit8000/devkit8000.c           |  2 +-
 board/toradex/apalis_imx6/apalis_imx6.c       |  2 +-
 .../toradex/colibri-imx6ull/colibri-imx6ull.c |  2 +-
 board/toradex/colibri_imx6/colibri_imx6.c     |  2 +-
 board/toradex/colibri_pxa270/colibri_pxa270.c |  4 +-
 doc/driver-model/design.rst                   | 18 ++---
 doc/driver-model/of-plat.rst                  | 12 ++--
 doc/driver-model/remoteproc-framework.rst     |  2 +-
 doc/driver-model/spi-howto.rst                |  4 +-
 drivers/crypto/fsl/fsl_rsa.c                  |  2 +-
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c       |  2 +-
 drivers/demo/demo-pdata.c                     | 10 +--
 drivers/gpio/imx_rgpio2p.c                    |  4 +-
 drivers/gpio/mxc_gpio.c                       |  2 +-
 drivers/remoteproc/sandbox_testproc.c         |  2 +-
 drivers/rtc/emul_rtc.c                        |  2 +-
 drivers/serial/sandbox.c                      |  2 +-
 drivers/sysreset/sysreset_sandbox.c           |  4 +-
 drivers/timer/sandbox_timer.c                 |  2 +-
 drivers/video/sunxi/sunxi_de2.c               |  2 +-
 drivers/video/sunxi/sunxi_dw_hdmi.c           |  2 +-
 drivers/video/sunxi/sunxi_lcd.c               |  2 +-
 dts/Kconfig                                   |  8 +--
 include/dm/device.h                           |  4 +-
 include/dm/lists.h                            |  2 +-
 include/dm/platdata.h                         | 16 ++---
 include/dm/platform_data/spi_pl022.h          |  2 +-
 test/dm/core.c                                |  6 +-
 tools/dtoc/dtb_platdata.py                    |  8 +--
 tools/dtoc/test_dtoc.py                       | 66 +++++++++----------
 64 files changed, 148 insertions(+), 148 deletions(-)

diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
index 9d787197f35..c10571fa28a 100644
--- a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
@@ -219,7 +219,7 @@ static const struct at91_port_plat at91sam9260_plat[] = {
 	{ ATMEL_BASE_PIOC, "PC" },
 };
 
-U_BOOT_DEVICES(at91sam9260_gpios) = {
+U_BOOT_DRVINFOS(at91sam9260_gpios) = {
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
index f503553b926..d517810c991 100644
--- a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
+++ b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
@@ -175,7 +175,7 @@ static const struct at91_port_plat at91sam9260_plat[] = {
 	{ ATMEL_BASE_PIOE, "PE" },
 };
 
-U_BOOT_DEVICES(at91sam9260_gpios) = {
+U_BOOT_DRVINFOS(at91sam9260_gpios) = {
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
 	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
index 1649f6d9480..bf6dddfdc9d 100644
--- a/arch/arm/mach-imx/mx6/soc.c
+++ b/arch/arm/mach-imx/mx6/soc.c
@@ -44,7 +44,7 @@ static const struct imx_thermal_plat imx6_thermal_plat = {
 	.fuse_word = 6,
 };
 
-U_BOOT_DEVICE(imx6_thermal) = {
+U_BOOT_DRVINFO(imx6_thermal) = {
 	.name = "imx_thermal",
 	.plat = &imx6_thermal_plat,
 };
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c
index 13593994f14..fda25ba66a3 100644
--- a/arch/arm/mach-imx/mx7/soc.c
+++ b/arch/arm/mach-imx/mx7/soc.c
@@ -60,7 +60,7 @@ static const struct imx_thermal_plat imx7_thermal_plat = {
 	.fuse_word = 3,
 };
 
-U_BOOT_DEVICE(imx7_thermal) = {
+U_BOOT_DRVINFO(imx7_thermal) = {
 	.name = "imx_thermal",
 	.plat = &imx7_thermal_plat,
 };
diff --git a/arch/arm/mach-lpc32xx/devices.c b/arch/arm/mach-lpc32xx/devices.c
index 04e026a8b77..e1e2e0d0949 100644
--- a/arch/arm/mach-lpc32xx/devices.c
+++ b/arch/arm/mach-lpc32xx/devices.c
@@ -62,7 +62,7 @@ static const struct lpc32xx_hsuart_plat lpc32xx_hsuart[] = {
 };
 #endif
 
-U_BOOT_DEVICES(lpc32xx_uarts) = {
+U_BOOT_DRVINFOS(lpc32xx_uarts) = {
 #if defined(CONFIG_LPC32XX_HSUART)
 	{ "lpc32xx_hsuart", &lpc32xx_hsuart[0], },
 	{ "lpc32xx_hsuart", &lpc32xx_hsuart[1], },
@@ -124,7 +124,7 @@ void lpc32xx_i2c_init(unsigned int devnum)
 	writel(ctrl, &clk->i2cclk_ctrl);
 }
 
-U_BOOT_DEVICE(lpc32xx_gpios) = {
+U_BOOT_DRVINFO(lpc32xx_gpios) = {
 	.name = "gpio_lpc32xx"
 };
 
diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c
index b5f2b75e244..e17898d8fbf 100644
--- a/arch/arm/mach-omap2/am33xx/board.c
+++ b/arch/arm/mach-omap2/am33xx/board.c
@@ -99,7 +99,7 @@ static const struct ns16550_plat am33xx_serial[] = {
 # endif
 };
 
-U_BOOT_DEVICES(am33xx_uarts) = {
+U_BOOT_DRVINFOS(am33xx_uarts) = {
 	{ "ns16550_serial", &am33xx_serial[0] },
 #  ifdef CONFIG_SYS_NS16550_COM2
 	{ "ns16550_serial", &am33xx_serial[1] },
@@ -119,7 +119,7 @@ static const struct omap_i2c_plat am33xx_i2c[] = {
 	{ I2C_BASE3, 100000, OMAP_I2C_REV_V2},
 };
 
-U_BOOT_DEVICES(am33xx_i2c) = {
+U_BOOT_DRVINFOS(am33xx_i2c) = {
 	{ "i2c_omap", &am33xx_i2c[0] },
 	{ "i2c_omap", &am33xx_i2c[1] },
 	{ "i2c_omap", &am33xx_i2c[2] },
@@ -138,7 +138,7 @@ static const struct omap_gpio_plat am33xx_gpio[] = {
 #endif
 };
 
-U_BOOT_DEVICES(am33xx_gpios) = {
+U_BOOT_DRVINFOS(am33xx_gpios) = {
 	{ "gpio_omap", &am33xx_gpio[0] },
 	{ "gpio_omap", &am33xx_gpio[1] },
 	{ "gpio_omap", &am33xx_gpio[2] },
@@ -155,7 +155,7 @@ static const struct omap3_spi_plat omap3_spi_pdata = {
 	.pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT,
 };
 
-U_BOOT_DEVICE(am33xx_spi) = {
+U_BOOT_DRVINFO(am33xx_spi) = {
 	.name = "omap3_spi",
 	.plat = &omap3_spi_pdata,
 };
@@ -234,7 +234,7 @@ static struct ti_musb_plat usb1 = {
 		},
 };
 
-U_BOOT_DEVICES(am33xx_usbs) = {
+U_BOOT_DRVINFOS(am33xx_usbs) = {
 #if CONFIG_AM335X_USB0_MODE == MUSB_PERIPHERAL
 	{ "ti-musb-peripheral", &usb0 },
 #elif CONFIG_AM335X_USB0_MODE == MUSB_HOST
diff --git a/arch/arm/mach-omap2/omap3/board.c b/arch/arm/mach-omap2/omap3/board.c
index 6ffedd1769f..4da8df47cc6 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -47,7 +47,7 @@ static const struct omap_gpio_plat omap34xx_gpio[] = {
 	{ 5, OMAP34XX_GPIO6_BASE },
 };
 
-U_BOOT_DEVICES(omap34xx_gpios) = {
+U_BOOT_DRVINFOS(omap34xx_gpios) = {
 	{ "gpio_omap", &omap34xx_gpio[0] },
 	{ "gpio_omap", &omap34xx_gpio[1] },
 	{ "gpio_omap", &omap34xx_gpio[2] },
diff --git a/arch/arm/mach-tegra/board.c b/arch/arm/mach-tegra/board.c
index bf01aa5ee8f..9de9836c8d2 100644
--- a/arch/arm/mach-tegra/board.c
+++ b/arch/arm/mach-tegra/board.c
@@ -264,7 +264,7 @@ static struct ns16550_plat ns16550_com1_pdata = {
 	.fcr = UART_FCR_DEFVAL,
 };
 
-U_BOOT_DEVICE(ns16550_com1) = {
+U_BOOT_DRVINFO(ns16550_com1) = {
 	"ns16550_serial", &ns16550_com1_pdata
 };
 #endif
diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c
index 48c4f32d6f9..8569ad7c6fc 100644
--- a/arch/arm/mach-tegra/board2.c
+++ b/arch/arm/mach-tegra/board2.c
@@ -42,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #ifdef CONFIG_SPL_BUILD
 /* TODO(sjg at chromium.org): Remove once SPL supports device tree */
-U_BOOT_DEVICE(tegra_gpios) = {
+U_BOOT_DRVINFO(tegra_gpios) = {
 	"gpio_tegra"
 };
 #endif
diff --git a/board/armltd/integrator/integrator.c b/board/armltd/integrator/integrator.c
index 21bea62e9b7..3c56fa1c019 100644
--- a/board/armltd/integrator/integrator.c
+++ b/board/armltd/integrator/integrator.c
@@ -43,7 +43,7 @@ static const struct pl01x_serial_plat serial_plat = {
 #endif
 };
 
-U_BOOT_DEVICE(integrator_serials) = {
+U_BOOT_DRVINFO(integrator_serials) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/armltd/total_compute/total_compute.c b/board/armltd/total_compute/total_compute.c
index 6263d0c3612..da24b32333b 100644
--- a/board/armltd/total_compute/total_compute.c
+++ b/board/armltd/total_compute/total_compute.c
@@ -15,7 +15,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = CONFIG_PL011_CLOCK,
 };
 
-U_BOOT_DEVICE(total_compute_serials) = {
+U_BOOT_DRVINFO(total_compute_serials) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c
index 6df6bcd3cf5..bd66d52cb7b 100644
--- a/board/armltd/vexpress64/vexpress64.c
+++ b/board/armltd/vexpress64/vexpress64.c
@@ -26,7 +26,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = CONFIG_PL011_CLOCK,
 };
 
-U_BOOT_DEVICE(vexpress_serials) = {
+U_BOOT_DRVINFO(vexpress_serials) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/bluewater/gurnard/gurnard.c b/board/bluewater/gurnard/gurnard.c
index a71b4eb7339..17ecdb679e1 100644
--- a/board/bluewater/gurnard/gurnard.c
+++ b/board/bluewater/gurnard/gurnard.c
@@ -420,7 +420,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
 	.base_addr = ATMEL_BASE_DBGU,
 };
 
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
 	.name	= "serial_atmel",
 	.plat = &at91sam9260_serial_plat,
 };
diff --git a/board/bluewater/snapper9260/snapper9260.c b/board/bluewater/snapper9260/snapper9260.c
index 9e41a42263d..58fab15c112 100644
--- a/board/bluewater/snapper9260/snapper9260.c
+++ b/board/bluewater/snapper9260/snapper9260.c
@@ -147,7 +147,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
 	.base_addr = ATMEL_BASE_DBGU,
 };
 
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
 	.name	= "serial_atmel",
 	.plat = &at91sam9260_serial_plat,
 };
diff --git a/board/cadence/xtfpga/xtfpga.c b/board/cadence/xtfpga/xtfpga.c
index 29db51b0260..c26793d76cc 100644
--- a/board/cadence/xtfpga/xtfpga.c
+++ b/board/cadence/xtfpga/xtfpga.c
@@ -93,7 +93,7 @@ int misc_init_r(void)
 	return 0;
 }
 
-U_BOOT_DEVICE(sysreset) = {
+U_BOOT_DRVINFO(sysreset) = {
 	.name = "xtfpga_sysreset",
 };
 
@@ -104,7 +104,7 @@ static struct ethoc_eth_pdata ethoc_pdata = {
 	.packet_base = CONFIG_SYS_ETHOC_BUFFER_ADDR,
 };
 
-U_BOOT_DEVICE(ethoc) = {
+U_BOOT_DRVINFO(ethoc) = {
 	.name = "ethoc",
 	.plat = &ethoc_pdata,
 };
diff --git a/board/cavium/thunderx/thunderx.c b/board/cavium/thunderx/thunderx.c
index 22c4c72361e..fd234728980 100644
--- a/board/cavium/thunderx/thunderx.c
+++ b/board/cavium/thunderx/thunderx.c
@@ -25,7 +25,7 @@ static const struct pl01x_serial_plat serial0 = {
 	.skip_init = true,
 };
 
-U_BOOT_DEVICE(thunderx_serial0) = {
+U_BOOT_DRVINFO(thunderx_serial0) = {
 	.name = "serial_pl01x",
 	.plat = &serial0,
 };
@@ -37,7 +37,7 @@ static const struct pl01x_serial_plat serial1 = {
 	.skip_init = true,
 };
 
-U_BOOT_DEVICE(thunderx_serial1) = {
+U_BOOT_DRVINFO(thunderx_serial1) = {
 	.name = "serial_pl01x",
 	.plat = &serial1,
 };
diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c
index bc3ce4d16c9..7520e96e078 100644
--- a/board/compulab/cm_fx6/cm_fx6.c
+++ b/board/compulab/cm_fx6/cm_fx6.c
@@ -728,7 +728,7 @@ static struct mxc_serial_plat cm_fx6_mxc_serial_plat = {
 	.reg = (struct mxc_uart *)UART4_BASE,
 };
 
-U_BOOT_DEVICE(cm_fx6_serial) = {
+U_BOOT_DRVINFO(cm_fx6_serial) = {
 	.name	= "serial_mxc",
 	.plat = &cm_fx6_mxc_serial_plat,
 };
diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c b/board/davinci/da8xxevm/omapl138_lcdk.c
index a8ece170ce3..a08858550d4 100644
--- a/board/davinci/da8xxevm/omapl138_lcdk.c
+++ b/board/davinci/da8xxevm/omapl138_lcdk.c
@@ -363,7 +363,7 @@ static const struct ns16550_plat serial_pdata = {
 	.fcr = UART_FCR_DEFVAL,
 };
 
-U_BOOT_DEVICE(omapl138_uart) = {
+U_BOOT_DRVINFO(omapl138_uart) = {
 	.name = "ns16550_serial",
 	.plat = &serial_pdata,
 };
@@ -379,7 +379,7 @@ static const struct davinci_mmc_plat mmc_plat = {
 		.name = "da830-mmc",
 	},
 };
-U_BOOT_DEVICE(omapl138_mmc) = {
+U_BOOT_DRVINFO(omapl138_mmc) = {
 	.name = "ti_da830_mmc",
 	.plat = &mmc_plat,
 };
diff --git a/board/freescale/ls1012afrdm/eth.c b/board/freescale/ls1012afrdm/eth.c
index 85104ab22c8..d2df9351eac 100644
--- a/board/freescale/ls1012afrdm/eth.c
+++ b/board/freescale/ls1012afrdm/eth.c
@@ -114,12 +114,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
 	},
 };
 
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata0,
 };
 
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata1,
 };
diff --git a/board/freescale/ls1012aqds/eth.c b/board/freescale/ls1012aqds/eth.c
index f6f43d2b137..8189f41becb 100644
--- a/board/freescale/ls1012aqds/eth.c
+++ b/board/freescale/ls1012aqds/eth.c
@@ -298,12 +298,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
 	},
 };
 
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata0,
 };
 
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata1,
 };
diff --git a/board/freescale/ls1012ardb/eth.c b/board/freescale/ls1012ardb/eth.c
index 5e923e52527..2241d061dd8 100644
--- a/board/freescale/ls1012ardb/eth.c
+++ b/board/freescale/ls1012ardb/eth.c
@@ -160,12 +160,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
 	},
 };
 
-U_BOOT_DEVICE(ls1012a_pfe0) = {
+U_BOOT_DRVINFO(ls1012a_pfe0) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata0,
 };
 
-U_BOOT_DEVICE(ls1012a_pfe1) = {
+U_BOOT_DRVINFO(ls1012a_pfe1) = {
 	.name = "pfe_eth",
 	.plat = &pfe_pdata1,
 };
diff --git a/board/freescale/lx2160a/lx2160a.c b/board/freescale/lx2160a/lx2160a.c
index 8d0115eace4..70dd34e7cee 100644
--- a/board/freescale/lx2160a/lx2160a.c
+++ b/board/freescale/lx2160a/lx2160a.c
@@ -62,7 +62,7 @@ static struct pl01x_serial_plat serial0 = {
 	.type = TYPE_PL011,
 };
 
-U_BOOT_DEVICE(nxp_serial0) = {
+U_BOOT_DRVINFO(nxp_serial0) = {
 	.name = "serial_pl01x",
 	.plat = &serial0,
 };
@@ -72,7 +72,7 @@ static struct pl01x_serial_plat serial1 = {
 	.type = TYPE_PL011,
 };
 
-U_BOOT_DEVICE(nxp_serial1) = {
+U_BOOT_DRVINFO(nxp_serial1) = {
 	.name = "serial_pl01x",
 	.plat = &serial1,
 };
diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
index c7224d1efe3..048f624c352 100644
--- a/board/gateworks/gw_ventana/gw_ventana.c
+++ b/board/gateworks/gw_ventana/gw_ventana.c
@@ -1375,7 +1375,7 @@ static struct mxc_serial_plat ventana_mxc_serial_plat = {
 	.reg = (struct mxc_uart *)UART2_BASE,
 };
 
-U_BOOT_DEVICE(ventana_serial) = {
+U_BOOT_DRVINFO(ventana_serial) = {
 	.name   = "serial_mxc",
 	.plat = &ventana_mxc_serial_plat,
 };
diff --git a/board/hisilicon/hikey/hikey.c b/board/hisilicon/hikey/hikey.c
index 0ac88306d09..65a8179adbf 100644
--- a/board/hisilicon/hikey/hikey.c
+++ b/board/hisilicon/hikey/hikey.c
@@ -50,7 +50,7 @@ static const struct hikey_gpio_plat hi6220_gpio[] = {
 
 };
 
-U_BOOT_DEVICES(hi6220_gpios) = {
+U_BOOT_DRVINFOS(hi6220_gpios) = {
 	{ "gpio_hi6220", &hi6220_gpio[0] },
 	{ "gpio_hi6220", &hi6220_gpio[1] },
 	{ "gpio_hi6220", &hi6220_gpio[2] },
@@ -89,7 +89,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = 19200000
 };
 
-U_BOOT_DEVICE(hikey_seriala) = {
+U_BOOT_DRVINFO(hikey_seriala) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/hisilicon/hikey960/hikey960.c b/board/hisilicon/hikey960/hikey960.c
index 04b8cde1363..3fe4c60d02e 100644
--- a/board/hisilicon/hikey960/hikey960.c
+++ b/board/hisilicon/hikey960/hikey960.c
@@ -32,7 +32,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = 19200000
 };
 
-U_BOOT_DEVICE(hikey960_serial0) = {
+U_BOOT_DRVINFO(hikey960_serial0) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/hisilicon/poplar/poplar.c b/board/hisilicon/poplar/poplar.c
index b8be4ce45a6..bfb2c66a17a 100644
--- a/board/hisilicon/poplar/poplar.c
+++ b/board/hisilicon/poplar/poplar.c
@@ -46,7 +46,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = 75000000,
 };
 
-U_BOOT_DEVICE(poplar_serial) = {
+U_BOOT_DRVINFO(poplar_serial) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
index 6a7da502dda..0932f62b9be 100644
--- a/board/isee/igep00x0/igep00x0.c
+++ b/board/isee/igep00x0/igep00x0.c
@@ -36,7 +36,7 @@ static const struct ns16550_plat igep_serial = {
 	.fcr = UART_FCR_DEFVAL,
 };
 
-U_BOOT_DEVICE(igep_uart) = {
+U_BOOT_DRVINFO(igep_uart) = {
 	"ns16550_serial",
 	&igep_serial
 };
diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c
index d11630b9543..118ab269d6f 100644
--- a/board/lg/sniper/sniper.c
+++ b/board/lg/sniper/sniper.c
@@ -37,7 +37,7 @@ static const struct ns16550_plat serial_omap_plat = {
 	.fcr = UART_FCR_DEFVAL,
 };
 
-U_BOOT_DEVICE(sniper_serial) = {
+U_BOOT_DRVINFO(sniper_serial) = {
 	.name = "ns16550_serial",
 	.plat = &serial_omap_plat
 };
diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
index bafb6205bd8..253ee3c7b29 100644
--- a/board/nokia/rx51/rx51.c
+++ b/board/nokia/rx51/rx51.c
@@ -709,7 +709,7 @@ static const struct omap_i2c_plat rx51_i2c[] = {
 	{ I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
 };
 
-U_BOOT_DEVICES(rx51_i2c) = {
+U_BOOT_DRVINFOS(rx51_i2c) = {
 	{ "i2c_omap", &rx51_i2c[0] },
 	{ "i2c_omap", &rx51_i2c[1] },
 	{ "i2c_omap", &rx51_i2c[2] },
diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
index 3235541a7d5..d152703b154 100644
--- a/board/sandbox/sandbox.c
+++ b/board/sandbox/sandbox.c
@@ -23,7 +23,7 @@ gd_t *gd;
 
 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
 /* Add a simple GPIO device */
-U_BOOT_DEVICE(gpio_sandbox) = {
+U_BOOT_DRVINFO(gpio_sandbox) = {
 	.name = "sandbox_gpio",
 };
 #endif
diff --git a/board/siemens/corvus/board.c b/board/siemens/corvus/board.c
index 1613c449294..25d85a8f170 100644
--- a/board/siemens/corvus/board.c
+++ b/board/siemens/corvus/board.c
@@ -318,7 +318,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
 	.base_addr = ATMEL_BASE_DBGU,
 };
 
-U_BOOT_DEVICE(at91sam9260_serial) = {
+U_BOOT_DRVINFO(at91sam9260_serial) = {
 	.name	= "serial_atmel",
 	.plat = &at91sam9260_serial_plat,
 };
diff --git a/board/st/stv0991/stv0991.c b/board/st/stv0991/stv0991.c
index 3371973600a..95e203ff0ea 100644
--- a/board/st/stv0991/stv0991.c
+++ b/board/st/stv0991/stv0991.c
@@ -30,7 +30,7 @@ static const struct pl01x_serial_plat serial_plat = {
 	.clock = 2700 * 1000,
 };
 
-U_BOOT_DEVICE(stv09911_serials) = {
+U_BOOT_DRVINFO(stv09911_serials) = {
 	.name = "serial_pl01x",
 	.plat = &serial_plat,
 };
diff --git a/board/sysam/amcore/amcore.c b/board/sysam/amcore/amcore.c
index 42e1a80ec5f..65fc60e2b46 100644
--- a/board/sysam/amcore/amcore.c
+++ b/board/sysam/amcore/amcore.c
@@ -113,7 +113,7 @@ static struct coldfire_serial_plat mcf5307_serial_plat = {
 	.baudrate = CONFIG_BAUDRATE,
 };
 
-U_BOOT_DEVICE(coldfire_serial) = {
+U_BOOT_DRVINFO(coldfire_serial) = {
 	.name = "serial_coldfire",
 	.plat = &mcf5307_serial_plat,
 };
diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index 2aa385a937b..40d2e0238fd 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -927,7 +927,7 @@ struct eth_pdata cpsw_pdata = {
 	.priv_pdata = &am335_eth_data,
 };
 
-U_BOOT_DEVICE(am335x_eth) = {
+U_BOOT_DRVINFO(am335x_eth) = {
 	.name = "eth_cpsw",
 	.plat = &cpsw_pdata,
 };
@@ -972,7 +972,7 @@ static const struct omap_hsmmc_plat am335x_mmc0_plat = {
 	.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
 };
 
-U_BOOT_DEVICE(am335x_mmc0) = {
+U_BOOT_DRVINFO(am335x_mmc0) = {
 	.name = "omap_hsmmc",
 	.plat = &am335x_mmc0_plat,
 };
@@ -986,7 +986,7 @@ static const struct omap_hsmmc_plat am335x_mmc1_plat = {
 	.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
 };
 
-U_BOOT_DEVICE(am335x_mmc1) = {
+U_BOOT_DRVINFO(am335x_mmc1) = {
 	.name = "omap_hsmmc",
 	.plat = &am335x_mmc1_plat,
 };
diff --git a/board/timll/devkit8000/devkit8000.c b/board/timll/devkit8000/devkit8000.c
index 875383625d4..0731fb76456 100644
--- a/board/timll/devkit8000/devkit8000.c
+++ b/board/timll/devkit8000/devkit8000.c
@@ -54,7 +54,7 @@ static const struct ns16550_plat devkit8000_serial = {
 	.fcr = UART_FCR_DEFVAL,
 };
 
-U_BOOT_DEVICE(devkit8000_uart) = {
+U_BOOT_DRVINFO(devkit8000_uart) = {
 	"ns16550_serial",
 	&devkit8000_serial
 };
diff --git a/board/toradex/apalis_imx6/apalis_imx6.c b/board/toradex/apalis_imx6/apalis_imx6.c
index 362a750b199..5ae5274584a 100644
--- a/board/toradex/apalis_imx6/apalis_imx6.c
+++ b/board/toradex/apalis_imx6/apalis_imx6.c
@@ -1149,7 +1149,7 @@ static struct mxc_serial_plat mxc_serial_plat = {
 	.use_dte = true,
 };
 
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
 	.name = "serial_mxc",
 	.plat = &mxc_serial_plat,
 };
diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
index 056064f6b97..6ff55ce57b9 100644
--- a/board/toradex/colibri-imx6ull/colibri-imx6ull.c
+++ b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
@@ -208,7 +208,7 @@ static struct mxc_serial_plat mxc_serial_plat = {
 	.use_dte = 1,
 };
 
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
 	.name = "serial_mxc",
 	.plat = &mxc_serial_plat,
 };
diff --git a/board/toradex/colibri_imx6/colibri_imx6.c b/board/toradex/colibri_imx6/colibri_imx6.c
index a82daad7395..57d3e526b4c 100644
--- a/board/toradex/colibri_imx6/colibri_imx6.c
+++ b/board/toradex/colibri_imx6/colibri_imx6.c
@@ -1091,7 +1091,7 @@ static struct mxc_serial_plat mxc_serial_plat = {
 	.use_dte = true,
 };
 
-U_BOOT_DEVICE(mxc_serial) = {
+U_BOOT_DRVINFO(mxc_serial) = {
 	.name = "serial_mxc",
 	.plat = &mxc_serial_plat,
 };
diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c
index b9d0fb98af3..645751a37ec 100644
--- a/board/toradex/colibri_pxa270/colibri_pxa270.c
+++ b/board/toradex/colibri_pxa270/colibri_pxa270.c
@@ -133,7 +133,7 @@ static const struct pxa_mmc_plat mmc_plat = {
 	.base = (struct pxa_mmc_regs *)MMC0_BASE,
 };
 
-U_BOOT_DEVICE(pxa_mmcs) = {
+U_BOOT_DRVINFO(pxa_mmcs) = {
 	.name = "pxa_mmc",
 	.plat = &mmc_plat,
 };
@@ -146,7 +146,7 @@ static const struct pxa_serial_plat serial_plat = {
 	.baudrate = CONFIG_BAUDRATE,
 };
 
-U_BOOT_DEVICE(pxa_serials) = {
+U_BOOT_DRVINFO(pxa_serials) = {
 	.name = "serial_pxa",
 	.plat = &serial_plat,
 };
diff --git a/doc/driver-model/design.rst b/doc/driver-model/design.rst
index f26e4f14df0..ffed7d5f79a 100644
--- a/doc/driver-model/design.rst
+++ b/doc/driver-model/design.rst
@@ -422,7 +422,7 @@ Device Tree
 
 While plat is useful, a more flexible way of providing device data is
 by using device tree. In U-Boot you should use this where possible. Avoid
-sending patches which make use of the U_BOOT_DEVICE() macro unless strictly
+sending patches which make use of the U_BOOT_DRVINFO() macro unless strictly
 necessary.
 
 With device tree we replace the above code with the following device tree
@@ -436,7 +436,7 @@ fragment:
 		sides = <4>;
 	};
 
-This means that instead of having lots of U_BOOT_DEVICE() declarations in
+This means that instead of having lots of U_BOOT_DRVINFO() declarations in
 the board file, we put these in the device tree. This approach allows a lot
 more generality, since the same board file can support many types of boards
 (e,g. with the same SoC) just by using different device trees. An added
@@ -665,9 +665,9 @@ Bind stage
 
 U-Boot discovers devices using one of these two methods:
 
-- Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified
+- Scan the U_BOOT_DRVINFO() definitions. U-Boot looks up the name specified
   by each, to find the appropriate U_BOOT_DRIVER() definition. In this case,
-  there is no path by which driver_data may be provided, but the U_BOOT_DEVICE()
+  there is no path by which driver_data may be provided, but the U_BOOT_DRVINFO()
   may provide plat.
 
 - Scan through the device tree definitions. U-Boot looks at top-level
@@ -685,7 +685,7 @@ driver's bind() method if one is defined.
 At this point all the devices are known, and bound to their drivers. There
 is a 'struct udevice' allocated for all devices. However, nothing has been
 activated (except for the root device). Each bound device that was created
-from a U_BOOT_DEVICE() declaration will hold the plat pointer specified
+from a U_BOOT_DRVINFO() declaration will hold the plat pointer specified
 in that declaration. For a bound device created from the device tree,
 plat will be NULL, but of_offset will be the offset of the device tree
 node that caused the device to be created. The uclass is set correctly for
@@ -726,7 +726,7 @@ The steps are:
    2. If plat_auto is non-zero, then the platform data space
    is allocated. This is only useful for device tree operation, since
    otherwise you would have to specific the platform data in the
-   U_BOOT_DEVICE() declaration. The space is allocated for the device and
+   U_BOOT_DRVINFO() declaration. The space is allocated for the device and
    zeroed. It will be accessible as dev->plat.
 
    3. If the device's uclass specifies a non-zero per_device_auto,
@@ -746,7 +746,7 @@ The steps are:
    do various calls like dev_read_u32(dev, ...) to access the node and store
    the resulting information into dev->plat. After this point, the device
    works the same way whether it was bound using a device tree node or
-   U_BOOT_DEVICE() structure. In either case, the platform data is now stored
+   U_BOOT_DRVINFO() structure. In either case, the platform data is now stored
    in the plat structure. Typically you will use the
    plat_auto feature to specify the size of the platform data
    structure, and U-Boot will automatically allocate and zero it for you before
@@ -855,7 +855,7 @@ remove it. This performs the probe steps in reverse:
    4. The device memory is freed (platform data, private data, uclass data,
    parent data).
 
-   Note: Because the platform data for a U_BOOT_DEVICE() is defined with a
+   Note: Because the platform data for a U_BOOT_DRVINFO() is defined with a
    static pointer, it is not de-allocated during the remove() method. For
    a device instantiated using the device tree data, the platform data will
    be dynamically allocated, and thus needs to be deallocated during the
@@ -931,7 +931,7 @@ property can provide better control granularity on which device is bound
 before relocation. While with DM_FLAG_PRE_RELOC flag of the driver all
 devices with the same driver are bound, which requires allocation a large
 amount of memory. When device tree is not used, DM_FLAG_PRE_RELOC is the
-only way for statically declared devices via U_BOOT_DEVICE() to be bound
+only way for statically declared devices via U_BOOT_DRVINFO() to be bound
 prior to relocation.
 
 It is possible to limit this to specific relocation steps, by using
diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
index afa27c211cc..39e6295aa09 100644
--- a/doc/driver-model/of-plat.rst
+++ b/doc/driver-model/of-plat.rst
@@ -21,7 +21,7 @@ SoCs require a 16KB SPL image which must include a full MMC stack. In this
 case the overhead of device tree access may be too great.
 
 It is possible to create platform data manually by defining C structures
-for it, and reference that data in a U_BOOT_DEVICE() declaration. This
+for it, and reference that data in a U_BOOT_DRVINFO() declaration. This
 bypasses the use of device tree completely, effectively creating a parallel
 configuration mechanism. But it is an available option for SPL.
 
@@ -79,7 +79,7 @@ SPL/TPL and should be tested with:
 
 A new tool called 'dtoc' converts a device tree file either into a set of
 struct declarations, one for each compatible node, and a set of
-U_BOOT_DEVICE() declarations along with the actual platform data for each
+U_BOOT_DRVINFO() declarations along with the actual platform data for each
 device. As an example, consider this MMC node:
 
 .. code-block:: none
@@ -155,7 +155,7 @@ and the following device declarations:
             .card_detect_delay      = 0xc8,
     };
 
-    U_BOOT_DEVICE(dwmmc_at_ff0c0000) = {
+    U_BOOT_DRVINFO(dwmmc_at_ff0c0000) = {
             .name           = "rockchip_rk3288_dw_mshc",
             .plat       = &dtv_dwmmc_at_ff0c0000,
             .plat_size  = sizeof(dtv_dwmmc_at_ff0c0000),
@@ -178,7 +178,7 @@ platform data in the driver. The of_to_plat() method should
 therefore do nothing in such a driver.
 
 Note that for the platform data to be matched with a driver, the 'name'
-property of the U_BOOT_DEVICE() declaration has to match a driver declared
+property of the U_BOOT_DRVINFO() declaration has to match a driver declared
 via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a
 'name' corresponding to the devicetree 'compatible' string (after converting
 it to a valid name for C) is needed, so a dedicated driver is required for
@@ -189,7 +189,7 @@ used to declare an alias for a driver name, typically a 'compatible' string.
 This macro produces no code, but it is by dtoc tool.
 
 The parent_idx is the index of the parent driver_info structure within its
-linker list (instantiated by the U_BOOT_DEVICE() macro). This is used to support
+linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support
 dev_get_parent(). The dm_populate_phandle_data() is included to allow for
 fix-ups required by dtoc. It is not currently used. The values in 'clocks' are
 the index of the driver_info for the target device followed by any phandle
@@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with
 The dt-plat.c file contains the device declarations and is is built in
 spl/dt-plat.c. It additionally contains the definition of
 dm_populate_phandle_data() which is responsible of filling the phandle
-information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE
+information by adding references to U_BOOT_DRVINFO by using DM_GET_DEVICE
 
 The pylibfdt Python module is used to access the devicetree.
 
diff --git a/doc/driver-model/remoteproc-framework.rst b/doc/driver-model/remoteproc-framework.rst
index edb09cc1057..566495a21c4 100644
--- a/doc/driver-model/remoteproc-framework.rst
+++ b/doc/driver-model/remoteproc-framework.rst
@@ -125,7 +125,7 @@ a simplified definition of a device is as follows:
 		.driver_plat_data = &mydriver_data;
 	};
 
-	U_BOOT_DEVICE(proc_3_demo) = {
+	U_BOOT_DRVINFO(proc_3_demo) = {
 		.name = "sandbox_test_proc",
 		.plat = &proc_3_test,
 	};
diff --git a/doc/driver-model/spi-howto.rst b/doc/driver-model/spi-howto.rst
index f1c41671390..97fbf750cb6 100644
--- a/doc/driver-model/spi-howto.rst
+++ b/doc/driver-model/spi-howto.rst
@@ -270,7 +270,7 @@ fills in the fields from device tree.
 Add the platform data [non-device-tree only]
 --------------------------------------------
 
-Specify this data in a U_BOOT_DEVICE() declaration in your board file:
+Specify this data in a U_BOOT_DRVINFO() declaration in your board file:
 
 .. code-block:: c
 
@@ -281,7 +281,7 @@ Specify this data in a U_BOOT_DEVICE() declaration in your board file:
 		.deactivate_delay_us = ...
 	};
 
-	U_BOOT_DEVICE(board_spi0) = {
+	U_BOOT_DRVINFO(board_spi0) = {
 		.name = "exynos_spi",
 		.plat = &platdata_spi0,
 	};
diff --git a/drivers/crypto/fsl/fsl_rsa.c b/drivers/crypto/fsl/fsl_rsa.c
index ed2a54f6ec2..897ee855ead 100644
--- a/drivers/crypto/fsl/fsl_rsa.c
+++ b/drivers/crypto/fsl/fsl_rsa.c
@@ -55,6 +55,6 @@ U_BOOT_DRIVER(fsl_rsa_mod_exp) = {
 	.ops	= &fsl_mod_exp_ops,
 };
 
-U_BOOT_DEVICE(fsl_rsa) = {
+U_BOOT_DRVINFO(fsl_rsa) = {
 	.name = "fsl_rsa_mod_exp",
 };
diff --git a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
index 4ce85b32244..7bed444c3fb 100644
--- a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
+++ b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
@@ -35,6 +35,6 @@ U_BOOT_DRIVER(mod_exp_sw) = {
 	.flags	= DM_FLAG_PRE_RELOC,
 };
 
-U_BOOT_DEVICE(mod_exp_sw) = {
+U_BOOT_DRVINFO(mod_exp_sw) = {
 	.name = "mod_exp_sw",
 };
diff --git a/drivers/demo/demo-pdata.c b/drivers/demo/demo-pdata.c
index b504c31373c..818f77503a3 100644
--- a/drivers/demo/demo-pdata.c
+++ b/drivers/demo/demo-pdata.c
@@ -20,27 +20,27 @@ static const struct dm_demo_pdata yellow_hexagon = {
 	.sides = 6.
 };
 
-U_BOOT_DEVICE(demo0) = {
+U_BOOT_DRVINFO(demo0) = {
 	.name = "demo_shape_drv",
 	.plat = &red_square,
 };
 
-U_BOOT_DEVICE(demo1) = {
+U_BOOT_DRVINFO(demo1) = {
 	.name = "demo_simple_drv",
 	.plat = &red_square,
 };
 
-U_BOOT_DEVICE(demo2) = {
+U_BOOT_DRVINFO(demo2) = {
 	.name = "demo_shape_drv",
 	.plat = &green_triangle,
 };
 
-U_BOOT_DEVICE(demo3) = {
+U_BOOT_DRVINFO(demo3) = {
 	.name = "demo_simple_drv",
 	.plat = &yellow_hexagon,
 };
 
-U_BOOT_DEVICE(demo4) = {
+U_BOOT_DRVINFO(demo4) = {
 	.name = "demo_shape_drv",
 	.plat = &yellow_hexagon,
 };
diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c
index a5a290a00ce..0e2874ca95c 100644
--- a/drivers/gpio/imx_rgpio2p.c
+++ b/drivers/gpio/imx_rgpio2p.c
@@ -158,7 +158,7 @@ static int imx_rgpio2p_bind(struct udevice *dev)
 	/*
 	 * If plat already exsits, directly return.
 	 * Actually only when DT is not supported, plat
-	 * is statically initialized in U_BOOT_DEVICES.Here
+	 * is statically initialized in U_BOOT_DRVINFOS.Here
 	 * will return.
 	 */
 	if (plat)
@@ -216,7 +216,7 @@ static const struct imx_rgpio2p_plat imx_plat[] = {
 	{ 5, (struct gpio_regs *)RGPIO2P_GPIO6_BASE_ADDR },
 };
 
-U_BOOT_DEVICES(imx_rgpio2ps) = {
+U_BOOT_DRVINFOS(imx_rgpio2ps) = {
 	{ "imx_rgpio2p", &imx_plat[0] },
 	{ "imx_rgpio2p", &imx_plat[1] },
 	{ "imx_rgpio2p", &imx_plat[2] },
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 9fc217ae6ae..6280fb59840 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -372,7 +372,7 @@ static const struct mxc_gpio_plat mxc_plat[] = {
 #endif
 };
 
-U_BOOT_DEVICES(mxc_gpios) = {
+U_BOOT_DRVINFOS(mxc_gpios) = {
 	{ "gpio_mxc", &mxc_plat[0] },
 	{ "gpio_mxc", &mxc_plat[1] },
 	{ "gpio_mxc", &mxc_plat[2] },
diff --git a/drivers/remoteproc/sandbox_testproc.c b/drivers/remoteproc/sandbox_testproc.c
index ee2ee730712..6836eca4c55 100644
--- a/drivers/remoteproc/sandbox_testproc.c
+++ b/drivers/remoteproc/sandbox_testproc.c
@@ -352,7 +352,7 @@ static struct dm_rproc_uclass_pdata proc_3_test = {
 	.mem_type = RPROC_INTERNAL_MEMORY_MAPPED,
 };
 
-U_BOOT_DEVICE(proc_3_demo) = {
+U_BOOT_DRVINFO(proc_3_demo) = {
 	.name = "sandbox_test_proc",
 	.plat = &proc_3_test,
 };
diff --git a/drivers/rtc/emul_rtc.c b/drivers/rtc/emul_rtc.c
index 1dc80ca1274..8f0e1ab5ac6 100644
--- a/drivers/rtc/emul_rtc.c
+++ b/drivers/rtc/emul_rtc.c
@@ -91,6 +91,6 @@ U_BOOT_DRIVER(rtc_emul) = {
 	.priv_auto	= sizeof(struct emul_rtc),
 };
 
-U_BOOT_DEVICE(rtc_emul) = {
+U_BOOT_DRVINFO(rtc_emul) = {
 	.name	= "rtc_emul",
 };
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 19368ba2560..756738c2d21 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -241,7 +241,7 @@ static const struct sandbox_serial_plat platdata_non_fdt = {
 	.colour = -1,
 };
 
-U_BOOT_DEVICE(serial_sandbox_non_fdt) = {
+U_BOOT_DRVINFO(serial_sandbox_non_fdt) = {
 	.name = "sandbox_serial",
 	.plat = &platdata_non_fdt,
 };
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index 8eca7d8bfda..08685823e99 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -47,7 +47,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
 
 	/*
 	 * If we have a device tree, the device we created from platform data
-	 * (see the U_BOOT_DEVICE() declaration below) should not do anything.
+	 * (see the U_BOOT_DRVINFO() declaration below) should not do anything.
 	 * If we are that device, return an error.
 	 */
 	if (state->fdt_fname && !dev_has_ofnode(dev))
@@ -135,7 +135,7 @@ U_BOOT_DRIVER(warm_sysreset_sandbox) = {
 
 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
 /* This is here in case we don't have a device tree */
-U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
+U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
 	.name = "sysreset_sandbox",
 };
 #endif
diff --git a/drivers/timer/sandbox_timer.c b/drivers/timer/sandbox_timer.c
index 135c0f38a4d..2075cd4edda 100644
--- a/drivers/timer/sandbox_timer.c
+++ b/drivers/timer/sandbox_timer.c
@@ -65,6 +65,6 @@ U_BOOT_DRIVER(sandbox_timer) = {
 };
 
 /* This is here in case we don't have a device tree */
-U_BOOT_DEVICE(sandbox_timer_non_fdt) = {
+U_BOOT_DRVINFO(sandbox_timer_non_fdt) = {
 	.name = "sandbox_timer",
 };
diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
index 50657a77d36..a3e21aa5f13 100644
--- a/drivers/video/sunxi/sunxi_de2.c
+++ b/drivers/video/sunxi/sunxi_de2.c
@@ -319,7 +319,7 @@ U_BOOT_DRIVER(sunxi_de2) = {
 	.flags	= DM_FLAG_PRE_RELOC,
 };
 
-U_BOOT_DEVICE(sunxi_de2) = {
+U_BOOT_DRVINFO(sunxi_de2) = {
 	.name = "sunxi_de2"
 };
 
diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c b/drivers/video/sunxi/sunxi_dw_hdmi.c
index 3e8d71538f2..0b8cefc311e 100644
--- a/drivers/video/sunxi/sunxi_dw_hdmi.c
+++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
@@ -398,6 +398,6 @@ U_BOOT_DRIVER(sunxi_dw_hdmi) = {
 	.priv_auto	= sizeof(struct sunxi_dw_hdmi_priv),
 };
 
-U_BOOT_DEVICE(sunxi_dw_hdmi) = {
+U_BOOT_DRVINFO(sunxi_dw_hdmi) = {
 	.name = "sunxi_dw_hdmi"
 };
diff --git a/drivers/video/sunxi/sunxi_lcd.c b/drivers/video/sunxi/sunxi_lcd.c
index dd2bb1f5fc5..635edf6dd3b 100644
--- a/drivers/video/sunxi/sunxi_lcd.c
+++ b/drivers/video/sunxi/sunxi_lcd.c
@@ -146,7 +146,7 @@ U_BOOT_DRIVER(sunxi_lcd) = {
 };
 
 #ifdef CONFIG_MACH_SUN50I
-U_BOOT_DEVICE(sunxi_lcd) = {
+U_BOOT_DRVINFO(sunxi_lcd) = {
 	.name = "sunxi_lcd"
 };
 #endif
diff --git a/dts/Kconfig b/dts/Kconfig
index aeda542f985..71f50552e4f 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -346,13 +346,13 @@ config SPL_OF_PLATDATA
 	  former can add 3KB or more to a Thumb 2 Image.
 
 	  This option enables generation of platform data from the device
-	  tree as C code. This code creates devices using U_BOOT_DEVICE()
+	  tree as C code. This code creates devices using U_BOOT_DRVINFO()
 	  declarations. The benefit is that it allows driver code to access
 	  the platform data directly in C structures, avoidin the libfdt
 	  overhead.
 
 	  This option works by generating C structure declarations for each
-	  compatible string, then adding platform data and U_BOOT_DEVICE
+	  compatible string, then adding platform data and U_BOOT_DRVINFO
 	  declarations for each node. See of-plat.txt for more information.
 
 config SPL_OF_PLATDATA_PARENT
@@ -376,13 +376,13 @@ config TPL_OF_PLATDATA
 	  former can add 3KB or more to a Thumb 2 Image.
 
 	  This option enables generation of platform data from the device
-	  tree as C code. This code creates devices using U_BOOT_DEVICE()
+	  tree as C code. This code creates devices using U_BOOT_DRVINFO()
 	  declarations. The benefit is that it allows driver code to access
 	  the platform data directly in C structures, avoidin the libfdt
 	  overhead.
 
 	  This option works by generating C structure declarations for each
-	  compatible string, then adding platform data and U_BOOT_DEVICE
+	  compatible string, then adding platform data and U_BOOT_DRVINFO
 	  declarations for each node. See of-plat.txt for more information.
 
 config TPL_OF_PLATDATA_PARENT
diff --git a/include/dm/device.h b/include/dm/device.h
index 4469804a00e..e16ba2405f9 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -104,7 +104,7 @@ enum {
  * particular port or peripheral (essentially a driver instance).
  *
  * A device will come into existence through a 'bind' call, either due to
- * a U_BOOT_DEVICE() macro (in which case plat is non-NULL) or a node
+ * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node
  * in the device tree (in which case of_offset is >= 0). In the latter case
  * we translate the device tree information into plat in a function
  * implemented by the driver of_to_plat method (called just before the
@@ -293,7 +293,7 @@ struct udevice_id {
  * platform data to be allocated in the device's ->plat pointer.
  * This is typically only useful for device-tree-aware drivers (those with
  * an of_match), since drivers which use plat will have the data
- * provided in the U_BOOT_DEVICE() instantiation.
+ * provided in the U_BOOT_DRVINFO() instantiation.
  * @per_child_auto: Each device can hold private data owned by
  * its parent. If required this will be automatically allocated if this
  * value is non-zero.
diff --git a/include/dm/lists.h b/include/dm/lists.h
index 070bc9c19f6..1a865525461 100644
--- a/include/dm/lists.h
+++ b/include/dm/lists.h
@@ -35,7 +35,7 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id);
 /**
  * lists_bind_drivers() - search for and bind all drivers to parent
  *
- * This searches the U_BOOT_DEVICE() structures and creates new devices for
+ * This searches the U_BOOT_DRVINFO() structures and creates new devices for
  * each one. The devices will have @parent as their parent.
  *
  * @parent: parent device (root)
diff --git a/include/dm/platdata.h b/include/dm/platdata.h
index d650fb39190..e2b16ce6e4e 100644
--- a/include/dm/platdata.h
+++ b/include/dm/platdata.h
@@ -56,31 +56,31 @@ struct driver_rt {
  * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
  * available). U-Boot's driver model uses device tree for configuration.
  *
- * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the
+ * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the
  * dt-plat.c file created by dtoc
  */
 #if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
-#define U_BOOT_DEVICE(__name)	_Static_assert(false, \
-	"Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead")
+#define U_BOOT_DRVINFO(__name)	_Static_assert(false, \
+	"Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead")
 #else
-#define U_BOOT_DEVICE(__name)						\
+#define U_BOOT_DRVINFO(__name)						\
 	ll_entry_declare(struct driver_info, __name, driver_info)
 #endif
 
 /* Declare a list of devices. The argument is a driver_info[] array */
-#define U_BOOT_DEVICES(__name)						\
+#define U_BOOT_DRVINFOS(__name)						\
 	ll_entry_declare_list(struct driver_info, __name, driver_info)
 
 /**
  * Get a pointer to a given device info given its name
  *
- * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
+ * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a
  * pointer to the struct driver_info created by that declaration.
  *
  * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
  * struct driver_info to find the device pointer itself.
  *
- * TODO(sjg at chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so
+ * TODO(sjg at chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so
  * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
  * finds the driver_info record, not the device.
  *
@@ -93,7 +93,7 @@ struct driver_rt {
 /**
  * dm_populate_phandle_data() - Populates phandle data in platda
  *
- * This populates phandle data with an U_BOOT_DEVICE entry get by
+ * This populates phandle data with an U_BOOT_DRVINFO entry get by
  * DM_GET_DEVICE. The implementation of this function will be done
  * by dtoc when parsing dtb.
  */
diff --git a/include/dm/platform_data/spi_pl022.h b/include/dm/platform_data/spi_pl022.h
index c5aa3212915..7f74b3cbc5c 100644
--- a/include/dm/platform_data/spi_pl022.h
+++ b/include/dm/platform_data/spi_pl022.h
@@ -3,7 +3,7 @@
  * (C) Copyright 2018
  * Quentin Schulz, Bootlin, quentin.schulz@bootlin.com
  *
- * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use
+ * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use
  * in of_to_plat.
  */
 
diff --git a/test/dm/core.c b/test/dm/core.c
index 580d171e30e..82b7a668ddc 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -43,17 +43,17 @@ static const struct dm_test_pdata test_pdata_pre_reloc = {
 	.ping_add		= TEST_INTVAL_PRE_RELOC,
 };
 
-U_BOOT_DEVICE(dm_test_info1) = {
+U_BOOT_DRVINFO(dm_test_info1) = {
 	.name = "test_drv",
 	.plat = &test_pdata[0],
 };
 
-U_BOOT_DEVICE(dm_test_info2) = {
+U_BOOT_DRVINFO(dm_test_info2) = {
 	.name = "test_drv",
 	.plat = &test_pdata[1],
 };
 
-U_BOOT_DEVICE(dm_test_info3) = {
+U_BOOT_DRVINFO(dm_test_info3) = {
 	.name = "test_drv",
 	.plat = &test_pdata[2],
 };
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 7bd19891139..ebe5132e143 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -713,14 +713,14 @@ class DtbPlatdata():
     def _declare_device(self, var_name, struct_name, node_parent):
         """Add a device declaration to the output
 
-        This declares a U_BOOT_DEVICE() for the device being processed
+        This declares a U_BOOT_DRVINFO() for the device being processed
 
         Args:
             var_name (str): C name for the node
             struct_name (str): Name for the dt struct associated with the node
             node_parent (Node): Parent of the node (or None if none)
         """
-        self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
+        self.buf('U_BOOT_DRVINFO(%s) = {\n' % var_name)
         self.buf('\t.name\t\t= "%s",\n' % struct_name)
         self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
         self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
@@ -783,14 +783,14 @@ class DtbPlatdata():
         """Generate device defintions for the platform data
 
         This writes out C platform data initialisation data and
-        U_BOOT_DEVICE() declarations for each valid node. Where a node has
+        U_BOOT_DRVINFO() declarations for each valid node. Where a node has
         multiple compatible strings, a #define is used to make them equivalent.
 
         See the documentation in doc/driver-model/of-plat.rst for more
         information.
         """
         self.out_header()
-        self.out('/* Allow use of U_BOOT_DEVICE() in this file */\n')
+        self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
         self.out('#define DT_PLATDATA_C\n')
         self.out('\n')
         self.out('#include <common.h>\n')
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index fb65f284ceb..dbd4e3bf1d4 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -44,7 +44,7 @@ C_HEADER = '''/*
  * This file was generated by dtoc from a .dtb (device tree binary) file.
  */
 
-/* Allow use of U_BOOT_DEVICE() in this file */
+/* Allow use of U_BOOT_DRVINFO() in this file */
 #define DT_PLATDATA_C
 
 #include <common.h>
@@ -214,7 +214,7 @@ struct dtd_sandbox_spl_test {
 /* Node /i2c at 0 index 0 */
 static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
 };
-U_BOOT_DEVICE(i2c_at_0) = {
+U_BOOT_DRVINFO(i2c_at_0) = {
 \t.name\t\t= "sandbox_i2c_test",
 \t.plat\t= &dtv_i2c_at_0,
 \t.plat_size\t= sizeof(dtv_i2c_at_0),
@@ -226,7 +226,7 @@ static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
 \t.low_power\t\t= true,
 \t.reg\t\t\t= {0x9, 0x0},
 };
-U_BOOT_DEVICE(pmic_at_9) = {
+U_BOOT_DRVINFO(pmic_at_9) = {
 \t.name\t\t= "sandbox_pmic_test",
 \t.plat\t= &dtv_pmic_at_9,
 \t.plat_size\t= sizeof(dtv_pmic_at_9),
@@ -246,7 +246,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.stringarray\t\t= {"multi-word", "message", ""},
 \t.stringval\t\t= "message",
 };
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
 \t.name\t\t= "sandbox_spl_test",
 \t.plat\t= &dtv_spl_test,
 \t.plat_size\t= sizeof(dtv_spl_test),
@@ -265,7 +265,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.stringarray\t\t= {"another", "multi-word", "message"},
 \t.stringval\t\t= "message2",
 };
-U_BOOT_DEVICE(spl_test2) = {
+U_BOOT_DRVINFO(spl_test2) = {
 \t.name\t\t= "sandbox_spl_test",
 \t.plat\t= &dtv_spl_test2,
 \t.plat_size\t= sizeof(dtv_spl_test2),
@@ -278,7 +278,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test3 = {
 \t\t0x0},
 \t.stringarray\t\t= {"one", "", ""},
 };
-U_BOOT_DEVICE(spl_test3) = {
+U_BOOT_DRVINFO(spl_test3) = {
 \t.name\t\t= "sandbox_spl_test",
 \t.plat\t= &dtv_spl_test3,
 \t.plat_size\t= sizeof(dtv_spl_test3),
@@ -333,7 +333,7 @@ static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
 \t.gpio_controller\t= true,
 \t.sandbox_gpio_count\t= 0x14,
 };
-U_BOOT_DEVICE(gpios_at_0) = {
+U_BOOT_DRVINFO(gpios_at_0) = {
 \t.name\t\t= "sandbox_gpio",
 \t.plat\t= &dtv_gpios_at_0,
 \t.plat_size\t= sizeof(dtv_gpios_at_0),
@@ -365,7 +365,7 @@ struct dtd_invalid {
 /* Node /spl-test index 0 */
 static struct dtd_invalid dtv_spl_test = {
 };
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
 \t.name\t\t= "invalid",
 \t.plat\t= &dtv_spl_test,
 \t.plat_size\t= sizeof(dtv_spl_test),
@@ -400,7 +400,7 @@ struct dtd_target {
 static struct dtd_target dtv_phandle2_target = {
 \t.intval\t\t\t= 0x1,
 };
-U_BOOT_DEVICE(phandle2_target) = {
+U_BOOT_DRVINFO(phandle2_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle2_target,
 \t.plat_size\t= sizeof(dtv_phandle2_target),
@@ -411,7 +411,7 @@ U_BOOT_DEVICE(phandle2_target) = {
 static struct dtd_target dtv_phandle3_target = {
 \t.intval\t\t\t= 0x2,
 };
-U_BOOT_DEVICE(phandle3_target) = {
+U_BOOT_DRVINFO(phandle3_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle3_target,
 \t.plat_size\t= sizeof(dtv_phandle3_target),
@@ -422,7 +422,7 @@ U_BOOT_DEVICE(phandle3_target) = {
 static struct dtd_target dtv_phandle_target = {
 \t.intval\t\t\t= 0x0,
 };
-U_BOOT_DEVICE(phandle_target) = {
+U_BOOT_DRVINFO(phandle_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle_target,
 \t.plat_size\t= sizeof(dtv_phandle_target),
@@ -437,7 +437,7 @@ static struct dtd_source dtv_phandle_source = {
 \t\t\t{1, {12, 13}},
 \t\t\t{4, {}},},
 };
-U_BOOT_DEVICE(phandle_source) = {
+U_BOOT_DRVINFO(phandle_source) = {
 \t.name\t\t= "source",
 \t.plat\t= &dtv_phandle_source,
 \t.plat_size\t= sizeof(dtv_phandle_source),
@@ -449,7 +449,7 @@ static struct dtd_source dtv_phandle_source2 = {
 \t.clocks\t\t\t= {
 \t\t\t{4, {}},},
 };
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
 \t.name\t\t= "source",
 \t.plat\t= &dtv_phandle_source2,
 \t.plat_size\t= sizeof(dtv_phandle_source2),
@@ -487,7 +487,7 @@ struct dtd_target {
 /* Node /phandle-target index 1 */
 static struct dtd_target dtv_phandle_target = {
 };
-U_BOOT_DEVICE(phandle_target) = {
+U_BOOT_DRVINFO(phandle_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle_target,
 \t.plat_size\t= sizeof(dtv_phandle_target),
@@ -499,7 +499,7 @@ static struct dtd_source dtv_phandle_source2 = {
 \t.clocks\t\t\t= {
 \t\t\t{1, {}},},
 };
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
 \t.name\t\t= "source",
 \t.plat\t= &dtv_phandle_source2,
 \t.plat_size\t= sizeof(dtv_phandle_source2),
@@ -522,7 +522,7 @@ void dm_populate_phandle_data(void) {
 static struct dtd_target dtv_phandle2_target = {
 \t.intval\t\t\t= 0x1,
 };
-U_BOOT_DEVICE(phandle2_target) = {
+U_BOOT_DRVINFO(phandle2_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle2_target,
 \t.plat_size\t= sizeof(dtv_phandle2_target),
@@ -533,7 +533,7 @@ U_BOOT_DEVICE(phandle2_target) = {
 static struct dtd_target dtv_phandle3_target = {
 \t.intval\t\t\t= 0x2,
 };
-U_BOOT_DEVICE(phandle3_target) = {
+U_BOOT_DRVINFO(phandle3_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle3_target,
 \t.plat_size\t= sizeof(dtv_phandle3_target),
@@ -544,7 +544,7 @@ U_BOOT_DEVICE(phandle3_target) = {
 static struct dtd_target dtv_phandle_target = {
 \t.intval\t\t\t= 0x0,
 };
-U_BOOT_DEVICE(phandle_target) = {
+U_BOOT_DRVINFO(phandle_target) = {
 \t.name\t\t= "target",
 \t.plat\t= &dtv_phandle_target,
 \t.plat_size\t= sizeof(dtv_phandle_target),
@@ -559,7 +559,7 @@ static struct dtd_source dtv_phandle_source = {
 \t\t\t{1, {12, 13}},
 \t\t\t{4, {}},},
 };
-U_BOOT_DEVICE(phandle_source) = {
+U_BOOT_DRVINFO(phandle_source) = {
 \t.name\t\t= "source",
 \t.plat\t= &dtv_phandle_source,
 \t.plat_size\t= sizeof(dtv_phandle_source),
@@ -571,7 +571,7 @@ static struct dtd_source dtv_phandle_source2 = {
 \t.cd_gpios\t\t= {
 \t\t\t{4, {}},},
 };
-U_BOOT_DEVICE(phandle_source2) = {
+U_BOOT_DRVINFO(phandle_source2) = {
 \t.name\t\t= "source",
 \t.plat\t= &dtv_phandle_source2,
 \t.plat_size\t= sizeof(dtv_phandle_source2),
@@ -629,7 +629,7 @@ struct dtd_test3 {
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
 };
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
 \t.name\t\t= "test1",
 \t.plat\t= &dtv_test1,
 \t.plat_size\t= sizeof(dtv_test1),
@@ -640,7 +640,7 @@ U_BOOT_DEVICE(test1) = {
 static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
 };
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
 \t.name\t\t= "test2",
 \t.plat\t= &dtv_test2,
 \t.plat_size\t= sizeof(dtv_test2),
@@ -651,7 +651,7 @@ U_BOOT_DEVICE(test2) = {
 static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
 };
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
 \t.name\t\t= "test3",
 \t.plat\t= &dtv_test3,
 \t.plat_size\t= sizeof(dtv_test3),
@@ -684,7 +684,7 @@ struct dtd_test2 {
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
 };
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
 \t.name\t\t= "test1",
 \t.plat\t= &dtv_test1,
 \t.plat_size\t= sizeof(dtv_test1),
@@ -695,7 +695,7 @@ U_BOOT_DEVICE(test1) = {
 static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
 };
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
 \t.name\t\t= "test2",
 \t.plat\t= &dtv_test2,
 \t.plat_size\t= sizeof(dtv_test2),
@@ -731,7 +731,7 @@ struct dtd_test3 {
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x123400000000, 0x5678},
 };
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
 \t.name\t\t= "test1",
 \t.plat\t= &dtv_test1,
 \t.plat_size\t= sizeof(dtv_test1),
@@ -742,7 +742,7 @@ U_BOOT_DEVICE(test1) = {
 static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x98765432},
 };
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
 \t.name\t\t= "test2",
 \t.plat\t= &dtv_test2,
 \t.plat_size\t= sizeof(dtv_test2),
@@ -753,7 +753,7 @@ U_BOOT_DEVICE(test2) = {
 static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
 };
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
 \t.name\t\t= "test3",
 \t.plat\t= &dtv_test3,
 \t.plat_size\t= sizeof(dtv_test3),
@@ -789,7 +789,7 @@ struct dtd_test3 {
 static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x567800000000},
 };
-U_BOOT_DEVICE(test1) = {
+U_BOOT_DRVINFO(test1) = {
 \t.name\t\t= "test1",
 \t.plat\t= &dtv_test1,
 \t.plat_size\t= sizeof(dtv_test1),
@@ -800,7 +800,7 @@ U_BOOT_DEVICE(test1) = {
 static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x12345678, 0x9876543210987654},
 };
-U_BOOT_DEVICE(test2) = {
+U_BOOT_DRVINFO(test2) = {
 \t.name\t\t= "test2",
 \t.plat\t= &dtv_test2,
 \t.plat_size\t= sizeof(dtv_test2),
@@ -811,7 +811,7 @@ U_BOOT_DEVICE(test2) = {
 static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
 };
-U_BOOT_DEVICE(test3) = {
+U_BOOT_DRVINFO(test3) = {
 \t.name\t\t= "test3",
 \t.plat\t= &dtv_test3,
 \t.plat_size\t= sizeof(dtv_test3),
@@ -863,7 +863,7 @@ struct dtd_sandbox_spl_test {
 static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.intval\t\t\t= 0x1,
 };
-U_BOOT_DEVICE(spl_test) = {
+U_BOOT_DRVINFO(spl_test) = {
 \t.name\t\t= "sandbox_spl_test",
 \t.plat\t= &dtv_spl_test,
 \t.plat_size\t= sizeof(dtv_spl_test),
@@ -874,7 +874,7 @@ U_BOOT_DEVICE(spl_test) = {
 static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.intarray\t\t= 0x5,
 };
-U_BOOT_DEVICE(spl_test2) = {
+U_BOOT_DRVINFO(spl_test2) = {
 \t.name\t\t= "sandbox_spl_test",
 \t.plat\t= &dtv_spl_test2,
 \t.plat_size\t= sizeof(dtv_spl_test2),
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (7 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2021-01-06  3:40   ` Walter Lozano
  2021-01-06 15:13   ` Simon Glass
  2020-12-29  3:34 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
                   ` (59 subsequent siblings)
  68 siblings, 2 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

This does not get a device (struct udevice *) but a struct driver_info *
so the name is confusing.

Rename it accordingly. Since we plan to have several various of these
macros, put GET at the end instead of the middle, so it is easier to spot
the related macros.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst |  2 +-
 include/dm/platdata.h        | 10 +++-------
 tools/dtoc/dtb_platdata.py   |  4 ++--
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
index 39e6295aa09..21b45f6a7e7 100644
--- a/doc/driver-model/of-plat.rst
+++ b/doc/driver-model/of-plat.rst
@@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with
 The dt-plat.c file contains the device declarations and is is built in
 spl/dt-plat.c. It additionally contains the definition of
 dm_populate_phandle_data() which is responsible of filling the phandle
-information by adding references to U_BOOT_DRVINFO by using DM_GET_DEVICE
+information by adding references to U_BOOT_DRVINFO by using DM_DRVINFO_GET
 
 The pylibfdt Python module is used to access the devicetree.
 
diff --git a/include/dm/platdata.h b/include/dm/platdata.h
index e2b16ce6e4e..df1f6abcc7e 100644
--- a/include/dm/platdata.h
+++ b/include/dm/platdata.h
@@ -74,27 +74,23 @@ struct driver_rt {
 /**
  * Get a pointer to a given device info given its name
  *
- * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a
+ * With the declaration U_BOOT_DRVINFO(name), DM_DRVINFO_GET(name) will return a
  * pointer to the struct driver_info created by that declaration.
  *
  * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
  * struct driver_info to find the device pointer itself.
  *
- * TODO(sjg at chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so
- * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
- * finds the driver_info record, not the device.
- *
  * @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
  * @return struct driver_info * to the driver that created the device
  */
-#define DM_GET_DEVICE(__name)						\
+#define DM_DRVINFO_GET(__name)						\
 	ll_entry_get(struct driver_info, __name, driver_info)
 
 /**
  * dm_populate_phandle_data() - Populates phandle data in platda
  *
  * This populates phandle data with an U_BOOT_DRVINFO entry get by
- * DM_GET_DEVICE. The implementation of this function will be done
+ * DM_DRVINFO_GET. The implementation of this function will be done
  * by dtoc when parsing dtb.
  */
 void dm_populate_phandle_data(void);
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index ebe5132e143..1a6a511b015 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -811,8 +811,8 @@ class DtbPlatdata():
             nodes_to_output.remove(node)
 
         # Define dm_populate_phandle_data() which will add the linking between
-        # nodes using DM_GET_DEVICE
-        # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
+        # nodes using DM_DRVINFO_GET
+        # dtv_dmc_at_xxx.clocks[0].node = DM_DRVINFO_GET(clock_controller_at_xxx)
         self.buf('void dm_populate_phandle_data(void) {\n')
         self.buf('}\n')
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (8 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
                   ` (58 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

In the spirit of using the same base name for all of these related macros,
rename this to have the operation at the end. This is not widely used so
the impact is fairly small.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/lib/gic-v3-its.c                       | 10 +++++-----
 arch/arm/mach-aspeed/ast2500/clk_ast2500.c      |  2 +-
 arch/arm/mach-k3/am6_init.c                     |  2 +-
 arch/arm/mach-k3/common.c                       |  2 +-
 arch/arm/mach-k3/j721e_init.c                   |  2 +-
 arch/arm/mach-mediatek/mt7629/init.c            |  4 ++--
 arch/arm/mach-mediatek/mt8516/init.c            |  2 +-
 arch/arm/mach-rockchip/misc.c                   |  4 ++--
 arch/arm/mach-rockchip/px30/clk_px30.c          |  2 +-
 arch/arm/mach-rockchip/rk3036/clk_rk3036.c      |  2 +-
 arch/arm/mach-rockchip/rk3128/clk_rk3128.c      |  2 +-
 arch/arm/mach-rockchip/rk3188/clk_rk3188.c      |  2 +-
 arch/arm/mach-rockchip/rk322x/clk_rk322x.c      |  2 +-
 arch/arm/mach-rockchip/rk3288/clk_rk3288.c      |  2 +-
 arch/arm/mach-rockchip/rk3308/clk_rk3308.c      |  2 +-
 arch/arm/mach-rockchip/rk3328/clk_rk3328.c      |  2 +-
 arch/arm/mach-rockchip/rk3368/clk_rk3368.c      |  2 +-
 arch/arm/mach-rockchip/rk3399/clk_rk3399.c      |  4 ++--
 arch/arm/mach-rockchip/rv1108/clk_rv1108.c      |  2 +-
 arch/arm/mach-socfpga/clock_manager_agilex.c    |  2 +-
 arch/arm/mach-stm32mp/bsec.c                    |  2 +-
 arch/arm/mach-stm32mp/cmd_stm32key.c            |  2 +-
 arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c |  6 +++---
 arch/arm/mach-stm32mp/cpu.c                     |  6 +++---
 arch/arm/mach-uniphier/micro-support-card.c     |  2 +-
 arch/arm/mach-zynq/clk.c                        |  4 ++--
 arch/arm/mach-zynq/timer.c                      |  2 +-
 arch/mips/mach-mtmips/mt7628/init.c             |  2 +-
 arch/riscv/lib/sifive_clint.c                   |  2 +-
 board/dhelectronics/dh_stm32mp1/board.c         |  6 +++---
 board/google/gru/gru.c                          |  2 +-
 board/nvidia/jetson-tk1/jetson-tk1.c            |  2 +-
 board/nvidia/nyan-big/nyan-big.c                |  2 +-
 board/renesas/ulcb/cpld.c                       |  2 +-
 board/sifive/fu540/fu540.c                      |  2 +-
 board/st/common/cmd_stboard.c                   |  2 +-
 board/st/common/stm32mp_dfu.c                   |  4 ++--
 board/st/common/stpmic1.c                       |  4 ++--
 board/st/common/stusb160x.c                     |  2 +-
 board/st/stm32mp1/stm32mp1.c                    | 12 ++++++------
 board/ti/j721e/evm.c                            |  4 ++--
 board/toradex/apalis-tk1/apalis-tk1.c           |  4 ++--
 drivers/clk/clk_stm32mp1.c                      |  2 +-
 drivers/clk/clk_zynqmp.c                        |  2 +-
 drivers/clk/imx/clk-imx8.c                      |  2 +-
 drivers/clk/mediatek/clk-mtk.c                  |  6 +++---
 drivers/clk/sifive/fu540-prci.c                 |  2 +-
 drivers/firmware/scmi/scmi_agent-uclass.c       |  4 ++--
 drivers/gpio/gpio-uclass.c                      |  2 +-
 drivers/misc/i2c_eeprom.c                       |  2 +-
 drivers/misc/rockchip-efuse.c                   |  2 +-
 drivers/misc/stm32mp_fuse.c                     | 16 ++++++++--------
 drivers/mtd/nand/raw/arasan_nfc.c               |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c   |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c    |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c   |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c    |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c    |  2 +-
 drivers/mtd/nand/raw/davinci_nand.c             |  2 +-
 drivers/mtd/nand/raw/denali_dt.c                |  2 +-
 drivers/mtd/nand/raw/mxs_nand_dt.c              |  2 +-
 drivers/mtd/nand/raw/octeontx_nand.c            |  6 +++---
 drivers/mtd/nand/raw/pxa3xx_nand.c              |  2 +-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c          |  2 +-
 drivers/mtd/nand/raw/tegra_nand.c               |  2 +-
 drivers/mtd/nand/raw/vf610_nfc.c                |  2 +-
 drivers/mtd/nand/raw/zynq_nand.c                |  2 +-
 drivers/reset/reset-ast2500.c                   |  2 +-
 drivers/video/lg4573.c                          |  2 +-
 include/dm/device.h                             |  2 +-
 include/dm/uclass.h                             |  2 +-
 test/dm/core.c                                  |  2 +-
 test/dm/test-fdt.c                              |  6 +++---
 73 files changed, 110 insertions(+), 110 deletions(-)

diff --git a/arch/arm/lib/gic-v3-its.c b/arch/arm/lib/gic-v3-its.c
index a1657e38536..f5a921b3d1b 100644
--- a/arch/arm/lib/gic-v3-its.c
+++ b/arch/arm/lib/gic-v3-its.c
@@ -43,10 +43,10 @@ static int gic_v3_its_get_gic_addr(struct gic_v3_its_priv *priv)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_IRQ,
-					  DM_GET_DRIVER(arm_gic_v3_its), &dev);
+					  DM_DRIVER_GET(arm_gic_v3_its), &dev);
 	if (ret) {
 		pr_err("%s: failed to get %s irq device\n", __func__,
-		       DM_GET_DRIVER(arm_gic_v3_its)->name);
+		       DM_DRIVER_GET(arm_gic_v3_its)->name);
 		return ret;
 	}
 
@@ -74,17 +74,17 @@ static int gic_v3_its_get_gic_lpi_addr(struct gic_v3_its_priv *priv)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_SYSCON,
-					  DM_GET_DRIVER(gic_lpi_syscon), &dev);
+					  DM_DRIVER_GET(gic_lpi_syscon), &dev);
 	if (ret) {
 		pr_err("%s: failed to get %s syscon device\n", __func__,
-		       DM_GET_DRIVER(gic_lpi_syscon)->name);
+		       DM_DRIVER_GET(gic_lpi_syscon)->name);
 		return ret;
 	}
 
 	regmap = syscon_get_regmap(dev);
 	if (!regmap) {
 		pr_err("%s: failed to regmap for %s syscon device\n", __func__,
-		       DM_GET_DRIVER(gic_lpi_syscon)->name);
+		       DM_DRIVER_GET(gic_lpi_syscon)->name);
 		return -ENODEV;
 	}
 	priv->lpi_base = regmap->ranges[0].start;
diff --git a/arch/arm/mach-aspeed/ast2500/clk_ast2500.c b/arch/arm/mach-aspeed/ast2500/clk_ast2500.c
index 3e9f5e57ed0..02bd3f67c96 100644
--- a/arch/arm/mach-aspeed/ast2500/clk_ast2500.c
+++ b/arch/arm/mach-aspeed/ast2500/clk_ast2500.c
@@ -12,7 +12,7 @@
 int ast_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(aspeed_ast2500_scu), devp);
+			DM_DRIVER_GET(aspeed_ast2500_scu), devp);
 }
 
 void *ast_get_scu(void)
diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
index 0fed5aec59d..dea470c02f7 100644
--- a/arch/arm/mach-k3/am6_init.c
+++ b/arch/arm/mach-k3/am6_init.c
@@ -238,7 +238,7 @@ void board_init_f(ulong dummy)
 	do_board_detect();
 
 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
-	ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
+	ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
 					  &dev);
 	if (ret)
 		printf("AVS init failed: %d\n", ret);
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 8c903f14ff8..8b54e0cf529 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -33,7 +33,7 @@ struct ti_sci_handle *get_ti_sci_handle(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
-					  DM_GET_DRIVER(ti_sci), &dev);
+					  DM_DRIVER_GET(ti_sci), &dev);
 	if (ret)
 		panic("Failed to get SYSFW (%d)\n", ret);
 
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 0201690f93c..1a4f796e5ef 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -206,7 +206,7 @@ void board_init_f(ulong dummy)
 		do_board_detect();
 
 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
-	ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
+	ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
 					  &dev);
 	if (ret)
 		printf("AVS init failed: %d\n", ret);
diff --git a/arch/arm/mach-mediatek/mt7629/init.c b/arch/arm/mach-mediatek/mt7629/init.c
index c260413a57a..1f102dddd4f 100644
--- a/arch/arm/mach-mediatek/mt7629/init.c
+++ b/arch/arm/mach-mediatek/mt7629/init.c
@@ -40,7 +40,7 @@ int mtk_pll_early_init(void)
 	int ret, i;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(mtk_clk_apmixedsys), &dev);
+			DM_DRIVER_GET(mtk_clk_apmixedsys), &dev);
 	if (ret)
 		return ret;
 
@@ -59,7 +59,7 @@ int mtk_pll_early_init(void)
 
 	/* setup mcu bus */
 	ret = uclass_get_device_by_driver(UCLASS_SYSCON,
-			DM_GET_DRIVER(mtk_mcucfg), &dev);
+			DM_DRIVER_GET(mtk_mcucfg), &dev);
 	if (ret)
 		return ret;
 
diff --git a/arch/arm/mach-mediatek/mt8516/init.c b/arch/arm/mach-mediatek/mt8516/init.c
index 13be3912211..2ffa5595cfc 100644
--- a/arch/arm/mach-mediatek/mt8516/init.c
+++ b/arch/arm/mach-mediatek/mt8516/init.c
@@ -52,7 +52,7 @@ int mtk_pll_early_init(void)
 	int ret, i;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(mtk_clk_apmixedsys), &dev);
+			DM_DRIVER_GET(mtk_clk_apmixedsys), &dev);
 	if (ret)
 		return ret;
 
diff --git a/arch/arm/mach-rockchip/misc.c b/arch/arm/mach-rockchip/misc.c
index 28c7c7214cb..87eebd9872d 100644
--- a/arch/arm/mach-rockchip/misc.c
+++ b/arch/arm/mach-rockchip/misc.c
@@ -67,10 +67,10 @@ int rockchip_cpuid_from_efuse(const u32 cpuid_offset,
 	/* retrieve the device */
 #if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(rockchip_efuse), &dev);
+					  DM_DRIVER_GET(rockchip_efuse), &dev);
 #elif CONFIG_IS_ENABLED(ROCKCHIP_OTP)
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(rockchip_otp), &dev);
+					  DM_DRIVER_GET(rockchip_otp), &dev);
 #endif
 	if (ret) {
 		debug("%s: could not find efuse device\n", __func__);
diff --git a/arch/arm/mach-rockchip/px30/clk_px30.c b/arch/arm/mach-rockchip/px30/clk_px30.c
index 98a1bcd224f..7edf1321feb 100644
--- a/arch/arm/mach-rockchip/px30/clk_px30.c
+++ b/arch/arm/mach-rockchip/px30/clk_px30.c
@@ -13,7 +13,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_px30_cru), devp);
+			DM_DRIVER_GET(rockchip_px30_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3036/clk_rk3036.c b/arch/arm/mach-rockchip/rk3036/clk_rk3036.c
index 5d0def3b524..116dccd7b87 100644
--- a/arch/arm/mach-rockchip/rk3036/clk_rk3036.c
+++ b/arch/arm/mach-rockchip/rk3036/clk_rk3036.c
@@ -14,7 +14,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3036_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3036_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3128/clk_rk3128.c b/arch/arm/mach-rockchip/rk3128/clk_rk3128.c
index f9ce1f72348..a1b038c6486 100644
--- a/arch/arm/mach-rockchip/rk3128/clk_rk3128.c
+++ b/arch/arm/mach-rockchip/rk3128/clk_rk3128.c
@@ -13,7 +13,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3128_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3128_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3188/clk_rk3188.c b/arch/arm/mach-rockchip/rk3188/clk_rk3188.c
index a0dcac37324..94d1d23e1f4 100644
--- a/arch/arm/mach-rockchip/rk3188/clk_rk3188.c
+++ b/arch/arm/mach-rockchip/rk3188/clk_rk3188.c
@@ -14,7 +14,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3188_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3188_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk322x/clk_rk322x.c b/arch/arm/mach-rockchip/rk322x/clk_rk322x.c
index fc5abd736e8..2e57672b246 100644
--- a/arch/arm/mach-rockchip/rk322x/clk_rk322x.c
+++ b/arch/arm/mach-rockchip/rk322x/clk_rk322x.c
@@ -13,7 +13,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk322x_cru), devp);
+			DM_DRIVER_GET(rockchip_rk322x_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3288/clk_rk3288.c b/arch/arm/mach-rockchip/rk3288/clk_rk3288.c
index e05bd06a8d2..fb4c0891d0d 100644
--- a/arch/arm/mach-rockchip/rk3288/clk_rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/clk_rk3288.c
@@ -14,7 +14,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3288_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3288_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3308/clk_rk3308.c b/arch/arm/mach-rockchip/rk3308/clk_rk3308.c
index 1feb2372240..ccda53380c6 100644
--- a/arch/arm/mach-rockchip/rk3308/clk_rk3308.c
+++ b/arch/arm/mach-rockchip/rk3308/clk_rk3308.c
@@ -13,7 +13,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3308_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3308_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3328/clk_rk3328.c b/arch/arm/mach-rockchip/rk3328/clk_rk3328.c
index e5375514def..70c0eb6f98e 100644
--- a/arch/arm/mach-rockchip/rk3328/clk_rk3328.c
+++ b/arch/arm/mach-rockchip/rk3328/clk_rk3328.c
@@ -12,7 +12,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3328_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3328_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3368/clk_rk3368.c b/arch/arm/mach-rockchip/rk3368/clk_rk3368.c
index 9a33c67bc94..b075319720d 100644
--- a/arch/arm/mach-rockchip/rk3368/clk_rk3368.c
+++ b/arch/arm/mach-rockchip/rk3368/clk_rk3368.c
@@ -14,7 +14,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3368_cru), devp);
+			DM_DRIVER_GET(rockchip_rk3368_cru), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-rockchip/rk3399/clk_rk3399.c b/arch/arm/mach-rockchip/rk3399/clk_rk3399.c
index d23a5e9435c..9d9a837fc74 100644
--- a/arch/arm/mach-rockchip/rk3399/clk_rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/clk_rk3399.c
@@ -14,7 +14,7 @@
 static int rockchip_get_cruclk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(clk_rk3399), devp);
+			DM_DRIVER_GET(clk_rk3399), devp);
 }
 
 void *rockchip_get_cru(void)
@@ -35,7 +35,7 @@ void *rockchip_get_cru(void)
 static int rockchip_get_pmucruclk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(rockchip_rk3399_pmuclk), devp);
+			DM_DRIVER_GET(rockchip_rk3399_pmuclk), devp);
 }
 
 void *rockchip_get_pmucru(void)
diff --git a/arch/arm/mach-rockchip/rv1108/clk_rv1108.c b/arch/arm/mach-rockchip/rv1108/clk_rv1108.c
index b37ae1c4945..44b53c407a7 100644
--- a/arch/arm/mach-rockchip/rv1108/clk_rv1108.c
+++ b/arch/arm/mach-rockchip/rv1108/clk_rv1108.c
@@ -14,7 +14,7 @@
 int rockchip_get_clk(struct udevice **devp)
 {
 	return uclass_get_device_by_driver(UCLASS_CLK,
-			DM_GET_DRIVER(clk_rv1108), devp);
+			DM_DRIVER_GET(clk_rv1108), devp);
 }
 
 void *rockchip_get_cru(void)
diff --git a/arch/arm/mach-socfpga/clock_manager_agilex.c b/arch/arm/mach-socfpga/clock_manager_agilex.c
index 6188a8c3d2d..a960176da77 100644
--- a/arch/arm/mach-socfpga/clock_manager_agilex.c
+++ b/arch/arm/mach-socfpga/clock_manager_agilex.c
@@ -24,7 +24,7 @@ static ulong cm_get_rate_dm(u32 id)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-					  DM_GET_DRIVER(socfpga_agilex_clk),
+					  DM_DRIVER_GET(socfpga_agilex_clk),
 					  &dev);
 	if (ret)
 		return 0;
diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c
index 85a9e6f84e7..84e0bddcd44 100644
--- a/arch/arm/mach-stm32mp/bsec.c
+++ b/arch/arm/mach-stm32mp/bsec.c
@@ -525,7 +525,7 @@ bool bsec_dbgswenable(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec), &dev);
+					  DM_DRIVER_GET(stm32mp_bsec), &dev);
 	if (ret || !dev) {
 		pr_debug("bsec driver not available\n");
 		return false;
diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c
index f191085a12d..544bab38480 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32key.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32key.c
@@ -31,7 +31,7 @@ static void fuse_hash_value(u32 addr, bool print)
 	int i, ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 	if (ret) {
 		pr_err("Can't find stm32mp_bsec driver\n");
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
index a777827c55e..fc9a2af5459 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
@@ -1340,7 +1340,7 @@ int stm32prog_pmic_read(struct stm32prog_data *data, u32 offset, u8 *buffer,
 
 	pr_debug("%s: %x %lx\n", __func__, offset, *size);
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stpmic1_nvm),
+					  DM_DRIVER_GET(stpmic1_nvm),
 					  &dev);
 	if (ret)
 		return ret;
@@ -1351,7 +1351,7 @@ int stm32prog_pmic_read(struct stm32prog_data *data, u32 offset, u8 *buffer,
 		memset(data->pmic_part, 0, PMIC_SIZE);
 
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stpmic1_nvm),
+						  DM_DRIVER_GET(stpmic1_nvm),
 						  &dev);
 		if (ret)
 			return ret;
@@ -1389,7 +1389,7 @@ int stm32prog_pmic_start(struct stm32prog_data *data)
 	}
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stpmic1_nvm),
+					  DM_DRIVER_GET(stpmic1_nvm),
 					  &dev);
 	if (ret)
 		return ret;
diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index 1520c6eaed6..29c0d92195c 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -318,7 +318,7 @@ static u32 get_otp(int index, int shift, int mask)
 	u32 otp = 0;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 
 	if (!ret)
@@ -563,7 +563,7 @@ __weak int setup_mac_address(void)
 		return 0;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 	if (ret)
 		return ret;
@@ -601,7 +601,7 @@ static int setup_serial_number(void)
 		return 0;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 	if (ret)
 		return ret;
diff --git a/arch/arm/mach-uniphier/micro-support-card.c b/arch/arm/mach-uniphier/micro-support-card.c
index dbd156ffcec..95780f79c2c 100644
--- a/arch/arm/mach-uniphier/micro-support-card.c
+++ b/arch/arm/mach-uniphier/micro-support-card.c
@@ -95,7 +95,7 @@ void support_card_init(void)
 
 	/* The system bus must be initialized for access to the support card. */
 	ret = uclass_get_device_by_driver(UCLASS_SIMPLE_BUS,
-					  DM_GET_DRIVER(uniphier_system_bus_driver),
+					  DM_DRIVER_GET(uniphier_system_bus_driver),
 					  &dev);
 	if (ret)
 		return;
diff --git a/arch/arm/mach-zynq/clk.c b/arch/arm/mach-zynq/clk.c
index 1ace117fc8e..856047613c1 100644
--- a/arch/arm/mach-zynq/clk.c
+++ b/arch/arm/mach-zynq/clk.c
@@ -40,7 +40,7 @@ int set_cpu_clk_info(void)
 	int i, ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-		DM_GET_DRIVER(zynq_clk), &dev);
+		DM_DRIVER_GET(zynq_clk), &dev);
 	if (ret)
 		return ret;
 
@@ -75,7 +75,7 @@ int soc_clk_dump(void)
 	int i, ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-		DM_GET_DRIVER(zynq_clk), &dev);
+		DM_DRIVER_GET(zynq_clk), &dev);
 	if (ret)
 		return ret;
 
diff --git a/arch/arm/mach-zynq/timer.c b/arch/arm/mach-zynq/timer.c
index cc0e24cbfed..37193157d9e 100644
--- a/arch/arm/mach-zynq/timer.c
+++ b/arch/arm/mach-zynq/timer.c
@@ -68,7 +68,7 @@ int timer_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-		DM_GET_DRIVER(zynq_clk), &dev);
+		DM_DRIVER_GET(zynq_clk), &dev);
 	if (ret)
 		return ret;
 
diff --git a/arch/mips/mach-mtmips/mt7628/init.c b/arch/mips/mach-mtmips/mt7628/init.c
index 77d1f2ea0dc..33538647a2d 100644
--- a/arch/mips/mach-mtmips/mt7628/init.c
+++ b/arch/mips/mach-mtmips/mt7628/init.c
@@ -74,7 +74,7 @@ int print_cpuinfo(void)
 	       ddr ? "" : "2", chipmode & 0x01 ? 4 : 3,
 	       chipmode & 0x02 ? "XTAL" : "CPLL");
 
-	ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(mt7628_clk),
+	ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(mt7628_clk),
 					  &clkdev);
 	if (ret)
 		return ret;
diff --git a/arch/riscv/lib/sifive_clint.c b/arch/riscv/lib/sifive_clint.c
index c8079dc510c..cfa288a01a8 100644
--- a/arch/riscv/lib/sifive_clint.c
+++ b/arch/riscv/lib/sifive_clint.c
@@ -25,7 +25,7 @@ int riscv_init_ipi(void)
 	struct udevice *dev;
 
 	ret = uclass_get_device_by_driver(UCLASS_TIMER,
-					  DM_GET_DRIVER(sifive_clint), &dev);
+					  DM_DRIVER_GET(sifive_clint), &dev);
 	if (ret)
 		return ret;
 
diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index f42d395098b..35669c252bf 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -343,7 +343,7 @@ int g_dnl_board_usb_cable_connected(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
-					  DM_GET_DRIVER(dwc2_udc_otg),
+					  DM_DRIVER_GET(dwc2_udc_otg),
 					  &dwc2_udc_otg);
 	if (!ret)
 		debug("dwc2_udc_otg init failed\n");
@@ -475,11 +475,11 @@ static void sysconf_init(void)
 	 *      but this value need to be consistent with board design
 	 */
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(stm32mp_pwr_pmic),
+					  DM_DRIVER_GET(stm32mp_pwr_pmic),
 					  &pwr_dev);
 	if (!ret) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret) {
 			pr_err("Can't find stm32mp_bsec driver\n");
diff --git a/board/google/gru/gru.c b/board/google/gru/gru.c
index 441a1a376a9..23080c1798b 100644
--- a/board/google/gru/gru.c
+++ b/board/google/gru/gru.c
@@ -45,7 +45,7 @@ int board_early_init_r(void)
 	 * setting up.
 	 */
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-					  DM_GET_DRIVER(clk_rk3399), &clk);
+					  DM_DRIVER_GET(clk_rk3399), &clk);
 	if (ret) {
 		debug("%s: CLK init failed: %d\n", __func__, ret);
 		return ret;
diff --git a/board/nvidia/jetson-tk1/jetson-tk1.c b/board/nvidia/jetson-tk1/jetson-tk1.c
index 9eccdc4a832..d349531261e 100644
--- a/board/nvidia/jetson-tk1/jetson-tk1.c
+++ b/board/nvidia/jetson-tk1/jetson-tk1.c
@@ -60,7 +60,7 @@ int tegra_pcie_board_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(pmic_as3722), &dev);
+					  DM_DRIVER_GET(pmic_as3722), &dev);
 	if (ret) {
 		debug("%s: Failed to find PMIC\n", __func__);
 		return ret;
diff --git a/board/nvidia/nyan-big/nyan-big.c b/board/nvidia/nyan-big/nyan-big.c
index 71c71ed6ec2..06a36f8ed38 100644
--- a/board/nvidia/nyan-big/nyan-big.c
+++ b/board/nvidia/nyan-big/nyan-big.c
@@ -52,7 +52,7 @@ int tegra_lcd_pmic_init(int board_id)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(pmic_as3722), &dev);
+					  DM_DRIVER_GET(pmic_as3722), &dev);
 	if (ret) {
 		debug("%s: Failed to find PMIC\n", __func__);
 		return ret;
diff --git a/board/renesas/ulcb/cpld.c b/board/renesas/ulcb/cpld.c
index e3fa3526b75..ebb2d6f7420 100644
--- a/board/renesas/ulcb/cpld.c
+++ b/board/renesas/ulcb/cpld.c
@@ -91,7 +91,7 @@ static int do_cpld(struct cmd_tbl *cmdtp, int flag, int argc,
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_SYSRESET,
-					  DM_GET_DRIVER(sysreset_renesas_ulcb),
+					  DM_DRIVER_GET(sysreset_renesas_ulcb),
 					  &dev);
 	if (ret)
 		return ret;
diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
index 54e5a4c1673..a4e78220cba 100644
--- a/board/sifive/fu540/fu540.c
+++ b/board/sifive/fu540/fu540.c
@@ -58,7 +58,7 @@ static u32 fu540_read_serialnum(void)
 
 	/* init OTP */
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(sifive_otp), &dev);
+					  DM_DRIVER_GET(sifive_otp), &dev);
 
 	if (ret) {
 		debug("%s: could not find otp device\n", __func__);
diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c
index e1038619f0c..2fba3831685 100644
--- a/board/st/common/cmd_stboard.c
+++ b/board/st/common/cmd_stboard.c
@@ -85,7 +85,7 @@ static int do_stboard(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_USAGE;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 
 	ret = misc_read(dev, STM32_BSEC_OTP(BSEC_OTP_BOARD),
diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c
index aab7d741ac6..9c3d115dce7 100644
--- a/board/st/common/stm32mp_dfu.c
+++ b/board/st/common/stm32mp_dfu.c
@@ -163,7 +163,7 @@ static int dfu_otp_read(u64 offset, u8 *buffer, long *size)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stm32mp_bsec),
+					  DM_DRIVER_GET(stm32mp_bsec),
 					  &dev);
 	if (ret)
 		return ret;
@@ -184,7 +184,7 @@ static int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
 	struct udevice *dev;
 
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(stpmic1_nvm),
+					  DM_DRIVER_GET(stpmic1_nvm),
 					  &dev);
 	if (ret)
 		return ret;
diff --git a/board/st/common/stpmic1.c b/board/st/common/stpmic1.c
index 3aa379e8a50..a313b817c57 100644
--- a/board/st/common/stpmic1.c
+++ b/board/st/common/stpmic1.c
@@ -20,7 +20,7 @@ int board_ddr_power_init(enum ddr_type ddr_type)
 	u32 buck2;
 
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(pmic_stpmic1), &dev);
+					  DM_DRIVER_GET(pmic_stpmic1), &dev);
 	if (ret)
 		/* No PMIC on board */
 		return 0;
@@ -187,7 +187,7 @@ void stpmic1_init(u32 voltage_mv)
 	struct udevice *dev;
 
 	if (uclass_get_device_by_driver(UCLASS_PMIC,
-					DM_GET_DRIVER(pmic_stpmic1), &dev))
+					DM_DRIVER_GET(pmic_stpmic1), &dev))
 		return;
 
 	/* update VDDCORE = BUCK1 */
diff --git a/board/st/common/stusb160x.c b/board/st/common/stusb160x.c
index f1197f9faa4..e0a2b76353a 100644
--- a/board/st/common/stusb160x.c
+++ b/board/st/common/stusb160x.c
@@ -22,7 +22,7 @@ int stusb160x_cable_connected(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_I2C_GENERIC,
-					  DM_GET_DRIVER(stusb160x),
+					  DM_DRIVER_GET(stusb160x),
 					  &dev);
 	if (ret < 0)
 		return ret;
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 8a3ce0a6f59..08393b27eb2 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -116,7 +116,7 @@ int checkboard(void)
 	/* display the STMicroelectronics board identification */
 	if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (!ret)
 			ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
@@ -196,7 +196,7 @@ int g_dnl_board_usb_cable_connected(void)
 		return ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
-					  DM_GET_DRIVER(dwc2_udc_otg),
+					  DM_DRIVER_GET(dwc2_udc_otg),
 					  &dwc2_udc_otg);
 	if (!ret)
 		debug("dwc2_udc_otg init failed\n");
@@ -464,11 +464,11 @@ static void sysconf_init(void)
 	 *      but this value need to be consistent with board design
 	 */
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(stm32mp_pwr_pmic),
+					  DM_DRIVER_GET(stm32mp_pwr_pmic),
 					  &pwr_dev);
 	if (!ret && IS_ENABLED(CONFIG_DM_REGULATOR)) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret) {
 			pr_err("Can't find stm32mp_bsec driver\n");
@@ -618,7 +618,7 @@ static void board_ev1_init(void)
 	struct udevice *dev;
 
 	/* configure IRQ line on EV1 for touchscreen before LCD reset */
-	uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev);
+	uclass_get_device_by_driver(UCLASS_NOP, DM_DRIVER_GET(goodix), &dev);
 }
 
 /* board dependent setup after realloc */
@@ -680,7 +680,7 @@ int board_late_init(void)
 			}
 		}
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 
 		if (!ret)
diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c
index d8711eb9005..44969e80b4d 100644
--- a/board/ti/j721e/evm.c
+++ b/board/ti/j721e/evm.c
@@ -411,7 +411,7 @@ void spl_board_init(void)
 #ifdef CONFIG_ESM_K3
 	if (board_ti_k3_is("J721EX-PM2-SOM")) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(k3_esm), &dev);
+						  DM_DRIVER_GET(k3_esm), &dev);
 		if (ret)
 			printf("ESM init failed: %d\n", ret);
 	}
@@ -420,7 +420,7 @@ void spl_board_init(void)
 #ifdef CONFIG_ESM_PMIC
 	if (board_ti_k3_is("J721EX-PM2-SOM")) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(pmic_esm),
+						  DM_DRIVER_GET(pmic_esm),
 						  &dev);
 		if (ret)
 			printf("ESM PMIC init failed: %d\n", ret);
diff --git a/board/toradex/apalis-tk1/apalis-tk1.c b/board/toradex/apalis-tk1/apalis-tk1.c
index e7a2186c2c4..b97617cfca3 100644
--- a/board/toradex/apalis-tk1/apalis-tk1.c
+++ b/board/toradex/apalis-tk1/apalis-tk1.c
@@ -155,7 +155,7 @@ int tegra_pcie_board_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
-					  DM_GET_DRIVER(pmic_as3722), &dev);
+					  DM_DRIVER_GET(pmic_as3722), &dev);
 	if (ret) {
 		pr_err("failed to find AS3722 PMIC: %d\n", ret);
 		return ret;
@@ -194,7 +194,7 @@ void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
 		int ret;
 
 		ret = uclass_get_device_by_driver(UCLASS_PMIC,
-						  DM_GET_DRIVER(pmic_as3722),
+						  DM_DRIVER_GET(pmic_as3722),
 						  &dev);
 		if (ret) {
 			debug("%s: Failed to find PMIC\n", __func__);
diff --git a/drivers/clk/clk_stm32mp1.c b/drivers/clk/clk_stm32mp1.c
index 72cbcdf6a21..5bea2b60b9b 100644
--- a/drivers/clk/clk_stm32mp1.c
+++ b/drivers/clk/clk_stm32mp1.c
@@ -2253,7 +2253,7 @@ int soc_clk_dump(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-					  DM_GET_DRIVER(stm32mp1_clock),
+					  DM_DRIVER_GET(stm32mp1_clock),
 					  &dev);
 	if (ret)
 		return ret;
diff --git a/drivers/clk/clk_zynqmp.c b/drivers/clk/clk_zynqmp.c
index a9988d8f1a8..e8acca00660 100644
--- a/drivers/clk/clk_zynqmp.c
+++ b/drivers/clk/clk_zynqmp.c
@@ -617,7 +617,7 @@ int soc_clk_dump(void)
 	int i, ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-		DM_GET_DRIVER(zynqmp_clk), &dev);
+		DM_DRIVER_GET(zynqmp_clk), &dev);
 	if (ret)
 		return ret;
 
diff --git a/drivers/clk/imx/clk-imx8.c b/drivers/clk/imx/clk-imx8.c
index 27a652a625a..8484613eed5 100644
--- a/drivers/clk/imx/clk-imx8.c
+++ b/drivers/clk/imx/clk-imx8.c
@@ -51,7 +51,7 @@ int soc_clk_dump(void)
 	int i, ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-					  DM_GET_DRIVER(imx8_clk), &dev);
+					  DM_DRIVER_GET(imx8_clk), &dev);
 	if (ret)
 		return ret;
 
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 388471b03a9..d43b8a0648c 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -296,7 +296,7 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off)
 	switch (fdiv->flags & CLK_PARENT_MASK) {
 	case CLK_PARENT_APMIXED:
 		rate = mtk_clk_find_parent_rate(clk, fdiv->parent,
-				DM_GET_DRIVER(mtk_clk_apmixedsys));
+				DM_DRIVER_GET(mtk_clk_apmixedsys));
 		break;
 	case CLK_PARENT_TOPCKGEN:
 		rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL);
@@ -474,11 +474,11 @@ static ulong mtk_clk_gate_get_rate(struct clk *clk)
 	switch (gate->flags & CLK_PARENT_MASK) {
 	case CLK_PARENT_APMIXED:
 		return mtk_clk_find_parent_rate(clk, gate->parent,
-				DM_GET_DRIVER(mtk_clk_apmixedsys));
+				DM_DRIVER_GET(mtk_clk_apmixedsys));
 		break;
 	case CLK_PARENT_TOPCKGEN:
 		return mtk_clk_find_parent_rate(clk, gate->parent,
-				DM_GET_DRIVER(mtk_clk_topckgen));
+				DM_DRIVER_GET(mtk_clk_topckgen));
 		break;
 
 	default:
diff --git a/drivers/clk/sifive/fu540-prci.c b/drivers/clk/sifive/fu540-prci.c
index 9a08c148a0d..b3882d0b77d 100644
--- a/drivers/clk/sifive/fu540-prci.c
+++ b/drivers/clk/sifive/fu540-prci.c
@@ -537,7 +537,7 @@ static int __prci_consumer_reset(const char *rst_name, bool trigger)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_RESET,
-					  DM_GET_DRIVER(sifive_reset),
+					  DM_DRIVER_GET(sifive_reset),
 					  &dev);
 	if (ret) {
 		dev_err(dev, "Reset driver not found: %d\n", ret);
diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index b3d3f0a51b0..516e690ac2d 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -73,11 +73,11 @@ static int scmi_bind_protocols(struct udevice *dev)
 		switch (protocol_id) {
 		case SCMI_PROTOCOL_ID_CLOCK:
 			if (IS_ENABLED(CONFIG_CLK_SCMI))
-				drv = DM_GET_DRIVER(scmi_clock);
+				drv = DM_DRIVER_GET(scmi_clock);
 			break;
 		case SCMI_PROTOCOL_ID_RESET_DOMAIN:
 			if (IS_ENABLED(CONFIG_RESET_SCMI))
-				drv = DM_GET_DRIVER(scmi_reset_domain);
+				drv = DM_DRIVER_GET(scmi_reset_domain);
 			break;
 		default:
 			break;
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 952c111b087..bad6b71e0c3 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -306,7 +306,7 @@ int gpio_hog_probe_all(void)
 	for (uclass_first_device(UCLASS_NOP, &dev);
 	     dev;
 	     uclass_find_next_device(&dev)) {
-		if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
+		if (dev->driver == DM_DRIVER_GET(gpio_hog)) {
 			ret = device_probe(dev);
 			if (ret) {
 				printf("Failed to probe device %s err: %d\n",
diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c
index 9ffd28f597d..5926c91a2ec 100644
--- a/drivers/misc/i2c_eeprom.c
+++ b/drivers/misc/i2c_eeprom.c
@@ -131,7 +131,7 @@ static int i2c_eeprom_std_bind(struct udevice *dev)
 		if (!name)
 			continue;
 
-		device_bind(dev, DM_GET_DRIVER(i2c_eeprom_partition), name,
+		device_bind(dev, DM_DRIVER_GET(i2c_eeprom_partition), name,
 			    NULL, partition, NULL);
 	}
 
diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c
index be25389e0e3..083ee65e0ad 100644
--- a/drivers/misc/rockchip-efuse.c
+++ b/drivers/misc/rockchip-efuse.c
@@ -58,7 +58,7 @@ static int dump_efuses(struct cmd_tbl *cmdtp, int flag,
 
 	/* retrieve the device */
 	ret = uclass_get_device_by_driver(UCLASS_MISC,
-					  DM_GET_DRIVER(rockchip_efuse), &dev);
+					  DM_DRIVER_GET(rockchip_efuse), &dev);
 	if (ret) {
 		printf("%s: no misc-device found\n", __func__);
 		return 0;
diff --git a/drivers/misc/stm32mp_fuse.c b/drivers/misc/stm32mp_fuse.c
index 0eed3459734..9fd6c367dc6 100644
--- a/drivers/misc/stm32mp_fuse.c
+++ b/drivers/misc/stm32mp_fuse.c
@@ -26,7 +26,7 @@ int fuse_read(u32 bank, u32 word, u32 *val)
 	switch (bank) {
 	case STM32MP_OTP_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret)
 			return ret;
@@ -41,7 +41,7 @@ int fuse_read(u32 bank, u32 word, u32 *val)
 #ifdef CONFIG_PMIC_STPMIC1
 	case STM32MP_NVM_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stpmic1_nvm),
+						  DM_DRIVER_GET(stpmic1_nvm),
 						  &dev);
 		if (ret)
 			return ret;
@@ -71,7 +71,7 @@ int fuse_prog(u32 bank, u32 word, u32 val)
 	switch (bank) {
 	case STM32MP_OTP_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret)
 			return ret;
@@ -86,7 +86,7 @@ int fuse_prog(u32 bank, u32 word, u32 val)
 #ifdef CONFIG_PMIC_STPMIC1
 	case STM32MP_NVM_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stpmic1_nvm),
+						  DM_DRIVER_GET(stpmic1_nvm),
 						  &dev);
 		if (ret)
 			return ret;
@@ -115,7 +115,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val)
 	switch (bank) {
 	case STM32MP_OTP_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret)
 			return ret;
@@ -129,7 +129,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val)
 #ifdef CONFIG_PMIC_STPMIC1
 	case STM32MP_NVM_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stpmic1_nvm),
+						  DM_DRIVER_GET(stpmic1_nvm),
 						  &dev);
 		if (ret)
 			return ret;
@@ -159,7 +159,7 @@ int fuse_override(u32 bank, u32 word, u32 val)
 	switch (bank) {
 	case STM32MP_OTP_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stm32mp_bsec),
+						  DM_DRIVER_GET(stm32mp_bsec),
 						  &dev);
 		if (ret)
 			return ret;
@@ -174,7 +174,7 @@ int fuse_override(u32 bank, u32 word, u32 val)
 #ifdef CONFIG_PMIC_STPMIC1
 	case STM32MP_NVM_BANK:
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(stpmic1_nvm),
+						  DM_DRIVER_GET(stpmic1_nvm),
 						  &dev);
 		if (ret)
 			return ret;
diff --git a/drivers/mtd/nand/raw/arasan_nfc.c b/drivers/mtd/nand/raw/arasan_nfc.c
index d4e8f8df87d..4621bfb03e3 100644
--- a/drivers/mtd/nand/raw/arasan_nfc.c
+++ b/drivers/mtd/nand/raw/arasan_nfc.c
@@ -1319,7 +1319,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(arasan_nand), &dev);
+					  DM_DRIVER_GET(arasan_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret);
 }
diff --git a/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c
index 71682cb6e79..aa095c439ba 100644
--- a/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c
+++ b/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c
@@ -118,7 +118,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(bcm63158_nand), &dev);
+					  DM_DRIVER_GET(bcm63158_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c
index f424194ecca..e4bf1936810 100644
--- a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c
+++ b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c
@@ -111,7 +111,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(bcm6368_nand), &dev);
+					  DM_DRIVER_GET(bcm6368_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c
index 47ddde4f9b0..586ea3d8fbb 100644
--- a/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c
+++ b/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c
@@ -117,7 +117,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(bcm68360_nand), &dev);
+					  DM_DRIVER_GET(bcm68360_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c
index 646495096c2..85f318bd779 100644
--- a/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c
+++ b/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c
@@ -117,7 +117,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(bcm6838_nand), &dev);
+					  DM_DRIVER_GET(bcm6838_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c
index 7573cd944ff..a5e159ad521 100644
--- a/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c
+++ b/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c
@@ -118,7 +118,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(bcm6858_nand), &dev);
+					  DM_DRIVER_GET(bcm6858_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/davinci_nand.c b/drivers/mtd/nand/raw/davinci_nand.c
index 4645cc16997..9ad3a57690e 100644
--- a/drivers/mtd/nand/raw/davinci_nand.c
+++ b/drivers/mtd/nand/raw/davinci_nand.c
@@ -825,7 +825,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(davinci_nand), &dev);
+					  DM_DRIVER_GET(davinci_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s: %d\n", dev->name, ret);
 }
diff --git a/drivers/mtd/nand/raw/denali_dt.c b/drivers/mtd/nand/raw/denali_dt.c
index 140ef7f725e..cf4df0168a3 100644
--- a/drivers/mtd/nand/raw/denali_dt.c
+++ b/drivers/mtd/nand/raw/denali_dt.c
@@ -181,7 +181,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(denali_nand_dt),
+					  DM_DRIVER_GET(denali_nand_dt),
 					  &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize Denali NAND controller. (error %d)\n",
diff --git a/drivers/mtd/nand/raw/mxs_nand_dt.c b/drivers/mtd/nand/raw/mxs_nand_dt.c
index 78a423dbbf4..878796d5552 100644
--- a/drivers/mtd/nand/raw/mxs_nand_dt.c
+++ b/drivers/mtd/nand/raw/mxs_nand_dt.c
@@ -177,7 +177,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(mxs_nand_dt),
+					  DM_DRIVER_GET(mxs_nand_dt),
 					  &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c
index 64433cf6ccc..9997135ef93 100644
--- a/drivers/mtd/nand/raw/octeontx_nand.c
+++ b/drivers/mtd/nand/raw/octeontx_nand.c
@@ -2233,14 +2233,14 @@ void board_nand_init(void)
 
 	if (IS_ENABLED(CONFIG_NAND_OCTEONTX_HW_ECC)) {
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(octeontx_pci_bchpf),
+						  DM_DRIVER_GET(octeontx_pci_bchpf),
 						  &dev);
 		if (ret && ret != -ENODEV) {
 			pr_err("Failed to initialize OcteonTX BCH PF controller. (error %d)\n",
 			       ret);
 		}
 		ret = uclass_get_device_by_driver(UCLASS_MISC,
-						  DM_GET_DRIVER(octeontx_pci_bchvf),
+						  DM_DRIVER_GET(octeontx_pci_bchvf),
 						  &dev);
 		if (ret && ret != -ENODEV) {
 			pr_err("Failed to initialize OcteonTX BCH VF controller. (error %d)\n",
@@ -2249,7 +2249,7 @@ void board_nand_init(void)
 	}
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(octeontx_pci_nand),
+					  DM_DRIVER_GET(octeontx_pci_nand),
 					  &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize OcteonTX NAND controller. (error %d)\n",
diff --git a/drivers/mtd/nand/raw/pxa3xx_nand.c b/drivers/mtd/nand/raw/pxa3xx_nand.c
index e923ce363a0..f6233756d85 100644
--- a/drivers/mtd/nand/raw/pxa3xx_nand.c
+++ b/drivers/mtd/nand/raw/pxa3xx_nand.c
@@ -1947,7 +1947,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-			DM_GET_DRIVER(pxa3xx_nand), &dev);
+			DM_DRIVER_GET(pxa3xx_nand), &dev);
 	if (ret && ret != -ENODEV) {
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 			   ret);
diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
index 8fe7ec1343e..b8561b2516c 100644
--- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c
+++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
@@ -1042,7 +1042,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(stm32_fmc2_nfc),
+					  DM_DRIVER_GET(stm32_fmc2_nfc),
 					  &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize STM32 FMC2 NFC controller. (error %d)\n",
diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
index 797fc230504..a530127cb77 100644
--- a/drivers/mtd/nand/raw/tegra_nand.c
+++ b/drivers/mtd/nand/raw/tegra_nand.c
@@ -999,7 +999,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(tegra_nand), &dev);
+					  DM_DRIVER_GET(tegra_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name,
 		       ret);
diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index 422b9c57a88..e33953ec7c6 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -794,7 +794,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(vf610_nfc_dt),
+					  DM_DRIVER_GET(vf610_nfc_dt),
 					  &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize NAND controller. (error %d)\n",
diff --git a/drivers/mtd/nand/raw/zynq_nand.c b/drivers/mtd/nand/raw/zynq_nand.c
index 7cf0ccb656c..15d4a238e6f 100644
--- a/drivers/mtd/nand/raw/zynq_nand.c
+++ b/drivers/mtd/nand/raw/zynq_nand.c
@@ -1295,7 +1295,7 @@ void board_nand_init(void)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_MTD,
-					  DM_GET_DRIVER(zynq_nand), &dev);
+					  DM_DRIVER_GET(zynq_nand), &dev);
 	if (ret && ret != -ENODEV)
 		pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret);
 }
diff --git a/drivers/reset/reset-ast2500.c b/drivers/reset/reset-ast2500.c
index a229d490f36..c3d650fc6b0 100644
--- a/drivers/reset/reset-ast2500.c
+++ b/drivers/reset/reset-ast2500.c
@@ -72,7 +72,7 @@ static int ast2500_reset_probe(struct udevice *dev)
 
 	/* get SCU base from clock device */
 	rc = uclass_get_device_by_driver(UCLASS_CLK,
-					 DM_GET_DRIVER(aspeed_ast2500_scu), &scu_dev);
+					 DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev);
 	if (rc) {
 		debug("%s: clock device not found, rc=%d\n", __func__, rc);
 		return rc;
diff --git a/drivers/video/lg4573.c b/drivers/video/lg4573.c
index abf40bddfbe..dd87fc461b9 100644
--- a/drivers/video/lg4573.c
+++ b/drivers/video/lg4573.c
@@ -219,7 +219,7 @@ static int do_lgset(struct cmd_tbl *cmdtp, int flag, int argc,
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
-					  DM_GET_DRIVER(lg4573_lcd), &dev);
+					  DM_DRIVER_GET(lg4573_lcd), &dev);
 	if (ret) {
 		printf("%s: Could not get lg4573 device\n", __func__);
 		return ret;
diff --git a/include/dm/device.h b/include/dm/device.h
index e16ba2405f9..68990301051 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -335,7 +335,7 @@ struct driver {
 	ll_entry_declare(struct driver, __name, driver)
 
 /* Get a pointer to a given driver */
-#define DM_GET_DRIVER(__name)						\
+#define DM_DRIVER_GET(__name)						\
 	ll_entry_get(struct driver, __name, driver)
 
 /**
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index f06339e4d69..b5f066dbf48 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -264,7 +264,7 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
  * uclass_get_device_by_driver() - Get a uclass device for a driver
  *
  * This searches the devices in the uclass for one that uses the given
- * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is
+ * driver. Use DM_DRIVER_GET(name) for the @drv argument, where 'name' is
  * the driver name - as used in U_BOOT_DRIVER(name).
  *
  * The device is probed to activate it ready for use.
diff --git a/test/dm/core.c b/test/dm/core.c
index 82b7a668ddc..1f5ca570dc7 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -1052,7 +1052,7 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
 	 */
 	ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
 							UCLASS_TEST, &dev1));
-	ut_assertok(device_bind(parent, DM_GET_DRIVER(test_drv),
+	ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv),
 				"test_child", 0, ofnode_null(), &dev1));
 
 	ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 711bf20a9c5..b53539055b6 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -328,7 +328,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 
 	/* Check creating a device with an alias */
 	node = ofnode_path("/some-bus/c-test at 1");
-	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
 				"c-test at 1", NULL, node, &dev));
 	ut_asserteq(12, dev_seq(dev));
 	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
@@ -348,11 +348,11 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 	 *
 	 * So next available is 19
 	 */
-	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
 				"fred", NULL, ofnode_null(), &dev));
 	ut_asserteq(19, dev_seq(dev));
 
-	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
 				"fred2", NULL, ofnode_null(), &dev));
 	ut_asserteq(20, dev_seq(dev));
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (9 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
                   ` (57 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

We use the U_BOOT_ prefix (i.e. U_BOOT_DRIVER) to declare a driver but
in every other case we just use DM_. Update the alias macros to use the
DM_ prefix.

We could perhaps rename U_BOOT_DRIVER() to DM_DRIVER(), but this macro
is widely used and there is at least some benefit to indicating it us a
U-Boot driver, particularly for code ported from Linux. So for now, let's
keep that name.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst          | 6 +++---
 drivers/gpio/mxc_gpio.c               | 2 +-
 drivers/gpio/mxs_gpio.c               | 2 +-
 drivers/gpio/sandbox.c                | 2 +-
 drivers/i2c/rk_i2c.c                  | 2 +-
 drivers/mmc/fsl_esdhc_imx.c           | 2 +-
 drivers/mmc/mxsmmc.c                  | 2 +-
 drivers/mmc/rockchip_dw_mmc.c         | 4 ++--
 drivers/mtd/spi/sf_probe.c            | 2 +-
 drivers/pinctrl/nxp/pinctrl-imx6.c    | 2 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c     | 2 +-
 drivers/pinctrl/pinctrl-at91.c        | 2 +-
 drivers/power/pmic/rk8xx.c            | 2 +-
 drivers/serial/ns16550.c              | 6 +++---
 drivers/spi/mxs_spi.c                 | 2 +-
 drivers/spi/rk_spi.c                  | 2 +-
 include/dm/device.h                   | 2 +-
 tools/dtoc/dtb_platdata.py            | 6 +++---
 tools/dtoc/dtoc_test_scan_drivers.cxx | 2 +-
 19 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
index 21b45f6a7e7..78afbdbcc95 100644
--- a/doc/driver-model/of-plat.rst
+++ b/doc/driver-model/of-plat.rst
@@ -184,7 +184,7 @@ via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a
 it to a valid name for C) is needed, so a dedicated driver is required for
 each 'compatible' string.
 
-In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be
+In order to make this a bit more flexible DM_DRIVER_ALIAS macro can be
 used to declare an alias for a driver name, typically a 'compatible' string.
 This macro produces no code, but it is by dtoc tool.
 
@@ -195,7 +195,7 @@ fix-ups required by dtoc. It is not currently used. The values in 'clocks' are
 the index of the driver_info for the target device followed by any phandle
 arguments. This is used to support device_get_by_driver_info_idx().
 
-During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS
+During the build process dtoc parses both U_BOOT_DRIVER and DM_DRIVER_ALIAS
 to build a list of valid driver names and driver aliases. If the 'compatible'
 string used for a device does not not match a valid driver name, it will be
 checked against the list of driver aliases in order to get the right driver
@@ -297,7 +297,7 @@ For example:
             .plat_auto = sizeof(struct mmc_plat),
     };
 
-    U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */
+    DM_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */
 
 Note that struct mmc_plat is defined in the C file, not in a header. This
 is to avoid needing to include dt-structs.h in a header file. The idea is to
diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 6280fb59840..06e6b2279f6 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -345,7 +345,7 @@ U_BOOT_DRIVER(gpio_mxc) = {
 	.bind	= mxc_gpio_bind,
 };
 
-U_BOOT_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio)
+DM_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio)
 
 #if !CONFIG_IS_ENABLED(OF_CONTROL)
 static const struct mxc_gpio_plat mxc_plat[] = {
diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c
index fd5e0ea5c25..4b2b18fdb53 100644
--- a/drivers/gpio/mxs_gpio.c
+++ b/drivers/gpio/mxs_gpio.c
@@ -306,5 +306,5 @@ U_BOOT_DRIVER(fsl_imx23_gpio) = {
 #endif
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio)
+DM_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio)
 #endif /* DM_GPIO */
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index f8fa4baa2c3..dc8d506e8d4 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -327,7 +327,7 @@ U_BOOT_DRIVER(sandbox_gpio) = {
 	ACPI_OPS_PTR(&gpio_sandbox_acpi_ops)
 };
 
-U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
+DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
 
 /* pincontrol: used only to check GPIO pin configuration (pinmux command) */
 
diff --git a/drivers/i2c/rk_i2c.c b/drivers/i2c/rk_i2c.c
index 704bafe2389..f8fac45b6ca 100644
--- a/drivers/i2c/rk_i2c.c
+++ b/drivers/i2c/rk_i2c.c
@@ -495,4 +495,4 @@ U_BOOT_DRIVER(rockchip_rk3066_i2c) = {
 	.ops	= &rockchip_i2c_ops,
 };
 
-U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c)
+DM_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c)
diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 34c2dceb188..c528d345cdf 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -1711,5 +1711,5 @@ U_BOOT_DRIVER(fsl_esdhc) = {
 	.priv_auto	= sizeof(struct fsl_esdhc_priv),
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
+DM_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
 #endif
diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c
index b3fb559a677..8fd41764152 100644
--- a/drivers/mmc/mxsmmc.c
+++ b/drivers/mmc/mxsmmc.c
@@ -722,5 +722,5 @@ U_BOOT_DRIVER(fsl_imx23_mmc) = {
 	.plat_auto	= sizeof(struct mxsmmc_plat),
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc)
+DM_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc)
 #endif /* CONFIG_DM_MMC */
diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c
index 75db81ba4ca..1be3c1741fd 100644
--- a/drivers/mmc/rockchip_dw_mmc.c
+++ b/drivers/mmc/rockchip_dw_mmc.c
@@ -180,8 +180,8 @@ U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = {
 	.plat_auto	= sizeof(struct rockchip_mmc_plat),
 };
 
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
+DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
+DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
 
 #ifdef CONFIG_PWRSEQ
 static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 630787df1bf..6c874348676 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -170,6 +170,6 @@ U_BOOT_DRIVER(jedec_spi_nor) = {
 	.ops		= &spi_flash_std_ops,
 };
 
-U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16)
+DM_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16)
 
 #endif /* CONFIG_DM_SPI_FLASH */
diff --git a/drivers/pinctrl/nxp/pinctrl-imx6.c b/drivers/pinctrl/nxp/pinctrl-imx6.c
index 3cb0bf3b5af..6994dbb61a3 100644
--- a/drivers/pinctrl/nxp/pinctrl-imx6.c
+++ b/drivers/pinctrl/nxp/pinctrl-imx6.c
@@ -52,4 +52,4 @@ U_BOOT_DRIVER(fsl_imx6q_iomuxc) = {
 	.flags = DM_FLAG_PRE_RELOC,
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc)
+DM_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc)
diff --git a/drivers/pinctrl/nxp/pinctrl-mxs.c b/drivers/pinctrl/nxp/pinctrl-mxs.c
index 5ada2ac4052..449a0aa8b5f 100644
--- a/drivers/pinctrl/nxp/pinctrl-mxs.c
+++ b/drivers/pinctrl/nxp/pinctrl-mxs.c
@@ -192,4 +192,4 @@ U_BOOT_DRIVER(fsl_imx23_pinctrl) = {
 	.ops = &mxs_pinctrl_ops,
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl)
+DM_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl)
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 74bfd3c3dca..ddaad55ddc5 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -528,4 +528,4 @@ U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = {
 	.ops = &at91_pinctrl_ops,
 };
 
-U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl)
+DM_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl)
diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c
index 2f547a314d9..5f442fea689 100644
--- a/drivers/power/pmic/rk8xx.c
+++ b/drivers/power/pmic/rk8xx.c
@@ -195,4 +195,4 @@ U_BOOT_DRIVER(rockchip_rk805) = {
 	.ops = &rk8xx_ops,
 };
 
-U_BOOT_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808)
+DM_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index 508c134b94f..65c6db073ec 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -621,9 +621,9 @@ U_BOOT_DRIVER(ns16550_serial) = {
 #endif
 };
 
-U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart)
-U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart)
-U_BOOT_DRIVER_ALIAS(ns16550_serial, ti_da830_uart)
+DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart)
+DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart)
+DM_DRIVER_ALIAS(ns16550_serial, ti_da830_uart)
 #endif
 #endif /* SERIAL_PRESENT */
 
diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index 7f632d98bb6..d41352a0bb8 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -493,4 +493,4 @@ U_BOOT_DRIVER(fsl_imx23_spi) = {
 	.probe	= mxs_spi_probe,
 };
 
-U_BOOT_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi)
+DM_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi)
diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c
index 51abebb9478..40bd8851b7c 100644
--- a/drivers/spi/rk_spi.c
+++ b/drivers/spi/rk_spi.c
@@ -565,4 +565,4 @@ U_BOOT_DRIVER(rockchip_rk3288_spi) = {
 	.probe	= rockchip_spi_probe,
 };
 
-U_BOOT_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi)
+DM_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi)
diff --git a/include/dm/device.h b/include/dm/device.h
index 68990301051..f5b4cd6876e 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -343,7 +343,7 @@ struct driver {
  * produce no code but its information will be parsed by tools like
  * dtoc
  */
-#define U_BOOT_DRIVER_ALIAS(__name, __alias)
+#define DM_DRIVER_ALIAS(__name, __alias)
 
 /**
  * dev_get_plat() - Get the platform data for a device
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 1a6a511b015..e12aaa5399f 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -187,7 +187,7 @@ class DtbPlatdata():
             value: Driver for that driver
         _driver_aliases: Dict that holds aliases for driver names
             key: Driver alias declared with
-                U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
+                DM_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
         _drivers_additional: List of additional drivers to use during scanning
         _dirname: Directory to hold output files, or None for none (all files
@@ -416,9 +416,9 @@ class DtbPlatdata():
                 self._drivers[driver] = Driver(driver)
 
             # The following re will search for driver aliases declared as
-            # U_BOOT_DRIVER_ALIAS(alias, driver_name)
+            # DM_DRIVER_ALIAS(alias, driver_name)
             driver_aliases = re.findall(
-                r'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
+                r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
                 buff)
 
             for alias in driver_aliases: # pragma: no cover
diff --git a/tools/dtoc/dtoc_test_scan_drivers.cxx b/tools/dtoc/dtoc_test_scan_drivers.cxx
index 557c692ba2c..f448767670e 100644
--- a/tools/dtoc/dtoc_test_scan_drivers.cxx
+++ b/tools/dtoc/dtoc_test_scan_drivers.cxx
@@ -1 +1 @@
-U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2)
+DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 12/49] concurrencytest: Fix Python3 warning
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (10 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:34 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
                   ` (56 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

This gives a warning in some situations:

  File "tools/dtoc/../concurrencytest/concurrencytest.py", line 95,
       in do_fork
    stream = os.fdopen(c2pread, 'rb', 1)
  File "/usr/lib/python3.8/os.py", line 1023, in fdopen
    return io.open(fd, *args, **kwargs)
RuntimeWarning: line buffering (buffering=1) isn't supported in binary
    mode, the default buffer size will be used

Fix this by dropping the line-buffer parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/concurrencytest/concurrencytest.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/concurrencytest/concurrencytest.py b/tools/concurrencytest/concurrencytest.py
index 418d7eed21d..5e88b94f415 100644
--- a/tools/concurrencytest/concurrencytest.py
+++ b/tools/concurrencytest/concurrencytest.py
@@ -68,7 +68,7 @@ def fork_for_tests(concurrency_num=CPU_COUNT):
             pid = os.fork()
             if pid == 0:
                 try:
-                    stream = os.fdopen(c2pwrite, 'wb', 1)
+                    stream = os.fdopen(c2pwrite, 'wb')
                     os.close(c2pread)
                     # Leave stderr and stdout open so we can see test noise
                     # Close stdin so that the child goes away if it decides to
@@ -92,7 +92,7 @@ def fork_for_tests(concurrency_num=CPU_COUNT):
                 os._exit(0)
             else:
                 os.close(c2pwrite)
-                stream = os.fdopen(c2pread, 'rb', 1)
+                stream = os.fdopen(c2pread, 'rb')
                 test = ProtocolTestCase(stream)
                 result.append(test)
         return result
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 13/49] dtoc: Run tests using test_util
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (11 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
@ 2020-12-29  3:34 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
                   ` (55 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:34 UTC (permalink / raw)
  To: u-boot

Use the standard function for running tests and reported results. This
allows the tests to run in parallel, which is a significant speed-up on
most machines (e.g. 4.5 seconds -> 1.5s on mine).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/main.py | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index f82ee782682..9d0b3915c0e 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -38,10 +38,11 @@ sys.path.insert(0, os.path.join(our_path,
 from dtoc import dtb_platdata
 from patman import test_util
 
-def run_tests(args):
+def run_tests(processes, args):
     """Run all the test we have for dtoc
 
     Args:
+        processes: Number of processes to use to run tests (None=same as #CPUs)
         args: List of positional args provided to dtoc. This can hold a test
             name to execute (as in 'dtoc -t test_empty_file', for example)
     """
@@ -50,25 +51,13 @@ def run_tests(args):
     result = unittest.TestResult()
     sys.argv = [sys.argv[0]]
     test_name = args and args[0] or None
-    for module in (test_dtoc.TestDtoc,):
-        if test_name:
-            try:
-                suite = unittest.TestLoader().loadTestsFromName(test_name, module)
-            except AttributeError:
-                continue
-        else:
-            suite = unittest.TestLoader().loadTestsFromTestCase(module)
-        suite.run(result)
-
-    print(result)
-    for _, err in result.errors:
-        print(err)
-    for _, err in result.failures:
-        print(err)
-    if result.errors or result.failures:
-        print('dtoc tests FAILED')
-        return 1
-    return 0
+
+    test_util.RunTestSuites(
+        result, debug=True, verbosity=1, test_preserve_dirs=False,
+        processes=processes, test_name=test_name, toolpath=[],
+        test_class_list=[test_dtoc.TestDtoc,])
+
+    return test_util.ReportResult('binman', test_name, result)
 
 def RunTestCoverage():
     """Run the tests and check that we get 100% coverage"""
@@ -103,7 +92,7 @@ parser.add_option('-T', '--test-coverage', action='store_true',
 
 # Run our meagre tests
 if options.test:
-    ret_code = run_tests(args)
+    ret_code = run_tests(options.processes, args)
     sys.exit(ret_code)
 
 elif options.test_coverage:
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 14/49] dtoc: Add a header comment to each generated file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (12 preceding siblings ...)
  2020-12-29  3:34 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
                   ` (54 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

It is currently fairly obvious what the two generated files are for, but
this will change as more are added. It is helpful for readers to describe
the purpose of each file.

Add a header commment field to OutputFile and use it to generate a comment
at the top of each file.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 30 ++++++++++++++++++++----------
 tools/dtoc/test_dtoc.py    |  6 ++++--
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index e12aaa5399f..b3d777e0c5e 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -56,8 +56,10 @@ class Ftype(IntEnum):
 
 # This holds information about each type of output file dtoc can create
 # type: Type of file (Ftype)
-# fname: Filename excluding directory, e.g. 'dt-platdata.c'
-OutputFile = collections.namedtuple('OutputFile', ['ftype', 'fname'])
+# fname: Filename excluding directory, e.g. 'dt-plat.c'
+# hdr_comment: Comment explaining the purpose of the file
+OutputFile = collections.namedtuple('OutputFile',
+                                    ['ftype', 'fname', 'hdr_comment'])
 
 # This holds information about a property which includes phandles.
 #
@@ -331,15 +333,20 @@ class DtbPlatdata():
         self._lines = []
         return lines
 
-    def out_header(self):
-        """Output a message indicating that this is an auto-generated file"""
+    def out_header(self, outfile):
+        """Output a message indicating that this is an auto-generated file
+
+        Args:
+            outfile: OutputFile describing the file being generated
+        """
         self.out('''/*
  * DO NOT MODIFY
  *
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * %s.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
  */
 
-''')
+''' % outfile.hdr_comment)
 
     def get_phandle_argc(self, prop, node_name):
         """Check if a node contains phandles
@@ -646,7 +653,6 @@ class DtbPlatdata():
                     value: Prop object with field information
 
         """
-        self.out_header()
         self.out('#include <stdbool.h>\n')
         self.out('#include <linux/libfdt.h>\n')
 
@@ -789,7 +795,6 @@ class DtbPlatdata():
         See the documentation in doc/driver-model/of-plat.rst for more
         information.
         """
-        self.out_header()
         self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
         self.out('#define DT_PLATDATA_C\n')
         self.out('\n')
@@ -823,8 +828,12 @@ class DtbPlatdata():
 # key: Command used to generate this file
 # value: OutputFile for this command
 OUTPUT_FILES = {
-    'struct': OutputFile(Ftype.HEADER, 'dt-structs-gen.h'),
-    'platdata': OutputFile(Ftype.SOURCE, 'dt-platdata.c'),
+    'struct':
+        OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
+                   'Defines the structs used to hold devicetree data'),
+    'platdata':
+        OutputFile(Ftype.SOURCE, 'dt-platdata.c',
+                   'Declares the U_BOOT_DRIVER() records and platform data'),
     }
 
 
@@ -872,6 +881,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
                              (cmd, ', '.join(sorted(OUTPUT_FILES.keys()))))
         plat.setup_output(outfile.ftype,
                           outfile.fname if output_dirs else output)
+        plat.out_header(outfile)
         if cmd == 'struct':
             plat.generate_structs(structs)
         elif cmd == 'platdata':
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index dbd4e3bf1d4..2e4dd2b24d2 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -32,7 +32,8 @@ OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 HEADER = '''/*
  * DO NOT MODIFY
  *
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * Defines the structs used to hold devicetree data.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
  */
 
 #include <stdbool.h>
@@ -41,7 +42,8 @@ HEADER = '''/*
 C_HEADER = '''/*
  * DO NOT MODIFY
  *
- * This file was generated by dtoc from a .dtb (device tree binary) file.
+ * Declares the U_BOOT_DRIVER() records and platform data.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
  */
 
 /* Allow use of U_BOOT_DRVINFO() in this file */
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (13 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
                   ` (53 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Use this new name to be consistent with the rest of U-Boot, which talks
about 'plat' for the platform data, which is what this file holds.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/platdata.h       | 2 +-
 include/linux/mtd/spi-nor.h | 2 +-
 scripts/Makefile.spl        | 2 +-
 tools/dtoc/dtb_platdata.py  | 4 ++--
 tools/dtoc/test_dtoc.py     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/dm/platdata.h b/include/dm/platdata.h
index df1f6abcc7e..dc3cbfcbc7f 100644
--- a/include/dm/platdata.h
+++ b/include/dm/platdata.h
@@ -59,7 +59,7 @@ struct driver_rt {
  * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the
  * dt-plat.c file created by dtoc
  */
-#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
+#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLAT_C)
 #define U_BOOT_DRVINFO(__name)	_Static_assert(false, \
 	"Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead")
 #else
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 363f2749d7d..4a8e19ee4f9 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -262,7 +262,7 @@ struct spi_flash {
  *	Defined below (keep this text to enable searching for spi_flash decl)
  * }
  */
-#ifndef DT_PLATDATA_C
+#ifndef DT_PLAT_C
 #define spi_flash spi_nor
 #endif
 
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 3d60cf5120e..87021e22e55 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -120,7 +120,7 @@ endif
 u-boot-spl-init := $(head-y)
 u-boot-spl-main := $(libs-y)
 ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA
-u-boot-spl-platdata := $(obj)/dts/dt-platdata.o
+u-boot-spl-platdata := $(obj)/dts/dt-plat.o
 u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata))
 endif
 
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index b3d777e0c5e..e07a5d3a1c8 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -796,7 +796,7 @@ class DtbPlatdata():
         information.
         """
         self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
-        self.out('#define DT_PLATDATA_C\n')
+        self.out('#define DT_PLAT_C\n')
         self.out('\n')
         self.out('#include <common.h>\n')
         self.out('#include <dm.h>\n')
@@ -832,7 +832,7 @@ OUTPUT_FILES = {
         OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
                    'Defines the structs used to hold devicetree data'),
     'platdata':
-        OutputFile(Ftype.SOURCE, 'dt-platdata.c',
+        OutputFile(Ftype.SOURCE, 'dt-plat.c',
                    'Declares the U_BOOT_DRIVER() records and platform data'),
     }
 
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 2e4dd2b24d2..d56cd311fa1 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -47,7 +47,7 @@ C_HEADER = '''/*
  */
 
 /* Allow use of U_BOOT_DRVINFO() in this file */
-#define DT_PLATDATA_C
+#define DT_PLAT_C
 
 #include <common.h>
 #include <dm.h>
@@ -979,5 +979,5 @@ U_BOOT_DRVINFO(spl_test2) = {
 
         leafs = set(os.path.basename(fname) for fname in fnames)
         self.assertEqual(
-            {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'},
+            {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
             leafs)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 16/49] dtoc: Add the method for each command to OutputFile
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (14 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
                   ` (52 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Rather than the if/else construct, update OutputFile with the method to
call to process each command. This is easier to maintain as the number of
commands increases.

Rename generate_tables to generate_plat since it better describes what is
being generated ('plat' is the U-Boot name for platform data).

With this, each output method needs to have the same signature. Store the
output structures in a member variable instead of using parameters, to
accomplish this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 42 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index e07a5d3a1c8..4696ff63095 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -59,7 +59,7 @@ class Ftype(IntEnum):
 # fname: Filename excluding directory, e.g. 'dt-plat.c'
 # hdr_comment: Comment explaining the purpose of the file
 OutputFile = collections.namedtuple('OutputFile',
-                                    ['ftype', 'fname', 'hdr_comment'])
+                                    ['ftype', 'fname', 'method', 'hdr_comment'])
 
 # This holds information about a property which includes phandles.
 #
@@ -194,6 +194,11 @@ class DtbPlatdata():
         _drivers_additional: List of additional drivers to use during scanning
         _dirname: Directory to hold output files, or None for none (all files
             go to stdout)
+        _struct_data (dict): OrderedDict of dtplat structures to output
+            key (str): Node name, as a C identifier
+                    value: dict containing structure fields:
+                        key (str): Field name
+                        value: Prop object with field information
     """
     def __init__(self, dtb_fname, include_disabled, warning_disabled,
                  drivers_additional=None):
@@ -208,6 +213,7 @@ class DtbPlatdata():
         self._driver_aliases = {}
         self._drivers_additional = drivers_additional or []
         self._dirnames = [None] * len(Ftype)
+        self._struct_data = collections.OrderedDict()
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -570,14 +576,9 @@ class DtbPlatdata():
         Once the widest property is determined, all other properties are
         updated to match that width.
 
-        Returns:
-            dict of dict: dict containing structures:
-                key (str): Node name, as a C identifier
-                value: dict containing structure fields:
-                    key (str): Field name
-                    value: Prop object with field information
+        The results are written to self._struct_data
         """
-        structs = collections.OrderedDict()
+        structs = self._struct_data
         for node in self._valid_nodes:
             node_name, _ = self.get_normalized_compat_name(node)
             fields = {}
@@ -608,8 +609,6 @@ class DtbPlatdata():
                 if name not in PROP_IGNORE_LIST and name[0] != '#':
                     prop.Widen(struct[name])
 
-        return structs
-
     def scan_phandles(self):
         """Figure out what phandles each node uses
 
@@ -638,21 +637,14 @@ class DtbPlatdata():
                         pos += 1 + args
 
 
-    def generate_structs(self, structs):
+    def generate_structs(self):
         """Generate struct defintions for the platform data
 
         This writes out the body of a header file consisting of structure
         definitions for node in self._valid_nodes. See the documentation in
         doc/driver-model/of-plat.rst for more information.
-
-        Args:
-            structs (dict): dict containing structures:
-                key (str): Node name, as a C identifier
-                value: dict containing structure fields:
-                    key (str): Field name
-                    value: Prop object with field information
-
         """
+        structs = self._struct_data
         self.out('#include <stdbool.h>\n')
         self.out('#include <linux/libfdt.h>\n')
 
@@ -785,7 +777,7 @@ class DtbPlatdata():
 
         self.out(''.join(self.get_buf()))
 
-    def generate_tables(self):
+    def generate_plat(self):
         """Generate device defintions for the platform data
 
         This writes out C platform data initialisation data and
@@ -830,9 +822,10 @@ class DtbPlatdata():
 OUTPUT_FILES = {
     'struct':
         OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
+                   DtbPlatdata.generate_structs,
                    'Defines the structs used to hold devicetree data'),
     'platdata':
-        OutputFile(Ftype.SOURCE, 'dt-plat.c',
+        OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat,
                    'Declares the U_BOOT_DRIVER() records and platform data'),
     }
 
@@ -868,7 +861,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     plat.scan_tree()
     plat.scan_reg_sizes()
     plat.setup_output_dirs(output_dirs)
-    structs = plat.scan_structs()
+    plat.scan_structs()
     plat.scan_phandles()
 
     cmds = args[0].split(',')
@@ -882,8 +875,5 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
         plat.setup_output(outfile.ftype,
                           outfile.fname if output_dirs else output)
         plat.out_header(outfile)
-        if cmd == 'struct':
-            plat.generate_structs(structs)
-        elif cmd == 'platdata':
-            plat.generate_tables()
+        outfile.method(plat)
     plat.finish_output()
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 17/49] dtoc: Allow specifying the base directory for tests
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (15 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
                   ` (51 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

The base directory of U-Boot, where the source is, it currently calculated
from the directory of the dtb_platdata.py script. If this is installed
elsewhere that will not work. Also it is inconvenient for tests.

Add a parameter to allow specifying this base directory.

To test this, pass a temporary directory with some files in it and check
that they are passed to scan_driver().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 18 ++++++++++++------
 tools/dtoc/test_dtoc.py    | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 4696ff63095..acb9689ea10 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -199,6 +199,7 @@ class DtbPlatdata():
                     value: dict containing structure fields:
                         key (str): Field name
                         value: Prop object with field information
+        _basedir (str): Base directory of source tree
     """
     def __init__(self, dtb_fname, include_disabled, warning_disabled,
                  drivers_additional=None):
@@ -214,6 +215,7 @@ class DtbPlatdata():
         self._drivers_additional = drivers_additional or []
         self._dirnames = [None] * len(Ftype)
         self._struct_data = collections.OrderedDict()
+        self._basedir = None
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -439,15 +441,17 @@ class DtbPlatdata():
                     continue
                 self._driver_aliases[alias[1]] = alias[0]
 
-    def scan_drivers(self):
+    def scan_drivers(self, basedir=None):
         """Scan the driver folders to build a list of driver names and aliases
 
         This procedure will populate self._drivers and self._driver_aliases
 
         """
-        basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
-        if basedir == '':
-            basedir = './'
+        if not basedir:
+            basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
+            if basedir == '':
+                basedir = './'
+        self._basedir = basedir
         for (dirpath, _, filenames) in os.walk(basedir):
             for fname in filenames:
                 if not fname.endswith('.c'):
@@ -831,7 +835,7 @@ OUTPUT_FILES = {
 
 
 def run_steps(args, dtb_file, include_disabled, output, output_dirs,
-              warning_disabled=False, drivers_additional=None):
+              warning_disabled=False, drivers_additional=None, basedir=None):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -846,6 +850,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
             drivers
         drivers_additional (list): List of additional drivers to use during
             scanning
+        basedir (str): Base directory of U-Boot source code. Defaults to the
+            grandparent of this file's directory
     Raises:
         ValueError: if args has no command, or an unknown command
     """
@@ -856,7 +862,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
 
     plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled,
                        drivers_additional)
-    plat.scan_drivers()
+    plat.scan_drivers(basedir)
     plat.scan_dtb()
     plat.scan_tree()
     plat.scan_reg_sizes()
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index d56cd311fa1..c517fd5c4ef 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -12,9 +12,11 @@ tool.
 import collections
 import glob
 import os
+import shutil
 import struct
 import tempfile
 import unittest
+from unittest import mock
 
 from dtb_platdata import conv_name_to_c
 from dtb_platdata import get_compat_name
@@ -981,3 +983,35 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertEqual(
             {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
             leafs)
+
+    def test_scan_dirs(self):
+        """Test scanning of source directories"""
+        def add_file(fname):
+            pathname = os.path.join(indir, fname)
+            dirname = os.path.dirname(pathname)
+            os.makedirs(dirname, exist_ok=True)
+            tools.WriteFile(pathname, '', binary=False)
+            fname_list.append(pathname)
+
+        try:
+            outdir = tools.GetOutputDir()
+            indir = tempfile.mkdtemp(prefix='dtoc.')
+            dtb_file = get_dtb_file('dtoc_test_simple.dts')
+
+            fname_list = []
+            add_file('fname.c')
+            add_file('dir/fname2.c')
+
+            # Mock out scan_driver and check that it is called with the
+            # expected files
+            with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \
+                    as mocked:
+                dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir],
+                                       True, basedir=indir)
+            self.assertEqual(2, len(mocked.mock_calls))
+            self.assertEqual(mock.call(fname_list[0]),
+                             mocked.mock_calls[0])
+            self.assertEqual(mock.call(fname_list[1]),
+                             mocked.mock_calls[1])
+        finally:
+            shutil.rmtree(indir)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 18/49] dtoc: Output nodes in order
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (16 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
                   ` (50 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Previously we had to worry about nodes being output before those that they
depended on, thus causing build errors.  So the current algorithm is
careful to output nodes in the right order.

We now use a different method for outputting phandles that does not
involve pointers. Also we plan to add a 'declarations' header file to
declare all drivers as 'extern'.

Update the code to drop the dependency checking and output in a simple
loop. This makes the output easier to follow since drivers are in order of
thier indices (0, 1, ...), which is also the order it appears in in the
linker list.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 13 ++------
 tools/dtoc/test_dtoc.py    | 64 +++++++++++++++++++-------------------
 2 files changed, 34 insertions(+), 43 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index acb9689ea10..4cdbd60c9ae 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -798,18 +798,9 @@ class DtbPlatdata():
         self.out('#include <dm.h>\n')
         self.out('#include <dt-structs.h>\n')
         self.out('\n')
-        nodes_to_output = list(self._valid_nodes)
-
-        # Keep outputing nodes until there is none left
-        while nodes_to_output:
-            node = nodes_to_output[0]
-            # Output all the node's dependencies first
-            for req_node in node.phandles:
-                if req_node in nodes_to_output:
-                    self.output_node(req_node)
-                    nodes_to_output.remove(req_node)
+
+        for node in self._valid_nodes:
             self.output_node(node)
-            nodes_to_output.remove(node)
 
         # Define dm_populate_phandle_data() which will add the linking between
         # nodes using DM_DRVINFO_GET
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c517fd5c4ef..f17d2e4b45d 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -422,17 +422,6 @@ U_BOOT_DRVINFO(phandle3_target) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /phandle-target index 4 */
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DRVINFO(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
 /* Node /phandle-source index 2 */
 static struct dtd_source dtv_phandle_source = {
 \t.clocks\t\t\t= {
@@ -460,6 +449,17 @@ U_BOOT_DRVINFO(phandle_source2) = {
 \t.parent_idx\t= -1,
 };
 
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
 void dm_populate_phandle_data(void) {
 }
 ''', data)
@@ -488,16 +488,6 @@ struct dtd_target {
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
-/* Node /phandle-target index 1 */
-static struct dtd_target dtv_phandle_target = {
-};
-U_BOOT_DRVINFO(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
 /* Node /phandle-source2 index 0 */
 static struct dtd_source dtv_phandle_source2 = {
 \t.clocks\t\t\t= {
@@ -510,6 +500,16 @@ U_BOOT_DRVINFO(phandle_source2) = {
 \t.parent_idx\t= -1,
 };
 
+/* Node /phandle-target index 1 */
+static struct dtd_target dtv_phandle_target = {
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
 void dm_populate_phandle_data(void) {
 }
 ''', data)
@@ -544,17 +544,6 @@ U_BOOT_DRVINFO(phandle3_target) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /phandle-target index 4 */
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DRVINFO(phandle_target) = {
-\t.name\t\t= "target",
-\t.plat\t= &dtv_phandle_target,
-\t.plat_size\t= sizeof(dtv_phandle_target),
-\t.parent_idx\t= -1,
-};
-
 /* Node /phandle-source index 2 */
 static struct dtd_source dtv_phandle_source = {
 \t.cd_gpios\t\t= {
@@ -582,6 +571,17 @@ U_BOOT_DRVINFO(phandle_source2) = {
 \t.parent_idx\t= -1,
 };
 
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DRVINFO(phandle_target) = {
+\t.name\t\t= "target",
+\t.plat\t= &dtv_phandle_target,
+\t.plat_size\t= sizeof(dtv_phandle_target),
+\t.parent_idx\t= -1,
+};
+
 void dm_populate_phandle_data(void) {
 }
 ''', data)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 19/49] dtoc: Drop dm_populate_phandle_data()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (17 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 20/49] dtoc: Split source-code scanning to a separate file Simon Glass
                   ` (49 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

This has not been needed since parent information was added and we started
using indicies for references to other drivers instead of pointers. It was
kept around in the expectation that it might be needed later.

However with the latest updates, it doesn't seem likely that we'll need
this in the foreseeable future.

Drop dm_populate_phandle_data() from dtoc and driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst | 16 ++++++----------
 drivers/core/root.c          |  3 ---
 include/dm/platdata.h        |  8 --------
 tools/dtoc/dtb_platdata.py   |  6 ------
 tools/dtoc/test_dtoc.py      | 29 +++++++----------------------
 5 files changed, 13 insertions(+), 49 deletions(-)

diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
index 78afbdbcc95..4ef2fe699a4 100644
--- a/doc/driver-model/of-plat.rst
+++ b/doc/driver-model/of-plat.rst
@@ -162,9 +162,6 @@ and the following device declarations:
             .parent_idx     = -1,
     };
 
-    void dm_populate_phandle_data(void) {
-    }
-
 The device is then instantiated at run-time and the platform data can be
 accessed using:
 
@@ -190,10 +187,7 @@ This macro produces no code, but it is by dtoc tool.
 
 The parent_idx is the index of the parent driver_info structure within its
 linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support
-dev_get_parent(). The dm_populate_phandle_data() is included to allow for
-fix-ups required by dtoc. It is not currently used. The values in 'clocks' are
-the index of the driver_info for the target device followed by any phandle
-arguments. This is used to support device_get_by_driver_info_idx().
+dev_get_parent().
 
 During the build process dtoc parses both U_BOOT_DRIVER and DM_DRIVER_ALIAS
 to build a list of valid driver names and driver aliases. If the 'compatible'
@@ -337,9 +331,11 @@ prevents them being used inadvertently. All usage must be bracketed with
 #if CONFIG_IS_ENABLED(OF_PLATDATA).
 
 The dt-plat.c file contains the device declarations and is is built in
-spl/dt-plat.c. It additionally contains the definition of
-dm_populate_phandle_data() which is responsible of filling the phandle
-information by adding references to U_BOOT_DRVINFO by using DM_DRVINFO_GET
+spl/dt-plat.c.
+
+The dm_populate_phandle_data() function that was previous needed has now been
+removed, since dtoc can address the drivers directly from dt-plat.c and does
+not need to fix up things at runtime.
 
 The pylibfdt Python module is used to access the devicetree.
 
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 3adbc94eb94..78de7cdf875 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -336,9 +336,6 @@ int dm_init_and_scan(bool pre_reloc_only)
 {
 	int ret;
 
-	if (CONFIG_IS_ENABLED(OF_PLATDATA))
-		dm_populate_phandle_data();
-
 	ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE));
 	if (ret) {
 		debug("dm_init() failed: %d\n", ret);
diff --git a/include/dm/platdata.h b/include/dm/platdata.h
index dc3cbfcbc7f..3821a56f2ca 100644
--- a/include/dm/platdata.h
+++ b/include/dm/platdata.h
@@ -86,12 +86,4 @@ struct driver_rt {
 #define DM_DRVINFO_GET(__name)						\
 	ll_entry_get(struct driver_info, __name, driver_info)
 
-/**
- * dm_populate_phandle_data() - Populates phandle data in platda
- *
- * This populates phandle data with an U_BOOT_DRVINFO entry get by
- * DM_DRVINFO_GET. The implementation of this function will be done
- * by dtoc when parsing dtb.
- */
-void dm_populate_phandle_data(void);
 #endif
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 4cdbd60c9ae..f1c09d629ff 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -802,12 +802,6 @@ class DtbPlatdata():
         for node in self._valid_nodes:
             self.output_node(node)
 
-        # Define dm_populate_phandle_data() which will add the linking between
-        # nodes using DM_DRVINFO_GET
-        # dtv_dmc_at_xxx.clocks[0].node = DM_DRVINFO_GET(clock_controller_at_xxx)
-        self.buf('void dm_populate_phandle_data(void) {\n')
-        self.buf('}\n')
-
         self.out(''.join(self.get_buf()))
 
 
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index f17d2e4b45d..bcbf58c45bc 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -56,10 +56,6 @@ C_HEADER = '''/*
 #include <dt-structs.h>
 '''
 
-C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
-}
-'''
-
 # This is a test so is allowed to access private things in the module it is
 # testing
 # pylint: disable=W0212
@@ -190,8 +186,7 @@ class TestDtoc(unittest.TestCase):
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             lines = infile.read().splitlines()
-        self.assertEqual(C_HEADER.splitlines() + [''] +
-                         C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
+        self.assertEqual(C_HEADER.splitlines() + [''], lines)
 
     struct_text = HEADER + '''
 struct dtd_sandbox_i2c_test {
@@ -289,7 +284,7 @@ U_BOOT_DRVINFO(spl_test3) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA
+'''
 
     def test_simple(self):
         """Test output from some simple nodes with various types of data"""
@@ -344,8 +339,6 @@ U_BOOT_DRVINFO(gpios_at_0) = {
 \t.parent_idx\t= -1,
 };
 
-void dm_populate_phandle_data(void) {
-}
 ''', data)
 
     def test_invalid_driver(self):
@@ -376,8 +369,6 @@ U_BOOT_DRVINFO(spl_test) = {
 \t.parent_idx\t= -1,
 };
 
-void dm_populate_phandle_data(void) {
-}
 ''', data)
 
     def test_phandle(self):
@@ -460,8 +451,6 @@ U_BOOT_DRVINFO(phandle_target) = {
 \t.parent_idx\t= -1,
 };
 
-void dm_populate_phandle_data(void) {
-}
 ''', data)
 
     def test_phandle_single(self):
@@ -510,8 +499,6 @@ U_BOOT_DRVINFO(phandle_target) = {
 \t.parent_idx\t= -1,
 };
 
-void dm_populate_phandle_data(void) {
-}
 ''', data)
 
     def test_phandle_cd_gpio(self):
@@ -582,8 +569,6 @@ U_BOOT_DRVINFO(phandle_target) = {
 \t.parent_idx\t= -1,
 };
 
-void dm_populate_phandle_data(void) {
-}
 ''', data)
 
     def test_phandle_bad(self):
@@ -662,7 +647,7 @@ U_BOOT_DRVINFO(test3) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
 
     def test_addresses32(self):
         """Test output from a node with a 'reg' property with na=1, ns=1"""
@@ -706,7 +691,7 @@ U_BOOT_DRVINFO(test2) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
 
     def test_addresses64_32(self):
         """Test output from a node with a 'reg' property with na=2, ns=1"""
@@ -764,7 +749,7 @@ U_BOOT_DRVINFO(test3) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
 
     def test_addresses32_64(self):
         """Test output from a node with a 'reg' property with na=1, ns=2"""
@@ -822,7 +807,7 @@ U_BOOT_DRVINFO(test3) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
 
     def test_bad_reg(self):
         """Test that a reg property with an invalid type generates an error"""
@@ -885,7 +870,7 @@ U_BOOT_DRVINFO(spl_test2) = {
 \t.parent_idx\t= -1,
 };
 
-''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
+''', data)
 
     def test_stdout(self):
         """Test output to stdout"""
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 20/49] dtoc: Split source-code scanning to a separate file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (18 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 21/49] dtoc: Move src_scan tests " Simon Glass
                   ` (48 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Before expanding the scanning features any more, move this into a separate
file. This will make it easier to maintain in the future. In particular,
it reduces the size of dtb_platdata.py and allows us to add tests
specifically for scanning, without going through that file.

The pieces moved are the Driver class, the scanning code and the various
naming functions, since they mostly depend on the scanning results.

So far there is are no separate tests for src_scan. These will be added
as new functionality appears.

This introduces no functional change.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 174 +++-------------------------------
 tools/dtoc/src_scan.py     | 185 +++++++++++++++++++++++++++++++++++++
 tools/dtoc/test_dtoc.py    |  14 +--
 3 files changed, 204 insertions(+), 169 deletions(-)
 create mode 100644 tools/dtoc/src_scan.py

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index f1c09d629ff..ad642f30625 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -22,6 +22,8 @@ import sys
 
 from dtoc import fdt
 from dtoc import fdt_util
+from dtoc import src_scan
+from dtoc.src_scan import conv_name_to_c
 
 # When we see these properties we ignore them - i.e. do not create a structure
 # member
@@ -76,39 +78,6 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
 PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
 
 
-class Driver:
-    """Information about a driver in U-Boot
-
-    Attributes:
-        name: Name of driver. For U_BOOT_DRIVER(x) this is 'x'
-    """
-    def __init__(self, name):
-        self.name = name
-
-    def __eq__(self, other):
-        return self.name == other.name
-
-    def __repr__(self):
-        return "Driver(name='%s')" % self.name
-
-
-def conv_name_to_c(name):
-    """Convert a device-tree name to a C identifier
-
-    This uses multiple replace() calls instead of re.sub() since it is faster
-    (400ms for 1m calls versus 1000ms for the 're' version).
-
-    Args:
-        name (str): Name to convert
-    Return:
-        str: String containing the C version of this name
-    """
-    new = name.replace('@', '_at_')
-    new = new.replace('-', '_')
-    new = new.replace(',', '_')
-    new = new.replace('.', '_')
-    return new
-
 def tab_to(num_tabs, line):
     """Append tabs to a line of text to reach a tab stop.
 
@@ -154,19 +123,6 @@ def get_value(ftype, value):
         val = '%#x' % value
     return val
 
-def get_compat_name(node):
-    """Get the node's list of compatible string as a C identifiers
-
-    Args:
-        node (fdt.Node): Node object to check
-    Return:
-        list of str: List of C identifiers for all the compatible strings
-    """
-    compat = node.props['compatible'].value
-    if not isinstance(compat, list):
-        compat = [compat]
-    return [conv_name_to_c(c) for c in compat]
-
 
 class DtbPlatdata():
     """Provide a means to convert device tree binary data to platform data
@@ -176,22 +132,15 @@ class DtbPlatdata():
     code is not affordable.
 
     Properties:
+        _scan: Scan object, for scanning and reporting on useful information
+            from the U-Boot source code
         _fdt: Fdt object, referencing the device tree
         _dtb_fname: Filename of the input device tree binary file
         _valid_nodes: A list of Node object with compatible strings. The list
             is ordered by conv_name_to_c(node.name)
         _include_disabled: true to include nodes marked status = "disabled"
         _outfile: The current output file (sys.stdout or a real file)
-        _warning_disabled: true to disable warnings about driver names not found
         _lines: Stashed list of output lines for outputting in the future
-        _drivers: Dict of valid driver names found in drivers/
-            key: Driver name
-            value: Driver for that driver
-        _driver_aliases: Dict that holds aliases for driver names
-            key: Driver alias declared with
-                DM_DRIVER_ALIAS(driver_alias, driver_name)
-            value: Driver name declared with U_BOOT_DRIVER(driver_name)
-        _drivers_additional: List of additional drivers to use during scanning
         _dirname: Directory to hold output files, or None for none (all files
             go to stdout)
         _struct_data (dict): OrderedDict of dtplat structures to output
@@ -201,58 +150,18 @@ class DtbPlatdata():
                         value: Prop object with field information
         _basedir (str): Base directory of source tree
     """
-    def __init__(self, dtb_fname, include_disabled, warning_disabled,
-                 drivers_additional=None):
+    def __init__(self, scan, dtb_fname, include_disabled):
+        self._scan = scan
         self._fdt = None
         self._dtb_fname = dtb_fname
         self._valid_nodes = None
         self._include_disabled = include_disabled
         self._outfile = None
-        self._warning_disabled = warning_disabled
         self._lines = []
-        self._drivers = {}
-        self._driver_aliases = {}
-        self._drivers_additional = drivers_additional or []
         self._dirnames = [None] * len(Ftype)
         self._struct_data = collections.OrderedDict()
         self._basedir = None
 
-    def get_normalized_compat_name(self, node):
-        """Get a node's normalized compat name
-
-        Returns a valid driver name by retrieving node's list of compatible
-        string as a C identifier and performing a check against _drivers
-        and a lookup in driver_aliases printing a warning in case of failure.
-
-        Args:
-            node (Node): Node object to check
-        Return:
-            Tuple:
-                Driver name associated with the first compatible string
-                List of C identifiers for all the other compatible strings
-                    (possibly empty)
-                In case of no match found, the return will be the same as
-                get_compat_name()
-        """
-        compat_list_c = get_compat_name(node)
-
-        for compat_c in compat_list_c:
-            if not compat_c in self._drivers.keys():
-                compat_c = self._driver_aliases.get(compat_c)
-                if not compat_c:
-                    continue
-
-            aliases_c = compat_list_c
-            if compat_c in aliases_c:
-                aliases_c.remove(compat_c)
-            return compat_c, aliases_c
-
-        if not self._warning_disabled:
-            print('WARNING: the driver %s was not found in the driver list'
-                  % (compat_list_c[0]))
-
-        return compat_list_c[0], compat_list_c[1:]
-
     def setup_output_dirs(self, output_dirs):
         """Set up the output directories
 
@@ -407,65 +316,6 @@ class DtbPlatdata():
             return PhandleInfo(max_args, args)
         return None
 
-    def scan_driver(self, fname):
-        """Scan a driver file to build a list of driver names and aliases
-
-        This procedure will populate self._drivers and self._driver_aliases
-
-        Args
-            fname: Driver filename to scan
-        """
-        with open(fname, encoding='utf-8') as inf:
-            try:
-                buff = inf.read()
-            except UnicodeDecodeError:
-                # This seems to happen on older Python versions
-                print("Skipping file '%s' due to unicode error" % fname)
-                return
-
-            # The following re will search for driver names declared as
-            # U_BOOT_DRIVER(driver_name)
-            drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
-
-            for driver in drivers:
-                self._drivers[driver] = Driver(driver)
-
-            # The following re will search for driver aliases declared as
-            # DM_DRIVER_ALIAS(alias, driver_name)
-            driver_aliases = re.findall(
-                r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
-                buff)
-
-            for alias in driver_aliases: # pragma: no cover
-                if len(alias) != 2:
-                    continue
-                self._driver_aliases[alias[1]] = alias[0]
-
-    def scan_drivers(self, basedir=None):
-        """Scan the driver folders to build a list of driver names and aliases
-
-        This procedure will populate self._drivers and self._driver_aliases
-
-        """
-        if not basedir:
-            basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
-            if basedir == '':
-                basedir = './'
-        self._basedir = basedir
-        for (dirpath, _, filenames) in os.walk(basedir):
-            for fname in filenames:
-                if not fname.endswith('.c'):
-                    continue
-                self.scan_driver(dirpath + '/' + fname)
-
-        for fname in self._drivers_additional:
-            if not isinstance(fname, str) or len(fname) == 0:
-                continue
-            if fname[0] == '/':
-                self.scan_driver(fname)
-            else:
-                self.scan_driver(basedir + '/' + fname)
-
     def scan_dtb(self):
         """Scan the device tree to obtain a tree of nodes and properties
 
@@ -584,7 +434,7 @@ class DtbPlatdata():
         """
         structs = self._struct_data
         for node in self._valid_nodes:
-            node_name, _ = self.get_normalized_compat_name(node)
+            node_name, _ = self._scan.get_normalized_compat_name(node)
             fields = {}
 
             # Get a list of all the valid properties in this node.
@@ -607,7 +457,7 @@ class DtbPlatdata():
                 structs[node_name] = fields
 
         for node in self._valid_nodes:
-            node_name, _ = self.get_normalized_compat_name(node)
+            node_name, _ = self._scan.get_normalized_compat_name(node)
             struct = structs[node_name]
             for name, prop in node.props.items():
                 if name not in PROP_IGNORE_LIST and name[0] != '#':
@@ -772,7 +622,7 @@ class DtbPlatdata():
         Args:
             node (fdt.Node): node to output
         """
-        struct_name, _ = self.get_normalized_compat_name(node)
+        struct_name, _ = self._scan.get_normalized_compat_name(node)
         var_name = conv_name_to_c(node.name)
         self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
 
@@ -845,9 +695,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     if output and output_dirs and any(output_dirs):
         raise ValueError('Must specify either output or output_dirs, not both')
 
-    plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled,
-                       drivers_additional)
-    plat.scan_drivers(basedir)
+    scan = src_scan.Scanner(basedir, drivers_additional, warning_disabled)
+    plat = DtbPlatdata(scan, dtb_file, include_disabled)
+    scan.scan_drivers()
     plat.scan_dtb()
     plat.scan_tree()
     plat.scan_reg_sizes()
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
new file mode 100644
index 00000000000..185a6d9284d
--- /dev/null
+++ b/tools/dtoc/src_scan.py
@@ -0,0 +1,185 @@
+#!/usr/bin/python
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2017 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+
+"""Scanning of U-Boot source for drivers and structs
+
+This scans the source tree to find out things about all instances of
+U_BOOT_DRIVER(), UCLASS_DRIVER and all struct declarations in header files.
+
+See doc/driver-model/of-plat.rst for more informaiton
+"""
+
+import os
+import re
+import sys
+
+
+def conv_name_to_c(name):
+    """Convert a device-tree name to a C identifier
+
+    This uses multiple replace() calls instead of re.sub() since it is faster
+    (400ms for 1m calls versus 1000ms for the 're' version).
+
+    Args:
+        name (str): Name to convert
+    Return:
+        str: String containing the C version of this name
+    """
+    new = name.replace('@', '_at_')
+    new = new.replace('-', '_')
+    new = new.replace(',', '_')
+    new = new.replace('.', '_')
+    return new
+
+def get_compat_name(node):
+    """Get the node's list of compatible string as a C identifiers
+
+    Args:
+        node (fdt.Node): Node object to check
+    Return:
+        list of str: List of C identifiers for all the compatible strings
+    """
+    compat = node.props['compatible'].value
+    if not isinstance(compat, list):
+        compat = [compat]
+    return [conv_name_to_c(c) for c in compat]
+
+
+class Driver:
+    """Information about a driver in U-Boot
+
+    Attributes:
+        name: Name of driver. For U_BOOT_DRIVER(x) this is 'x'
+    """
+    def __init__(self, name):
+        self.name = name
+
+    def __eq__(self, other):
+        return self.name == other.name
+
+    def __repr__(self):
+        return "Driver(name='%s')" % self.name
+
+
+class Scanner:
+    """Scanning of the U-Boot source tree
+
+    Properties:
+        _basedir (str): Base directory of U-Boot source code. Defaults to the
+            grandparent of this file's directory
+        _drivers: Dict of valid driver names found in drivers/
+            key: Driver name
+            value: Driver for that driver
+        _driver_aliases: Dict that holds aliases for driver names
+            key: Driver alias declared with
+                DM_DRIVER_ALIAS(driver_alias, driver_name)
+            value: Driver name declared with U_BOOT_DRIVER(driver_name)
+        _drivers_additional (list or str): List of additional drivers to use
+            during scanning
+        _warning_disabled: true to disable warnings about driver names not found
+    """
+    def __init__(self, basedir, drivers_additional, warning_disabled):
+        """Set up a new Scanner
+        """
+        if not basedir:
+            basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
+            if basedir == '':
+                basedir = './'
+        self._basedir = basedir
+        self._drivers = {}
+        self._driver_aliases = {}
+        self._drivers_additional = drivers_additional or []
+        self._warning_disabled = warning_disabled
+
+    def get_normalized_compat_name(self, node):
+        """Get a node's normalized compat name
+
+        Returns a valid driver name by retrieving node's list of compatible
+        string as a C identifier and performing a check against _drivers
+        and a lookup in driver_aliases printing a warning in case of failure.
+
+        Args:
+            node (Node): Node object to check
+        Return:
+            Tuple:
+                Driver name associated with the first compatible string
+                List of C identifiers for all the other compatible strings
+                    (possibly empty)
+                In case of no match found, the return will be the same as
+                get_compat_name()
+        """
+        compat_list_c = get_compat_name(node)
+
+        for compat_c in compat_list_c:
+            if not compat_c in self._drivers.keys():
+                compat_c = self._driver_aliases.get(compat_c)
+                if not compat_c:
+                    continue
+
+            aliases_c = compat_list_c
+            if compat_c in aliases_c:
+                aliases_c.remove(compat_c)
+            return compat_c, aliases_c
+
+        if not self._warning_disabled:
+            print('WARNING: the driver %s was not found in the driver list'
+                  % (compat_list_c[0]))
+
+        return compat_list_c[0], compat_list_c[1:]
+
+    def scan_driver(self, fname):
+        """Scan a driver file to build a list of driver names and aliases
+
+        This procedure will populate self._drivers and self._driver_aliases
+
+        Args
+            fname: Driver filename to scan
+        """
+        with open(fname, encoding='utf-8') as inf:
+            try:
+                buff = inf.read()
+            except UnicodeDecodeError:
+                # This seems to happen on older Python versions
+                print("Skipping file '%s' due to unicode error" % fname)
+                return
+
+            # The following re will search for driver names declared as
+            # U_BOOT_DRIVER(driver_name)
+            drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
+
+            for driver in drivers:
+                self._drivers[driver] = Driver(driver)
+
+            # The following re will search for driver aliases declared as
+            # DM_DRIVER_ALIAS(alias, driver_name)
+            driver_aliases = re.findall(
+                r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
+                buff)
+
+            for alias in driver_aliases: # pragma: no cover
+                if len(alias) != 2:
+                    continue
+                self._driver_aliases[alias[1]] = alias[0]
+
+    def scan_drivers(self):
+        """Scan the driver folders to build a list of driver names and aliases
+
+        This procedure will populate self._drivers and self._driver_aliases
+        """
+        for (dirpath, _, filenames) in os.walk(self._basedir):
+            for fname in filenames:
+                if not fname.endswith('.c'):
+                    continue
+                self.scan_driver(dirpath + '/' + fname)
+
+        for fname in self._drivers_additional:
+            if not isinstance(fname, str) or len(fname) == 0:
+                continue
+            if fname[0] == '/':
+                self.scan_driver(fname)
+            else:
+                self.scan_driver(self._basedir + '/' + fname)
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index bcbf58c45bc..8e8dd847c10 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -18,13 +18,14 @@ import tempfile
 import unittest
 from unittest import mock
 
-from dtb_platdata import conv_name_to_c
-from dtb_platdata import get_compat_name
 from dtb_platdata import get_value
 from dtb_platdata import tab_to
 from dtoc import dtb_platdata
 from dtoc import fdt
 from dtoc import fdt_util
+from dtoc import src_scan
+from dtoc.src_scan import conv_name_to_c
+from dtoc.src_scan import get_compat_name
 from patman import test_util
 from patman import tools
 
@@ -933,9 +934,9 @@ U_BOOT_DRVINFO(spl_test2) = {
 
     def test_driver(self):
         """Test the Driver class"""
-        drv1 = dtb_platdata.Driver('fred')
-        drv2 = dtb_platdata.Driver('mary')
-        drv3 = dtb_platdata.Driver('fred')
+        drv1 = src_scan.Driver('fred')
+        drv2 = src_scan.Driver('mary')
+        drv3 = src_scan.Driver('fred')
         self.assertEqual("Driver(name='fred')", str(drv1))
         self.assertEqual(drv1, drv3)
         self.assertNotEqual(drv1, drv2)
@@ -989,8 +990,7 @@ U_BOOT_DRVINFO(spl_test2) = {
 
             # Mock out scan_driver and check that it is called with the
             # expected files
-            with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \
-                    as mocked:
+            with mock.patch.object(src_scan.Scanner, "scan_driver")  as mocked:
                 dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir],
                                        True, basedir=indir)
             self.assertEqual(2, len(mocked.mock_calls))
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 21/49] dtoc: Move src_scan tests to a separate file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (19 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 20/49] dtoc: Split source-code scanning to a separate file Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
                   ` (47 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Move the tests related to scanning into their own class, updating them
to avoid using dtb_platdata as a pass-through.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py  |  2 +-
 tools/dtoc/main.py          |  5 +-
 tools/dtoc/src_scan.py      |  4 +-
 tools/dtoc/test_dtoc.py     | 73 -----------------------------
 tools/dtoc/test_src_scan.py | 91 +++++++++++++++++++++++++++++++++++++
 5 files changed, 97 insertions(+), 78 deletions(-)
 create mode 100644 tools/dtoc/test_src_scan.py

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index ad642f30625..b7abaed67ac 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -695,7 +695,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     if output and output_dirs and any(output_dirs):
         raise ValueError('Must specify either output or output_dirs, not both')
 
-    scan = src_scan.Scanner(basedir, drivers_additional, warning_disabled)
+    scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
     plat = DtbPlatdata(scan, dtb_file, include_disabled)
     scan.scan_drivers()
     plat.scan_dtb()
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 9d0b3915c0e..b0ad0f3952a 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -46,7 +46,8 @@ def run_tests(processes, args):
         args: List of positional args provided to dtoc. This can hold a test
             name to execute (as in 'dtoc -t test_empty_file', for example)
     """
-    import test_dtoc
+    from dtoc import test_src_scan
+    from dtoc import test_dtoc
 
     result = unittest.TestResult()
     sys.argv = [sys.argv[0]]
@@ -55,7 +56,7 @@ def run_tests(processes, args):
     test_util.RunTestSuites(
         result, debug=True, verbosity=1, test_preserve_dirs=False,
         processes=processes, test_name=test_name, toolpath=[],
-        test_class_list=[test_dtoc.TestDtoc,])
+        test_class_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
 
     return test_util.ReportResult('binman', test_name, result)
 
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 185a6d9284d..f63c9fc166e 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -78,11 +78,11 @@ class Scanner:
             key: Driver alias declared with
                 DM_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
+        _warning_disabled: true to disable warnings about driver names not found
         _drivers_additional (list or str): List of additional drivers to use
             during scanning
-        _warning_disabled: true to disable warnings about driver names not found
     """
-    def __init__(self, basedir, drivers_additional, warning_disabled):
+    def __init__(self, basedir, warning_disabled, drivers_additional):
         """Set up a new Scanner
         """
         if not basedir:
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 8e8dd847c10..d961d67b8fc 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -12,18 +12,14 @@ tool.
 import collections
 import glob
 import os
-import shutil
 import struct
-import tempfile
 import unittest
-from unittest import mock
 
 from dtb_platdata import get_value
 from dtb_platdata import tab_to
 from dtoc import dtb_platdata
 from dtoc import fdt
 from dtoc import fdt_util
-from dtoc import src_scan
 from dtoc.src_scan import conv_name_to_c
 from dtoc.src_scan import get_compat_name
 from patman import test_util
@@ -904,44 +900,6 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
                       str(exc.exception))
 
-    @staticmethod
-    def test_scan_drivers():
-        """Test running dtoc with additional drivers to scan"""
-        dtb_file = get_dtb_file('dtoc_test_simple.dts')
-        output = tools.GetOutputFilename('output')
-        with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(
-                ['struct'], dtb_file, False, output, [], True,
-                [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
-
-    @staticmethod
-    def test_unicode_error():
-        """Test running dtoc with an invalid unicode file
-
-        To be able to perform this test without adding a weird text file which
-        would produce issues when using checkpatch.pl or patman, generate the
-        file at runtime and then process it.
-        """
-        dtb_file = get_dtb_file('dtoc_test_simple.dts')
-        output = tools.GetOutputFilename('output')
-        driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
-        with open(driver_fn, 'wb+') as fout:
-            fout.write(b'\x81')
-
-        with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
-                                   True, [driver_fn])
-
-    def test_driver(self):
-        """Test the Driver class"""
-        drv1 = src_scan.Driver('fred')
-        drv2 = src_scan.Driver('mary')
-        drv3 = src_scan.Driver('fred')
-        self.assertEqual("Driver(name='fred')", str(drv1))
-        self.assertEqual(drv1, drv3)
-        self.assertNotEqual(drv1, drv2)
-        self.assertNotEqual(drv2, drv3)
-
     def test_output_conflict(self):
         """Test a conflict between and output dirs and output file"""
         with self.assertRaises(ValueError) as exc:
@@ -969,34 +927,3 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertEqual(
             {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
             leafs)
-
-    def test_scan_dirs(self):
-        """Test scanning of source directories"""
-        def add_file(fname):
-            pathname = os.path.join(indir, fname)
-            dirname = os.path.dirname(pathname)
-            os.makedirs(dirname, exist_ok=True)
-            tools.WriteFile(pathname, '', binary=False)
-            fname_list.append(pathname)
-
-        try:
-            outdir = tools.GetOutputDir()
-            indir = tempfile.mkdtemp(prefix='dtoc.')
-            dtb_file = get_dtb_file('dtoc_test_simple.dts')
-
-            fname_list = []
-            add_file('fname.c')
-            add_file('dir/fname2.c')
-
-            # Mock out scan_driver and check that it is called with the
-            # expected files
-            with mock.patch.object(src_scan.Scanner, "scan_driver")  as mocked:
-                dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir],
-                                       True, basedir=indir)
-            self.assertEqual(2, len(mocked.mock_calls))
-            self.assertEqual(mock.call(fname_list[0]),
-                             mocked.mock_calls[0])
-            self.assertEqual(mock.call(fname_list[1]),
-                             mocked.mock_calls[1])
-        finally:
-            shutil.rmtree(indir)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
new file mode 100644
index 00000000000..d25da5760a1
--- /dev/null
+++ b/tools/dtoc/test_src_scan.py
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2020 Google LLC
+#
+
+"""Tests for the src_scan module
+
+This includes unit tests for scanning of the source code
+"""
+
+import os
+import shutil
+import tempfile
+import unittest
+from unittest import mock
+
+from dtoc import src_scan
+from patman import tools
+
+# This is a test so is allowed to access private things in the module it is
+# testing
+# pylint: disable=W0212
+
+class TestSrcScan(unittest.TestCase):
+    """Tests for src_scan"""
+    @classmethod
+    def setUpClass(cls):
+        tools.PrepareOutputDir(None)
+
+    @classmethod
+    def tearDownClass(cls):
+        tools.FinaliseOutputDir()
+
+    @classmethod
+    def test_scan_drivers(cls):
+        """Test running dtoc with additional drivers to scan"""
+        scan = src_scan.Scanner(
+            None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+        scan.scan_drivers()
+
+    @classmethod
+    def test_unicode_error(cls):
+        """Test running dtoc with an invalid unicode file
+
+        To be able to perform this test without adding a weird text file which
+        would produce issues when using checkpatch.pl or patman, generate the
+        file at runtime and then process it.
+        """
+        driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
+        with open(driver_fn, 'wb+') as fout:
+            fout.write(b'\x81')
+
+        src_scan.Scanner(None, True, [driver_fn])
+
+    def test_driver(self):
+        """Test the Driver class"""
+        drv1 = src_scan.Driver('fred')
+        drv2 = src_scan.Driver('mary')
+        drv3 = src_scan.Driver('fred')
+        self.assertEqual("Driver(name='fred')", str(drv1))
+        self.assertEqual(drv1, drv3)
+        self.assertNotEqual(drv1, drv2)
+        self.assertNotEqual(drv2, drv3)
+
+    def test_scan_dirs(self):
+        """Test scanning of source directories"""
+        def add_file(fname):
+            pathname = os.path.join(indir, fname)
+            dirname = os.path.dirname(pathname)
+            os.makedirs(dirname, exist_ok=True)
+            tools.WriteFile(pathname, '', binary=False)
+            fname_list.append(pathname)
+
+        try:
+            indir = tempfile.mkdtemp(prefix='dtoc.')
+
+            fname_list = []
+            add_file('fname.c')
+            add_file('dir/fname2.c')
+
+            # Mock out scan_driver and check that it is called with the
+            # expected files
+            with mock.patch.object(src_scan.Scanner, "scan_driver")  as mocked:
+                scan = src_scan.Scanner(indir, True, None)
+                scan.scan_drivers()
+            self.assertEqual(2, len(mocked.mock_calls))
+            self.assertEqual(mock.call(fname_list[0]),
+                             mocked.mock_calls[0])
+            self.assertEqual(mock.call(fname_list[1]),
+                             mocked.mock_calls[1])
+        finally:
+            shutil.rmtree(indir)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 22/49] dtoc: Tidy up src_scan tests
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (20 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 21/49] dtoc: Move src_scan tests " Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 23/49] dtoc: Scan drivers for available information Simon Glass
                   ` (46 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Some of these tests don't actually check anything. Add a few more checks
to complete the tests.

Also add a simple scan test that does the basics.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_src_scan.py | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index d25da5760a1..7d686530d68 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -14,6 +14,7 @@ import unittest
 from unittest import mock
 
 from dtoc import src_scan
+from patman import test_util
 from patman import tools
 
 # This is a test so is allowed to access private things in the module it is
@@ -30,15 +31,26 @@ class TestSrcScan(unittest.TestCase):
     def tearDownClass(cls):
         tools.FinaliseOutputDir()
 
-    @classmethod
-    def test_scan_drivers(cls):
-        """Test running dtoc with additional drivers to scan"""
+    def test_simple(self):
+        """Simple test of scanning drivers"""
+        scan = src_scan.Scanner(None, True, None)
+        scan.scan_drivers()
+        self.assertIn('sandbox_gpio', scan._drivers)
+        self.assertIn('sandbox_gpio_alias', scan._driver_aliases)
+        self.assertEqual('sandbox_gpio',
+                         scan._driver_aliases['sandbox_gpio_alias'])
+        self.assertNotIn('sandbox_gpio_alias2', scan._driver_aliases)
+
+    def test_additional(self):
+        """Test with additional drivers to scan"""
         scan = src_scan.Scanner(
             None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
         scan.scan_drivers()
+        self.assertIn('sandbox_gpio_alias2', scan._driver_aliases)
+        self.assertEqual('sandbox_gpio',
+                         scan._driver_aliases['sandbox_gpio_alias2'])
 
-    @classmethod
-    def test_unicode_error(cls):
+    def test_unicode_error(self):
         """Test running dtoc with an invalid unicode file
 
         To be able to perform this test without adding a weird text file which
@@ -49,7 +61,11 @@ class TestSrcScan(unittest.TestCase):
         with open(driver_fn, 'wb+') as fout:
             fout.write(b'\x81')
 
-        src_scan.Scanner(None, True, [driver_fn])
+        scan = src_scan.Scanner(None, True, [driver_fn])
+        with test_util.capture_sys_output() as (stdout, _):
+            scan.scan_drivers()
+        self.assertRegex(stdout.getvalue(),
+                         r"Skipping file '.*' due to unicode error\s*")
 
     def test_driver(self):
         """Test the Driver class"""
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 23/49] dtoc: Scan drivers for available information
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (21 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 24/49] dtoc: Save scan information across test runs Simon Glass
                   ` (45 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

At present we simply record the name of a driver parsed from its
implementation file. We also need to get the uclass and a few other
things so we can instantiate devices at build time. Add support for
collecting this information. This requires parsing each driver file.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 194 ++++++++++++++++++++++++++++++++++--
 tools/dtoc/test_src_scan.py | 131 +++++++++++++++++++++++-
 2 files changed, 311 insertions(+), 14 deletions(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index f63c9fc166e..095fb6d4766 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -54,15 +54,30 @@ class Driver:
 
     Attributes:
         name: Name of driver. For U_BOOT_DRIVER(x) this is 'x'
+        fname: Filename where the driver was found
+        uclass_id: Name of uclass, e.g. 'UCLASS_I2C'
+        compat: Driver data for each compatible string:
+            key: Compatible string, e.g. 'rockchip,rk3288-grf'
+            value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
+        fname: Filename where the driver was found
+        priv (str): struct name of the priv_auto member, e.g. 'serial_priv'
     """
-    def __init__(self, name):
+    def __init__(self, name, fname):
         self.name = name
+        self.fname = fname
+        self.uclass_id = None
+        self.compat = None
+        self.priv = ''
 
     def __eq__(self, other):
-        return self.name == other.name
+        return (self.name == other.name and
+                self.uclass_id == other.uclass_id and
+                self.compat == other.compat and
+                self.priv == other.priv)
 
     def __repr__(self):
-        return "Driver(name='%s')" % self.name
+        return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
+                (self.name, self.uclass_id, self.compat, self.priv))
 
 
 class Scanner:
@@ -81,6 +96,12 @@ class Scanner:
         _warning_disabled: true to disable warnings about driver names not found
         _drivers_additional (list or str): List of additional drivers to use
             during scanning
+        _of_match: Dict holding information about compatible strings
+            key: Name of struct udevice_id variable
+            value: Dict of compatible info in that variable:
+               key: Compatible string, e.g. 'rockchip,rk3288-grf'
+               value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
+        _compat_to_driver: Maps compatible strings to Driver
     """
     def __init__(self, basedir, warning_disabled, drivers_additional):
         """Set up a new Scanner
@@ -94,6 +115,8 @@ class Scanner:
         self._driver_aliases = {}
         self._drivers_additional = drivers_additional or []
         self._warning_disabled = warning_disabled
+        self._of_match = {}
+        self._compat_to_driver = {}
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -131,10 +154,163 @@ class Scanner:
 
         return compat_list_c[0], compat_list_c[1:]
 
+    @classmethod
+    def _get_re_for_member(cls, member):
+        """_get_re_for_member: Get a compiled regular expression
+
+        Args:
+            member (str): Struct member name, e.g. 'priv_auto'
+
+        Returns:
+            re.Pattern: Compiled regular expression that parses:
+
+               .member = sizeof(struct fred),
+
+            and returns "fred" as group 1
+        """
+        return re.compile(r'^\s*.%s\s*=\s*sizeof\(struct\s+(.*)\),$' % member)
+
+    def _parse_driver(self, fname, buff):
+        """Parse a C file to extract driver information contained within
+
+        This parses U_BOOT_DRIVER() structs to obtain various pieces of useful
+        information.
+
+        It updates the following members:
+            _drivers - updated with new Driver records for each driver found
+                in the file
+            _of_match - updated with each compatible string found in the file
+            _compat_to_driver - Maps compatible string to Driver
+
+        Args:
+            fname (str): Filename being parsed (used for warnings)
+            buff (str): Contents of file
+
+        Raises:
+            ValueError: Compatible variable is mentioned in .of_match in
+                U_BOOT_DRIVER() but not found in the file
+        """
+        # Dict holding information about compatible strings collected in this
+        # function so far
+        #    key: Name of struct udevice_id variable
+        #    value: Dict of compatible info in that variable:
+        #       key: Compatible string, e.g. 'rockchip,rk3288-grf'
+        #       value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
+        of_match = {}
+
+        # Dict holding driver information collected in this function so far
+        #    key: Driver name (C name as in U_BOOT_DRIVER(xxx))
+        #    value: Driver
+        drivers = {}
+
+        # Collect the driver info
+        driver = None
+        re_driver = re.compile(r'U_BOOT_DRIVER\((.*)\)')
+
+        # Collect the uclass ID, e.g. 'UCLASS_SPI'
+        re_id = re.compile(r'\s*\.id\s*=\s*(UCLASS_[A-Z0-9_]+)')
+
+        # Collect the compatible string, e.g. 'rockchip,rk3288-grf'
+        compat = None
+        re_compat = re.compile(r'{\s*.compatible\s*=\s*"(.*)"\s*'
+                               r'(,\s*.data\s*=\s*(\S*))?\s*},')
+
+        # This is a dict of compatible strings that were found:
+        #    key: Compatible string, e.g. 'rockchip,rk3288-grf'
+        #    value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
+        compat_dict = {}
+
+        # Holds the var nane of the udevice_id list, e.g.
+        # 'rk3288_syscon_ids_noc' in
+        # static const struct udevice_id rk3288_syscon_ids_noc[] = {
+        ids_name = None
+        re_ids = re.compile(r'struct udevice_id (.*)\[\]\s*=')
+
+        # Matches the references to the udevice_id list
+        re_of_match = re.compile(
+            r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
+
+        # Matches the struct name for priv
+        re_priv = self._get_re_for_member('priv_auto')
+
+        prefix = ''
+        for line in buff.splitlines():
+            # Handle line continuation
+            if prefix:
+                line = prefix + line
+                prefix = ''
+            if line.endswith('\\'):
+                prefix = line[:-1]
+                continue
+
+            driver_match = re_driver.search(line)
+
+            # If this line contains U_BOOT_DRIVER()...
+            if driver:
+                m_id = re_id.search(line)
+                m_of_match = re_of_match.search(line)
+                m_priv = re_priv.match(line)
+                if m_priv:
+                    driver.priv = m_priv.group(1)
+                elif m_id:
+                    driver.uclass_id = m_id.group(1)
+                elif m_of_match:
+                    compat = m_of_match.group(2)
+                elif '};' in line:
+                    if driver.uclass_id and compat:
+                        if compat not in of_match:
+                            raise ValueError(
+                                "%s: Unknown compatible var '%s' (found: %s)" %
+                                (fname, compat, ','.join(of_match.keys())))
+                        driver.compat = of_match[compat]
+
+                        # This needs to be deterministic, since a driver may
+                        # have multiple compatible strings pointing to it.
+                        # We record the one earliest in the alphabet so it
+                        # will produce the same result on all machines.
+                        for compat_id in of_match[compat]:
+                            old = self._compat_to_driver.get(compat_id)
+                            if not old or driver.name < old.name:
+                                self._compat_to_driver[compat_id] = driver
+                        drivers[driver.name] = driver
+                    else:
+                        # The driver does not have a uclass or compat string.
+                        # The first is required but the second is not, so just
+                        # ignore this.
+                        pass
+                    driver = None
+                    ids_name = None
+                    compat = None
+                    compat_dict = {}
+
+            elif ids_name:
+                compat_m = re_compat.search(line)
+                if compat_m:
+                    compat_dict[compat_m.group(1)] = compat_m.group(3)
+                elif '};' in line:
+                    of_match[ids_name] = compat_dict
+                    ids_name = None
+            elif driver_match:
+                driver_name = driver_match.group(1)
+                driver = Driver(driver_name, fname)
+            else:
+                ids_m = re_ids.search(line)
+                if ids_m:
+                    ids_name = ids_m.group(1)
+
+        # Make the updates based on what we found
+        self._drivers.update(drivers)
+        self._of_match.update(of_match)
+
     def scan_driver(self, fname):
         """Scan a driver file to build a list of driver names and aliases
 
-        This procedure will populate self._drivers and self._driver_aliases
+        It updates the following members:
+            _drivers - updated with new Driver records for each driver found
+                in the file
+            _of_match - updated with each compatible string found in the file
+            _compat_to_driver - Maps compatible string to Driver
+            _driver_aliases - Maps alias names to driver name
 
         Args
             fname: Driver filename to scan
@@ -147,12 +323,10 @@ class Scanner:
                 print("Skipping file '%s' due to unicode error" % fname)
                 return
 
-            # The following re will search for driver names declared as
-            # U_BOOT_DRIVER(driver_name)
-            drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
-
-            for driver in drivers:
-                self._drivers[driver] = Driver(driver)
+            # If this file has any U_BOOT_DRIVER() declarations, process it to
+            # obtain driver information
+            if 'U_BOOT_DRIVER' in buff:
+                self._parse_driver(fname, buff)
 
             # The following re will search for driver aliases declared as
             # DM_DRIVER_ALIAS(alias, driver_name)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 7d686530d68..25e4866f201 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -17,6 +17,20 @@ from dtoc import src_scan
 from patman import test_util
 from patman import tools
 
+OUR_PATH = os.path.dirname(os.path.realpath(__file__))
+
+class FakeNode:
+    """Fake Node object for testing"""
+    def __init__(self):
+        self.name = None
+        self.props = {}
+
+class FakeProp:
+    """Fake Prop object for testing"""
+    def __init__(self):
+        self.name = None
+        self.value = None
+
 # This is a test so is allowed to access private things in the module it is
 # testing
 # pylint: disable=W0212
@@ -69,10 +83,22 @@ class TestSrcScan(unittest.TestCase):
 
     def test_driver(self):
         """Test the Driver class"""
-        drv1 = src_scan.Driver('fred')
-        drv2 = src_scan.Driver('mary')
-        drv3 = src_scan.Driver('fred')
-        self.assertEqual("Driver(name='fred')", str(drv1))
+        i2c = 'I2C_UCLASS'
+        compat = {'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF',
+                  'rockchip,rk3288-srf': None}
+        drv1 = src_scan.Driver('fred', 'fred.c')
+        drv2 = src_scan.Driver('mary', 'mary.c')
+        drv3 = src_scan.Driver('fred', 'fred.c')
+        drv1.uclass_id = i2c
+        drv1.compat = compat
+        drv2.uclass_id = i2c
+        drv2.compat = compat
+        drv3.uclass_id = i2c
+        drv3.compat = compat
+        self.assertEqual(
+            "Driver(name='fred', uclass_id='I2C_UCLASS', "
+            "compat={'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF', "
+            "'rockchip,rk3288-srf': None}, priv=)", str(drv1))
         self.assertEqual(drv1, drv3)
         self.assertNotEqual(drv1, drv2)
         self.assertNotEqual(drv2, drv3)
@@ -105,3 +131,100 @@ class TestSrcScan(unittest.TestCase):
                              mocked.mock_calls[1])
         finally:
             shutil.rmtree(indir)
+
+    def test_scan(self):
+        """Test scanning of a driver"""
+        fname = os.path.join(OUR_PATH, '..', '..', 'drivers/i2c/tegra_i2c.c')
+        buff = tools.ReadFile(fname, False)
+        scan = src_scan.Scanner(None, False, None)
+        scan._parse_driver(fname, buff)
+        self.assertIn('i2c_tegra', scan._drivers)
+        drv = scan._drivers['i2c_tegra']
+        self.assertEqual('i2c_tegra', drv.name)
+        self.assertEqual('UCLASS_I2C', drv.uclass_id)
+        self.assertEqual(
+            {'nvidia,tegra114-i2c': 'TYPE_114',
+             'nvidia,tegra20-i2c': 'TYPE_STD',
+             'nvidia,tegra20-i2c-dvc': 'TYPE_DVC'}, drv.compat)
+        self.assertEqual('i2c_bus', drv.priv)
+        self.assertEqual(1, len(scan._drivers))
+
+    def test_normalized_name(self):
+        """Test operation of get_normalized_compat_name()"""
+        prop = FakeProp()
+        prop.name = 'compatible'
+        prop.value = 'rockchip,rk3288-grf'
+        node = FakeNode()
+        node.props = {'compatible': prop}
+        scan = src_scan.Scanner(None, False, None)
+        with test_util.capture_sys_output() as (stdout, _):
+            name, aliases = scan.get_normalized_compat_name(node)
+        self.assertEqual('rockchip_rk3288_grf', name)
+        self.assertEqual([], aliases)
+        self.assertEqual(
+            'WARNING: the driver rockchip_rk3288_grf was not found in the driver list',
+            stdout.getvalue().strip())
+
+        i2c = 'I2C_UCLASS'
+        compat = {'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF',
+                  'rockchip,rk3288-srf': None}
+        drv = src_scan.Driver('fred', 'fred.c')
+        drv.uclass_id = i2c
+        drv.compat = compat
+        scan._drivers['rockchip_rk3288_grf'] = drv
+
+        scan._driver_aliases['rockchip_rk3288_srf'] = 'rockchip_rk3288_grf'
+
+        with test_util.capture_sys_output() as (stdout, _):
+            name, aliases = scan.get_normalized_compat_name(node)
+        self.assertEqual('', stdout.getvalue().strip())
+        self.assertEqual('rockchip_rk3288_grf', name)
+        self.assertEqual([], aliases)
+
+        prop.value = 'rockchip,rk3288-srf'
+        with test_util.capture_sys_output() as (stdout, _):
+            name, aliases = scan.get_normalized_compat_name(node)
+        self.assertEqual('', stdout.getvalue().strip())
+        self.assertEqual('rockchip_rk3288_grf', name)
+        self.assertEqual(['rockchip_rk3288_srf'], aliases)
+
+    def test_scan_errors(self):
+        """Test detection of scanning errors"""
+        buff = '''
+static const struct udevice_id tegra_i2c_ids2[] = {
+	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+	{ }
+};
+
+U_BOOT_DRIVER(i2c_tegra) = {
+	.name	= "i2c_tegra",
+	.id	= UCLASS_I2C,
+	.of_match = tegra_i2c_ids,
+};
+'''
+        scan = src_scan.Scanner(None, False, None)
+        with self.assertRaises(ValueError) as exc:
+            scan._parse_driver('file.c', buff)
+        self.assertIn(
+            "file.c: Unknown compatible var 'tegra_i2c_ids' (found: tegra_i2c_ids2)",
+            str(exc.exception))
+
+    def test_of_match(self):
+        """Test detection of of_match_ptr() member"""
+        buff = '''
+static const struct udevice_id tegra_i2c_ids[] = {
+	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+	{ }
+};
+
+U_BOOT_DRIVER(i2c_tegra) = {
+	.name	= "i2c_tegra",
+	.id	= UCLASS_I2C,
+	.of_match = of_match_ptr(tegra_i2c_ids),
+};
+'''
+        scan = src_scan.Scanner(None, False, None)
+        scan._parse_driver('file.c', buff)
+        self.assertIn('i2c_tegra', scan._drivers)
+        drv = scan._drivers['i2c_tegra']
+        self.assertEqual('i2c_tegra', drv.name)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 24/49] dtoc: Save scan information across test runs
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (22 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 23/49] dtoc: Scan drivers for available information Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 25/49] dtoc: Ignore unwanted files when scanning for drivers Simon Glass
                   ` (44 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

At present most of the tests scan the U-Boot source tree as part of their
run. This information does not change across tests, so we can save time
by remembering it.

Add a way to set up this information and use it for each test, taking a
copy first, so as not to mess up the original.

This reduces the run time from about 1.6 seconds to 1.5 seconds on my
machine. For code coverage (which cannot run in parallel), it reduces from
33 seconds to 5.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 11 ++++++++---
 tools/dtoc/main.py         |  2 ++
 tools/dtoc/test_dtoc.py    | 40 +++++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index b7abaed67ac..e9be5985c72 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -670,7 +670,8 @@ OUTPUT_FILES = {
 
 
 def run_steps(args, dtb_file, include_disabled, output, output_dirs,
-              warning_disabled=False, drivers_additional=None, basedir=None):
+              warning_disabled=False, drivers_additional=None, basedir=None,
+              scan=None):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -687,6 +688,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
             scanning
         basedir (str): Base directory of U-Boot source code. Defaults to the
             grandparent of this file's directory
+        scan (src_src.Scanner): Scanner from a previous run. This can help speed
+            up tests. Use None for normal operation
+
     Raises:
         ValueError: if args has no command, or an unknown command
     """
@@ -695,9 +699,10 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     if output and output_dirs and any(output_dirs):
         raise ValueError('Must specify either output or output_dirs, not both')
 
-    scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
+    if not scan:
+        scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
+        scan.scan_drivers()
     plat = DtbPlatdata(scan, dtb_file, include_disabled)
-    scan.scan_drivers()
     plat.scan_dtb()
     plat.scan_tree()
     plat.scan_reg_sizes()
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index b0ad0f3952a..355b1e62773 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -53,6 +53,8 @@ def run_tests(processes, args):
     sys.argv = [sys.argv[0]]
     test_name = args and args[0] or None
 
+    test_dtoc.setup()
+
     test_util.RunTestSuites(
         result, debug=True, verbosity=1, test_preserve_dirs=False,
         processes=processes, test_name=test_name, toolpath=[],
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index d961d67b8fc..6865d949a05 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -10,6 +10,7 @@ tool.
 """
 
 import collections
+import copy
 import glob
 import os
 import struct
@@ -20,6 +21,7 @@ from dtb_platdata import tab_to
 from dtoc import dtb_platdata
 from dtoc import fdt
 from dtoc import fdt_util
+from dtoc import src_scan
 from dtoc.src_scan import conv_name_to_c
 from dtoc.src_scan import get_compat_name
 from patman import test_util
@@ -53,6 +55,9 @@ C_HEADER = '''/*
 #include <dt-structs.h>
 '''
 
+# Scanner saved from a previous run of the tests (to speed things up)
+saved_scan = None
+
 # This is a test so is allowed to access private things in the module it is
 # testing
 # pylint: disable=W0212
@@ -71,6 +76,19 @@ def get_dtb_file(dts_fname, capture_stderr=False):
                                    capture_stderr=capture_stderr)
 
 
+def setup():
+    global saved_scan
+
+    # Disable warnings so that calls to get_normalized_compat_name() will not
+    # output things.
+    saved_scan = src_scan.Scanner(None, True, False)
+    saved_scan.scan_drivers()
+
+def copy_scan():
+    """Get a copy of saved_scan so that each test can start clean"""
+    return copy.deepcopy(saved_scan)
+
+
 class TestDtoc(unittest.TestCase):
     """Tests for dtoc"""
     @classmethod
@@ -120,7 +138,8 @@ class TestDtoc(unittest.TestCase):
             dtb_file (str): Filename of .dtb file
             output (str): Filename of output file
         """
-        dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
+        dtb_platdata.run_steps(args, dtb_file, False, output, [], True,
+                               None, None, scan=copy_scan())
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -175,7 +194,9 @@ class TestDtoc(unittest.TestCase):
         """Test output from a device tree file with no nodes"""
         dtb_file = get_dtb_file('dtoc_test_empty.dts')
         output = tools.GetOutputFilename('output')
-        self.run_test(['struct'], dtb_file, output)
+
+        # Run this one without saved_scan to complete test coverage
+        dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], True)
         with open(output) as infile:
             lines = infile.read().splitlines()
         self.assertEqual(HEADER.splitlines(), lines)
@@ -343,7 +364,8 @@ U_BOOT_DRVINFO(gpios_at_0) = {
         dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
+            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
+                                   scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(HEADER + '''
@@ -352,7 +374,8 @@ struct dtd_invalid {
 ''', data)
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
+            dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [],
+                                   scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -502,7 +525,8 @@ U_BOOT_DRVINFO(phandle_target) = {
         """Test that phandle targets are generated when unsing cd-gpios"""
         dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
         output = tools.GetOutputFilename('output')
-        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
+        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True,
+                               scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -903,7 +927,8 @@ U_BOOT_DRVINFO(spl_test2) = {
     def test_output_conflict(self):
         """Test a conflict between and output dirs and output file"""
         with self.assertRaises(ValueError) as exc:
-            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True)
+            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True,
+                                   scan=copy_scan())
         self.assertIn("Must specify either output or output_dirs, not both",
                       str(exc.exception))
 
@@ -919,7 +944,8 @@ U_BOOT_DRVINFO(spl_test2) = {
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(2, len(fnames))
 
-        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
+        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True,
+                               scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(4, len(fnames))
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 25/49] dtoc: Ignore unwanted files when scanning for drivers
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (23 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 24/49] dtoc: Save scan information across test runs Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 26/49] dtoc: Collect priv/plat struct info from drivers Simon Glass
                   ` (43 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

We should ignore anything in the .git directory or any of the
build-sandbox, etc. directories created by 'make check'. These can confuse
dtoc. Update the code to ignore these.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 5 +++++
 tools/dtoc/test_src_scan.py | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 095fb6d4766..761164a9c9a 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -345,6 +345,11 @@ class Scanner:
         This procedure will populate self._drivers and self._driver_aliases
         """
         for (dirpath, _, filenames) in os.walk(self._basedir):
+            rel_path = dirpath[len(self._basedir):]
+            if rel_path.startswith('/'):
+                rel_path = rel_path[1:]
+            if rel_path.startswith('build') or rel_path.startswith('.git'):
+                continue
             for fname in filenames:
                 if not fname.endswith('.c'):
                     continue
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 25e4866f201..ada49fb7042 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -117,7 +117,9 @@ class TestSrcScan(unittest.TestCase):
 
             fname_list = []
             add_file('fname.c')
+            add_file('.git/ignoreme.c')
             add_file('dir/fname2.c')
+            add_file('build-sandbox/ignoreme2.c')
 
             # Mock out scan_driver and check that it is called with the
             # expected files
@@ -127,7 +129,8 @@ class TestSrcScan(unittest.TestCase):
             self.assertEqual(2, len(mocked.mock_calls))
             self.assertEqual(mock.call(fname_list[0]),
                              mocked.mock_calls[0])
-            self.assertEqual(mock.call(fname_list[1]),
+            # .git file should be ignored
+            self.assertEqual(mock.call(fname_list[2]),
                              mocked.mock_calls[1])
         finally:
             shutil.rmtree(indir)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 26/49] dtoc: Collect priv/plat struct info from drivers
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (24 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 25/49] dtoc: Ignore unwanted files when scanning for drivers Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 27/49] dtoc: Support scanning of uclasses Simon Glass
                   ` (42 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

In order to output variables to hold the priv/plat information used by
each device, dtoc needs to know the struct for each. With this, it can
declare this at build time:

   u8 xxx_priv [sizeof(struct <name>)];

Collect the various struct names from the drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 25 +++++++++++++++++++++++--
 tools/dtoc/test_src_scan.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 761164a9c9a..ff3ab409e4b 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -61,6 +61,11 @@ class Driver:
             value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
         fname: Filename where the driver was found
         priv (str): struct name of the priv_auto member, e.g. 'serial_priv'
+        plat (str): struct name of the plat_auto member, e.g. 'serial_plat'
+        child_priv (str): struct name of the per_child_auto member,
+            e.g. 'pci_child_priv'
+        child_plat (str): struct name of the per_child_plat_auto member,
+            e.g. 'pci_child_plat'
     """
     def __init__(self, name, fname):
         self.name = name
@@ -68,12 +73,16 @@ class Driver:
         self.uclass_id = None
         self.compat = None
         self.priv = ''
+        self.plat = ''
+        self.child_priv = ''
+        self.child_plat = ''
 
     def __eq__(self, other):
         return (self.name == other.name and
                 self.uclass_id == other.uclass_id and
                 self.compat == other.compat and
-                self.priv == other.priv)
+                self.priv == other.priv and
+                self.plat == other.plat)
 
     def __repr__(self):
         return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
@@ -230,8 +239,11 @@ class Scanner:
         re_of_match = re.compile(
             r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
 
-        # Matches the struct name for priv
+        # Matches the struct name for priv, plat
         re_priv = self._get_re_for_member('priv_auto')
+        re_plat = self._get_re_for_member('plat_auto')
+        re_child_priv = self._get_re_for_member('per_child_auto')
+        re_child_plat = self._get_re_for_member('per_child_plat_auto')
 
         prefix = ''
         for line in buff.splitlines():
@@ -250,8 +262,17 @@ class Scanner:
                 m_id = re_id.search(line)
                 m_of_match = re_of_match.search(line)
                 m_priv = re_priv.match(line)
+                m_plat = re_plat.match(line)
+                m_cplat = re_child_plat.match(line)
+                m_cpriv = re_child_priv.match(line)
                 if m_priv:
                     driver.priv = m_priv.group(1)
+                elif m_plat:
+                    driver.plat = m_plat.group(1)
+                elif m_cplat:
+                    driver.child_plat = m_cplat.group(1)
+                elif m_cpriv:
+                    driver.child_priv = m_cpriv.group(1)
                 elif m_id:
                     driver.uclass_id = m_id.group(1)
                 elif m_of_match:
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index ada49fb7042..62dea2a9612 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -231,3 +231,35 @@ U_BOOT_DRIVER(i2c_tegra) = {
         self.assertIn('i2c_tegra', scan._drivers)
         drv = scan._drivers['i2c_tegra']
         self.assertEqual('i2c_tegra', drv.name)
+
+    def test_priv(self):
+        """Test collection of struct info from drivers"""
+        buff = '''
+static const struct udevice_id test_ids[] = {
+	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+	{ }
+};
+
+U_BOOT_DRIVER(testing) = {
+	.name	= "testing",
+	.id	= UCLASS_I2C,
+	.of_match = test_ids,
+	.priv_auto	= sizeof(struct some_priv),
+	.plat_auto = sizeof(struct some_plat),
+	.per_child_auto	= sizeof(struct some_cpriv),
+	.per_child_plat_auto = sizeof(struct some_cplat),
+};
+'''
+        scan = src_scan.Scanner(None, False, None)
+        scan._parse_driver('file.c', buff)
+        self.assertIn('testing', scan._drivers)
+        drv = scan._drivers['testing']
+        self.assertEqual('testing', drv.name)
+        self.assertEqual('UCLASS_I2C', drv.uclass_id)
+        self.assertEqual(
+            {'nvidia,tegra114-i2c': 'TYPE_114'}, drv.compat)
+        self.assertEqual('some_priv', drv.priv)
+        self.assertEqual('some_plat', drv.plat)
+        self.assertEqual('some_cpriv', drv.child_priv)
+        self.assertEqual('some_cplat', drv.child_plat)
+        self.assertEqual(1, len(scan._drivers))
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 27/49] dtoc: Support scanning of uclasses
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (25 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 26/49] dtoc: Collect priv/plat struct info from drivers Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 28/49] dtoc: Support scanning of structs in header files Simon Glass
                   ` (41 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Uclasses can have per-device private / platform data so dtoc needs to
scan these drivers. This allows it to find out the size of this data so
it can be allocated a build time.

Add a parser for uclass information, similar to drivers. Keep a dict of
the uclasses that were found.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 122 ++++++++++++++++++++++++++++++++++++
 tools/dtoc/test_src_scan.py |  55 ++++++++++++++++
 2 files changed, 177 insertions(+)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index ff3ab409e4b..3245d02e09b 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -89,6 +89,43 @@ class Driver:
                 (self.name, self.uclass_id, self.compat, self.priv))
 
 
+class UclassDriver:
+    """Holds information about a uclass driver
+
+    Attributes:
+        name: Uclass name, e.g. 'i2c' if the driver is for UCLASS_I2C
+        uclass_id: Uclass ID, e.g. 'UCLASS_I2C'
+        priv: struct name of the private data, e.g. 'i2c_priv'
+        per_dev_priv (str): struct name of the priv_auto member, e.g. 'spi_info'
+        per_dev_plat (str): struct name of the plat_auto member, e.g. 'i2c_chip'
+        per_child_priv (str): struct name of the per_child_auto member,
+            e.g. 'pci_child_priv'
+        per_child_plat (str): struct name of the per_child_plat_auto member,
+            e.g. 'pci_child_plat'
+    """
+    def __init__(self, name):
+        self.name = name
+        self.uclass_id = None
+        self.priv = ''
+        self.per_dev_priv = ''
+        self.per_dev_plat = ''
+        self.per_child_priv = ''
+        self.per_child_plat = ''
+
+    def __eq__(self, other):
+        return (self.name == other.name and
+                self.uclass_id == other.uclass_id and
+                self.priv == other.priv)
+
+    def __repr__(self):
+        return ("UclassDriver(name='%s', uclass_id='%s')" %
+                (self.name, self.uclass_id))
+
+    def __hash__(self):
+        # We can use the uclass ID since it is unique among uclasses
+        return hash(self.uclass_id)
+
+
 class Scanner:
     """Scanning of the U-Boot source tree
 
@@ -111,6 +148,9 @@ class Scanner:
                key: Compatible string, e.g. 'rockchip,rk3288-grf'
                value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
         _compat_to_driver: Maps compatible strings to Driver
+        _uclass: Dict of uclass information
+            key: uclass name, e.g. 'UCLASS_I2C'
+            value: UClassDriver
     """
     def __init__(self, basedir, warning_disabled, drivers_additional):
         """Set up a new Scanner
@@ -126,6 +166,7 @@ class Scanner:
         self._warning_disabled = warning_disabled
         self._of_match = {}
         self._compat_to_driver = {}
+        self._uclass = {}
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -179,6 +220,85 @@ class Scanner:
         """
         return re.compile(r'^\s*.%s\s*=\s*sizeof\(struct\s+(.*)\),$' % member)
 
+    def _parse_uclass_driver(self, fname, buff):
+        """Parse a C file to extract uclass driver information contained within
+
+        This parses UCLASS_DRIVER() structs to obtain various pieces of useful
+        information.
+
+        It updates the following member:
+            _uclass: Dict of uclass information
+                key: uclass name, e.g. 'UCLASS_I2C'
+                value: UClassDriver
+
+        Args:
+            fname (str): Filename being parsed (used for warnings)
+            buff (str): Contents of file
+        """
+        uc_drivers = {}
+
+        # Collect the driver name and associated Driver
+        driver = None
+        re_driver = re.compile(r'UCLASS_DRIVER\((.*)\)')
+
+        # Collect the uclass ID, e.g. 'UCLASS_SPI'
+        re_id = re.compile(r'\s*\.id\s*=\s*(UCLASS_[A-Z0-9_]+)')
+
+        # Matches the header/size information for uclass-private data
+        re_priv = self._get_re_for_member('priv_auto')
+
+        # Set up parsing for the auto members
+        re_per_device_priv = self._get_re_for_member('per_device_auto')
+        re_per_device_plat = self._get_re_for_member('per_device_plat_auto')
+        re_per_child_priv = self._get_re_for_member('per_child_auto')
+        re_per_child_plat = self._get_re_for_member('per_child_plat_auto')
+
+        prefix = ''
+        for line in buff.splitlines():
+            # Handle line continuation
+            if prefix:
+                line = prefix + line
+                prefix = ''
+            if line.endswith('\\'):
+                prefix = line[:-1]
+                continue
+
+            driver_match = re_driver.search(line)
+
+            # If we have seen UCLASS_DRIVER()...
+            if driver:
+                m_id = re_id.search(line)
+                m_priv = re_priv.match(line)
+                m_per_dev_priv = re_per_device_priv.match(line)
+                m_per_dev_plat = re_per_device_plat.match(line)
+                m_per_child_priv = re_per_child_priv.match(line)
+                m_per_child_plat = re_per_child_plat.match(line)
+                if m_id:
+                    driver.uclass_id = m_id.group(1)
+                elif m_priv:
+                    driver.priv = m_priv.group(1)
+                elif m_per_dev_priv:
+                    driver.per_dev_priv = m_per_dev_priv.group(1)
+                elif m_per_dev_plat:
+                    driver.per_dev_plat = m_per_dev_plat.group(1)
+                elif m_per_child_priv:
+                    driver.per_child_priv = m_per_child_priv.group(1)
+                elif m_per_child_plat:
+                    driver.per_child_plat = m_per_child_plat.group(1)
+                elif '};' in line:
+                    if not driver.uclass_id:
+                        raise ValueError(
+                            "%s: Cannot parse uclass ID in driver '%s'" %
+                            (fname, driver.name))
+                    uc_drivers[driver.uclass_id] = driver
+                    driver = None
+
+            elif driver_match:
+                driver_name = driver_match.group(1)
+                driver = UclassDriver(driver_name)
+
+        self._uclass.update(uc_drivers)
+
     def _parse_driver(self, fname, buff):
         """Parse a C file to extract driver information contained within
 
@@ -348,6 +468,8 @@ class Scanner:
             # obtain driver information
             if 'U_BOOT_DRIVER' in buff:
                 self._parse_driver(fname, buff)
+            if 'UCLASS_DRIVER' in buff:
+                self._parse_uclass_driver(fname, buff)
 
             # The following re will search for driver aliases declared as
             # DM_DRIVER_ALIAS(alias, driver_name)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 62dea2a9612..641d6495de3 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -7,6 +7,7 @@
 This includes unit tests for scanning of the source code
 """
 
+import copy
 import os
 import shutil
 import tempfile
@@ -263,3 +264,57 @@ U_BOOT_DRIVER(testing) = {
         self.assertEqual('some_cpriv', drv.child_priv)
         self.assertEqual('some_cplat', drv.child_plat)
         self.assertEqual(1, len(scan._drivers))
+
+    def test_uclass_scan(self):
+        """Test collection of uclass-driver info"""
+        buff = '''
+UCLASS_DRIVER(i2c) = {
+	.id		= UCLASS_I2C,
+	.name		= "i2c",
+	.flags		= DM_UC_FLAG_SEQ_ALIAS,
+	.priv_auto	= sizeof(struct some_priv),
+	.per_device_auto	= sizeof(struct per_dev_priv),
+	.per_device_plat_auto	= sizeof(struct per_dev_plat),
+	.per_child_auto	= sizeof(struct per_child_priv),
+	.per_child_plat_auto	= sizeof(struct per_child_plat),
+	.child_post_bind = i2c_child_post_bind,
+};
+
+'''
+        scan = src_scan.Scanner(None, False, None)
+        scan._parse_uclass_driver('file.c', buff)
+        self.assertIn('UCLASS_I2C', scan._uclass)
+        drv = scan._uclass['UCLASS_I2C']
+        self.assertEqual('i2c', drv.name)
+        self.assertEqual('UCLASS_I2C', drv.uclass_id)
+        self.assertEqual('some_priv', drv.priv)
+        self.assertEqual('per_dev_priv', drv.per_dev_priv)
+        self.assertEqual('per_dev_plat', drv.per_dev_plat)
+        self.assertEqual('per_child_priv', drv.per_child_priv)
+        self.assertEqual('per_child_plat', drv.per_child_plat)
+        self.assertEqual(1, len(scan._uclass))
+
+        drv2 = copy.deepcopy(drv)
+        self.assertEqual(drv, drv2)
+        drv2.priv = 'other_priv'
+        self.assertNotEqual(drv, drv2)
+
+        # The hashes only depend on the uclass ID, so should be equal
+        self.assertEqual(drv.__hash__(), drv2.__hash__())
+
+        self.assertEqual("UclassDriver(name='i2c', uclass_id='UCLASS_I2C')",
+                         str(drv))
+
+    def test_uclass_scan_errors(self):
+        """Test detection of uclass scanning errors"""
+        buff = '''
+UCLASS_DRIVER(i2c) = {
+	.name		= "i2c",
+};
+
+'''
+        scan = src_scan.Scanner(None, False, None)
+        with self.assertRaises(ValueError) as exc:
+            scan._parse_uclass_driver('file.c', buff)
+        self.assertIn("file.c: Cannot parse uclass ID in driver 'i2c'",
+                      str(exc.exception))
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 28/49] dtoc: Support scanning of structs in header files
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (26 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 27/49] dtoc: Support scanning of uclasses Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 29/49] dtoc: Move test files into a test/ directory Simon Glass
                   ` (40 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Drivers can have private / platform data contained in structs and these
struct definitions are generally kept in header files. In order to
generate build-time devices, dtoc needs to generate code that declares
the data contained in those structs. This generated code must include the
relevant header file, to avoid a build error.

We need a way for dtoc to scan header files for struct definitions. Then,
when it wants to generate code that uses a struct, it can make sure it
includes the correct header file, first.

Add a parser for struct information, similar to drivers. Keep a dict of
the structs that were found.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 86 +++++++++++++++++++++++++++++++++++--
 tools/dtoc/test_src_scan.py | 45 +++++++++++++++++++
 2 files changed, 128 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 3245d02e09b..bf3e5de9b1e 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -126,6 +126,22 @@ class UclassDriver:
         return hash(self.uclass_id)
 
 
+class Struct:
+    """Holds information about a struct definition
+
+    Attributes:
+        name: Struct name, e.g. 'fred' if the struct is 'struct fred'
+        fname: Filename containing the struct, in a format that C files can
+            include, e.g. 'asm/clk.h'
+    """
+    def __init__(self, name, fname):
+        self.name = name
+        self.fname =fname
+
+    def __repr__(self):
+        return ("Struct(name='%s', fname='%s')" % (self.name, self.fname))
+
+
 class Scanner:
     """Scanning of the U-Boot source tree
 
@@ -151,6 +167,9 @@ class Scanner:
         _uclass: Dict of uclass information
             key: uclass name, e.g. 'UCLASS_I2C'
             value: UClassDriver
+        _structs: Dict of all structs found in U-Boot:
+            key: Name of struct
+            value: Struct object
     """
     def __init__(self, basedir, warning_disabled, drivers_additional):
         """Set up a new Scanner
@@ -167,6 +186,7 @@ class Scanner:
         self._of_match = {}
         self._compat_to_driver = {}
         self._uclass = {}
+        self._structs = {}
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -204,6 +224,41 @@ class Scanner:
 
         return compat_list_c[0], compat_list_c[1:]
 
+    def _parse_structs(self, fname, buff):
+        """Parse a H file to extract struct definitions contained within
+
+        This parses 'struct xx {' definitions to figure out what structs this
+        header defines.
+
+        Args:
+            buff (str): Contents of file
+            fname (str): Filename (to use when printing errors)
+        """
+        structs = {}
+
+        re_struct = re.compile('^struct ([a-z0-9_]+) {$')
+        re_asm = re.compile('../arch/[a-z0-9]+/include/asm/(.*)')
+        prefix = ''
+        for line in buff.splitlines():
+            # Handle line continuation
+            if prefix:
+                line = prefix + line
+                prefix = ''
+            if line.endswith('\\'):
+                prefix = line[:-1]
+                continue
+
+            m_struct = re_struct.match(line)
+            if m_struct:
+                name = m_struct.group(1)
+                include_dir = os.path.join(self._basedir, 'include')
+                rel_fname = os.path.relpath(fname, include_dir)
+                m_asm = re_asm.match(rel_fname)
+                if m_asm:
+                    rel_fname = 'asm/' + m_asm.group(1)
+                structs[name] = Struct(name, rel_fname)
+        self._structs.update(structs)
+
     @classmethod
     def _get_re_for_member(cls, member):
         """_get_re_for_member: Get a compiled regular expression
@@ -482,6 +537,29 @@ class Scanner:
                     continue
                 self._driver_aliases[alias[1]] = alias[0]
 
+    def scan_header(self, fname):
+        """Scan a header file to build a list of struct definitions
+
+        It updates the following members:
+            _structs - updated with new Struct records for each struct found
+                in the file
+
+        Args
+            fname: header filename to scan
+        """
+        with open(fname, encoding='utf-8') as inf:
+            try:
+                buff = inf.read()
+            except UnicodeDecodeError:
+                # This seems to happen on older Python versions
+                print("Skipping file '%s' due to unicode error" % fname)
+                return
+
+            # If this file has any U_BOOT_DRIVER() declarations, process it to
+            # obtain driver information
+            if 'struct' in buff:
+                self._parse_structs(fname, buff)
+
     def scan_drivers(self):
         """Scan the driver folders to build a list of driver names and aliases
 
@@ -494,9 +572,11 @@ class Scanner:
             if rel_path.startswith('build') or rel_path.startswith('.git'):
                 continue
             for fname in filenames:
-                if not fname.endswith('.c'):
-                    continue
-                self.scan_driver(dirpath + '/' + fname)
+                pathname = dirpath + '/' + fname
+                if fname.endswith('.c'):
+                    self.scan_driver(pathname)
+                elif fname.endswith('.h'):
+                    self.scan_header(pathname)
 
         for fname in self._drivers_additional:
             if not isinstance(fname, str) or len(fname) == 0:
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 641d6495de3..a0b0e097eb2 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -318,3 +318,48 @@ UCLASS_DRIVER(i2c) = {
             scan._parse_uclass_driver('file.c', buff)
         self.assertIn("file.c: Cannot parse uclass ID in driver 'i2c'",
                       str(exc.exception))
+
+    def test_struct_scan(self):
+        """Test collection of struct info"""
+        buff = '''
+/* some comment */
+struct some_struct1 {
+	struct i2c_msg *msgs;
+	uint nmsgs;
+};
+'''
+        scan = src_scan.Scanner(None, False, None)
+        scan._basedir = os.path.join(OUR_PATH, '..', '..')
+        scan._parse_structs('arch/arm/include/asm/file.h', buff)
+        self.assertIn('some_struct1', scan._structs)
+        struc = scan._structs['some_struct1']
+        self.assertEqual('some_struct1', struc.name)
+        self.assertEqual('asm/file.h', struc.fname)
+
+        buff = '''
+/* another comment */
+struct another_struct {
+	int speed_hz;
+	int max_transaction_bytes;
+};
+'''
+        scan._parse_structs('include/file2.h', buff)
+        self.assertIn('another_struct', scan._structs)
+        struc = scan._structs['another_struct']
+        self.assertEqual('another_struct', struc.name)
+        self.assertEqual('file2.h', struc.fname)
+
+        self.assertEqual(2, len(scan._structs))
+
+        self.assertEqual("Struct(name='another_struct', fname='file2.h')",
+                         str(struc))
+
+    def test_struct_scan_errors(self):
+        """Test scanning a header file with an invalid unicode file"""
+        output = tools.GetOutputFilename('output.h')
+        tools.WriteFile(output, b'struct this is a test \x81 of bad unicode')
+
+        scan = src_scan.Scanner(None, False, None)
+        with test_util.capture_sys_output() as (stdout, _):
+            scan.scan_header(output)
+        self.assertIn('due to unicode error', stdout.getvalue())
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 29/49] dtoc: Move test files into a test/ directory
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (27 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 28/49] dtoc: Support scanning of structs in header files Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 30/49] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test Simon Glass
                   ` (39 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

It is confusing to have the test files in the same places as the
implementation. Move them into a separate directory.

Add a helper function for test_dtoc, to avoid repeating the same
path.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/{ => test}/dtoc_test.dts           |  0
 tools/dtoc/{ => test}/dtoc_test_add_prop.dts  |  0
 tools/dtoc/{ => test}/dtoc_test_addr32.dts    |  0
 tools/dtoc/{ => test}/dtoc_test_addr32_64.dts |  0
 tools/dtoc/{ => test}/dtoc_test_addr64.dts    |  0
 tools/dtoc/{ => test}/dtoc_test_addr64_32.dts |  0
 tools/dtoc/{ => test}/dtoc_test_aliases.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_bad_reg.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts  |  0
 .../{ => test}/dtoc_test_driver_alias.dts     |  0
 tools/dtoc/{ => test}/dtoc_test_empty.dts     |  0
 .../{ => test}/dtoc_test_invalid_driver.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_phandle.dts   |  0
 .../dtoc/{ => test}/dtoc_test_phandle_bad.dts |  0
 .../{ => test}/dtoc_test_phandle_bad2.dts     |  0
 .../{ => test}/dtoc_test_phandle_cd_gpios.dts |  0
 .../{ => test}/dtoc_test_phandle_reorder.dts  |  0
 .../{ => test}/dtoc_test_phandle_single.dts   |  0
 .../{ => test}/dtoc_test_scan_drivers.cxx     |  0
 tools/dtoc/{ => test}/dtoc_test_simple.dts    |  0
 tools/dtoc/test_dtoc.py                       |  2 +-
 tools/dtoc/test_fdt.py                        | 31 +++++++++++++------
 tools/dtoc/test_src_scan.py                   |  3 +-
 23 files changed, 24 insertions(+), 12 deletions(-)
 rename tools/dtoc/{ => test}/dtoc_test.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_add_prop.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32_64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64_32.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_aliases.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_driver_alias.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_empty.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_invalid_driver.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_cd_gpios.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_reorder.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_single.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_scan_drivers.cxx (100%)
 rename tools/dtoc/{ => test}/dtoc_test_simple.dts (100%)

diff --git a/tools/dtoc/dtoc_test.dts b/tools/dtoc/test/dtoc_test.dts
similarity index 100%
rename from tools/dtoc/dtoc_test.dts
rename to tools/dtoc/test/dtoc_test.dts
diff --git a/tools/dtoc/dtoc_test_add_prop.dts b/tools/dtoc/test/dtoc_test_add_prop.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_add_prop.dts
rename to tools/dtoc/test/dtoc_test_add_prop.dts
diff --git a/tools/dtoc/dtoc_test_addr32.dts b/tools/dtoc/test/dtoc_test_addr32.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_addr32.dts
rename to tools/dtoc/test/dtoc_test_addr32.dts
diff --git a/tools/dtoc/dtoc_test_addr32_64.dts b/tools/dtoc/test/dtoc_test_addr32_64.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_addr32_64.dts
rename to tools/dtoc/test/dtoc_test_addr32_64.dts
diff --git a/tools/dtoc/dtoc_test_addr64.dts b/tools/dtoc/test/dtoc_test_addr64.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_addr64.dts
rename to tools/dtoc/test/dtoc_test_addr64.dts
diff --git a/tools/dtoc/dtoc_test_addr64_32.dts b/tools/dtoc/test/dtoc_test_addr64_32.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_addr64_32.dts
rename to tools/dtoc/test/dtoc_test_addr64_32.dts
diff --git a/tools/dtoc/dtoc_test_aliases.dts b/tools/dtoc/test/dtoc_test_aliases.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_aliases.dts
rename to tools/dtoc/test/dtoc_test_aliases.dts
diff --git a/tools/dtoc/dtoc_test_bad_reg.dts b/tools/dtoc/test/dtoc_test_bad_reg.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_bad_reg.dts
rename to tools/dtoc/test/dtoc_test_bad_reg.dts
diff --git a/tools/dtoc/dtoc_test_bad_reg2.dts b/tools/dtoc/test/dtoc_test_bad_reg2.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_bad_reg2.dts
rename to tools/dtoc/test/dtoc_test_bad_reg2.dts
diff --git a/tools/dtoc/dtoc_test_driver_alias.dts b/tools/dtoc/test/dtoc_test_driver_alias.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_driver_alias.dts
rename to tools/dtoc/test/dtoc_test_driver_alias.dts
diff --git a/tools/dtoc/dtoc_test_empty.dts b/tools/dtoc/test/dtoc_test_empty.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_empty.dts
rename to tools/dtoc/test/dtoc_test_empty.dts
diff --git a/tools/dtoc/dtoc_test_invalid_driver.dts b/tools/dtoc/test/dtoc_test_invalid_driver.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_invalid_driver.dts
rename to tools/dtoc/test/dtoc_test_invalid_driver.dts
diff --git a/tools/dtoc/dtoc_test_phandle.dts b/tools/dtoc/test/dtoc_test_phandle.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle.dts
rename to tools/dtoc/test/dtoc_test_phandle.dts
diff --git a/tools/dtoc/dtoc_test_phandle_bad.dts b/tools/dtoc/test/dtoc_test_phandle_bad.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle_bad.dts
rename to tools/dtoc/test/dtoc_test_phandle_bad.dts
diff --git a/tools/dtoc/dtoc_test_phandle_bad2.dts b/tools/dtoc/test/dtoc_test_phandle_bad2.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle_bad2.dts
rename to tools/dtoc/test/dtoc_test_phandle_bad2.dts
diff --git a/tools/dtoc/dtoc_test_phandle_cd_gpios.dts b/tools/dtoc/test/dtoc_test_phandle_cd_gpios.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle_cd_gpios.dts
rename to tools/dtoc/test/dtoc_test_phandle_cd_gpios.dts
diff --git a/tools/dtoc/dtoc_test_phandle_reorder.dts b/tools/dtoc/test/dtoc_test_phandle_reorder.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle_reorder.dts
rename to tools/dtoc/test/dtoc_test_phandle_reorder.dts
diff --git a/tools/dtoc/dtoc_test_phandle_single.dts b/tools/dtoc/test/dtoc_test_phandle_single.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_phandle_single.dts
rename to tools/dtoc/test/dtoc_test_phandle_single.dts
diff --git a/tools/dtoc/dtoc_test_scan_drivers.cxx b/tools/dtoc/test/dtoc_test_scan_drivers.cxx
similarity index 100%
rename from tools/dtoc/dtoc_test_scan_drivers.cxx
rename to tools/dtoc/test/dtoc_test_scan_drivers.cxx
diff --git a/tools/dtoc/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts
similarity index 100%
rename from tools/dtoc/dtoc_test_simple.dts
rename to tools/dtoc/test/dtoc_test_simple.dts
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 6865d949a05..523f0a923eb 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -72,7 +72,7 @@ def get_dtb_file(dts_fname, capture_stderr=False):
     Returns:
         str: Filename of compiled file in output directory
     """
-    return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname),
+    return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, 'test', dts_fname),
                                    capture_stderr=capture_stderr)
 
 
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index dc6943f7337..5bcc84b31c3 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -48,6 +48,17 @@ def _GetPropertyValue(dtb, node, prop_name):
     data = dtb.GetContents()[offset:offset + len(prop.value)]
     return prop, [chr(x) for x in data]
 
+def find_dtb_file(dts_fname):
+    """Locate a test file in the test/ directory
+
+    Args:
+        dts_fname (str): Filename to find, e.g. 'dtoc_test_simple.dts]
+
+    Returns:
+        str: Path to the test filename
+    """
+    return os.path.join('tools/dtoc/test', dts_fname)
+
 
 class TestFdt(unittest.TestCase):
     """Tests for the Fdt module
@@ -64,7 +75,7 @@ class TestFdt(unittest.TestCase):
         tools.FinaliseOutputDir()
 
     def setUp(self):
-        self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts')
+        self.dtb = fdt.FdtScan(find_dtb_file('dtoc_test_simple.dts'))
 
     def testFdt(self):
         """Test that we can open an Fdt"""
@@ -141,7 +152,7 @@ class TestNode(unittest.TestCase):
         tools.FinaliseOutputDir()
 
     def setUp(self):
-        self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts')
+        self.dtb = fdt.FdtScan(find_dtb_file('dtoc_test_simple.dts'))
         self.node = self.dtb.GetNode('/spl-test')
 
     def testOffset(self):
@@ -203,7 +214,7 @@ class TestNode(unittest.TestCase):
 
     def testLookupPhandle(self):
         """Test looking up a single phandle"""
-        dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
+        dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts'))
         node = dtb.GetNode('/phandle-source2')
         prop = node.props['clocks']
         target = dtb.GetNode('/phandle-target')
@@ -222,7 +233,7 @@ class TestProp(unittest.TestCase):
         tools.FinaliseOutputDir()
 
     def setUp(self):
-        self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts')
+        self.dtb = fdt.FdtScan(find_dtb_file('dtoc_test_simple.dts'))
         self.node = self.dtb.GetNode('/spl-test')
         self.fdt = self.dtb.GetFdtObj()
 
@@ -230,7 +241,7 @@ class TestProp(unittest.TestCase):
         self.assertEqual(None, self.dtb.GetNode('missing'))
 
     def testPhandle(self):
-        dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
+        dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts'))
         node = dtb.GetNode('/phandle-source2')
         prop = node.props['clocks']
         self.assertTrue(fdt32_to_cpu(prop.value) > 0)
@@ -482,7 +493,7 @@ class TestFdtUtil(unittest.TestCase):
         tools.FinaliseOutputDir()
 
     def setUp(self):
-        self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts')
+        self.dtb = fdt.FdtScan(find_dtb_file('dtoc_test_simple.dts'))
         self.node = self.dtb.GetNode('/spl-test')
 
     def testGetInt(self):
@@ -525,7 +536,7 @@ class TestFdtUtil(unittest.TestCase):
                       str(e.exception))
 
     def testGetPhandleList(self):
-        dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
+        dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts'))
         node = dtb.GetNode('/phandle-source2')
         self.assertEqual([1], fdt_util.GetPhandleList(node, 'clocks'))
         node = dtb.GetNode('/phandle-source')
@@ -545,7 +556,7 @@ class TestFdtUtil(unittest.TestCase):
         self.assertEqual(0, fdt_util.fdt_cells_to_cpu(val, 0))
         self.assertEqual(2, fdt_util.fdt_cells_to_cpu(val, 1))
 
-        dtb2 = fdt.FdtScan('tools/dtoc/dtoc_test_addr64.dts')
+        dtb2 = fdt.FdtScan(find_dtb_file('dtoc_test_addr64.dts'))
         node1 = dtb2.GetNode('/test1')
         val = node1.props['reg'].value
         self.assertEqual(0x1234, fdt_util.fdt_cells_to_cpu(val, 2))
@@ -559,7 +570,7 @@ class TestFdtUtil(unittest.TestCase):
 
     def testEnsureCompiled(self):
         """Test a degenerate case of this function (file already compiled)"""
-        dtb = fdt_util.EnsureCompiled('tools/dtoc/dtoc_test_simple.dts')
+        dtb = fdt_util.EnsureCompiled(find_dtb_file('dtoc_test_simple.dts'))
         self.assertEqual(dtb, fdt_util.EnsureCompiled(dtb))
 
     def testEnsureCompiledTmpdir(self):
@@ -568,7 +579,7 @@ class TestFdtUtil(unittest.TestCase):
             old_outdir = tools.outdir
             tools.outdir= None
             tmpdir = tempfile.mkdtemp(prefix='test_fdt.')
-            dtb = fdt_util.EnsureCompiled('tools/dtoc/dtoc_test_simple.dts',
+            dtb = fdt_util.EnsureCompiled(find_dtb_file('dtoc_test_simple.dts'),
                                           tmpdir)
             self.assertEqual(tmpdir, os.path.dirname(dtb))
             shutil.rmtree(tmpdir)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index a0b0e097eb2..a7eba3005e5 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -59,7 +59,8 @@ class TestSrcScan(unittest.TestCase):
     def test_additional(self):
         """Test with additional drivers to scan"""
         scan = src_scan.Scanner(
-            None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+            None, True,
+            [None, '', 'tools/dtoc/test/dtoc_test_scan_drivers.cxx'])
         scan.scan_drivers()
         self.assertIn('sandbox_gpio_alias2', scan._driver_aliases)
         self.assertEqual('sandbox_gpio',
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 30/49] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (28 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 29/49] dtoc: Move test files into a test/ directory Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 31/49] dtoc: Add some extra properties to nodes Simon Glass
                   ` (38 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

These have '_test' suffixes which are not present on the drivers in the
source code. Drop the suffixes to avoid a mismatch when scanning.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test/dtoc_test_simple.dts |  4 ++--
 tools/dtoc/test_dtoc.py              | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts
index 1c87b891929..d8ab8613ee3 100644
--- a/tools/dtoc/test/dtoc_test_simple.dts
+++ b/tools/dtoc/test/dtoc_test_simple.dts
@@ -45,12 +45,12 @@
 	};
 
 	i2c at 0 {
-		compatible = "sandbox,i2c-test";
+		compatible = "sandbox,i2c";
 		u-boot,dm-pre-reloc;
 		#address-cells = <1>;
 		#size-cells = <0>;
 		pmic at 9 {
-			compatible = "sandbox,pmic-test";
+			compatible = "sandbox,pmic";
 			u-boot,dm-pre-reloc;
 			reg = <9>;
 			low-power;
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 523f0a923eb..9049c2895f1 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -207,9 +207,9 @@ class TestDtoc(unittest.TestCase):
         self.assertEqual(C_HEADER.splitlines() + [''], lines)
 
     struct_text = HEADER + '''
-struct dtd_sandbox_i2c_test {
+struct dtd_sandbox_i2c {
 };
-struct dtd_sandbox_pmic_test {
+struct dtd_sandbox_pmic {
 \tbool\t\tlow_power;
 \tfdt64_t\t\treg[2];
 };
@@ -229,22 +229,22 @@ struct dtd_sandbox_spl_test {
 
     platdata_text = C_HEADER + '''
 /* Node /i2c at 0 index 0 */
-static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
+static struct dtd_sandbox_i2c dtv_i2c_at_0 = {
 };
 U_BOOT_DRVINFO(i2c_at_0) = {
-\t.name\t\t= "sandbox_i2c_test",
+\t.name\t\t= "sandbox_i2c",
 \t.plat\t= &dtv_i2c_at_0,
 \t.plat_size\t= sizeof(dtv_i2c_at_0),
 \t.parent_idx\t= -1,
 };
 
 /* Node /i2c at 0/pmic at 9 index 1 */
-static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
+static struct dtd_sandbox_pmic dtv_pmic_at_9 = {
 \t.low_power\t\t= true,
 \t.reg\t\t\t= {0x9, 0x0},
 };
 U_BOOT_DRVINFO(pmic_at_9) = {
-\t.name\t\t= "sandbox_pmic_test",
+\t.name\t\t= "sandbox_pmic",
 \t.plat\t= &dtv_pmic_at_9,
 \t.plat_size\t= sizeof(dtv_pmic_at_9),
 \t.parent_idx\t= 0,
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 31/49] dtoc: Add some extra properties to nodes
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (29 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 30/49] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 32/49] dtoc: Make use of node properties Simon Glass
                   ` (37 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

It is convenient to attach drivers, etc. to nodes so that we can use the
Node object as the main data structure in this module.

Add a function which adds the new properties, along with documentation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index e9be5985c72..8c36fbc68d2 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -354,8 +354,44 @@ class DtbPlatdata():
         self.scan_node(self._fdt.GetRoot(), valid_nodes)
         self._valid_nodes = sorted(valid_nodes,
                                    key=lambda x: conv_name_to_c(x.name))
+
+    def prepare_nodes(self):
+        """Add extra properties to the nodes we are using
+
+        The following properties are added for use by dtoc:
+            idx: Index number of this node (0=first, etc.)
+            struct_name: Name of the struct dtd used by this node
+            var_name: C name for this node
+            child_devs: List of child devices for this node, each a None
+            child_refs: Dict of references for each child:
+                key: Position in child list (-1=head, 0=first, 1=second, ...
+                                             n-1=last, n=head)
+            seq: Sequence number of the device (unique within its uclass), or
+                -1 not not known yet
+            dev_ref: Reference to this device, e.g. 'DM_DEVICE_REF(serial)'
+            driver: Driver record for this node, or None if not known
+            uclass: Uclass record for this node, or None if not known
+            uclass_seq: Position of this device within the uclass list (0=first,
+                n-1=last)
+            parent_seq: Position of this device within it siblings (0=first,
+                n-1=last)
+            parent_driver: Driver record of the node's parent, or None if none.
+                We don't use node.parent.driver since node.parent may not be in
+                the list of valid nodes
+        """
         for idx, node in enumerate(self._valid_nodes):
             node.idx = idx
+            node.struct_name, _ = self._scan.get_normalized_compat_name(node)
+            node.var_name = conv_name_to_c(node.name)
+            node.child_devs = []
+            node.child_refs = {}
+            node.seq = -1
+            node.dev_ref = None
+            node.driver = None
+            node.uclass = None
+            node.uclass_seq = None
+            node.parent_seq = None
+            node.parent_driver = None
 
     @staticmethod
     def get_num_cells(node):
@@ -705,6 +741,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     plat = DtbPlatdata(scan, dtb_file, include_disabled)
     plat.scan_dtb()
     plat.scan_tree()
+    plat.prepare_nodes()
     plat.scan_reg_sizes()
     plat.setup_output_dirs(output_dirs)
     plat.scan_structs()
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 32/49] dtoc: Make use of node properties
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (30 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 31/49] dtoc: Add some extra properties to nodes Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 33/49] dtoc: Process nodes to set up required properties Simon Glass
                   ` (36 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Now that we have these available, use them instead of recalculating
things each time.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 45 ++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 8c36fbc68d2..2ec22edfbf0 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -470,7 +470,6 @@ class DtbPlatdata():
         """
         structs = self._struct_data
         for node in self._valid_nodes:
-            node_name, _ = self._scan.get_normalized_compat_name(node)
             fields = {}
 
             # Get a list of all the valid properties in this node.
@@ -478,9 +477,9 @@ class DtbPlatdata():
                 if name not in PROP_IGNORE_LIST and name[0] != '#':
                     fields[name] = copy.deepcopy(prop)
 
-            # If we've seen this node_name before, update the existing struct.
-            if node_name in structs:
-                struct = structs[node_name]
+            # If we've seen this struct_name before, update the existing struct
+            if node.struct_name in structs:
+                struct = structs[node.struct_name]
                 for name, prop in fields.items():
                     oldprop = struct.get(name)
                     if oldprop:
@@ -490,11 +489,10 @@ class DtbPlatdata():
 
             # Otherwise store this as a new struct.
             else:
-                structs[node_name] = fields
+                structs[node.struct_name] = fields
 
         for node in self._valid_nodes:
-            node_name, _ = self._scan.get_normalized_compat_name(node)
-            struct = structs[node_name]
+            struct = structs[node.struct_name]
             for name, prop in node.props.items():
                 if name not in PROP_IGNORE_LIST and name[0] != '#':
                     prop.Widen(struct[name])
@@ -598,23 +596,22 @@ class DtbPlatdata():
                 self.buf(', '.join(vals[i:i + 8]))
         self.buf('}')
 
-    def _declare_device(self, var_name, struct_name, node_parent):
+    def _declare_device(self, node):
         """Add a device declaration to the output
 
         This declares a U_BOOT_DRVINFO() for the device being processed
 
         Args:
-            var_name (str): C name for the node
-            struct_name (str): Name for the dt struct associated with the node
-            node_parent (Node): Parent of the node (or None if none)
+            node: Node to process
         """
-        self.buf('U_BOOT_DRVINFO(%s) = {\n' % var_name)
-        self.buf('\t.name\t\t= "%s",\n' % struct_name)
-        self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
-        self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
+        self.buf('U_BOOT_DRVINFO(%s) = {\n' % node.var_name)
+        self.buf('\t.name\t\t= "%s",\n' % node.struct_name)
+        self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, node.var_name))
+        self.buf('\t.plat_size\t= sizeof(%s%s),\n' %
+                 (VAL_PREFIX, node.var_name))
         idx = -1
-        if node_parent and node_parent in self._valid_nodes:
-            idx = node_parent.idx
+        if node.parent and node.parent in self._valid_nodes:
+            idx = node.parent.idx
         self.buf('\t.parent_idx\t= %d,\n' % idx)
         self.buf('};\n')
         self.buf('\n')
@@ -638,16 +635,14 @@ class DtbPlatdata():
             self.buf(get_value(prop.type, prop.value))
         self.buf(',\n')
 
-    def _output_values(self, var_name, struct_name, node):
+    def _output_values(self, node):
         """Output the definition of a device's struct values
 
         Args:
-            var_name (str): C name for the node
-            struct_name (str): Name for the dt struct associated with the node
-            node (Node): Node being output
+            node (Node): Node to output
         """
         self.buf('static struct %s%s %s%s = {\n' %
-                 (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
+                 (STRUCT_PREFIX, node.struct_name, VAL_PREFIX, node.var_name))
         for pname in sorted(node.props):
             self._output_prop(node, node.props[pname])
         self.buf('};\n')
@@ -658,12 +653,10 @@ class DtbPlatdata():
         Args:
             node (fdt.Node): node to output
         """
-        struct_name, _ = self._scan.get_normalized_compat_name(node)
-        var_name = conv_name_to_c(node.name)
         self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
 
-        self._output_values(var_name, struct_name, node)
-        self._declare_device(var_name, struct_name, node.parent)
+        self._output_values(node)
+        self._declare_device(node)
 
         self.out(''.join(self.get_buf()))
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 33/49] dtoc: Process nodes to set up required properties
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (31 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 32/49] dtoc: Make use of node properties Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 34/49] dtoc: Track nodes which are actually used Simon Glass
                   ` (35 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add logic to assign property values to nodes as required by dtoc. The
references allow nodes to refer to each other in C code. The macros used
by dtoc are not yet defined in driver model. They will be added along
with the actual driver model implementation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 37 +++++++++++++++++++
 tools/dtoc/src_scan.py     | 11 ++++++
 tools/dtoc/test_dtoc.py    | 76 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 2ec22edfbf0..ad71f703e52 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -647,6 +647,38 @@ class DtbPlatdata():
             self._output_prop(node, node.props[pname])
         self.buf('};\n')
 
+    def process_nodes(self, need_drivers):
+        nodes_to_output = list(self._valid_nodes)
+
+        for node in nodes_to_output:
+            node.dev_ref = 'DM_DEVICE_REF(%s)' % node.var_name
+            driver = self._scan.get_driver(node.struct_name)
+            if not driver:
+                if not need_drivers:
+                    continue
+                raise ValueError("Cannot parse/find driver for '%s'" %
+                                 node.struct_name)
+            node.driver = driver
+            parent_driver = None
+            if node.parent in self._valid_nodes:
+                parent_driver = self._scan.get_driver(node.parent.struct_name)
+                if not parent_driver:
+                    if not need_drivers:
+                        continue
+                    raise ValueError(
+                        "Cannot parse/find parent driver '%s' for '%s'" %
+                        (node.parent.struct_name, node.struct_name))
+                node.parent_seq = len(node.parent.child_devs)
+                node.parent.child_devs.append(node)
+                node.parent.child_refs[node.parent_seq] = \
+                    '&%s->sibling_node' % node.dev_ref
+                node.parent_driver = parent_driver
+
+        for node in nodes_to_output:
+            ref = '&%s->child_head' % node.dev_ref
+            node.child_refs[-1] = ref
+            node.child_refs[len(node.child_devs)] = ref
+
     def output_node(self, node):
         """Output the C code for a node
 
@@ -731,6 +763,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     if not scan:
         scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
         scan.scan_drivers()
+        do_process = True
+    else:
+        do_process = False
     plat = DtbPlatdata(scan, dtb_file, include_disabled)
     plat.scan_dtb()
     plat.scan_tree()
@@ -739,6 +774,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
     plat.setup_output_dirs(output_dirs)
     plat.scan_structs()
     plat.scan_phandles()
+    if do_process:
+        plat.process_nodes(False)
 
     cmds = args[0].split(',')
     if 'all' in cmds:
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index bf3e5de9b1e..504dac008d6 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -188,6 +188,17 @@ class Scanner:
         self._uclass = {}
         self._structs = {}
 
+    def get_driver(self, name):
+        """Get a driver given its name
+
+        Args:
+            name (str): Driver name
+
+        Returns:
+            Driver: Driver or None if not found
+        """
+        return self._drivers.get(name)
+
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
 
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 9049c2895f1..3e98e363125 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -953,3 +953,79 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertEqual(
             {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
             leafs)
+
+    def setup_process_test(self):
+        """Set up a test of process_nodes()
+
+        This uses saved_scan but returns a deep copy of it, so it is safe to
+        modify it in these tests
+
+        Returns:
+            tuple:
+                DtbPlatdata: object to test
+                Scanner: scanner to use
+        """
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        output = tools.GetOutputFilename('output')
+
+        # Take a copy before messing with it
+        scan = copy.deepcopy(saved_scan)
+        plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False)
+        plat.scan_dtb()
+        plat.scan_tree()
+        plat.prepare_nodes()
+        return plat, scan
+
+    def test_process_nodes(self):
+        """Test processing nodes to add various info"""
+        plat, scan = self.setup_process_test()
+        plat.process_nodes(True)
+
+        i2c_node = plat._fdt.GetNode('/i2c at 0')
+        pmic_node = plat._fdt.GetNode('/i2c at 0/pmic at 9')
+        pmic = scan._drivers['sandbox_pmic']
+        i2c = scan._drivers['sandbox_i2c']
+        self.assertEqual('DM_DEVICE_REF(pmic_at_9)', pmic_node.dev_ref)
+        self.assertEqual(pmic, pmic_node.driver)
+        self.assertEqual(i2c_node, pmic_node.parent)
+        self.assertEqual(i2c, pmic_node.parent_driver)
+
+        # The pmic is the only child
+        self.assertEqual(pmic_node.parent_seq, 0)
+        self.assertEqual([pmic_node], i2c_node.child_devs)
+
+        # Start and end of the list should be the child_head
+        ref = '&DM_DEVICE_REF(i2c_at_0)->child_head'
+        self.assertEqual(
+            {-1: ref, 0: '&DM_DEVICE_REF(pmic_at_9)->sibling_node', 1: ref},
+            i2c_node.child_refs)
+
+    def test_process_nodes_bad_parent(self):
+        # Pretend that i2c has a parent (the pmic) and delete that driver
+        plat, scan = self.setup_process_test()
+
+        i2c_node = plat._fdt.GetNode('/i2c at 0')
+        pmic_node = plat._fdt.GetNode('/i2c at 0/pmic at 9')
+        del scan._drivers['sandbox_pmic']
+        i2c_node.parent = pmic_node
+
+        # Process twice, the second time to generate an exception
+        plat.process_nodes(False)
+        with self.assertRaises(ValueError) as exc:
+            plat.process_nodes(True)
+        self.assertIn(
+            "Cannot parse/find parent driver 'sandbox_pmic' for 'sandbox_i2c",
+            str(exc.exception))
+
+    def test_process_nodes_bad_node(self):
+        plat, scan = self.setup_process_test()
+
+        # Now remove the pmic driver
+        del scan._drivers['sandbox_pmic']
+
+        # Process twice, the second time to generate an exception
+        plat.process_nodes(False)
+        with self.assertRaises(ValueError) as exc:
+            plat.process_nodes(True)
+        self.assertIn("Cannot parse/find driver for 'sandbox_pmic",
+                      str(exc.exception))
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 34/49] dtoc: Track nodes which are actually used
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (32 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 33/49] dtoc: Process nodes to set up required properties Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 35/49] dtoc: Support tracking the phase of U-Boot Simon Glass
                   ` (34 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Mark all nodes that are actually used, so we can perform extra checks on
them.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py  |  3 +++
 tools/dtoc/src_scan.py      | 25 ++++++++++++++++++++++---
 tools/dtoc/test_dtoc.py     | 11 +++++++++++
 tools/dtoc/test_src_scan.py |  2 +-
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index ad71f703e52..28669f31217 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -650,6 +650,9 @@ class DtbPlatdata():
     def process_nodes(self, need_drivers):
         nodes_to_output = list(self._valid_nodes)
 
+        # Figure out which drivers we actually use
+        self._scan.mark_used(nodes_to_output)
+
         for node in nodes_to_output:
             node.dev_ref = 'DM_DEVICE_REF(%s)' % node.var_name
             driver = self._scan.get_driver(node.struct_name)
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 504dac008d6..1a02d41063f 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -66,6 +66,7 @@ class Driver:
             e.g. 'pci_child_priv'
         child_plat (str): struct name of the per_child_plat_auto member,
             e.g. 'pci_child_plat'
+        used (bool): True if the driver is used by the structs being output
     """
     def __init__(self, name, fname):
         self.name = name
@@ -76,17 +77,19 @@ class Driver:
         self.plat = ''
         self.child_priv = ''
         self.child_plat = ''
+        self.used = False
 
     def __eq__(self, other):
         return (self.name == other.name and
                 self.uclass_id == other.uclass_id and
                 self.compat == other.compat and
                 self.priv == other.priv and
-                self.plat == other.plat)
+                self.plat == other.plat and
+                self.used == other.used)
 
     def __repr__(self):
-        return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
-                (self.name, self.uclass_id, self.compat, self.priv))
+        return ("Driver(name='%s', used=%s, uclass_id='%s', compat=%s, priv=%s)" %
+                (self.name, self.used, self.uclass_id, self.compat, self.priv))
 
 
 class UclassDriver:
@@ -596,3 +599,19 @@ class Scanner:
                 self.scan_driver(fname)
             else:
                 self.scan_driver(self._basedir + '/' + fname)
+
+    def mark_used(self, nodes):
+        """Mark the drivers associated with a list of nodes as 'used'
+
+        This takes a list of nodes, finds the driver for each one and marks it
+        as used.
+
+        Args:
+            nodes (list of None): Nodes that are in use
+        """
+        # Figure out which drivers we actually use
+        for node in nodes:
+            struct_name, _ = self.get_normalized_compat_name(node)
+            driver = self._drivers.get(struct_name)
+            if driver:
+                driver.used = True
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 3e98e363125..d90ece205d7 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -1029,3 +1029,14 @@ U_BOOT_DRVINFO(spl_test2) = {
             plat.process_nodes(True)
         self.assertIn("Cannot parse/find driver for 'sandbox_pmic",
                       str(exc.exception))
+
+    def test_process_nodes_used(self):
+        """Test processing nodes to add various info"""
+        plat, scan = self.setup_process_test()
+        plat.process_nodes(True)
+
+        pmic = scan._drivers['sandbox_pmic']
+        self.assertTrue(pmic.used)
+
+        gpio = scan._drivers['sandbox_gpio']
+        self.assertFalse(gpio.used)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index a7eba3005e5..ebdc12abc87 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -98,7 +98,7 @@ class TestSrcScan(unittest.TestCase):
         drv3.uclass_id = i2c
         drv3.compat = compat
         self.assertEqual(
-            "Driver(name='fred', uclass_id='I2C_UCLASS', "
+            "Driver(name='fred', used=False, uclass_id='I2C_UCLASS', "
             "compat={'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF', "
             "'rockchip,rk3288-srf': None}, priv=)", str(drv1))
         self.assertEqual(drv1, drv3)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 35/49] dtoc: Support tracking the phase of U-Boot
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (33 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 34/49] dtoc: Track nodes which are actually used Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 36/49] Makefile: Pass the U-Boot phase to dtoc Simon Glass
                   ` (33 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

U-Boot operates in several phases, typically TPL, SPL and U-Boot proper.
The latter does not use dtoc.

In some rare cases different drivers are used for two phases. For example,
in TPL it may not be necessary to use the full PCI subsystem, so a simple
driver can be used instead.

This works in the build system simply by compiling in one driver or the
other (e.g. PCI driver + uclass for SPL; simple_bus for TPL). But dtoc has
no way of knowing which code is compiled in for which phase, since it does
not inspect Makefiles or dependency graphs.

So to make this work for dtoc, we need to be able to explicitly mark
drivers with their phase. This is done by adding an empty macro to the
driver. Add support for this in dtoc.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/device.h         | 16 ++++++++++++++++
 tools/dtoc/dtb_platdata.py  |  7 +++++--
 tools/dtoc/main.py          |  5 ++++-
 tools/dtoc/src_scan.py      | 12 +++++++++++-
 tools/dtoc/test_dtoc.py     | 16 ++++++++--------
 tools/dtoc/test_src_scan.py |  3 +++
 6 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/include/dm/device.h b/include/dm/device.h
index f5b4cd6876e..51b550d8ed2 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -345,6 +345,22 @@ struct driver {
  */
 #define DM_DRIVER_ALIAS(__name, __alias)
 
+/**
+ * Declare a macro to indicate which phase of U-Boot this driver is fore.
+ *
+ *
+ * This macro produces no code but its information will be parsed by dtoc. The
+ * macro can be only be used once in a driver. Put it within the U_BOOT_DRIVER()
+ * declaration, e.g.:
+ *
+ * U_BOOT_DRIVER(cpu) = {
+ *	.name = ...
+ *	...
+ *	DM_PHASE(tpl)
+ * };
+ */
+#define DM_PHASE(_phase)
+
 /**
  * dev_get_plat() - Get the platform data for a device
  *
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 28669f31217..ef0454c8904 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -733,7 +733,7 @@ OUTPUT_FILES = {
     }
 
 
-def run_steps(args, dtb_file, include_disabled, output, output_dirs,
+def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
               warning_disabled=False, drivers_additional=None, basedir=None,
               scan=None):
     """Run all the steps of the dtoc tool
@@ -746,6 +746,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
         output_dirs (tuple of str):
             Directory to put C output files
             Directory to put H output files
+        phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
+             or 'tpl'. None if not known
         warning_disabled (bool): True to avoid showing warnings about missing
             drivers
         drivers_additional (list): List of additional drivers to use during
@@ -764,7 +766,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
         raise ValueError('Must specify either output or output_dirs, not both')
 
     if not scan:
-        scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
+        scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional,
+                                phase)
         scan.scan_drivers()
         do_process = True
     else:
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 355b1e62773..15a8ff167a9 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -85,6 +85,8 @@ parser.add_option('--include-disabled', action='store_true',
                   help='Include disabled nodes')
 parser.add_option('-o', '--output', action='store',
                   help='Select output filename')
+parser.add_option('-p', '--phase', type=str,
+                  help='set phase of U-Boot this invocation is for (spl/tpl)')
 parser.add_option('-P', '--processes', type=int,
                   help='set number of processes to use for running tests')
 parser.add_option('-t', '--test', action='store_true', dest='test',
@@ -104,4 +106,5 @@ elif options.test_coverage:
 else:
     dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
                            options.output,
-                           [options.c_output_dir, options.h_output_dir])
+                           [options.c_output_dir, options.h_output_dir],
+                           phase=options.phase)
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 1a02d41063f..2699153016c 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -67,6 +67,7 @@ class Driver:
         child_plat (str): struct name of the per_child_plat_auto member,
             e.g. 'pci_child_plat'
         used (bool): True if the driver is used by the structs being output
+        phase (str): Which phase of U-Boot to use this driver
     """
     def __init__(self, name, fname):
         self.name = name
@@ -78,6 +79,7 @@ class Driver:
         self.child_priv = ''
         self.child_plat = ''
         self.used = False
+        self.phase = ''
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -173,8 +175,10 @@ class Scanner:
         _structs: Dict of all structs found in U-Boot:
             key: Name of struct
             value: Struct object
+        _phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
+             or 'tpl'. None if not known
     """
-    def __init__(self, basedir, warning_disabled, drivers_additional):
+    def __init__(self, basedir, warning_disabled, drivers_additional, phase=''):
         """Set up a new Scanner
         """
         if not basedir:
@@ -190,6 +194,7 @@ class Scanner:
         self._compat_to_driver = {}
         self._uclass = {}
         self._structs = {}
+        self._phase = phase
 
     def get_driver(self, name):
         """Get a driver given its name
@@ -428,6 +433,8 @@ class Scanner:
         re_of_match = re.compile(
             r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
 
+        re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
+
         # Matches the struct name for priv, plat
         re_priv = self._get_re_for_member('priv_auto')
         re_plat = self._get_re_for_member('plat_auto')
@@ -454,6 +461,7 @@ class Scanner:
                 m_plat = re_plat.match(line)
                 m_cplat = re_child_plat.match(line)
                 m_cpriv = re_child_priv.match(line)
+                m_phase = re_phase.match(line)
                 if m_priv:
                     driver.priv = m_priv.group(1)
                 elif m_plat:
@@ -466,6 +474,8 @@ class Scanner:
                     driver.uclass_id = m_id.group(1)
                 elif m_of_match:
                     compat = m_of_match.group(2)
+                elif m_phase:
+                    driver.phase = m_phase.group(1)
                 elif '};' in line:
                     if driver.uclass_id and compat:
                         if compat not in of_match:
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index d90ece205d7..c1fafb656fb 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -138,8 +138,8 @@ class TestDtoc(unittest.TestCase):
             dtb_file (str): Filename of .dtb file
             output (str): Filename of output file
         """
-        dtb_platdata.run_steps(args, dtb_file, False, output, [], True,
-                               None, None, scan=copy_scan())
+        dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
+                               warning_disabled=True, scan=copy_scan())
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -365,7 +365,7 @@ U_BOOT_DRVINFO(gpios_at_0) = {
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
-                                   scan=copy_scan())
+                                   None, scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(HEADER + '''
@@ -375,7 +375,7 @@ struct dtd_invalid {
 
         with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [],
-                                   scan=copy_scan())
+                                   None, scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -927,8 +927,8 @@ U_BOOT_DRVINFO(spl_test2) = {
     def test_output_conflict(self):
         """Test a conflict between and output dirs and output file"""
         with self.assertRaises(ValueError) as exc:
-            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True,
-                                   scan=copy_scan())
+            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], None,
+                                   warning_disabled=True, scan=copy_scan())
         self.assertIn("Must specify either output or output_dirs, not both",
                       str(exc.exception))
 
@@ -944,8 +944,8 @@ U_BOOT_DRVINFO(spl_test2) = {
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(2, len(fnames))
 
-        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True,
-                               scan=copy_scan())
+        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], None,
+                               warning_disabled=True, scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(4, len(fnames))
 
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index ebdc12abc87..8d35b33c28a 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -233,6 +233,7 @@ U_BOOT_DRIVER(i2c_tegra) = {
         self.assertIn('i2c_tegra', scan._drivers)
         drv = scan._drivers['i2c_tegra']
         self.assertEqual('i2c_tegra', drv.name)
+        self.assertEqual('', drv.phase)
 
     def test_priv(self):
         """Test collection of struct info from drivers"""
@@ -250,6 +251,7 @@ U_BOOT_DRIVER(testing) = {
 	.plat_auto = sizeof(struct some_plat),
 	.per_child_auto	= sizeof(struct some_cpriv),
 	.per_child_plat_auto = sizeof(struct some_cplat),
+	DM_PHASE(tpl)
 };
 '''
         scan = src_scan.Scanner(None, False, None)
@@ -264,6 +266,7 @@ U_BOOT_DRIVER(testing) = {
         self.assertEqual('some_plat', drv.plat)
         self.assertEqual('some_cpriv', drv.child_priv)
         self.assertEqual('some_cplat', drv.child_plat)
+        self.assertEqual('tpl', drv.phase)
         self.assertEqual(1, len(scan._drivers))
 
     def test_uclass_scan(self):
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 36/49] Makefile: Pass the U-Boot phase to dtoc
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (34 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 35/49] dtoc: Support tracking the phase of U-Boot Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 37/49] dtoc: Support headers needed for drivers Simon Glass
                   ` (32 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Pass the U-Boot phase as a parameter so dtoc can use it. At present it is
ether "spl" or "tpl".

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 scripts/Makefile.spl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 87021e22e55..72c0ad82793 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -309,7 +309,7 @@ $(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE
 pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 
 DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
-	-d $(obj)/$(SPL_BIN).dtb
+	-d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
 
 quiet_cmd_dtoc = DTOC    $@
 cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 37/49] dtoc: Support headers needed for drivers
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (35 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 36/49] Makefile: Pass the U-Boot phase to dtoc Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 38/49] dtoc: Process driver aliases along with drivers Simon Glass
                   ` (31 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Typically dtoc can detect the header file needed for a driver by looking
for the structs that it uses. For example, if a driver as a .priv_auto
that uses 'struct serial_priv', then dtoc can search header files for the
definition of that struct and use the file.

In some cases, enums are used in drivers, typically with the .data field
of struct udevice_id. Since dtoc does not support searching for these,
add a way to tell dtoc which header to use. This works as a macro included
in the driver definition.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/device.h         | 18 ++++++++++++++++++
 tools/dtoc/src_scan.py      |  7 +++++++
 tools/dtoc/test_src_scan.py |  4 ++++
 3 files changed, 29 insertions(+)

diff --git a/include/dm/device.h b/include/dm/device.h
index 51b550d8ed2..e08a11c4a18 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -361,6 +361,24 @@ struct driver {
  */
 #define DM_PHASE(_phase)
 
+/**
+ * Declare a macro to declare a header needed for a driver. Often the correct
+ * header can be found automatically, but only for struct declarations. For
+ * enums and #defines used in the driver declaration and declared in a different
+ * header from the structs, this macro must be used.
+ *
+ * This macro produces no code but its information will be parsed by dtoc. The
+ * macro can be used multiple times with different headers, for the same driver.
+ * Put it within the U_BOOT_DRIVER() declaration, e.g.:
+ *
+ * U_BOOT_DRIVER(cpu) = {
+ *	.name = ...
+ *	...
+ *	DM_HEADER(<asm/cpu.h>)
+ * };
+ */
+#define DM_HEADER(_hdr)
+
 /**
  * dev_get_plat() - Get the platform data for a device
  *
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 2699153016c..206b2b37583 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -68,6 +68,8 @@ class Driver:
             e.g. 'pci_child_plat'
         used (bool): True if the driver is used by the structs being output
         phase (str): Which phase of U-Boot to use this driver
+        headers (list): List of header files needed for this driver (each a str)
+            e.g. ['<asm/cpu.h>']
     """
     def __init__(self, name, fname):
         self.name = name
@@ -80,6 +82,7 @@ class Driver:
         self.child_plat = ''
         self.used = False
         self.phase = ''
+        self.headers = []
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -434,6 +437,7 @@ class Scanner:
             r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
 
         re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
+        re_hdr = re.compile('^\s*DM_HEADER\((.*)\).*$')
 
         # Matches the struct name for priv, plat
         re_priv = self._get_re_for_member('priv_auto')
@@ -462,6 +466,7 @@ class Scanner:
                 m_cplat = re_child_plat.match(line)
                 m_cpriv = re_child_priv.match(line)
                 m_phase = re_phase.match(line)
+                m_hdr = re_hdr.match(line)
                 if m_priv:
                     driver.priv = m_priv.group(1)
                 elif m_plat:
@@ -476,6 +481,8 @@ class Scanner:
                     compat = m_of_match.group(2)
                 elif m_phase:
                     driver.phase = m_phase.group(1)
+                elif m_hdr:
+                    driver.headers.append(m_hdr.group(1))
                 elif '};' in line:
                     if driver.uclass_id and compat:
                         if compat not in of_match:
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 8d35b33c28a..245b7302fd6 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -234,6 +234,7 @@ U_BOOT_DRIVER(i2c_tegra) = {
         drv = scan._drivers['i2c_tegra']
         self.assertEqual('i2c_tegra', drv.name)
         self.assertEqual('', drv.phase)
+        self.assertEqual([], drv.headers)
 
     def test_priv(self):
         """Test collection of struct info from drivers"""
@@ -252,6 +253,8 @@ U_BOOT_DRIVER(testing) = {
 	.per_child_auto	= sizeof(struct some_cpriv),
 	.per_child_plat_auto = sizeof(struct some_cplat),
 	DM_PHASE(tpl)
+	DM_HEADER(<i2c.h>)
+	DM_HEADER(<asm/clk.h>)
 };
 '''
         scan = src_scan.Scanner(None, False, None)
@@ -267,6 +270,7 @@ U_BOOT_DRIVER(testing) = {
         self.assertEqual('some_cpriv', drv.child_priv)
         self.assertEqual('some_cplat', drv.child_plat)
         self.assertEqual('tpl', drv.phase)
+        self.assertEqual(['<i2c.h>', '<asm/clk.h>'], drv.headers)
         self.assertEqual(1, len(scan._drivers))
 
     def test_uclass_scan(self):
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 38/49] dtoc: Process driver aliases along with drivers
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (36 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 37/49] dtoc: Support headers needed for drivers Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 39/49] dtoc: Warn of duplicate drivers Simon Glass
                   ` (30 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Instead of using a separate step for this processing, handle it while
scanning its associated driver. This allows us to drop the code coverage
exception in this case.

Note that only files containing drivers are scanned by dtoc, so aliases
declared in a file that doesn't hold a driver will not be noticed. It
would be confusing to put them anywhere other than in the driver that they
relate to, but update the documentation to say this explicitly, just in
case.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst               |  3 ++-
 tools/dtoc/src_scan.py                     | 16 +++++-----------
 tools/dtoc/test/dtoc_test_scan_drivers.cxx |  4 ++++
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
index 4ef2fe699a4..a5a6e46e3ec 100644
--- a/doc/driver-model/of-plat.rst
+++ b/doc/driver-model/of-plat.rst
@@ -183,7 +183,8 @@ each 'compatible' string.
 
 In order to make this a bit more flexible DM_DRIVER_ALIAS macro can be
 used to declare an alias for a driver name, typically a 'compatible' string.
-This macro produces no code, but it is by dtoc tool.
+This macro produces no code, but it is by dtoc tool. It must be located in the
+same file as its associated driver, ideally just after it.
 
 The parent_idx is the index of the parent driver_info structure within its
 linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 206b2b37583..9d161a2cbc7 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -387,6 +387,7 @@ class Scanner:
                 in the file
             _of_match - updated with each compatible string found in the file
             _compat_to_driver - Maps compatible string to Driver
+            _driver_aliases - Maps alias names to driver name
 
         Args:
             fname (str): Filename being parsed (used for warnings)
@@ -438,6 +439,7 @@ class Scanner:
 
         re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
         re_hdr = re.compile('^\s*DM_HEADER\((.*)\).*$')
+        re_alias = re.compile(r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)')
 
         # Matches the struct name for priv, plat
         re_priv = self._get_re_for_member('priv_auto')
@@ -522,8 +524,11 @@ class Scanner:
                 driver = Driver(driver_name, fname)
             else:
                 ids_m = re_ids.search(line)
+                m_alias = re_alias.match(line)
                 if ids_m:
                     ids_name = ids_m.group(1)
+                elif m_alias:
+                    self._driver_aliases[m_alias[2]] = m_alias[1]
 
         # Make the updates based on what we found
         self._drivers.update(drivers)
@@ -557,17 +562,6 @@ class Scanner:
             if 'UCLASS_DRIVER' in buff:
                 self._parse_uclass_driver(fname, buff)
 
-            # The following re will search for driver aliases declared as
-            # DM_DRIVER_ALIAS(alias, driver_name)
-            driver_aliases = re.findall(
-                r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
-                buff)
-
-            for alias in driver_aliases: # pragma: no cover
-                if len(alias) != 2:
-                    continue
-                self._driver_aliases[alias[1]] = alias[0]
-
     def scan_header(self, fname):
         """Scan a header file to build a list of struct definitions
 
diff --git a/tools/dtoc/test/dtoc_test_scan_drivers.cxx b/tools/dtoc/test/dtoc_test_scan_drivers.cxx
index f448767670e..f370b8951d0 100644
--- a/tools/dtoc/test/dtoc_test_scan_drivers.cxx
+++ b/tools/dtoc/test/dtoc_test_scan_drivers.cxx
@@ -1 +1,5 @@
+/* Aliases must be in driver files */
+U_BOOT_DRIVER(sandbox_gpio) {
+};
+
 DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 39/49] dtoc: Warn of duplicate drivers
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (37 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 38/49] dtoc: Process driver aliases along with drivers Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 40/49] dtoc: Read aliases for uclasses Simon Glass
                   ` (29 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

If drivers have the same name then we cannot distinguish them. This only
matters if the driver is actually used by dtoc, but in that case, issue
a warning.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/src_scan.py      | 28 ++++++++++-
 tools/dtoc/test_src_scan.py | 95 +++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 9d161a2cbc7..fb78536e003 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -70,6 +70,10 @@ class Driver:
         phase (str): Which phase of U-Boot to use this driver
         headers (list): List of header files needed for this driver (each a str)
             e.g. ['<asm/cpu.h>']
+        dups (list): Driver objects with the same name as this one, that were
+            found after this one
+        warn_dups (bool): True if the duplicates are not distinguisble using
+            the phase
     """
     def __init__(self, name, fname):
         self.name = name
@@ -83,6 +87,8 @@ class Driver:
         self.used = False
         self.phase = ''
         self.headers = []
+        self.dups = []
+        self.warn_dups = False
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -531,7 +537,21 @@ class Scanner:
                     self._driver_aliases[m_alias[2]] = m_alias[1]
 
         # Make the updates based on what we found
-        self._drivers.update(drivers)
+        for driver in drivers.values():
+            if driver.name in self._drivers:
+                orig = self._drivers[driver.name]
+                if self._phase:
+                    # If the original driver matches our phase, use it
+                    if orig.phase == self._phase:
+                        orig.dups.append(driver)
+                        continue
+
+                    # Otherwise use the new driver, which is assumed to match
+                else:
+                    # We have no way of distinguishing them
+                    driver.warn_dups = True
+                driver.dups.append(orig)
+            self._drivers[driver.name] = driver
         self._of_match.update(of_match)
 
     def scan_driver(self, fname):
@@ -617,6 +637,8 @@ class Scanner:
         This takes a list of nodes, finds the driver for each one and marks it
         as used.
 
+        If two used drivers have the same name, issue a warning.
+
         Args:
             nodes (list of None): Nodes that are in use
         """
@@ -626,3 +648,7 @@ class Scanner:
             driver = self._drivers.get(struct_name)
             if driver:
                 driver.used = True
+                if driver.dups and driver.warn_dups:
+                    print("Warning: Duplicate driver name '%s' (orig=%s, dups=%s)" %
+                          (driver.name, driver.fname,
+                           ', '.join([drv.fname for drv in driver.dups])))
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 245b7302fd6..598ff256a60 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -371,3 +371,98 @@ struct another_struct {
         with test_util.capture_sys_output() as (stdout, _):
             scan.scan_header(output)
         self.assertIn('due to unicode error', stdout.getvalue())
+
+    def setup_dup_drivers(self, name, phase=''):
+        """Set up for a duplcate test
+
+        Returns:
+            tuple:
+                Scanner to use
+                Driver record for first driver
+                Text of second driver declaration
+                Node for driver 1
+        """
+        driver1 = '''
+static const struct udevice_id test_ids[] = {
+	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+	{ }
+};
+
+U_BOOT_DRIVER(%s) = {
+	.name	= "testing",
+	.id	= UCLASS_I2C,
+	.of_match = test_ids,
+	%s
+};
+''' % (name, 'DM_PHASE(%s)' % phase if phase else '')
+        driver2 = '''
+static const struct udevice_id test_ids[] = {
+	{ .compatible = "nvidia,tegra114-dvc" },
+	{ }
+};
+
+U_BOOT_DRIVER(%s) = {
+	.name	= "testing",
+	.id	= UCLASS_RAM,
+	.of_match = test_ids,
+};
+''' % name
+        scan = src_scan.Scanner(None, False, None, phase)
+        scan._parse_driver('file1.c', driver1)
+        self.assertIn(name, scan._drivers)
+        drv1 = scan._drivers[name]
+
+        prop = FakeProp()
+        prop.name = 'compatible'
+        prop.value = 'nvidia,tegra114-i2c'
+        node = FakeNode()
+        node.name = 'testing'
+        node.props = {'compatible': prop}
+
+        return scan, drv1, driver2, node
+
+    def test_dup_drivers(self):
+        """Test handling of duplicate drivers"""
+        name = 'nvidia_tegra114_i2c'
+        scan, drv1, driver2, node = self.setup_dup_drivers(name)
+        self.assertEqual('', drv1.phase)
+
+        # The driver should not have a duplicate yet
+        self.assertEqual([], drv1.dups)
+
+        scan._parse_driver('file2.c', driver2)
+
+        # The first driver should now be a duplicate of the second
+        drv2 = scan._drivers[name]
+        self.assertEqual('', drv2.phase)
+        self.assertEqual(1, len(drv2.dups))
+        self.assertEqual([drv1], drv2.dups)
+
+        # There is no way to distinguish them, so we should expect a warning
+        self.assertTrue(drv2.warn_dups)
+
+        # We should see a warning
+        with test_util.capture_sys_output() as (stdout, _):
+            scan.mark_used([node])
+        self.assertEqual(
+            "Warning: Duplicate driver name 'nvidia_tegra114_i2c' (orig=file2.c, dups=file1.c)",
+            stdout.getvalue().strip())
+
+    def test_dup_drivers_phase(self):
+        """Test handling of duplicate drivers but with different phases"""
+        name = 'nvidia_tegra114_i2c'
+        scan, drv1, driver2, node = self.setup_dup_drivers(name, 'spl')
+        scan._parse_driver('file2.c', driver2)
+        self.assertEqual('spl', drv1.phase)
+
+        # The second driver should now be a duplicate of the second
+        self.assertEqual(1, len(drv1.dups))
+        drv2 = drv1.dups[0]
+
+        # The phase is different, so we should not warn of dups
+        self.assertFalse(drv1.warn_dups)
+
+        # We should not see a warning
+        with test_util.capture_sys_output() as (stdout, _):
+            scan.mark_used([node])
+        self.assertEqual('', stdout.getvalue().strip())
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 40/49] dtoc: Read aliases for uclasses
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (38 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 39/49] dtoc: Warn of duplicate drivers Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 41/49] dtoc: Assign a sequence number to each node Simon Glass
                   ` (28 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Scan the aliases in the device tree to establish the number of devices
within each uclass, and the sequence number of each.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py                   | 28 ++++++++++
 tools/dtoc/src_scan.py                       | 32 ++++++++++-
 tools/dtoc/test/dtoc_test_alias_bad.dts      | 58 ++++++++++++++++++++
 tools/dtoc/test/dtoc_test_alias_bad_path.dts | 58 ++++++++++++++++++++
 tools/dtoc/test/dtoc_test_alias_bad_uc.dts   | 58 ++++++++++++++++++++
 tools/dtoc/test/dtoc_test_inst.dts           | 58 ++++++++++++++++++++
 tools/dtoc/test_dtoc.py                      | 56 ++++++++++++++++++-
 7 files changed, 345 insertions(+), 3 deletions(-)
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_path.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_uc.dts
 create mode 100644 tools/dtoc/test/dtoc_test_inst.dts

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index ef0454c8904..f6dcf47d490 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -647,6 +647,29 @@ class DtbPlatdata():
             self._output_prop(node, node.props[pname])
         self.buf('};\n')
 
+    def read_aliases(self):
+        """Read the aliases and attach the information to self._alias
+
+        Raises:
+            ValueError: The alias path is not found
+        """
+        alias_node = self._fdt.GetNode('/aliases')
+        if not alias_node:
+            return
+        re_num = re.compile('(^[a-z0-9-]+[a-z]+)([0-9]+)$')
+        for prop in alias_node.props.values():
+            m_alias = re_num.match(prop.name)
+            if not m_alias:
+                raise ValueError("Cannot decode alias '%s'" % prop.name)
+            name, num = m_alias.groups()
+            node = self._fdt.GetNode(prop.value)
+            result = self._scan.add_uclass_alias(name, num, node)
+            if result is None:
+                raise ValueError("Alias '%s' path '%s' not found" %
+                                 (prop.name, prop.value))
+            elif result is False:
+                print("Could not find uclass for alias '%s'" % prop.name)
+
     def process_nodes(self, need_drivers):
         nodes_to_output = list(self._valid_nodes)
 
@@ -757,6 +780,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
         scan (src_src.Scanner): Scanner from a previous run. This can help speed
             up tests. Use None for normal operation
 
+    Returns:
+        DtbPlatdata object
+
     Raises:
         ValueError: if args has no command, or an unknown command
     """
@@ -782,6 +808,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
     plat.scan_phandles()
     if do_process:
         plat.process_nodes(False)
+    plat.read_aliases()
 
     cmds = args[0].split(',')
     if 'all' in cmds:
@@ -796,3 +823,4 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
         plat.out_header(outfile)
         outfile.method(plat)
     plat.finish_output()
+    return plat
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index fb78536e003..a2750321791 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -116,6 +116,13 @@ class UclassDriver:
             e.g. 'pci_child_priv'
         per_child_plat (str): struct name of the per_child_plat_auto member,
             e.g. 'pci_child_plat'
+        alias_num_to_node (dict): Aliases for this uclasses (for sequence
+                numbers)
+            key (int): Alias number, e.g. 2 for "pci2"
+            value (str): Node the alias points to
+        alias_path_to_num (dict): Convert a path to an alias number
+            key (str): Full path to node (e.g. '/soc/pci')
+            seq (int): Alias number, e.g. 2 for "pci2"
     """
     def __init__(self, name):
         self.name = name
@@ -125,6 +132,8 @@ class UclassDriver:
         self.per_dev_plat = ''
         self.per_child_priv = ''
         self.per_child_plat = ''
+        self.alias_num_to_node = {}
+        self.alias_path_to_num = {}
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -622,7 +631,6 @@ class Scanner:
                     self.scan_driver(pathname)
                 elif fname.endswith('.h'):
                     self.scan_header(pathname)
-
         for fname in self._drivers_additional:
             if not isinstance(fname, str) or len(fname) == 0:
                 continue
@@ -652,3 +660,25 @@ class Scanner:
                     print("Warning: Duplicate driver name '%s' (orig=%s, dups=%s)" %
                           (driver.name, driver.fname,
                            ', '.join([drv.fname for drv in driver.dups])))
+
+    def add_uclass_alias(self, name, num, node):
+        """Add an alias to a uclass
+
+        Args:
+            name: Name of uclass, e.g. 'i2c'
+            num: Alias number, e.g. 2 for alias 'i2c2'
+            node: Node the alias points to, or None if None
+
+        Returns:
+            True if the node was added
+            False if the node was not added (uclass of that name not found)
+            None if the node could not be added because it was None
+        """
+        for uclass in self._uclass.values():
+            if uclass.name == name:
+                if node is None:
+                    return None
+                uclass.alias_num_to_node[int(num)] = node
+                uclass.alias_path_to_num[node.path] = int(num)
+                return True
+        return False
diff --git a/tools/dtoc/test/dtoc_test_alias_bad.dts b/tools/dtoc/test/dtoc_test_alias_bad.dts
new file mode 100644
index 00000000000..d4f502ad0aa
--- /dev/null
+++ b/tools/dtoc/test/dtoc_test_alias_bad.dts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	aliases {
+		testbus2 = &bus2;
+		testfdt1 = &testfdt_1;
+		i2c4- = &i2c;
+	};
+
+	spl-test {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		boolval;
+		intval = <1>;
+	};
+
+	i2c: i2c {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,i2c";
+		intval = <3>;
+	};
+
+	spl-test3 {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		stringarray = "one";
+		longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
+	};
+
+	bus2: some-bus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "denx,u-boot-test-bus";
+		reg = <3 1>;
+		ping-expect = <4>;
+		ping-add = <4>;
+		testfdt_1: test {
+			compatible = "denx,u-boot-fdt-test", "google,another-fdt-test";
+			reg = <5>;
+			ping-expect = <5>;
+			ping-add = <5>;
+		};
+
+		test0 {
+			compatible = "google,another-fdt-test";
+		};
+	};
+};
diff --git a/tools/dtoc/test/dtoc_test_alias_bad_path.dts b/tools/dtoc/test/dtoc_test_alias_bad_path.dts
new file mode 100644
index 00000000000..0beca4f0d03
--- /dev/null
+++ b/tools/dtoc/test/dtoc_test_alias_bad_path.dts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	aliases {
+		testbus2 = &bus2;
+		testfdt1 = &testfdt_1;
+		i2c4 = "/does/not/exist";
+	};
+
+	spl-test {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		boolval;
+		intval = <1>;
+	};
+
+	i2c: i2c {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,i2c";
+		intval = <3>;
+	};
+
+	spl-test3 {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		stringarray = "one";
+		longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
+	};
+
+	bus2: some-bus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "denx,u-boot-test-bus";
+		reg = <3 1>;
+		ping-expect = <4>;
+		ping-add = <4>;
+		testfdt_1: test {
+			compatible = "denx,u-boot-fdt-test", "google,another-fdt-test";
+			reg = <5>;
+			ping-expect = <5>;
+			ping-add = <5>;
+		};
+
+		test0 {
+			compatible = "google,another-fdt-test";
+		};
+	};
+};
diff --git a/tools/dtoc/test/dtoc_test_alias_bad_uc.dts b/tools/dtoc/test/dtoc_test_alias_bad_uc.dts
new file mode 100644
index 00000000000..ae64f5b3b29
--- /dev/null
+++ b/tools/dtoc/test/dtoc_test_alias_bad_uc.dts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	aliases {
+		testbus2 = &bus2;
+		testfdt1 = &testfdt_1;
+		other1 = &testfdt_1;
+	};
+
+	spl-test {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		boolval;
+		intval = <1>;
+	};
+
+	i2c: i2c {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,i2c";
+		intval = <3>;
+	};
+
+	spl-test3 {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		stringarray = "one";
+		longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
+	};
+
+	bus2: some-bus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "denx,u-boot-test-bus";
+		reg = <3 1>;
+		ping-expect = <4>;
+		ping-add = <4>;
+		testfdt_1: test {
+			compatible = "denx,u-boot-fdt-test", "google,another-fdt-test";
+			reg = <5>;
+			ping-expect = <5>;
+			ping-add = <5>;
+		};
+
+		test0 {
+			compatible = "google,another-fdt-test";
+		};
+	};
+};
diff --git a/tools/dtoc/test/dtoc_test_inst.dts b/tools/dtoc/test/dtoc_test_inst.dts
new file mode 100644
index 00000000000..b8177fcef5f
--- /dev/null
+++ b/tools/dtoc/test/dtoc_test_inst.dts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	aliases {
+		testbus2 = &bus2;
+		testfdt1 = &testfdt_1;
+		i2c4 = &i2c;
+	};
+
+	spl-test {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		boolval;
+		intval = <1>;
+	};
+
+	i2c: i2c {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,i2c";
+		intval = <3>;
+	};
+
+	spl-test3 {
+		u-boot,dm-pre-reloc;
+		compatible = "sandbox,spl-test";
+		stringarray = "one";
+		longbytearray = [09 0a 0b 0c 0d 0e 0f 10];
+	};
+
+	bus2: some-bus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "denx,u-boot-test-bus";
+		reg = <3 1>;
+		ping-expect = <4>;
+		ping-add = <4>;
+		testfdt_1: test {
+			compatible = "denx,u-boot-fdt-test", "google,another-fdt-test";
+			reg = <5>;
+			ping-expect = <5>;
+			ping-add = <5>;
+		};
+
+		test0 {
+			compatible = "google,another-fdt-test";
+		};
+	};
+};
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c1fafb656fb..706cc39b3d5 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -137,9 +137,12 @@ class TestDtoc(unittest.TestCase):
             args (list of str): List of arguments for dtoc
             dtb_file (str): Filename of .dtb file
             output (str): Filename of output file
+
+        Returns:
+            DtbPlatdata object
         """
-        dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
-                               warning_disabled=True, scan=copy_scan())
+        return dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
+                                      warning_disabled=True, scan=copy_scan())
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -1040,3 +1043,52 @@ U_BOOT_DRVINFO(spl_test2) = {
 
         gpio = scan._drivers['sandbox_gpio']
         self.assertFalse(gpio.used)
+
+    def test_alias_read(self):
+        """Test obtaining aliases"""
+        dtb_file = get_dtb_file('dtoc_test_inst.dts')
+        output = tools.GetOutputFilename('output')
+        plat = self.run_test(['struct'], dtb_file, output)
+
+        scan = plat._scan
+        testfdt_node = plat._fdt.GetNode('/some-bus/test')
+        self.assertIn('UCLASS_TEST_FDT', scan._uclass)
+        uc = scan._uclass['UCLASS_TEST_FDT']
+        self.assertEqual({1: testfdt_node}, uc.alias_num_to_node)
+        self.assertEqual({'/some-bus/test': 1}, uc.alias_path_to_num)
+
+        # Try adding an alias that doesn't exist
+        self.assertFalse(scan.add_uclass_alias('fred', 3, None))
+
+        # Try adding an alias for a missing node
+        self.assertIsNone(scan.add_uclass_alias('testfdt', 3, None))
+
+    def test_alias_read_bad(self):
+        """Test invalid alias property name"""
+        dtb_file = get_dtb_file('dtoc_test_alias_bad.dts')
+        output = tools.GetOutputFilename('output')
+        with self.assertRaises(ValueError) as exc:
+            plat = self.run_test(['struct'], dtb_file, output)
+        self.assertIn("Cannot decode alias 'i2c4-'", str(exc.exception))
+
+    def test_alias_read_bad_path(self):
+        """Test alias pointing to a non-existent node"""
+        # This line may produce a warning, so capture it:
+        # Warning (alias_paths): /aliases:i2c4: aliases property is not a valid
+        #    node (/does/not/exist)
+        dtb_file = get_dtb_file('dtoc_test_alias_bad_path.dts', True)
+
+        output = tools.GetOutputFilename('output')
+        with self.assertRaises(ValueError) as exc:
+            plat = self.run_test(['struct'], dtb_file, output)
+        self.assertIn("Alias 'i2c4' path '/does/not/exist' not found",
+                      str(exc.exception))
+
+    def test_alias_read_bad_uclass(self):
+        """Test alias for a uclass that doesn't exist"""
+        dtb_file = get_dtb_file('dtoc_test_alias_bad_uc.dts')
+        output = tools.GetOutputFilename('output')
+        with test_util.capture_sys_output() as (stdout, _):
+            plat = self.run_test(['struct'], dtb_file, output)
+        self.assertEqual("Could not find uclass for alias 'other1'",
+                         stdout.getvalue().strip())
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 41/49] dtoc: Assign a sequence number to each node
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (39 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 40/49] dtoc: Read aliases for uclasses Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 42/49] dtoc: Set up the uclasses that are used Simon Glass
                   ` (27 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Now that we have the alias information we can assign a sequence number
to each device in the uclass. Store this in the node associated with each
device.

This requires renaming the sandbox test drivers to have the right name.
Note that test coverage is broken with this patch, but fixed in the next
one.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/test_drv.c    |  6 +++--
 test/dm/test-fdt.c         |  6 ++---
 tools/dtoc/dtb_platdata.py | 55 +++++++++++++++++++++++++++-----------
 tools/dtoc/test_dtoc.py    |  6 +++++
 4 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index 7dd3de34c99..ac762fd9fea 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -85,7 +85,7 @@ static const struct udevice_id testbus_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(testbus_drv) = {
+U_BOOT_DRIVER(denx_u_boot_test_bus) = {
 	.name	= "testbus_drv",
 	.of_match	= testbus_ids,
 	.id	= UCLASS_TEST_BUS,
@@ -159,7 +159,9 @@ static const struct udevice_id testfdt_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(testfdt_drv) = {
+DM_DRIVER_ALIAS(denx_u_boot_fdt_test, google_another_fdt_test)
+
+U_BOOT_DRIVER(denx_u_boot_fdt_test) = {
 	.name	= "testfdt_drv",
 	.of_match	= testfdt_ids,
 	.id	= UCLASS_TEST_FDT,
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index b53539055b6..df4d3fe522d 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -328,7 +328,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 
 	/* Check creating a device with an alias */
 	node = ofnode_path("/some-bus/c-test at 1");
-	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
 				"c-test at 1", NULL, node, &dev));
 	ut_asserteq(12, dev_seq(dev));
 	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
@@ -348,11 +348,11 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 	 *
 	 * So next available is 19
 	 */
-	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
 				"fred", NULL, ofnode_null(), &dev));
 	ut_asserteq(19, dev_seq(dev));
 
-	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv),
+	ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
 				"fred2", NULL, ofnode_null(), &dev));
 	ut_asserteq(20, dev_seq(dev));
 
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index f6dcf47d490..9e99c63ae70 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -136,8 +136,10 @@ class DtbPlatdata():
             from the U-Boot source code
         _fdt: Fdt object, referencing the device tree
         _dtb_fname: Filename of the input device tree binary file
-        _valid_nodes: A list of Node object with compatible strings. The list
-            is ordered by conv_name_to_c(node.name)
+        _valid_nodes_unsorted: A list of Node object with compatible strings,
+            ordered by devicetree node order
+        _valid_nodes: A list of Node object with compatible strings, ordered by
+            conv_name_to_c(node.name)
         _include_disabled: true to include nodes marked status = "disabled"
         _outfile: The current output file (sys.stdout or a real file)
         _lines: Stashed list of output lines for outputting in the future
@@ -155,6 +157,7 @@ class DtbPlatdata():
         self._fdt = None
         self._dtb_fname = dtb_fname
         self._valid_nodes = None
+        self._valid_nodes_unsorted = None
         self._include_disabled = include_disabled
         self._outfile = None
         self._lines = []
@@ -324,34 +327,38 @@ class DtbPlatdata():
         """
         self._fdt = fdt.FdtScan(self._dtb_fname)
 
-    def scan_node(self, root, valid_nodes):
+    def scan_node(self, node, valid_nodes):
         """Scan a node and subnodes to build a tree of node and phandle info
 
-        This adds each node to self._valid_nodes.
+        This adds each subnode to self._valid_nodes if it is enabled and has a
+        compatible string.
 
         Args:
-            root (Node): Root node for scan
+            node (Node): Node for scan for subnodes
             valid_nodes (list of Node): List of Node objects to add to
         """
-        for node in root.subnodes:
-            if 'compatible' in node.props:
-                status = node.props.get('status')
+        for subnode in node.subnodes:
+            if 'compatible' in subnode.props:
+                status = subnode.props.get('status')
                 if (not self._include_disabled and not status or
                         status.value != 'disabled'):
-                    valid_nodes.append(node)
+                    valid_nodes.append(subnode)
 
             # recurse to handle any subnodes
-            self.scan_node(node, valid_nodes)
+            self.scan_node(subnode, valid_nodes)
 
     def scan_tree(self):
         """Scan the device tree for useful information
 
         This fills in the following properties:
-            _valid_nodes: A list of nodes we wish to consider include in the
-                platform data
+            _valid_nodes_unsorted: A list of nodes we wish to consider include
+                in the platform data (in devicetree node order)
+            _valid_nodes: Sorted version of _valid_nodes_unsorted
         """
+        root = self._fdt.GetRoot()
         valid_nodes = []
-        self.scan_node(self._fdt.GetRoot(), valid_nodes)
+        self.scan_node(root, valid_nodes)
+        self._valid_nodes_unsorted = valid_nodes
         self._valid_nodes = sorted(valid_nodes,
                                    key=lambda x: conv_name_to_c(x.name))
 
@@ -670,6 +677,24 @@ class DtbPlatdata():
             elif result is False:
                 print("Could not find uclass for alias '%s'" % prop.name)
 
+    def assign_seq(self):
+        """Assign a sequence number to each node"""
+        for node in self._valid_nodes_unsorted:
+            if node.driver and node.seq == -1 and node.uclass:
+                uclass = node.uclass
+                num = uclass.alias_path_to_num.get(node.path)
+                if num is not None:
+                    node.seq = num
+                else:
+                    # Dynamically allocate the next available value after all
+                    # existing ones
+                    for seq in range(1000):
+                        if seq not in uclass.alias_num_to_node:
+                            break
+                    node.seq = seq
+                    uclass.alias_path_to_num[node.path] = seq
+                    uclass.alias_num_to_node[seq] = node
+
     def process_nodes(self, need_drivers):
         nodes_to_output = list(self._valid_nodes)
 
@@ -806,9 +831,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
     plat.setup_output_dirs(output_dirs)
     plat.scan_structs()
     plat.scan_phandles()
-    if do_process:
-        plat.process_nodes(False)
+    plat.process_nodes(False)
     plat.read_aliases()
+    plat.assign_seq()
 
     cmds = args[0].split(',')
     if 'all' in cmds:
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 706cc39b3d5..b4c0a042a9f 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -1092,3 +1092,9 @@ U_BOOT_DRVINFO(spl_test2) = {
             plat = self.run_test(['struct'], dtb_file, output)
         self.assertEqual("Could not find uclass for alias 'other1'",
                          stdout.getvalue().strip())
+
+    def test_sequence(self):
+        """Test assignment of sequence numnbers"""
+        dtb_file = get_dtb_file('dtoc_test_inst.dts')
+        output = tools.GetOutputFilename('output')
+        plat = self.run_test(['struct'], dtb_file, output)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 42/49] dtoc: Set up the uclasses that are used
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (40 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 41/49] dtoc: Assign a sequence number to each node Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 43/49] dtoc: Support processing the root node Simon Glass
                   ` (26 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

We only care about uclasses that are actually used. This is determined by
the drivers that use them. Check all the used drivers and build a list of
'valid' uclasses.

Also add references to the uclasses so we can generate C code that uses
them. Attach a uclass to each valid driver.

For the tests, now that we have uclasses we must create an explicit test
for the case where a node does not have one. This should only happen if
the source code does not build, or the source-code scanning fails to find
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py  | 46 ++++++++++++++++++++++++-------------
 tools/dtoc/src_scan.py      | 45 ++++++++++++++++++++++++++++++++++++
 tools/dtoc/test_dtoc.py     | 27 ++++++++++++++++++++--
 tools/dtoc/test_src_scan.py | 17 ++++++++++++++
 4 files changed, 117 insertions(+), 18 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 9e99c63ae70..af21156659b 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -151,6 +151,8 @@ class DtbPlatdata():
                         key (str): Field name
                         value: Prop object with field information
         _basedir (str): Base directory of source tree
+        _valid_uclasses (list of src_scan.Uclass): List of uclasses needed for
+            the selected devices (see _valid_node), in alphabetical order
     """
     def __init__(self, scan, dtb_fname, include_disabled):
         self._scan = scan
@@ -164,6 +166,7 @@ class DtbPlatdata():
         self._dirnames = [None] * len(Ftype)
         self._struct_data = collections.OrderedDict()
         self._basedir = None
+        self._valid_uclasses = None
 
     def setup_output_dirs(self, output_dirs):
         """Set up the output directories
@@ -677,23 +680,12 @@ class DtbPlatdata():
             elif result is False:
                 print("Could not find uclass for alias '%s'" % prop.name)
 
-    def assign_seq(self):
+    def assign_seqs(self):
         """Assign a sequence number to each node"""
         for node in self._valid_nodes_unsorted:
-            if node.driver and node.seq == -1 and node.uclass:
-                uclass = node.uclass
-                num = uclass.alias_path_to_num.get(node.path)
-                if num is not None:
-                    node.seq = num
-                else:
-                    # Dynamically allocate the next available value after all
-                    # existing ones
-                    for seq in range(1000):
-                        if seq not in uclass.alias_num_to_node:
-                            break
-                    node.seq = seq
-                    uclass.alias_path_to_num[node.path] = seq
-                    uclass.alias_num_to_node[seq] = node
+            seq = self._scan.assign_seq(node)
+            if seq is not None:
+                node.seq = seq
 
     def process_nodes(self, need_drivers):
         nodes_to_output = list(self._valid_nodes)
@@ -710,6 +702,16 @@ class DtbPlatdata():
                 raise ValueError("Cannot parse/find driver for '%s'" %
                                  node.struct_name)
             node.driver = driver
+            uclass = self._scan._uclass.get(driver.uclass_id)
+            if not uclass:
+                raise ValueError("Cannot parse/find uclass '%s' for driver '%s'" %
+                                (driver.uclass_id, node.struct_name))
+            node.uclass = uclass
+            node.uclass_seq = len(node.uclass.devs)
+            node.uclass.devs.append(node)
+            uclass.node_refs[node.uclass_seq] = \
+                '&%s->uclass_node' % node.dev_ref
+
             parent_driver = None
             if node.parent in self._valid_nodes:
                 parent_driver = self._scan.get_driver(node.parent.struct_name)
@@ -730,6 +732,18 @@ class DtbPlatdata():
             node.child_refs[-1] = ref
             node.child_refs[len(node.child_devs)] = ref
 
+        uclass_set = set()
+        for driver in self._scan._drivers.values():
+            if driver.used and driver.uclass:
+                uclass_set.add(driver.uclass)
+        self._valid_uclasses = sorted(list(uclass_set),
+                                      key=lambda uc: uc.uclass_id)
+
+        for seq, uclass in enumerate(uclass_set):
+            ref = '&DM_UCLASS_REF(%s)->dev_head' % uclass.name
+            uclass.node_refs[-1] = ref
+            uclass.node_refs[len(uclass.devs)] = ref
+
     def output_node(self, node):
         """Output the C code for a node
 
@@ -833,7 +847,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
     plat.scan_phandles()
     plat.process_nodes(False)
     plat.read_aliases()
-    plat.assign_seq()
+    plat.assign_seqs()
 
     cmds = args[0].split(',')
     if 'all' in cmds:
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index a2750321791..07bfb35195f 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -74,6 +74,7 @@ class Driver:
             found after this one
         warn_dups (bool): True if the duplicates are not distinguisble using
             the phase
+        uclass (Uclass): uclass for this driver
     """
     def __init__(self, name, fname):
         self.name = name
@@ -89,6 +90,7 @@ class Driver:
         self.headers = []
         self.dups = []
         self.warn_dups = False
+        self.uclass = None
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -123,6 +125,10 @@ class UclassDriver:
         alias_path_to_num (dict): Convert a path to an alias number
             key (str): Full path to node (e.g. '/soc/pci')
             seq (int): Alias number, e.g. 2 for "pci2"
+        devs (list): List of devices in this uclass, each a Node
+        node_refs (dict): References in the linked list of devices:
+            key (int): Sequence number (0=first, n-1=last, -1=head, n=tail)
+            value (str): Reference to the device at that position
     """
     def __init__(self, name):
         self.name = name
@@ -134,6 +140,8 @@ class UclassDriver:
         self.per_child_plat = ''
         self.alias_num_to_node = {}
         self.alias_path_to_num = {}
+        self.devs = []
+        self.node_refs = {}
 
     def __eq__(self, other):
         return (self.name == other.name and
@@ -639,6 +647,12 @@ class Scanner:
             else:
                 self.scan_driver(self._basedir + '/' + fname)
 
+        # Get the uclass for each driver
+        # TODO: Can we just get the uclass for the ones we use, e.g. in
+        # mark_used()?
+        for driver in self._drivers.values():
+            driver.uclass = self._uclass.get(driver.uclass_id)
+
     def mark_used(self, nodes):
         """Mark the drivers associated with a list of nodes as 'used'
 
@@ -682,3 +696,34 @@ class Scanner:
                 uclass.alias_path_to_num[node.path] = int(num)
                 return True
         return False
+
+    def assign_seq(self, node):
+        """Figure out the sequence number for a node
+
+        This looks in the node's uclass and assigns a sequence number if needed,
+        based on the aliases and other nodes in that uclass.
+
+        It updates the uclass alias_path_to_num and alias_num_to_node
+
+        Args:
+            node (Node): Node object to look up
+        """
+        if node.driver and node.seq == -1 and node.uclass:
+            uclass = node.uclass
+            num = uclass.alias_path_to_num.get(node.path)
+            if num is not None:
+                return num
+            else:
+                # Dynamically allocate the next available value after all
+                # existing ones
+                if uclass.alias_num_to_node:
+                    start = max(uclass.alias_num_to_node.keys())
+                else:
+                    start = -1
+                for seq in range(start + 1, 1000):
+                    if seq not in uclass.alias_num_to_node:
+                        break
+                uclass.alias_path_to_num[node.path] = seq
+                uclass.alias_num_to_node[seq] = node
+                return seq
+        return None
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index b4c0a042a9f..c182966f552 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -141,6 +141,8 @@ class TestDtoc(unittest.TestCase):
         Returns:
             DtbPlatdata object
         """
+        # Make a copy of the 'scan' object, since it includes uclasses and
+        # drivers, which get updated during execution.
         return dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
                                       warning_disabled=True, scan=copy_scan())
 
@@ -1033,6 +1035,16 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertIn("Cannot parse/find driver for 'sandbox_pmic",
                       str(exc.exception))
 
+    def test_process_nodes_bad_uclass(self):
+        plat, scan = self.setup_process_test()
+
+        self.assertIn('UCLASS_I2C', scan._uclass)
+        del scan._uclass['UCLASS_I2C']
+        with self.assertRaises(ValueError) as exc:
+            plat.process_nodes(True)
+        self.assertIn("Cannot parse/find uclass 'UCLASS_I2C' for driver 'sandbox_i2c'",
+                      str(exc.exception))
+
     def test_process_nodes_used(self):
         """Test processing nodes to add various info"""
         plat, scan = self.setup_process_test()
@@ -1052,10 +1064,13 @@ U_BOOT_DRVINFO(spl_test2) = {
 
         scan = plat._scan
         testfdt_node = plat._fdt.GetNode('/some-bus/test')
+        test0_node = plat._fdt.GetNode('/some-bus/test0')
         self.assertIn('UCLASS_TEST_FDT', scan._uclass)
         uc = scan._uclass['UCLASS_TEST_FDT']
-        self.assertEqual({1: testfdt_node}, uc.alias_num_to_node)
-        self.assertEqual({'/some-bus/test': 1}, uc.alias_path_to_num)
+        self.assertEqual({1: testfdt_node, 2: test0_node},
+                         uc.alias_num_to_node)
+        self.assertEqual({'/some-bus/test': 1, '/some-bus/test0': 2},
+                         uc.alias_path_to_num)
 
         # Try adding an alias that doesn't exist
         self.assertFalse(scan.add_uclass_alias('fred', 3, None))
@@ -1098,3 +1113,11 @@ U_BOOT_DRVINFO(spl_test2) = {
         dtb_file = get_dtb_file('dtoc_test_inst.dts')
         output = tools.GetOutputFilename('output')
         plat = self.run_test(['struct'], dtb_file, output)
+
+        scan = plat._scan
+        testfdt = plat._fdt.GetNode('/some-bus/test')
+        self.assertEqual(1, testfdt.seq)
+        i2c = plat._fdt.GetNode('/i2c')
+        self.assertEqual(4, i2c.seq)
+        spl = plat._fdt.GetNode('/spl-test')
+        self.assertEqual(0, spl.seq)
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 598ff256a60..d32aa58400f 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -466,3 +466,20 @@ U_BOOT_DRIVER(%s) = {
         with test_util.capture_sys_output() as (stdout, _):
             scan.mark_used([node])
         self.assertEqual('', stdout.getvalue().strip())
+
+    def test_sequence(self):
+        """Test assignment of sequence numnbers"""
+        scan = src_scan.Scanner(None, False, None, '')
+        node = FakeNode()
+        uc = src_scan.UclassDriver('UCLASS_I2C')
+        node.uclass = uc
+        node.driver = True
+        node.seq = -1
+        node.path = 'mypath'
+        uc.alias_num_to_node[2] = node
+
+        # This should assign 3 (after the 2 that exists)
+        seq = scan.assign_seq(node)
+        self.assertEqual(3, seq)
+        self.assertEqual({'mypath': 3}, uc.alias_path_to_num)
+        self.assertEqual({2: node, 3: node}, uc.alias_num_to_node)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 43/49] dtoc: Support processing the root node
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (41 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 42/49] dtoc: Set up the uclasses that are used Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 44/49] dtoc: Add an option for device instantiation Simon Glass
                   ` (25 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

The device for the root node is normally bound by driver model on init.
With devices being instantiated at build time, we must handle the root
device also.

Add support for processing the root node, which may not have a compatible
string.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py  | 10 ++++++++--
 tools/dtoc/src_scan.py      | 39 ++++++++++++++++++++++---------------
 tools/dtoc/test_dtoc.py     | 23 ++++++++++++++++++++--
 tools/dtoc/test_src_scan.py |  7 +++++++
 4 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index af21156659b..e08b92cf8a3 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -350,16 +350,22 @@ class DtbPlatdata():
             # recurse to handle any subnodes
             self.scan_node(subnode, valid_nodes)
 
-    def scan_tree(self):
+    def scan_tree(self, add_root):
         """Scan the device tree for useful information
 
         This fills in the following properties:
             _valid_nodes_unsorted: A list of nodes we wish to consider include
                 in the platform data (in devicetree node order)
             _valid_nodes: Sorted version of _valid_nodes_unsorted
+
+        Args:
+            add_root: True to add the root node also (which wouldn't normally
+                be added as it may not have a compatible string)
         """
         root = self._fdt.GetRoot()
         valid_nodes = []
+        if add_root:
+            valid_nodes.append(root)
         self.scan_node(root, valid_nodes)
         self._valid_nodes_unsorted = valid_nodes
         self._valid_nodes = sorted(valid_nodes,
@@ -839,7 +845,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
         do_process = False
     plat = DtbPlatdata(scan, dtb_file, include_disabled)
     plat.scan_dtb()
-    plat.scan_tree()
+    plat.scan_tree(add_root=False)
     plat.prepare_nodes()
     plat.scan_reg_sizes()
     plat.setup_output_dirs(output_dirs)
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 07bfb35195f..4db7f6509b0 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -33,6 +33,8 @@ def conv_name_to_c(name):
     new = new.replace('-', '_')
     new = new.replace(',', '_')
     new = new.replace('.', '_')
+    if new == '/':
+        return 'root'
     return new
 
 def get_compat_name(node):
@@ -250,7 +252,10 @@ class Scanner:
                 In case of no match found, the return will be the same as
                 get_compat_name()
         """
-        compat_list_c = get_compat_name(node)
+        if not node.parent:
+            compat_list_c = ['root_driver']
+        else:
+            compat_list_c = get_compat_name(node)
 
         for compat_c in compat_list_c:
             if not compat_c in self._drivers.keys():
@@ -509,21 +514,23 @@ class Scanner:
                 elif m_hdr:
                     driver.headers.append(m_hdr.group(1))
                 elif '};' in line:
-                    if driver.uclass_id and compat:
-                        if compat not in of_match:
-                            raise ValueError(
-                                "%s: Unknown compatible var '%s' (found: %s)" %
-                                (fname, compat, ','.join(of_match.keys())))
-                        driver.compat = of_match[compat]
-
-                        # This needs to be deterministic, since a driver may
-                        # have multiple compatible strings pointing to it.
-                        # We record the one earliest in the alphabet so it
-                        # will produce the same result on all machines.
-                        for compat_id in of_match[compat]:
-                            old = self._compat_to_driver.get(compat_id)
-                            if not old or driver.name < old.name:
-                                self._compat_to_driver[compat_id] = driver
+                    is_root = driver.name == 'root_driver'
+                    if driver.uclass_id and (compat or is_root):
+                        if not is_root:
+                            if compat not in of_match:
+                                raise ValueError(
+                                    "%s: Unknown compatible var '%s' (found: %s)" %
+                                    (fname, compat, ','.join(of_match.keys())))
+                            driver.compat = of_match[compat]
+
+                            # This needs to be deterministic, since a driver may
+                            # have multiple compatible strings pointing to it.
+                            # We record the one earliest in the alphabet so it
+                            # will produce the same result on all machines.
+                            for compat_id in of_match[compat]:
+                                old = self._compat_to_driver.get(compat_id)
+                                if not old or driver.name < old.name:
+                                    self._compat_to_driver[compat_id] = driver
                         drivers[driver.name] = driver
                     else:
                         # The driver does not have a uclass or compat string.
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c182966f552..428bcbbe905 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -974,10 +974,10 @@ U_BOOT_DRVINFO(spl_test2) = {
         output = tools.GetOutputFilename('output')
 
         # Take a copy before messing with it
-        scan = copy.deepcopy(saved_scan)
+        scan = copy_scan()
         plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False)
         plat.scan_dtb()
-        plat.scan_tree()
+        plat.scan_tree(False)
         plat.prepare_nodes()
         return plat, scan
 
@@ -1121,3 +1121,22 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertEqual(4, i2c.seq)
         spl = plat._fdt.GetNode('/spl-test')
         self.assertEqual(0, spl.seq)
+
+    def test_process_root(self):
+        """Test assignment of sequence numnbers"""
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        output = tools.GetOutputFilename('output')
+
+        # Take a copy before messing with it
+        scan = copy_scan()
+        plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False)
+        plat.scan_dtb()
+        root = plat._fdt.GetRoot()
+
+        plat.scan_tree(False)
+        self.assertNotIn(root, plat._valid_nodes)
+
+        plat.scan_tree(True)
+        self.assertIn(root, plat._valid_nodes)
+        self.assertEqual('root_driver',
+                         scan.get_normalized_compat_name(root)[0])
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index d32aa58400f..0af86dcf0c3 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -161,6 +161,10 @@ class TestSrcScan(unittest.TestCase):
         prop.value = 'rockchip,rk3288-grf'
         node = FakeNode()
         node.props = {'compatible': prop}
+
+        # get_normalized_compat_name() uses this to check for root node
+        node.parent = FakeNode()
+
         scan = src_scan.Scanner(None, False, None)
         with test_util.capture_sys_output() as (stdout, _):
             name, aliases = scan.get_normalized_compat_name(node)
@@ -419,6 +423,9 @@ U_BOOT_DRIVER(%s) = {
         node.name = 'testing'
         node.props = {'compatible': prop}
 
+        # get_normalized_compat_name() uses this to check for root node
+        node.parent = FakeNode()
+
         return scan, drv1, driver2, node
 
     def test_dup_drivers(self):
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 44/49] dtoc: Add an option for device instantiation
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (42 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 43/49] dtoc: Support processing the root node Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 45/49] dm: of-platadata: Add " Simon Glass
                   ` (24 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add an option to instantiate devices at build time. For now this just
parses the option and sets up a few parameters.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 17 +++++++++++------
 tools/dtoc/main.py         |  4 +++-
 tools/dtoc/test_dtoc.py    | 37 ++++++++++++++++++++++---------------
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index e08b92cf8a3..46e2725a86c 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -153,8 +153,10 @@ class DtbPlatdata():
         _basedir (str): Base directory of source tree
         _valid_uclasses (list of src_scan.Uclass): List of uclasses needed for
             the selected devices (see _valid_node), in alphabetical order
+        _instantiate: Instantiate devices so they don't need to be bound at
+            run-time
     """
-    def __init__(self, scan, dtb_fname, include_disabled):
+    def __init__(self, scan, dtb_fname, include_disabled, instantiate=False):
         self._scan = scan
         self._fdt = None
         self._dtb_fname = dtb_fname
@@ -167,6 +169,7 @@ class DtbPlatdata():
         self._struct_data = collections.OrderedDict()
         self._basedir = None
         self._valid_uclasses = None
+        self._instantiate = instantiate
 
     def setup_output_dirs(self, output_dirs):
         """Set up the output directories
@@ -802,8 +805,8 @@ OUTPUT_FILES = {
 
 
 def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
-              warning_disabled=False, drivers_additional=None, basedir=None,
-              scan=None):
+              instantiate, warning_disabled=False, drivers_additional=None,
+              basedir=None, scan=None):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -816,6 +819,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
             Directory to put H output files
         phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
              or 'tpl'. None if not known
+        instantiate: Instantiate devices so they don't need to be bound at
+            run-time
         warning_disabled (bool): True to avoid showing warnings about missing
             drivers
         drivers_additional (list): List of additional drivers to use during
@@ -843,15 +848,15 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
         do_process = True
     else:
         do_process = False
-    plat = DtbPlatdata(scan, dtb_file, include_disabled)
+    plat = DtbPlatdata(scan, dtb_file, include_disabled, instantiate)
     plat.scan_dtb()
-    plat.scan_tree(add_root=False)
+    plat.scan_tree(add_root=instantiate)
     plat.prepare_nodes()
     plat.scan_reg_sizes()
     plat.setup_output_dirs(output_dirs)
     plat.scan_structs()
     plat.scan_phandles()
-    plat.process_nodes(False)
+    plat.process_nodes(instantiate)
     plat.read_aliases()
     plat.assign_seqs()
 
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 15a8ff167a9..93706de89bf 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -81,6 +81,8 @@ parser.add_option('-C', '--h-output-dir', action='store',
                   help='Select output directory for H files (defaults to --c-output-di)')
 parser.add_option('-d', '--dtb-file', action='store',
                   help='Specify the .dtb input file')
+parser.add_option('-i', '--instantiate', action='store_true', default=False,
+                  help='Instantiate devices to avoid needing device_bind()')
 parser.add_option('--include-disabled', action='store_true',
                   help='Include disabled nodes')
 parser.add_option('-o', '--output', action='store',
@@ -107,4 +109,4 @@ else:
     dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
                            options.output,
                            [options.c_output_dir, options.h_output_dir],
-                           phase=options.phase)
+                           options.phase, instantiate=options.instantiate)
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 428bcbbe905..fb5ec8abc8d 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -130,7 +130,7 @@ class TestDtoc(unittest.TestCase):
         self.assertEqual(expected, actual)
 
     @staticmethod
-    def run_test(args, dtb_file, output):
+    def run_test(args, dtb_file, output, instantiate=False):
         """Run a test using dtoc
 
         Args:
@@ -143,8 +143,9 @@ class TestDtoc(unittest.TestCase):
         """
         # Make a copy of the 'scan' object, since it includes uclasses and
         # drivers, which get updated during execution.
-        return dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
-                                      warning_disabled=True, scan=copy_scan())
+        return dtb_platdata.run_steps(
+            args, dtb_file, False, output, [], None, instantiate,
+            warning_disabled=True, scan=copy_scan())
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -201,7 +202,8 @@ class TestDtoc(unittest.TestCase):
         output = tools.GetOutputFilename('output')
 
         # Run this one without saved_scan to complete test coverage
-        dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], True)
+        dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], None,
+                               False)
         with open(output) as infile:
             lines = infile.read().splitlines()
         self.assertEqual(HEADER.splitlines(), lines)
@@ -369,8 +371,9 @@ U_BOOT_DRVINFO(gpios_at_0) = {
         dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
-                                   None, scan=copy_scan())
+            dtb_platdata.run_steps(
+                ['struct'], dtb_file, False, output, [], None, False,
+                scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(HEADER + '''
@@ -379,8 +382,9 @@ struct dtd_invalid {
 ''', data)
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [],
-                                   None, scan=copy_scan())
+            dtb_platdata.run_steps(
+                ['platdata'], dtb_file, False, output, [], None, False,
+                scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -530,8 +534,9 @@ U_BOOT_DRVINFO(phandle_target) = {
         """Test that phandle targets are generated when unsing cd-gpios"""
         dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
         output = tools.GetOutputFilename('output')
-        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True,
-                               scan=copy_scan())
+        dtb_platdata.run_steps(
+            ['platdata'], dtb_file, False, output, [], None, False,
+            warning_disabled=True, scan=copy_scan())
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -925,15 +930,16 @@ U_BOOT_DRVINFO(spl_test2) = {
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
         with self.assertRaises(ValueError) as exc:
-            self.run_test(['invalid-cmd'], dtb_file, output)
+            self.run_test(['invalid-cmd'], dtb_file, output, False)
         self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
                       str(exc.exception))
 
     def test_output_conflict(self):
         """Test a conflict between and output dirs and output file"""
         with self.assertRaises(ValueError) as exc:
-            dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], None,
-                                   warning_disabled=True, scan=copy_scan())
+            dtb_platdata.run_steps(
+                ['all'], None, False, 'out', ['cdir'], None, False,
+                warning_disabled=True, scan=copy_scan())
         self.assertIn("Must specify either output or output_dirs, not both",
                       str(exc.exception))
 
@@ -949,8 +955,9 @@ U_BOOT_DRVINFO(spl_test2) = {
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(2, len(fnames))
 
-        dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], None,
-                               warning_disabled=True, scan=copy_scan())
+        dtb_platdata.run_steps(
+            ['all'], dtb_file, False, None, [outdir], None, False,
+            warning_disabled=True, scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
         self.assertEqual(4, len(fnames))
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 45/49] dm: of-platadata: Add option for device instantiation
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (43 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 44/49] dtoc: Add an option for device instantiation Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2021-01-06  3:39   ` Walter Lozano
  2020-12-29  3:35 ` [PATCH 46/49] dtoc: Add support for decl file Simon Glass
                   ` (23 subsequent siblings)
  68 siblings, 1 reply; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add Kconfig options to support build-time device instantiation. When
fully implemented, this will allow dtoc to create U-Boot devices (i.e.
struct udevice records) at build time, thus reducing code space in
SPL.

For now this defaults to off, but will be enabled when the rest of
the implementation is in place.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 dts/Kconfig          | 23 +++++++++++++++++++++--
 scripts/Makefile.spl |  4 ++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/dts/Kconfig b/dts/Kconfig
index 71f50552e4f..e861ea48d01 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -355,15 +355,24 @@ config SPL_OF_PLATDATA
 	  compatible string, then adding platform data and U_BOOT_DRVINFO
 	  declarations for each node. See of-plat.txt for more information.
 
+if SPL_OF_PLATDATA
+
 config SPL_OF_PLATDATA_PARENT
 	bool "Support parent information in devices"
-	depends on SPL_OF_PLATDATA
 	default y
 	help
 	  Generally it is useful to be able to access the parent of a device
 	  with of-platdata. To save space this can be disabled, but in that
 	  case dev_get_parent() will always return NULL;
 
+config SPL_OF_PLATDATA_INST
+	bool "Declare devices at build time"
+	help
+	  Declare devices as udevice instances so that they do not need to be
+	  bound when U-Boot starts. This can save time and code space.
+
+endif
+
 config TPL_OF_PLATDATA
 	bool "Generate platform data for use in TPL"
 	depends on TPL_OF_CONTROL
@@ -385,13 +394,23 @@ config TPL_OF_PLATDATA
 	  compatible string, then adding platform data and U_BOOT_DRVINFO
 	  declarations for each node. See of-plat.txt for more information.
 
+if TPL_OF_PLATDATA
+
 config TPL_OF_PLATDATA_PARENT
 	bool "Support parent information in devices"
-	depends on TPL_OF_PLATDATA
 	default y
 	help
 	  Generally it is useful to be able to access the parent of a device
 	  with of-platdata. To save space this can be disabled, but in that
 	  case dev_get_parent() will always return NULL;
 
+config TPL_OF_PLATDATA_INST
+	bool "Declare devices at build time"
+
+	help
+	  Declare devices as udevice instances so that they do not need to be
+	  bound when U-Boot starts. This can save time and code space.
+
+endif
+
 endmenu
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 72c0ad82793..6ca33abf348 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -311,6 +311,10 @@ pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
 	-d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
 
+ifneq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA_INST),)
+DTOC_ARGS += -i
+endif
+
 quiet_cmd_dtoc = DTOC    $@
 cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 46/49] dtoc: Add support for decl file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (44 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 45/49] dm: of-platadata: Add " Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 47/49] dtoc: Don't generate platform data with instantiation Simon Glass
                   ` (22 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add an option to generate the declaration file, which declares all
drivers and uclasses, so references can be used in the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 36 +++++++++++++++
 tools/dtoc/test_dtoc.py    | 91 +++++++++++++++++++++++++++++++++++---
 2 files changed, 120 insertions(+), 7 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 46e2725a86c..040b7246787 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -689,6 +689,39 @@ class DtbPlatdata():
             elif result is False:
                 print("Could not find uclass for alias '%s'" % prop.name)
 
+    def generate_decl(self):
+        nodes_to_output = list(self._valid_nodes)
+
+        self.buf('#include <dm/device-internal.h>\n')
+        self.buf('#include <dm/uclass-internal.h>\n')
+        self.buf('\n')
+        self.buf(
+            '/* driver declarations - these allow DM_DRIVER_GET() to be used */\n')
+        for node in nodes_to_output:
+            self.buf('DM_DRIVER_DECL(%s);\n' % node.struct_name);
+        self.buf('\n')
+
+        if self._instantiate:
+            self.buf(
+                '/* device declarations - these allow DM_DEVICE_REF() to be used */\n')
+            for node in nodes_to_output:
+                self.buf('DM_DEVICE_DECL(%s);\n' % node.var_name)
+            self.buf('\n')
+
+        uclass_list = self._valid_uclasses
+
+        self.buf(
+            '/* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */\n')
+        for uclass in uclass_list:
+            self.buf('DM_UCLASS_DRIVER_DECL(%s);\n' % uclass.name)
+
+        if self._instantiate:
+            self.buf('\n')
+            self.buf('/* uclass declarations - needed for DM_UCLASS_REF() */\n')
+            for uclass in uclass_list:
+                self.buf('DM_UCLASS_DECL(%s);\n' % uclass.name)
+        self.out(''.join(self.get_buf()))
+
     def assign_seqs(self):
         """Assign a sequence number to each node"""
         for node in self._valid_nodes_unsorted:
@@ -794,6 +827,9 @@ class DtbPlatdata():
 # key: Command used to generate this file
 # value: OutputFile for this command
 OUTPUT_FILES = {
+    'decl':
+        OutputFile(Ftype.HEADER, 'dt-decl.h', DtbPlatdata.generate_decl,
+                   'Declares externs for all device/uclass instances'),
     'struct':
         OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
                    DtbPlatdata.generate_structs,
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index fb5ec8abc8d..f241a94091c 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -40,6 +40,14 @@ HEADER = '''/*
 #include <stdbool.h>
 #include <linux/libfdt.h>'''
 
+DECL_HEADER = '''/*
+ * DO NOT MODIFY
+ *
+ * Declares externs for all device/uclass instances.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
+ */
+'''
+
 C_HEADER = '''/*
  * DO NOT MODIFY
  *
@@ -213,6 +221,54 @@ class TestDtoc(unittest.TestCase):
             lines = infile.read().splitlines()
         self.assertEqual(C_HEADER.splitlines() + [''], lines)
 
+    decl_text = DECL_HEADER + '''
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+
+/* driver declarations - these allow DM_DRIVER_GET() to be used */
+DM_DRIVER_DECL(sandbox_i2c);
+DM_DRIVER_DECL(sandbox_pmic);
+DM_DRIVER_DECL(sandbox_spl_test);
+DM_DRIVER_DECL(sandbox_spl_test);
+DM_DRIVER_DECL(sandbox_spl_test);
+
+/* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */
+DM_UCLASS_DRIVER_DECL(i2c);
+DM_UCLASS_DRIVER_DECL(misc);
+DM_UCLASS_DRIVER_DECL(pmic);
+'''
+    decl_text_inst = DECL_HEADER + '''
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+
+/* driver declarations - these allow DM_DRIVER_GET() to be used */
+DM_DRIVER_DECL(sandbox_i2c);
+DM_DRIVER_DECL(sandbox_pmic);
+DM_DRIVER_DECL(root_driver);
+DM_DRIVER_DECL(sandbox_spl_test);
+DM_DRIVER_DECL(sandbox_spl_test);
+DM_DRIVER_DECL(sandbox_spl_test);
+
+/* device declarations - these allow DM_DEVICE_REF() to be used */
+DM_DEVICE_DECL(i2c_at_0);
+DM_DEVICE_DECL(pmic_at_9);
+DM_DEVICE_DECL(root);
+DM_DEVICE_DECL(spl_test);
+DM_DEVICE_DECL(spl_test2);
+DM_DEVICE_DECL(spl_test3);
+
+/* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */
+DM_UCLASS_DRIVER_DECL(i2c);
+DM_UCLASS_DRIVER_DECL(misc);
+DM_UCLASS_DRIVER_DECL(pmic);
+DM_UCLASS_DRIVER_DECL(root);
+
+/* uclass declarations - needed for DM_UCLASS_REF() */
+DM_UCLASS_DECL(i2c);
+DM_UCLASS_DECL(misc);
+DM_UCLASS_DECL(pmic);
+DM_UCLASS_DECL(root);
+'''
     struct_text = HEADER + '''
 struct dtd_sandbox_i2c {
 };
@@ -327,10 +383,17 @@ U_BOOT_DRVINFO(spl_test3) = {
 
         self._check_strings(self.platdata_text, data)
 
+        self.run_test(['decl'], dtb_file, output)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(self.decl_text, data)
+
         # Try the 'all' command
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
-        self._check_strings(self.platdata_text + self.struct_text, data)
+        self._check_strings(self.decl_text + self.platdata_text +
+                            self.struct_text, data)
 
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
@@ -916,7 +979,8 @@ U_BOOT_DRVINFO(spl_test2) = {
         output = tools.GetOutputFilename('output')
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
-        self._check_strings(self.platdata_text + self.struct_text, data)
+        self._check_strings(self.decl_text + self.platdata_text +
+                            self.struct_text, data)
 
     def test_no_command(self):
         """Test running dtoc without a command"""
@@ -930,9 +994,10 @@ U_BOOT_DRVINFO(spl_test2) = {
         dtb_file = get_dtb_file('dtoc_test_simple.dts')
         output = tools.GetOutputFilename('output')
         with self.assertRaises(ValueError) as exc:
-            self.run_test(['invalid-cmd'], dtb_file, output, False)
-        self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
-                      str(exc.exception))
+            self.run_test(['invalid-cmd'], dtb_file, output)
+        self.assertIn(
+            "Unknown command 'invalid-cmd': (use: decl, platdata, struct)",
+            str(exc.exception))
 
     def test_output_conflict(self):
         """Test a conflict between and output dirs and output file"""
@@ -959,11 +1024,12 @@ U_BOOT_DRVINFO(spl_test2) = {
             ['all'], dtb_file, False, None, [outdir], None, False,
             warning_disabled=True, scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
-        self.assertEqual(4, len(fnames))
+        self.assertEqual(5, len(fnames))
 
         leafs = set(os.path.basename(fname) for fname in fnames)
         self.assertEqual(
-            {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'},
+            {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb',
+             'dt-decl.h'},
             leafs)
 
     def setup_process_test(self):
@@ -1147,3 +1213,14 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.assertIn(root, plat._valid_nodes)
         self.assertEqual('root_driver',
                          scan.get_normalized_compat_name(root)[0])
+
+    def test_simple_inst(self):
+        """Test output from some simple nodes with instantiate enabled"""
+        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        output = tools.GetOutputFilename('output')
+
+        self.run_test(['decl'], dtb_file, output, True)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(self.decl_text_inst, data)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 47/49] dtoc: Don't generate platform data with instantiation
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (45 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 46/49] dtoc: Add support for decl file Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 48/49] dtoc: Generate uclass devices Simon Glass
                   ` (21 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

This file is not used when instantiating devices. Update dtoc to skip
generating its contents and just add a comment instead.

Also it is useful to see the driver name and parent for each device.
Update the file to show that information, to avoid updating the same
tests twice.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 35 ++++++++++++++++++++++---
 tools/dtoc/test_dtoc.py    | 53 +++++++++++++++++++++++++++++++-------
 2 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 040b7246787..befe7c14901 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -786,19 +786,46 @@ class DtbPlatdata():
             uclass.node_refs[-1] = ref
             uclass.node_refs[len(uclass.devs)] = ref
 
-    def output_node(self, node):
+    def output_node_plat(self, node):
         """Output the C code for a node
 
         Args:
             node (fdt.Node): node to output
         """
-        self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
+        driver = node.driver
+        parent_driver = node.parent_driver
+
+        line1 = 'Node %s index %d' % (node.path, node.idx)
+        if driver:
+            self.buf('/*\n')
+            self.buf(' * %s\n' % line1)
+            self.buf(' * driver %s parent %s\n' % (driver.name,
+                parent_driver.name if parent_driver else 'None'))
+            self.buf(' */\n')
+        else:
+            self.buf('/* %s */\n' % line1)
 
         self._output_values(node)
         self._declare_device(node)
 
         self.out(''.join(self.get_buf()))
 
+    def check_instantiate(self, require):
+        """Check if self._instantiate is set to the required value
+
+        If not, this outputs a message into the current file
+
+        Args:
+            require: True to require --instantiate, False to require that it not
+                be enabled
+        """
+        if require != self._instantiate:
+            self.out(
+                '/* This file is not used: --instantiate was %senabled */\n' %
+                ('not ' if require else ''))
+            return False
+        return True
+
     def generate_plat(self):
         """Generate device defintions for the platform data
 
@@ -809,6 +836,8 @@ class DtbPlatdata():
         See the documentation in doc/driver-model/of-plat.rst for more
         information.
         """
+        if not self.check_instantiate(False):
+            return
         self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
         self.out('#define DT_PLAT_C\n')
         self.out('\n')
@@ -818,7 +847,7 @@ class DtbPlatdata():
         self.out('\n')
 
         for node in self._valid_nodes:
-            self.output_node(node)
+            self.output_node_plat(node)
 
         self.out(''.join(self.get_buf()))
 
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index f241a94091c..1381c7eded3 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -48,13 +48,15 @@ DECL_HEADER = '''/*
  */
 '''
 
-C_HEADER = '''/*
+C_HEADER_PRE = '''/*
  * DO NOT MODIFY
  *
  * Declares the U_BOOT_DRIVER() records and platform data.
  * This was generated by dtoc from a .dtb (device tree binary) file.
  */
+'''
 
+C_HEADER = C_HEADER_PRE + '''
 /* Allow use of U_BOOT_DRVINFO() in this file */
 #define DT_PLAT_C
 
@@ -289,9 +291,11 @@ struct dtd_sandbox_spl_test {
 \tconst char *\tstringval;
 };
 '''
-
     platdata_text = C_HEADER + '''
-/* Node /i2c at 0 index 0 */
+/*
+ * Node /i2c at 0 index 0
+ * driver sandbox_i2c parent None
+ */
 static struct dtd_sandbox_i2c dtv_i2c_at_0 = {
 };
 U_BOOT_DRVINFO(i2c_at_0) = {
@@ -301,7 +305,10 @@ U_BOOT_DRVINFO(i2c_at_0) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /i2c at 0/pmic at 9 index 1 */
+/*
+ * Node /i2c at 0/pmic at 9 index 1
+ * driver sandbox_pmic parent sandbox_i2c
+ */
 static struct dtd_sandbox_pmic dtv_pmic_at_9 = {
 \t.low_power\t\t= true,
 \t.reg\t\t\t= {0x9, 0x0},
@@ -313,7 +320,10 @@ U_BOOT_DRVINFO(pmic_at_9) = {
 \t.parent_idx\t= 0,
 };
 
-/* Node /spl-test index 2 */
+/*
+ * Node /spl-test index 2
+ * driver sandbox_spl_test parent None
+ */
 static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.boolval\t\t= true,
 \t.bytearray\t\t= {0x6, 0x0, 0x0},
@@ -333,7 +343,10 @@ U_BOOT_DRVINFO(spl_test) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /spl-test2 index 3 */
+/*
+ * Node /spl-test2 index 3
+ * driver sandbox_spl_test parent None
+ */
 static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.acpi_name\t\t= "\\\\_SB.GPO0",
 \t.bytearray\t\t= {0x1, 0x23, 0x34},
@@ -352,7 +365,10 @@ U_BOOT_DRVINFO(spl_test2) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /spl-test3 index 4 */
+/*
+ * Node /spl-test3 index 4
+ * driver sandbox_spl_test parent None
+ */
 static struct dtd_sandbox_spl_test dtv_spl_test3 = {
 \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
 \t\t0x0},
@@ -414,7 +430,10 @@ struct dtd_sandbox_gpio {
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
-/* Node /gpios at 0 index 0 */
+/*
+ * Node /gpios at 0 index 0
+ * driver sandbox_gpio parent None
+ */
 static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
 \t.gpio_bank_name\t\t= "a",
 \t.gpio_controller\t= true,
@@ -942,7 +961,10 @@ struct dtd_sandbox_spl_test {
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
-/* Node /spl-test index 0 */
+/*
+ * Node /spl-test index 0
+ * driver sandbox_spl_test parent None
+ */
 static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.intval\t\t\t= 0x1,
 };
@@ -953,7 +975,10 @@ U_BOOT_DRVINFO(spl_test) = {
 \t.parent_idx\t= -1,
 };
 
-/* Node /spl-test2 index 1 */
+/*
+ * Node /spl-test2 index 1
+ * driver sandbox_spl_test parent None
+ */
 static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.intarray\t\t= 0x5,
 };
@@ -1224,3 +1249,11 @@ U_BOOT_DRVINFO(spl_test2) = {
             data = infile.read()
 
         self._check_strings(self.decl_text_inst, data)
+
+        self.run_test(['platdata'], dtb_file, output, True)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(C_HEADER_PRE + '''
+/* This file is not used: --instantiate was enabled */
+''', data)
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 48/49] dtoc: Generate uclass devices
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (46 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 47/49] dtoc: Don't generate platform data with instantiation Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2020-12-29  3:35 ` [PATCH 49/49] dtoc: Generate device instances Simon Glass
                   ` (20 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add support for generating a file containing uclass instances. This avoids
the need to create these at run time.

Update a test uclass to include a 'priv_auto' member, to increase test
coverage.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/test_drv.c    |   1 +
 include/dm/test.h          |   5 ++
 tools/dtoc/dtb_platdata.py |  93 +++++++++++++++++++++
 tools/dtoc/test_dtoc.py    | 164 ++++++++++++++++++++++++++++++++++---
 4 files changed, 250 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index ac762fd9fea..c516d6a262d 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -204,6 +204,7 @@ UCLASS_DRIVER(testfdt) = {
 	.name		= "testfdt",
 	.id		= UCLASS_TEST_FDT,
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
+	.priv_auto	= sizeof(struct dm_test_uc_priv),
 };
 
 static const struct udevice_id testfdtm_ids[] = {
diff --git a/include/dm/test.h b/include/dm/test.h
index 6ac6672cd6f..c37085e9264 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -71,6 +71,11 @@ struct dm_test_priv {
 	int uclass_postp;
 };
 
+/* struct dm_test_uc_priv - private data for the testdrv uclass */
+struct dm_test_uc_priv {
+	int dummy;
+};
+
 /**
  * struct dm_test_perdev_class_priv - private per-device data for test uclass
  */
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index befe7c14901..069f1295a0c 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -232,6 +232,7 @@ class DtbPlatdata():
         """
         if self._outfile != sys.stdout:
             self._outfile.close()
+            self._outfile = None
 
     def out(self, line):
         """Output a string to the output file
@@ -635,6 +636,27 @@ class DtbPlatdata():
         self.buf('};\n')
         self.buf('\n')
 
+    def prep_priv(self, struc, name, suffix, section='.priv_data'):
+        if not struc:
+            return None
+        var_name = '_%s%s' % (name, suffix)
+        hdr = self._scan._structs.get(struc)
+        if hdr:
+            self.buf('#include <%s>\n' % hdr.fname)
+        else:
+            print('Warning: Cannot find header file for struct %s' % struc)
+        attr = '__attribute__ ((section ("%s")))' % section
+        return var_name, struc, attr
+
+    def alloc_priv(self, info, name, extra, suffix='_priv'):
+        result = self.prep_priv(info, name, suffix)
+        if not result:
+            return None
+        var_name, struc, section = result
+        self.buf('u8 %s_%s[sizeof(struct %s)]\n\t%s;\n' %
+                 (var_name, extra, struc.strip(), section))
+        return '%s_%s' % (var_name, extra)
+
     def _output_prop(self, node, prop):
         """Output a line containing the value of a struct member
 
@@ -666,6 +688,74 @@ class DtbPlatdata():
             self._output_prop(node, node.props[pname])
         self.buf('};\n')
 
+    def list_head(self, head_member, node_member, node_refs, var_name):
+        self.buf('\t.%s\t= {\n' % head_member)
+        if node_refs:
+            last = node_refs[-1].dev_ref
+            first = node_refs[0].dev_ref
+            member = node_member
+        else:
+            last = 'DM_DEVICE_REF(%s)' % var_name
+            first = last
+            member = head_member
+        self.buf('\t\t.prev = &%s->%s,\n' % (last, member))
+        self.buf('\t\t.next = &%s->%s,\n' % (first, member))
+        self.buf('\t},\n')
+
+    def list_node(self, member, node_refs, seq):
+        self.buf('\t.%s\t= {\n' % member)
+        self.buf('\t\t.prev = %s,\n' % node_refs[seq - 1])
+        self.buf('\t\t.next = %s,\n' % node_refs[seq + 1])
+        self.buf('\t},\n')
+
+    def generate_uclasses(self):
+        if not self.check_instantiate(True):
+            return
+        self.out('\n')
+        self.out('#include <common.h>\n')
+        self.out('#include <dm.h>\n')
+        self.out('#include <dt-structs.h>\n')
+        self.out('\n')
+        self.buf('/*\n')
+        self.buf(' * uclass declarations\n')
+        self.buf(' *\n')
+        self.buf(' * Sequence numbers:\n')
+        uclass_list = self._valid_uclasses
+        for uclass in uclass_list:
+            if uclass.alias_num_to_node:
+                self.buf(' * %s: %s\n' % (uclass.name, uclass.uclass_id))
+                for seq, node in uclass.alias_num_to_node.items():
+                    self.buf(' *    %d: %s\n' % (seq, node.path))
+        self.buf(' */\n')
+
+        uclass_node = {}
+        for seq, uclass in enumerate(uclass_list):
+            uclass_node[seq] = ('&DM_UCLASS_REF(%s)->sibling_node' %
+                                uclass.name)
+        uclass_node[-1] = '&uclass_head'
+        uclass_node[len(uclass_list)] = '&uclass_head'
+        self.buf('\n')
+        self.buf('struct list_head %s = {\n' % 'uclass_head')
+        self.buf('\t.prev = %s,\n' % uclass_node[len(uclass_list) -1])
+        self.buf('\t.next = %s,\n' % uclass_node[0])
+        self.buf('};\n')
+        self.buf('\n')
+
+        for seq, uclass in enumerate(uclass_list):
+            uc_drv = self._scan._uclass.get(uclass.uclass_id)
+
+            priv_name = self.alloc_priv(uc_drv.priv, uc_drv.name, '')
+
+            self.buf('DM_UCLASS_INST(%s) = {\n' % uclass.name)
+            if priv_name:
+                self.buf('\t.priv_\t\t= %s,\n' % priv_name)
+            self.buf('\t.uc_drv\t\t= DM_UCLASS_DRIVER_REF(%s),\n' % uclass.name)
+            self.list_node('sibling_node', uclass_node, seq)
+            self.list_head('dev_head', 'uclass_node', uc_drv.devs, None)
+            self.buf('};\n')
+            self.buf('\n')
+        self.out(''.join(self.get_buf()))
+
     def read_aliases(self):
         """Read the aliases and attach the information to self._alias
 
@@ -866,6 +956,9 @@ OUTPUT_FILES = {
     'platdata':
         OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat,
                    'Declares the U_BOOT_DRIVER() records and platform data'),
+    'uclass':
+        OutputFile(Ftype.SOURCE, 'dt-uclass.c', DtbPlatdata.generate_uclasses,
+                   'Declares the uclass instances (struct uclass)'),
     }
 
 
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 1381c7eded3..352753a1e3a 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -16,6 +16,7 @@ import os
 import struct
 import unittest
 
+from dtb_platdata import Ftype
 from dtb_platdata import get_value
 from dtb_platdata import tab_to
 from dtoc import dtb_platdata
@@ -65,6 +66,18 @@ C_HEADER = C_HEADER_PRE + '''
 #include <dt-structs.h>
 '''
 
+UCLASS_HEADER_COMMON = '''/*
+ * DO NOT MODIFY
+ *
+ * Declares the uclass instances (struct uclass).
+ * This was generated by dtoc from a .dtb (device tree binary) file.
+ */
+'''
+
+UCLASS_HEADER = UCLASS_HEADER_COMMON + '''
+/* This file is not used: --instantiate was not enabled */
+'''
+
 # Scanner saved from a previous run of the tests (to speed things up)
 saved_scan = None
 
@@ -245,31 +258,35 @@ DM_UCLASS_DRIVER_DECL(pmic);
 
 /* driver declarations - these allow DM_DRIVER_GET() to be used */
 DM_DRIVER_DECL(sandbox_i2c);
-DM_DRIVER_DECL(sandbox_pmic);
 DM_DRIVER_DECL(root_driver);
+DM_DRIVER_DECL(denx_u_boot_test_bus);
 DM_DRIVER_DECL(sandbox_spl_test);
 DM_DRIVER_DECL(sandbox_spl_test);
-DM_DRIVER_DECL(sandbox_spl_test);
+DM_DRIVER_DECL(denx_u_boot_fdt_test);
+DM_DRIVER_DECL(denx_u_boot_fdt_test);
 
 /* device declarations - these allow DM_DEVICE_REF() to be used */
-DM_DEVICE_DECL(i2c_at_0);
-DM_DEVICE_DECL(pmic_at_9);
+DM_DEVICE_DECL(i2c);
 DM_DEVICE_DECL(root);
+DM_DEVICE_DECL(some_bus);
 DM_DEVICE_DECL(spl_test);
-DM_DEVICE_DECL(spl_test2);
 DM_DEVICE_DECL(spl_test3);
+DM_DEVICE_DECL(test);
+DM_DEVICE_DECL(test0);
 
 /* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */
 DM_UCLASS_DRIVER_DECL(i2c);
 DM_UCLASS_DRIVER_DECL(misc);
-DM_UCLASS_DRIVER_DECL(pmic);
 DM_UCLASS_DRIVER_DECL(root);
+DM_UCLASS_DRIVER_DECL(testbus);
+DM_UCLASS_DRIVER_DECL(testfdt);
 
 /* uclass declarations - needed for DM_UCLASS_REF() */
 DM_UCLASS_DECL(i2c);
 DM_UCLASS_DECL(misc);
-DM_UCLASS_DECL(pmic);
 DM_UCLASS_DECL(root);
+DM_UCLASS_DECL(testbus);
+DM_UCLASS_DECL(testfdt);
 '''
     struct_text = HEADER + '''
 struct dtd_sandbox_i2c {
@@ -381,6 +398,101 @@ U_BOOT_DRVINFO(spl_test3) = {
 \t.parent_idx\t= -1,
 };
 
+'''
+    uclass_text = UCLASS_HEADER
+    uclass_text_inst = '''
+
+#include <common.h>
+#include <dm.h>
+#include <dt-structs.h>
+
+/*
+ * uclass declarations
+ *
+ * Sequence numbers:
+ * i2c: UCLASS_I2C
+ *    4: /i2c
+ * misc: UCLASS_MISC
+ *    0: /spl-test
+ *    1: /spl-test3
+ * root: UCLASS_ROOT
+ *    0: /
+ * testbus: UCLASS_TEST_BUS
+ *    2: /some-bus
+ * testfdt: UCLASS_TEST_FDT
+ *    1: /some-bus/test
+ *    2: /some-bus/test0
+ */
+
+struct list_head uclass_head = {
+	.prev = &DM_UCLASS_REF(testfdt)->sibling_node,
+	.next = &DM_UCLASS_REF(i2c)->sibling_node,
+};
+
+DM_UCLASS_INST(i2c) = {
+	.uc_drv		= DM_UCLASS_DRIVER_REF(i2c),
+	.sibling_node	= {
+		.prev = &uclass_head,
+		.next = &DM_UCLASS_REF(misc)->sibling_node,
+	},
+	.dev_head	= {
+		.prev = &DM_DEVICE_REF(i2c)->uclass_node,
+		.next = &DM_DEVICE_REF(i2c)->uclass_node,
+	},
+};
+
+DM_UCLASS_INST(misc) = {
+	.uc_drv		= DM_UCLASS_DRIVER_REF(misc),
+	.sibling_node	= {
+		.prev = &DM_UCLASS_REF(i2c)->sibling_node,
+		.next = &DM_UCLASS_REF(root)->sibling_node,
+	},
+	.dev_head	= {
+		.prev = &DM_DEVICE_REF(spl_test3)->uclass_node,
+		.next = &DM_DEVICE_REF(spl_test)->uclass_node,
+	},
+};
+
+DM_UCLASS_INST(root) = {
+	.uc_drv		= DM_UCLASS_DRIVER_REF(root),
+	.sibling_node	= {
+		.prev = &DM_UCLASS_REF(misc)->sibling_node,
+		.next = &DM_UCLASS_REF(testbus)->sibling_node,
+	},
+	.dev_head	= {
+		.prev = &DM_DEVICE_REF(root)->uclass_node,
+		.next = &DM_DEVICE_REF(root)->uclass_node,
+	},
+};
+
+DM_UCLASS_INST(testbus) = {
+	.uc_drv		= DM_UCLASS_DRIVER_REF(testbus),
+	.sibling_node	= {
+		.prev = &DM_UCLASS_REF(root)->sibling_node,
+		.next = &DM_UCLASS_REF(testfdt)->sibling_node,
+	},
+	.dev_head	= {
+		.prev = &DM_DEVICE_REF(some_bus)->uclass_node,
+		.next = &DM_DEVICE_REF(some_bus)->uclass_node,
+	},
+};
+
+#include <dm/test.h>
+u8 _testfdt_priv_[sizeof(struct dm_test_uc_priv)]
+	__attribute__ ((section (".priv_data")));
+DM_UCLASS_INST(testfdt) = {
+	.priv_		= _testfdt_priv_,
+	.uc_drv		= DM_UCLASS_DRIVER_REF(testfdt),
+	.sibling_node	= {
+		.prev = &DM_UCLASS_REF(testbus)->sibling_node,
+		.next = &uclass_head,
+	},
+	.dev_head	= {
+		.prev = &DM_DEVICE_REF(test0)->uclass_node,
+		.next = &DM_DEVICE_REF(test)->uclass_node,
+	},
+};
+
 '''
 
     def test_simple(self):
@@ -409,7 +521,7 @@ U_BOOT_DRVINFO(spl_test3) = {
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
         self._check_strings(self.decl_text + self.platdata_text +
-                            self.struct_text, data)
+                            self.struct_text + self.uclass_text, data)
 
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
@@ -1005,7 +1117,7 @@ U_BOOT_DRVINFO(spl_test2) = {
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
         self._check_strings(self.decl_text + self.platdata_text +
-                            self.struct_text, data)
+                            self.struct_text + self.uclass_text, data)
 
     def test_no_command(self):
         """Test running dtoc without a command"""
@@ -1021,7 +1133,7 @@ U_BOOT_DRVINFO(spl_test2) = {
         with self.assertRaises(ValueError) as exc:
             self.run_test(['invalid-cmd'], dtb_file, output)
         self.assertIn(
-            "Unknown command 'invalid-cmd': (use: decl, platdata, struct)",
+            "Unknown command 'invalid-cmd': (use: decl, platdata, struct, uclass)",
             str(exc.exception))
 
     def test_output_conflict(self):
@@ -1049,12 +1161,12 @@ U_BOOT_DRVINFO(spl_test2) = {
             ['all'], dtb_file, False, None, [outdir], None, False,
             warning_disabled=True, scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
-        self.assertEqual(5, len(fnames))
+        self.assertEqual(6, len(fnames))
 
         leafs = set(os.path.basename(fname) for fname in fnames)
         self.assertEqual(
             {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb',
-             'dt-decl.h'},
+             'dt-uclass.c', 'dt-decl.h'},
             leafs)
 
     def setup_process_test(self):
@@ -1241,7 +1353,7 @@ U_BOOT_DRVINFO(spl_test2) = {
 
     def test_simple_inst(self):
         """Test output from some simple nodes with instantiate enabled"""
-        dtb_file = get_dtb_file('dtoc_test_simple.dts')
+        dtb_file = get_dtb_file('dtoc_test_inst.dts')
         output = tools.GetOutputFilename('output')
 
         self.run_test(['decl'], dtb_file, output, True)
@@ -1257,3 +1369,29 @@ U_BOOT_DRVINFO(spl_test2) = {
         self._check_strings(C_HEADER_PRE + '''
 /* This file is not used: --instantiate was enabled */
 ''', data)
+
+        self.run_test(['uclass'], dtb_file, output, True)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(UCLASS_HEADER_COMMON + self.uclass_text_inst, data)
+
+    def test_inst_no_hdr(self):
+        """Test dealing with a struct that has no header"""
+        dtb_file = get_dtb_file('dtoc_test_inst.dts')
+        output = tools.GetOutputFilename('output')
+
+        # Run it once to set everything up
+        plat = self.run_test(['decl'], dtb_file, output, True)
+        scan = plat._scan
+
+        # Restart the output file and delete any record of the uclass' struct
+        plat.setup_output(Ftype.SOURCE, output)
+        del scan._structs['dm_test_uc_priv']
+
+        # Now generate the uclasses, which should provide a warning
+        with test_util.capture_sys_output() as (stdout, _):
+            plat.generate_uclasses()
+        self.assertEqual(
+            'Warning: Cannot find header file for struct dm_test_uc_priv',
+            stdout.getvalue().strip())
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 49/49] dtoc: Generate device instances
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (47 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 48/49] dtoc: Generate uclass devices Simon Glass
@ 2020-12-29  3:35 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
                   ` (19 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2020-12-29  3:35 UTC (permalink / raw)
  To: u-boot

Add support for generating a file containing udevice instances. This
avoids the need to create these at run time.

Update a test uclass to include a 'per_device_plat_auto' member, to
increase test coverage.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/test_drv.c    |   4 +
 tools/dtoc/dtb_platdata.py | 145 +++++++++++++++++-
 tools/dtoc/test_dtoc.py    | 303 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 442 insertions(+), 10 deletions(-)

diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index c516d6a262d..a6dd013e319 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -97,6 +97,7 @@ U_BOOT_DRIVER(denx_u_boot_test_bus) = {
 	.per_child_plat_auto	= sizeof(struct dm_test_parent_plat),
 	.child_pre_probe = testbus_child_pre_probe,
 	.child_post_remove = testbus_child_post_remove,
+	DM_HEADER(<test.h>)
 };
 
 UCLASS_DRIVER(testbus) = {
@@ -105,6 +106,9 @@ UCLASS_DRIVER(testbus) = {
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 	.child_pre_probe = testbus_child_pre_probe_uclass,
 	.child_post_probe = testbus_child_post_probe_uclass,
+
+	/* This is for dtoc testing only */
+	.per_device_plat_auto   = sizeof(struct dm_test_uclass_priv),
 };
 
 static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 069f1295a0c..4b56be681b3 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -657,7 +657,104 @@ class DtbPlatdata():
                  (var_name, extra, struc.strip(), section))
         return '%s_%s' % (var_name, extra)
 
-    def _output_prop(self, node, prop):
+    def alloc_plat(self, info, name, extra, node):
+        result = self.prep_priv(info, name, '_plat')
+        if not result:
+            return None
+        var_name, struc, section = result
+        self.buf('struct %s %s\n\t%s_%s = {\n' %
+                 (struc.strip(), section, var_name, extra))
+        self.buf('\t.dtplat = {\n')
+        for pname in sorted(node.props):
+            self._output_prop(node, node.props[pname], 2)
+        self.buf('\t},\n')
+        self.buf('};\n')
+        return '&%s_%s' % (var_name, extra)
+
+    def _declare_device_inst(self, node, parent_driver):
+        """Add a device instance declaration to the output
+
+        This declares a DM_DEVICE_INST() for the device being processed
+
+        Args:
+            node: Node to output
+        """
+        driver = node.driver
+        uclass = node.uclass
+        self.buf('\n')
+        num_lines = len(self._lines)
+        plat_name = self.alloc_plat(driver.plat, driver.name, node.var_name,
+                                    node)
+        priv_name = self.alloc_priv(driver.priv, driver.name, node.var_name)
+        parent_plat_name = None
+        parent_priv_name = None
+        if parent_driver:
+            # TODO: deal with uclass providing these values
+            parent_plat_name = self.alloc_priv(
+                parent_driver.child_plat, driver.name, node.var_name,
+                '_parent_plat')
+            parent_priv_name = self.alloc_priv(
+                parent_driver.child_priv, driver.name, node.var_name,
+                '_parent_priv')
+        uclass_plat_name = self.alloc_priv(uclass.per_dev_plat, driver.name,
+                                           node.var_name)
+        uclass_priv_name = self.alloc_priv(uclass.per_dev_priv,
+                                           driver.name + '_uc', node.var_name)
+        for hdr in driver.headers:
+            self.buf('#include %s\n' % hdr)
+
+        # Add a blank line if we emitted any stuff above, for readability
+        if num_lines != len(self._lines):
+            self.buf('\n')
+
+        self.buf('DM_DEVICE_INST(%s) = {\n' % node.var_name)
+        self.buf('\t.driver\t\t= DM_DRIVER_REF(%s),\n' % node.struct_name)
+        self.buf('\t.name\t\t= "%s",\n' % node.struct_name)
+        if plat_name:
+            self.buf('\t.plat_\t= %s,\n' % plat_name)
+        else:
+            self.buf('\t.plat_\t= &%s%s,\n' % (VAL_PREFIX, node.var_name))
+        if parent_plat_name:
+            self.buf('\t.parent_plat_ = %s,\n' % parent_plat_name)
+        if uclass_plat_name:
+            self.buf('\t.uclass_plat_ = %s,\n' % uclass_plat_name)
+        driver_date = None
+
+        if node != self._fdt.GetRoot():
+            compat_list = node.props['compatible'].value
+            if not isinstance(compat_list, list):
+                compat_list = [compat_list]
+            for compat in compat_list:
+                driver_data = driver.compat.get(compat)
+                if driver_data:
+                    self.buf('\t.driver_data\t= %s,\n' % driver_data)
+                    break
+
+        if node.parent and node.parent.parent:
+            self.buf('\t.parent\t\t= DM_DEVICE_REF(%s),\n' %
+                     node.parent.var_name)
+        if priv_name:
+            self.buf('\t.priv_\t\t= %s,\n' % priv_name)
+        self.buf('\t.uclass\t= DM_UCLASS_REF(%s),\n' % uclass.name)
+
+        if uclass_priv_name:
+            self.buf('\t.uclass_priv_ = %s,\n' % uclass_priv_name)
+        if parent_priv_name:
+            self.buf('\t.parent_priv_\t= %s,\n' % parent_priv_name)
+        self.list_node('uclass_node', uclass.node_refs, node.uclass_seq)
+        self.list_head('child_head', 'sibling_node', node.child_devs, node.var_name)
+        if node.parent in self._valid_nodes:
+            self.list_node('sibling_node', node.parent.child_refs,
+                           node.parent_seq)
+        # flags is left as 0
+
+        self.buf('\t.seq_ = %d,\n' % node.seq)
+
+        self.buf('};\n')
+        self.buf('\n')
+        return parent_plat_name
+
+    def _output_prop(self, node, prop, tabs=1):
         """Output a line containing the value of a struct member
 
         Args:
@@ -667,7 +764,7 @@ class DtbPlatdata():
         if prop.name in PROP_IGNORE_LIST or prop.name[0] == '#':
             return
         member_name = conv_name_to_c(prop.name)
-        self.buf('\t%s= ' % tab_to(3, '.' + member_name))
+        self.buf('%s%s= ' % ('\t' * tabs, tab_to(3, '.' + member_name)))
 
         # Special handling for lists
         if isinstance(prop.value, list):
@@ -900,6 +997,26 @@ class DtbPlatdata():
 
         self.out(''.join(self.get_buf()))
 
+    def output_node_instance(self, node):
+        """Output the C code for a node
+
+        Args:
+            node (fdt.Node): node to output
+        """
+        parent_driver = node.parent_driver
+
+        self.buf('/*\n')
+        self.buf(' * Node %s index %d\n' % (node.path, node.idx))
+        self.buf(' * driver %s parent %s\n' % (node.driver.name,
+                 parent_driver.name if parent_driver else 'None'))
+        self.buf('*/\n')
+
+        if not node.driver.plat:
+            self._output_values(node)
+        self._declare_device_inst(node, parent_driver)
+
+        self.out(''.join(self.get_buf()))
+
     def check_instantiate(self, require):
         """Check if self._instantiate is set to the required value
 
@@ -941,6 +1058,27 @@ class DtbPlatdata():
 
         self.out(''.join(self.get_buf()))
 
+    def generate_device(self):
+        """Generate device instances
+
+        This writes out DM_DEVICE_INST() records for each device in the
+        build.
+
+        See the documentation in doc/driver-model/of-plat.rst for more
+        information.
+        """
+        if not self.check_instantiate(True):
+            return
+        self.out('#include <common.h>\n')
+        self.out('#include <dm.h>\n')
+        self.out('#include <dt-structs.h>\n')
+        self.out('\n')
+
+        for node in self._valid_nodes:
+            self.output_node_instance(node)
+
+        self.out(''.join(self.get_buf()))
+
 
 # Types of output file we understand
 # key: Command used to generate this file
@@ -956,6 +1094,9 @@ OUTPUT_FILES = {
     'platdata':
         OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat,
                    'Declares the U_BOOT_DRIVER() records and platform data'),
+    'device':
+        OutputFile(Ftype.SOURCE, 'dt-device.c', DtbPlatdata.generate_device,
+                   'Declares the DM_DEVICE_INST() records'),
     'uclass':
         OutputFile(Ftype.SOURCE, 'dt-uclass.c', DtbPlatdata.generate_uclasses,
                    'Declares the uclass instances (struct uclass)'),
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 352753a1e3a..e6211bc37dc 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -493,6 +493,285 @@ DM_UCLASS_INST(testfdt) = {
 	},
 };
 
+'''
+    device_text = '''/*
+ * DO NOT MODIFY
+ *
+ * Declares the DM_DEVICE_INST() records.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
+ */
+
+/* This file is not used: --instantiate was not enabled */
+'''
+    device_text_inst = '''/*
+ * DO NOT MODIFY
+ *
+ * Declares the DM_DEVICE_INST() records.
+ * This was generated by dtoc from a .dtb (device tree binary) file.
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dt-structs.h>
+
+/*
+ * Node /i2c index 0
+ * driver sandbox_i2c parent root_driver
+*/
+static struct dtd_sandbox_i2c dtv_i2c = {
+	.intval			= 0x3,
+};
+
+#include <asm/i2c.h>
+u8 _sandbox_i2c_priv_i2c[sizeof(struct sandbox_i2c_priv)]
+	__attribute__ ((section (".priv_data")));
+#include <i2c.h>
+u8 _sandbox_i2c_uc_priv_i2c[sizeof(struct dm_i2c_bus)]
+	__attribute__ ((section (".priv_data")));
+
+DM_DEVICE_INST(i2c) = {
+	.driver		= DM_DRIVER_REF(sandbox_i2c),
+	.name		= "sandbox_i2c",
+	.plat_	= &dtv_i2c,
+	.priv_		= _sandbox_i2c_priv_i2c,
+	.uclass	= DM_UCLASS_REF(i2c),
+	.uclass_priv_ = _sandbox_i2c_uc_priv_i2c,
+	.uclass_node	= {
+		.prev = &DM_UCLASS_REF(i2c)->dev_head,
+		.next = &DM_UCLASS_REF(i2c)->dev_head,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(i2c)->child_head,
+		.next = &DM_DEVICE_REF(i2c)->child_head,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(root)->child_head,
+		.next = &DM_DEVICE_REF(some_bus)->sibling_node,
+	},
+	.seq_ = 4,
+};
+
+/*
+ * Node / index 1
+ * driver root_driver parent None
+*/
+static struct dtd_root_driver dtv_root = {
+};
+
+DM_DEVICE_INST(root) = {
+	.driver		= DM_DRIVER_REF(root_driver),
+	.name		= "root_driver",
+	.plat_	= &dtv_root,
+	.uclass	= DM_UCLASS_REF(root),
+	.uclass_node	= {
+		.prev = &DM_UCLASS_REF(root)->dev_head,
+		.next = &DM_UCLASS_REF(root)->dev_head,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(spl_test3)->sibling_node,
+		.next = &DM_DEVICE_REF(i2c)->sibling_node,
+	},
+	.seq_ = 0,
+};
+
+/*
+ * Node /some-bus index 2
+ * driver denx_u_boot_test_bus parent root_driver
+*/
+
+#include <dm/test.h>
+struct dm_test_pdata __attribute__ ((section (".priv_data")))
+	_denx_u_boot_test_bus_plat_some_bus = {
+	.dtplat = {
+		.ping_add		= 0x4,
+		.ping_expect		= 0x4,
+		.reg			= {0x3, 0x1},
+	},
+};
+#include <dm/test.h>
+u8 _denx_u_boot_test_bus_priv_some_bus[sizeof(struct dm_test_priv)]
+	__attribute__ ((section (".priv_data")));
+#include <dm/test.h>
+u8 _denx_u_boot_test_bus_priv_some_bus[sizeof(struct dm_test_uclass_priv)]
+	__attribute__ ((section (".priv_data")));
+#include <test.h>
+
+DM_DEVICE_INST(some_bus) = {
+	.driver		= DM_DRIVER_REF(denx_u_boot_test_bus),
+	.name		= "denx_u_boot_test_bus",
+	.plat_	= &_denx_u_boot_test_bus_plat_some_bus,
+	.uclass_plat_ = _denx_u_boot_test_bus_priv_some_bus,
+	.driver_data	= DM_TEST_TYPE_FIRST,
+	.priv_		= _denx_u_boot_test_bus_priv_some_bus,
+	.uclass	= DM_UCLASS_REF(testbus),
+	.uclass_node	= {
+		.prev = &DM_UCLASS_REF(testbus)->dev_head,
+		.next = &DM_UCLASS_REF(testbus)->dev_head,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(test0)->sibling_node,
+		.next = &DM_DEVICE_REF(test)->sibling_node,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(i2c)->sibling_node,
+		.next = &DM_DEVICE_REF(spl_test)->sibling_node,
+	},
+	.seq_ = 2,
+};
+
+/*
+ * Node /spl-test index 3
+ * driver sandbox_spl_test parent root_driver
+*/
+static struct dtd_sandbox_spl_test dtv_spl_test = {
+	.boolval		= true,
+	.intval			= 0x1,
+};
+
+DM_DEVICE_INST(spl_test) = {
+	.driver		= DM_DRIVER_REF(sandbox_spl_test),
+	.name		= "sandbox_spl_test",
+	.plat_	= &dtv_spl_test,
+	.uclass	= DM_UCLASS_REF(misc),
+	.uclass_node	= {
+		.prev = &DM_UCLASS_REF(misc)->dev_head,
+		.next = &DM_DEVICE_REF(spl_test3)->uclass_node,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(spl_test)->child_head,
+		.next = &DM_DEVICE_REF(spl_test)->child_head,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(some_bus)->sibling_node,
+		.next = &DM_DEVICE_REF(spl_test3)->sibling_node,
+	},
+	.seq_ = 0,
+};
+
+/*
+ * Node /spl-test3 index 4
+ * driver sandbox_spl_test parent root_driver
+*/
+static struct dtd_sandbox_spl_test dtv_spl_test3 = {
+	.longbytearray		= {0x90a0b0c, 0xd0e0f10},
+	.stringarray		= "one",
+};
+
+DM_DEVICE_INST(spl_test3) = {
+	.driver		= DM_DRIVER_REF(sandbox_spl_test),
+	.name		= "sandbox_spl_test",
+	.plat_	= &dtv_spl_test3,
+	.uclass	= DM_UCLASS_REF(misc),
+	.uclass_node	= {
+		.prev = &DM_DEVICE_REF(spl_test)->uclass_node,
+		.next = &DM_UCLASS_REF(misc)->dev_head,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(spl_test3)->child_head,
+		.next = &DM_DEVICE_REF(spl_test3)->child_head,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(spl_test)->sibling_node,
+		.next = &DM_DEVICE_REF(root)->child_head,
+	},
+	.seq_ = 1,
+};
+
+/*
+ * Node /some-bus/test index 5
+ * driver denx_u_boot_fdt_test parent denx_u_boot_test_bus
+*/
+
+#include <dm/test.h>
+struct dm_test_pdata __attribute__ ((section (".priv_data")))
+	_denx_u_boot_fdt_test_plat_test = {
+	.dtplat = {
+		.ping_add		= 0x5,
+		.ping_expect		= 0x5,
+		.reg			= {0x5, 0x0},
+	},
+};
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_priv_test[sizeof(struct dm_test_priv)]
+	__attribute__ ((section (".priv_data")));
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_parent_plat_test[sizeof(struct dm_test_parent_plat)]
+	__attribute__ ((section (".priv_data")));
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_parent_priv_test[sizeof(struct dm_test_parent_data)]
+	__attribute__ ((section (".priv_data")));
+
+DM_DEVICE_INST(test) = {
+	.driver		= DM_DRIVER_REF(denx_u_boot_fdt_test),
+	.name		= "denx_u_boot_fdt_test",
+	.plat_	= &_denx_u_boot_fdt_test_plat_test,
+	.parent_plat_ = _denx_u_boot_fdt_test_parent_plat_test,
+	.driver_data	= DM_TEST_TYPE_FIRST,
+	.parent		= DM_DEVICE_REF(some_bus),
+	.priv_		= _denx_u_boot_fdt_test_priv_test,
+	.uclass	= DM_UCLASS_REF(testfdt),
+	.parent_priv_	= _denx_u_boot_fdt_test_parent_priv_test,
+	.uclass_node	= {
+		.prev = &DM_UCLASS_REF(testfdt)->dev_head,
+		.next = &DM_DEVICE_REF(test0)->uclass_node,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(test)->child_head,
+		.next = &DM_DEVICE_REF(test)->child_head,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(some_bus)->child_head,
+		.next = &DM_DEVICE_REF(test0)->sibling_node,
+	},
+	.seq_ = 1,
+};
+
+/*
+ * Node /some-bus/test0 index 6
+ * driver denx_u_boot_fdt_test parent denx_u_boot_test_bus
+*/
+
+#include <dm/test.h>
+struct dm_test_pdata __attribute__ ((section (".priv_data")))
+	_denx_u_boot_fdt_test_plat_test0 = {
+	.dtplat = {
+	},
+};
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_priv_test0[sizeof(struct dm_test_priv)]
+	__attribute__ ((section (".priv_data")));
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_parent_plat_test0[sizeof(struct dm_test_parent_plat)]
+	__attribute__ ((section (".priv_data")));
+#include <dm/test.h>
+u8 _denx_u_boot_fdt_test_parent_priv_test0[sizeof(struct dm_test_parent_data)]
+	__attribute__ ((section (".priv_data")));
+
+DM_DEVICE_INST(test0) = {
+	.driver		= DM_DRIVER_REF(denx_u_boot_fdt_test),
+	.name		= "denx_u_boot_fdt_test",
+	.plat_	= &_denx_u_boot_fdt_test_plat_test0,
+	.parent_plat_ = _denx_u_boot_fdt_test_parent_plat_test0,
+	.driver_data	= DM_TEST_TYPE_SECOND,
+	.parent		= DM_DEVICE_REF(some_bus),
+	.priv_		= _denx_u_boot_fdt_test_priv_test0,
+	.uclass	= DM_UCLASS_REF(testfdt),
+	.parent_priv_	= _denx_u_boot_fdt_test_parent_priv_test0,
+	.uclass_node	= {
+		.prev = &DM_DEVICE_REF(test)->uclass_node,
+		.next = &DM_UCLASS_REF(testfdt)->dev_head,
+	},
+	.child_head	= {
+		.prev = &DM_DEVICE_REF(test0)->child_head,
+		.next = &DM_DEVICE_REF(test0)->child_head,
+	},
+	.sibling_node	= {
+		.prev = &DM_DEVICE_REF(test)->sibling_node,
+		.next = &DM_DEVICE_REF(some_bus)->child_head,
+	},
+	.seq_ = 2,
+};
+
 '''
 
     def test_simple(self):
@@ -520,8 +799,9 @@ DM_UCLASS_INST(testfdt) = {
         # Try the 'all' command
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
-        self._check_strings(self.decl_text + self.platdata_text +
-                            self.struct_text + self.uclass_text, data)
+        self._check_strings(
+            self.decl_text + self.device_text + self.platdata_text +
+            self.struct_text + self.uclass_text, data)
 
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
@@ -1116,8 +1396,9 @@ U_BOOT_DRVINFO(spl_test2) = {
         output = tools.GetOutputFilename('output')
         self.run_test(['all'], dtb_file, output)
         data = tools.ReadFile(output, binary=False)
-        self._check_strings(self.decl_text + self.platdata_text +
-                            self.struct_text + self.uclass_text, data)
+        self._check_strings(
+            self.decl_text + self.device_text + self.platdata_text +
+            self.struct_text + self.uclass_text, data)
 
     def test_no_command(self):
         """Test running dtoc without a command"""
@@ -1133,7 +1414,7 @@ U_BOOT_DRVINFO(spl_test2) = {
         with self.assertRaises(ValueError) as exc:
             self.run_test(['invalid-cmd'], dtb_file, output)
         self.assertIn(
-            "Unknown command 'invalid-cmd': (use: decl, platdata, struct, uclass)",
+            "Unknown command 'invalid-cmd': (use: decl, device, platdata, struct, uclass)",
             str(exc.exception))
 
     def test_output_conflict(self):
@@ -1161,12 +1442,12 @@ U_BOOT_DRVINFO(spl_test2) = {
             ['all'], dtb_file, False, None, [outdir], None, False,
             warning_disabled=True, scan=copy_scan())
         fnames = glob.glob(outdir + '/*')
-        self.assertEqual(6, len(fnames))
+        self.assertEqual(7, len(fnames))
 
         leafs = set(os.path.basename(fname) for fname in fnames)
         self.assertEqual(
             {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb',
-             'dt-uclass.c', 'dt-decl.h'},
+             'dt-uclass.c', 'dt-decl.h', 'dt-device.c'},
             leafs)
 
     def setup_process_test(self):
@@ -1376,8 +1657,14 @@ U_BOOT_DRVINFO(spl_test2) = {
 
         self._check_strings(UCLASS_HEADER_COMMON + self.uclass_text_inst, data)
 
+        self.run_test(['device'], dtb_file, output, True)
+        with open(output) as infile:
+            data = infile.read()
+
+        self._check_strings(self.device_text_inst, data)
+
     def test_inst_no_hdr(self):
-        """Test dealing with a struct that has no header"""
+        """Test dealing with a struct tsssshat has no header"""
         dtb_file = get_dtb_file('dtoc_test_inst.dts')
         output = tools.GetOutputFilename('output')
 
-- 
2.29.2.729.g45daf8777d-goog

^ permalink raw reply related	[flat|nested] 76+ messages in thread

* [PATCH 45/49] dm: of-platadata: Add option for device instantiation
  2020-12-29  3:35 ` [PATCH 45/49] dm: of-platadata: Add " Simon Glass
@ 2021-01-06  3:39   ` Walter Lozano
  2021-01-23 15:10     ` Simon Glass
  0 siblings, 1 reply; 76+ messages in thread
From: Walter Lozano @ 2021-01-06  3:39 UTC (permalink / raw)
  To: u-boot


On 12/29/20 12:35 AM, Simon Glass wrote:
> Add Kconfig options to support build-time device instantiation. When
> fully implemented, this will allow dtoc to create U-Boot devices (i.e.
> struct udevice records) at build time, thus reducing code space in
> SPL.
>
> For now this defaults to off, but will be enabled when the rest of
> the implementation is in place.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   dts/Kconfig          | 23 +++++++++++++++++++++--
>   scripts/Makefile.spl |  4 ++++
>   2 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/dts/Kconfig b/dts/Kconfig
> index 71f50552e4f..e861ea48d01 100644
> --- a/dts/Kconfig
> +++ b/dts/Kconfig
> @@ -355,15 +355,24 @@ config SPL_OF_PLATDATA
>   	  compatible string, then adding platform data and U_BOOT_DRVINFO
>   	  declarations for each node. See of-plat.txt for more information.
>   
> +if SPL_OF_PLATDATA
> +
>   config SPL_OF_PLATDATA_PARENT
>   	bool "Support parent information in devices"
> -	depends on SPL_OF_PLATDATA
>   	default y
>   	help
>   	  Generally it is useful to be able to access the parent of a device
>   	  with of-platdata. To save space this can be disabled, but in that
>   	  case dev_get_parent() will always return NULL;
>   
> +config SPL_OF_PLATDATA_INST

Not sure about the limits to config names, I understand that 
SPL_OF_PLATDATA_INST means SPL_OF_PLATDATA_INSTANCE? I'm not sure but 
maybe a better name could be SPL_OF_PLATDATA_BTIME_DEV. To be honest I 
find it difficult to come with nice name.

> +	bool "Declare devices at build time"
> +	help
> +	  Declare devices as udevice instances so that they do not need to be
> +	  bound when U-Boot starts. This can save time and code space.
> +
> +endif
> +
>   config TPL_OF_PLATDATA
>   	bool "Generate platform data for use in TPL"
>   	depends on TPL_OF_CONTROL
> @@ -385,13 +394,23 @@ config TPL_OF_PLATDATA
>   	  compatible string, then adding platform data and U_BOOT_DRVINFO
>   	  declarations for each node. See of-plat.txt for more information.
>   
> +if TPL_OF_PLATDATA
> +
>   config TPL_OF_PLATDATA_PARENT
>   	bool "Support parent information in devices"
> -	depends on TPL_OF_PLATDATA
>   	default y
>   	help
>   	  Generally it is useful to be able to access the parent of a device
>   	  with of-platdata. To save space this can be disabled, but in that
>   	  case dev_get_parent() will always return NULL;
>   
> +config TPL_OF_PLATDATA_INST

Same here. Also I have a question, in which case TPL_OF_PLATDATA_INST 
and SPL_OF_PLATDATA_INST would have different values. Which is the value 
of decoupling the TPL and SPL behavior? Or is use for consistency with 
SPL_OF_PLATDATA_PARENT and TPL_OF_PLATDATA_PARENT (which also not sure 
if needed to have two different options).

> +	bool "Declare devices at build time"
> +
> +	help
> +	  Declare devices as udevice instances so that they do not need to be
> +	  bound when U-Boot starts. This can save time and code space.
> +
> +endif
> +
>   endmenu
> diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
> index 72c0ad82793..6ca33abf348 100644
> --- a/scripts/Makefile.spl
> +++ b/scripts/Makefile.spl
> @@ -311,6 +311,10 @@ pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
>   DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \
>   	-d $(obj)/$(SPL_BIN).dtb -p $(SPL_NAME)
>   
> +ifneq ($(CONFIG_$(SPL_TPL_)OF_PLATDATA_INST),)
> +DTOC_ARGS += -i
> +endif
> +
>   quiet_cmd_dtoc = DTOC    $@
>   cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all
>   

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET()
  2020-12-29  3:34 ` [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() Simon Glass
@ 2021-01-06  3:40   ` Walter Lozano
  2021-01-06 15:13   ` Simon Glass
  1 sibling, 0 replies; 76+ messages in thread
From: Walter Lozano @ 2021-01-06  3:40 UTC (permalink / raw)
  To: u-boot


On 12/29/20 12:34 AM, Simon Glass wrote:
> This does not get a device (struct udevice *) but a struct driver_info *
> so the name is confusing.
>
> Rename it accordingly. Since we plan to have several various of these
> macros, put GET at the end instead of the middle, so it is easier to spot
> the related macros.
>
> Signed-off-by: Simon Glass<sjg@chromium.org>

Reviewed-by: Walter Lozano <walter.lozano@collabora.com>

Thanks,

> ---
>
>   doc/driver-model/of-plat.rst |  2 +-
>   include/dm/platdata.h        | 10 +++-------
>   tools/dtoc/dtb_platdata.py   |  4 ++--
>   3 files changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
> index 39e6295aa09..21b45f6a7e7 100644
> --- a/doc/driver-model/of-plat.rst
> +++ b/doc/driver-model/of-plat.rst
> @@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with
>   The dt-plat.c file contains the device declarations and is is built in
>   spl/dt-plat.c. It additionally contains the definition of
>   dm_populate_phandle_data() which is responsible of filling the phandle
> -information by adding references to U_BOOT_DRVINFO by using DM_GET_DEVICE
> +information by adding references to U_BOOT_DRVINFO by using DM_DRVINFO_GET
>   
>   The pylibfdt Python module is used to access the devicetree.
>   
> diff --git a/include/dm/platdata.h b/include/dm/platdata.h
> index e2b16ce6e4e..df1f6abcc7e 100644
> --- a/include/dm/platdata.h
> +++ b/include/dm/platdata.h
> @@ -74,27 +74,23 @@ struct driver_rt {
>   /**
>    * Get a pointer to a given device info given its name
>    *
> - * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a
> + * With the declaration U_BOOT_DRVINFO(name), DM_DRVINFO_GET(name) will return a
>    * pointer to the struct driver_info created by that declaration.
>    *
>    * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
>    * struct driver_info to find the device pointer itself.
>    *
> - * TODO(sjg at chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so
> - * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
> - * finds the driver_info record, not the device.
> - *
>    * @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
>    * @return struct driver_info * to the driver that created the device
>    */
> -#define DM_GET_DEVICE(__name)						\
> +#define DM_DRVINFO_GET(__name)						\
>   	ll_entry_get(struct driver_info, __name, driver_info)
>   
>   /**
>    * dm_populate_phandle_data() - Populates phandle data in platda
>    *
>    * This populates phandle data with an U_BOOT_DRVINFO entry get by
> - * DM_GET_DEVICE. The implementation of this function will be done
> + * DM_DRVINFO_GET. The implementation of this function will be done
>    * by dtoc when parsing dtb.
>    */
>   void dm_populate_phandle_data(void);
> diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
> index ebe5132e143..1a6a511b015 100644
> --- a/tools/dtoc/dtb_platdata.py
> +++ b/tools/dtoc/dtb_platdata.py
> @@ -811,8 +811,8 @@ class DtbPlatdata():
>               nodes_to_output.remove(node)
>   
>           # Define dm_populate_phandle_data() which will add the linking between
> -        # nodes using DM_GET_DEVICE
> -        # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
> +        # nodes using DM_DRVINFO_GET
> +        # dtv_dmc_at_xxx.clocks[0].node = DM_DRVINFO_GET(clock_controller_at_xxx)
>           self.buf('void dm_populate_phandle_data(void) {\n')
>           self.buf('}\n')
>   

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()
  2020-12-29  3:34 ` [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() Simon Glass
@ 2021-01-06  3:40   ` Walter Lozano
  2021-01-06 15:13   ` Simon Glass
  1 sibling, 0 replies; 76+ messages in thread
From: Walter Lozano @ 2021-01-06  3:40 UTC (permalink / raw)
  To: u-boot


On 12/29/20 12:34 AM, Simon Glass wrote:
> The current macro is a misnomer since it does not declare a device
> directly. Instead, it declares driver_info record which U-Boot uses at
> runtime to create a device.
>
> The distinction seems somewhat minor most of the time, but is becomes
> quite confusing when we actually want to declare a device, with
> of-platdata. We are left trying to distinguish between a device which
> isn't actually device, and a device that is (perhaps an 'instance'?)
>
> It seems better to rename this macro to describe what it actually is. The
> macros is not widely used, since boards should use devicetree to declare
> devices.
>
> Rename it to U_BOOT_DRVINFO(), which indicates clearly that this is
> declaring a new driver_info record, not a device.
>
> Signed-off-by: Simon Glass<sjg@chromium.org>

I couldn't agree more.

Reviewed-by: Walter Lozano <walter.lozano@collabora.com>

Thanks,

> ---
>
>   .../mach-at91/arm926ejs/at91sam9260_devices.c |  2 +-
>   .../arm926ejs/at91sam9m10g45_devices.c        |  2 +-
>   arch/arm/mach-imx/mx6/soc.c                   |  2 +-
>   arch/arm/mach-imx/mx7/soc.c                   |  2 +-
>   arch/arm/mach-lpc32xx/devices.c               |  4 +-
>   arch/arm/mach-omap2/am33xx/board.c            | 10 +--
>   arch/arm/mach-omap2/omap3/board.c             |  2 +-
>   arch/arm/mach-tegra/board.c                   |  2 +-
>   arch/arm/mach-tegra/board2.c                  |  2 +-
>   board/armltd/integrator/integrator.c          |  2 +-
>   board/armltd/total_compute/total_compute.c    |  2 +-
>   board/armltd/vexpress64/vexpress64.c          |  2 +-
>   board/bluewater/gurnard/gurnard.c             |  2 +-
>   board/bluewater/snapper9260/snapper9260.c     |  2 +-
>   board/cadence/xtfpga/xtfpga.c                 |  4 +-
>   board/cavium/thunderx/thunderx.c              |  4 +-
>   board/compulab/cm_fx6/cm_fx6.c                |  2 +-
>   board/davinci/da8xxevm/omapl138_lcdk.c        |  4 +-
>   board/freescale/ls1012afrdm/eth.c             |  4 +-
>   board/freescale/ls1012aqds/eth.c              |  4 +-
>   board/freescale/ls1012ardb/eth.c              |  4 +-
>   board/freescale/lx2160a/lx2160a.c             |  4 +-
>   board/gateworks/gw_ventana/gw_ventana.c       |  2 +-
>   board/hisilicon/hikey/hikey.c                 |  4 +-
>   board/hisilicon/hikey960/hikey960.c           |  2 +-
>   board/hisilicon/poplar/poplar.c               |  2 +-
>   board/isee/igep00x0/igep00x0.c                |  2 +-
>   board/lg/sniper/sniper.c                      |  2 +-
>   board/nokia/rx51/rx51.c                       |  2 +-
>   board/sandbox/sandbox.c                       |  2 +-
>   board/siemens/corvus/board.c                  |  2 +-
>   board/st/stv0991/stv0991.c                    |  2 +-
>   board/sysam/amcore/amcore.c                   |  2 +-
>   board/ti/am335x/board.c                       |  6 +-
>   board/timll/devkit8000/devkit8000.c           |  2 +-
>   board/toradex/apalis_imx6/apalis_imx6.c       |  2 +-
>   .../toradex/colibri-imx6ull/colibri-imx6ull.c |  2 +-
>   board/toradex/colibri_imx6/colibri_imx6.c     |  2 +-
>   board/toradex/colibri_pxa270/colibri_pxa270.c |  4 +-
>   doc/driver-model/design.rst                   | 18 ++---
>   doc/driver-model/of-plat.rst                  | 12 ++--
>   doc/driver-model/remoteproc-framework.rst     |  2 +-
>   doc/driver-model/spi-howto.rst                |  4 +-
>   drivers/crypto/fsl/fsl_rsa.c                  |  2 +-
>   drivers/crypto/rsa_mod_exp/mod_exp_sw.c       |  2 +-
>   drivers/demo/demo-pdata.c                     | 10 +--
>   drivers/gpio/imx_rgpio2p.c                    |  4 +-
>   drivers/gpio/mxc_gpio.c                       |  2 +-
>   drivers/remoteproc/sandbox_testproc.c         |  2 +-
>   drivers/rtc/emul_rtc.c                        |  2 +-
>   drivers/serial/sandbox.c                      |  2 +-
>   drivers/sysreset/sysreset_sandbox.c           |  4 +-
>   drivers/timer/sandbox_timer.c                 |  2 +-
>   drivers/video/sunxi/sunxi_de2.c               |  2 +-
>   drivers/video/sunxi/sunxi_dw_hdmi.c           |  2 +-
>   drivers/video/sunxi/sunxi_lcd.c               |  2 +-
>   dts/Kconfig                                   |  8 +--
>   include/dm/device.h                           |  4 +-
>   include/dm/lists.h                            |  2 +-
>   include/dm/platdata.h                         | 16 ++---
>   include/dm/platform_data/spi_pl022.h          |  2 +-
>   test/dm/core.c                                |  6 +-
>   tools/dtoc/dtb_platdata.py                    |  8 +--
>   tools/dtoc/test_dtoc.py                       | 66 +++++++++----------
>   64 files changed, 148 insertions(+), 148 deletions(-)
>
> diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
> index 9d787197f35..c10571fa28a 100644
> --- a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
> +++ b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c
> @@ -219,7 +219,7 @@ static const struct at91_port_plat at91sam9260_plat[] = {
>   	{ ATMEL_BASE_PIOC, "PC" },
>   };
>   
> -U_BOOT_DEVICES(at91sam9260_gpios) = {
> +U_BOOT_DRVINFOS(at91sam9260_gpios) = {
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
> diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
> index f503553b926..d517810c991 100644
> --- a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
> +++ b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c
> @@ -175,7 +175,7 @@ static const struct at91_port_plat at91sam9260_plat[] = {
>   	{ ATMEL_BASE_PIOE, "PE" },
>   };
>   
> -U_BOOT_DEVICES(at91sam9260_gpios) = {
> +U_BOOT_DRVINFOS(at91sam9260_gpios) = {
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
>   	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
> diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> index 1649f6d9480..bf6dddfdc9d 100644
> --- a/arch/arm/mach-imx/mx6/soc.c
> +++ b/arch/arm/mach-imx/mx6/soc.c
> @@ -44,7 +44,7 @@ static const struct imx_thermal_plat imx6_thermal_plat = {
>   	.fuse_word = 6,
>   };
>   
> -U_BOOT_DEVICE(imx6_thermal) = {
> +U_BOOT_DRVINFO(imx6_thermal) = {
>   	.name = "imx_thermal",
>   	.plat = &imx6_thermal_plat,
>   };
> diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c
> index 13593994f14..fda25ba66a3 100644
> --- a/arch/arm/mach-imx/mx7/soc.c
> +++ b/arch/arm/mach-imx/mx7/soc.c
> @@ -60,7 +60,7 @@ static const struct imx_thermal_plat imx7_thermal_plat = {
>   	.fuse_word = 3,
>   };
>   
> -U_BOOT_DEVICE(imx7_thermal) = {
> +U_BOOT_DRVINFO(imx7_thermal) = {
>   	.name = "imx_thermal",
>   	.plat = &imx7_thermal_plat,
>   };
> diff --git a/arch/arm/mach-lpc32xx/devices.c b/arch/arm/mach-lpc32xx/devices.c
> index 04e026a8b77..e1e2e0d0949 100644
> --- a/arch/arm/mach-lpc32xx/devices.c
> +++ b/arch/arm/mach-lpc32xx/devices.c
> @@ -62,7 +62,7 @@ static const struct lpc32xx_hsuart_plat lpc32xx_hsuart[] = {
>   };
>   #endif
>   
> -U_BOOT_DEVICES(lpc32xx_uarts) = {
> +U_BOOT_DRVINFOS(lpc32xx_uarts) = {
>   #if defined(CONFIG_LPC32XX_HSUART)
>   	{ "lpc32xx_hsuart", &lpc32xx_hsuart[0], },
>   	{ "lpc32xx_hsuart", &lpc32xx_hsuart[1], },
> @@ -124,7 +124,7 @@ void lpc32xx_i2c_init(unsigned int devnum)
>   	writel(ctrl, &clk->i2cclk_ctrl);
>   }
>   
> -U_BOOT_DEVICE(lpc32xx_gpios) = {
> +U_BOOT_DRVINFO(lpc32xx_gpios) = {
>   	.name = "gpio_lpc32xx"
>   };
>   
> diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c
> index b5f2b75e244..e17898d8fbf 100644
> --- a/arch/arm/mach-omap2/am33xx/board.c
> +++ b/arch/arm/mach-omap2/am33xx/board.c
> @@ -99,7 +99,7 @@ static const struct ns16550_plat am33xx_serial[] = {
>   # endif
>   };
>   
> -U_BOOT_DEVICES(am33xx_uarts) = {
> +U_BOOT_DRVINFOS(am33xx_uarts) = {
>   	{ "ns16550_serial", &am33xx_serial[0] },
>   #  ifdef CONFIG_SYS_NS16550_COM2
>   	{ "ns16550_serial", &am33xx_serial[1] },
> @@ -119,7 +119,7 @@ static const struct omap_i2c_plat am33xx_i2c[] = {
>   	{ I2C_BASE3, 100000, OMAP_I2C_REV_V2},
>   };
>   
> -U_BOOT_DEVICES(am33xx_i2c) = {
> +U_BOOT_DRVINFOS(am33xx_i2c) = {
>   	{ "i2c_omap", &am33xx_i2c[0] },
>   	{ "i2c_omap", &am33xx_i2c[1] },
>   	{ "i2c_omap", &am33xx_i2c[2] },
> @@ -138,7 +138,7 @@ static const struct omap_gpio_plat am33xx_gpio[] = {
>   #endif
>   };
>   
> -U_BOOT_DEVICES(am33xx_gpios) = {
> +U_BOOT_DRVINFOS(am33xx_gpios) = {
>   	{ "gpio_omap", &am33xx_gpio[0] },
>   	{ "gpio_omap", &am33xx_gpio[1] },
>   	{ "gpio_omap", &am33xx_gpio[2] },
> @@ -155,7 +155,7 @@ static const struct omap3_spi_plat omap3_spi_pdata = {
>   	.pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT,
>   };
>   
> -U_BOOT_DEVICE(am33xx_spi) = {
> +U_BOOT_DRVINFO(am33xx_spi) = {
>   	.name = "omap3_spi",
>   	.plat = &omap3_spi_pdata,
>   };
> @@ -234,7 +234,7 @@ static struct ti_musb_plat usb1 = {
>   		},
>   };
>   
> -U_BOOT_DEVICES(am33xx_usbs) = {
> +U_BOOT_DRVINFOS(am33xx_usbs) = {
>   #if CONFIG_AM335X_USB0_MODE == MUSB_PERIPHERAL
>   	{ "ti-musb-peripheral", &usb0 },
>   #elif CONFIG_AM335X_USB0_MODE == MUSB_HOST
> diff --git a/arch/arm/mach-omap2/omap3/board.c b/arch/arm/mach-omap2/omap3/board.c
> index 6ffedd1769f..4da8df47cc6 100644
> --- a/arch/arm/mach-omap2/omap3/board.c
> +++ b/arch/arm/mach-omap2/omap3/board.c
> @@ -47,7 +47,7 @@ static const struct omap_gpio_plat omap34xx_gpio[] = {
>   	{ 5, OMAP34XX_GPIO6_BASE },
>   };
>   
> -U_BOOT_DEVICES(omap34xx_gpios) = {
> +U_BOOT_DRVINFOS(omap34xx_gpios) = {
>   	{ "gpio_omap", &omap34xx_gpio[0] },
>   	{ "gpio_omap", &omap34xx_gpio[1] },
>   	{ "gpio_omap", &omap34xx_gpio[2] }, diff --git a/arch/arm/mach-tegra/board.c 
> b/arch/arm/mach-tegra/board.c index bf01aa5ee8f..9de9836c8d2 100644 
> --- a/arch/arm/mach-tegra/board.c +++ b/arch/arm/mach-tegra/board.c @@ 
> -264,7 +264,7 @@ static struct ns16550_plat ns16550_com1_pdata = { 
> .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(ns16550_com1) = { 
> +U_BOOT_DRVINFO(ns16550_com1) = { "ns16550_serial", &ns16550_com1_pdata
>   };
>   #endif
> diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c
> index 48c4f32d6f9..8569ad7c6fc 100644
> --- a/arch/arm/mach-tegra/board2.c
> +++ b/arch/arm/mach-tegra/board2.c
> @@ -42,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR;
>   
>   #ifdef CONFIG_SPL_BUILD
>   /* TODO(sjg at chromium.org): Remove once SPL supports device tree */
> -U_BOOT_DEVICE(tegra_gpios) = {
> +U_BOOT_DRVINFO(tegra_gpios) = {
>   	"gpio_tegra"
>   };
>   #endif
> diff --git a/board/armltd/integrator/integrator.c b/board/armltd/integrator/integrator.c
> index 21bea62e9b7..3c56fa1c019 100644
> --- a/board/armltd/integrator/integrator.c
> +++ b/board/armltd/integrator/integrator.c
> @@ -43,7 +43,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   #endif
>   };
>   
> -U_BOOT_DEVICE(integrator_serials) = {
> +U_BOOT_DRVINFO(integrator_serials) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/armltd/total_compute/total_compute.c b/board/armltd/total_compute/total_compute.c
> index 6263d0c3612..da24b32333b 100644
> --- a/board/armltd/total_compute/total_compute.c
> +++ b/board/armltd/total_compute/total_compute.c
> @@ -15,7 +15,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = CONFIG_PL011_CLOCK,
>   };
>   
> -U_BOOT_DEVICE(total_compute_serials) = {
> +U_BOOT_DRVINFO(total_compute_serials) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c
> index 6df6bcd3cf5..bd66d52cb7b 100644
> --- a/board/armltd/vexpress64/vexpress64.c
> +++ b/board/armltd/vexpress64/vexpress64.c
> @@ -26,7 +26,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = CONFIG_PL011_CLOCK,
>   };
>   
> -U_BOOT_DEVICE(vexpress_serials) = {
> +U_BOOT_DRVINFO(vexpress_serials) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/bluewater/gurnard/gurnard.c b/board/bluewater/gurnard/gurnard.c
> index a71b4eb7339..17ecdb679e1 100644
> --- a/board/bluewater/gurnard/gurnard.c
> +++ b/board/bluewater/gurnard/gurnard.c
> @@ -420,7 +420,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
>   	.base_addr = ATMEL_BASE_DBGU,
>   };
>   
> -U_BOOT_DEVICE(at91sam9260_serial) = {
> +U_BOOT_DRVINFO(at91sam9260_serial) = {
>   	.name	= "serial_atmel",
>   	.plat = &at91sam9260_serial_plat,
>   };
> diff --git a/board/bluewater/snapper9260/snapper9260.c b/board/bluewater/snapper9260/snapper9260.c
> index 9e41a42263d..58fab15c112 100644
> --- a/board/bluewater/snapper9260/snapper9260.c
> +++ b/board/bluewater/snapper9260/snapper9260.c
> @@ -147,7 +147,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
>   	.base_addr = ATMEL_BASE_DBGU,
>   };
>   
> -U_BOOT_DEVICE(at91sam9260_serial) = {
> +U_BOOT_DRVINFO(at91sam9260_serial) = {
>   	.name	= "serial_atmel",
>   	.plat = &at91sam9260_serial_plat,
>   };
> diff --git a/board/cadence/xtfpga/xtfpga.c b/board/cadence/xtfpga/xtfpga.c
> index 29db51b0260..c26793d76cc 100644
> --- a/board/cadence/xtfpga/xtfpga.c
> +++ b/board/cadence/xtfpga/xtfpga.c
> @@ -93,7 +93,7 @@ int misc_init_r(void)
>   	return 0;
>   }
>   
> -U_BOOT_DEVICE(sysreset) = {
> +U_BOOT_DRVINFO(sysreset) = {
>   	.name = "xtfpga_sysreset",
>   };
>   
> @@ -104,7 +104,7 @@ static struct ethoc_eth_pdata ethoc_pdata = {
>   	.packet_base = CONFIG_SYS_ETHOC_BUFFER_ADDR,
>   };
>   
> -U_BOOT_DEVICE(ethoc) = {
> +U_BOOT_DRVINFO(ethoc) = {
>   	.name = "ethoc",
>   	.plat = &ethoc_pdata,
>   };
> diff --git a/board/cavium/thunderx/thunderx.c b/board/cavium/thunderx/thunderx.c
> index 22c4c72361e..fd234728980 100644
> --- a/board/cavium/thunderx/thunderx.c
> +++ b/board/cavium/thunderx/thunderx.c
> @@ -25,7 +25,7 @@ static const struct pl01x_serial_plat serial0 = {
>   	.skip_init = true,
>   };
>   
> -U_BOOT_DEVICE(thunderx_serial0) = {
> +U_BOOT_DRVINFO(thunderx_serial0) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial0,
>   };
> @@ -37,7 +37,7 @@ static const struct pl01x_serial_plat serial1 = {
>   	.skip_init = true,
>   };
>   
> -U_BOOT_DEVICE(thunderx_serial1) = {
> +U_BOOT_DRVINFO(thunderx_serial1) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial1,
>   };
> diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c
> index bc3ce4d16c9..7520e96e078 100644
> --- a/board/compulab/cm_fx6/cm_fx6.c
> +++ b/board/compulab/cm_fx6/cm_fx6.c
> @@ -728,7 +728,7 @@ static struct mxc_serial_plat cm_fx6_mxc_serial_plat = {
>   	.reg = (struct mxc_uart *)UART4_BASE,
>   };
>   
> -U_BOOT_DEVICE(cm_fx6_serial) = {
> +U_BOOT_DRVINFO(cm_fx6_serial) = {
>   	.name	= "serial_mxc",
>   	.plat = &cm_fx6_mxc_serial_plat,
>   };
> diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c b/board/davinci/da8xxevm/omapl138_lcdk.c
> index a8ece170ce3..a08858550d4 100644
> --- a/board/davinci/da8xxevm/omapl138_lcdk.c
> +++ b/board/davinci/da8xxevm/omapl138_lcdk.c
> @@ -363,7 +363,7 @@ static const struct ns16550_plat serial_pdata = {
>   	.fcr = UART_FCR_DEFVAL,
>   };
>   
> -U_BOOT_DEVICE(omapl138_uart) = {
> +U_BOOT_DRVINFO(omapl138_uart) = {
>   	.name = "ns16550_serial",
>   	.plat = &serial_pdata,
>   };
> @@ -379,7 +379,7 @@ static const struct davinci_mmc_plat mmc_plat = {
>   		.name = "da830-mmc",
>   	},
>   };
> -U_BOOT_DEVICE(omapl138_mmc) = {
> +U_BOOT_DRVINFO(omapl138_mmc) = {
>   	.name = "ti_da830_mmc",
>   	.plat = &mmc_plat,
>   };
> diff --git a/board/freescale/ls1012afrdm/eth.c b/board/freescale/ls1012afrdm/eth.c
> index 85104ab22c8..d2df9351eac 100644
> --- a/board/freescale/ls1012afrdm/eth.c
> +++ b/board/freescale/ls1012afrdm/eth.c
> @@ -114,12 +114,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
>   	},
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe0) = {
> +U_BOOT_DRVINFO(ls1012a_pfe0) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata0,
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe1) = {
> +U_BOOT_DRVINFO(ls1012a_pfe1) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata1,
>   };
> diff --git a/board/freescale/ls1012aqds/eth.c b/board/freescale/ls1012aqds/eth.c
> index f6f43d2b137..8189f41becb 100644
> --- a/board/freescale/ls1012aqds/eth.c
> +++ b/board/freescale/ls1012aqds/eth.c
> @@ -298,12 +298,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
>   	},
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe0) = {
> +U_BOOT_DRVINFO(ls1012a_pfe0) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata0,
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe1) = {
> +U_BOOT_DRVINFO(ls1012a_pfe1) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata1,
>   };
> diff --git a/board/freescale/ls1012ardb/eth.c b/board/freescale/ls1012ardb/eth.c
> index 5e923e52527..2241d061dd8 100644
> --- a/board/freescale/ls1012ardb/eth.c
> +++ b/board/freescale/ls1012ardb/eth.c
> @@ -160,12 +160,12 @@ static struct pfe_eth_pdata pfe_pdata1 = {
>   	},
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe0) = {
> +U_BOOT_DRVINFO(ls1012a_pfe0) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata0,
>   };
>   
> -U_BOOT_DEVICE(ls1012a_pfe1) = {
> +U_BOOT_DRVINFO(ls1012a_pfe1) = {
>   	.name = "pfe_eth",
>   	.plat = &pfe_pdata1,
>   };
> diff --git a/board/freescale/lx2160a/lx2160a.c b/board/freescale/lx2160a/lx2160a.c
> index 8d0115eace4..70dd34e7cee 100644
> --- a/board/freescale/lx2160a/lx2160a.c
> +++ b/board/freescale/lx2160a/lx2160a.c
> @@ -62,7 +62,7 @@ static struct pl01x_serial_plat serial0 = {
>   	.type = TYPE_PL011,
>   };
>   
> -U_BOOT_DEVICE(nxp_serial0) = {
> +U_BOOT_DRVINFO(nxp_serial0) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial0,
>   };
> @@ -72,7 +72,7 @@ static struct pl01x_serial_plat serial1 = {
>   	.type = TYPE_PL011,
>   };
>   
> -U_BOOT_DEVICE(nxp_serial1) = {
> +U_BOOT_DRVINFO(nxp_serial1) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial1,
>   };
> diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
> index c7224d1efe3..048f624c352 100644
> --- a/board/gateworks/gw_ventana/gw_ventana.c
> +++ b/board/gateworks/gw_ventana/gw_ventana.c
> @@ -1375,7 +1375,7 @@ static struct mxc_serial_plat ventana_mxc_serial_plat = {
>   	.reg = (struct mxc_uart *)UART2_BASE,
>   };
>   
> -U_BOOT_DEVICE(ventana_serial) = {
> +U_BOOT_DRVINFO(ventana_serial) = {
>   	.name   = "serial_mxc",
>   	.plat = &ventana_mxc_serial_plat,
>   };
> diff --git a/board/hisilicon/hikey/hikey.c b/board/hisilicon/hikey/hikey.c
> index 0ac88306d09..65a8179adbf 100644
> --- a/board/hisilicon/hikey/hikey.c
> +++ b/board/hisilicon/hikey/hikey.c
> @@ -50,7 +50,7 @@ static const struct hikey_gpio_plat hi6220_gpio[] = {
>   
>   };
>   
> -U_BOOT_DEVICES(hi6220_gpios) = {
> +U_BOOT_DRVINFOS(hi6220_gpios) = {
>   	{ "gpio_hi6220", &hi6220_gpio[0] },
>   	{ "gpio_hi6220", &hi6220_gpio[1] },
>   	{ "gpio_hi6220", &hi6220_gpio[2] },
> @@ -89,7 +89,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = 19200000
>   };
>   
> -U_BOOT_DEVICE(hikey_seriala) = {
> +U_BOOT_DRVINFO(hikey_seriala) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/hisilicon/hikey960/hikey960.c b/board/hisilicon/hikey960/hikey960.c
> index 04b8cde1363..3fe4c60d02e 100644
> --- a/board/hisilicon/hikey960/hikey960.c
> +++ b/board/hisilicon/hikey960/hikey960.c
> @@ -32,7 +32,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = 19200000
>   };
>   
> -U_BOOT_DEVICE(hikey960_serial0) = {
> +U_BOOT_DRVINFO(hikey960_serial0) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/hisilicon/poplar/poplar.c b/board/hisilicon/poplar/poplar.c
> index b8be4ce45a6..bfb2c66a17a 100644
> --- a/board/hisilicon/poplar/poplar.c
> +++ b/board/hisilicon/poplar/poplar.c
> @@ -46,7 +46,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = 75000000,
>   };
>   
> -U_BOOT_DEVICE(poplar_serial) = {
> +U_BOOT_DRVINFO(poplar_serial) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c
> index 6a7da502dda..0932f62b9be 100644
> --- a/board/isee/igep00x0/igep00x0.c
> +++ b/board/isee/igep00x0/igep00x0.c
> @@ -36,7 +36,7 @@ static const struct ns16550_plat igep_serial = {
>   	.fcr = UART_FCR_DEFVAL,
>   };
>   
> -U_BOOT_DEVICE(igep_uart) = {
> +U_BOOT_DRVINFO(igep_uart) = {
>   	"ns16550_serial",
>   	&igep_serial
>   };
> diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c
> index d11630b9543..118ab269d6f 100644
> --- a/board/lg/sniper/sniper.c
> +++ b/board/lg/sniper/sniper.c
> @@ -37,7 +37,7 @@ static const struct ns16550_plat serial_omap_plat = {
>   	.fcr = UART_FCR_DEFVAL,
>   };
>   
> -U_BOOT_DEVICE(sniper_serial) = {
> +U_BOOT_DRVINFO(sniper_serial) = {
>   	.name = "ns16550_serial",
>   	.plat = &serial_omap_plat
>   };
> diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
> index bafb6205bd8..253ee3c7b29 100644
> --- a/board/nokia/rx51/rx51.c
> +++ b/board/nokia/rx51/rx51.c
> @@ -709,7 +709,7 @@ static const struct omap_i2c_plat rx51_i2c[] = {
>   	{ I2C_BASE3, 400000, OMAP_I2C_REV_V1 },
>   };
>   
> -U_BOOT_DEVICES(rx51_i2c) = {
> +U_BOOT_DRVINFOS(rx51_i2c) = {
>   	{ "i2c_omap", &rx51_i2c[0] },
>   	{ "i2c_omap", &rx51_i2c[1] },
>   	{ "i2c_omap", &rx51_i2c[2] },
> diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
> index 3235541a7d5..d152703b154 100644
> --- a/board/sandbox/sandbox.c
> +++ b/board/sandbox/sandbox.c
> @@ -23,7 +23,7 @@ gd_t *gd;
>   
>   #if !CONFIG_IS_ENABLED(OF_PLATDATA)
>   /* Add a simple GPIO device */
> -U_BOOT_DEVICE(gpio_sandbox) = {
> +U_BOOT_DRVINFO(gpio_sandbox) = {
>   	.name = "sandbox_gpio",
>   };
>   #endif
> diff --git a/board/siemens/corvus/board.c b/board/siemens/corvus/board.c
> index 1613c449294..25d85a8f170 100644
> --- a/board/siemens/corvus/board.c
> +++ b/board/siemens/corvus/board.c
> @@ -318,7 +318,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = {
>   	.base_addr = ATMEL_BASE_DBGU,
>   };
>   
> -U_BOOT_DEVICE(at91sam9260_serial) = {
> +U_BOOT_DRVINFO(at91sam9260_serial) = {
>   	.name	= "serial_atmel",
>   	.plat = &at91sam9260_serial_plat,
>   };
> diff --git a/board/st/stv0991/stv0991.c b/board/st/stv0991/stv0991.c
> index 3371973600a..95e203ff0ea 100644
> --- a/board/st/stv0991/stv0991.c
> +++ b/board/st/stv0991/stv0991.c
> @@ -30,7 +30,7 @@ static const struct pl01x_serial_plat serial_plat = {
>   	.clock = 2700 * 1000,
>   };
>   
> -U_BOOT_DEVICE(stv09911_serials) = {
> +U_BOOT_DRVINFO(stv09911_serials) = {
>   	.name = "serial_pl01x",
>   	.plat = &serial_plat,
>   };
> diff --git a/board/sysam/amcore/amcore.c b/board/sysam/amcore/amcore.c
> index 42e1a80ec5f..65fc60e2b46 100644
> --- a/board/sysam/amcore/amcore.c
> +++ b/board/sysam/amcore/amcore.c
> @@ -113,7 +113,7 @@ static struct coldfire_serial_plat mcf5307_serial_plat = {
>   	.baudrate = CONFIG_BAUDRATE,
>   };
>   
> -U_BOOT_DEVICE(coldfire_serial) = {
> +U_BOOT_DRVINFO(coldfire_serial) = {
>   	.name = "serial_coldfire",
>   	.plat = &mcf5307_serial_plat,
>   };
> diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
> index 2aa385a937b..40d2e0238fd 100644
> --- a/board/ti/am335x/board.c
> +++ b/board/ti/am335x/board.c
> @@ -927,7 +927,7 @@ struct eth_pdata cpsw_pdata = {
>   	.priv_pdata = &am335_eth_data,
>   };
>   
> -U_BOOT_DEVICE(am335x_eth) = {
> +U_BOOT_DRVINFO(am335x_eth) = {
>   	.name = "eth_cpsw",
>   	.plat = &cpsw_pdata,
>   };
> @@ -972,7 +972,7 @@ static const struct omap_hsmmc_plat am335x_mmc0_plat = {
>   	.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
>   };
>   
> -U_BOOT_DEVICE(am335x_mmc0) = {
> +U_BOOT_DRVINFO(am335x_mmc0) = {
>   	.name = "omap_hsmmc",
>   	.plat = &am335x_mmc0_plat,
>   };
> @@ -986,7 +986,7 @@ static const struct omap_hsmmc_plat am335x_mmc1_plat = {
>   	.cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
>   };
>   
> -U_BOOT_DEVICE(am335x_mmc1) = {
> +U_BOOT_DRVINFO(am335x_mmc1) = {
>   	.name = "omap_hsmmc",
>   	.plat = &am335x_mmc1_plat,
>   };
> diff --git a/board/timll/devkit8000/devkit8000.c b/board/timll/devkit8000/devkit8000.c
> index 875383625d4..0731fb76456 100644
> --- a/board/timll/devkit8000/devkit8000.c
> +++ b/board/timll/devkit8000/devkit8000.c
> @@ -54,7 +54,7 @@ static const struct ns16550_plat devkit8000_serial = {
>   	.fcr = UART_FCR_DEFVAL,
>   };
>   
> -U_BOOT_DEVICE(devkit8000_uart) = {
> +U_BOOT_DRVINFO(devkit8000_uart) = {
>   	"ns16550_serial", &devkit8000_serial }; diff --git 
> a/board/toradex/apalis_imx6/apalis_imx6.c 
> b/board/toradex/apalis_imx6/apalis_imx6.c index 
> 362a750b199..5ae5274584a 100644 --- 
> a/board/toradex/apalis_imx6/apalis_imx6.c +++ 
> b/board/toradex/apalis_imx6/apalis_imx6.c @@ -1149,7 +1149,7 @@ static 
> struct mxc_serial_plat mxc_serial_plat = { .use_dte = true, }; 
> -U_BOOT_DEVICE(mxc_serial) = { +U_BOOT_DRVINFO(mxc_serial) = { .name = "serial_mxc",
>   	.plat = &mxc_serial_plat,
>   };
> diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
> index 056064f6b97..6ff55ce57b9 100644
> --- a/board/toradex/colibri-imx6ull/colibri-imx6ull.c
> +++ b/board/toradex/colibri-imx6ull/colibri-imx6ull.c
> @@ -208,7 +208,7 @@ static struct mxc_serial_plat mxc_serial_plat = {
>   	.use_dte = 1,
>   };
>   
> -U_BOOT_DEVICE(mxc_serial) = {
> +U_BOOT_DRVINFO(mxc_serial) = {
>   	.name = "serial_mxc",
>   	.plat = &mxc_serial_plat,
>   };
> diff --git a/board/toradex/colibri_imx6/colibri_imx6.c b/board/toradex/colibri_imx6/colibri_imx6.c
> index a82daad7395..57d3e526b4c 100644
> --- a/board/toradex/colibri_imx6/colibri_imx6.c
> +++ b/board/toradex/colibri_imx6/colibri_imx6.c
> @@ -1091,7 +1091,7 @@ static struct mxc_serial_plat mxc_serial_plat = {
>   	.use_dte = true,
>   };
>   
> -U_BOOT_DEVICE(mxc_serial) = {
> +U_BOOT_DRVINFO(mxc_serial) = {
>   	.name = "serial_mxc",
>   	.plat = &mxc_serial_plat,
>   };
> diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c
> index b9d0fb98af3..645751a37ec 100644
> --- a/board/toradex/colibri_pxa270/colibri_pxa270.c
> +++ b/board/toradex/colibri_pxa270/colibri_pxa270.c
> @@ -133,7 +133,7 @@ static const struct pxa_mmc_plat mmc_plat = {
>   	.base = (struct pxa_mmc_regs *)MMC0_BASE,
>   };
>   
> -U_BOOT_DEVICE(pxa_mmcs) = {
> +U_BOOT_DRVINFO(pxa_mmcs) = {
>   	.name = "pxa_mmc",
>   	.plat = &mmc_plat,
>   };
> @@ -146,7 +146,7 @@ static const struct pxa_serial_plat serial_plat = {
>   	.baudrate = CONFIG_BAUDRATE,
>   };
>   
> -U_BOOT_DEVICE(pxa_serials) = {
> +U_BOOT_DRVINFO(pxa_serials) = {
>   	.name = "serial_pxa",
>   	.plat = &serial_plat,
>   };
> diff --git a/doc/driver-model/design.rst b/doc/driver-model/design.rst
> index f26e4f14df0..ffed7d5f79a 100644
> --- a/doc/driver-model/design.rst
> +++ b/doc/driver-model/design.rst
> @@ -422,7 +422,7 @@ Device Tree
>   
>   While plat is useful, a more flexible way of providing device data is
>   by using device tree. In U-Boot you should use this where possible. Avoid
> -sending patches which make use of the U_BOOT_DEVICE() macro unless strictly
> +sending patches which make use of the U_BOOT_DRVINFO() macro unless strictly
>   necessary.
>   
>   With device tree we replace the above code with the following device tree
> @@ -436,7 +436,7 @@ fragment:
>   		sides = <4>;
>   	};
>   
> -This means that instead of having lots of U_BOOT_DEVICE() declarations in
> +This means that instead of having lots of U_BOOT_DRVINFO() declarations in
>   the board file, we put these in the device tree. This approach allows a lot
>   more generality, since the same board file can support many types of boards
>   (e,g. with the same SoC) just by using different device trees. An added
> @@ -665,9 +665,9 @@ Bind stage
>   
>   U-Boot discovers devices using one of these two methods:
>   
> -- Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified
> +- Scan the U_BOOT_DRVINFO() definitions. U-Boot looks up the name specified
>     by each, to find the appropriate U_BOOT_DRIVER() definition. In this case,
> -  there is no path by which driver_data may be provided, but the U_BOOT_DEVICE()
> +  there is no path by which driver_data may be provided, but the U_BOOT_DRVINFO()
>     may provide plat.
>   
>   - Scan through the device tree definitions. U-Boot looks at top-level
> @@ -685,7 +685,7 @@ driver's bind() method if one is defined.
>   At this point all the devices are known, and bound to their drivers. There
>   is a 'struct udevice' allocated for all devices. However, nothing has been
>   activated (except for the root device). Each bound device that was created
> -from a U_BOOT_DEVICE() declaration will hold the plat pointer specified
> +from a U_BOOT_DRVINFO() declaration will hold the plat pointer specified
>   in that declaration. For a bound device created from the device tree,
>   plat will be NULL, but of_offset will be the offset of the device tree
>   node that caused the device to be created. The uclass is set correctly for
> @@ -726,7 +726,7 @@ The steps are:
>      2. If plat_auto is non-zero, then the platform data space
>      is allocated. This is only useful for device tree operation, since
>      otherwise you would have to specific the platform data in the
> -   U_BOOT_DEVICE() declaration. The space is allocated for the device and
> +   U_BOOT_DRVINFO() declaration. The space is allocated for the device and
>      zeroed. It will be accessible as dev->plat.
>   
>      3. If the device's uclass specifies a non-zero per_device_auto,
> @@ -746,7 +746,7 @@ The steps are:
>      do various calls like dev_read_u32(dev, ...) to access the node and store
>      the resulting information into dev->plat. After this point, the device
>      works the same way whether it was bound using a device tree node or
> -   U_BOOT_DEVICE() structure. In either case, the platform data is now stored
> +   U_BOOT_DRVINFO() structure. In either case, the platform data is now stored
>      in the plat structure. Typically you will use the
>      plat_auto feature to specify the size of the platform data
>      structure, and U-Boot will automatically allocate and zero it for you before
> @@ -855,7 +855,7 @@ remove it. This performs the probe steps in reverse:
>      4. The device memory is freed (platform data, private data, uclass data,
>      parent data).
>   
> -   Note: Because the platform data for a U_BOOT_DEVICE() is defined with a
> +   Note: Because the platform data for a U_BOOT_DRVINFO() is defined with a
>      static pointer, it is not de-allocated during the remove() method. For
>      a device instantiated using the device tree data, the platform data will
>      be dynamically allocated, and thus needs to be deallocated during the
> @@ -931,7 +931,7 @@ property can provide better control granularity on which device is bound
>   before relocation. While with DM_FLAG_PRE_RELOC flag of the driver all
>   devices with the same driver are bound, which requires allocation a large
>   amount of memory. When device tree is not used, DM_FLAG_PRE_RELOC is the
> -only way for statically declared devices via U_BOOT_DEVICE() to be bound
> +only way for statically declared devices via U_BOOT_DRVINFO() to be bound
>   prior to relocation.
>   
>   It is possible to limit this to specific relocation steps, by using
> diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst
> index afa27c211cc..39e6295aa09 100644
> --- a/doc/driver-model/of-plat.rst
> +++ b/doc/driver-model/of-plat.rst
> @@ -21,7 +21,7 @@ SoCs require a 16KB SPL image which must include a full MMC stack. In this
>   case the overhead of device tree access may be too great.
>   
>   It is possible to create platform data manually by defining C structures
> -for it, and reference that data in a U_BOOT_DEVICE() declaration. This
> +for it, and reference that data in a U_BOOT_DRVINFO() declaration. This
>   bypasses the use of device tree completely, effectively creating a parallel
>   configuration mechanism. But it is an available option for SPL.
>   
> @@ -79,7 +79,7 @@ SPL/TPL and should be tested with:
>   
>   A new tool called 'dtoc' converts a device tree file either into a set of
>   struct declarations, one for each compatible node, and a set of
> -U_BOOT_DEVICE() declarations along with the actual platform data for each
> +U_BOOT_DRVINFO() declarations along with the actual platform data for each
>   device. As an example, consider this MMC node:
>   
>   .. code-block:: none
> @@ -155,7 +155,7 @@ and the following device declarations:
>               .card_detect_delay      = 0xc8,
>       };
>   
> -    U_BOOT_DEVICE(dwmmc_at_ff0c0000) = {
> +    U_BOOT_DRVINFO(dwmmc_at_ff0c0000) = {
>               .name           = "rockchip_rk3288_dw_mshc",
>               .plat       = &dtv_dwmmc_at_ff0c0000,
>               .plat_size  = sizeof(dtv_dwmmc_at_ff0c0000),
> @@ -178,7 +178,7 @@ platform data in the driver. The of_to_plat() method should
>   therefore do nothing in such a driver.
>   
>   Note that for the platform data to be matched with a driver, the 'name'
> -property of the U_BOOT_DEVICE() declaration has to match a driver declared
> +property of the U_BOOT_DRVINFO() declaration has to match a driver declared
>   via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a
>   'name' corresponding to the devicetree 'compatible' string (after converting
>   it to a valid name for C) is needed, so a dedicated driver is required for
> @@ -189,7 +189,7 @@ used to declare an alias for a driver name, typically a 'compatible' string.
>   This macro produces no code, but it is by dtoc tool.
>   
>   The parent_idx is the index of the parent driver_info structure within its
> -linker list (instantiated by the U_BOOT_DEVICE() macro). This is used to support
> +linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support
>   dev_get_parent(). The dm_populate_phandle_data() is included to allow for
>   fix-ups required by dtoc. It is not currently used. The values in 'clocks' are
>   the index of the driver_info for the target device followed by any phandle
> @@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with
>   The dt-plat.c file contains the device declarations and is is built in
>   spl/dt-plat.c. It additionally contains the definition of
>   dm_populate_phandle_data() which is responsible of filling the phandle
> -information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE
> +information by adding references to U_BOOT_DRVINFO by using DM_GET_DEVICE
>   
>   The pylibfdt Python module is used to access the devicetree.
>   
> diff --git a/doc/driver-model/remoteproc-framework.rst b/doc/driver-model/remoteproc-framework.rst
> index edb09cc1057..566495a21c4 100644
> --- a/doc/driver-model/remoteproc-framework.rst
> +++ b/doc/driver-model/remoteproc-framework.rst
> @@ -125,7 +125,7 @@ a simplified definition of a device is as follows:
>   		.driver_plat_data = &mydriver_data;
>   	};
>   
> -	U_BOOT_DEVICE(proc_3_demo) = {
> +	U_BOOT_DRVINFO(proc_3_demo) = {
>   		.name = "sandbox_test_proc",
>   		.plat = &proc_3_test,
>   	};
> diff --git a/doc/driver-model/spi-howto.rst b/doc/driver-model/spi-howto.rst
> index f1c41671390..97fbf750cb6 100644
> --- a/doc/driver-model/spi-howto.rst
> +++ b/doc/driver-model/spi-howto.rst
> @@ -270,7 +270,7 @@ fills in the fields from device tree.
>   Add the platform data [non-device-tree only]
>   --------------------------------------------
>   
> -Specify this data in a U_BOOT_DEVICE() declaration in your board file:
> +Specify this data in a U_BOOT_DRVINFO() declaration in your board file:
>   
>   .. code-block:: c
>   
> @@ -281,7 +281,7 @@ Specify this data in a U_BOOT_DEVICE() declaration in your board file:
>   		.deactivate_delay_us = ...
>   	};
>   
> -	U_BOOT_DEVICE(board_spi0) = {
> +	U_BOOT_DRVINFO(board_spi0) = {
>   		.name = "exynos_spi",
>   		.plat = &platdata_spi0,
>   	};
> diff --git a/drivers/crypto/fsl/fsl_rsa.c b/drivers/crypto/fsl/fsl_rsa.c
> index ed2a54f6ec2..897ee855ead 100644
> --- a/drivers/crypto/fsl/fsl_rsa.c
> +++ b/drivers/crypto/fsl/fsl_rsa.c
> @@ -55,6 +55,6 @@ U_BOOT_DRIVER(fsl_rsa_mod_exp) = {
>   	.ops	= &fsl_mod_exp_ops,
>   };
>   
> -U_BOOT_DEVICE(fsl_rsa) = {
> +U_BOOT_DRVINFO(fsl_rsa) = {
>   	.name = "fsl_rsa_mod_exp",
>   };
> diff --git a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
> index 4ce85b32244..7bed444c3fb 100644
> --- a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
> +++ b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c
> @@ -35,6 +35,6 @@ U_BOOT_DRIVER(mod_exp_sw) = {
>   	.flags	= DM_FLAG_PRE_RELOC,
>   };
>   
> -U_BOOT_DEVICE(mod_exp_sw) = {
> +U_BOOT_DRVINFO(mod_exp_sw) = {
>   	.name = "mod_exp_sw", }; diff --git a/drivers/demo/demo-pdata.c 
> b/drivers/demo/demo-pdata.c index b504c31373c..818f77503a3 100644 --- 
> a/drivers/demo/demo-pdata.c +++ b/drivers/demo/demo-pdata.c @@ -20,27 
> +20,27 @@ static const struct dm_demo_pdata yellow_hexagon = { .sides 
> = 6. }; -U_BOOT_DEVICE(demo0) = { +U_BOOT_DRVINFO(demo0) = { .name = "demo_shape_drv",
>   	.plat = &red_square,
>   };
>   
> -U_BOOT_DEVICE(demo1) = {
> +U_BOOT_DRVINFO(demo1) = {
>   	.name = "demo_simple_drv",
>   	.plat = &red_square,
>   };
>   
> -U_BOOT_DEVICE(demo2) = {
> +U_BOOT_DRVINFO(demo2) = {
>   	.name = "demo_shape_drv",
>   	.plat = &green_triangle,
>   };
>   
> -U_BOOT_DEVICE(demo3) = {
> +U_BOOT_DRVINFO(demo3) = {
>   	.name = "demo_simple_drv",
>   	.plat = &yellow_hexagon,
>   };
>   
> -U_BOOT_DEVICE(demo4) = {
> +U_BOOT_DRVINFO(demo4) = {
>   	.name = "demo_shape_drv",
>   	.plat = &yellow_hexagon,
>   };
> diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c
> index a5a290a00ce..0e2874ca95c 100644
> --- a/drivers/gpio/imx_rgpio2p.c
> +++ b/drivers/gpio/imx_rgpio2p.c
> @@ -158,7 +158,7 @@ static int imx_rgpio2p_bind(struct udevice *dev)
>   	/*
>   	 * If plat already exsits, directly return.
>   	 * Actually only when DT is not supported, plat
> -	 * is statically initialized in U_BOOT_DEVICES.Here
> +	 * is statically initialized in U_BOOT_DRVINFOS.Here
>   	 * will return.
>   	 */
>   	if (plat)
> @@ -216,7 +216,7 @@ static const struct imx_rgpio2p_plat imx_plat[] = {
>   	{ 5, (struct gpio_regs *)RGPIO2P_GPIO6_BASE_ADDR },
>   };
>   
> -U_BOOT_DEVICES(imx_rgpio2ps) = {
> +U_BOOT_DRVINFOS(imx_rgpio2ps) = {
>   	{ "imx_rgpio2p", &imx_plat[0] },
>   	{ "imx_rgpio2p", &imx_plat[1] },
>   	{ "imx_rgpio2p", &imx_plat[2] },
> diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
> index 9fc217ae6ae..6280fb59840 100644
> --- a/drivers/gpio/mxc_gpio.c
> +++ b/drivers/gpio/mxc_gpio.c
> @@ -372,7 +372,7 @@ static const struct mxc_gpio_plat mxc_plat[] = {
>   #endif
>   };
>   
> -U_BOOT_DEVICES(mxc_gpios) = {
> +U_BOOT_DRVINFOS(mxc_gpios) = {
>   	{ "gpio_mxc", &mxc_plat[0] },
>   	{ "gpio_mxc", &mxc_plat[1] },
>   	{ "gpio_mxc", &mxc_plat[2] }, diff --git a/drivers/remoteproc/sandbox_testproc.c 
> b/drivers/remoteproc/sandbox_testproc.c index ee2ee730712..6836eca4c55 
> 100644 --- a/drivers/remoteproc/sandbox_testproc.c +++ 
> b/drivers/remoteproc/sandbox_testproc.c @@ -352,7 +352,7 @@ static 
> struct dm_rproc_uclass_pdata proc_3_test = { .mem_type = 
> RPROC_INTERNAL_MEMORY_MAPPED, }; -U_BOOT_DEVICE(proc_3_demo) = { 
> +U_BOOT_DRVINFO(proc_3_demo) = { .name = "sandbox_test_proc",
>   	.plat = &proc_3_test,
>   };
> diff --git a/drivers/rtc/emul_rtc.c b/drivers/rtc/emul_rtc.c
> index 1dc80ca1274..8f0e1ab5ac6 100644
> --- a/drivers/rtc/emul_rtc.c
> +++ b/drivers/rtc/emul_rtc.c
> @@ -91,6 +91,6 @@ U_BOOT_DRIVER(rtc_emul) = {
>   	.priv_auto	= sizeof(struct emul_rtc),
>   };
>   
> -U_BOOT_DEVICE(rtc_emul) = {
> +U_BOOT_DRVINFO(rtc_emul) = {
>   	.name	= "rtc_emul", }; diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c 
> index 19368ba2560..756738c2d21 100644 --- a/drivers/serial/sandbox.c 
> +++ b/drivers/serial/sandbox.c @@ -241,7 +241,7 @@ static const struct 
> sandbox_serial_plat platdata_non_fdt = { .colour = -1, }; 
> -U_BOOT_DEVICE(serial_sandbox_non_fdt) = { 
> +U_BOOT_DRVINFO(serial_sandbox_non_fdt) = { .name = "sandbox_serial",
>   	.plat = &platdata_non_fdt,
>   };
> diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
> index 8eca7d8bfda..08685823e99 100644
> --- a/drivers/sysreset/sysreset_sandbox.c
> +++ b/drivers/sysreset/sysreset_sandbox.c
> @@ -47,7 +47,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
>   
>   	/*
>   	 * If we have a device tree, the device we created from platform data
> -	 * (see the U_BOOT_DEVICE() declaration below) should not do anything.
> +	 * (see the U_BOOT_DRVINFO() declaration below) should not do anything.
>   	 * If we are that device, return an error.
>   	 */
>   	if (state->fdt_fname && !dev_has_ofnode(dev))
> @@ -135,7 +135,7 @@ U_BOOT_DRIVER(warm_sysreset_sandbox) = {
>   
>   #if !CONFIG_IS_ENABLED(OF_PLATDATA)
>   /* This is here in case we don't have a device tree */
> -U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
> +U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
>   	.name = "sysreset_sandbox",
>   };
>   #endif
> diff --git a/drivers/timer/sandbox_timer.c b/drivers/timer/sandbox_timer.c
> index 135c0f38a4d..2075cd4edda 100644
> --- a/drivers/timer/sandbox_timer.c
> +++ b/drivers/timer/sandbox_timer.c
> @@ -65,6 +65,6 @@ U_BOOT_DRIVER(sandbox_timer) = {
>   };
>   
>   /* This is here in case we don't have a device tree */
> -U_BOOT_DEVICE(sandbox_timer_non_fdt) = {
> +U_BOOT_DRVINFO(sandbox_timer_non_fdt) = {
>   	.name = "sandbox_timer", }; diff --git a/drivers/video/sunxi/sunxi_de2.c 
> b/drivers/video/sunxi/sunxi_de2.c index 50657a77d36..a3e21aa5f13 
> 100644 --- a/drivers/video/sunxi/sunxi_de2.c +++ 
> b/drivers/video/sunxi/sunxi_de2.c @@ -319,7 +319,7 @@ 
> U_BOOT_DRIVER(sunxi_de2) = { .flags = DM_FLAG_PRE_RELOC, }; 
> -U_BOOT_DEVICE(sunxi_de2) = { +U_BOOT_DRVINFO(sunxi_de2) = { .name = "sunxi_de2"
>   };
>   
> diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c b/drivers/video/sunxi/sunxi_dw_hdmi.c
> index 3e8d71538f2..0b8cefc311e 100644
> --- a/drivers/video/sunxi/sunxi_dw_hdmi.c
> +++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
> @@ -398,6 +398,6 @@ U_BOOT_DRIVER(sunxi_dw_hdmi) = {
>   	.priv_auto	= sizeof(struct sunxi_dw_hdmi_priv),
>   };
>   
> -U_BOOT_DEVICE(sunxi_dw_hdmi) = {
> +U_BOOT_DRVINFO(sunxi_dw_hdmi) = {
>   	.name = "sunxi_dw_hdmi" }; diff --git a/drivers/video/sunxi/sunxi_lcd.c 
> b/drivers/video/sunxi/sunxi_lcd.c index dd2bb1f5fc5..635edf6dd3b 
> 100644 --- a/drivers/video/sunxi/sunxi_lcd.c +++ 
> b/drivers/video/sunxi/sunxi_lcd.c @@ -146,7 +146,7 @@ 
> U_BOOT_DRIVER(sunxi_lcd) = { }; #ifdef CONFIG_MACH_SUN50I 
> -U_BOOT_DEVICE(sunxi_lcd) = { +U_BOOT_DRVINFO(sunxi_lcd) = { .name = "sunxi_lcd"
>   };
>   #endif
> diff --git a/dts/Kconfig b/dts/Kconfig
> index aeda542f985..71f50552e4f 100644
> --- a/dts/Kconfig
> +++ b/dts/Kconfig
> @@ -346,13 +346,13 @@ config SPL_OF_PLATDATA
>   	  former can add 3KB or more to a Thumb 2 Image.
>   
>   	  This option enables generation of platform data from the device
> -	  tree as C code. This code creates devices using U_BOOT_DEVICE()
> +	  tree as C code. This code creates devices using U_BOOT_DRVINFO()
>   	  declarations. The benefit is that it allows driver code to access
>   	  the platform data directly in C structures, avoidin the libfdt
>   	  overhead.
>   
>   	  This option works by generating C structure declarations for each
> -	  compatible string, then adding platform data and U_BOOT_DEVICE
> +	  compatible string, then adding platform data and U_BOOT_DRVINFO
>   	  declarations for each node. See of-plat.txt for more information.
>   
>   config SPL_OF_PLATDATA_PARENT
> @@ -376,13 +376,13 @@ config TPL_OF_PLATDATA
>   	  former can add 3KB or more to a Thumb 2 Image.
>   
>   	  This option enables generation of platform data from the device
> -	  tree as C code. This code creates devices using U_BOOT_DEVICE()
> +	  tree as C code. This code creates devices using U_BOOT_DRVINFO()
>   	  declarations. The benefit is that it allows driver code to access
>   	  the platform data directly in C structures, avoidin the libfdt
>   	  overhead.
>   
>   	  This option works by generating C structure declarations for each
> -	  compatible string, then adding platform data and U_BOOT_DEVICE
> +	  compatible string, then adding platform data and U_BOOT_DRVINFO
>   	  declarations for each node. See of-plat.txt for more information.
>   
>   config TPL_OF_PLATDATA_PARENT
> diff --git a/include/dm/device.h b/include/dm/device.h
> index 4469804a00e..e16ba2405f9 100644
> --- a/include/dm/device.h
> +++ b/include/dm/device.h
> @@ -104,7 +104,7 @@ enum {
>    * particular port or peripheral (essentially a driver instance).
>    *
>    * A device will come into existence through a 'bind' call, either due to
> - * a U_BOOT_DEVICE() macro (in which case plat is non-NULL) or a node
> + * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node
>    * in the device tree (in which case of_offset is >= 0). In the latter case
>    * we translate the device tree information into plat in a function
>    * implemented by the driver of_to_plat method (called just before the
> @@ -293,7 +293,7 @@ struct udevice_id {
>    * platform data to be allocated in the device's ->plat pointer.
>    * This is typically only useful for device-tree-aware drivers (those with
>    * an of_match), since drivers which use plat will have the data
> - * provided in the U_BOOT_DEVICE() instantiation.
> + * provided in the U_BOOT_DRVINFO() instantiation.
>    * @per_child_auto: Each device can hold private data owned by
>    * its parent. If required this will be automatically allocated if this
>    * value is non-zero.
> diff --git a/include/dm/lists.h b/include/dm/lists.h
> index 070bc9c19f6..1a865525461 100644
> --- a/include/dm/lists.h
> +++ b/include/dm/lists.h
> @@ -35,7 +35,7 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id);
>   /**
>    * lists_bind_drivers() - search for and bind all drivers to parent
>    *
> - * This searches the U_BOOT_DEVICE() structures and creates new devices for
> + * This searches the U_BOOT_DRVINFO() structures and creates new devices for
>    * each one. The devices will have @parent as their parent.
>    *
>    * @parent: parent device (root)
> diff --git a/include/dm/platdata.h b/include/dm/platdata.h
> index d650fb39190..e2b16ce6e4e 100644
> --- a/include/dm/platdata.h
> +++ b/include/dm/platdata.h
> @@ -56,31 +56,31 @@ struct driver_rt {
>    * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
>    * available). U-Boot's driver model uses device tree for configuration.
>    *
> - * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the
> + * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the
>    * dt-plat.c file created by dtoc
>    */
>   #if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C)
> -#define U_BOOT_DEVICE(__name)	_Static_assert(false, \
> -	"Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead")
> +#define U_BOOT_DRVINFO(__name)	_Static_assert(false, \
> +	"Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead")
>   #else
> -#define U_BOOT_DEVICE(__name)						\
> +#define U_BOOT_DRVINFO(__name)						\
>   	ll_entry_declare(struct driver_info, __name, driver_info)
>   #endif
>   
>   /* Declare a list of devices. The argument is a driver_info[] array */
> -#define U_BOOT_DEVICES(__name)						\
> +#define U_BOOT_DRVINFOS(__name)						\
>   	ll_entry_declare_list(struct driver_info, __name, driver_info)
>   
>   /**
>    * Get a pointer to a given device info given its name
>    *
> - * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
> + * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a
>    * pointer to the struct driver_info created by that declaration.
>    *
>    * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
>    * struct driver_info to find the device pointer itself.
>    *
> - * TODO(sjg at chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so
> + * TODO(sjg at chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so
>    * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
>    * finds the driver_info record, not the device.
>    *
> @@ -93,7 +93,7 @@ struct driver_rt {
>   /**
>    * dm_populate_phandle_data() - Populates phandle data in platda
>    *
> - * This populates phandle data with an U_BOOT_DEVICE entry get by
> + * This populates phandle data with an U_BOOT_DRVINFO entry get by
>    * DM_GET_DEVICE. The implementation of this function will be done
>    * by dtoc when parsing dtb.
>    */
> diff --git a/include/dm/platform_data/spi_pl022.h b/include/dm/platform_data/spi_pl022.h
> index c5aa3212915..7f74b3cbc5c 100644
> --- a/include/dm/platform_data/spi_pl022.h
> +++ b/include/dm/platform_data/spi_pl022.h
> @@ -3,7 +3,7 @@
>    * (C) Copyright 2018
>    * Quentin Schulz, Bootlin,quentin.schulz at bootlin.com
>    *
> - * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use
> + * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use
>    * in of_to_plat.
>    */
>   
> diff --git a/test/dm/core.c b/test/dm/core.c
> index 580d171e30e..82b7a668ddc 100644
> --- a/test/dm/core.c
> +++ b/test/dm/core.c
> @@ -43,17 +43,17 @@ static const struct dm_test_pdata test_pdata_pre_reloc = {
>   	.ping_add		= TEST_INTVAL_PRE_RELOC,
>   };
>   
> -U_BOOT_DEVICE(dm_test_info1) = {
> +U_BOOT_DRVINFO(dm_test_info1) = {
>   	.name = "test_drv",
>   	.plat = &test_pdata[0],
>   };
>   
> -U_BOOT_DEVICE(dm_test_info2) = {
> +U_BOOT_DRVINFO(dm_test_info2) = {
>   	.name = "test_drv",
>   	.plat = &test_pdata[1],
>   };
>   
> -U_BOOT_DEVICE(dm_test_info3) = {
> +U_BOOT_DRVINFO(dm_test_info3) = {
>   	.name = "test_drv",
>   	.plat = &test_pdata[2],
>   };
> diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
> index 7bd19891139..ebe5132e143 100644
> --- a/tools/dtoc/dtb_platdata.py
> +++ b/tools/dtoc/dtb_platdata.py
> @@ -713,14 +713,14 @@ class DtbPlatdata():
>       def _declare_device(self, var_name, struct_name, node_parent):
>           """Add a device declaration to the output
>   
> -        This declares a U_BOOT_DEVICE() for the device being processed
> +        This declares a U_BOOT_DRVINFO() for the device being processed
>   
>           Args:
>               var_name (str): C name for the node
>               struct_name (str): Name for the dt struct associated with the node
>               node_parent (Node): Parent of the node (or None if none)
>           """
> -        self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
> +        self.buf('U_BOOT_DRVINFO(%s) = {\n' % var_name)
>           self.buf('\t.name\t\t= "%s",\n' % struct_name)
>           self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
>           self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
> @@ -783,14 +783,14 @@ class DtbPlatdata():
>           """Generate device defintions for the platform data
>   
>           This writes out C platform data initialisation data and
> -        U_BOOT_DEVICE() declarations for each valid node. Where a node has
> +        U_BOOT_DRVINFO() declarations for each valid node. Where a node has
>           multiple compatible strings, a #define is used to make them equivalent.
>   
>           See the documentation in doc/driver-model/of-plat.rst for more
>           information.
>           """
>           self.out_header()
> -        self.out('/* Allow use of U_BOOT_DEVICE() in this file */\n')
> +        self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
>           self.out('#define DT_PLATDATA_C\n')
>           self.out('\n')
>           self.out('#include <common.h>\n')
> diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
> index fb65f284ceb..dbd4e3bf1d4 100755
> --- a/tools/dtoc/test_dtoc.py
> +++ b/tools/dtoc/test_dtoc.py
> @@ -44,7 +44,7 @@ C_HEADER = '''/*
>    * This file was generated by dtoc from a .dtb (device tree binary) file.
>    */
>   
> -/* Allow use of U_BOOT_DEVICE() in this file */
> +/* Allow use of U_BOOT_DRVINFO() in this file */
>   #define DT_PLATDATA_C
>   
>   #include <common.h>
> @@ -214,7 +214,7 @@ struct dtd_sandbox_spl_test {
>   /* Node /i2c at 0 index 0 */
>   static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
>   };
> -U_BOOT_DEVICE(i2c_at_0) = {
> +U_BOOT_DRVINFO(i2c_at_0) = {
>   \t.name\t\t= "sandbox_i2c_test",
>   \t.plat\t= &dtv_i2c_at_0,
>   \t.plat_size\t= sizeof(dtv_i2c_at_0),
> @@ -226,7 +226,7 @@ static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
>   \t.low_power\t\t= true,
>   \t.reg\t\t\t= {0x9, 0x0},
>   };
> -U_BOOT_DEVICE(pmic_at_9) = {
> +U_BOOT_DRVINFO(pmic_at_9) = {
>   \t.name\t\t= "sandbox_pmic_test",
>   \t.plat\t= &dtv_pmic_at_9,
>   \t.plat_size\t= sizeof(dtv_pmic_at_9),
> @@ -246,7 +246,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test = {
>   \t.stringarray\t\t= {"multi-word", "message", ""},
>   \t.stringval\t\t= "message",
>   };
> -U_BOOT_DEVICE(spl_test) = {
> +U_BOOT_DRVINFO(spl_test) = {
>   \t.name\t\t= "sandbox_spl_test",
>   \t.plat\t= &dtv_spl_test,
>   \t.plat_size\t= sizeof(dtv_spl_test),
> @@ -265,7 +265,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = {
>   \t.stringarray\t\t= {"another", "multi-word", "message"},
>   \t.stringval\t\t= "message2",
>   };
> -U_BOOT_DEVICE(spl_test2) = {
> +U_BOOT_DRVINFO(spl_test2) = {
>   \t.name\t\t= "sandbox_spl_test",
>   \t.plat\t= &dtv_spl_test2,
>   \t.plat_size\t= sizeof(dtv_spl_test2),
> @@ -278,7 +278,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test3 = {
>   \t\t0x0},
>   \t.stringarray\t\t= {"one", "", ""},
>   };
> -U_BOOT_DEVICE(spl_test3) = {
> +U_BOOT_DRVINFO(spl_test3) = {
>   \t.name\t\t= "sandbox_spl_test",
>   \t.plat\t= &dtv_spl_test3,
>   \t.plat_size\t= sizeof(dtv_spl_test3),
> @@ -333,7 +333,7 @@ static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
>   \t.gpio_controller\t= true,
>   \t.sandbox_gpio_count\t= 0x14,
>   };
> -U_BOOT_DEVICE(gpios_at_0) = {
> +U_BOOT_DRVINFO(gpios_at_0) = {
>   \t.name\t\t= "sandbox_gpio",
>   \t.plat\t= &dtv_gpios_at_0,
>   \t.plat_size\t= sizeof(dtv_gpios_at_0),
> @@ -365,7 +365,7 @@ struct dtd_invalid {
>   /* Node /spl-test index 0 */
>   static struct dtd_invalid dtv_spl_test = {
>   };
> -U_BOOT_DEVICE(spl_test) = {
> +U_BOOT_DRVINFO(spl_test) = {
>   \t.name\t\t= "invalid",
>   \t.plat\t= &dtv_spl_test,
>   \t.plat_size\t= sizeof(dtv_spl_test),
> @@ -400,7 +400,7 @@ struct dtd_target {
>   static struct dtd_target dtv_phandle2_target = {
>   \t.intval\t\t\t= 0x1,
>   };
> -U_BOOT_DEVICE(phandle2_target) = {
> +U_BOOT_DRVINFO(phandle2_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle2_target,
>   \t.plat_size\t= sizeof(dtv_phandle2_target),
> @@ -411,7 +411,7 @@ U_BOOT_DEVICE(phandle2_target) = {
>   static struct dtd_target dtv_phandle3_target = {
>   \t.intval\t\t\t= 0x2,
>   };
> -U_BOOT_DEVICE(phandle3_target) = {
> +U_BOOT_DRVINFO(phandle3_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle3_target,
>   \t.plat_size\t= sizeof(dtv_phandle3_target),
> @@ -422,7 +422,7 @@ U_BOOT_DEVICE(phandle3_target) = {
>   static struct dtd_target dtv_phandle_target = {
>   \t.intval\t\t\t= 0x0,
>   };
> -U_BOOT_DEVICE(phandle_target) = {
> +U_BOOT_DRVINFO(phandle_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle_target,
>   \t.plat_size\t= sizeof(dtv_phandle_target),
> @@ -437,7 +437,7 @@ static struct dtd_source dtv_phandle_source = {
>   \t\t\t{1, {12, 13}},
>   \t\t\t{4, {}},},
>   };
> -U_BOOT_DEVICE(phandle_source) = {
> +U_BOOT_DRVINFO(phandle_source) = {
>   \t.name\t\t= "source",
>   \t.plat\t= &dtv_phandle_source,
>   \t.plat_size\t= sizeof(dtv_phandle_source),
> @@ -449,7 +449,7 @@ static struct dtd_source dtv_phandle_source2 = {
>   \t.clocks\t\t\t= {
>   \t\t\t{4, {}},},
>   };
> -U_BOOT_DEVICE(phandle_source2) = {
> +U_BOOT_DRVINFO(phandle_source2) = {
>   \t.name\t\t= "source",
>   \t.plat\t= &dtv_phandle_source2,
>   \t.plat_size\t= sizeof(dtv_phandle_source2),
> @@ -487,7 +487,7 @@ struct dtd_target {
>   /* Node /phandle-target index 1 */
>   static struct dtd_target dtv_phandle_target = {
>   };
> -U_BOOT_DEVICE(phandle_target) = {
> +U_BOOT_DRVINFO(phandle_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle_target,
>   \t.plat_size\t= sizeof(dtv_phandle_target),
> @@ -499,7 +499,7 @@ static struct dtd_source dtv_phandle_source2 = {
>   \t.clocks\t\t\t= {
>   \t\t\t{1, {}},},
>   };
> -U_BOOT_DEVICE(phandle_source2) = {
> +U_BOOT_DRVINFO(phandle_source2) = {
>   \t.name\t\t= "source",
>   \t.plat\t= &dtv_phandle_source2,
>   \t.plat_size\t= sizeof(dtv_phandle_source2),
> @@ -522,7 +522,7 @@ void dm_populate_phandle_data(void) {
>   static struct dtd_target dtv_phandle2_target = {
>   \t.intval\t\t\t= 0x1,
>   };
> -U_BOOT_DEVICE(phandle2_target) = {
> +U_BOOT_DRVINFO(phandle2_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle2_target,
>   \t.plat_size\t= sizeof(dtv_phandle2_target),
> @@ -533,7 +533,7 @@ U_BOOT_DEVICE(phandle2_target) = {
>   static struct dtd_target dtv_phandle3_target = {
>   \t.intval\t\t\t= 0x2,
>   };
> -U_BOOT_DEVICE(phandle3_target) = {
> +U_BOOT_DRVINFO(phandle3_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle3_target,
>   \t.plat_size\t= sizeof(dtv_phandle3_target),
> @@ -544,7 +544,7 @@ U_BOOT_DEVICE(phandle3_target) = {
>   static struct dtd_target dtv_phandle_target = {
>   \t.intval\t\t\t= 0x0,
>   };
> -U_BOOT_DEVICE(phandle_target) = {
> +U_BOOT_DRVINFO(phandle_target) = {
>   \t.name\t\t= "target",
>   \t.plat\t= &dtv_phandle_target,
>   \t.plat_size\t= sizeof(dtv_phandle_target),
> @@ -559,7 +559,7 @@ static struct dtd_source dtv_phandle_source = {
>   \t\t\t{1, {12, 13}},
>   \t\t\t{4, {}},},
>   };
> -U_BOOT_DEVICE(phandle_source) = {
> +U_BOOT_DRVINFO(phandle_source) = {
>   \t.name\t\t= "source",
>   \t.plat\t= &dtv_phandle_source,
>   \t.plat_size\t= sizeof(dtv_phandle_source),
> @@ -571,7 +571,7 @@ static struct dtd_source dtv_phandle_source2 = {
>   \t.cd_gpios\t\t= {
>   \t\t\t{4, {}},},
>   };
> -U_BOOT_DEVICE(phandle_source2) = {
> +U_BOOT_DRVINFO(phandle_source2) = {
>   \t.name\t\t= "source",
>   \t.plat\t= &dtv_phandle_source2,
>   \t.plat_size\t= sizeof(dtv_phandle_source2),
> @@ -629,7 +629,7 @@ struct dtd_test3 {
>   static struct dtd_test1 dtv_test1 = {
>   \t.reg\t\t\t= {0x1234, 0x5678},
>   };
> -U_BOOT_DEVICE(test1) = {
> +U_BOOT_DRVINFO(test1) = {
>   \t.name\t\t= "test1",
>   \t.plat\t= &dtv_test1,
>   \t.plat_size\t= sizeof(dtv_test1),
> @@ -640,7 +640,7 @@ U_BOOT_DEVICE(test1) = {
>   static struct dtd_test2 dtv_test2 = {
>   \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
>   };
> -U_BOOT_DEVICE(test2) = {
> +U_BOOT_DRVINFO(test2) = {
>   \t.name\t\t= "test2",
>   \t.plat\t= &dtv_test2,
>   \t.plat_size\t= sizeof(dtv_test2),
> @@ -651,7 +651,7 @@ U_BOOT_DEVICE(test2) = {
>   static struct dtd_test3 dtv_test3 = {
>   \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
>   };
> -U_BOOT_DEVICE(test3) = {
> +U_BOOT_DRVINFO(test3) = {
>   \t.name\t\t= "test3",
>   \t.plat\t= &dtv_test3,
>   \t.plat_size\t= sizeof(dtv_test3),
> @@ -684,7 +684,7 @@ struct dtd_test2 {
>   static struct dtd_test1 dtv_test1 = {
>   \t.reg\t\t\t= {0x1234, 0x5678},
>   };
> -U_BOOT_DEVICE(test1) = {
> +U_BOOT_DRVINFO(test1) = {
>   \t.name\t\t= "test1",
>   \t.plat\t= &dtv_test1,
>   \t.plat_size\t= sizeof(dtv_test1),
> @@ -695,7 +695,7 @@ U_BOOT_DEVICE(test1) = {
>   static struct dtd_test2 dtv_test2 = {
>   \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
>   };
> -U_BOOT_DEVICE(test2) = {
> +U_BOOT_DRVINFO(test2) = {
>   \t.name\t\t= "test2",
>   \t.plat\t= &dtv_test2,
>   \t.plat_size\t= sizeof(dtv_test2),
> @@ -731,7 +731,7 @@ struct dtd_test3 {
>   static struct dtd_test1 dtv_test1 = {
>   \t.reg\t\t\t= {0x123400000000, 0x5678},
>   };
> -U_BOOT_DEVICE(test1) = {
> +U_BOOT_DRVINFO(test1) = {
>   \t.name\t\t= "test1",
>   \t.plat\t= &dtv_test1,
>   \t.plat_size\t= sizeof(dtv_test1),
> @@ -742,7 +742,7 @@ U_BOOT_DEVICE(test1) = {
>   static struct dtd_test2 dtv_test2 = {
>   \t.reg\t\t\t= {0x1234567890123456, 0x98765432},
>   };
> -U_BOOT_DEVICE(test2) = {
> +U_BOOT_DRVINFO(test2) = {
>   \t.name\t\t= "test2",
>   \t.plat\t= &dtv_test2,
>   \t.plat_size\t= sizeof(dtv_test2),
> @@ -753,7 +753,7 @@ U_BOOT_DEVICE(test2) = {
>   static struct dtd_test3 dtv_test3 = {
>   \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
>   };
> -U_BOOT_DEVICE(test3) = {
> +U_BOOT_DRVINFO(test3) = {
>   \t.name\t\t= "test3",
>   \t.plat\t= &dtv_test3,
>   \t.plat_size\t= sizeof(dtv_test3),
> @@ -789,7 +789,7 @@ struct dtd_test3 {
>   static struct dtd_test1 dtv_test1 = {
>   \t.reg\t\t\t= {0x1234, 0x567800000000},
>   };
> -U_BOOT_DEVICE(test1) = {
> +U_BOOT_DRVINFO(test1) = {
>   \t.name\t\t= "test1",
>   \t.plat\t= &dtv_test1,
>   \t.plat_size\t= sizeof(dtv_test1),
> @@ -800,7 +800,7 @@ U_BOOT_DEVICE(test1) = {
>   static struct dtd_test2 dtv_test2 = {
>   \t.reg\t\t\t= {0x12345678, 0x9876543210987654},
>   };
> -U_BOOT_DEVICE(test2) = {
> +U_BOOT_DRVINFO(test2) = {
>   \t.name\t\t= "test2",
>   \t.plat\t= &dtv_test2,
>   \t.plat_size\t= sizeof(dtv_test2),
> @@ -811,7 +811,7 @@ U_BOOT_DEVICE(test2) = {
>   static struct dtd_test3 dtv_test3 = {
>   \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
>   };
> -U_BOOT_DEVICE(test3) = {
> +U_BOOT_DRVINFO(test3) = {
>   \t.name\t\t= "test3",
>   \t.plat\t= &dtv_test3,
>   \t.plat_size\t= sizeof(dtv_test3),
> @@ -863,7 +863,7 @@ struct dtd_sandbox_spl_test {
>   static struct dtd_sandbox_spl_test dtv_spl_test = {
>   \t.intval\t\t\t= 0x1,
>   };
> -U_BOOT_DEVICE(spl_test) = {
> +U_BOOT_DRVINFO(spl_test) = {
>   \t.name\t\t= "sandbox_spl_test",
>   \t.plat\t= &dtv_spl_test,
>   \t.plat_size\t= sizeof(dtv_spl_test),
> @@ -874,7 +874,7 @@ U_BOOT_DEVICE(spl_test) = {
>   static struct dtd_sandbox_spl_test dtv_spl_test2 = {
>   \t.intarray\t\t= 0x5,
>   };
> -U_BOOT_DEVICE(spl_test2) = {
> +U_BOOT_DRVINFO(spl_test2) = {
>   \t.name\t\t= "sandbox_spl_test",
>   \t.plat\t= &dtv_spl_test2,
>   \t.plat_size\t= sizeof(dtv_spl_test2),

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 22/49] dtoc: Tidy up src_scan tests
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (48 preceding siblings ...)
  2020-12-29  3:35 ` [PATCH 49/49] dtoc: Generate device instances Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 21/49] dtoc: Move src_scan tests to a separate file Simon Glass
                   ` (18 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Some of these tests don't actually check anything. Add a few more checks
to complete the tests.

Also add a simple scan test that does the basics.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_src_scan.py | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 21/49] dtoc: Move src_scan tests to a separate file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (49 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 20/49] dtoc: Split source-code scanning " Simon Glass
                   ` (17 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Move the tests related to scanning into their own class, updating them
to avoid using dtb_platdata as a pass-through.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py  |  2 +-
 tools/dtoc/main.py          |  5 +-
 tools/dtoc/src_scan.py      |  4 +-
 tools/dtoc/test_dtoc.py     | 73 -----------------------------
 tools/dtoc/test_src_scan.py | 91 +++++++++++++++++++++++++++++++++++++
 5 files changed, 97 insertions(+), 78 deletions(-)
 create mode 100644 tools/dtoc/test_src_scan.py

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 20/49] dtoc: Split source-code scanning to a separate file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (50 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 21/49] dtoc: Move src_scan tests to a separate file Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
                   ` (16 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Before expanding the scanning features any more, move this into a separate
file. This will make it easier to maintain in the future. In particular,
it reduces the size of dtb_platdata.py and allows us to add tests
specifically for scanning, without going through that file.

The pieces moved are the Driver class, the scanning code and the various
naming functions, since they mostly depend on the scanning results.

So far there is are no separate tests for src_scan. These will be added
as new functionality appears.

This introduces no functional change.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 174 +++-------------------------------
 tools/dtoc/src_scan.py     | 185 +++++++++++++++++++++++++++++++++++++
 tools/dtoc/test_dtoc.py    |  14 +--
 3 files changed, 204 insertions(+), 169 deletions(-)
 create mode 100644 tools/dtoc/src_scan.py

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 19/49] dtoc: Drop dm_populate_phandle_data()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (51 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 20/49] dtoc: Split source-code scanning " Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
                   ` (15 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

This has not been needed since parent information was added and we started
using indicies for references to other drivers instead of pointers. It was
kept around in the expectation that it might be needed later.

However with the latest updates, it doesn't seem likely that we'll need
this in the foreseeable future.

Drop dm_populate_phandle_data() from dtoc and driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst | 16 ++++++----------
 drivers/core/root.c          |  3 ---
 include/dm/platdata.h        |  8 --------
 tools/dtoc/dtb_platdata.py   |  6 ------
 tools/dtoc/test_dtoc.py      | 29 +++++++----------------------
 5 files changed, 13 insertions(+), 49 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 18/49] dtoc: Output nodes in order
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (52 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
                   ` (14 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Previously we had to worry about nodes being output before those that they
depended on, thus causing build errors.  So the current algorithm is
careful to output nodes in the right order.

We now use a different method for outputting phandles that does not
involve pointers. Also we plan to add a 'declarations' header file to
declare all drivers as 'extern'.

Update the code to drop the dependency checking and output in a simple
loop. This makes the output easier to follow since drivers are in order of
thier indices (0, 1, ...), which is also the order it appears in in the
linker list.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 13 ++------
 tools/dtoc/test_dtoc.py    | 64 +++++++++++++++++++-------------------
 2 files changed, 34 insertions(+), 43 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 17/49] dtoc: Allow specifying the base directory for tests
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (53 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
                   ` (13 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

The base directory of U-Boot, where the source is, it currently calculated
from the directory of the dtb_platdata.py script. If this is installed
elsewhere that will not work. Also it is inconvenient for tests.

Add a parameter to allow specifying this base directory.

To test this, pass a temporary directory with some files in it and check
that they are passed to scan_driver().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 18 ++++++++++++------
 tools/dtoc/test_dtoc.py    | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 16/49] dtoc: Add the method for each command to OutputFile
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (54 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
                   ` (12 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Rather than the if/else construct, update OutputFile with the method to
call to process each command. This is easier to maintain as the number of
commands increases.

Rename generate_tables to generate_plat since it better describes what is
being generated ('plat' is the U-Boot name for platform data).

With this, each output method needs to have the same signature. Store the
output structures in a member variable instead of using parameters, to
accomplish this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 42 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (55 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
                   ` (11 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Use this new name to be consistent with the rest of U-Boot, which talks
about 'plat' for the platform data, which is what this file holds.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/dm/platdata.h       | 2 +-
 include/linux/mtd/spi-nor.h | 2 +-
 scripts/Makefile.spl        | 2 +-
 tools/dtoc/dtb_platdata.py  | 4 ++--
 tools/dtoc/test_dtoc.py     | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 14/49] dtoc: Add a header comment to each generated file
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (56 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
                   ` (10 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

It is currently fairly obvious what the two generated files are for, but
this will change as more are added. It is helpful for readers to describe
the purpose of each file.

Add a header commment field to OutputFile and use it to generate a comment
at the top of each file.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 30 ++++++++++++++++++++----------
 tools/dtoc/test_dtoc.py    |  6 ++++--
 2 files changed, 24 insertions(+), 12 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 13/49] dtoc: Run tests using test_util
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (57 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:12 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
                   ` (9 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

Use the standard function for running tests and reported results. This
allows the tests to run in parallel, which is a significant speed-up on
most machines (e.g. 4.5 seconds -> 1.5s on mine).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/main.py | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 12/49] concurrencytest: Fix Python3 warning
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (58 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
@ 2021-01-06 15:12 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
                   ` (8 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:12 UTC (permalink / raw)
  To: u-boot

This gives a warning in some situations:

  File "tools/dtoc/../concurrencytest/concurrencytest.py", line 95,
       in do_fork
    stream = os.fdopen(c2pread, 'rb', 1)
  File "/usr/lib/python3.8/os.py", line 1023, in fdopen
    return io.open(fd, *args, **kwargs)
RuntimeWarning: line buffering (buffering=1) isn't supported in binary
    mode, the default buffer size will be used

Fix this by dropping the line-buffer parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/concurrencytest/concurrencytest.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (59 preceding siblings ...)
  2021-01-06 15:12 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
                   ` (7 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

We use the U_BOOT_ prefix (i.e. U_BOOT_DRIVER) to declare a driver but
in every other case we just use DM_. Update the alias macros to use the
DM_ prefix.

We could perhaps rename U_BOOT_DRIVER() to DM_DRIVER(), but this macro
is widely used and there is at least some benefit to indicating it us a
U-Boot driver, particularly for code ported from Linux. So for now, let's
keep that name.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/of-plat.rst          | 6 +++---
 drivers/gpio/mxc_gpio.c               | 2 +-
 drivers/gpio/mxs_gpio.c               | 2 +-
 drivers/gpio/sandbox.c                | 2 +-
 drivers/i2c/rk_i2c.c                  | 2 +-
 drivers/mmc/fsl_esdhc_imx.c           | 2 +-
 drivers/mmc/mxsmmc.c                  | 2 +-
 drivers/mmc/rockchip_dw_mmc.c         | 4 ++--
 drivers/mtd/spi/sf_probe.c            | 2 +-
 drivers/pinctrl/nxp/pinctrl-imx6.c    | 2 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c     | 2 +-
 drivers/pinctrl/pinctrl-at91.c        | 2 +-
 drivers/power/pmic/rk8xx.c            | 2 +-
 drivers/serial/ns16550.c              | 6 +++---
 drivers/spi/mxs_spi.c                 | 2 +-
 drivers/spi/rk_spi.c                  | 2 +-
 include/dm/device.h                   | 2 +-
 tools/dtoc/dtb_platdata.py            | 6 +++---
 tools/dtoc/dtoc_test_scan_drivers.cxx | 2 +-
 19 files changed, 26 insertions(+), 26 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET()
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (60 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
                   ` (6 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

In the spirit of using the same base name for all of these related macros,
rename this to have the operation at the end. This is not widely used so
the impact is fairly small.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/lib/gic-v3-its.c                       | 10 +++++-----
 arch/arm/mach-aspeed/ast2500/clk_ast2500.c      |  2 +-
 arch/arm/mach-k3/am6_init.c                     |  2 +-
 arch/arm/mach-k3/common.c                       |  2 +-
 arch/arm/mach-k3/j721e_init.c                   |  2 +-
 arch/arm/mach-mediatek/mt7629/init.c            |  4 ++--
 arch/arm/mach-mediatek/mt8516/init.c            |  2 +-
 arch/arm/mach-rockchip/misc.c                   |  4 ++--
 arch/arm/mach-rockchip/px30/clk_px30.c          |  2 +-
 arch/arm/mach-rockchip/rk3036/clk_rk3036.c      |  2 +-
 arch/arm/mach-rockchip/rk3128/clk_rk3128.c      |  2 +-
 arch/arm/mach-rockchip/rk3188/clk_rk3188.c      |  2 +-
 arch/arm/mach-rockchip/rk322x/clk_rk322x.c      |  2 +-
 arch/arm/mach-rockchip/rk3288/clk_rk3288.c      |  2 +-
 arch/arm/mach-rockchip/rk3308/clk_rk3308.c      |  2 +-
 arch/arm/mach-rockchip/rk3328/clk_rk3328.c      |  2 +-
 arch/arm/mach-rockchip/rk3368/clk_rk3368.c      |  2 +-
 arch/arm/mach-rockchip/rk3399/clk_rk3399.c      |  4 ++--
 arch/arm/mach-rockchip/rv1108/clk_rv1108.c      |  2 +-
 arch/arm/mach-socfpga/clock_manager_agilex.c    |  2 +-
 arch/arm/mach-stm32mp/bsec.c                    |  2 +-
 arch/arm/mach-stm32mp/cmd_stm32key.c            |  2 +-
 arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c |  6 +++---
 arch/arm/mach-stm32mp/cpu.c                     |  6 +++---
 arch/arm/mach-uniphier/micro-support-card.c     |  2 +-
 arch/arm/mach-zynq/clk.c                        |  4 ++--
 arch/arm/mach-zynq/timer.c                      |  2 +-
 arch/mips/mach-mtmips/mt7628/init.c             |  2 +-
 arch/riscv/lib/sifive_clint.c                   |  2 +-
 board/dhelectronics/dh_stm32mp1/board.c         |  6 +++---
 board/google/gru/gru.c                          |  2 +-
 board/nvidia/jetson-tk1/jetson-tk1.c            |  2 +-
 board/nvidia/nyan-big/nyan-big.c                |  2 +-
 board/renesas/ulcb/cpld.c                       |  2 +-
 board/sifive/fu540/fu540.c                      |  2 +-
 board/st/common/cmd_stboard.c                   |  2 +-
 board/st/common/stm32mp_dfu.c                   |  4 ++--
 board/st/common/stpmic1.c                       |  4 ++--
 board/st/common/stusb160x.c                     |  2 +-
 board/st/stm32mp1/stm32mp1.c                    | 12 ++++++------
 board/ti/j721e/evm.c                            |  4 ++--
 board/toradex/apalis-tk1/apalis-tk1.c           |  4 ++--
 drivers/clk/clk_stm32mp1.c                      |  2 +-
 drivers/clk/clk_zynqmp.c                        |  2 +-
 drivers/clk/imx/clk-imx8.c                      |  2 +-
 drivers/clk/mediatek/clk-mtk.c                  |  6 +++---
 drivers/clk/sifive/fu540-prci.c                 |  2 +-
 drivers/firmware/scmi/scmi_agent-uclass.c       |  4 ++--
 drivers/gpio/gpio-uclass.c                      |  2 +-
 drivers/misc/i2c_eeprom.c                       |  2 +-
 drivers/misc/rockchip-efuse.c                   |  2 +-
 drivers/misc/stm32mp_fuse.c                     | 16 ++++++++--------
 drivers/mtd/nand/raw/arasan_nfc.c               |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c   |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c    |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c   |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c    |  2 +-
 drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c    |  2 +-
 drivers/mtd/nand/raw/davinci_nand.c             |  2 +-
 drivers/mtd/nand/raw/denali_dt.c                |  2 +-
 drivers/mtd/nand/raw/mxs_nand_dt.c              |  2 +-
 drivers/mtd/nand/raw/octeontx_nand.c            |  6 +++---
 drivers/mtd/nand/raw/pxa3xx_nand.c              |  2 +-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c          |  2 +-
 drivers/mtd/nand/raw/tegra_nand.c               |  2 +-
 drivers/mtd/nand/raw/vf610_nfc.c                |  2 +-
 drivers/mtd/nand/raw/zynq_nand.c                |  2 +-
 drivers/reset/reset-ast2500.c                   |  2 +-
 drivers/video/lg4573.c                          |  2 +-
 include/dm/device.h                             |  2 +-
 include/dm/uclass.h                             |  2 +-
 test/dm/core.c                                  |  2 +-
 test/dm/test-fdt.c                              |  6 +++---
 73 files changed, 110 insertions(+), 110 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET()
  2020-12-29  3:34 ` [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() Simon Glass
  2021-01-06  3:40   ` Walter Lozano
@ 2021-01-06 15:13   ` Simon Glass
  1 sibling, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

On 12/29/20 12:34 AM, Simon Glass wrote:
> This does not get a device (struct udevice *) but a struct driver_info *
> so the name is confusing.
>
> Rename it accordingly. Since we plan to have several various of these
> macros, put GET at the end instead of the middle, so it is easier to spot
> the related macros.
>
> Signed-off-by: Simon Glass<sjg@chromium.org>

Reviewed-by: Walter Lozano <walter.lozano@collabora.com>

Thanks,

> ---
>
>   doc/driver-model/of-plat.rst |  2 +-
>   include/dm/platdata.h        | 10 +++-------
>   tools/dtoc/dtb_platdata.py   |  4 ++--
>   3 files changed, 6 insertions(+), 10 deletions(-)
>
Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO()
  2020-12-29  3:34 ` [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() Simon Glass
  2021-01-06  3:40   ` Walter Lozano
@ 2021-01-06 15:13   ` Simon Glass
  1 sibling, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

On 12/29/20 12:34 AM, Simon Glass wrote:
> The current macro is a misnomer since it does not declare a device
> directly. Instead, it declares driver_info record which U-Boot uses at
> runtime to create a device.
>
> The distinction seems somewhat minor most of the time, but is becomes
> quite confusing when we actually want to declare a device, with
> of-platdata. We are left trying to distinguish between a device which
> isn't actually device, and a device that is (perhaps an 'instance'?)
>
> It seems better to rename this macro to describe what it actually is. The
> macros is not widely used, since boards should use devicetree to declare
> devices.
>
> Rename it to U_BOOT_DRVINFO(), which indicates clearly that this is
> declaring a new driver_info record, not a device.
>
> Signed-off-by: Simon Glass<sjg@chromium.org>

I couldn't agree more.

Reviewed-by: Walter Lozano <walter.lozano@collabora.com>

Thanks,

> ---
>
>   .../mach-at91/arm926ejs/at91sam9260_devices.c |  2 +-
>   .../arm926ejs/at91sam9m10g45_devices.c        |  2 +-
>   arch/arm/mach-imx/mx6/soc.c                   |  2 +-
>   arch/arm/mach-imx/mx7/soc.c                   |  2 +-
>   arch/arm/mach-lpc32xx/devices.c               |  4 +-
>   arch/arm/mach-omap2/am33xx/board.c            | 10 +--
>   arch/arm/mach-omap2/omap3/board.c             |  2 +-
>   arch/arm/mach-tegra/board.c                   |  2 +-
>   arch/arm/mach-tegra/board2.c                  |  2 +-
>   board/armltd/integrator/integrator.c          |  2 +-
>   board/armltd/total_compute/total_compute.c    |  2 +-
>   board/armltd/vexpress64/vexpress64.c          |  2 +-
>   board/bluewater/gurnard/gurnard.c             |  2 +-
>   board/bluewater/snapper9260/snapper9260.c     |  2 +-
>   board/cadence/xtfpga/xtfpga.c                 |  4 +-
>   board/cavium/thunderx/thunderx.c              |  4 +-
>   board/compulab/cm_fx6/cm_fx6.c                |  2 +-
>   board/davinci/da8xxevm/omapl138_lcdk.c        |  4 +-
>   board/freescale/ls1012afrdm/eth.c             |  4 +-
>   board/freescale/ls1012aqds/eth.c              |  4 +-
>   board/freescale/ls1012ardb/eth.c              |  4 +-
>   board/freescale/lx2160a/lx2160a.c             |  4 +-
>   board/gateworks/gw_ventana/gw_ventana.c       |  2 +-
>   board/hisilicon/hikey/hikey.c                 |  4 +-
>   board/hisilicon/hikey960/hikey960.c           |  2 +-
>   board/hisilicon/poplar/poplar.c               |  2 +-
>   board/isee/igep00x0/igep00x0.c                |  2 +-
>   board/lg/sniper/sniper.c                      |  2 +-
>   board/nokia/rx51/rx51.c                       |  2 +-
>   board/sandbox/sandbox.c                       |  2 +-
>   board/siemens/corvus/board.c                  |  2 +-
>   board/st/stv0991/stv0991.c                    |  2 +-
>   board/sysam/amcore/amcore.c                   |  2 +-
>   board/ti/am335x/board.c                       |  6 +-
>   board/timll/devkit8000/devkit8000.c           |  2 +-
>   board/toradex/apalis_imx6/apalis_imx6.c       |  2 +-
>   .../toradex/colibri-imx6ull/colibri-imx6ull.c |  2 +-
>   board/toradex/colibri_imx6/colibri_imx6.c     |  2 +-
>   board/toradex/colibri_pxa270/colibri_pxa270.c |  4 +-
>   doc/driver-model/design.rst                   | 18 ++---
>   doc/driver-model/of-plat.rst                  | 12 ++--
>   doc/driver-model/remoteproc-framework.rst     |  2 +-
>   doc/driver-model/spi-howto.rst                |  4 +-
>   drivers/crypto/fsl/fsl_rsa.c                  |  2 +-
>   drivers/crypto/rsa_mod_exp/mod_exp_sw.c       |  2 +-
>   drivers/demo/demo-pdata.c                     | 10 +--
>   drivers/gpio/imx_rgpio2p.c                    |  4 +-
>   drivers/gpio/mxc_gpio.c                       |  2 +-
>   drivers/remoteproc/sandbox_testproc.c         |  2 +-
>   drivers/rtc/emul_rtc.c                        |  2 +-
>   drivers/serial/sandbox.c                      |  2 +-
>   drivers/sysreset/sysreset_sandbox.c           |  4 +-
>   drivers/timer/sandbox_timer.c                 |  2 +-
>   drivers/video/sunxi/sunxi_de2.c               |  2 +-
>   drivers/video/sunxi/sunxi_dw_hdmi.c           |  2 +-
>   drivers/video/sunxi/sunxi_lcd.c               |  2 +-
>   dts/Kconfig                                   |  8 +--
>   include/dm/device.h                           |  4 +-
>   include/dm/lists.h                            |  2 +-
>   include/dm/platdata.h                         | 16 ++---
>   include/dm/platform_data/spi_pl022.h          |  2 +-
>   test/dm/core.c                                |  6 +-
>   tools/dtoc/dtb_platdata.py                    |  8 +--
>   tools/dtoc/test_dtoc.py                       | 66 +++++++++----------
>   64 files changed, 148 insertions(+), 148 deletions(-)
>
Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 07/49] Makefile: Invoke dtoc only once
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (61 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
                   ` (5 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

Update the Makefile to run dtoc only once, generating all required files.
This saves time since there is a lot of processing in each invocation of
dtoc.

We already have a variable for the object files to build, so use that
instead of repeating the same filenames. Add a C version of this also,
for the same reason.

This makes it easier to add new C files (generated by dtoc) to the build
later, as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 scripts/Makefile.spl | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 05/49] dtoc: Allow outputing to multiple files
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (63 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
                   ` (3 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

Implement the 'output directory' feature, allowing dtoc to write the
output files separately to the supplied directories. This allows us to
handle the struct and platdata output in one run of dtoc.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 96 ++++++++++++++++++++++++++++++++++----
 tools/dtoc/test_dtoc.py    |  8 ++++
 2 files changed, 94 insertions(+), 10 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 06/49] dtoc: Add an 'all' command
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (62 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
                   ` (4 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

With upcoming changes, dtoc will output several files for different
of-platdata components.

Add a way to output all ava!ilable files at once ('all'), to the
appropriate directories, without needing to specify each one invidually.

This puts the commands in alphabetical order, so update the tests
accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py |  7 +++++--
 tools/dtoc/main.py         |  6 +-----
 tools/dtoc/test_dtoc.py    | 40 +++++++++++++++++++++++++++++++++++---
 tools/patman/tools.py      |  8 ++++++++
 4 files changed, 51 insertions(+), 10 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 04/49] dtoc: Allow providing a directory to write files to
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (64 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
                   ` (2 subsequent siblings)
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

At present dtoc writes only a single file on each invocation. U-Boot
writes the two files it needs by separate invocations of dtoc. Since dtoc
now scans all U-Boot driver source, this is fairly slow (about 1 second
per file).

It would be better if dtoc could write all the files at once.

In preparation for this, add a way to specify an output directory for the
files.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py |  8 ++++++--
 tools/dtoc/main.py         |  7 ++++++-
 tools/dtoc/test_dtoc.py    | 14 +++++++-------
 3 files changed, 19 insertions(+), 10 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 03/49] dtoc: Test the stdout output
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (65 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
  2021-01-06 15:13 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

Normally dtoc outputs to a file but it also offers a way to write output
to stdout. At present the test for that does not actually check that the
output is correct. Add this to the test.

This uses a member variable to hold the expected text, so it can be used
in muitiple places.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_dtoc.py | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 02/49] dtoc: Use None to mean stdout
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (66 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  2021-01-06 15:13 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

At present dtoc uses '-' internally to mean that output should go to
stdout. This is not necessary and None is more convenient. Update it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 10 +++++-----
 tools/dtoc/main.py         |  2 +-
 tools/dtoc/test_dtoc.py    |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 01/49] dtoc: Tidy up pylint warnings in test
  2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
                   ` (67 preceding siblings ...)
  2021-01-06 15:13 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
@ 2021-01-06 15:13 ` Simon Glass
  68 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-06 15:13 UTC (permalink / raw)
  To: u-boot

Tidy up this file to reduce the number of pylint warnings.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/test_dtoc.py | 156 ++++++++++++++++++++++------------------
 1 file changed, 85 insertions(+), 71 deletions(-)

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 76+ messages in thread

* [PATCH 45/49] dm: of-platadata: Add option for device instantiation
  2021-01-06  3:39   ` Walter Lozano
@ 2021-01-23 15:10     ` Simon Glass
  0 siblings, 0 replies; 76+ messages in thread
From: Simon Glass @ 2021-01-23 15:10 UTC (permalink / raw)
  To: u-boot

Hi Walter,

On Tue, 5 Jan 2021 at 20:40, Walter Lozano <walter.lozano@collabora.com> wrote:
>
>
> On 12/29/20 12:35 AM, Simon Glass wrote:
> > Add Kconfig options to support build-time device instantiation. When
> > fully implemented, this will allow dtoc to create U-Boot devices (i.e.
> > struct udevice records) at build time, thus reducing code space in
> > SPL.
> >
> > For now this defaults to off, but will be enabled when the rest of
> > the implementation is in place.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >   dts/Kconfig          | 23 +++++++++++++++++++++--
> >   scripts/Makefile.spl |  4 ++++
> >   2 files changed, 25 insertions(+), 2 deletions(-)
> >
> > diff --git a/dts/Kconfig b/dts/Kconfig
> > index 71f50552e4f..e861ea48d01 100644
> > --- a/dts/Kconfig
> > +++ b/dts/Kconfig
> > @@ -355,15 +355,24 @@ config SPL_OF_PLATDATA
> >         compatible string, then adding platform data and U_BOOT_DRVINFO
> >         declarations for each node. See of-plat.txt for more information.
> >
> > +if SPL_OF_PLATDATA
> > +
> >   config SPL_OF_PLATDATA_PARENT
> >       bool "Support parent information in devices"
> > -     depends on SPL_OF_PLATDATA
> >       default y
> >       help
> >         Generally it is useful to be able to access the parent of a device
> >         with of-platdata. To save space this can be disabled, but in that
> >         case dev_get_parent() will always return NULL;
> >
> > +config SPL_OF_PLATDATA_INST
>
> Not sure about the limits to config names, I understand that
> SPL_OF_PLATDATA_INST means SPL_OF_PLATDATA_INSTANCE? I'm not sure but
> maybe a better name could be SPL_OF_PLATDATA_BTIME_DEV. To be honest I
> find it difficult to come with nice name.

Yes that's right - INST standards for instantiate. I don't think there
is a limit to the name length, but obviously longer names are harder
to read. BTIME doesn't seem any more enlightening that INST though.

I will try out SPL_OF_PLATDATA_INSTANTIATE and see how long it looks!

>
> > +     bool "Declare devices at build time"
> > +     help
> > +       Declare devices as udevice instances so that they do not need to be
> > +       bound when U-Boot starts. This can save time and code space.
> > +
> > +endif
> > +
> >   config TPL_OF_PLATDATA
> >       bool "Generate platform data for use in TPL"
> >       depends on TPL_OF_CONTROL
> > @@ -385,13 +394,23 @@ config TPL_OF_PLATDATA
> >         compatible string, then adding platform data and U_BOOT_DRVINFO
> >         declarations for each node. See of-plat.txt for more information.
> >
> > +if TPL_OF_PLATDATA
> > +
> >   config TPL_OF_PLATDATA_PARENT
> >       bool "Support parent information in devices"
> > -     depends on TPL_OF_PLATDATA
> >       default y
> >       help
> >         Generally it is useful to be able to access the parent of a device
> >         with of-platdata. To save space this can be disabled, but in that
> >         case dev_get_parent() will always return NULL;
> >
> > +config TPL_OF_PLATDATA_INST
>
> Same here. Also I have a question, in which case TPL_OF_PLATDATA_INST
> and SPL_OF_PLATDATA_INST would have different values. Which is the value
> of decoupling the TPL and SPL behavior? Or is use for consistency with
> SPL_OF_PLATDATA_PARENT and TPL_OF_PLATDATA_PARENT (which also not sure
> if needed to have two different options).

It is partly consistency, but also just that CONFIG_IS_ENABLED() only
works if you define them separately. Also I want to be able to check
TPL_OF_PLATDATA_INST by itself without having to check TPL_OF_PLATDATA
first.

Regards,
Simon

^ permalink raw reply	[flat|nested] 76+ messages in thread

end of thread, other threads:[~2021-01-23 15:10 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29  3:34 [PATCH 00/49] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
2020-12-29  3:34 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass
2020-12-29  3:34 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
2020-12-29  3:34 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
2020-12-29  3:34 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
2020-12-29  3:34 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
2020-12-29  3:34 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
2020-12-29  3:34 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
2020-12-29  3:34 ` [PATCH 08/49] dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() Simon Glass
2021-01-06  3:40   ` Walter Lozano
2021-01-06 15:13   ` Simon Glass
2020-12-29  3:34 ` [PATCH 09/49] dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() Simon Glass
2021-01-06  3:40   ` Walter Lozano
2021-01-06 15:13   ` Simon Glass
2020-12-29  3:34 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
2020-12-29  3:34 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
2020-12-29  3:34 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
2020-12-29  3:34 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
2020-12-29  3:35 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
2020-12-29  3:35 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
2020-12-29  3:35 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
2020-12-29  3:35 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
2020-12-29  3:35 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
2020-12-29  3:35 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
2020-12-29  3:35 ` [PATCH 20/49] dtoc: Split source-code scanning to a separate file Simon Glass
2020-12-29  3:35 ` [PATCH 21/49] dtoc: Move src_scan tests " Simon Glass
2020-12-29  3:35 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
2020-12-29  3:35 ` [PATCH 23/49] dtoc: Scan drivers for available information Simon Glass
2020-12-29  3:35 ` [PATCH 24/49] dtoc: Save scan information across test runs Simon Glass
2020-12-29  3:35 ` [PATCH 25/49] dtoc: Ignore unwanted files when scanning for drivers Simon Glass
2020-12-29  3:35 ` [PATCH 26/49] dtoc: Collect priv/plat struct info from drivers Simon Glass
2020-12-29  3:35 ` [PATCH 27/49] dtoc: Support scanning of uclasses Simon Glass
2020-12-29  3:35 ` [PATCH 28/49] dtoc: Support scanning of structs in header files Simon Glass
2020-12-29  3:35 ` [PATCH 29/49] dtoc: Move test files into a test/ directory Simon Glass
2020-12-29  3:35 ` [PATCH 30/49] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test Simon Glass
2020-12-29  3:35 ` [PATCH 31/49] dtoc: Add some extra properties to nodes Simon Glass
2020-12-29  3:35 ` [PATCH 32/49] dtoc: Make use of node properties Simon Glass
2020-12-29  3:35 ` [PATCH 33/49] dtoc: Process nodes to set up required properties Simon Glass
2020-12-29  3:35 ` [PATCH 34/49] dtoc: Track nodes which are actually used Simon Glass
2020-12-29  3:35 ` [PATCH 35/49] dtoc: Support tracking the phase of U-Boot Simon Glass
2020-12-29  3:35 ` [PATCH 36/49] Makefile: Pass the U-Boot phase to dtoc Simon Glass
2020-12-29  3:35 ` [PATCH 37/49] dtoc: Support headers needed for drivers Simon Glass
2020-12-29  3:35 ` [PATCH 38/49] dtoc: Process driver aliases along with drivers Simon Glass
2020-12-29  3:35 ` [PATCH 39/49] dtoc: Warn of duplicate drivers Simon Glass
2020-12-29  3:35 ` [PATCH 40/49] dtoc: Read aliases for uclasses Simon Glass
2020-12-29  3:35 ` [PATCH 41/49] dtoc: Assign a sequence number to each node Simon Glass
2020-12-29  3:35 ` [PATCH 42/49] dtoc: Set up the uclasses that are used Simon Glass
2020-12-29  3:35 ` [PATCH 43/49] dtoc: Support processing the root node Simon Glass
2020-12-29  3:35 ` [PATCH 44/49] dtoc: Add an option for device instantiation Simon Glass
2020-12-29  3:35 ` [PATCH 45/49] dm: of-platadata: Add " Simon Glass
2021-01-06  3:39   ` Walter Lozano
2021-01-23 15:10     ` Simon Glass
2020-12-29  3:35 ` [PATCH 46/49] dtoc: Add support for decl file Simon Glass
2020-12-29  3:35 ` [PATCH 47/49] dtoc: Don't generate platform data with instantiation Simon Glass
2020-12-29  3:35 ` [PATCH 48/49] dtoc: Generate uclass devices Simon Glass
2020-12-29  3:35 ` [PATCH 49/49] dtoc: Generate device instances Simon Glass
2021-01-06 15:12 ` [PATCH 22/49] dtoc: Tidy up src_scan tests Simon Glass
2021-01-06 15:12 ` [PATCH 21/49] dtoc: Move src_scan tests to a separate file Simon Glass
2021-01-06 15:12 ` [PATCH 20/49] dtoc: Split source-code scanning " Simon Glass
2021-01-06 15:12 ` [PATCH 19/49] dtoc: Drop dm_populate_phandle_data() Simon Glass
2021-01-06 15:12 ` [PATCH 18/49] dtoc: Output nodes in order Simon Glass
2021-01-06 15:12 ` [PATCH 17/49] dtoc: Allow specifying the base directory for tests Simon Glass
2021-01-06 15:12 ` [PATCH 16/49] dtoc: Add the method for each command to OutputFile Simon Glass
2021-01-06 15:12 ` [PATCH 15/49] dtoc: Rename dt-platdata.c to dt-plat.c Simon Glass
2021-01-06 15:12 ` [PATCH 14/49] dtoc: Add a header comment to each generated file Simon Glass
2021-01-06 15:12 ` [PATCH 13/49] dtoc: Run tests using test_util Simon Glass
2021-01-06 15:12 ` [PATCH 12/49] concurrencytest: Fix Python3 warning Simon Glass
2021-01-06 15:13 ` [PATCH 11/49] dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS Simon Glass
2021-01-06 15:13 ` [PATCH 10/49] dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() Simon Glass
2021-01-06 15:13 ` [PATCH 07/49] Makefile: Invoke dtoc only once Simon Glass
2021-01-06 15:13 ` [PATCH 06/49] dtoc: Add an 'all' command Simon Glass
2021-01-06 15:13 ` [PATCH 05/49] dtoc: Allow outputing to multiple files Simon Glass
2021-01-06 15:13 ` [PATCH 04/49] dtoc: Allow providing a directory to write files to Simon Glass
2021-01-06 15:13 ` [PATCH 03/49] dtoc: Test the stdout output Simon Glass
2021-01-06 15:13 ` [PATCH 02/49] dtoc: Use None to mean stdout Simon Glass
2021-01-06 15:13 ` [PATCH 01/49] dtoc: Tidy up pylint warnings in test Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.