Page 1 of 1

(resolved) creating custom partition

Posted: Wed Nov 07, 2018 4:41 pm
by mzimmers
Hi all -

I'm still trying to figure out how to do the serialization of our ESP32-based products. I have to load each unit with a unique MAC address and serial number assigned by us (can't use the MAC supplied through Espressif).

A couple questions about partitions:

1. I notice that the first partition in the default table is nvs, and begins at offset 0x9000. Is the space below that reserved, or can I use it?
2. If I can't use this space, I assume I can make the nvs partition smaller and create another partition to use that recovered space?
2. I've read the pages on creating a partition .bin file. How does one go about flashing this file (to load just one partition)?

Thanks...

Re: creating custom partition

Posted: Wed Nov 07, 2018 9:25 pm
by chegewara
Its not exactly that nvs is first partition. Not all partitions are included in partitions.csv file. This is default single app partition table:

Code: Select all

# Espressif ESP32 Partition Table
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
and here is part of output from make command:

Code: Select all

0x1000 /home/imper/examples/ble_mesh_provisioner/build/bootloader/bootloader.bin 
0x10000 /home/imper/examples/ble_mesh_provisioner/build/bt_mesh_provisioner.bin 
0x8000 /home/imper/examples/ble_mesh_provisioner/build/partitions_singleapp.bin
As you can see bootloader partition is loaded from address 0x1000 and partition table from 0x8000, but none is included in partitions.csv. Address 0x0000-0x1000 is system reserved.

2. Assuming that you will use flash encryption on your final product then minimum nvs size is 4096 bytes:
https://docs.espressif.com/projects/esp ... -partition
3. You can use flash download tool or from cli use proper command: make flash partition_table, make flash_app, make flash bootloader or:

Code: Select all

python /home/imper/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /home/imper/examples/ble_mesh_provisioner/build/bootloader/bootloader.bin 0x10000 /home/imper/examples/ble_mesh_provisioner/build/bt_mesh_provisioner.bin 0x8000 /home/imper/examples/ble_mesh_provisioner/build/partitions_singleapp.bin
With this command you can flash as many partitions as you want/need and you can control start address to flash.

Re: creating custom partition

Posted: Wed Nov 07, 2018 9:36 pm
by mzimmers
So, if my partition structure looks like this currently:

Code: Select all

I (57) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (64) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (72) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (79) boot:  3 factory          factory app      00 00 00010000 00100000
I (87) boot:  4 ota_0            OTA app          00 10 00110000 00100000
I (94) boot:  5 ota_1            OTA app          00 11 00210000 00100000
I should be able to reduce nvs to 0x2000 bytes, giving me room for a new partition at 0xa000, right?

And, I notice your esptool.py example flashes 3 partitions. If I only wish to flash one partition, can I do so, or will it erase the other existing partitions?

Re: creating custom partition

Posted: Wed Nov 07, 2018 10:38 pm
by chegewara
Probably someone more experienced can confirm my answer but from my experience i can say yes, you can resize nvs to 0x2000 and add another partition.
I notice your esptool.py example flashes 3 partitions. If I only wish to flash one partition, can I do so, or will it erase the other existing partitions?
As long as binary file size that you want to flash is smaller than partition size you can safely flash it(1 or 2 or 3 etc), but if binary is bigger than partition size then next partition will be overlapped and corrupted.

Re: creating custom partition

Posted: Wed Nov 07, 2018 11:09 pm
by mzimmers
Thanks for the answers. I reduced my nvs partition to 0x1000 bytes. When I try to call nvs_set_blob() for a write of 0x3fc bytes, I get an error ESP_ERR_NVS_VALUE_TOO_LONG. I didn't get this error when my nvs partition was 0x2000 bytes. I guess there's a substantial amount of overhead associated with using the NVS library.

Anyway, it's no big deal. I changed my nvs partition to 0x3000 bytes and everything seems happy now. Thanks for the help.