Incorrect reported partition size on custom board & partition

I have a ‘weird’ problem regarding the partition configuration for my custom board. Here’s my project folder:

project_root
|-.pio
|-boards
| |-myboard.json
| |-mypartition.csv
|-...
|-platformio.ini

Board:

{
  "build": {
    "arduino": {
      "ldscript": "esp32_out.ld",
      "partitions": "boards/mypartition.csv"
    },
    "core": "esp32",
    "extra_flags": "-DARDUINO_ESP32_DEV",
    "f_cpu": "240000000L",
    "f_flash": "40000000L",
    "flash_mode": "dio",
    "mcu": "esp32",
    "variant": "esp32"
  },
  "connectivity": [
    "wifi",
    "bluetooth"
  ],
  "debug": {
    "openocd_board": "esp-wroom-32.cfg"
  },
  "frameworks": "arduino",
  "name": "MY BOARD",
  "upload": {
    "flash_size": "16MB",
    "maximum_ram_size": 327680,
    "maximum_size": 16777216,
    "require_upload_port": true,
    "speed": 921600
  },
  "url": "-",
  "vendor": "-"
}

Partition:

#name,    type, subtype,  offset,   size,     flags
nvs,      data, nvs,      0x9000,   0x5000,
otadata,  data, ota,      0xE000,   0x2000,
factory,  app,  factory,  0x10000,  0x200000,
app0,     app,  ota_0,    0x210000, 0x200000,
app1,     app,  ota_1,    0x410000, 0x200000,
spiffs,   data, spiffs,   0x610000, 0x9E4000,

I’ve set "partitions": "boards/mypartition.csv" inside myboard.json and set board = myboard on platformio.ini. When it built, the terminal showing the app flash size (total) is 1310720 bytes which if I’m not mistaken is the default partition size. But if I add an additional line board_build.partitions = boards/mypartition.csv on the ini file it will be built in the correct size (~2MB).

Is this behavior expected? Why the compiler doesn’t register the partition configuration that I’ve already put on my board file?

Full platformio.ini?

[env:development]
platform = espressif32
framework = arduino
board = myboard
;current working config, with explicit board_build parameter
board_build.partitions = boards/mypartition.csv
board_build.filesystem = littlefs
lib_deps = some_library
build_flags = -DCORE_DEBUG_LEVEL=0
upload_port = COM3
upload_speed = 921600
monitor_port = COM3
monitor_speed = 115200
monitor_filters = time, send_on_enter
monitor_flags = --echo

I’m also trying to create a new empty project with this same custom board and partition and it still presents the same behavior as my original project.

This is weird, 3 app partitions?

Try replacing your partition file content with

and see if the sizes changes. If yes, the previous file content was wrong.

For this, I’m just following the Partition Tables documentation, I think it shouldn’t be a problem.

Right now I have 3 partition files:

#mypartition0.csv - original
nvs,      data, nvs,      0x9000,   0x5000,
otadata,  data, ota,      0xE000,   0x2000,
factory,  app,  factory,  0x10000,  0x200000,
app0,     app,  ota_0,    0x210000, 0x200000,
app1,     app,  ota_1,    0x410000, 0x200000,
spiffs,   data, spiffs,   0x610000, 0x9E4000,

#mypartition1.csv - mypartition0 without factory
nvs,      data, nvs,      0x9000,   0x5000,
otadata,  data, ota,      0xE000,   0x2000,
ota_0,    app,  ota_0,    0x10000,  0x200000,
ota_1,    app,  ota_1,    0x210000, 0x200000,
spiffs,   data, spiffs,  0x410000, 0xBC4000,

#mypartition2.csv - same as default_16MB.csv
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x640000,
app1,     app,  ota_1,   0x650000,0x640000,
spiffs,   data, spiffs,  0xc90000,0x370000,

and here are my test result:

myboard.json -> build.arduino.partitions
board/mypartition0.csv, reported storage -> 1310720 bytes
board/mypartition1.csv, reported storage -> 1310720 bytes
board/mypartition2.csv, reported storage -> 1310720 bytes
default_16MB.csv,       reported storage -> 1310720 bytes

platformio.ini -> board_build.partitions
board/mypartition0.csv, reported storage -> 2097152 bytes
board/mypartition1.csv, reported storage -> 2097152 bytes
board/mypartition2.csv, reported storage -> 6553600 bytes
default_16MB.csv,       reported storage -> 6553600 bytes

Any changes on the custom board JSON file don’t affect the compiler to set the partition information, even using the pre-defined partition file.

Things get weirder, I’m curious to try a pre-defined board that already has 16MB flash for example esp32thing_plus. It used the default_16MB partition and it also reported 1310720 bytes. (???)

Please let me know if maybe there’s a dump file that can be helpful to be analyzed.

It may be the case that when you’re doing this, it expects the file to be in <home folder>/.platformio/packages/framework-arduinoespressif32/tools/partitions/, and falls back to the default.csv since it does not find it there. I’ll have too add some print statements and look at verbose compilation logs to figure that one out.

I’ve also tried to put my custom partition file on the project root as described here, but it still reported the wrong size. I think it’s not caused by file location, because in these two scenario:

  1. Set "partitions": "default_16MB.csv" on custom board json, default_16MB.csv file is already on the default path as you mentioned above.
  2. Use board = esp32thing_plus on platformio.ini, also the board is already built-in on the official platform release and used "partitions": "default_16MB.csv" in its board file.

Both resulting the same wrong value.

Here’re some compile verbose message:

Processing customboard (platform: espressif32; board: myboard; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/myboard.html
PLATFORM: Espressif 32 (4.2.0) > MY BOARD
HARDWARE: ESP32 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.20002.220503 (2.0.2)
 - tool-esptoolpy 1.30300.220323 (3.3.0)
 - toolchain-xtensa-esp32 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 31 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\customboard\firmware.elf
Checking size .pio\build\customboard\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.9% (used 16148 bytes from 327680 bytes)
Flash: [==        ]  15.7% (used 206225 bytes from 1310720 bytes)

Processing predefined (platform: espressif32; board: esp32thing_plus; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32thing_plus.html
PLATFORM: Espressif 32 (4.2.0) > SparkFun ESP32 Thing Plus
HARDWARE: ESP32 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.20002.220503 (2.0.2)
 - tool-esptoolpy 1.30300.220323 (3.3.0)
 - toolchain-xtensa-esp32 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 31 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\predefined\firmware.elf
Checking size .pio\build\predefined\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.9% (used 16148 bytes from 327680 bytes)
Flash: [==        ]  15.7% (used 206225 bytes from 1310720 bytes)

Both using same "partitions": "default_16MB.csv" in the board file.