The esp_partition
component has higher-level API functions which work with partitions defined in the Partition Tables. These APIs are based on lower level API provided by SPI Flash API.
ESP-IDF projects use a partition table to maintain information about various regions of SPI flash memory (bootloader, various application binaries, data, filesystems). More information can be found in Partition Tables.
This component provides API functions to enumerate partitions found in the partition table and perform operations on them. These functions are declared in esp_partition.h
:
esp_partition_find()
checks a partition table for entries with specific type, returns an opaque iterator.
esp_partition_get()
returns a structure describing the partition for a given iterator.
esp_partition_next()
shifts the iterator to the next found partition.
esp_partition_iterator_release()
releases iterator returned by esp_partition_find()
.
esp_partition_find_first()
is a convenience function which returns the structure describing the first partition found by esp_partition_find()
.
esp_partition_read()
, esp_partition_write()
, esp_partition_erase_range()
are equivalent to esp_flash_read()
, esp_flash_write()
, esp_flash_erase_region()
, but operate within partition boundaries.
storage/partition_api/partition_ops demonstrates how to perform read, write, and erase operations on a partition table.
storage/parttool demonstrates how to use the partitions tool to perform operations such as reading, writing, erasing partitions, retrieving partition information, and dumping the entire partition table.
storage/partition_api/partition_find demonstrates how to search the partition table and return matching partitions based on set constraints such as partition type, subtype, and label/name.
storage/partition_api/partition_mmap demonstrates how to configure the MMU, map a partition into memory address space for read operations, and verify the data written and read.
Over The Air Updates (OTA) provides high-level API for updating applications stored in flash.
Non-Volatile Storage Library provides a structured API for storing small pieces of data in SPI flash.
Find partition based on one or more parameters.
type -- Partition type, one of esp_partition_type_t values or an 8-bit unsigned integer. To find all partitions, no matter the type, use ESP_PARTITION_TYPE_ANY, and set subtype argument to ESP_PARTITION_SUBTYPE_ANY.
subtype -- Partition subtype, one of esp_partition_subtype_t values or an 8-bit unsigned integer. To find all partitions of given type, use ESP_PARTITION_SUBTYPE_ANY.
label -- (optional) Partition label. Set this value if looking for partition with a specific name. Pass NULL otherwise.
iterator which can be used to enumerate all the partitions found, or NULL if no partitions were found. Iterator obtained through this function has to be released using esp_partition_iterator_release when not used any more.
Find first partition based on one or more parameters.
type -- Partition type, one of esp_partition_type_t values or an 8-bit unsigned integer. To find all partitions, no matter the type, use ESP_PARTITION_TYPE_ANY, and set subtype argument to ESP_PARTITION_SUBTYPE_ANY.
subtype -- Partition subtype, one of esp_partition_subtype_t values or an 8-bit unsigned integer To find all partitions of given type, use ESP_PARTITION_SUBTYPE_ANY.
label -- (optional) Partition label. Set this value if looking for partition with a specific name. Pass NULL otherwise.
pointer to esp_partition_t structure, or NULL if no partition is found. This pointer is valid for the lifetime of the application.
Get esp_partition_t structure for given partition.
iterator -- Iterator obtained using esp_partition_find. Must be non-NULL.
pointer to esp_partition_t structure. This pointer is valid for the lifetime of the application.
Move partition iterator to the next partition found.
Any copies of the iterator will be invalid after this call.
iterator -- Iterator obtained using esp_partition_find. Must be non-NULL.
NULL if no partition was found, valid esp_partition_iterator_t otherwise.
Release partition iterator.
iterator -- Iterator obtained using esp_partition_find. The iterator is allowed to be NULL, so it is not necessary to check its value before calling this function.
Verify partition data.
Given a pointer to partition data, verify this partition exists in the partition table (all fields match.)
This function is also useful to take partition data which may be in a RAM buffer and convert it to a pointer to the permanent partition data stored in flash.
Pointers returned from this function can be compared directly to the address of any pointer returned from esp_partition_get(), as a test for equality.
partition -- Pointer to partition data to verify. Must be non-NULL. All fields of this structure must match the partition table entry in flash for this function to return a successful match.
If partition not found, returns NULL.
If found, returns a pointer to the esp_partition_t structure in flash. This pointer is always valid for the lifetime of the application.
Read data from the partition.
Partitions marked with an encryption flag will automatically be be read and decrypted via a cache mapping.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
dst -- Pointer to the buffer where data should be stored. Pointer must be non-NULL and buffer must be at least 'size' bytes long.
src_offset -- Address of the data to be read, relative to the beginning of the partition.
size -- Size of data to be read, in bytes.
ESP_OK, if data was read successfully; ESP_ERR_INVALID_ARG, if src_offset exceeds partition size; ESP_ERR_INVALID_SIZE, if read would go out of bounds of the partition; or one of error codes from lower-level flash driver.
Write data to the partition.
Before writing data to flash, corresponding region of flash needs to be erased. This can be done using esp_partition_erase_range function.
Partitions marked with an encryption flag will automatically be written via the esp_flash_write_encrypted() function. If writing to an encrypted partition, all write offsets and lengths must be multiples of 16 bytes. See the esp_flash_write_encrypted() function for more details. Unencrypted partitions do not have this restriction.
Note
Prior to writing to flash memory, make sure it has been erased with esp_partition_erase_range call.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
dst_offset -- Address where the data should be written, relative to the beginning of the partition.
src -- Pointer to the source buffer. Pointer must be non-NULL and buffer must be at least 'size' bytes long.
size -- Size of data to be written, in bytes.
ESP_OK, if data was written successfully; ESP_ERR_INVALID_ARG, if dst_offset exceeds partition size; ESP_ERR_INVALID_SIZE, if write would go out of bounds of the partition; ESP_ERR_NOT_ALLOWED, if partition is read-only; or one of error codes from lower-level flash driver.
Read data from the partition without any transformation/decryption.
Note
This function is essentially the same as esp_partition_read()
above. It just never decrypts data but returns it as is.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
dst -- Pointer to the buffer where data should be stored. Pointer must be non-NULL and buffer must be at least 'size' bytes long.
src_offset -- Address of the data to be read, relative to the beginning of the partition.
size -- Size of data to be read, in bytes.
ESP_OK, if data was read successfully; ESP_ERR_INVALID_ARG, if src_offset exceeds partition size; ESP_ERR_INVALID_SIZE, if read would go out of bounds of the partition; or one of error codes from lower-level flash driver.
Write data to the partition without any transformation/encryption.
Before writing data to flash, corresponding region of flash needs to be erased. This can be done using esp_partition_erase_range function.
Note
This function is essentially the same as esp_partition_write()
above. It just never encrypts data but writes it as is.
Note
Prior to writing to flash memory, make sure it has been erased with esp_partition_erase_range call.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
dst_offset -- Address where the data should be written, relative to the beginning of the partition.
src -- Pointer to the source buffer. Pointer must be non-NULL and buffer must be at least 'size' bytes long.
size -- Size of data to be written, in bytes.
ESP_OK, if data was written successfully; ESP_ERR_INVALID_ARG, if dst_offset exceeds partition size; ESP_ERR_INVALID_SIZE, if write would go out of bounds of the partition; ESP_ERR_NOT_ALLOWED, if partition is read-only; or one of the error codes from lower-level flash driver.
Erase part of the partition.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
offset -- Offset from the beginning of partition where erase operation should start. Must be aligned to partition->erase_size.
size -- Size of the range which should be erased, in bytes. Must be divisible by partition->erase_size.
ESP_OK, if the range was erased successfully; ESP_ERR_INVALID_ARG, if iterator or dst are NULL; ESP_ERR_INVALID_SIZE, if erase would go out of bounds of the partition; ESP_ERR_NOT_ALLOWED, if partition is read-only; or one of error codes from lower-level flash driver.
Configure MMU to map partition into data memory.
Unlike spi_flash_mmap function, which requires a 64kB aligned base address, this function doesn't impose such a requirement. If offset results in a flash address which is not aligned to 64kB boundary, address will be rounded to the lower 64kB boundary, so that mapped region includes requested range. Pointer returned via out_ptr argument will be adjusted to point to the requested offset (not necessarily to the beginning of mmap-ed region).
To release mapped memory, pass handle returned via out_handle argument to esp_partition_munmap function.
partition -- Pointer to partition structure obtained using esp_partition_find_first or esp_partition_get. Must be non-NULL.
offset -- Offset from the beginning of partition where mapping should start.
size -- Size of the area to be mapped.
memory -- Memory space where the region should be mapped
out_ptr -- Output, pointer to the mapped memory region
out_handle -- Output, handle which should be used for esp_partition_munmap call
ESP_OK, if successful
Release region previously obtained using esp_partition_mmap.
Note
Calling this function will not necessarily unmap memory region. Region will only be unmapped when there are no other handles which reference this region. In case of partially overlapping regions it is possible that memory will be unmapped partially.
handle -- Handle obtained from spi_flash_mmap
Get SHA-256 digest for required partition.
For apps with SHA-256 appended to the app image, the result is the appended SHA-256 value for the app image content. The hash is verified before returning, if app content is invalid then the function returns ESP_ERR_IMAGE_INVALID. For apps without SHA-256 appended to the image, the result is the SHA-256 of all bytes in the app image. For other partition types, the result is the SHA-256 of the entire partition.
partition -- [in] Pointer to info for partition containing app or data. (fields: address, size and type, are required to be filled).
sha_256 -- [out] Returned SHA-256 digest for a given partition.
ESP_OK: In case of successful operation.
ESP_ERR_INVALID_ARG: The size was 0 or the sha_256 was NULL.
ESP_ERR_NO_MEM: Cannot allocate memory for sha256 operation.
ESP_ERR_IMAGE_INVALID: App partition doesn't contain a valid app image.
ESP_FAIL: An allocation error occurred.
Check for the identity of two partitions by SHA-256 digest.
partition_1 -- [in] Pointer to info for partition 1 containing app or data. (fields: address, size and type, are required to be filled).
partition_2 -- [in] Pointer to info for partition 2 containing app or data. (fields: address, size and type, are required to be filled).
True: In case of the two firmware is equal.
False: Otherwise
Register a partition on an external flash chip.
This API allows designating certain areas of external flash chips (identified by the esp_flash_t structure) as partitions. This allows using them with components which access SPI flash through the esp_partition API.
flash_chip -- Pointer to the structure identifying the flash chip. If NULL then the internal flash chip is used (esp_flash_default_chip).
offset -- Address in bytes, where the partition starts
size -- Size of the partition in bytes
label -- Partition name
type -- One of the partition types (ESP_PARTITION_TYPE_*), or an integer. Note that applications can not be booted from external flash chips, so using ESP_PARTITION_TYPE_APP is not supported.
subtype -- One of the partition subtypes (ESP_PARTITION_SUBTYPE_*), or an integer.
out_partition -- [out] Output, if non-NULL, receives the pointer to the resulting esp_partition_t structure
ESP_OK on success
ESP_ERR_NO_MEM if memory allocation has failed
ESP_ERR_INVALID_ARG if the new partition overlaps another partition on the same flash chip
ESP_ERR_INVALID_SIZE if the partition doesn't fit into the flash chip size
Deregister the partition previously registered using esp_partition_register_external.
partition -- pointer to the partition structure obtained from esp_partition_register_external,
ESP_OK on success
ESP_ERR_NOT_FOUND if the partition pointer is not found
ESP_ERR_INVALID_ARG if the partition comes from the partition table
ESP_ERR_INVALID_ARG if the partition was not registered using esp_partition_register_external function.
Unload partitions and free space allocated by them.
Get the main flash sector size.
SPI_FLASH_SEC_SIZE - For esp32xx target
ESP_PARTITION_EMULATED_SECTOR_SIZE - For linux target
Copy data from a source partition at a specific offset to a destination partition at a specific offset.
The destination offset must be aligned to the flash sector size (SPI_FLASH_SEC_SIZE = 0x1000). If "size" is SIZE_MAX, the entire destination partition (from dest_offset onward) will be erased, and the function will copy all of the source partition starting from src_offset into the destination. The function ensures that the destination partition is erased on sector boundaries (erase size is aligned up SPI_FLASH_SEC_SIZE).
This function does the following:
erases the destination partition from dest_offset to the specified size (or the whole partition if "size" == SIZE_MAX),
maps data from the source partition in chunks,
writes the source data into the destination partition in corresponding chunks.
dest_part -- Pointer to a destination partition.
dest_offset -- Offset in the destination partition where the data should be written (must be aligned to SPI_FLASH_SEC_SIZE = 0x1000).
src_part -- Pointer to a source partition (must be located on internal flash).
src_offset -- Offset in the source partition where the data should be read from.
size -- Number of bytes to copy from the source partition to the destination partition. If "size" is SIZE_MAX, the function copies from src_offset to the end of the source partition and erases the entire destination partition (from dest_offset onward).
ESP_OK, if the source partition was copied successfully to the destination partition; ESP_ERR_INVALID_ARG, if src_part or dest_part are incorrect, or if dest_offset is not sector aligned; ESP_ERR_INVALID_SIZE, if the copy would go out of bounds of the source or destination partition; ESP_ERR_NOT_ALLOWED, if the destination partition is read-only; or one of the error codes from the lower-level flash driver.
partition information structure
This is not the format in flash, that format is esp_partition_info_t.
However, this is the format used by this API.
Public Members
SPI flash chip on which the partition resides
partition type (app/data)
partition subtype
starting address of the partition in flash
size of the partition, in bytes
size the erase operation should be aligned to
partition label, zero-terminated ASCII string
flag is set to true if partition is encrypted
flag is set to true if partition is read-only
Convenience macro to get esp_partition_subtype_t value for the i-th OTA partition.
Opaque handle for memory region obtained from esp_partition_mmap.
Opaque partition iterator type.
Enumeration which specifies memory space requested in an mmap call.
Values:
map to data memory (Vaddr0), allows byte-aligned access, (4 MB total - only for esp32)
map to instruction memory (Vaddr1-3), allows only 4-byte-aligned access, (11 MB total - only for esp32)
Partition type.
Note
Partition types with integer value 0x00-0x3F are reserved for partition types defined by ESP-IDF. Any other integer value 0x40-0xFE can be used by individual applications, without restriction.
Values:
Application partition type.
Data partition type.
Bootloader partition type.
Partition table type.
Used to search for partitions with any type.
Partition subtype.
Application-defined partition types (0x40-0xFE) can set any numeric subtype value.
Note
These ESP-IDF-defined partition subtypes apply to partitions of type ESP_PARTITION_TYPE_APP and ESP_PARTITION_TYPE_DATA.
Values:
Primary Bootloader.
Temporary OTA storage for Bootloader, where the OTA uploads a new Bootloader image.
Recovery Bootloader.
Primary Partition table.
Temporary OTA storage for Partition table, where the OTA uploads a new Partition table image.
Factory application partition.
Base for OTA partition subtypes.
OTA partition 0.
OTA partition 1.
OTA partition 2.
OTA partition 3.
OTA partition 4.
OTA partition 5.
OTA partition 6.
OTA partition 7.
OTA partition 8.
OTA partition 9.
OTA partition 10.
OTA partition 11.
OTA partition 12.
OTA partition 13.
OTA partition 14.
OTA partition 15.
Max subtype of OTA partition.
Test application partition.
Base for TEE partition subtypes.
TEE partition 0.
TEE partition 1.
Max subtype of TEE partition.
OTA selection partition.
PHY init data partition.
NVS partition.
COREDUMP partition.
Partition for NVS keys.
Partition for emulate eFuse bits.
Undefined (or unspecified) data partition.
ESPHTTPD partition.
FAT partition.
SPIFFS partition.
LITTLEFS partition.
TEE OTA selection partition.
Used to search for partitions with any subtype.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4