Could Parttion.writeblocks write a Partition from a bin_file on flash?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
JakcieLs
Posts: 2
Joined: Thu May 19, 2022 5:28 am

Could Parttion.writeblocks write a Partition from a bin_file on flash?

Post by JakcieLs » Thu May 19, 2022 5:57 am

The source code

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)

Here is the REPL

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')
I use the above to write a hello_world.bin(file is on the flash) in to my next partition, it could be written. But I when I reboot, it could not reboot from the next partition.But when i use the otatool.py to write_ota_partition it works well. What's the problem.

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)

JakcieLs
Posts: 2
Joined: Thu May 19, 2022 5:28 am

Re: Could Parttion.writeblocks write a Partition from a bin_file on flash?

Post by JakcieLs » Tue May 24, 2022 1:50 am

It's worked. Just because of the Thonny IDE doesn't work very well.When I use screen It's worked.

Post Reply