コード例 #1
0
def generate_prop_defines(node_path, prop):
    # Generates #defines (and .conf file values) from the prop
    # named 'prop' on the device tree node at 'node_path'

    binding = get_binding(node_path)
    if 'parent' in binding and 'bus' in binding['parent']:
        # If the binding specifies a parent for the node, then include the
        # parent in the #define's generated for the properties
        parent_path = get_parent_path(node_path)
        def_label = 'DT_' + node_label(parent_path) + '_' \
                          + node_label(node_path)
    else:
        def_label = 'DT_' + node_label(node_path)

    names = prop_names(reduced[node_path], prop)

    if prop == 'reg':
        reg.extract(node_path, names, def_label, 1)
    elif prop == 'interrupts' or prop == 'interrupts-extended':
        interrupts.extract(node_path, prop, names, def_label)
    elif prop == 'compatible':
        compatible.extract(node_path, prop, def_label)
    elif 'clocks' in prop:
        clocks.extract(node_path, prop, def_label)
    elif 'pwms' in prop or 'gpios' in prop:
        prop_values = reduced[node_path]['props'][prop]
        generic = prop[:-1]  # Drop the 's' from the prop

        extract_controller(node_path, prop, prop_values, 0, def_label, generic)
        extract_cells(node_path, prop, prop_values, names, 0, def_label,
                      generic)
    else:
        default.extract(node_path, prop, binding['properties'][prop]['type'],
                        def_label)
コード例 #2
0
ファイル: flash.py プロジェクト: voicevon/zephyr
    def _extract_flash(self, node_address, prop, def_label):
        load_defs = {
            'CONFIG_FLASH_BASE_ADDRESS': 0,
            'CONFIG_FLASH_SIZE': 0
        }

        if node_address == 'dummy-flash':
            # We will add addr/size of 0 for systems with no flash controller
            # This is what they already do in the Kconfig options anyway
            insert_defs(node_address, load_defs, {})
            self._flash_base_address = 0
            return

        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"]
        for prop in flash_props:
            if prop in self._flash_node['props']:
                default.extract(node_address, prop, None, def_label)
        insert_defs(node_address, load_defs, {})
コード例 #3
0
ファイル: flash.py プロジェクト: xiaowenxia/zephyr
    def _extract_flash(self, node_address, yaml, prop, def_label):
        load_defs = {}

        if node_address == 'dummy-flash':
            # We will add addr/size of 0 for systems with no flash controller
            # 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, {})
            self._flash_base_address = 0
            return

        self._flash_node = reduced[node_address]

        flash_props = ["label", "write-block-size", "erase-block-size"]
        for prop in flash_props:
            if prop in self._flash_node['props']:
                default.extract(node_address, None, prop, None, def_label)
        insert_defs(node_address, load_defs, {})
コード例 #4
0
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)
コード例 #5
0
def extract_property(node_compat, node_address, prop, prop_val, names):

    node = reduced[node_address]
    yaml_node_compat = get_binding(node_address)
    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 = get_binding(parent_address)
                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, 'parent-label', 'bus-name',
                           'DT_' + def_label)

    if 'base_label' not in yaml_node_compat:
        def_label = 'DT_' + def_label

    if prop == 'reg':
        reg.extract(node_address, names, def_label, 1)
    elif prop == 'interrupts' or prop == 'interrupts-extended':
        interrupts.extract(node_address, prop, names, def_label)
    elif prop == 'compatible':
        compatible.extract(node_address, prop, def_label)
    elif 'pinctrl-' in prop:
        pinctrl.extract(node_address, prop, def_label)
    elif 'clocks' in prop:
        clocks.extract(node_address, 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)

        extract_controller(node_address, prop, prop_values, 0, def_label,
                           generic)
        extract_cells(node_address, prop, prop_values, names, 0, def_label,
                      generic)
    else:
        default.extract(node_address, prop, prop_val['type'], def_label)
