1+ #!/usr/bin/env python3
2+
3+ """
4+ Wrapper around imx_cfg_utils.py to provide arguments to module
5+ """
6+ import argparse
7+ import datetime
8+ import pathlib
9+ import sys
10+ from errno import ENOTDIR , EINVAL
11+
12+ import imx_cfg_utils
13+
14+
15+ HELPSTR = """
16+ Processes NXP iMX.RT signal configuration files
17+
18+ Given a processor folder, generates the SOC level pinctrl DTSI defintions
19+ required for Zephyr. Only supports iMX.RT parts.
20+
21+ This tool is intended to be used with the configuration data downloaded
22+ from NXP's website. One way to extract this config data is to use the
23+ MCUXpresso configuration tool to download processor defintions, locate
24+ those defintions on the disk. Alternatively, individual processor config
25+ data packs can be downloaded from the MCUXpresso SDK builder tool. Either way,
26+ the path to the 'processors' directory must be provided as the 'cfg-tool-root'
27+ parameter.
28+ """
29+
30+
31+ parser = argparse .ArgumentParser (description = HELPSTR ,
32+ formatter_class = argparse .RawDescriptionHelpFormatter )
33+ parser .add_argument ('processor_root' , metavar = 'PROC_ROOT' ,
34+ type = str ,
35+ help = 'folder with processor signal configuration files' )
36+ parser .add_argument ('--copyright' , action = 'store_true' ,
37+ help = 'Enable default NXP copyright' )
38+ parser .add_argument ('--soc-output' , metavar = 'BOARD_OUT' , type = str ,
39+ help = 'Output path for soc level dtsi 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 package_root in proc_root .iterdir ():
56+ signal_path = package_root / 'signal_configuration.xml'
57+ # Check if this is a processor package folder
58+ if signal_path .exists ():
59+ # Generate SOC DTSI file
60+ if args .copyright :
61+ # Add default copyright
62+ COPYRIGHT = (f"Copyright (c) { datetime .datetime .today ().year } , NXP\n "
63+ f" * SPDX-License-Identifier: Apache-2.0" )
64+ else :
65+ COPYRIGHT = ""
66+ util = imx_cfg_utils .NXPSdkUtil (str (package_root ), copyright_header = COPYRIGHT )
67+ out_path = f"{ args .soc_output .rstrip ('/' )} /{ util .get_part_num ().lower ()} -pinctrl.dtsi"
68+ util .write_pinctrl_defs (out_path )
69+ print (f"Wrote SOC DTSI file to { out_path } " )
70+
0 commit comments