1515#
1616class DTFlash (DTDirective ):
1717 def __init__ (self ):
18- # Node of the flash
19- self ._flash_node = None
2018 self ._flash_area = {}
2119
2220 def _extract_partition (self , node_path ):
@@ -138,20 +136,20 @@ def extract_partition(self, node_path):
138136
139137 insert_defs (node_path , prop_def , prop_alias )
140138
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' ,
146145 {'DT_FLASH_BASE_ADDRESS' : 0 , 'DT_FLASH_SIZE' : 0 },
147146 {})
148- self ._flash_base_address = 0
149147 return
150148
151- self . _flash_node = reduced [node_path ]
149+ flash_node = reduced [node_path ]
152150 orig_node_addr = node_path
153151
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 )
155153 # if the nr_size_cells is 0, assume a SPI flash, need to look at parent
156154 # for addr/size info, and the second reg property (assume first is mmio
157155 # register for the controller itself)
@@ -193,28 +191,26 @@ def _extract_flash(self, node_path, prop, def_label):
193191 {})
194192
195193 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' )
198196
199197 # Add an non-DT prefix alias for compatiability
200198 prop_alias = {}
201199 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
203201 insert_defs (node_path , {}, prop_alias )
204202
205203
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' )):
218214 # only compute the load offset if the code partition
219215 # is not the same as the flash base address
220216 load_offset = node ['props' ]['reg' ][0 ]
@@ -228,27 +224,7 @@ def _extract_code_partition(self, node_path, prop, def_label):
228224 'DT_CODE_PARTITION_SIZE' : load_size },
229225 {})
230226
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+
252228##
253229# @brief Management information for flash.
254230flash = DTFlash ()
0 commit comments