Skip to content

Commit 28313ce

Browse files
committed
[NXP][scripts][build_examples] Adding support to build applications with cmake using build_examples.py as the entry-point for RW61x
Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
1 parent dfc609c commit 28313ce

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

scripts/build/build/targets.py

+2
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ def BuildNxpTarget():
536536
target.AppendModifier(name="wifi", enable_wifi=True).OnlyIfRe('rw61x')
537537
target.AppendModifier(name="thread", enable_thread=True).ExceptIfRe('zephyr')
538538
target.AppendModifier(name="matter-shell", enable_shell=True).ExceptIfRe('k32w0|k32w1')
539+
target.AppendModifier(name="factory-build", enable_factory_data_build=True).OnlyIfRe('rw61x')
540+
target.AppendModifier(name="frdm", board_variant="frdm").OnlyIfRe('rw61x')
539541

540542
return target
541543

scripts/build/builders/nxp.py

+77-27
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ def __init__(self,
124124
disable_ble: bool = False,
125125
enable_thread: bool = False,
126126
enable_wifi: bool = False,
127-
disable_ipv4: bool = False,
128127
enable_shell: bool = False,
129-
enable_ota: bool = False):
128+
enable_ota: bool = False,
129+
enable_factory_data_build: bool = False,
130+
disable_pairing_autostart: bool = False,
131+
board_variant = None):
130132
super(NxpBuilder, self).__init__(
131133
root=app.BuildRoot(root, board, os_env),
132134
runner=runner)
@@ -142,12 +144,14 @@ def __init__(self,
142144
self.enable_lit = enable_lit
143145
self.enable_rotating_id = enable_rotating_id
144146
self.has_sw_version_2 = has_sw_version_2
145-
self.disable_ipv4 = disable_ipv4
146147
self.disable_ble = disable_ble
147148
self.enable_thread = enable_thread
148149
self.enable_wifi = enable_wifi
149150
self.enable_ota = enable_ota
150151
self.enable_shell = enable_shell
152+
self.enable_factory_data_build = enable_factory_data_build
153+
self.disable_pairing_autostart = disable_pairing_autostart
154+
self.board_variant = board_variant
151155

152156
def GnBuildArgs(self):
153157
args = []
@@ -199,18 +203,54 @@ def GnBuildArgs(self):
199203

200204
return args
201205

202-
def WestBuildArgs(self):
203-
args = []
206+
def CmakeBuildFlags(self):
207+
flags = []
204208
if self.enable_factory_data:
205-
args.append('-DFILE_SUFFIX=fdata')
209+
if self.os_env == NxpOsUsed.ZEPHYR:
210+
flags.append('-DFILE_SUFFIX=fdata')
211+
else:
212+
flags.append("-DCONFIG_CHIP_FACTORY_DATA=true")
206213

207214
if self.has_sw_version_2:
208-
args.append('-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2')
215+
flags.append("-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2")
216+
flags.append("-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING=\"2.0\"")
217+
218+
if self.enable_ota:
219+
flags.append("-DCONFIG_CHIP_OTA_REQUESTOR=true")
220+
if self.os_env == NxpOsUsed.FREERTOS and self.board == NxpBoard.RW61X:
221+
flags.append("-DCONFIG_BOOTLOADER_MCUBOOT=true")
209222

210-
build_args = " -- " + " ".join(args) if len(args) > 0 else ""
211-
return build_args
223+
if self.disable_ble:
224+
flags.append("-DCONFIG_BT=false")
225+
226+
if self.enable_wifi:
227+
flags.append('-DCONFIG_CHIP_WIFI=true')
228+
229+
if self.enable_thread:
230+
flags.append("-DCONFIG_NET_L2_OPENTHREAD=true -DCONFIG_CHIP_IPV4=false")
231+
232+
if self.enable_factory_data_build:
233+
# Generate the factory data binary
234+
flags.append("-DCONFIG_CHIP_FACTORY_DATA_BUILD=true -DCONFIG_CHIP_FACTORY_DATA=true")
235+
236+
if self.enable_shell:
237+
flags.append("-DCONFIG_CHIP_LIB_SHELL=true")
238+
239+
if not self.disable_pairing_autostart:
240+
flags.append('-DCONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=true')
241+
242+
if self.board_variant:
243+
if self.board == NxpBoard.RW61X:
244+
flag_board_variant = "-DCONFIG_BOARD_VARIANT=\"%s\"" % self.board_variant
245+
246+
flags.append(flag_board_variant)
247+
248+
build_flags = " ".join(flags) if len(flags) > 0 else ""
249+
250+
return build_flags
212251

213252
def generate(self):
253+
build_flags = self.CmakeBuildFlags()
214254
if self.os_env == NxpOsUsed.ZEPHYR:
215255
if 'ZEPHYR_NXP_SDK_INSTALL_DIR' in os.environ:
216256
cmd = 'export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_NXP_SDK_INSTALL_DIR"\n'
@@ -220,14 +260,13 @@ def generate(self):
220260
cmd += 'export ZEPHYR_BASE="$ZEPHYR_NXP_BASE"\n'
221261
else:
222262
raise Exception("ZEPHYR_NXP_BASE need to be set")
223-
build_args = self.WestBuildArgs()
224263
cmd += '''
225-
west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_args}
264+
west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_flags}
226265
'''.format(
227266
board_name=self.board.Name(self.os_env),
228267
out_folder=self.output_dir,
229268
example_folder=self.app.BuildRoot(self.code_root, self.board, self.os_env),
230-
build_args=build_args).strip()
269+
build_flags=build_flags).strip()
231270
self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier)
232271
else:
233272
cmd = ''
@@ -243,29 +282,40 @@ def generate(self):
243282
cmd += 'export NXP_K32W0_SDK_ROOT="' + str(p.sdk_storage_location_abspath) + '" \n '
244283
elif p.sdk_name == 'common':
245284
cmd += 'export NXP_SDK_ROOT="' + str(p.sdk_storage_location_abspath) + '" \n '
246-
# add empty space at the end to avoid concatenation issue when there is no --args
247-
cmd += 'gn gen --check --fail-on-unused-args --export-compile-commands --root=%s ' % self.root
248285

