Beispiel #1
0
    def __init__(self, _debug=True):
        self.debug = _debug
        self.update_file_pages_counter = 0
        self.update_file_page_data = bytearray()

        current_partition = Partition(Partition.RUNNING)
        current_partition_name = current_partition.info()[4]

        self.plot_debug("current partition:" + str(current_partition.info()))

        if not current_partition_name.startswith(
                "ota_"):  # firmware is adapted to OTA ?
            print(
                "memory_esp32: skipping... Partition table not adapted to OTA")
            raise SystemExit

        self.partition = current_partition.get_next_update()
        self.plot_debug("next partition:" + str(self.partition.info()))
    log("Partition copy: {} --> {}".format(src.info(), dest.info()))
    sz = src.info()[3]
    if dest.info()[3] != sz:
        raise ValueError("Sizes don't match: {} vs {}".format(sz, dest.info()[3]))
    addr = 0
    blk = bytearray(4096)
    while addr < sz:
        if sz - addr < 4096:
            blk = blk[: sz - addr]
        if addr & 0xFFFF == 0:
            # need to show progress to run-tests.py else it times out
            print("   ... 0x{:06x}".format(addr))
        src.readblocks(addr >> 12, blk)
        dest.writeblocks(addr >> 12, blk)
        addr += len(blk)


# get things started by copying the current partition into the next slot and rebooting
print("Copying current to next partition")
nxt = cur.get_next_update()
copy_partition(cur, nxt)
print("Partition copied, booting into it")
nxt.set_boot()

# the step.py file is used to keep track of state across reboots
# EXPECT is the name of the partition we expect to reboot into
with open("step.py", "w") as f:
    f.write('STEP=0\nEXPECT="' + nxt.info()[4] + '"\n')

machine.reset()