15
15
#
16
16
class DTFlash (DTDirective ):
17
17
def __init__ (self ):
18
- # Node of the flash
19
- self ._flash_node = None
20
18
self ._flash_area = {}
21
19
22
20
def _extract_partition (self , node_path ):
@@ -138,20 +136,20 @@ def extract_partition(self, node_path):
138
136
139
137
insert_defs (node_path , prop_def , prop_alias )
140
138
141
- def _extract_flash (self , node_path , prop , def_label ):
142
- if node_path == 'dummy-flash' :
143
- # We will add addr/size of 0 for systems with no flash controller
144
- # This is what they already do in the Kconfig options anyway
145
- insert_defs (node_path ,
139
+ def extract_flash (self ):
140
+ node_path = chosen .get ('zephyr,flash' )
141
+ if not node_path :
142
+ # Add addr/size 0 for systems with no flash controller. This is
143
+ # what they already do in the Kconfig options anyway.
144
+ insert_defs ('dummy-flash' ,
146
145
{'DT_FLASH_BASE_ADDRESS' : 0 , 'DT_FLASH_SIZE' : 0 },
147
146
{})
148
- self ._flash_base_address = 0
149
147
return
150
148
151
- self . _flash_node = reduced [node_path ]
149
+ flash_node = reduced [node_path ]
152
150
orig_node_addr = node_path
153
151
154
- ( nr_address_cells , nr_size_cells ) = get_addr_size_cells (node_path )
152
+ nr_address_cells , nr_size_cells = get_addr_size_cells (node_path )
155
153
# if the nr_size_cells is 0, assume a SPI flash, need to look at parent
156
154
# for addr/size info, and the second reg property (assume first is mmio
157
155
# register for the controller itself)
@@ -193,28 +191,26 @@ def _extract_flash(self, node_path, prop, def_label):
193
191
{})
194
192
195
193
for prop in 'write-block-size' , 'erase-block-size' :
196
- if prop in self . _flash_node ['props' ]:
197
- default .extract (node_path , prop , None , def_label )
194
+ if prop in flash_node ['props' ]:
195
+ default .extract (node_path , prop , None , 'DT_FLASH' )
198
196
199
197
# Add an non-DT prefix alias for compatiability
200
198
prop_alias = {}
201
199
label_post = '_' + str_to_label (prop )
202
- prop_alias ['FLASH' + label_post ] = def_label + label_post
200
+ prop_alias ['FLASH' + label_post ] = 'DT_FLASH' + label_post
203
201
insert_defs (node_path , {}, prop_alias )
204
202
205
203
206
- def _extract_code_partition (self , node_path , prop , def_label ):
207
- if node_path == 'dummy-flash' :
208
- node = None
209
- else :
210
- node = reduced [node_path ]
211
- if self ._flash_node is None :
212
- # No flash node scanned before-
213
- raise Exception (
214
- "Code partition '{}' {} without flash definition."
215
- .format (prop , node_path ))
216
-
217
- if node and node is not self ._flash_node :
204
+ def extract_code_partition (self ):
205
+ node_path = chosen .get ('zephyr,code-partition' )
206
+ if not node_path :
207
+ # Fall back on zephyr,flash if zephyr,code-partition isn't set.
208
+ # node_path will be 'dummy-flash' if neither is set.
209
+ node_path = chosen .get ('zephyr,flash' , 'dummy-flash' )
210
+
211
+ node = reduced .get (node_path )
212
+
213
+ if node and node is not reduced .get (chosen .get ('zephyr,flash' )):
218
214
# only compute the load offset if the code partition
219
215
# is not the same as the flash base address
220
216
load_offset = node ['props' ]['reg' ][0 ]
@@ -228,27 +224,7 @@ def _extract_code_partition(self, node_path, prop, def_label):
228
224
'DT_CODE_PARTITION_SIZE' : load_size },
229
225
{})
230
226
231
- ##
232
- # @brief Extract flash
233
- #
234
- # @param node_path Path to node owning the
235
- # flash definition.
236
- # @param prop compatible property name
237
- # @param def_label Define label string of node owning the
238
- # compatible definition.
239
- #
240
- def extract (self , node_path , prop , def_label ):
241
-
242
- if prop == 'zephyr,flash' :
243
- # indicator for flash
244
- self ._extract_flash (node_path , prop , def_label )
245
- elif prop == 'zephyr,code-partition' :
246
- # indicator for code_partition
247
- self ._extract_code_partition (node_path , prop , def_label )
248
- else :
249
- raise Exception (
250
- "DTFlash.extract called with unexpected directive ({})."
251
- .format (prop ))
227
+
252
228
##
253
229
# @brief Management information for flash.
254
230
flash = DTFlash ()
0 commit comments