Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1329CC61DA4 for ; Sun, 19 Feb 2023 14:54:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D53C85867; Sun, 19 Feb 2023 15:53:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="atFJkr+F"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 32E868572F; Sun, 19 Feb 2023 15:53:00 +0100 (CET) Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1FA3A857E9 for ; Sun, 19 Feb 2023 15:51:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2d.google.com with SMTP id n19so266132ioo.13 for ; Sun, 19 Feb 2023 06:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fc9PVF4TesL5fXQRaBtYwenBs25wEgogAAhc0/6dvTA=; b=atFJkr+FJy/A1y5xr17hTC2WaHLrwY7drF6A4SZi7U3mJd5GEuYhRmkZOoqAl1b7nG G/g0Xz4ZnARhSdXbEgFf6Ld5mLD3u3H+SuXyM8qH5JhYk9nCG99feb1ZcxHx9UjxSxq5 SlLZcNiGLI307Lq2jZhU2rgkFCI9/PdcKMBwg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fc9PVF4TesL5fXQRaBtYwenBs25wEgogAAhc0/6dvTA=; b=IUyxDzvFbK98LVfgal09wCQB9CvLKMuaLGixD7e4HLCEkag6dMSG1J/i4qzlHSJ72l l9DNlU+nUNohS8cHEuZbJTu3AoyvbQf7YEHjxatvfj7qcNbhRoAO7HtGZPhOjWsAENeO K4EQkvv34H7I32RN8X+ZaXURAebuVWcn5FU/FSlHmUqe03VjpJNvDnOmOxgixcQYnsiU GvepECiKV0r0n8+rfKS8q3DVN2tWiLNbpZwu5bc7VyvfiuWI+mmu7e6SoTsPPI33Vjsf ZyIs8uqmMoJAbzSeQTsbSkzHq2RwpWIXeCYmmS17Zm9SQi7Oz2W8wzFz0dndjD148A96 KNeA== X-Gm-Message-State: AO0yUKUJqG7YxFQferw7qjAvOEIPVaMUGeUIWyemT6OkGXI0V/QSBJ5O noLotVHLzjvMvaJoyL4B9wJ4Yko+VnxZ5R9T X-Google-Smtp-Source: AK7set9XWpIddwLcAg4ZY0uH76xW1fiznc/nbWanFqohhLf4OFH5CqZM7f1+gwLEwFF2xoQy74SJPg== X-Received: by 2002:a5e:d802:0:b0:6de:3e2c:d791 with SMTP id l2-20020a5ed802000000b006de3e2cd791mr5233337iok.1.1676818313524; Sun, 19 Feb 2023 06:51:53 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id c84-20020a6bb357000000b0071c66d1a2fcsm3444772iof.0.2023.02.19.06.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 06:51:53 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Alper Nebi Yasak , Neha Malcom Francis , Stefan Herbrechtsmeier , Philippe Reynes , Peng Fan , Simon Glass , =?UTF-8?q?Marek=20Beh=C3=BAn?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Quentin Schulz Subject: [PATCH 10/15] dtoc: Add support for building a dtoc PyPi package Date: Sun, 19 Feb 2023 07:51:18 -0700 Message-Id: <20230219145124.1782335-11-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230219145124.1782335-1-sjg@chromium.org> References: <20230219145124.1782335-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 --- 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@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