示例#1
0
def memory_expand( tree, subnode, memory_start = 0xbeef, prop_name = 'memory', verbose = 0 ):
    # /*
    # * 1:1 map, it should match the memory regions
    # * specified under access below.
    # *
    # * It is in the form:
    # * memory = <address size address size ...>
    # */
    try:
        mem = [subnode.props( prop_name )[0][0]]


        mem_list = []
        for m in mem:
            try:
                start = str(m['start'])
            except:
                start = str(int(memory_start))
            try:
                size = str(m['size'])
            except:
                size = str(int(0xbeef))

            if 'flags' in m.keys():
                flags = str(m['flags'])
                flag_node = LopperNode(-1, subnode.abs_path+'/flags')
                tree.add(flag_node)

                flag_reference_name = flag_node.abs_path+"/"+str(flags)
                flag_reference_node = LopperNode(-1, flag_reference_name )
                tree.add(flag_reference_node)

                flags_cells = LopperProp(name='#flags-cells',value=0x1)
                flags_prop =  LopperProp(name='flags',value=0x0)
                flags_names = LopperProp('flags-names',value = str(flags))

                subnode + flags_cells
                subnode + flags_prop
                subnode + flags_names

            #print( "memory expand: start/size as read: %s/%s" % (start,size))
            start = humanfriendly.parse_size( start, True )
            size = humanfriendly.parse_size( size, True )
            #print( "memory expand: start/size as converted: %s/%s" % (start,size))

            mem_list.append(int(start))
            mem_list.append(int(size))

    except Exception as e:
        mem_list = [0xdead, 0xffff ]

    if verbose:
        # dump the memory as hex
        print( '[DBG] memory: [{}]'.format(', '.join(hex(x) for x in mem_list)) )

    property_set( prop_name, mem_list, subnode )
示例#2
0
def subsystem_expand(tgt_node, sdt, verbose=0):
    if verbose:
        print("[INFO]: cb: subsystem_expand( %s, %s )" % (tgt_node, sdt))

    tree = sdt.tree

    try:
        domain_node = tree["/domains"]
    except:
        domain_node = LopperNode(-1, "/domains")

    # add the cells properties
    property_set("#address-cells", 2, domain_node)
    property_set("#size-cells", 2, domain_node)
    domain_node.sync()

    #domains = sdt.tree.nodes( "/domains/[^/]*$" )
    domain_count = 0
    for subnode in domain_node.child_nodes.values():
        if subnode._source == "yaml":
            if verbose:
                print(
                    "[DBG] yaml input dectected, expanding %s to full device tree domain"
                    % subnode.abs_path)

            # we flip the name and the label, since the yaml name does not
            # follow device tree conventions.
            name = subnode.name
            subnode.name = "domain@{}".format(domain_count)
            subnode.label = name
            property_set("lopper-label-gen1", subnode.label, subnode)

            # set the compatibility
            property_set("compatible", "openamp,domain-v1", subnode)

            # ensure that the xilinx,subsystem is set property
            property_set("xilinx,subsystem", 1, subnode)

            ## cpu processing
            cpu_expand(tree, subnode, verbose)

            ## memory processing
            memory_expand(tree, subnode, verbose)

            ## access processing
            access_expand(tree, subnode, verbose)

            subnode.sync()

        domain_count += 1

    return True
示例#3
0
def subsystem_generate( tgt_node, sdt, verbose = 0):
    if verbose:
        print( "[INFO]: cb: subsystem_generate( %s, %s )" % (tgt_node, sdt))

    tree = sdt.tree
    domain_tree = LopperTree()

    try:
        domain_node = tree["/domains"]
    except:
        domain_node = LopperNode( -1, "/domains" )

    domain_tree.__dbg__ = 4
    domain_tree = domain_tree + domain_node

    subsystem_node = LopperNode( -1 )
    subsystem_node.name = "subsystem1"

    domain_node + subsystem_node

    cpu_prop = None
    for node in sdt.tree:
        try:
            compatibility = node['compatible']
        except:
            compatibility = None

        if compatibility:
            cpu_compat = re.findall(r"(?=("+'|'.join(compatibility.value)+r"))", "cpus,cluster")
            if cpu_compat:
                if not cpu_prop:
                    # Note: The "mask" and "secure" entries are currently placeholders and will be
                    #       calculated differently in the future.
                    cpu_prop = LopperProp( "cpus", -1, subsystem_node,
                                           [ json.dumps( { 'cluster': node.label, "cpu_mask" : 0x3, "mode": { 'secure': True } }) ])
                    cpu_prop.pclass = "json"
                    subsystem_node = subsystem_node + cpu_prop
                else:
                    cpu_prop.value.append( json.dumps( { 'cluster': node.label, "cpu_mask" : 0x3, "mode": { 'secure': True } } ) )

    if verbose > 3:
        tree.__dbg__ = 4

    tree = tree + domain_node

    if verbose > 2:
        print( "[DBG++]: dumping yaml generated default subystem" )
        yaml = LopperYAML( None, domain_tree )
        yaml.to_yaml()

    return True
