[PATCH 10/15] dtoc: Add support for building a dtoc PyPi package

Simon Glass sjg at chromium.org
Sun Feb 19 15:51:18 CET 2023


Create the necessary files to build this new package.

This is needed for binman.

Move the main program into a function so that it can easily be called by
the PyPi-created script.

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

 Makefile                  |  1 +
 tools/dtoc/README.rst     | 15 +++++++
 tools/dtoc/main.py        | 95 ++++++++++++++++++++-------------------
 tools/dtoc/pyproject.toml | 26 +++++++++++
 4 files changed, 92 insertions(+), 45 deletions(-)
 create mode 100644 tools/dtoc/README.rst
 create mode 100644 tools/dtoc/pyproject.toml

diff --git a/Makefile b/Makefile
index 9f9d55e77ee..86c85c70999 100644
--- a/Makefile
+++ b/Makefile
@@ -2284,6 +2284,7 @@ _pip:
 	scripts/make_pip.sh u_boot_pylib ${PIP_ARGS}
 	scripts/make_pip.sh patmanu ${PIP_ARGS}
 	scripts/make_pip.sh buildman ${PIP_ARGS}
+	scripts/make_pip.sh dtoc ${PIP_ARGS}
 
 help:
 	@echo  'Cleaning targets:'
diff --git a/tools/dtoc/README.rst b/tools/dtoc/README.rst
new file mode 100644
index 00000000000..92b39759ed1
--- /dev/null
+++ b/tools/dtoc/README.rst
@@ -0,0 +1,15 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Devicetree-to-C generator
+=========================
+
+This is a Python program and associated utilities, which supports converting
+devicetree files into C code. It generates header files containing struct
+definitions, as well as C files containing the data. It does not require any
+modification of the devicetree files.
+
+Some high-level libraries are provided for working with devicetree. These may
+be useful in other projects.
+
+This package also includes some U-Boot-specific features, such as creating
+`struct udevice` and `struct uclass` entries for devicetree nodes.
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index fc9207d1b63..317002f48cd 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -61,7 +61,7 @@ def run_tests(processes, args):
     return (0 if result.wasSuccessful() else 1)
 
 
-def RunTestCoverage():
+def RunTestCoverage(args):
     """Run the tests and check that we get 100% coverage"""
     sys.argv = [sys.argv[0]]
     test_util.run_test_coverage('tools/dtoc/dtoc', '/main.py',
@@ -69,47 +69,52 @@ def RunTestCoverage():
             args.build_dir)
 
 
-if __name__ != '__main__':
-    sys.exit(1)
-
-epilog = '''Generate C code from devicetree files. See of-plat.rst for details'''
-
-parser = ArgumentParser(epilog=epilog)
-parser.add_argument('-B', '--build-dir', type=str, default='b',
-        help='Directory containing the build output')
-parser.add_argument('-c', '--c-output-dir', action='store',
-                  help='Select output directory for C files')
-parser.add_argument('-C', '--h-output-dir', action='store',
-                  help='Select output directory for H files (defaults to --c-output-di)')
-parser.add_argument('-d', '--dtb-file', action='store',
-                  help='Specify the .dtb input file')
-parser.add_argument('-i', '--instantiate', action='store_true', default=False,
-                  help='Instantiate devices to avoid needing device_bind()')
-parser.add_argument('--include-disabled', action='store_true',
-                  help='Include disabled nodes')
-parser.add_argument('-o', '--output', action='store',
-                  help='Select output filename')
-parser.add_argument('-p', '--phase', type=str,
-                  help='set phase of U-Boot this invocation is for (spl/tpl)')
-parser.add_argument('-P', '--processes', type=int,
-                  help='set number of processes to use for running tests')
-parser.add_argument('-t', '--test', action='store_true', dest='test',
-                  default=False, help='run tests')
-parser.add_argument('-T', '--test-coverage', action='store_true',
-                default=False, help='run tests and check for 100%% coverage')
-parser.add_argument('files', nargs='*')
-args = parser.parse_args()
-
-# Run our meagre tests
-if args.test:
-    ret_code = run_tests(args.processes, args)
-    sys.exit(ret_code)
-
-elif args.test_coverage:
-    RunTestCoverage()
-
-else:
-    dtb_platdata.run_steps(args.files, args.dtb_file, args.include_disabled,
-                           args.output,
-                           [args.c_output_dir, args.h_output_dir],
-                           args.phase, instantiate=args.instantiate)
+def run_dtoc():
+    epilog = 'Generate C code from devicetree files. See of-plat.rst for details'
+
+    parser = ArgumentParser(epilog=epilog)
+    parser.add_argument('-B', '--build-dir', type=str, default='b',
+            help='Directory containing the build output')
+    parser.add_argument('-c', '--c-output-dir', action='store',
+                      help='Select output directory for C files')
+    parser.add_argument(
+        '-C', '--h-output-dir', action='store',
+        help='Select output directory for H files (defaults to --c-output-di)')
+    parser.add_argument('-d', '--dtb-file', action='store',
+                      help='Specify the .dtb input file')
+    parser.add_argument(
+        '-i', '--instantiate', action='store_true', default=False,
+        help='Instantiate devices to avoid needing device_bind()')
+    parser.add_argument('--include-disabled', action='store_true',
+                      help='Include disabled nodes')
+    parser.add_argument('-o', '--output', action='store',
+                      help='Select output filename')
+    parser.add_argument(
+        '-p', '--phase', type=str,
+        help='set phase of U-Boot this invocation is for (spl/tpl)')
+    parser.add_argument('-P', '--processes', type=int,
+                      help='set number of processes to use for running tests')
+    parser.add_argument('-t', '--test', action='store_true', dest='test',
+                      default=False, help='run tests')
+    parser.add_argument(
+        '-T', '--test-coverage', action='store_true',
+        default=False, help='run tests and check for 100%% coverage')
+    parser.add_argument('files', nargs='*')
+    args = parser.parse_args()
+
+    # Run our meagre tests
+    if args.test:
+        ret_code = run_tests(args.processes, args)
+        sys.exit(ret_code)
+
+    elif args.test_coverage:
+        RunTestCoverage(args)
+
+    else:
+        dtb_platdata.run_steps(args.files, args.dtb_file, args.include_disabled,
+                               args.output,
+                               [args.c_output_dir, args.h_output_dir],
+                               args.phase, instantiate=args.instantiate)
+
+if __name__ == '__main__':
+    run_dtoc()
diff --git a/tools/dtoc/pyproject.toml b/tools/dtoc/pyproject.toml
new file mode 100644
index 00000000000..d127d07702d
--- /dev/null
+++ b/tools/dtoc/pyproject.toml
@@ -0,0 +1,26 @@
+[build-system]
+requires = ["setuptools>=61.0"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "dtoc"
+version = "0.0.1"
+authors = [
+  { name="Simon Glass", email="sjg at chromium.org" },
+]
+dependencies = ["u_boot_pylib"]
+description = "Devicetree-to-C generator"
+readme = "README.rst"
+requires-python = ">=3.7"
+classifiers = [
+    "Programming Language :: Python :: 3",
+    "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
+    "Operating System :: OS Independent",
+]
+
+[project.urls]
+"Homepage" = "https://u-boot.readthedocs.io/en/latest/develop/driver-model/of-plat.html"
+"Bug Tracker" = "https://source.denx.de/groups/u-boot/-/issues"
+
+[project.scripts]
+dtoc = "dtoc.main:run_dtoc"
-- 
2.39.2.637.g21b0678d19-goog



More information about the U-Boot mailing list