Skip to content

Commit 240960e

Browse files
scripts: add wrapper script to generate pinctrl groups
Add wrapper script capable of generating pinctrl groups for iMX RT parts from MEX files, that uses the rt_cfg_utils library Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 169c897 commit 240960e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

mcux/scripts/imx_gen_dts.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 re
9+
import pathlib
10+
import sys
11+
12+
import imx_cfg_utils
13+
14+
15+
HELPSTR = """
16+
Processes NXP iMX.RT MEX configuration files
17+
18+
Given a mex file, generates the board level pinctrl groups required for
19+
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('mex_file', metavar = 'MEX',
34+
type=str, help='path to source MEX file')
35+
parser.add_argument('--cfg-tool-root', metavar = 'CFG_TOOL', type=str,
36+
help='Path to root of MCUXpresso processors directory')
37+
parser.add_argument('--copyright', action='store_true',
38+
help='Enable default NXP copyright')
39+
parser.add_argument('--board-output', metavar = 'BOARD_OUT', type=str,
40+
help='Output path for board level DTS file')
41+
42+
args = parser.parse_args()
43+
44+
board_name = imx_cfg_utils.get_board_name(args.mex_file)
45+
processor_name = imx_cfg_utils.get_processor_name(args.mex_file)
46+
package_name = imx_cfg_utils.get_package_name(args.mex_file)
47+
soc_name = re.match(r'MIMXR?T?[0-9]+(M\w\d)*', processor_name).group(0)
48+
49+
# Set defaults for optional arguments
50+
if not args.board_output:
51+
args.board_output = f"{board_name.lower().replace('-', '_')}-pinctrl.dtsi"
52+
elif pathlib.Path(args.board_output).is_dir():
53+
# Add default name for file onto end of folder
54+
args.board_output = (str(pathlib.Path(args.board_output)) +
55+
f"/{board_name.lower().replace('-', '_')}-pinctrl.dtsi")
56+
57+
if not args.cfg_tool_root:
58+
print("configuration tool root argument ('--cfg-tool-root') is required!")
59+
sys.exit(1)
60+
proc_root = pathlib.Path(args.cfg_tool_root) / processor_name / 'ksdk2_0' / package_name
61+
if not proc_root.is_dir():
62+
print(f"Configuration tool root path {args.cfg_tool_root} is invalid")
63+
sys.exit(2)
64+
65+
66+
if args.copyright:
67+
# Add default copyright
68+
COPYRIGHT = (f"Copyright (c) {datetime.datetime.today().year}, NXP\n"
69+
f" * SPDX-License-Identifier: Apache-2.0")
70+
else:
71+
COPYRIGHT = ''
72+
util = imx_cfg_utils.NXPSdkUtil(str(proc_root), copyright_header= COPYRIGHT)
73+
print(f"Generating configuration for {board_name}")
74+
util.write_pinctrl_groups(args.mex_file, args.board_output)
75+
print(f"Wrote pinctrl dts file to {args.board_output}")

0 commit comments

Comments
 (0)