Select one of the symbols to view example projects that use it.
 
Outline
#include "esp_partition.h"
#include "nvs_partition_manager.hpp"
#include "nvs_partition_lookup.hpp"
#include "nvs_internal.h"
#include "nvs_encrypted_partition.hpp"
nvs
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
include
private_include
src
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/nvs_flash/src/nvs_partition_manager.cpp
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include "esp_partition.h" #include "nvs_partition_manager.hpp" #include "nvs_partition_lookup.hpp" #include "nvs_internal.h" #ifndef LINUX_TARGET #include "nvs_encrypted_partition.hpp" #endif // ! LINUX_TARGET namespace nvs { NVSPartitionManager* NVSPartitionManager::instance = nullptr; NVSPartitionManager* NVSPartitionManager::get_instance() { if (!instance) { instance = new (std::nothrow) NVSPartitionManager(); }{...} return instance; }{ ... } #ifdef ESP_PLATFORM esp_err_t NVSPartitionManager::init_partition(const char *partition_label) { if (strlen(partition_label) > NVS_PART_NAME_MAX_SIZE) { return ESP_ERR_INVALID_ARG; }{...} uint32_t size; const uint32_t sec_size = esp_partition_get_main_flash_sector_size(); Storage* mStorage; mStorage = lookup_storage_from_name(partition_label); if (mStorage) { return ESP_OK; }{...} NVS_ASSERT_OR_RETURN(sec_size != 0, ESP_FAIL); NVSPartition *p = nullptr; esp_err_t result = partition_lookup::lookup_nvs_partition(partition_label, &p); if (result != ESP_OK) { goto error; }{...} size = p->get_size(); result = init_custom(p, 0, size / sec_size); if (result != ESP_OK) { goto error; }{...} nvs_partition_list.push_back(p); return ESP_OK; error: delete p; return result; }{ ... } /* ... */#endif // ESP_PLATFORM esp_err_t NVSPartitionManager::init_custom(Partition *partition, uint32_t baseSector, uint32_t sectorCount) { Storage* new_storage = nullptr; Storage* storage = lookup_storage_from_name(partition->get_partition_name()); if (storage == nullptr) { new_storage = new (std::nothrow) Storage(partition); if (new_storage == nullptr) { return ESP_ERR_NO_MEM; }{...} storage = new_storage; }{...} else { // if storage was initialized already, we don't need partition and hence delete it for (auto it = nvs_partition_list.begin(); it != nvs_partition_list.end(); ++it) { if (partition == it) { nvs_partition_list.erase(it); delete partition; break; }{...} }{...} }{...} esp_err_t err = storage->init(baseSector, sectorCount); if (new_storage != nullptr) { if (err == ESP_OK) { nvs_storage_list.push_back(new_storage); }{...} else { delete new_storage; }{...} }{...} return err; }{ ... } #ifdef ESP_PLATFORM esp_err_t NVSPartitionManager::secure_init_partition(const char *part_name, nvs_sec_cfg_t* cfg) { if (strlen(part_name) > NVS_PART_NAME_MAX_SIZE) { return ESP_ERR_INVALID_ARG; }{...} Storage* mStorage; mStorage = lookup_storage_from_name(part_name); if (mStorage != nullptr) { return ESP_OK; }{...} NVSPartition *p; esp_err_t result; if (cfg != nullptr) { result = partition_lookup::lookup_nvs_encrypted_partition(part_name, cfg, &p); }{...} else { result = partition_lookup::lookup_nvs_partition(part_name, &p); }{...} if (result != ESP_OK) { return result; }{...} uint32_t size = p->get_size(); const uint32_t sec_size = esp_partition_get_main_flash_sector_size(); result = init_custom(p, 0, size / sec_size); if (result != ESP_OK) { delete p; return result; }{...} nvs_partition_list.push_back(p); return ESP_OK; }{ ... } /* ... */#endif // ESP_PLATFORM esp_err_t NVSPartitionManager::deinit_partition(const char *partition_label) { Storage* storage = lookup_storage_from_name(partition_label); if (!storage) { return ESP_ERR_NVS_NOT_INITIALIZED; }{...} /* Clean up handles related to the storage being deinitialized */ for (auto it = nvs_handles.begin(); it != nvs_handles.end(); ++it) { if (it->mStoragePtr == storage) { it->valid = false; nvs_handles.erase(it); }{...} }{...} /* Finally delete the storage and its partition */ nvs_storage_list.erase(storage); delete storage; for (auto it = nvs_partition_list.begin(); it != nvs_partition_list.end(); ++it) { if (strcmp(it->get_partition_name(), partition_label) == 0) { NVSPartition *p = it; nvs_partition_list.erase(it); delete p; break; }{...} }{...} return ESP_OK; }{ ... } esp_err_t NVSPartitionManager::open_handle(const char *part_name, const char *ns_name, nvs_open_mode_t open_mode, NVSHandleSimple** handle) { uint8_t nsIndex; Storage* sHandle; if (handle == nullptr) { return ESP_ERR_INVALID_ARG; }{...} if (nvs_storage_list.empty()) { return ESP_ERR_NVS_NOT_INITIALIZED; }{...} sHandle = lookup_storage_from_name(part_name); if (sHandle == nullptr) { return ESP_ERR_NVS_PART_NOT_FOUND; }{...} if (open_mode == NVS_READWRITE && const_cast<Partition*>(sHandle->getPart())->get_readonly()) { return ESP_ERR_NOT_ALLOWED; }{...} esp_err_t err = sHandle->createOrOpenNamespace(ns_name, open_mode == NVS_READWRITE, nsIndex); if (err != ESP_OK) { return err; }{...} NVSHandleSimple* new_handle = new (std::nothrow) NVSHandleSimple(open_mode==NVS_READONLY, nsIndex, sHandle); if (new_handle == nullptr) { return ESP_ERR_NO_MEM; }{...} nvs_handles.push_back(new_handle); *handle = new_handle; return ESP_OK; }{ ... } esp_err_t NVSPartitionManager::close_handle(NVSHandleSimple* handle) { for (auto it = nvs_handles.begin(); it != nvs_handles.end(); ++it) { if (it == intrusive_list<NVSHandleSimple>::iterator(handle)) { nvs_handles.erase(it); return ESP_OK; }{...} }{...} return ESP_ERR_NVS_INVALID_HANDLE; }{ ... } size_t NVSPartitionManager::open_handles_size() { return nvs_handles.size(); }{ ... } Storage* NVSPartitionManager::lookup_storage_from_name(const char* name) { auto it = find_if(begin(nvs_storage_list), end(nvs_storage_list), [=](Storage& e) -> bool { return (strcmp(e.getPartName(), name) == 0); }{...}); if (it == end(nvs_storage_list)) { return nullptr; }{...} return it; }{ ... } }{...} // nvs
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.