Files
esp-idf/examples/storage/partition_api/partition_ops/README.md
T
Adam Múdry 749c446a7e feat(esp_partition): Add esp_partition_flash_binary() CMake function
Add a new CMake function esp_partition_flash_binary() that provides a
unified API for registering partition data binaries to be flashed. It
replaces the direct esptool_py_flash_target calls scattered across
components (spiffs, fatfs, nvs_flash) with a single function that:

- Resolves partition offset from the partition table automatically
- Determines encryption requirements (auto-detect or ALWAYS_PLAINTEXT)
- Creates per-partition flash targets (e.g. idf.py <partition>-flash)
- Optionally includes the binary in `idf.py flash` via FLASH_IN_PROJECT

On the linux target, the function registers binaries for pre-loading
into the emulated flash. A build-time manifest (linux_flash_data.txt)
is generated via file(GENERATE), and partition_linux.c reads it at
runtime to copy each binary into the memory-mapped flash buffer at
the correct offset.

The partition_ops example is updated to use the new function and
includes a custom_partition with pre-built data to demonstrate the
full workflow, including on the linux target.
2026-04-10 15:22:50 +02:00

1.8 KiB

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-C5 ESP32-C6 ESP32-C61 ESP32-H2 ESP32-H21 ESP32-H4 ESP32-P4 ESP32-S2 ESP32-S3 ESP32-S31

Partition Read, Write, Erase Example

This example demonstrates how to perform partition read, write and erase operations using API functions esp_partition_read, esp_partition_write and esp_partition_erase.

Example Flow

The example uses a custom partition table, with a data partition storage used as the demo partition. For the most part the example code is well-commented so users should be able to follow along the code easily. Nevertheless, this section provides an overview of the code flow.

The partition table is searched for the storage partition. Once found, the entire partition is erased using esp_partition_erase_range. Sample data is written using esp_partition_write and read back using esp_partition_read, verifying the read and written data match. The partition is erased once again using esp_partition_erase_range, limited to the sector the sample data was written to.

Output

I (588) example: Written data: ESP-IDF Partition Operations Example (Read, Erase, Write)
I (588) example: Read data: ESP-IDF Partition Operations Example (Read, Erase, Write)
I (638) example: Erased data
I (693) example: Read data from custom partition: abcdef123456
I (693) example: Example end

Others

Detailed functional description of partition API is provided in documentation.

See the README.md file in the upper level 'examples' directory for more information about examples.