How much space do I need to leave at the end of a partition?

bottleopener7s3
Posts: 3
Joined: Mon Jul 21, 2025 11:43 pm

How much space do I need to leave at the end of a partition?

Postby bottleopener7s3 » Mon Jul 21, 2025 11:53 pm

I'm flashing a bin to a nvs partition called 'mfg'.

I discovered (after much head bashing) that I cannot flash a bin to a partition that is the size of the partition. Otherwise you get a ESP_ERR_NVS_NO_FREE_PAGES error when you try to init the partition.

My partition table looks like this:

Code: Select all

# Name,   Type, SubType,  Offset,   Size,  Flags
mfg,      data, nvs,      0xE000,  0x2000, readonly,encrypted
nvs,      data, nvs,      ,        0x4000,
nvs_key,  data, nvs_keys, ,        0x1000, 
phy_init, data, phy,      ,        0x1000,
otadata,  data, ota,      ,        0x2000,
factory,  app,  factory,  ,         2M,    
ota_0,    app,  ota_0,    ,         2M,    
ota_1,    app,  ota_1,    ,         2M,    
Right now I'm writing a 0x1000 byte bin to the mfg partition.

But what I'd like to do is size a mfg partition with 0x1000 bytes and write a smaller bin to that partition as I only need to write a couple small strings.

So my question is: what is the minimum amount of blank space I need to leave at the end of a partition?

Or, with a partition sized at 0x1000 bytes, what is the maximum size of the bin I can flash to that partition?


P.S. is that the correct way to have both readonly and encrypted flags set on a partition?

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How much space do I need to leave at the end of a partition?

Postby MicroController » Tue Jul 22, 2025 8:26 am

You can specify multiple flags by separating them with a colon. For example, encrypted:readonly.
https://docs.espressif.com/projects/esp ... html#flags

bottleopener7s3
Posts: 3
Joined: Mon Jul 21, 2025 11:43 pm

Re: How much space do I need to leave at the end of a partition?

Postby bottleopener7s3 » Wed Jul 23, 2025 1:53 pm

It's occurred to me that ESP_ERR_NVS_NO_FREE_PAGES might mean that you need at least one page free.

Digging further it looks like a standard page size is 256 bytes:
https://docs.espressif.com/projects/esp ... l#mkspiffs

So in theory the maximum size of a bin in a minimum sized read-only NVS partition would be 0x900 bytes - given the minimum size of a read-only NVS partition is 0x1000 (https://docs.espressif.com/projects/esp ... ml#subtype)

But, if you use esp-idf's supplied partition generation tool... bin sizes must be a multiple of 0x1000 bytes (https://docs.espressif.com/projects/esp ... on-default)

So practically, the minimum NVS size for a read only partition is actually 0x2000 bytes because you need at least 0x100 bytes free and you have to flash binaries in multiples of 0x1000...

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How much space do I need to leave at the end of a partition?

Postby MicroController » Fri Jul 25, 2025 7:27 am

Tha page size of the flash memory is actually 4k, i.e. 0x1000.
According to the docs, you don't need a free page if the partition is flagged read-only.

bottleopener7s3
Posts: 3
Joined: Mon Jul 21, 2025 11:43 pm

Re: How much space do I need to leave at the end of a partition?

Postby bottleopener7s3 » Fri Jul 25, 2025 8:28 am

Tha page size of the flash memory is actually 4k, i.e. 0x1000.
According to the docs, you don't need a free page if the partition is flagged read-only.
Could you link where it says that? It says you don’t need a free page, but it doesn’t init without error if it doesn’t have it. I don’t feel comfortable ignoring the error because I don’t know exactly what else might trigger the error that I shouldn’t ignore.


Who is online

Users browsing this forum: ChatGPT-User, Google [Bot] and 4 guests