Exemplo n.º 1
0
 def __init__(self, section, etype, node):
     Entry_section.__init__(self, section, etype, node)
     self._pattern = fdt_util.GetString(self._node, 'pattern')
     if not self._pattern:
         self.Raise("Missing 'pattern' property")
     self._compress = fdt_util.GetString(self._node, 'compress', 'none')
     self._require_matches = fdt_util.GetBool(self._node, 'require-matches')
Exemplo n.º 2
0
 def _ReadSubnodes(self):
     """Read the subnodes to find out what should go in this IFWI"""
     for node in self._node.subnodes:
         entry = Entry.Create(self.section, node)
         entry._ifwi_replace = fdt_util.GetBool(node, 'replace')
         entry._ifwi_subpart = fdt_util.GetString(node, 'ifwi-subpart')
         entry._ifwi_entry_name = fdt_util.GetString(node, 'ifwi-entry')
         self._ifwi_entries[entry._ifwi_subpart] = entry
Exemplo n.º 3
0
    def testGetString(self):
        self.assertEqual('message', fdt_util.GetString(self.node, 'stringval'))
        self.assertEqual('test', fdt_util.GetString(self.node, 'missing',
                                                    'test'))

        with self.assertRaises(ValueError) as e:
            self.assertEqual(3, fdt_util.GetString(self.node, 'stringarray'))
        self.assertIn("property 'stringarray' has list value: expecting a "
                      'single string', str(e.exception))
Exemplo n.º 4
0
    def __init__(self, section, etype, node):
        # Put this here to allow entry-docs and help to work without libfdt
        global state
        import state

        Entry_section.__init__(self, section, etype, node)
        self._pattern = fdt_util.GetString(self._node, 'pattern')
        if not self._pattern:
            self.Raise("Missing 'pattern' property")
        self._compress = fdt_util.GetString(self._node, 'compress', 'none')
        self._require_matches = fdt_util.GetBool(self._node, 'require-matches')
Exemplo n.º 5
0
 def _ReadSubnodes(self):
     """Read the subnodes to find out what should go in this IFWI"""
     for node in self._node.subnodes:
         entry = Entry.Create(self.section, node)
         entry._cbfs_name = fdt_util.GetString(node, 'cbfs-name', entry.name)
         entry._type = fdt_util.GetString(node, 'cbfs-type')
         compress = fdt_util.GetString(node, 'cbfs-compress', 'none')
         entry._cbfs_offset = fdt_util.GetInt(node, 'cbfs-offset')
         entry._cbfs_compress = cbfs_util.find_compress(compress)
         if entry._cbfs_compress is None:
             self.Raise("Invalid compression in '%s': '%s'" %
                        (node.name, compress))
         self._cbfs_entries[entry._cbfs_name] = entry
Exemplo n.º 6
0
    def Create(image, node, etype=None):
        """Create a new entry for a node.

        Args:
            image:  Image object containing this node
            node:   Node object containing information about the entry to create
            etype:  Entry type to use, or None to work it out (used for tests)

        Returns:
            A new Entry object of the correct type (a subclass of Entry)
        """
        if not etype:
            etype = fdt_util.GetString(node, 'type', node.name)
        module_name = etype.replace('-', '_')
        module = modules.get(module_name)

        # Import the module if we have not already done so.
        if not module:
            try:
                if have_importlib:
                    module = importlib.import_module(module_name)
                else:
                    module = __import__(module_name)
            except ImportError:
                raise ValueError("Unknown entry type '%s' in node '%s'" %
                                 (etype, node.path))
            modules[module_name] = module

        # Call its constructor to get the object we want.
        obj = getattr(module, 'Entry_%s' % module_name)
        return obj(image, etype, node)
Exemplo n.º 7
0
 def _ReadNode(self):
     """Read properties from the image node"""
     self._size = fdt_util.GetInt(self._node, 'size')
     filename = fdt_util.GetString(self._node, 'filename')
     if filename:
         self._filename = filename
     self._section = bsection.Section('main-section', self._node)
Exemplo n.º 8
0
 def _ReadNode(self):
     """Read properties from the section node"""
     self._offset = fdt_util.GetInt(self._node, 'offset')
     self._size = fdt_util.GetInt(self._node, 'size')
     self._align_size = fdt_util.GetInt(self._node, 'align-size')
     if tools.NotPowerOfTwo(self._align_size):
         self._Raise("Alignment size %s must be a power of two" %
                     self._align_size)
     self._pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
     self._pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
     self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0)
     self._sort = fdt_util.GetBool(self._node, 'sort-by-offset')
     self._end_4gb = fdt_util.GetBool(self._node, 'end-at-4gb')
     self._skip_at_start = fdt_util.GetInt(self._node, 'skip-at-start')
     if self._end_4gb:
         if not self._size:
             self._Raise("Section size must be provided when using end-at-4gb")
         if self._skip_at_start is not None:
             self._Raise("Provide either 'end-at-4gb' or 'skip-at-start'")
         else:
             self._skip_at_start = 0x100000000 - self._size
     else:
         if self._skip_at_start is None:
             self._skip_at_start = 0
     self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
