VSF Documented
esp_partition.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_ESPIDF_ESP_PARTITION_H__
19#define __VSF_ESPIDF_ESP_PARTITION_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include <stdint.h>
24#include <stdbool.h>
25#include <stddef.h>
26
27#include "esp_err.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*============================ MACROS ========================================*/
34
35/* Label storage is fixed at 16 bytes in the ESP-IDF partition table binary,
36 * plus one byte NUL terminator in the runtime struct.
37 */
38#define ESP_PARTITION_LABEL_MAX 16
39
40/*============================ TYPES =========================================*/
41
42/* Partition top-level type. Matches ESP-IDF v5.x. */
43typedef enum {
48
49/* Partition subtype. Only the values consumed by the currently implemented
50 * upstream modules are defined; additional subtypes can be added as new
51 * modules come online.
52 */
53typedef enum {
54 /* APP subtypes. */
61
62 /* DATA subtypes. */
74
77
78/* Flash / memory-capability hint for esp_partition_mmap(). This enum exists
79 * in the ESP-IDF public API but in this shim only SPI/DATA/INSTRUCTION are
80 * distinguished; all are collapsed onto the root mal's local buffer.
81 */
82typedef enum {
86
88
89/* Forward declarations. */
90struct vk_mal_t;
91
92/* Runtime description of one partition. Field layout follows ESP-IDF so that
93 * application code that peeks into it (type/subtype/address/size/label)
94 * keeps working.
95 *
96 * Fields specific to this shim:
97 * mal internal vk_mim_mal_t slice over the root mal. Callers MUST NOT
98 * dereference this field; it is exposed here only because the
99 * public esp_partition_t must be a complete type.
100 */
101typedef struct esp_partition_t {
110 /* Opaque back-end handle (vk_mim_mal_t *). */
111 void *mal;
113
114/* Opaque iterator handle returned by esp_partition_find(). */
116
117/*============================ PROTOTYPES ====================================*/
118
119/* --- Discovery --------------------------------------------------------- */
120
121/* Create an iterator over partitions matching (type, subtype, label).
122 * A NULL label matches every label. subtype == ESP_PARTITION_SUBTYPE_ANY
123 * matches every subtype; type == ESP_PARTITION_TYPE_ANY matches every type.
124 *
125 * The iterator must be released with esp_partition_iterator_release().
126 * Returns NULL if no partition matches or if the partition sub-system has
127 * not been initialised.
128 */
131 const char *label);
132
133/* Convenience form returning the first match directly, or NULL. The
134 * returned pointer is owned by the sub-system and stays valid until the
135 * partition is deregistered.
136 */
139 const char *label);
140
144
145/* Identity check (two pointers describe the same partition). */
147 const esp_partition_t *b);
148
149/* --- I/O --------------------------------------------------------------- */
150
151/* Synchronous read / write / erase over the partition's address space.
152 * All offsets are relative to the start of the partition; bounds are
153 * validated against partition->size. Must be called from a stack-owner
154 * thread (vsf_thread_t): the underlying vk_mal_t I/O is a peda subcall
155 * and only short-circuits to synchronous completion in that context.
156 */
157extern esp_err_t esp_partition_read(const esp_partition_t *partition,
158 size_t src_offset, void *dst, size_t size);
159extern esp_err_t esp_partition_write(const esp_partition_t *partition,
160 size_t dst_offset, const void *src,
161 size_t size);
163 size_t offset, size_t size);
164
165/* read_raw / write_raw on ESP-IDF bypass the flash encryption layer. This
166 * shim has no flash encryption, so they are aliases of read / write and
167 * are provided for API compatibility only.
168 */
169extern esp_err_t esp_partition_read_raw(const esp_partition_t *partition,
170 size_t src_offset, void *dst,
171 size_t size);
173 size_t dst_offset, const void *src,
174 size_t size);
175
176/* --- Memory mapping ---------------------------------------------------- */
177
178/* Map a [offset, offset+size) region of the partition into a directly
179 * addressable pointer. Succeeds only when the root mal advertises the
180 * VSF_MAL_LOCAL_BUFFER feature (otherwise returns ESP_ERR_NOT_SUPPORTED):
181 * mmap is a hardware capability and not every back-end provides it.
182 */
183extern esp_err_t esp_partition_mmap(const esp_partition_t *partition,
184 size_t offset, size_t size,
186 const void **out_ptr,
187 esp_partition_mmap_handle_t *out_handle);
189
190/* --- Verification ------------------------------------------------------ */
191
192/* Re-validate a partition pointer against the live registry. Returns the
193 * canonical partition pointer on success, NULL if the pointer no longer
194 * references a registered partition.
195 */
196extern const esp_partition_t * esp_partition_verify(const esp_partition_t *partition);
197
198/* --- Runtime registration --------------------------------------------- */
199
200/* Register an externally-located partition at runtime. The backing storage
201 * is the sub-system's configured root mal; `flash_chip` is accepted for API
202 * parity but ignored (the shim has a single root store).
203 *
204 * Returns ESP_OK on success; ESP_ERR_NO_MEM when the dynamic-registration
205 * slot pool is exhausted; ESP_ERR_INVALID_ARG on bad arguments;
206 * ESP_ERR_INVALID_STATE when dynamic registration is disabled at build
207 * time (VSF_ESPIDF_CFG_PARTITION_DYNAMIC == DISABLED).
208 */
209extern esp_err_t esp_partition_register_external(void *flash_chip,
210 size_t offset, size_t size,
211 const char *label,
214 const esp_partition_t **out_partition);
216
217#ifdef __cplusplus
218}
219#endif
220
221#endif /* __VSF_ESPIDF_ESP_PARTITION_H__ */
mal class
Definition vsf_mal.h:168
int esp_err_t
Definition esp_err.h:41
esp_err_t esp_partition_write(const esp_partition_t *partition, size_t dst_offset, const void *src, size_t size)
Definition esp_partition_port.c:381
uint32_t esp_partition_mmap_handle_t
Definition esp_partition.h:87
esp_err_t esp_partition_write_raw(const esp_partition_t *partition, size_t dst_offset, const void *src, size_t size)
Definition esp_partition_port.c:440
esp_err_t esp_partition_read(const esp_partition_t *partition, size_t src_offset, void *dst, size_t size)
Definition esp_partition_port.c:363
void esp_partition_iterator_release(esp_partition_iterator_t iterator)
Definition esp_partition_port.c:336
const esp_partition_t * esp_partition_get(esp_partition_iterator_t iterator)
Definition esp_partition_port.c:306
bool esp_partition_check_identity(const esp_partition_t *a, const esp_partition_t *b)
Definition esp_partition_port.c:344
esp_err_t esp_partition_deregister_external(const esp_partition_t *partition)
Definition esp_partition_port.c:552
esp_err_t esp_partition_read_raw(const esp_partition_t *partition, size_t src_offset, void *dst, size_t size)
Definition esp_partition_port.c:433
const esp_partition_t * esp_partition_verify(const esp_partition_t *partition)
Definition esp_partition_port.c:491
#define ESP_PARTITION_LABEL_MAX
Definition esp_partition.h:38
esp_partition_iterator_t esp_partition_find(esp_partition_type_t type, esp_partition_subtype_t subtype, const char *label)
Definition esp_partition_port.c:255
struct esp_partition_iterator_opaque_t * esp_partition_iterator_t
Definition esp_partition.h:115
esp_err_t esp_partition_mmap(const esp_partition_t *partition, size_t offset, size_t size, esp_partition_mmap_memory_t memory, const void **out_ptr, esp_partition_mmap_handle_t *out_handle)
Definition esp_partition_port.c:449
const esp_partition_t * esp_partition_find_first(esp_partition_type_t type, esp_partition_subtype_t subtype, const char *label)
Definition esp_partition_port.c:293
esp_partition_mmap_memory_t
Definition esp_partition.h:82
@ ESP_PARTITION_MMAP_INST
Definition esp_partition.h:84
@ ESP_PARTITION_MMAP_DATA
Definition esp_partition.h:83
esp_partition_type_t
Definition esp_partition.h:43
@ ESP_PARTITION_TYPE_ANY
Definition esp_partition.h:46
@ ESP_PARTITION_TYPE_DATA
Definition esp_partition.h:45
@ ESP_PARTITION_TYPE_APP
Definition esp_partition.h:44
esp_partition_iterator_t esp_partition_next(esp_partition_iterator_t iterator)
Definition esp_partition_port.c:318
esp_err_t esp_partition_register_external(void *flash_chip, size_t offset, size_t size, const char *label, esp_partition_type_t type, esp_partition_subtype_t subtype, const esp_partition_t **out_partition)
Definition esp_partition_port.c:508
esp_err_t esp_partition_erase_range(const esp_partition_t *partition, size_t offset, size_t size)
Definition esp_partition_port.c:402
void esp_partition_munmap(esp_partition_mmap_handle_t handle)
Definition esp_partition_port.c:482
esp_partition_subtype_t
Definition esp_partition.h:53
@ ESP_PARTITION_SUBTYPE_DATA_NVS
Definition esp_partition.h:65
@ ESP_PARTITION_SUBTYPE_APP_OTA_1
Definition esp_partition.h:58
@ ESP_PARTITION_SUBTYPE_APP_OTA_MIN
Definition esp_partition.h:56
@ ESP_PARTITION_SUBTYPE_APP_TEST
Definition esp_partition.h:60
@ ESP_PARTITION_SUBTYPE_ANY
Definition esp_partition.h:75
@ ESP_PARTITION_SUBTYPE_APP_FACTORY
Definition esp_partition.h:55
@ ESP_PARTITION_SUBTYPE_DATA_PHY
Definition esp_partition.h:64
@ ESP_PARTITION_SUBTYPE_APP_OTA_0
Definition esp_partition.h:57
@ ESP_PARTITION_SUBTYPE_DATA_EFUSE_EM
Definition esp_partition.h:68
@ ESP_PARTITION_SUBTYPE_DATA_ESPHTTPD
Definition esp_partition.h:70
@ ESP_PARTITION_SUBTYPE_DATA_LITTLEFS
Definition esp_partition.h:73
@ ESP_PARTITION_SUBTYPE_DATA_UNDEFINED
Definition esp_partition.h:69
@ ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS
Definition esp_partition.h:67
@ ESP_PARTITION_SUBTYPE_DATA_FAT
Definition esp_partition.h:71
@ ESP_PARTITION_SUBTYPE_APP_OTA_MAX
Definition esp_partition.h:59
@ ESP_PARTITION_SUBTYPE_DATA_SPIFFS
Definition esp_partition.h:72
@ ESP_PARTITION_SUBTYPE_DATA_COREDUMP
Definition esp_partition.h:66
@ ESP_PARTITION_SUBTYPE_DATA_OTA
Definition esp_partition.h:63
unsigned uint32_t
Definition stdint.h:9
Definition esp_partition_port.c:85
esp_partition_subtype_t subtype
Definition esp_partition_port.c:87
char label[ESP_PARTITION_LABEL_MAX+1]
Definition esp_partition_port.c:88
Definition esp_partition.h:101
uint32_t address
Definition esp_partition.h:104
esp_partition_type_t type
Definition esp_partition.h:102
bool encrypted
Definition esp_partition.h:108
esp_partition_subtype_t subtype
Definition esp_partition.h:103
uint32_t size
Definition esp_partition.h:105
uint32_t erase_size
Definition esp_partition.h:106
void * mal
Definition esp_partition.h:111
bool readonly
Definition esp_partition.h:109
char label[ESP_PARTITION_LABEL_MAX+1]
Definition esp_partition.h:107
vk_av_control_type_t type
Definition vsf_audio.h:170
uint64_t offset
Definition vsf_memfs.h:49
uint32_t size
Definition vsf_memfs.h:50
Generated from commit: vsfteam/vsf@015f4d1