def test_cbfs_stage(self): """Tests handling of a Coreboot Filesystem (CBFS)""" if not elf.ELF_TOOLS: self.skipTest('Python elftools not available') elf_fname = os.path.join(self._indir, 'cbfs-stage.elf') elf.MakeElf(elf_fname, U_BOOT_DATA, U_BOOT_DTB_DATA) size = 0xb0 cbw = CbfsWriter(size) cbw.add_file_stage('u-boot', tools.ReadFile(elf_fname)) data = cbw.get_data() cbfs = self._check_hdr(data, size) load = 0xfef20000 entry = load + 2 cfile = self._check_uboot(cbfs, cbfs_util.TYPE_STAGE, offset=0x28, data=U_BOOT_DATA + U_BOOT_DTB_DATA) self.assertEqual(entry, cfile.entry) self.assertEqual(load, cfile.load) self.assertEqual( len(U_BOOT_DATA) + len(U_BOOT_DTB_DATA), cfile.data_len) # Compare against what cbfstool creates if self.have_cbfstool: cbfs_fname = os.path.join(self._indir, 'test.cbfs') cbfs_util.cbfstool(cbfs_fname, 'create', '-m', 'x86', '-s', '%#x' % size) cbfs_util.cbfstool(cbfs_fname, 'add-stage', '-n', 'u-boot', '-f', elf_fname) self._compare_expected_cbfs(data, cbfs_fname)
def ObtainContents(self, skip=None): arch = cbfs_util.find_arch(self._cbfs_arg) if arch is None: self.Raise("Invalid architecture '%s'" % self._cbfs_arg) if self.size is None: self.Raise("'cbfs' entry must have a size property") cbfs = CbfsWriter(self.size, arch) for entry in self._cbfs_entries.values(): # First get the input data and put it in a file. If not available, # try later. if entry != skip and not entry.ObtainContents(): return False data = entry.GetData() cfile = None if entry._type == 'raw': cfile = cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_offset, entry._cbfs_compress) elif entry._type == 'stage': cfile = cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset) else: entry.Raise("Unknown cbfs-type '%s' (use 'raw', 'stage')" % entry._type) if cfile: entry._cbfs_file = cfile data = cbfs.get_data() self.SetContents(data) return True