Esempio n. 1
0
    def test_update_bootloader_params(self):
        merged = self.run_merge_bin(
            "esp32", [(0x1000, "bootloader_esp32.bin"),
                      (0x10000, "ram_helloworld/helloworld-esp32.bin")],
            ["--flash_size", "2MB", "--flash_mode", "dout"])
        self.assertAllFF(merged[:0x1000])

        bootloader = read_image("bootloader_esp32.bin")
        helloworld = read_image("ram_helloworld/helloworld-esp32.bin")

        # test the bootloader is unchanged apart from the header (updating the header doesn't change CRC,
        # and doesn't update the SHA although it will invalidate it!)
        self.assertEqual(merged[0x1010:0x1000 + len(bootloader)],
                         bootloader[0x10:])

        # check the individual bytes in the header are as expected
        merged_hdr = merged[0x1000:0x1010]
        bootloader_hdr = bootloader[:0x10]
        self.assertEqual(bootloader_hdr[:2], merged_hdr[:2])
        self.assertEqual(3, byte(merged_hdr, 2))  # flash mode dout
        self.assertEqual(0x10,
                         byte(merged_hdr, 3) & 0xF0)  # flash size 2MB (ESP32)
        self.assertEqual(
            byte(bootloader_hdr, 3) & 0x0F,
            byte(merged_hdr, 3) & 0x0F)  # flash speed is unchanged
        self.assertEqual(bootloader_hdr[4:],
                         merged_hdr[4:])  # remaining field are unchanged

        # check all the padding is as expected
        self.assertAllFF(merged[0x1000 + len(bootloader):0x10000])
        self.assertEqual(merged[0x10000:0x10000 + len(helloworld)], helloworld)
Esempio n. 2
0
 def check_format(self, new_value_str):
     if new_value_str is None:
         raise esptool.FatalError("Required MAC Address in AA:CD:EF:01:02:03 format!")
     if new_value_str.count(":") != 5:
         raise esptool.FatalError("MAC Address needs to be a 6-byte hexadecimal format separated by colons (:)!")
     hexad = new_value_str.replace(":", "")
     if len(hexad) != 12:
         raise esptool.FatalError("MAC Address needs to be a 6-byte hexadecimal number (12 hexadecimal characters)!")
     # order of bytearray = b'\xaa\xcd\xef\x01\x02\x03',
     bindata = binascii.unhexlify(hexad)
     # unicast address check according to https://tools.ietf.org/html/rfc7042#section-2.1
     if esptool.byte(bindata, 0) & 0x01:
         raise esptool.FatalError("Custom MAC must be a unicast MAC!")
     return bindata