|
| 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 | +import pathlib |
| 14 | +import sys |
| 15 | + |
| 16 | +import kinetis_cfg_utils |
| 17 | + |
| 18 | +HELPSTR = """ |
| 19 | +Processes NXP Kinetis MEX configuration files |
| 20 | +Given a mex file, generates the board level pinctrl groups required for |
| 21 | +Zephyr. 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('mex_file', metavar = 'MEX', |
| 35 | + type=str, help='path to source MEX file') |
| 36 | +parser.add_argument('--cfg-tool-root', metavar = 'CFG_TOOL', type=str, |
| 37 | + help='Path to root of MCUXpresso processors directory') |
| 38 | +parser.add_argument('--copyright', action='store_true', |
| 39 | + help='Enable default NXP copyright') |
| 40 | +parser.add_argument('--board-output', metavar = 'BOARD_OUT', type=str, |
| 41 | + help='Output path for board level DTS file') |
| 42 | + |
| 43 | +args = parser.parse_args() |
| 44 | + |
| 45 | +board_name = kinetis_cfg_utils.get_board_name(args.mex_file) |
| 46 | +processor_name = kinetis_cfg_utils.get_processor_name(args.mex_file) |
| 47 | +package_name = kinetis_cfg_utils.get_package_name(args.mex_file) |
| 48 | + |
| 49 | +if not args.board_output: |
| 50 | + args.board_output = f"{board_name.lower().replace('-', '_')}-pinctrl.dtsi" |
| 51 | +elif pathlib.Path(args.board_output).is_dir(): |
| 52 | + # Append board name to path |
| 53 | + if not args.board_output.endswith('/'): |
| 54 | + args.board_output += '/' |
| 55 | + args.board_output += f"{board_name.lower().replace('-', '_')}-pinctrl.dtsi" |
| 56 | + |
| 57 | +if args.cfg_tool_root: |
| 58 | + # Attempt to locate all the required config files automatically, using |
| 59 | + # the processor name given in the mex file |
| 60 | + proc_root = pathlib.Path(args.cfg_tool_root) / processor_name / 'ksdk2_0' / package_name |
| 61 | + if not proc_root.exists(): |
| 62 | + print(f"Error: Path {args.cfg_tool_root} provided for config root is invalid") |
| 63 | + sys.exit(255) |
| 64 | + # Check for all the files we need |
| 65 | + signal_path = proc_root / 'signal_configuration.xml' |
| 66 | + # Verify files exist |
| 67 | + if not signal_path.exists(): |
| 68 | + print("CFG tools path appears valid, but required files could not be found") |
| 69 | + sys.exit(254) |
| 70 | + signal_file = str(signal_path) |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +if args.copyright: |
| 75 | + # Add default copyright |
| 76 | + copyright_txt = (f"Copyright (c) {datetime.datetime.today().year}, NXP\n" |
| 77 | + f" * SPDX-License-Identifier: Apache-2.0") |
| 78 | + util = kinetis_cfg_utils.NXPSdkUtil(signal_file, copyright_header= copyright_txt) |
| 79 | +else: |
| 80 | + util = kinetis_cfg_utils.NXPSdkUtil(signal_file) |
| 81 | + |
| 82 | +print(f"Generating configuration for {board_name}") |
| 83 | +util.write_pinctrl_groups(args.mex_file, args.board_output) |
| 84 | +print(f"Wrote pinctrl dts file to {args.board_output}") |
0 commit comments