def generate_node_definitions(yaml_list): defs = {} structs = {} for k, v in reduced.items(): node_compat = get_compat(k) 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.") for k, v in regs_config.items(): if k in chosen: extract_reg_prop(chosen[k], None, defs, v, 1024, None) for k, v in name_config.items(): if k in chosen: extract_string_prop(chosen[k], None, "label", v, defs) node_address = chosen.get('ugelis,flash', 'dummy-flash') flash.extract(node_address, yaml_list, 'ugelis,flash', None, defs, 'FLASH') node_address = chosen.get('ugelis,code-partition', node_address) flash.extract(node_address, yaml_list, 'ugelis,code-partition', None, defs, 'FLASH') return defs
def generate_defines(): # Generates #defines (and .conf file values) from DTS # sorted() otherwise Python < 3.6 randomizes the order of the flash # partition table for node_path in sorted(reduced.keys()): generate_node_defines(node_path) if not defs: raise Exception("No information parsed from dts file.") for k, v in regs_config.items(): if k in chosen: reg.extract(chosen[k], None, v, 1024) for k, v in name_config.items(): if k in chosen: extract_string_prop(chosen[k], "label", v) node_path = chosen.get('zephyr,flash', 'dummy-flash') flash.extract(node_path, 'zephyr,flash', 'DT_FLASH') node_path = chosen.get('zephyr,code-partition', node_path) flash.extract(node_path, 'zephyr,code-partition', None) # Add DT_CHOSEN_<X> defines for c in sorted(chosen): insert_defs('chosen', {'DT_CHOSEN_' + str_to_label(c): '1'}, {})
def generate_node_definitions(): for k, v in reduced.items(): node_compat = get_compat(k) if node_compat is not None and node_compat in get_binding_compats(): extract_node_include_info(reduced, k, k, None) if not defs: raise Exception("No information parsed from dts file.") for k, v in regs_config.items(): if k in chosen: reg.extract(chosen[k], None, v, 1024) for k, v in name_config.items(): if k in chosen: extract_string_prop(chosen[k], "label", v) node_address = chosen.get('zephyr,flash', 'dummy-flash') flash.extract(node_address, 'zephyr,flash', 'DT_FLASH') node_address = chosen.get('zephyr,code-partition', node_address) flash.extract(node_address, 'zephyr,code-partition', None)
def generate_defines(): for node_path in reduced.keys(): if get_compat(node_path) in get_binding_compats(): generate_node_defines(node_path) if not defs: raise Exception("No information parsed from dts file.") for k, v in regs_config.items(): if k in chosen: reg.extract(chosen[k], None, v, 1024) for k, v in name_config.items(): if k in chosen: extract_string_prop(chosen[k], "label", v) node_address = chosen.get('zephyr,flash', 'dummy-flash') flash.extract(node_address, 'zephyr,flash', 'DT_FLASH') node_address = chosen.get('zephyr,code-partition', node_address) flash.extract(node_address, 'zephyr,code-partition', None) # Add DT_CHOSEN_<X> defines for c in sorted(chosen): insert_defs('chosen', {'DT_CHOSEN_' + str_to_label(c): '1'}, {})
def extract_property(node_compat, yaml, node_address, prop, prop_val, names, defs, label_override): if 'base_label' in yaml[node_compat]: def_label = yaml[node_compat].get('base_label') else: def_label = get_node_label(node_compat, node_address) if 'parent' in yaml[node_compat]: if 'bus' in yaml[node_compat]['parent']: # get parent label parent_address = '' for comp in node_address.split('/')[1:-1]: parent_address += '/' + comp #check parent has matching child bus value try: parent_yaml = \ yaml[reduced[parent_address]['props']['compatible']] parent_bus = parent_yaml['child']['bus'] except (KeyError, TypeError) as e: raise Exception( str(node_address) + " defines parent " + str(parent_address) + " as bus master but " + str(parent_address) + " not configured as bus master " + "in yaml description") if parent_bus != yaml[node_compat]['parent']['bus']: bus_value = yaml[node_compat]['parent']['bus'] raise Exception( str(node_address) + " defines parent " + str(parent_address) + " as " + bus_value + " bus master but " + str(parent_address) + " configured as " + str(parent_bus) + " bus master") # Generate alias definition if parent has any alias if parent_address in aliases: for i in aliases[parent_address]: node_alias = i + '_' + def_label aliases[node_address].append(node_alias) # Use parent label to generate label parent_label = get_node_label( find_parent_prop(node_address, 'compatible'), parent_address) def_label = parent_label + '_' + def_label # Generate bus-name define extract_single(node_address, yaml, 'parent-label', 'bus-name', defs, def_label) if label_override is not None: def_label += '_' + label_override if prop == 'reg': if 'partition@' in node_address: # reg in partition is covered by flash handling flash.extract(node_address, yaml, prop, names, defs, def_label) else: reg.extract(node_address, yaml, prop, names, defs, def_label) elif prop == 'interrupts' or prop == 'interrupts-extended': interrupts.extract(node_address, yaml, prop, names, defs, def_label) elif 'pinctrl-' in prop: pinctrl.extract(node_address, yaml, prop, names, defs, def_label) elif 'clocks' in prop: clocks.extract(node_address, yaml, prop, names, defs, def_label) elif 'gpios' in prop: try: prop_values = list(reduced[node_address]['props'].get(prop)) except: prop_values = reduced[node_address]['props'].get(prop) extract_controller(node_address, yaml, prop, prop_values, 0, defs, def_label, 'gpio') extract_cells(node_address, yaml, prop, prop_values, names, 0, defs, def_label, 'gpio') else: default.extract(node_address, yaml, prop, names, defs, def_label)
def extract_property(node_compat, yaml, node_address, prop, prop_val, names): node = reduced[node_address] label_override = None if yaml[node_compat].get('use-property-label', False): try: label_override = convert_string_to_label(node['props']['label']) except KeyError: pass if 'base_label' in yaml[node_compat]: def_label = yaml[node_compat].get('base_label') else: def_label = get_node_label(node_address) if 'parent' in yaml[node_compat]: if 'bus' in yaml[node_compat]['parent']: # get parent label parent_address = get_parent_address(node_address) #check parent has matching child bus value try: parent_yaml = \ yaml[reduced[parent_address]['props']['compatible']] parent_bus = parent_yaml['child']['bus'] except (KeyError, TypeError) as e: raise Exception( str(node_address) + " defines parent " + str(parent_address) + " as bus master but " + str(parent_address) + " not configured as bus master " + "in yaml description") if parent_bus != yaml[node_compat]['parent']['bus']: bus_value = yaml[node_compat]['parent']['bus'] raise Exception( str(node_address) + " defines parent " + str(parent_address) + " as " + bus_value + " bus master but " + str(parent_address) + " configured as " + str(parent_bus) + " bus master") # Generate alias definition if parent has any alias if parent_address in aliases: for i in aliases[parent_address]: # Build an alias name that respects device tree specs node_name = node_compat + '-' + node_address.split('@')[-1] node_strip = node_name.replace('@', '-').replace(',', '-') node_alias = i + '-' + node_strip if node_alias not in aliases[node_address]: # Need to generate alias name for this node: aliases[node_address].append(node_alias) # Use parent label to generate label parent_label = get_node_label(parent_address) def_label = parent_label + '_' + def_label # Generate bus-name define extract_single(node_address, yaml, 'parent-label', 'bus-name', def_label) if label_override is not None: def_label += '_' + label_override if prop == 'reg': if 'partition@' in node_address: # reg in partition is covered by flash handling flash.extract(node_address, yaml, prop, def_label) else: reg.extract(node_address, yaml, names, def_label, 1) elif prop == 'interrupts' or prop == 'interrupts-extended': interrupts.extract(node_address, yaml, prop, names, def_label) elif prop == 'compatible': compatible.extract(node_address, yaml, prop, def_label) elif 'pinctrl-' in prop: pinctrl.extract(node_address, yaml, prop, def_label) elif 'clocks' in prop: clocks.extract(node_address, yaml, prop, def_label) elif 'pwms' in prop or 'gpios' in prop: # drop the 's' from the prop generic = prop[:-1] try: prop_values = list(reduced[node_address]['props'].get(prop)) except: prop_values = reduced[node_address]['props'].get(prop) # Newer versions of dtc might have the property look like # cs-gpios = <0x05 0x0d 0x00>, < 0x06 0x00 0x00>; # So we need to flatten the list in that case if isinstance(prop_values[0], list): prop_values = [item for sublist in prop_values for item in sublist] extract_controller(node_address, yaml, prop, prop_values, 0, def_label, generic) extract_cells(node_address, yaml, prop, prop_values, names, 0, def_label, generic) else: default.extract(node_address, yaml, prop, prop_val['type'], def_label)