Code: Select all
def update_by_file(file_path):
p = getTargetPartition()
addr = 0
with open(file_path, 'rb') as f:
while True:
if addr & 0xFFFF == 0:
print(" ... 0x{:06x}".format(addr))
buff = f.read(BLOCK)
if not buff:
break
buff = bytearray(buff)
buff_size = len(buff)
# pad_to FF
if buff_size % BLOCK != 0:
pad = bytearray([255] * BLOCK)
buff = buff + pad[buff_size:]
p.writeblocks(addr >> 12, buff)
addr += len(buff)
Code: Select all
>>> import ybc_updater
>>> from esp32 import Partition
>>> cur = Partition(Partition.RUNNING)
>>> next = cur.get_next_update()
>>> cur.info()
(0, 16, 65536, 1572864, 'micropython_0', False)
>>> next.info()
(0, 17, 1638400, 1572864, 'micropython_1', False)
>>> ybc_updater.update_by_file('/data/hello_world.bin')
Code: Select all
>>> next.set_boot()
>>>
MicroPython df93ecb-dirty on 2022-05-19; 8MB/OTA module with ESP32
Type "help()" for more information.
>>> from esp32 import Partition
>>> cur = Partition(Partition.RUNNING)
>>> cur.info()
(0, 16, 65536, 1572864, 'micropython_0', False)