1
- # Copyright (c) 2021 Project CHIP Authors
1
+ # Copyright (c) 2021-2024 Project CHIP Authors
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import logging
15
16
import os
16
17
from enum import Enum , auto
17
18
18
19
from .builder import BuilderOutput
19
20
from .gn import GnBuilder
20
21
22
+ class NxpOsUsed (Enum ):
23
+ FREERTOS = auto ()
24
+ ZEPHYR = auto ()
25
+ def OsEnv (self ):
26
+ if self == NxpOsUsed .ZEPHYR :
27
+ return 'zephyr'
28
+ elif self == NxpOsUsed .FREERTOS :
29
+ return 'freertos'
30
+ else :
31
+ raise Exception ('Unknown OS type: %r' % self )
21
32
22
33
class NxpBoard (Enum ):
23
34
K32W0 = auto ()
24
35
K32W1 = auto ()
36
+ RW61X = auto ()
25
37
26
38
def Name (self ):
27
39
if self == NxpBoard .K32W0 :
28
40
return 'k32w0x'
29
41
elif self == NxpBoard .K32W1 :
30
42
return 'k32w1'
43
+ elif self == NxpBoard .RW61X :
44
+ return 'rd_rw612_bga'
31
45
else :
32
46
raise Exception ('Unknown board type: %r' % self )
33
47
@@ -36,19 +50,30 @@ def FolderName(self):
36
50
return 'k32w/k32w0'
37
51
elif self == NxpBoard .K32W1 :
38
52
return 'k32w/k32w1'
53
+ elif self == NxpBoard .RW61X :
54
+ return 'zephyr'
39
55
else :
40
56
raise Exception ('Unknown board type: %r' % self )
41
57
42
58
43
59
class NxpApp (Enum ):
44
60
LIGHTING = auto ()
45
61
CONTACT = auto ()
62
+ ALLCLUSTERS = auto ()
63
+ LAUNDRYWASHER = auto ()
64
+ THERMOSTAT = auto ()
46
65
47
66
def ExampleName (self ):
48
67
if self == NxpApp .LIGHTING :
49
68
return 'lighting-app'
50
69
elif self == NxpApp .CONTACT :
51
70
return "contact-sensor-app"
71
+ elif self == NxpApp .ALLCLUSTERS :
72
+ return "all-clusters-app"
73
+ elif self == NxpApp .LAUNDRYWASHER :
74
+ return "laundry-washer-app"
75
+ elif self == NxpApp .THERMOSTAT :
76
+ return "thermostat"
52
77
else :
53
78
raise Exception ('Unknown app type: %r' % self )
54
79
@@ -57,6 +82,12 @@ def NameSuffix(self):
57
82
return 'light-example'
58
83
elif self == NxpApp .CONTACT :
59
84
return 'contact-example'
85
+ elif self == NxpApp .ALLCLUSTERS :
86
+ return "all-cluster-example"
87
+ elif self == NxpApp .LAUNDRYWASHER :
88
+ return "laundry-washer-example"
89
+ elif self == NxpApp .THERMOSTAT :
90
+ return "thermostat-example"
60
91
else :
61
92
raise Exception ('Unknown app type: %r' % self )
62
93
@@ -71,6 +102,7 @@ def __init__(self,
71
102
runner ,
72
103
app : NxpApp = NxpApp .LIGHTING ,
73
104
board : NxpBoard = NxpBoard .K32W0 ,
105
+ os_env : NxpOsUsed = NxpOsUsed .FREERTOS ,
74
106
low_power : bool = False ,
75
107
smu2 : bool = False ,
76
108
enable_factory_data : bool = False ,
@@ -85,6 +117,7 @@ def __init__(self,
85
117
self .code_root = root
86
118
self .app = app
87
119
self .board = board
120
+ self .os_env = os_env
88
121
self .low_power = low_power
89
122
self .smu2 = smu2
90
123
self .enable_factory_data = enable_factory_data
@@ -125,15 +158,54 @@ def GnBuildArgs(self):
125
158
126
159
return args
127
160
161
+ def WestBuildArgs (self ):
162
+ args = []
163
+ if self .enable_factory_data :
164
+ args .append ('-DFILE_SUFFIX=fdata' )
165
+
166
+ if self .has_sw_version_2 :
167
+ args .append ('-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2' )
168
+
169
+ build_args = " -- " + " " .join (args ) if len (args ) > 0 else ""
170
+ return build_args
171
+
128
172
def generate (self ):
129
- super (NxpBuilder , self ).generate ()
173
+ if self .os_env == NxpOsUsed .ZEPHYR :
174
+ if 'ZEPHYR_NXP_SDK_INSTALL_DIR' in os .environ :
175
+ cmd = 'export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_NXP_SDK_INSTALL_DIR"\n '
176
+ else :
177
+ raise Exception ("ZEPHYR_SDK_INSTALL_DIR need to be set" )
178
+ if 'ZEPHYR_NXP_BASE' in os .environ :
179
+ cmd += 'export ZEPHYR_BASE="$ZEPHYR_NXP_BASE"\n '
180
+ else :
181
+ raise Exception ("ZEPHYR_NXP_BASE need to be set" )
182
+ build_args = self .WestBuildArgs ()
183
+ cmd += '''
184
+ west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_args}
185
+ ''' .format (
186
+ board_name = self .board .Name (),
187
+ out_folder = self .output_dir ,
188
+ example_folder = self .app .BuildRoot (self .code_root , self .board ),
189
+ build_args = build_args ).strip ()
190
+ self ._Execute (['bash' , '-c' , cmd ], title = 'Generating ' + self .identifier )
191
+ else :
192
+ super (NxpBuilder , self ).generate ()
130
193
131
194
def build_outputs (self ):
132
195
name = 'chip-%s-%s' % (self .board .Name (), self .app .NameSuffix ())
133
- yield BuilderOutput (
134
- os .path .join (self .output_dir , name ),
135
- f'{ name } .elf' )
136
- if self .options .enable_link_map_file :
196
+ if self .os_env == NxpOsUsed .ZEPHYR :
197
+ yield BuilderOutput (
198
+ os .path .join (self .output_dir , 'zephyr' , 'zephyr.elf' ),
199
+ f'{ name } .elf' )
200
+ if self .options .enable_link_map_file :
201
+ yield BuilderOutput (
202
+ os .path .join (self .output_dir , 'zephyr' , 'zephyr.map' ),
203
+ f'{ name } .map' )
204
+ else :
137
205
yield BuilderOutput (
138
- os .path .join (self .output_dir , f'{ name } .map' ),
139
- f'{ name } .map' )
206
+ os .path .join (self .output_dir , name ),
207
+ f'{ name } .elf' )
208
+ if self .options .enable_link_map_file :
209
+ yield BuilderOutput (
210
+ os .path .join (self .output_dir , f'{ name } .map' ),
211
+ f'{ name } .map' )
0 commit comments