scripts/dts/extract: Support QSPI memory mapped flash

We need to refactor how we determine CONFIG_FLASH_{SIZE,BASE_ADDRESS}
for when we have a QSPI that is memory mapped. "zephyr,flash" is going
to point the actual flash component that will be on a SPI bus and thus
the device node's reg property tells us which CS on the SPI bus its on,
not the memory mapped address/size of the flash.

So we make a few assumptions to handle this case:
1. If the #size-cells for the flash node is 0, we assume its a QSPI
   memory mapped flash
2. That the QSPI memory mapped node (parent of what "zephyr,flash" is
   point to, will contain a reg propery where the second reg pair will
   be the memory mapped region for the flash.

We move handling of CONFIG_FLASH_{SIZE,BASE_ADDRESS} into flash.extract
so its all in one place.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-01-10 15:51:38 -06:00 committed by Kumar Gala
commit e57a596a0c
2 changed files with 39 additions and 6 deletions

View file

@ -60,21 +60,55 @@ class DTFlash(DTDirective):
insert_defs(node_address, prop_def, prop_alias) insert_defs(node_address, prop_def, prop_alias)
def _extract_flash(self, node_address, prop, def_label): def _extract_flash(self, node_address, prop, def_label):
load_defs = {} load_defs = {
'CONFIG_FLASH_BASE_ADDRESS': 0,
'CONFIG_FLASH_SIZE': 0
}
if node_address == 'dummy-flash': if node_address == 'dummy-flash':
# We will add addr/size of 0 for systems with no flash controller # We will add addr/size of 0 for systems with no flash controller
# This is what they already do in the Kconfig options anyway # This is what they already do in the Kconfig options anyway
load_defs = {
'CONFIG_FLASH_BASE_ADDRESS': 0,
'CONFIG_FLASH_SIZE': 0
}
insert_defs(node_address, load_defs, {}) insert_defs(node_address, load_defs, {})
self._flash_base_address = 0 self._flash_base_address = 0
return return
self._flash_node = reduced[node_address] self._flash_node = reduced[node_address]
(nr_address_cells, nr_size_cells) = get_addr_size_cells(node_address)
# if the nr_size_cells is 0, assume a SPI flash, need to look at parent
# for addr/size info, and the second reg property (assume first is mmio
# register for the controller itself)
if (nr_size_cells == 0):
node_address = get_parent_address(node_address)
(nr_address_cells, nr_size_cells) = get_addr_size_cells(node_address)
node_compat = get_compat(node_address)
reg = reduced[node_address]['props']['reg']
if type(reg) is not list: reg = [ reg, ]
props = list(reg)
# Newer versions of dtc might have the reg propertly look like
# reg = <1 2>, <3 4>;
# So we need to flatten the list in that case
if isinstance(props[0], list):
props = [item for sublist in props for item in sublist]
# We assume the last reg property is the one we want
while props:
addr = 0
size = 0
for x in range(nr_address_cells):
addr += props.pop(0) << (32 * (nr_address_cells - x - 1))
for x in range(nr_size_cells):
size += props.pop(0) << (32 * (nr_size_cells - x - 1))
addr += translate_addr(addr, node_address,
nr_address_cells, nr_size_cells)
load_defs['CONFIG_FLASH_BASE_ADDRESS'] = hex(addr)
load_defs['CONFIG_FLASH_SIZE'] = int(size / 1024)
flash_props = ["label", "write-block-size", "erase-block-size"] flash_props = ["label", "write-block-size", "erase-block-size"]
for prop in flash_props: for prop in flash_props:
if prop in self._flash_node['props']: if prop in self._flash_node['props']:

View file

@ -21,7 +21,6 @@ bindings_compat = []
old_alias_names = False old_alias_names = False
regs_config = { regs_config = {
'zephyr,flash' : 'CONFIG_FLASH',
'zephyr,sram' : 'CONFIG_SRAM', 'zephyr,sram' : 'CONFIG_SRAM',
'zephyr,ccm' : 'CONFIG_CCM' 'zephyr,ccm' : 'CONFIG_CCM'
} }