How to use the esptool.LoadFirmwareImage function in esptool

To help you get started, we’ve selected a few esptool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github espressif / esptool / test / test_imagegen.py View on Github external
def test_loaded_sections(self):
        image = esptool.LoadFirmwareImage("esp8266", self.BIN_LOAD)
        self.assertEqual(3, len(image.segments))
        self.assertImageContainsSection(image, self.ELF, ".data")
        self.assertImageContainsSection(image, self.ELF, ".text")
        self.assertImageContainsSection(image, self.ELF, ".rodata")
github espressif / esptool / test / test_imagegen.py View on Github external
def _test_elf2image(self, elfpath, binpath):
        try:
            self.run_elf2image("esp32", elfpath)
            image = esptool.LoadFirmwareImage("esp32", binpath)
            self.assertImageInfo(binpath, "esp32")
            return image
        finally:
            try_delete(binpath)
github espressif / esptool / test / test_imagegen.py View on Github external
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()
github espressif / esptool / test / test_imagegen.py View on Github external
def test_elf_section_header_not_at_end(self):
        self.run_elf2image("esp8266", self.ELF)
        image = esptool.LoadFirmwareImage("esp8266", self.BIN_LOAD)
        self.assertEqual(3, len(image.segments))
        self.assertImageContainsSection(image, self.ELF, ".data")
        self.assertImageContainsSection(image, self.ELF, ".text")
        self.assertImageContainsSection(image, self.ELF, ".rodata")
github espressif / esptool / test / test_imagegen.py View on Github external
def test_binary_patched(self):
        self.run_elf2image("esp32", self.ELF, extra_args=["--elf-sha256-offset", "0x%x" % self.SHA_OFFS])
        image = esptool.LoadFirmwareImage("esp32", self.BIN)
        rodata_segment = image.segments[0]
        observed_sha256 = rodata_segment.data[self.SHA_OFFS-0x20:self.SHA_OFFS-0x20+32] # subtract 0x20 byte header here

        sha256 = hashlib.sha256()
        with open(self.ELF, "rb") as f:
            expected_sha256 = hashlib.sha256(f.read()).digest()

        self.assertSequenceEqual(expected_sha256, observed_sha256)