Exemplo n.º 9
0
    def testFdtNormalProp(self):
        fname = self.GetCompiled('045_prop_test.dts')
        dt = FdtScan(fname)
        node = dt.GetNode('/binman/intel-me')
        self.assertEquals('intel-me', node.name)
        val = fdt_util.GetString(node, 'filename')
        self.assertEquals(str, type(val))
        self.assertEquals('me.bin', val)

        prop = node.props['intval']
        self.assertEquals(fdt.TYPE_INT, prop.type)
        self.assertEquals(3, fdt_util.GetInt(node, 'intval'))

        prop = node.props['intarray']
        self.assertEquals(fdt.TYPE_INT, prop.type)
        self.assertEquals(list, type(prop.value))
        self.assertEquals(2, len(prop.value))
        self.assertEquals([5, 6],
                          [fdt_util.fdt32_to_cpu(val) for val in prop.value])

        prop = node.props['byteval']
        self.assertEquals(fdt.TYPE_BYTE, prop.type)
        self.assertEquals(chr(8), prop.value)

        prop = node.props['bytearray']
        self.assertEquals(fdt.TYPE_BYTE, prop.type)
        self.assertEquals(list, type(prop.value))
        self.assertEquals(str, type(prop.value[0]))
        self.assertEquals(3, len(prop.value))
        self.assertEquals([chr(1), '#', '4'], prop.value)

        prop = node.props['longbytearray']
        self.assertEquals(fdt.TYPE_INT, prop.type)
        self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))

        prop = node.props['stringval']
        self.assertEquals(fdt.TYPE_STRING, prop.type)
        self.assertEquals('message2', fdt_util.GetString(node, 'stringval'))

        prop = node.props['stringarray']
        self.assertEquals(fdt.TYPE_STRING, prop.type)
        self.assertEquals(list, type(prop.value))
        self.assertEquals(3, len(prop.value))
        self.assertEquals(['another', 'multi-word', 'message'], prop.value)
Exemplo n.º 10
0
    def __init__(self, section, etype, node):
        # Put this here to allow entry-docs and help to work without libfdt
        global state
        import state

        Entry.__init__(self, section, etype, node)
        self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
        self._cbfs_entries = OrderedDict()
        self._ReadSubnodes()
        self.reader = None
Exemplo n.º 11
0
 def __init__(self, name, node, test=False):
     self.image = self
     section.Entry_section.__init__(self, None, 'section', node, test)
     self.name = 'main-section'
     self.image_name = name
     self._filename = '%s.bin' % self.image_name
     if not test:
         filename = fdt_util.GetString(self._node, 'filename')
         if filename:
             self._filename = filename
Exemplo n.º 12
0
 def _ReadNode(self):
     """Read properties from the image node"""
     self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0)
     self._sort = fdt_util.GetBool(self._node, 'sort-by-offset')
     self._end_4gb = fdt_util.GetBool(self._node, 'end-at-4gb')
     self._skip_at_start = fdt_util.GetInt(self._node, 'skip-at-start')
     if self._end_4gb:
         if not self.size:
             self.Raise(
                 "Section size must be provided when using end-at-4gb")
         if self._skip_at_start is not None:
             self.Raise("Provide either 'end-at-4gb' or 'skip-at-start'")
         else:
             self._skip_at_start = 0x100000000 - self.size
     else:
         if self._skip_at_start is None:
             self._skip_at_start = 0
     self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
     filename = fdt_util.GetString(self._node, 'filename')
     if filename:
         self._filename = filename
Exemplo n.º 13
0
 def __init__(self, section, etype, node):
     Entry.__init__(self, section, etype, node)
     value = fdt_util.GetString(self._node, 'text')
     if value:
         value = tools.ToBytes(value)
     else:
         label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
         self.text_label = label
         if self.text_label:
             value, = self.GetEntryArgsOrProps([EntryArg(self.text_label,
                                                         str)])
             value = tools.ToBytes(value) if value is not None else value
     self.value = value
