def test_read_segments_fail(self): """Test for read_loadable_segments() without elftools""" try: old_val = elf.ELF_TOOLS elf.ELF_TOOLS = False fname = self.ElfTestFile('embed_data') with self.assertRaises(ValueError) as e: elf.read_loadable_segments(tools.read_file(fname)) self.assertIn("Python: No module named 'elftools'", str(e.exception)) finally: elf.ELF_TOOLS = old_val
def _gen_split_elf(base_node, node, elf_data, missing): """Add nodes for the ELF file, one per group of contiguous segments Args: base_node (Node): Template node from the binman definition node (Node): Node to replace (in the FIT being built) data (bytes): ELF-format data to process (may be empty) missing (bool): True if any of the data is missing """ # If any pieces are missing, skip this. The missing entries will # show an error if not missing: try: segments, entry = elf.read_loadable_segments(elf_data) except ValueError as exc: self._raise_subnode( node, f'Failed to read ELF file: {str(exc)}') for (seq, start, data) in segments: node_name = node.name[1:].replace('SEQ', str(seq + 1)) with fsw.add_node(node_name): loadables.append(node_name) for pname, prop in node.props.items(): if not pname.startswith('fit,'): fsw.property(pname, prop.bytes) elif pname == 'fit,load': fsw.property_u32('load', start) elif pname == 'fit,entry': if seq == 0: fsw.property_u32('entry', entry) elif pname == 'fit,data': fsw.property('data', bytes(data)) elif pname != 'fit,operation': self._raise_subnode( node, f"Unknown directive '{pname}'")
def test_read_segments_bad_data(self): """Test for read_loadable_segments() with an invalid ELF file""" fname = self.ElfTestFile('embed_data') with self.assertRaises(ValueError) as e: elf.read_loadable_segments(tools.get_bytes(100, 100)) self.assertIn('Magic number does not match', str(e.exception))
def test_read_loadable_segments(self): """Test for read_loadable_segments()""" if not elf.ELF_TOOLS: self.skipTest('Python elftools not available') fname = self.ElfTestFile('embed_data') segments, entry = elf.read_loadable_segments(tools.read_file(fname))