|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
A flash partition. More...
Classes | |
| class | mmap_handle |
| A memory-mapped partition region. More... | |
Public Types | |
| enum class | type : int { app = 0x00 , data = 0x01 , bootloader = 0x02 , partition_table = 0x03 , any = 0xff } |
| Partition type. More... | |
| enum class | subtype : int { bootloader_primary = 0x00 , bootloader_ota = 0x01 , bootloader_recovery = 0x02 , partition_table_primary = 0x00 , partition_table_ota = 0x01 , app_factory = 0x00 , app_ota_0 = 0x10 , app_ota_1 = 0x11 , app_ota_2 = 0x12 , app_ota_3 = 0x13 , app_ota_4 = 0x14 , app_ota_5 = 0x15 , app_ota_6 = 0x16 , app_ota_7 = 0x17 , app_ota_8 = 0x18 , app_ota_9 = 0x19 , app_ota_10 = 0x1a , app_ota_11 = 0x1b , app_ota_12 = 0x1c , app_ota_13 = 0x1d , app_ota_14 = 0x1e , app_ota_15 = 0x1f , app_test = 0x20 , data_ota = 0x00 , data_phy = 0x01 , data_nvs = 0x02 , data_coredump = 0x03 , data_nvs_keys = 0x04 , data_efuse_em = 0x05 , data_undefined = 0x06 , data_esphttpd = 0x80 , data_fat = 0x81 , data_spiffs = 0x82 , data_littlefs = 0x83 , any = 0xff } |
| Partition subtype. More... | |
| enum class | mmap_memory : int { data = 0 , inst } |
| Memory type for memory-mapped partition access. More... | |
Public Member Functions | |
| partition (const partition &)=default | |
| partition (partition &&)=default | |
| partition & | operator= (const partition &)=default |
| partition & | operator= (partition &&)=default |
| constexpr bool | operator== (const partition &) const noexcept=default |
| Compares two partitions for equality. | |
| enum type | type () const |
| Returns the partition type. | |
| enum subtype | subtype () const |
| Returns the partition subtype. | |
| uint32_t | address () const |
| Returns the starting address in flash. | |
| uint32_t | size () const |
| Returns the partition size in bytes. | |
| uint32_t | erase_size () const |
| Returns the erase block size. | |
| std::string_view | label () const |
| Returns the partition label. | |
| bool | encrypted () const |
| Returns true if the partition is encrypted. | |
| bool | readonly () const |
| Returns true if the partition is read-only. | |
| constexpr const esp_partition_t * | idf_handle () const |
| Returns the underlying ESP-IDF partition handle. | |
| void | read (size_t offset, void *dst, size_t size) const |
| Reads data from the partition with decryption if applicable. | |
| void | read (size_t offset, std::span< uint8_t > dst) const |
| Reads data from the partition with decryption if applicable. | |
| void | write (size_t offset, const void *src, size_t size) |
| Writes data to the partition with encryption if applicable. | |
| void | write (size_t offset, std::span< const uint8_t > src) |
| Writes data to the partition with encryption if applicable. | |
| void | read_raw (size_t offset, void *dst, size_t size) const |
| Reads data from the partition without decryption. | |
| void | read_raw (size_t offset, std::span< uint8_t > dst) const |
| Reads data from the partition without decryption. | |
| void | write_raw (size_t offset, const void *src, size_t size) |
| Writes data to the partition without encryption. | |
| void | write_raw (size_t offset, std::span< const uint8_t > src) |
| Writes data to the partition without encryption. | |
| void | erase_range (size_t offset, size_t size) |
| Erases a range of the partition. | |
| std::array< uint8_t, 32 > | sha256 () const |
| Computes the SHA-256 hash of the partition contents. | |
| mmap_handle | mmap (size_t offset, size_t size, enum mmap_memory memory=mmap_memory::data) const |
| Memory-maps a region of the partition. | |
| result< void > | try_read (size_t offset, void *dst, size_t size) const |
| Reads data from the partition with decryption if applicable. | |
| result< void > | try_read (size_t offset, std::span< uint8_t > dst) const |
| Reads data from the partition with decryption if applicable. | |
| result< void > | try_write (size_t offset, const void *src, size_t size) |
| Writes data to the partition with encryption if applicable. | |
| result< void > | try_write (size_t offset, std::span< const uint8_t > src) |
| Writes data to the partition with encryption if applicable. | |
| result< void > | try_read_raw (size_t offset, void *dst, size_t size) const |
| Reads data from the partition without decryption. | |
| result< void > | try_read_raw (size_t offset, std::span< uint8_t > dst) const |
| Reads data from the partition without decryption. | |
| result< void > | try_write_raw (size_t offset, const void *src, size_t size) |
| Writes data to the partition without encryption. | |
| result< void > | try_write_raw (size_t offset, std::span< const uint8_t > src) |
| Writes data to the partition without encryption. | |
| result< void > | try_erase_range (size_t offset, size_t size) |
| Erases a range of the partition. | |
| result< std::array< uint8_t, 32 > > | try_sha256 () const |
| Computes the SHA-256 hash of the partition contents. | |
| result< mmap_handle > | try_mmap (size_t offset, size_t size, enum mmap_memory memory=mmap_memory::data) const |
| Memory-maps a region of the partition. | |
| bool | check_identity (const partition &other) const |
| Checks if two partitions have identical contents by comparing SHA-256 hashes. | |
Static Public Member Functions | |
| static partition | find (enum type type, enum subtype subtype=subtype::any, std::string_view label={}) |
| Finds the first partition matching the given criteria. | |
| static partition | find (std::string_view label) |
| Finds the first partition with the given label. | |
| static result< partition > | try_find (enum type type, enum subtype subtype=subtype::any, std::string_view label={}) |
| Finds the first partition matching the given criteria. | |
| static result< partition > | try_find (std::string_view label) |
| Finds the first partition with the given label. | |
| static std::vector< partition > | find_all (enum type type=type::any, enum subtype subtype=subtype::any, std::string_view label={}) |
| Finds all partitions matching the given criteria. | |
| static constexpr partition | from_handle (const esp_partition_t *handle) |
| Constructs a partition from an ESP-IDF partition handle. | |
A flash partition.
Represents a region of flash storage defined in the partition table. Provides discovery, reading, writing, erasing, and memory mapping.
Use the static find methods to discover partitions from the partition table. Partitions are copyable and remain valid for the entire application lifetime.
Definition at line 51 of file partition.hpp.
|
strong |
Memory type for memory-mapped partition access.
| Enumerator | |
|---|---|
| data | Map to data memory, allows byte-aligned access. |
| inst | Map to instruction memory, allows only 4-byte-aligned access. |
Definition at line 112 of file partition.hpp.
|
strong |
Partition subtype.
Definition at line 63 of file partition.hpp.
|
strong |
Partition type.
| Enumerator | |
|---|---|
| app | Application partition. |
| data | Data partition. |
| bootloader | Bootloader partition. |
| partition_table | Partition table. |
| any | Match any partition type (for searching) |
Definition at line 54 of file partition.hpp.
|
default |
|
inline |
Returns the starting address in flash.
Definition at line 220 of file partition.hpp.
Checks if two partitions have identical contents by comparing SHA-256 hashes.
| other | The other partition to compare with. |
|
inline |
Returns true if the partition is encrypted.
Definition at line 232 of file partition.hpp.
Erases a range of the partition.
Both offset and size must be aligned to erase_size().
| offset | Byte offset within the partition (must be erase-aligned). |
| size | Number of bytes to erase (must be erase-aligned). |
| std::system_error | on failure. |
Definition at line 348 of file partition.hpp.
References size(), try_erase_range(), and idfxx::unwrap().
|
inline |
Returns the erase block size.
Definition at line 226 of file partition.hpp.
|
static |
Finds the first partition matching the given criteria.
| type | Partition type to match, or type::any for all types. |
| subtype | Partition subtype to match, or subtype::any for all subtypes. |
| label | Optional partition label to match. Empty matches all labels. |
| std::system_error | with idfxx::errc::not_found if no partition matches. |
Finds the first partition with the given label.
Searches across all partition types and subtypes.
| label | Partition label to match. |
| std::system_error | with idfxx::errc::not_found if no partition matches. |
|
static |
Finds all partitions matching the given criteria.
| type | Partition type to match, or type::any for all types. |
| subtype | Partition subtype to match, or subtype::any for all subtypes. |
| label | Optional partition label to match. Empty matches all labels. |
|
inlinestaticconstexpr |
Constructs a partition from an ESP-IDF partition handle.
| handle | Pointer to an ESP-IDF partition structure. Must not be null. |
Definition at line 198 of file partition.hpp.
|
inlineconstexpr |
Returns the underlying ESP-IDF partition handle.
Definition at line 238 of file partition.hpp.
|
inline |
Returns the partition label.
Definition at line 229 of file partition.hpp.
|
inline |
Memory-maps a region of the partition.
| offset | Byte offset within the partition (must be aligned to 0x10000 for data, or SPI_FLASH_MMU_PAGE_SIZE for instruction memory). |
| size | Number of bytes to map. |
| memory | Memory type to map to. |
| std::system_error | on failure. |
Definition at line 592 of file partition.hpp.
References idfxx::partition::mmap_handle::size(), try_mmap(), and idfxx::unwrap().
Compares two partitions for equality.
Reads data from the partition with decryption if applicable.
| offset | Byte offset within the partition. |
| dst | Destination span. |
| std::system_error | on failure. |
Definition at line 266 of file partition.hpp.
References try_read(), and idfxx::unwrap().
Reads data from the partition with decryption if applicable.
| offset | Byte offset within the partition. |
| dst | Destination buffer. |
| size | Number of bytes to read. |
| std::system_error | on failure. |
Definition at line 255 of file partition.hpp.
References size(), try_read(), and idfxx::unwrap().
Reads data from the partition without decryption.
| offset | Byte offset within the partition. |
| dst | Destination span. |
| std::system_error | on failure. |
Definition at line 312 of file partition.hpp.
References try_read_raw(), and idfxx::unwrap().
Reads data from the partition without decryption.
| offset | Byte offset within the partition. |
| dst | Destination buffer. |
| size | Number of bytes to read. |
| std::system_error | on failure. |
Definition at line 301 of file partition.hpp.
References size(), try_read_raw(), and idfxx::unwrap().
|
inline |
Returns true if the partition is read-only.
Definition at line 235 of file partition.hpp.
|
inline |
Computes the SHA-256 hash of the partition contents.
| std::system_error | on failure. |
Definition at line 358 of file partition.hpp.
References try_sha256(), and idfxx::unwrap().
|
inline |
Returns the partition size in bytes.
Definition at line 223 of file partition.hpp.
Referenced by erase_range(), read(), read_raw(), write(), and write_raw().
|
inline |
Returns the partition subtype.
Definition at line 217 of file partition.hpp.
Erases a range of the partition.
Both offset and size must be aligned to erase_size().
| offset | Byte offset within the partition (must be erase-aligned). |
| size | Number of bytes to erase (must be erase-aligned). |
Referenced by erase_range().
|
static |
Finds the first partition matching the given criteria.
| type | Partition type to match, or type::any for all types. |
| subtype | Partition subtype to match, or subtype::any for all subtypes. |
| label | Optional partition label to match. Empty matches all labels. |
| idfxx::errc::not_found | if no partition matches the criteria. |
Finds the first partition with the given label.
Searches across all partition types and subtypes.
| label | Partition label to match. |
| idfxx::errc::not_found | if no partition matches. |
| result< mmap_handle > idfxx::partition::try_mmap | ( | size_t | offset, |
| size_t | size, | ||
| enum mmap_memory | memory = mmap_memory::data |
||
| ) | const |
Memory-maps a region of the partition.
| offset | Byte offset within the partition (must be aligned to 0x10000 for data, or SPI_FLASH_MMU_PAGE_SIZE for instruction memory). |
| size | Number of bytes to map. |
| memory | Memory type to map to. |
Referenced by mmap().
Reads data from the partition with decryption if applicable.
| offset | Byte offset within the partition. |
| dst | Destination span. |
Reads data from the partition without decryption.
| offset | Byte offset within the partition. |
| dst | Destination span. |
Reads data from the partition without decryption.
| offset | Byte offset within the partition. |
| dst | Destination buffer. |
| size | Number of bytes to read. |
Referenced by read_raw(), and read_raw().
Computes the SHA-256 hash of the partition contents.
Referenced by sha256().
Writes data to the partition with encryption if applicable.
| offset | Byte offset within the partition. |
| src | Source span. |
Writes data to the partition without encryption.
| offset | Byte offset within the partition. |
| src | Source buffer. |
| size | Number of bytes to write. |
Referenced by write_raw(), and write_raw().
Writes data to the partition without encryption.
| offset | Byte offset within the partition. |
| src | Source span. |
|
inline |
Returns the partition type.
Definition at line 214 of file partition.hpp.
Writes data to the partition with encryption if applicable.
| offset | Byte offset within the partition. |
| src | Source buffer. |
| size | Number of bytes to write. |
| std::system_error | on failure. |
Definition at line 278 of file partition.hpp.
References size(), try_write(), and idfxx::unwrap().
Writes data to the partition with encryption if applicable.
| offset | Byte offset within the partition. |
| src | Source span. |
| std::system_error | on failure. |
Definition at line 289 of file partition.hpp.
References try_write(), and idfxx::unwrap().
Writes data to the partition without encryption.
| offset | Byte offset within the partition. |
| src | Source buffer. |
| size | Number of bytes to write. |
| std::system_error | on failure. |
Definition at line 324 of file partition.hpp.
References size(), try_write_raw(), and idfxx::unwrap().
Writes data to the partition without encryption.
| offset | Byte offset within the partition. |
| src | Source span. |
| std::system_error | on failure. |
Definition at line 335 of file partition.hpp.
References try_write_raw(), and idfxx::unwrap().