ESP32 multiple partitions

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Posts: 3
Joined: Tue Oct 24, 2017 10:38 am

ESP32 multiple partitions

Post by krono » Sat Jan 12, 2019 7:21 pm

I'm trying to mount another recovery partition in addition to the default one mounted on "/flash".
I'm doing this because I want to restore a configuration file (json), in case of corruption of the primary partition.
I can't mount the second volume because I can't see it using uos.listdir() and I can't move in using uos.chdir("/recovery").
I've an ESP32 with Micropython 1.9.4.

This is my partition table:

Code: Select all

nvs,      data, nvs,     0x9000,  0x4000
otadata,  data, ota,     0xd000,  0x2000
phy_init, data, phy,     0xf000,  0x1000
factory,  app,  factory, 0x10000, 1144k
ota_0,    app,  ota_0,   0x130000,1144k
ota_1,    app,  ota_1,   0x250000,1144k
internalfs, data,spiffs, 0x36e000,76k
recovery, data,spiffs, 0x381000,4k
Follows the code of

Code: Select all

# Mount primary partition
vfsFlash = uos.VfsFat(flashbdev.bdev)
uos.mount(vfsFlash, '/flash')

# Write config file into primary partition
with open("resources/config.json", 'w') as f:

# Mount recovery partition
bdevRecovery = FlashBdev(2048 * 1024 // FlashBdev.SEC_SIZE)
bdevRecovery.START_SEC = 3674112 // SEC_SIZE
vfsRecovery = uos.VfsFat(bdevRecovery)
uos.mount(vfsRecovery, '/recovery')

# Write config file into recovery partition
with open("resources/config.json", 'w') as f:
So to recap my target is to reset primary partition in case of corruption and use the recovery one to restore the json configuration file.
I didn't understand well VfsFat:
- what's the point of the calculation 2048 * 1024 // FlashBdev.SEC_SIZE which is done at the object allocation?
- how's the starting address of the partition calculated? (3674112 // SEC_SIZE)

Thank you in advance.

Post Reply