dts/extract_dts_includes.py: Add partition support
This patch adds parsing support for flash partitions. Signed-off-by: Andy Gross <andy.gross@linaro.org>
This commit is contained in:
parent
68e8813896
commit
69255043e7
1 changed files with 59 additions and 33 deletions
|
@ -3,7 +3,7 @@
|
||||||
# vim: ai:ts=4:sw=4
|
# vim: ai:ts=4:sw=4
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from os import walk
|
from os import listdir
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -231,7 +231,7 @@ def extract_interrupts(node_address, yaml, y_key, names, defs, def_label):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def extract_reg_prop(node_address, names, defs, def_label, div):
|
def extract_reg_prop(node_address, names, defs, def_label, div, post_label):
|
||||||
node = reduced[node_address]
|
node = reduced[node_address]
|
||||||
|
|
||||||
props = list(reduced[node_address]['props']['reg'])
|
props = list(reduced[node_address]['props']['reg'])
|
||||||
|
@ -244,9 +244,12 @@ def extract_reg_prop(node_address, names, defs, def_label, div):
|
||||||
address_cells = reduced[address]['props'].get('#address-cells', address_cells)
|
address_cells = reduced[address]['props'].get('#address-cells', address_cells)
|
||||||
size_cells = reduced[address]['props'].get('#size-cells', size_cells)
|
size_cells = reduced[address]['props'].get('#size-cells', size_cells)
|
||||||
|
|
||||||
|
if post_label is None:
|
||||||
|
post_label = "BASE_ADDRESS"
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
l_base = def_label.split('/')
|
l_base = def_label.split('/')
|
||||||
l_addr = ["BASE_ADDRESS"]
|
l_addr = [convert_string_to_label(post_label).upper()]
|
||||||
l_size = ["SIZE"]
|
l_size = ["SIZE"]
|
||||||
|
|
||||||
while props:
|
while props:
|
||||||
|
@ -401,14 +404,21 @@ def extract_single(node_address, yaml, prop, key, prefix, defs, def_label):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def extract_property(yaml, node_address, y_key, y_val, names, prefix, defs):
|
def extract_property(node_compat, yaml, node_address, y_key, y_val, names, prefix, defs, label_override):
|
||||||
|
|
||||||
node = reduced[node_address]
|
node = reduced[node_address]
|
||||||
def_label = convert_string_to_label(get_compat(node)).upper()
|
|
||||||
def_label += '_' + node_address.split('@')[-1].upper()
|
if 'base_label' in yaml[node_compat]:
|
||||||
|
def_label = yaml[node_compat].get('base_label')
|
||||||
|
else:
|
||||||
|
def_label = convert_string_to_label(node_compat.upper())
|
||||||
|
def_label += '_' + node_address.split('@')[-1].upper()
|
||||||
|
|
||||||
|
if label_override is not None:
|
||||||
|
def_label += '_' + label_override
|
||||||
|
|
||||||
if y_key == 'reg':
|
if y_key == 'reg':
|
||||||
extract_reg_prop(node_address, names, defs, def_label, 1)
|
extract_reg_prop(node_address, names, defs, def_label, 1, y_val.get('label', None))
|
||||||
elif y_key == 'interrupts' or y_key == 'interupts-extended':
|
elif y_key == 'interrupts' or y_key == 'interupts-extended':
|
||||||
extract_interrupts(node_address, yaml, y_key, names, defs, def_label)
|
extract_interrupts(node_address, yaml, y_key, names, defs, def_label)
|
||||||
elif 'pinctrl-' in y_key:
|
elif 'pinctrl-' in y_key:
|
||||||
|
@ -419,24 +429,40 @@ def extract_property(yaml, node_address, y_key, y_val, names, prefix, defs):
|
||||||
extract_cells(node_address, yaml, y_key,
|
extract_cells(node_address, yaml, y_key,
|
||||||
names, 0, prefix, defs, def_label)
|
names, 0, prefix, defs, def_label)
|
||||||
else:
|
else:
|
||||||
extract_single(node_address, yaml[get_compat(reduced[node_address])],
|
extract_single(node_address, yaml,
|
||||||
reduced[node_address]['props'][y_key], y_key,
|
reduced[node_address]['props'][y_key], y_key,
|
||||||
prefix, defs, def_label)
|
prefix, defs, def_label)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def extract_node_include_info(reduced, node_address, yaml, defs, structs):
|
def extract_node_include_info(reduced, root_node_address, sub_node_address,
|
||||||
node = reduced[node_address]
|
yaml, defs, structs, y_sub):
|
||||||
node_compat = get_compat(node)
|
node = reduced[sub_node_address]
|
||||||
|
node_compat = get_compat(reduced[root_node_address])
|
||||||
|
label_override = None
|
||||||
|
|
||||||
if not node_compat in yaml.keys():
|
if not node_compat in yaml.keys():
|
||||||
return {}, {}
|
return {}, {}
|
||||||
|
|
||||||
y_node = yaml[node_compat]
|
if y_sub is None:
|
||||||
|
y_node = yaml[node_compat]
|
||||||
|
else:
|
||||||
|
y_node = y_sub
|
||||||
|
|
||||||
|
if yaml[node_compat].get('use-property-label', False):
|
||||||
|
for yp in y_node['properties']:
|
||||||
|
if yp.get('label') is not None:
|
||||||
|
if node['props'].get('label') is not None:
|
||||||
|
label_override = convert_string_to_label(node['props']['label']).upper()
|
||||||
|
break
|
||||||
|
|
||||||
# check to see if we need to process the properties
|
# check to see if we need to process the properties
|
||||||
for yp in y_node['properties']:
|
for yp in y_node['properties']:
|
||||||
for k,v in yp.items():
|
for k,v in yp.items():
|
||||||
|
if 'properties' in v:
|
||||||
|
for c in reduced:
|
||||||
|
if root_node_address + '/' in c:
|
||||||
|
extract_node_include_info(reduced, root_node_address, c, yaml, defs, structs, v)
|
||||||
if 'generation' in v:
|
if 'generation' in v:
|
||||||
if v['generation'] == 'define':
|
if v['generation'] == 'define':
|
||||||
label = v.get('define_string')
|
label = v.get('define_string')
|
||||||
|
@ -465,7 +491,7 @@ def extract_node_include_info(reduced, node_address, yaml, defs, structs):
|
||||||
if not isinstance(names, list):
|
if not isinstance(names, list):
|
||||||
names = [names]
|
names = [names]
|
||||||
|
|
||||||
extract_property(yaml, node_address, c, v, names, prefix, defs)
|
extract_property(node_compat, yaml, sub_node_address, c, v, names, prefix, defs, label_override)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -622,10 +648,16 @@ def main():
|
||||||
|
|
||||||
# scan YAML files and find the ones we are interested in
|
# scan YAML files and find the ones we are interested in
|
||||||
yaml_files = []
|
yaml_files = []
|
||||||
for (dirpath, dirnames, filenames) in walk(args.yaml):
|
for filename in listdir(args.yaml):
|
||||||
yaml_files.extend([f for f in filenames if re.match('.*\.yaml\Z', f)])
|
if re.match('.*\.yaml\Z', filename):
|
||||||
yaml_files = [dirpath + '/' + t for t in yaml_files]
|
yaml_files.append(os.path.realpath(args.yaml + '/' + filename))
|
||||||
break
|
|
||||||
|
# scan common YAML files and find the ones we are interested in
|
||||||
|
zephyrbase = os.environ.get('ZEPHYR_BASE')
|
||||||
|
if zephyrbase is not None:
|
||||||
|
for filename in listdir(zephyrbase + '/dts/common/yaml'):
|
||||||
|
if re.match('.*\.yaml\Z', filename):
|
||||||
|
yaml_files.append(os.path.realpath(zephyrbase + '/dts/common/yaml/' + filename))
|
||||||
|
|
||||||
yaml_list = {}
|
yaml_list = {}
|
||||||
file_load_list = set()
|
file_load_list = set()
|
||||||
|
@ -646,36 +678,30 @@ def main():
|
||||||
# collapse the yaml inherited information
|
# collapse the yaml inherited information
|
||||||
yaml_list = yaml_collapse(yaml_list)
|
yaml_list = yaml_collapse(yaml_list)
|
||||||
|
|
||||||
# load zephyr specific nodes
|
|
||||||
flash = {}
|
|
||||||
console = {}
|
|
||||||
sram = {}
|
|
||||||
if 'zephyr,flash' in chosen:
|
|
||||||
flash = reduced[chosen['zephyr,flash']]
|
|
||||||
if 'zephyr,console' in chosen:
|
|
||||||
console = reduced[chosen['zephyr,console']]
|
|
||||||
if 'zephyr,sram' in chosen:
|
|
||||||
sram = reduced[chosen['zephyr,sram']]
|
|
||||||
|
|
||||||
defs = {}
|
defs = {}
|
||||||
structs = {}
|
structs = {}
|
||||||
for k, v in reduced.items():
|
for k, v in reduced.items():
|
||||||
node_compat = get_compat(v)
|
node_compat = get_compat(v)
|
||||||
if node_compat != None and node_compat in yaml_list:
|
if node_compat != None and node_compat in yaml_list:
|
||||||
extract_node_include_info(reduced, k, yaml_list, defs, structs)
|
extract_node_include_info(reduced, k, k, yaml_list, defs, structs, None)
|
||||||
|
|
||||||
if defs == {}:
|
if defs == {}:
|
||||||
raise Exception("No information parsed from dts file.")
|
raise Exception("No information parsed from dts file.")
|
||||||
|
|
||||||
if flash:
|
if 'zephyr,flash' in chosen:
|
||||||
extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH", 1024)
|
extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH", 1024, None)
|
||||||
else:
|
else:
|
||||||
# We will add address and size of 0 for systems with no flash controller
|
# We will add address and 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
|
||||||
defs['dummy-flash'] = { 'CONFIG_FLASH_BASE_ADDRESS': 0, 'CONFIG_FLASH_SIZE': 0 }
|
defs['dummy-flash'] = { 'CONFIG_FLASH_BASE_ADDRESS': 0, 'CONFIG_FLASH_SIZE': 0 }
|
||||||
|
|
||||||
if sram:
|
if 'zephyr,sram' in chosen:
|
||||||
extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024)
|
extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024, None)
|
||||||
|
|
||||||
|
if 'zephyr,code-partition' in chosen:
|
||||||
|
extract_reg_prop(chosen['zephyr,code-partition'], None, defs, "CONFIG_FLASH_LOAD", 1, "OFFSET")
|
||||||
|
else:
|
||||||
|
extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH_LOAD", 1, "OFFSET")
|
||||||
|
|
||||||
# generate include file
|
# generate include file
|
||||||
if args.keyvalue:
|
if args.keyvalue:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue