Skip to content

Commit df2bd6c

Browse files
zejiang0jasonmmahadevan108
authored andcommitted
mcux: script: Add script to sync mcux sdk ng code
The script sync the MCUX SDK code to folder mcux/mcux-sdk-ng Signed-off-by: Jason Yu <[email protected]>
1 parent 488cc1e commit df2bd6c

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

mcux/scripts/sync_sdk_ng.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2025 NXP
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
import os
8+
import sys
9+
import re
10+
import shutil
11+
import argparse
12+
from textwrap import dedent
13+
from pathlib import Path
14+
15+
HELPSTR = f"""
16+
This script synchronizes the MCUX SDK code to folder mcux/mcux-sdk-ng,
17+
use the argument `--mcuxsdk_dir` to specify the MCUX SDK code folder,
18+
like:
19+
{Path(__file__).name} --mcuxsdk_dir=~/mcuxsdk
20+
"""
21+
22+
# Content to copy, use wildcard
23+
COPY_CONTENT = [
24+
'devices/**/*',
25+
'drivers/**/*',
26+
'components/conn_fwloader/**/*',
27+
'components/flash/fsl_flash.h',
28+
'components/flash/mflash/**/*',
29+
'components/flash/nand/**/*',
30+
'components/flash/nor/**/*',
31+
'components/imu_adapter/**/*',
32+
'components/lists/**/*',
33+
'components/misc_utilities/**/*',
34+
'components/osa/**/*',
35+
'components/phy/**/*',
36+
'components/rpmsg/**/*',
37+
'components/wifi_bt_module/**/*',
38+
'middleware/usb/**/*',
39+
]
40+
41+
# Content to remove, use wildcard
42+
REMOVE_CONTENT = [
43+
'**/Kconfig*',
44+
'devices/**/RTE_Device.h',
45+
'devices/**/*.yml',
46+
'devices/**/*.icf',
47+
'devices/**/*.ld',
48+
'devices/**/*.scf',
49+
'devices/**/*.FLM',
50+
'devices/**/*.sdf',
51+
'devices/**/*.dbgconf',
52+
'devices/**/startup*.[sS]',
53+
'devices/**/mcuxpresso/startup_*.cpp',
54+
'devices/**/[Dd]oxygen',
55+
'devices/**/prj.conf',
56+
'drivers/**/[Dd]oxygen',
57+
'components/**/[Dd]oxygen',
58+
'middleware/usb/example',
59+
'middleware/usb/docs',
60+
]
61+
62+
def banner(*args):
63+
print('===', *args)
64+
65+
def small_banner(*args):
66+
print('---', *args)
67+
68+
69+
def copy_content():
70+
'''
71+
Copy the content specified by COPY_CONTENT
72+
'''
73+
for pattern in COPY_CONTENT:
74+
for f_src in MCUXSDK_BASE.glob(pattern):
75+
if '.git' in str(f_src):
76+
continue
77+
78+
f_dst = HAL_NXP_SDK_BASE / f_src.relative_to(MCUXSDK_BASE)
79+
80+
small_banner(f'Copy {f_src} to {f_dst}')
81+
82+
f_dst.parent.mkdir(parents=True, exist_ok=True)
83+
if f_src.is_file():
84+
shutil.copy(f_src, f_dst)
85+
86+
def remove_content():
87+
'''
88+
Remove the content specified by REMOVE_CONTENT, this is called after
89+
`copy_content`.
90+
'''
91+
for pattern in REMOVE_CONTENT:
92+
for f in HAL_NXP_SDK_BASE.glob(pattern):
93+
small_banner(f'Remove {f}')
94+
if f.is_file():
95+
f.unlink()
96+
elif f.is_dir():
97+
shutil.rmtree(f)
98+
99+
100+
def patch_clean_device_shared_cmake():
101+
'''
102+
Clean the shared.cmake file in devices folder, it adds the build flags,
103+
such as CC_FLAGS, LD_FLAGS, which are not used for zephyr.
104+
'''
105+
106+
devices_dir = HAL_NXP_SDK_BASE / 'devices'
107+
108+
for shared_cmake in devices_dir.rglob('shared.cmake'):
109+
small_banner(f'Clean the content of {shared_cmake}')
110+
with open(shared_cmake, 'w') as fd:
111+
fd.write('')
112+
113+
def patch_content():
114+
'''
115+
Patch the copied files from MCUX SDK, this is only for the changes which
116+
are not suitable to apply in MCUX SDK.
117+
'''
118+
patch_clean_device_shared_cmake()
119+
120+
def remove_empty_folders():
121+
'''
122+
Remove the empty folders.
123+
'''
124+
for folder in HAL_NXP_SDK_BASE.rglob('*'):
125+
if folder.is_dir() and not any(folder.iterdir()):
126+
small_banner(f'Remove empty folder {folder}')
127+
folder.rmdir()
128+
129+
def parse_args():
130+
131+
parser = argparse.ArgumentParser(
132+
allow_abbrev=False,
133+
formatter_class=argparse.RawTextHelpFormatter,
134+
description = HELPSTR,
135+
)
136+
137+
parser.add_argument("--mcuxsdk_dir", default='~/github/mcuxsdk',
138+
help="mcuxsdk repo path, like ~/mcuxsdk, will copy files from here")
139+
140+
args = parser.parse_args()
141+
142+
return args
143+
144+
145+
def main():
146+
global HAL_NXP_BASE, MCUXSDK_BASE, HAL_NXP_SDK_BASE
147+
148+
args = parse_args()
149+
MCUXSDK_BASE = Path(args.mcuxsdk_dir).expanduser().resolve()
150+
151+
HAL_NXP_BASE = Path(__file__).parent.parent.parent.resolve()
152+
HAL_NXP_SDK_BASE = HAL_NXP_BASE / 'mcux' / 'mcux-sdk-ng'
153+
154+
copy_content()
155+
remove_content()
156+
patch_content()
157+
158+
remove_empty_folders()
159+
160+
banner('=' * 80)
161+
banner('Copy completed.')
162+
163+
164+
if __name__ == '__main__':
165+
main()

0 commit comments

Comments
 (0)