1#!/usr/bin/env python3
2
3"""
4Wrapper around imx_cfg_utils.py to provide arguments to module
5"""
6import argparse
7import datetime
8import pathlib
9import sys
10from errno import ENOTDIR, EINVAL
11
12import imx_cfg_utils
13
14
15HELPSTR = """
16Processes NXP iMX.RT signal configuration files
17
18Given a processor folder, generates the SOC level gpio DTSI mux options used
19within Zephyr. These definitions should be copied where appropriate.
20
21This tool is intended to be used with the configuration data downloaded
22from NXP's website. One way to extract this config data is to use the
23MCUXpresso configuration tool to download processor defintions, locate
24those defintions on the disk. Alternatively, individual processor config
25data packs can be downloaded from the MCUXpresso SDK builder tool. Either way,
26the path to the 'processors' directory must be provided as the 'cfg-tool-root'
27parameter.
28"""
29
30
31parser = argparse.ArgumentParser(description=HELPSTR,
32        formatter_class=argparse.RawDescriptionHelpFormatter)
33parser.add_argument('processor_root', metavar = 'PROC_ROOT',
34                    type=str,
35                    help='folder with processor signal configuration files')
36
37args = parser.parse_args()
38
39# Attempt to locate the signal XML files we will generate from
40proc_root = pathlib.Path(args.processor_root) / 'ksdk2_0'
41if not proc_root.exists():
42    print(f"Error: Path {args.processor_root} provided for processor root is invalid")
43    sys.exit(EINVAL)
44# Iterate through all processor package signal.xml files
45for package_root in proc_root.iterdir():
46    signal_path = package_root / 'signal_configuration.xml'
47    # Check if this is a processor package folder
48    if signal_path.exists():
49        # Generate SOC GPIO file
50        util = imx_cfg_utils.NXPSdkUtil(str(package_root))
51        out_path = f"./{util.get_part_num().lower()}-gpio.dtsi"
52        util.write_gpio_mux(out_path)
53        print(f"Wrote SOC GPIO file to {out_path}")
54