Skip to content

Commit c1ddce0

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 3156d77 commit c1ddce0

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
@@ -538,6 +538,8 @@ def BuildNxpTarget():
538538
target.AppendModifier(name="wifi", enable_wifi=True).OnlyIfRe('rw61x')
539539
target.AppendModifier(name="thread", enable_thread=True).ExceptIfRe('zephyr')
540540
target.AppendModifier(name="matter-shell", enable_shell=True).ExceptIfRe('k32w0|k32w1')
541+
target.AppendModifier(name="factory-build", enable_factory_data_build=True).OnlyIfRe('rw61x')
542+
target.AppendModifier(name="frdm", board_variant="frdm").OnlyIfRe('rw61x')
541543

542544
return target
543545

scripts/build/builders/nxp.py

+77-27
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def __init__(self,
129129
disable_ble: bool = False,
130130
enable_thread: bool = False,
131131
enable_wifi: bool = False,
132-
disable_ipv4: bool = False,
133132
enable_shell: bool = False,
134-
enable_ota: bool = False):
133+
enable_ota: bool = False,
134+
enable_factory_data_build: bool = False,
135+
disable_pairing_autostart: bool = False,
136+
board_variant: str = None):
135137
super(NxpBuilder, self).__init__(
136138
root=app.BuildRoot(root, board, os_env),
137139
runner=runner)
@@ -147,12 +149,14 @@ def __init__(self,
147149
self.enable_lit = enable_lit
148150
self.enable_rotating_id = enable_rotating_id
149151
self.has_sw_version_2 = has_sw_version_2
150-
self.disable_ipv4 = disable_ipv4
151152
self.disable_ble = disable_ble
152153
self.enable_thread = enable_thread
153154
self.enable_wifi = enable_wifi
154155
self.enable_ota = enable_ota
155156
self.enable_shell = enable_shell
157+
self.enable_factory_data_build = enable_factory_data_build
158+
self.disable_pairing_autostart = disable_pairing_autostart
159+
self.board_variant = board_variant
156160

157161
def GnBuildArgs(self):
158162
args = []
@@ -204,18 +208,54 @@ def GnBuildArgs(self):
204208

205209
return args
206210

207-
def WestBuildArgs(self):
208-
args = []
211+
def CmakeBuildFlags(self):
212+
flags = []
209213
if self.enable_factory_data:
210-
args.append('-DFILE_SUFFIX=fdata')
214+
if self.os_env == NxpOsUsed.ZEPHYR:
215+
flags.append('-DFILE_SUFFIX=fdata')
216+
else:
217+
flags.append("-DCONFIG_CHIP_FACTORY_DATA=true")
211218

212219
if self.has_sw_version_2:
213-
args.append('-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2')
220+
flags.append("-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2")
221+
flags.append("-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING=\"2.0\"")
222+
223+
if self.enable_ota:
224+
flags.append("-DCONFIG_CHIP_OTA_REQUESTOR=true")
225+
if self.os_env == NxpOsUsed.FREERTOS and self.board == NxpBoard.RW61X:
226+
flags.append("-DCONFIG_BOOTLOADER_MCUBOOT=true")
214227

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

218257
def generate(self):
258+
build_flags = self.CmakeBuildFlags()
219259
if self.os_env == NxpOsUsed.ZEPHYR:
220260
if 'ZEPHYR_NXP_SDK_INSTALL_DIR' in os.environ:
221261
cmd = 'export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_NXP_SDK_INSTALL_DIR"\n'
@@ -225,14 +265,13 @@ def generate(self):
225265
cmd += 'export ZEPHYR_BASE="$ZEPHYR_NXP_BASE"\n'
226266
else:
227267
raise Exception("ZEPHYR_NXP_BASE need to be set")
228-
build_args = self.WestBuildArgs()
229268
cmd += '''
230-
west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_args}
269+
west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_flags}
231270
'''.format(
232271
board_name=self.board.Name(self.os_env),
233272
out_folder=self.output_dir,
234273
example_folder=self.app.BuildRoot(self.code_root, self.board, self.os_env),
235-
build_args=build_args).strip()
274+
build_flags=build_flags).strip()
236275
self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier)
237276
else:
238277
cmd = ''
@@ -248,29 +287,40 @@ def generate(self):
248287
cmd += 'export NXP_K32W0_SDK_ROOT="' + str(p.sdk_storage_location_abspath) + '" \n '
249288
elif p.sdk_name == 'common':
250289
cmd += 'export NXP_SDK_ROOT="' + str(p.sdk_storage_location_abspath) + '" \n '
251-
# add empty space at the end to avoid concatenation issue when there is no --args
252-
cmd += 'gn gen --check --fail-on-unused-args --export-compile-commands --root=%s ' % self.root
253290

254-
extra_args = []
291+
if self.board == NxpBoard.RW61X:
292+
cmd += '''
293+
cmake -GNinja {build_flags} -H{example_folder} -B{out_folder}
294+
'''.format(
295+
build_flags=build_flags,
296+
example_folder=self.app.BuildRoot(self.code_root, self.board, self.os_env),
297+
out_folder=self.output_dir).strip()
298+
self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier)
255299

256-
if self.options.pw_command_launcher:
257-
extra_args.append('pw_command_launcher="%s"' % self.options.pw_command_launcher)
300+
else:
301+
# add empty space at the end to avoid concatenation issue when there is no --args
302+
cmd += 'gn gen --check --fail-on-unused-args --export-compile-commands --root=%s ' % self.root
258303

259-
if self.options.enable_link_map_file:
260-
extra_args.append('chip_generate_link_map_file=true')
304+
extra_args = []
305+
306+
if self.options.pw_command_launcher:
307+
extra_args.append('pw_command_launcher="%s"' % self.options.pw_command_launcher)
308+
309+
if self.options.enable_link_map_file:
310+
extra_args.append('chip_generate_link_map_file=true')
261311

262-
if self.options.pregen_dir:
263-
extra_args.append('chip_code_pre_generated_directory="%s"' % self.options.pregen_dir)
312+
if self.options.pregen_dir:
313+
extra_args.append('chip_code_pre_generated_directory="%s"' % self.options.pregen_dir)
264314

265-
extra_args.extend(self.GnBuildArgs() or [])
266-
if extra_args:
267-
cmd += ' --args="%s' % ' '.join(extra_args) + '" '
315+
extra_args.extend(self.GnBuildArgs() or [])
316+
if extra_args:
317+
cmd += ' --args="%s' % ' '.join(extra_args) + '" '
268318

269-
cmd += self.output_dir
319+
cmd += self.output_dir
270320

271-
title = 'Generating ' + self.identifier
321+
title = 'Generating ' + self.identifier
272322

273-
self._Execute(['bash', '-c', cmd], title=title)
323+
self._Execute(['bash', '-c', cmd], title=title)
274324

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

0 commit comments

Comments
 (0)