示例#4
0
    def to_tree(self):
        """ Export LopperYAML to a LopperTree

        Args:
           None

        Returns:
          LopperTree object representation of YAML object
        """
        if not self.anytree:
            print("[ERROR]: cannot export tree, nothing is loaded")
            return None

        lt = LopperTreePrinter()

        excluded_props = ["name", "fdt_name"]

        for node in PreOrderIter(self.anytree):
            if node.name == "root":
                ln = lt["/"]
            else:
                ln = LopperNode(-1, node.name)
                ln.abs_path = self.path(node)

            props = self.props(node)
            lt = lt + ln

            for p in props:
                if type(props[p]) == list:
                    lp = LopperProp(p, -1, ln, props[p])
                    ln + lp
                if type(props[p]) == bool:
                    if props[p]:
                        lp = LopperProp(p, -1, ln, [])
                        ln + lp
                    else:
                        print("[INFO]: not encoding false boolean type: %s" %
                              p)
                else:
                    if not p in excluded_props:
                        lp = LopperProp(p, -1, ln, props[p])
                        ln + lp

        lt.resolve()
        lt.sync()

        return lt
示例#5
0
    def to_tree(self):
        """ Export LopperYAML to a LopperTree

        Args:
           None

        Returns:
          LopperTree object representation of YAML object
        """
        if not self.anytree:
            print("[ERROR]: cannot export tree, nothing is loaded")
            return None

        lt = LopperTreePrinter()

        excluded_props = ["name", "fdt_name"]
        serialize_json = True
        verbose = 0

        for node in PreOrderIter(self.anytree):
            if node.name == "root":
                ln = lt["/"]
                #ln = LopperNode( -1, None )
                #ln.abs_path = "/"
            else:
                ln = LopperNode(-1, node.name)
                ln.abs_path = self.path(node)

            if verbose:
                lt.__dbg__ = 4
                ln.__dbg__ = 4

            ln._source = "yaml"

            # add the node to the tree
            lt = lt + ln

            props = self.props(node)
            for p in props:
                if verbose:
                    print("[DBG+]: prop: %s (%s)" % (p, props[p]))
                if serialize_json:
                    use_json = False
                    skip = False
                    if type(props[p]) == list:
                        for p2 in props[p]:
                            if type(p2) == list or type(p2) == dict:
                                use_json = True
                    elif type(props[p]) == dict:
                        for p2 in props[p].values():
                            if type(p2) == list or type(p2) == dict:
                                use_json = True
                    elif type(props[p]) == bool:
                        # don't encode false bool, and a true is just an empty list
                        if props[p]:
                            if self.boolean_as_int:
                                props[p] = [1]
                            else:
                                props[p] = None
                        else:
                            if self.boolean_as_int:
                                props[p] = [0]
                            else:
                                skip = True

                    if use_json:
                        x = json.dumps(props[p])
                    else:
                        x = props[p]

                    if not skip:
                        if not p in excluded_props:
                            lp = LopperProp(p, -1, ln, x)
                            lp.resolve()
                            if use_json:
                                lp.pclass = "json"
                            # add the property to the node
                            ln + lp
                else:
                    if type(props[p]) == list:
                        # we need to check if there are embedded dictionaries, and if so, expand them.
                        # since a dictionary doesn't map directly to device tree output.
                        prop_list = self.prop_expand(props[p])
                        lp = LopperProp(p, -1, ln, prop_list)
                        lp.resolve()
                        ln + lp
                    elif type(props[p]) == bool:
                        if props[p]:
                            lp = LopperProp(p, -1, ln, [])
                            lp.resolve()
                            # add the prop the node
                            ln + lp
                        else:
                            print(
                                "[INFO]: not encoding false boolean type: %s" %
                                p)
                    elif type(props[p]) == dict:
                        # we need to check if there are embedded dictionaries, and if so, expand them.
                        # since a dictionary doesn't map directly to device tree output.
                        prop_list = self.prop_expand(props[p])
                        lp = LopperProp(p, -1, ln, prop_list)
                        lp.resolve()
                        ln + lp
                    else:
                        if not p in excluded_props:
                            lp = LopperProp(p, -1, ln, props[p])
                            lp.resolve()
                            ln + lp

        lt.resolve()
        lt.sync()

        return lt