def _test_elf2image(self, elfpath, binpath): try: self.run_elf2image("esp8266", elfpath, 2) image = esptool.LoadFirmwareImage("esp8266", binpath) self.assertEqual(4, len(image.segments)) self.assertImageContainsSection(image, elfpath, ".data") self.assertImageContainsSection(image, elfpath, ".text") self.assertImageContainsSection(image, elfpath, ".rodata") irom_segment = image.segments[0] self.assertEqual(0, irom_segment.addr, "IROM segment 'load address' should be zero") with open(elfpath, "rb") as f: e = ELFFile(f) sh_size = (e.get_section_by_name(".irom0.text").header.sh_size + 15) & ~15 self.assertEqual( len(irom_segment.data), sh_size, "irom segment (0x%x) should be same size (16 padded) as .irom0.text section (0x%x)" % (len(irom_segment.data), sh_size)) # check V2 CRC (for ESP8266 SDK bootloader) with open(binpath, "rb") as f: f.seek(-4, os.SEEK_END) image_len = f.tell() crc_stored = struct.unpack("<I", f.read(4))[0] f.seek(0) crc_calc = esptool.esp8266_crc32(f.read(image_len)) self.assertEqual(crc_stored, crc_calc) # test imageinfo doesn't fail self.assertImageInfo(binpath) finally: try_delete(binpath)
def _test_elf2image(self, elfpath, binpath): try: self.run_elf2image("esp8266", elfpath, 2) image = esptool.LoadFirmwareImage("esp8266", binpath) self.assertEqual(4, len(image.segments)) self.assertImageContainsSection(image, elfpath, ".data") self.assertImageContainsSection(image, elfpath, ".text") self.assertImageContainsSection(image, elfpath, ".rodata") irom_segment = image.segments[0] self.assertEqual(0, irom_segment.addr, "IROM segment 'load address' should be zero") with open(elfpath, "rb") as f: e = ELFFile(f) sh_size = (e.get_section_by_name(".irom0.text").header.sh_size + 15) & ~15 self.assertEqual(len(irom_segment.data), sh_size, "irom segment (0x%x) should be same size (16 padded) as .irom0.text section (0x%x)" % (len(irom_segment.data), sh_size)) # check V2 CRC (for ESP8266 SDK bootloader) with open(binpath, "rb") as f: f.seek(-4, os.SEEK_END) image_len = f.tell() crc_stored = struct.unpack("<I", f.read(4))[0] f.seek(0) crc_calc = esptool.esp8266_crc32(f.read(image_len)) self.assertEqual(crc_stored, crc_calc) # test imageinfo doesn't fail self.assertImageInfo(binpath) finally: try_delete(binpath)