27#include <esp_partition.h>
123#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
188 [[
nodiscard]]
static std::vector<partition>
244#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
568 static_assert(std::is_const_v<T>,
"T must be const-qualified; mapped partition memory is read-only");
569 return {
static_cast<T*
>(_ptr), _size /
sizeof(
T)};
586 const void* _ptr =
nullptr;
591#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
A memory-mapped partition region.
esp_partition_mmap_handle_t release() noexcept
Releases ownership without unmapping.
std::span< T > as_span() const
Returns a typed span over the mapped memory region.
mmap_handle(mmap_handle &&other) noexcept
Move constructor.
mmap_handle(const mmap_handle &)=delete
mmap_handle & operator=(const mmap_handle &)=delete
const void * data() const
Returns a pointer to the mapped memory region.
mmap_handle & operator=(mmap_handle &&other) noexcept
Move assignment.
size_t size() const
Returns the size of the mapped region in bytes.
mmap_handle()=default
Constructs an invalid (unmapped) handle.
enum subtype subtype() const
Returns the partition subtype.
static constexpr partition from_handle(const esp_partition_t *handle)
Constructs a partition from an ESP-IDF partition handle.
void read(size_t offset, void *dst, size_t size) const
Reads data from the partition with decryption if applicable.
partition(partition &&)=default
std::string_view label() const
Returns the partition label.
result< void > try_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 write(size_t offset, const void *src, size_t size)
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.
partition(const partition &)=default
uint32_t erase_size() const
Returns the erase block size.
mmap_memory
Memory type for memory-mapped partition access.
@ inst
Map to instruction memory, allows only 4-byte-aligned access.
@ data
Map to data memory, allows byte-aligned access.
static partition find(std::string_view label)
Finds the first partition with the given label.
static partition find(enum type type, enum subtype subtype=subtype::any, std::string_view label={})
Finds the first partition matching the given criteria.
result< void > try_erase_range(size_t offset, size_t size)
Erases a range of the partition.
result< void > try_read_raw(size_t offset, std::span< uint8_t > dst) const
Reads data from the partition without decryption.
bool check_identity(const partition &other) const
Checks if two partitions have identical contents by comparing SHA-256 hashes.
void erase_range(size_t offset, size_t size)
Erases a range of the partition.
void 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, std::span< const uint8_t > src)
Writes data to the partition with encryption if applicable.
void 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.
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.
result< void > try_read(size_t offset, void *dst, size_t size) const
Reads data from the partition with decryption if applicable.
@ partition_table
Partition table.
@ any
Match any partition type (for searching)
@ bootloader
Bootloader partition.
@ app
Application partition.
mmap_handle mmap(size_t offset, size_t size, enum mmap_memory memory=mmap_memory::data) const
Memory-maps a region of the partition.
bool encrypted() const
Returns true if the partition is encrypted.
constexpr bool operator==(const partition &) const noexcept=default
Compares two partitions for equality.
static result< partition > try_find(std::string_view label)
Finds the first partition with the given label.
subtype
Partition subtype.
@ app_ota_5
OTA application slot 5.
@ data_nvs_keys
NVS encryption keys.
@ app_ota_0
OTA application slot 0.
@ any
Match any subtype (for searching)
@ partition_table_primary
Primary partition table.
@ app_ota_14
OTA application slot 14.
@ app_ota_10
OTA application slot 10.
@ app_ota_3
OTA application slot 3.
@ app_ota_9
OTA application slot 9.
@ app_factory
Factory application.
@ data_efuse_em
eFuse emulation data
@ data_coredump
Core dump data.
@ app_ota_4
OTA application slot 4.
@ bootloader_recovery
Recovery bootloader.
@ app_ota_13
OTA application slot 13.
@ partition_table_ota
OTA partition table.
@ data_undefined
Undefined data.
@ bootloader_primary
Primary bootloader.
@ app_ota_2
OTA application slot 2.
@ app_ota_8
OTA application slot 8.
@ data_esphttpd
ESPHTTPD data.
@ app_ota_6
OTA application slot 6.
@ app_test
Test application.
@ app_ota_11
OTA application slot 11.
@ app_ota_1
OTA application slot 1.
@ app_ota_15
OTA application slot 15.
@ data_littlefs
LittleFS data.
@ bootloader_ota
OTA bootloader.
@ app_ota_12
OTA application slot 12.
@ data_fat
FAT filesystem data.
@ app_ota_7
OTA application slot 7.
@ data_spiffs
SPIFFS data.
constexpr const esp_partition_t * idf_handle() const
Returns the underlying ESP-IDF partition handle.
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.
uint32_t address() const
Returns the starting address in flash.
result< void > try_write(size_t offset, const void *src, size_t size)
Writes data to the partition with encryption if applicable.
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.
enum type type() const
Returns the partition type.
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.
std::array< uint8_t, 32 > sha256() const
Computes the SHA-256 hash of the partition contents.
bool readonly() const
Returns true if the partition is read-only.
result< std::array< uint8_t, 32 > > try_sha256() const
Computes the SHA-256 hash of the partition contents.
result< void > try_read(size_t offset, std::span< uint8_t > dst) const
Reads data from the partition with decryption if applicable.
partition & operator=(partition &&)=default
uint32_t size() const
Returns the partition size in bytes.
partition & operator=(const partition &)=default
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
constexpr enum partition::subtype app_ota(unsigned i)
Computes an OTA app subtype from a slot index.