Exemplo n.º 14
0
    def FromFile(cls, fname):
        """Convert an image file into an Image for use in binman

        Args:
            fname: Filename of image file to read

        Returns:
            Image object on success

        Raises:
            ValueError if something goes wrong
        """
        data = tools.ReadFile(fname)
        size = len(data)

        # First look for an image header
        pos = image_header.LocateHeaderOffset(data)
        if pos is None:
            # Look for the FDT map
            pos = fdtmap.LocateFdtmap(data)
        if pos is None:
            raise ValueError('Cannot find FDT map in image')

        # We don't know the FDT size, so check its header first
        probe_dtb = fdt.Fdt.FromData(
            data[pos + fdtmap.FDTMAP_HDR_LEN:pos + 256])
        dtb_size = probe_dtb.GetFdtObj().totalsize()
        fdtmap_data = data[pos:pos + dtb_size + fdtmap.FDTMAP_HDR_LEN]
        fdt_data = fdtmap_data[fdtmap.FDTMAP_HDR_LEN:]
        out_fname = tools.GetOutputFilename('fdtmap.in.dtb')
        tools.WriteFile(out_fname, fdt_data)
        dtb = fdt.Fdt(out_fname)
        dtb.Scan()

        # Return an Image with the associated nodes
        root = dtb.GetRoot()
        image = Image('image', root, copy_to_orig=False)

        image.image_node = fdt_util.GetString(root, 'image-node', 'image')
        image.fdtmap_dtb = dtb
        image.fdtmap_data = fdtmap_data
        image._data = data
        image._filename = fname
        image.image_name, _ = os.path.splitext(fname)
        return image
Exemplo n.º 15
0
    def Create(section, node, etype=None):
        """Create a new entry for a node.

        Args:
            section: Section object containing this node
            node:    Node object containing information about the entry to
                     create
            etype:   Entry type to use, or None to work it out (used for tests)

        Returns:
            A new Entry object of the correct type (a subclass of Entry)
        """
        if not etype:
            etype = fdt_util.GetString(node, 'type', node.name)
        obj = Entry.Lookup(node.path, etype)

        # Call its constructor to get the object we want.
        return obj(section, etype, node)
Exemplo n.º 16
0
 def _ReadNode(self):
     """Read properties from the image node"""
     self._size = fdt_util.GetInt(self._node, 'size')
     self._align_size = fdt_util.GetInt(self._node, 'align-size')
     if tools.NotPowerOfTwo(self._align_size):
         self._Raise("Alignment size %s must be a power of two" %
                     self._align_size)
     self._pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
     self._pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
     self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0)
     filename = fdt_util.GetString(self._node, 'filename')
     if filename:
         self._filename = filename
     self._sort = fdt_util.GetBool(self._node, 'sort-by-pos')
     self._end_4gb = fdt_util.GetBool(self._node, 'end-at-4gb')
     if self._end_4gb and not self._size:
         self._Raise("Image size must be provided when using end-at-4gb")
     if self._end_4gb:
         self._skip_at_start = 0x100000000 - self._size
Exemplo n.º 17
0
    def Create(section, node, etype=None):
        """Create a new entry for a node.

        Args:
            section:  Image object containing this node
            node:   Node object containing information about the entry to create
            etype:  Entry type to use, or None to work it out (used for tests)

        Returns:
            A new Entry object of the correct type (a subclass of Entry)
        """
        if not etype:
            etype = fdt_util.GetString(node, 'type', node.name)

        # Convert something like 'u-boot@0' to 'u_boot' since we are only
        # interested in the type.
        module_name = etype.replace('-', '_')
        if '@' in module_name:
            module_name = module_name.split('@')[0]
        module = modules.get(module_name)

        # Also allow entry-type modules to be brought in from the etype directory.

        # Import the module if we have not already done so.
        if not module:
            old_path = sys.path
            sys.path.insert(0, os.path.join(our_path, 'etype'))
            try:
                if have_importlib:
                    module = importlib.import_module(module_name)
                else:
                    module = __import__(module_name)
            except ImportError:
                raise ValueError("Unknown entry type '%s' in node '%s'" %
                                 (etype, node.path))
            finally:
                sys.path = old_path
            modules[module_name] = module

        # Call its constructor to get the object we want.
        obj = getattr(module, 'Entry_%s' % module_name)
        return obj(section, etype, node)
Exemplo n.º 18
0
 def __init__(self, section, etype, node):
     Entry.__init__(self, section, etype, node)
     self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
     self._cbfs_entries = OrderedDict()
     self._ReadSubnodes()
     self.reader = None
Exemplo n.º 19
0
 def ReadNode(self):
     section.Entry_section.ReadNode(self)
     filename = fdt_util.GetString(self._node, 'filename')
     if filename:
         self._filename = filename
     self.allow_repack = fdt_util.GetBool(self._node, 'allow-repack')
Exemplo n.º 20
0
 def __init__(self, section, etype, node):
     Entry.__init__(self, section, etype, node)
     self._filename = fdt_util.GetString(self._node, "filename", self.etype)
Exemplo n.º 21
0
 def __init__(self, section, etype, node):
     Entry.__init__(self, section, etype, node)
     self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
     self.compress = fdt_util.GetString(self._node, 'compress', 'none')
Exemplo n.º 22
0
 def __init__(self, section, etype, node):
     Entry.__init__(self, section, etype, node)
     self.location = fdt_util.GetString(self._node, 'location')