コード例 #6
0
    def extract_flash(self):
        node_path = chosen.get('zephyr,flash')
        if not node_path:
            # Add addr/size 0 for systems with no flash controller. This is
            # what they already do in the Kconfig options anyway.
            insert_defs('dummy-flash', {
                'DT_FLASH_BASE_ADDRESS': 0,
                'DT_FLASH_SIZE': 0
            }, {})
            return

        flash_node = reduced[node_path]
        orig_node_addr = node_path

        nr_address_cells, nr_size_cells = get_addr_size_cells(node_path)
        # 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)
        is_spi_flash = False
        if nr_size_cells == 0:
            is_spi_flash = True
            node_path = get_parent_path(node_path)
            (nr_address_cells, nr_size_cells) = get_addr_size_cells(node_path)

        node_compat = get_compat(node_path)
        reg = reduced[node_path]['props']['reg']
        if type(reg) is not list: reg = [
                reg,
        ]
        props = list(reg)

        num_reg_elem = len(props) / (nr_address_cells + nr_size_cells)

        # if we found a spi flash, but don't have mmio direct access support
        # which we determin by the spi controller node only have on reg element
        # (ie for the controller itself and no region for the MMIO flash access)
        if num_reg_elem == 1 and is_spi_flash:
            node_path = orig_node_addr
        else:
            # 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_path, nr_address_cells,
                                   nr_size_cells)

            insert_defs(node_path, {
                'DT_FLASH_BASE_ADDRESS': hex(addr),
                'DT_FLASH_SIZE': size // 1024
            }, {})

        for prop in 'write-block-size', 'erase-block-size':
            if prop in flash_node['props']:
                default.extract(node_path, prop, None, 'DT_FLASH')

                # Add an non-DT prefix alias for compatiability
                prop_alias = {}
                label_post = '_' + str_to_label(prop)
                prop_alias['FLASH' + label_post] = 'DT_FLASH' + label_post
                insert_defs(node_path, {}, prop_alias)
コード例 #7
0
ファイル: flash.py プロジェクト: jhn-nordic/zephyr
    def _extract_flash(self, node_address, prop, def_label):
        load_defs = {}

        if node_address == 'dummy-flash':
            load_defs = {
                'CONFIG_FLASH_BASE_ADDRESS': 0,
                'CONFIG_FLASH_SIZE': 0
            }

            # We will add addr/size of 0 for systems with no flash controller
            # This is what they already do in the Kconfig options anyway
            insert_defs(node_address, load_defs, {})
            self._flash_base_address = 0
            return

        self._flash_node = reduced[node_address]
        orig_node_addr = 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)
        is_spi_flash = False
        if (nr_size_cells == 0):
            is_spi_flash = True
            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)

        num_reg_elem = len(props)/(nr_address_cells + nr_size_cells)

        # if we found a spi flash, but don't have mmio direct access support
        # which we determin by the spi controller node only have on reg element
        # (ie for the controller itself and no region for the MMIO flash access)
        if (num_reg_elem == 1 and is_spi_flash):
            node_address = orig_node_addr
        else:
            # 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"]
        for prop in flash_props:
            if prop in self._flash_node['props']:
                default.extract(node_address, prop, None, def_label)
        insert_defs(node_address, load_defs, {})
コード例 #8
0
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)
コード例 #9
0
def extract_property(node_compat, node_address, prop, prop_val, names):
    node = reduced[node_address]
    yaml_node_compat = get_binding(node_address)
    def_label = get_node_label(node_address)

    if 'parent' in yaml_node_compat and 'bus' in yaml_node_compat['parent']:
        # Get parent label
        parent_address = get_parent_address(node_address)

        # Check that parent has matching child bus value
        try:
            parent_yaml = get_binding(parent_address)
            parent_bus = parent_yaml['child']['bus']
        except (KeyError, TypeError) as e:
            raise Exception("{0} defines parent {1} as bus master, but {1} is "
                            "not configured as bus master in binding".format(
                                node_address, parent_address))

        if parent_bus != yaml_node_compat['parent']['bus']:
            raise Exception("{0} defines parent {1} as {2} bus master, but "
                            "{1} is configured as {3} bus master".format(
                                node_address, parent_address,
                                yaml_node_compat['parent']['bus'], parent_bus))

        # 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)

        # Build the name from the parent node's label
        def_label = get_node_label(parent_address) + '_' + def_label

        # Generate *_BUS_NAME #define
        extract_bus_name(node_address, 'DT_' + def_label)

    def_label = 'DT_' + def_label

    if prop == 'reg':
        reg.extract(node_address, names, def_label, 1)
    elif prop == 'interrupts' or prop == 'interrupts-extended':
        interrupts.extract(node_address, prop, names, def_label)
    elif prop == 'compatible':
        compatible.extract(node_address, prop, def_label)
    elif 'pinctrl-' in prop:
        pinctrl.extract(node_address, prop, def_label)
    elif 'clocks' in prop:
        clocks.extract(node_address, prop, def_label)
    elif 'pwms' in prop or 'gpios' in prop:
        prop_values = reduced[node_address]['props'][prop]
        generic = prop[:-1]  # Drop the 's' from the prop

        extract_controller(node_address, prop, prop_values, 0, def_label,
                           generic)
        extract_cells(node_address, prop, prop_values, names, 0, def_label,
                      generic)
    else:
        default.extract(node_address, prop, prop_val['type'], def_label)