def __init__(self, section, etype, node): super().__init__(section, etype, node) self.algo_name = fdt_util.GetString(self._node, 'algo-name') self.padding_name = fdt_util.GetString(self._node, 'padding-name') self.key_name = fdt_util.GetString(self._node, 'key-name') self.header_size = fdt_util.GetInt(self._node, 'header-size') self.version = fdt_util.GetInt(self._node, 'version')
def ReadNode(self): """Read properties from the section node""" super().ReadNode() 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') self.align_default = fdt_util.GetInt(self._node, 'align-default', 0) filename = fdt_util.GetString(self._node, 'filename') if filename: self._filename = filename self._ReadEntries()
def ReadEntries(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.ReadNode() entry._ifwi_replace = fdt_util.GetBool(node, 'ifwi-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
def ReadNode(self): super().ReadNode() self._pattern = fdt_util.GetString(self._node, 'pattern') if not self._pattern: self.Raise("Missing 'pattern' property") self._files_compress = fdt_util.GetString(self._node, 'files-compress', 'none') self._files_align = fdt_util.GetInt(self._node, 'files-align') self._require_matches = fdt_util.GetBool(self._node, 'require-matches')
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))
def __init__(self, section, etype, node): # Put this here to allow entry-docs and help to work without libfdt global state from binman import state super().__init__(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')
def ReadNode(self): super().ReadNode() self.return_invalid_entry = fdt_util.GetBool(self._node, 'return-invalid-entry') self.return_unknown_contents = fdt_util.GetBool( self._node, 'return-unknown-contents') self.bad_update_contents = fdt_util.GetBool(self._node, 'bad-update-contents') self.bad_shrink_contents = fdt_util.GetBool(self._node, 'bad-shrink-contents') self.return_contents_once = fdt_util.GetBool(self._node, 'return-contents-once') self.bad_update_contents_twice = fdt_util.GetBool( self._node, 'bad-update-contents-twice') self.return_contents_later = fdt_util.GetBool(self._node, 'return-contents-later') # Set to True when the entry is ready to process the FDT. self.process_fdt_ready = False self.never_complete_process_fdt = fdt_util.GetBool( self._node, 'never-complete-process-fdt') self.require_args = fdt_util.GetBool(self._node, 'require-args') # This should be picked up by GetEntryArgsOrProps() self.test_existing_prop = 'existing' self.force_bad_datatype = fdt_util.GetBool(self._node, 'force-bad-datatype') (self.test_str_fdt, self.test_str_arg, self.test_int_fdt, self.test_int_arg, existing) = self.GetEntryArgsOrProps([ EntryArg('test-str-fdt', str), EntryArg('test-str-arg', str), EntryArg('test-int-fdt', int), EntryArg('test-int-arg', int), EntryArg('test-existing-prop', str) ], self.require_args) if self.force_bad_datatype: self.GetEntryArgsOrProps([EntryArg('test-bad-datatype-arg', bool)]) self.return_contents = True self.contents = b'aa' # Set to the required bintool when collecting bintools. self.bintool_for_contents = None self.require_bintool_for_contents = fdt_util.GetString( self._node, 'require-bintool-for-contents') if self.require_bintool_for_contents == '': self.require_bintool_for_contents = '_testing' self.bintool_for_pack = None self.require_bintool_for_pack = fdt_util.GetString( self._node, 'require-bintool-for-pack') if self.require_bintool_for_pack == '': self.require_bintool_for_pack = '_testing'
def ReadEntries(self): """Read the subnodes to find out what should go in this CBFS""" for node in self._node.subnodes: entry = Entry.Create(self, node) entry.ReadNode() 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._entries[entry._cbfs_name] = entry
def Create(section, node, etype=None, expanded=False, missing_etype=False): """Create a new entry for a node. Args: section (entry_Section): Section object containing this node node (Node): Node object containing information about the entry to create etype (str): Entry type to use, or None to work it out (used for tests) expanded (bool): Use the expanded version of etype missing_etype (bool): True to default to a blob etype if the requested etype is not found 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, expanded, missing_etype) if obj and expanded: # Check whether to use the expanded entry new_etype = etype + '-expanded' can_expand = not fdt_util.GetBool(node, 'no-expanded') if can_expand and obj.UseExpanded(node, etype, new_etype): etype = new_etype else: obj = None if not obj: obj = Entry.Lookup(node.path, etype, False, missing_etype) # Call its constructor to get the object we want. return obj(section, etype, node)
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)
def ReadNode(self): """Read entry information from the node This must be called as the first thing after the Entry is created. This reads all the fields we recognise from the node, ready for use. """ if 'pos' in self._node.props: self.Raise("Please use 'offset' instead of 'pos'") if 'expand-size' in self._node.props: self.Raise("Please use 'extend-size' instead of 'expand-size'") self.offset = fdt_util.GetInt(self._node, 'offset') self.size = fdt_util.GetInt(self._node, 'size') self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset') self.orig_size = fdt_util.GetInt(self._node, 'orig-size') if self.GetImage().copy_to_orig: self.orig_offset = self.offset self.orig_size = self.size # These should not be set in input files, but are set in an FDT map, # which is also read by this code. self.image_pos = fdt_util.GetInt(self._node, 'image-pos') self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size') self.align = fdt_util.GetInt(self._node, 'align') if tools.not_power_of_two(self.align): raise ValueError("Node '%s': Alignment %s must be a power of two" % (self._node.path, self.align)) if self.section and self.align is None: self.align = self.section.align_default self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0) self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0) self.align_size = fdt_util.GetInt(self._node, 'align-size') if tools.not_power_of_two(self.align_size): self.Raise("Alignment size %s must be a power of two" % self.align_size) self.align_end = fdt_util.GetInt(self._node, 'align-end') self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset') self.extend_size = fdt_util.GetBool(self._node, 'extend-size') self.missing_msg = fdt_util.GetString(self._node, 'missing-msg') # This is only supported by blobs and sections at present self.compress = fdt_util.GetString(self._node, 'compress', 'none')
def __init__(self, section, etype, node): # Put this here to allow entry-docs and help to work without libfdt global state from binman import state super().__init__(section, etype, node) self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86') self._cbfs_entries = OrderedDict() self._ReadSubnodes() self.reader = None
def __init__(self, section, etype, node): super().__init__(section, etype, node) value = fdt_util.GetString(self._node, 'text') if value: value = tools.to_bytes(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.to_bytes(value) if value is not None else value self.value = value
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.read_file(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.get_output_filename('fdtmap.in.dtb') tools.write_file(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, ignore_missing=True, missing_etype=True, generate=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
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)
def ReadEntries(self): """Read the subnodes to find out what should go in this FIP""" for node in self._node.subnodes: fip_type = None etype = None if node.name in FIP_TYPES: fip_type = node.name etype = 'blob-ext' entry = Entry.Create(self, node, etype) entry._fip_uuid = fdt_util.GetBytes(node, 'fip-uuid', UUID_LEN) if not fip_type and not entry._fip_uuid: fip_type = fdt_util.GetString(node, 'fip-type') if not fip_type: self.Raise( "Must provide a fip-type (node name '%s' is not a known FIP type)" % node.name) entry._fip_type = fip_type entry._fip_flags = fdt_util.GetInt64(node, 'fip-flags', 0) entry.ReadNode() entry._fip_name = node.name self._entries[entry._fip_name] = entry
def __init__(self, section, etype, node): super().__init__(section, etype, node) self._args = fdt_util.GetString(self._node, 'args').split(' ') self._mkimage_entries = OrderedDict() self.align_default = None self.ReadEntries()
def ReadNode(self): super().ReadNode() filename = fdt_util.GetString(self._node, 'filename') if filename: self._filename = filename self.allow_repack = fdt_util.GetBool(self._node, 'allow-repack')
def ReadNode(self): """Read properties from the atf-fip node""" super().ReadNode() self._cbfs_arg = fdt_util.GetString(self._node, 'cbfs-arch', 'x86') self.ReadEntries()
def __init__(self, section, etype, node): super().__init__(section, etype, node) self._filename = fdt_util.GetString(self._node, 'filename', self.etype)
def __init__(self, section, etype, node): Entry.__init__(self, section, etype, node) self.location = fdt_util.GetString(self._node, 'location')
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')
def __init__(self, section, etype, node): super().__init__(section, etype, node) self._args = fdt_util.GetString(self._node, 'args').split(' ') self._mkimage_entries = OrderedDict() self._ReadSubnodes()