249-
extra_args = []
286+
if self.board == NxpBoard.RW61X:
287+
cmd += '''
288+
cmake -GNinja {build_flags} -H{example_folder} -B{out_folder}
289+
'''.format(
290+
build_flags=build_flags,
291+
example_folder=self.app.BuildRoot(self.code_root, self.board, self.os_env),
292+
out_folder=self.output_dir).strip()
293+
self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier)
250294

251-
if self.options.pw_command_launcher:
252-
extra_args.append('pw_command_launcher="%s"' % self.options.pw_command_launcher)
295+
else:
296+
# add empty space at the end to avoid concatenation issue when there is no --args
297+
cmd += 'gn gen --check --fail-on-unused-args --export-compile-commands --root=%s ' % self.root
253298

254-
if self.options.enable_link_map_file:
255-
extra_args.append('chip_generate_link_map_file=true')
299+
extra_args = []
300+
301+
if self.options.pw_command_launcher:
302+
extra_args.append('pw_command_launcher="%s"' % self.options.pw_command_launcher)
303+
304+
if self.options.enable_link_map_file:
305+
extra_args.append('chip_generate_link_map_file=true')
256306

257-
if self.options.pregen_dir:
258-
extra_args.append('chip_code_pre_generated_directory="%s"' % self.options.pregen_dir)
307+
if self.options.pregen_dir:
308+
extra_args.append('chip_code_pre_generated_directory="%s"' % self.options.pregen_dir)
259309

260-
extra_args.extend(self.GnBuildArgs() or [])
261-
if extra_args:
262-
cmd += ' --args="%s' % ' '.join(extra_args) + '" '
310+
extra_args.extend(self.GnBuildArgs() or [])
311+
if extra_args:
312+
cmd += ' --args="%s' % ' '.join(extra_args) + '" '
263313

264-
cmd += self.output_dir
314+
cmd += self.output_dir
265315

266-
title = 'Generating ' + self.identifier
316+
title = 'Generating ' + self.identifier
267317

268-
self._Execute(['bash', '-c', cmd], title=title)
318+
self._Execute(['bash', '-c', cmd], title=title)
269319

270320
def build_outputs(self):
271321
name = 'chip-%s-%s' % (self.board.Name(self.os_env), self.app.NameSuffix())

0 commit comments

Comments
 (0)