def main(): args = parse_arguments() enable_old_alias_names(args.old_alias_names) # Parse DTS and fetch the root node with open(args.dts, 'r', encoding='utf-8') as f: root = parse_file(f)['/'] # Create some global data structures from the parsed DTS create_reduced(root, '/') create_phandles(root, '/') create_aliases(root) create_chosen(root) # Load any bindings (.yaml files) that match 'compatible' values from the # DTS load_bindings(root, args.yaml) # Generate keys and values for the configuration file and the header file generate_defines() # Write the configuration file and the header file if args.keyvalue is not None: with open(args.keyvalue, 'w', encoding='utf-8') as f: write_conf(f) if args.include is not None: with open(args.include, 'w', encoding='utf-8') as f: write_header(f)
def main(): args = parse_arguments() enable_old_alias_names(args.old_alias_names) # Parse DTS and fetch the root node with open(args.dts, 'r', encoding='utf-8') as f: root = parse_file(f)['/'] # Create some global data structures from the parsed DTS create_reduced(root, '/') create_phandles(root, '/') create_aliases(root) create_chosen(root) load_bindings(root, args.yaml) generate_node_definitions() # Add DT_CHOSEN_<X> defines to generated files for c in sorted(chosen): insert_defs('chosen', {'DT_CHOSEN_' + str_to_label(c): '1'}, {}) # Generate config and header files if args.keyvalue is not None: with open(args.keyvalue, 'w', encoding='utf-8') as f: write_conf(f) if args.include is not None: with open(args.include, 'w', encoding='utf-8') as f: write_header(f)
def main(): args = parse_arguments() enable_old_alias_names(args.old_alias_names) # Parse DTS and fetch the root node with open(args.dts, 'r', encoding='utf-8') as f: root = parse_file(f)['/'] # Create some global data structures from the parsed DTS create_reduced(root, '/') create_phandles(root, '/') create_aliases(root) create_chosen(root) # Re-sort instance_id by reg addr # # Note: this is a short term fix and should be removed when # generate defines for instance with a prefix like 'DT_INST' # # Build a dict of dicts, first level is index by compat # second level is index by reg addr compat_reg_dict = defaultdict(dict) for node in reduced.values(): instance = node.get('instance_id') if instance and node['addr'] is not None: for compat in instance: reg = node['addr'] compat_reg_dict[compat][reg] = node # Walk the reg addr in sorted order to re-index 'instance_id' for compat in compat_reg_dict: # only update if we have more than one instance if len(compat_reg_dict[compat]) > 1: for idx, reg_addr in enumerate(sorted(compat_reg_dict[compat])): compat_reg_dict[compat][reg_addr]['instance_id'][compat] = idx # Load any bindings (.yaml files) that match 'compatible' values from the # DTS load_bindings(root, args.yaml) # Generate keys and values for the configuration file and the header file generate_defines() # Write the configuration file and the header file if args.keyvalue is not None: with open(args.keyvalue, 'w', encoding='utf-8') as f: write_conf(f) if args.include is not None: with open(args.include, 'w', encoding='utf-8') as f: write_header(f, args.deprecated_only)
def main(args): if len(args) < 2: print('Usage: %s filename.dts path_to_yaml' % args[0]) return 1 try: with open(args[1], "r") as fd: d = parse_file(fd) except: raise Exception("Input file " + os.path.abspath(args[1]) + " does not exist.") # compress list to nodes w/ paths, add interrupt parent compress_nodes(d['/'], '/') # build up useful lists compatibles = get_all_compatibles(d['/'], '/', {}) get_phandles(d['/'], '/', {}) get_aliases(d['/']) get_chosen(d['/']) # find unique set of compatibles across all active nodes s = set() for k,v in compatibles.items(): if isinstance(v,list): for item in v: s.add(item) else: s.add(v) # scan YAML files and find the ones we are interested in yaml_files = [] for (dirpath, dirnames, filenames) in walk(args[2]): yaml_files.extend([f for f in filenames if re.match('.*\.yaml\Z', f)]) yaml_files = [dirpath + '/' + t for t in yaml_files] break yaml_list = {} file_load_list = set() for file in yaml_files: for line in open(file, 'r'): if re.search('^\s+constraint:*', line): c = line.split(':')[1].strip() c = c.strip('"') if c in s: if not file in file_load_list: file_load_list.add(file) with open(file, 'r') as yf: yaml_list[c] = yaml.load(yf, Loader) if yaml_list == {}: raise Exception("Missing YAML information. Check YAML sources") # collapse the yaml inherited information 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 = {} structs = {} for k, v in reduced.items(): node_compat = get_compat(v) if node_compat != None and node_compat in yaml_list: extract_node_include_info(reduced, k, yaml_list, defs, structs) if defs == {}: raise Exception("No information parsed from dts file.") if flash: extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH", 1024) else: # 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 defs['dummy-flash'] = { 'CONFIG_FLASH_BASE_ADDRESS': 0, 'CONFIG_FLASH_SIZE': 0 } if sram: extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024) # generate include file generate_include_file(defs)
def load_and_parse_dts(dts_file): with open(dts_file, "r") as fd: dts = parse_file(fd) return dts
def main(): args = parse_arguments() if not args.dts or not args.yaml: print('Usage: %s -d filename.dts -y path_to_yaml' % sys.argv[0]) return 1 try: with open(args.dts, "r") as fd: d = parse_file(fd) except: raise Exception("Input file " + os.path.abspath(args.dts) + " does not exist.") # compress list to nodes w/ paths, add interrupt parent compress_nodes(d['/'], '/') # build up useful lists compatibles = get_all_compatibles(d['/'], '/', {}) get_phandles(d['/'], '/', {}) get_aliases(d['/']) get_chosen(d['/']) # find unique set of compatibles across all active nodes s = set() for k, v in compatibles.items(): if isinstance(v, list): for item in v: s.add(item) else: s.add(v) # scan YAML files and find the ones we are interested in yaml_files = [] for filename in listdir(args.yaml): if re.match('.*\.yaml\Z', filename): yaml_files.append(os.path.realpath(args.yaml + '/' + filename)) # 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 = {} file_load_list = set() for file in yaml_files: for line in open(file, 'r'): if re.search('^\s+constraint:*', line): c = line.split(':')[1].strip() c = c.strip('"') if c in s: if file not in file_load_list: file_load_list.add(file) with open(file, 'r') as yf: yaml_list[c] = yaml.load(yf, Loader) if yaml_list == {}: raise Exception("Missing YAML information. Check YAML sources") # collapse the yaml inherited information yaml_list = yaml_collapse(yaml_list) defs = {} structs = {} for k, v in reduced.items(): node_compat = get_compat(v) if node_compat is not None and node_compat in yaml_list: extract_node_include_info(reduced, k, k, yaml_list, defs, structs, None) if defs == {}: raise Exception("No information parsed from dts file.") if 'zephyr,flash' in chosen: extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH", 1024, None) else: # We will add address/size of 0 for systems with no flash controller # This is what they already do in the Kconfig options anyway defs['dummy-flash'] = { 'CONFIG_FLASH_BASE_ADDRESS': 0, 'CONFIG_FLASH_SIZE': 0 } if 'zephyr,sram' in chosen: extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024, None) name_dict = { "CONFIG_UART_CONSOLE_ON_DEV_NAME": "zephyr,console", "CONFIG_BLUETOOTH_UART_ON_DEV_NAME": "zephyr,bt-uart", "CONFIG_UART_PIPE_ON_DEV_NAME": "zephyr,uart-pipe", "CONFIG_BLUETOOTH_MONITOR_ON_DEV_NAME": "zephyr,bt-mon-uart" } for k, v in name_dict.items(): if v in chosen: extract_string_prop(chosen[v], None, "label", k, defs) # only compute the load offset if a code partition exists and it is not the # same as the flash base address load_defs = {} if 'zephyr,code-partition' in chosen and \ 'zephyr,flash' in chosen and \ reduced[chosen['zephyr,flash']] is not \ reduced[chosen['zephyr,code-partition']]: part_defs = {} extract_reg_prop(chosen['zephyr,code-partition'], None, part_defs, "PARTITION", 1, 'offset') part_base = lookup_defs(part_defs, chosen['zephyr,code-partition'], 'PARTITION_OFFSET') load_defs['CONFIG_FLASH_LOAD_OFFSET'] = part_base load_defs['CONFIG_FLASH_LOAD_SIZE'] = \ lookup_defs(part_defs, chosen['zephyr,code-partition'], 'PARTITION_SIZE') else: load_defs['CONFIG_FLASH_LOAD_OFFSET'] = 0 load_defs['CONFIG_FLASH_LOAD_SIZE'] = 0 insert_defs(chosen['zephyr,flash'], defs, load_defs, {}) # generate include file if args.keyvalue: generate_keyvalue_file(defs, args) else: generate_include_file(defs, args)
def load_and_parse_dts(dts_file): with open(dts_file, "r", encoding="utf-8") as fd: dts = parse_file(fd) return dts
def main(): args = parse_arguments() if not args.dts or not args.yaml: print('Usage: %s -d filename.dts -y path_to_yaml' % sys.argv[0]) return 1 try: with open(args.dts, "r") as fd: d = parse_file(fd) except: raise Exception( "Input file " + os.path.abspath(args.dts) + " does not exist.") # compress list to nodes w/ paths, add interrupt parent compress_nodes(d['/'], '/') # build up useful lists compatibles = get_all_compatibles(d['/'], '/', {}) get_phandles(d['/'], '/', {}) get_aliases(d['/']) get_chosen(d['/']) # find unique set of compatibles across all active nodes s = set() for k, v in compatibles.items(): if isinstance(v, list): for item in v: s.add(item) else: s.add(v) # scan YAML files and find the ones we are interested in yaml_files = [] for filename in listdir(args.yaml): if re.match('.*\.yaml\Z', filename): yaml_files.append(os.path.realpath(args.yaml + '/' + filename)) # 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 = {} file_load_list = set() for file in yaml_files: for line in open(file, 'r'): if re.search('^\s+constraint:*', line): c = line.split(':')[1].strip() c = c.strip('"') if c in s: if file not in file_load_list: file_load_list.add(file) with open(file, 'r') as yf: yaml_list[c] = yaml.load(yf, Loader) if yaml_list == {}: raise Exception("Missing YAML information. Check YAML sources") # collapse the yaml inherited information yaml_list = yaml_collapse(yaml_list) defs = {} structs = {} for k, v in reduced.items(): node_compat = get_compat(v) if node_compat is not None and node_compat in yaml_list: extract_node_include_info( reduced, k, k, yaml_list, defs, structs, None) if defs == {}: raise Exception("No information parsed from dts file.") if 'zephyr,flash' in chosen: extract_reg_prop(chosen['zephyr,flash'], None, defs, "CONFIG_FLASH", 1024, None) else: # We will add address/size of 0 for systems with no flash controller # This is what they already do in the Kconfig options anyway defs['dummy-flash'] = {'CONFIG_FLASH_BASE_ADDRESS': 0, 'CONFIG_FLASH_SIZE': 0} if 'zephyr,sram' in chosen: extract_reg_prop(chosen['zephyr,sram'], None, defs, "CONFIG_SRAM", 1024, None) name_dict = { "CONFIG_UART_CONSOLE_ON_DEV_NAME": "zephyr,console", "CONFIG_BT_UART_ON_DEV_NAME": "zephyr,bt-uart", "CONFIG_UART_PIPE_ON_DEV_NAME": "zephyr,uart-pipe", "CONFIG_BT_MONITOR_ON_DEV_NAME": "zephyr,bt-mon-uart" } for k, v in name_dict.items(): if v in chosen: extract_string_prop(chosen[v], None, "label", k, defs) # only compute the load offset if a code partition exists and it is not the # same as the flash base address load_defs = {} if 'zephyr,code-partition' in chosen and \ 'zephyr,flash' in chosen and \ reduced[chosen['zephyr,flash']] is not \ reduced[chosen['zephyr,code-partition']]: part_defs = {} extract_reg_prop(chosen['zephyr,code-partition'], None, part_defs, "PARTITION", 1, 'offset') part_base = lookup_defs(part_defs, chosen['zephyr,code-partition'], 'PARTITION_OFFSET') load_defs['CONFIG_FLASH_LOAD_OFFSET'] = part_base load_defs['CONFIG_FLASH_LOAD_SIZE'] = \ lookup_defs(part_defs, chosen['zephyr,code-partition'], 'PARTITION_SIZE') else: load_defs['CONFIG_FLASH_LOAD_OFFSET'] = 0 load_defs['CONFIG_FLASH_LOAD_SIZE'] = 0 insert_defs(chosen['zephyr,flash'], defs, load_defs, {}) # generate include file if args.keyvalue: generate_keyvalue_file(defs, args) else: generate_include_file(defs, args)