|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright (c) 2022, NXP |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +""" |
| 8 | +Wrapper around kinetis_signal2dts.py to provide arguments |
| 9 | +""" |
| 10 | + |
| 11 | +import datetime |
| 12 | +import argparse |
| 13 | +from errno import EINVAL, ENOTDIR |
| 14 | +import pathlib |
| 15 | +import sys |
| 16 | + |
| 17 | +import kinetis_cfg_utils |
| 18 | + |
| 19 | +HELPSTR = """ |
| 20 | +Processes NXP Kinetis signal configuration files and outputs kinetis pinctrl |
| 21 | +headers. Only supports Kinetis parts. |
| 22 | +This tool is intended to be used with the configuration data downloaded |
| 23 | +from NXP's website. One way to extract this config data is to use the |
| 24 | +MCUXpresso configuration tool to download processor defintions, locate |
| 25 | +those defintions on the disk. Alternatively, individual processor config |
| 26 | +data packs can be downloaded from the MCUXpresso SDK builder tool. Either way, |
| 27 | +the path to the 'processors' directory must be provided as the 'cfg-tool-root' |
| 28 | +parameter. |
| 29 | +""" |
| 30 | + |
| 31 | +parser = argparse.ArgumentParser(description=HELPSTR, |
| 32 | + formatter_class=argparse.RawDescriptionHelpFormatter) |
| 33 | + |
| 34 | +parser.add_argument('--processor-root', metavar = 'PROC_ROOT', type=str, |
| 35 | + help='Path to root of processor directory with package defintions') |
| 36 | +parser.add_argument('--copyright', action='store_true', |
| 37 | + help='Enable default NXP copyright') |
| 38 | +parser.add_argument('--soc-output', metavar = 'SOC_OUT', type=str, |
| 39 | + help='Output folder for soc level header files') |
| 40 | + |
| 41 | +args = parser.parse_args() |
| 42 | + |
| 43 | +if not args.soc_output: |
| 44 | + args.soc_output = "." |
| 45 | +elif not pathlib.Path(args.soc_output).is_dir(): |
| 46 | + print('SOC output path must be a directory') |
| 47 | + sys.exit(ENOTDIR) |
| 48 | + |
| 49 | +# Attempt to locate the signal XML files we will generate from |
| 50 | +proc_root = pathlib.Path(args.processor_root) / 'ksdk2_0' |
| 51 | +if not proc_root.exists(): |
| 52 | + print(f"Error: Path {args.processor_root} provided for processor root is invalid") |
| 53 | + sys.exit(EINVAL) |
| 54 | +# Iterate through all processor package signal.xml files |
| 55 | +for directory in proc_root.iterdir(): |
| 56 | + signal_path = directory / 'signal_configuration.xml' |
| 57 | + if signal_path.exists(): |
| 58 | + if args.copyright: |
| 59 | + # Add default copyright |
| 60 | + copyright_txt = (f"Copyright (c) {datetime.datetime.today().year}, NXP\n" |
| 61 | + f" * SPDX-License-Identifier: Apache-2.0") |
| 62 | + util = kinetis_cfg_utils.NXPSdkUtil(str(signal_path), copyright_header= copyright_txt) |
| 63 | + else: |
| 64 | + util = kinetis_cfg_utils.NXPSdkUtil(str(signal_path)) |
| 65 | + out_path = f"{args.soc_output}/{util.get_part_num().upper()}-pinctrl.h" |
| 66 | + util.write_pinctrl_defs(out_path) |
| 67 | + print(f"Wrote pinctrl header defs to {out_path}") |
0 commit comments