优化了启动顺序和 storage使用不规范问题
This commit is contained in:
@@ -26,6 +26,7 @@ static const char *TAG = "app_comp_boot";
|
||||
|
||||
typedef enum {
|
||||
APP_COMPOSITION_BOOT_STAGE_POWER_HOLD = 1,
|
||||
APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
APP_COMPOSITION_BOOT_STAGE_AUDIO_INIT,
|
||||
APP_COMPOSITION_BOOT_STAGE_BOOT_SOUND,
|
||||
APP_COMPOSITION_BOOT_STAGE_AUDIO_READY,
|
||||
@@ -33,7 +34,6 @@ typedef enum {
|
||||
APP_COMPOSITION_BOOT_STAGE_LCD_RENDER_LOOP,
|
||||
APP_COMPOSITION_BOOT_STAGE_PLATFORM_DOMAIN,
|
||||
APP_COMPOSITION_BOOT_STAGE_TURNTABLE_CALIBRATION,
|
||||
APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
APP_COMPOSITION_BOOT_STAGE_WIFI_BOOTSTRAP,
|
||||
APP_COMPOSITION_BOOT_STAGE_RUNTIME_WORKERS,
|
||||
APP_COMPOSITION_BOOT_STAGE_NETWORK_SERVICES,
|
||||
@@ -70,6 +70,15 @@ static esp_err_t app_composition_run_plan_a_boot_sequence(void)
|
||||
"power_hold",
|
||||
"already_asserted_by_platform_core");
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
"storage_prepare",
|
||||
"control_plane_prepare_runtime_storage");
|
||||
esp_err_t err = control_plane_prepare_runtime_storage();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Runtime storage prepare failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_AUDIO_INIT,
|
||||
"audio_init",
|
||||
"boot_sound_policy_begin");
|
||||
@@ -124,7 +133,7 @@ static esp_err_t app_composition_run_plan_a_boot_sequence(void)
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_PLATFORM_DOMAIN,
|
||||
"platform_domain",
|
||||
"control_plane_init");
|
||||
esp_err_t err = control_plane_init();
|
||||
err = control_plane_init();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "control_plane_init failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
@@ -157,15 +166,6 @@ static esp_err_t app_composition_run_plan_a_boot_sequence(void)
|
||||
"disabled_by_config");
|
||||
#endif
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
"storage_prepare",
|
||||
"control_plane_prepare_runtime_storage");
|
||||
err = control_plane_prepare_runtime_storage();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Runtime storage prepare failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_WIFI_BOOTSTRAP,
|
||||
"wifi_bootstrap",
|
||||
"control_plane_bootstrap_connectivity");
|
||||
|
||||
@@ -184,13 +184,8 @@ esp_err_t control_plane_bootstrap_connectivity(const char *seed_ssid,
|
||||
(seed_ssid != NULL && seed_ssid[0] != '\0') ? seed_ssid : "<empty>",
|
||||
connect_timeout_ms);
|
||||
|
||||
esp_err_t err = control_plane_prepare_runtime_storage();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
control_plane_register_wifi_behavior_hooks();
|
||||
err = domain_runtime_wifi_portal_init_defaults(seed_ssid, seed_password);
|
||||
esp_err_t err = domain_runtime_wifi_portal_init_defaults(seed_ssid, seed_password);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ typedef struct {
|
||||
|
||||
esp_err_t platform_init(void);
|
||||
esp_err_t platform_prepare_storage(void);
|
||||
bool platform_storage_is_ready(void);
|
||||
esp_err_t platform_mount_littlefs(void);
|
||||
esp_err_t platform_mount_logfs(void);
|
||||
void platform_read_device_identity(char *device_id,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
static const char *TAG = "platform_core";
|
||||
static bool s_initialized;
|
||||
static bool s_storage_ready;
|
||||
static const char *k_identity_nvs_namespace = "ota";
|
||||
|
||||
static const char *const s_known_nvs_namespaces[] = {
|
||||
@@ -134,6 +135,10 @@ esp_err_t platform_init(void)
|
||||
|
||||
esp_err_t platform_prepare_storage(void)
|
||||
{
|
||||
if (s_storage_ready) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_LOGW(TAG, "Default NVS init failed with %s; erasing default NVS partition",
|
||||
@@ -145,11 +150,17 @@ esp_err_t platform_prepare_storage(void)
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
s_storage_ready = true;
|
||||
platform_log_nvs_stats();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
bool platform_storage_is_ready(void)
|
||||
{
|
||||
return s_storage_ready;
|
||||
}
|
||||
|
||||
void platform_read_device_identity(char *device_id,
|
||||
size_t device_id_len,
|
||||
char *serial_number,
|
||||
|
||||
@@ -6,11 +6,22 @@
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
|
||||
static const char *TAG = "platform_storage";
|
||||
|
||||
static esp_err_t ensure_storage_ready(const char *op)
|
||||
{
|
||||
if (platform_storage_is_ready()) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
ESP_LOGW(TAG, "%s rejected because storage is not prepared", op != NULL ? op : "storage operation");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
static esp_err_t open_storage_readonly(const char *ns, nvs_handle_t *out_handle)
|
||||
{
|
||||
if (ns == NULL || out_handle == NULL) {
|
||||
@@ -37,6 +48,7 @@ esp_err_t platform_storage_set_blob(const char *ns, const char *key, const void
|
||||
if (ns == NULL || key == NULL || data == NULL || len == 0U) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("set_blob"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
@@ -61,6 +73,7 @@ esp_err_t platform_storage_set_string(const char *ns, const char *key, const cha
|
||||
if (ns == NULL || key == NULL || value == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("set_string"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
@@ -85,6 +98,7 @@ esp_err_t platform_storage_set_u8(const char *ns, const char *key, uint8_t value
|
||||
if (ns == NULL || key == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("set_u8"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
@@ -109,6 +123,7 @@ esp_err_t platform_storage_set_i8(const char *ns, const char *key, int8_t value)
|
||||
if (ns == NULL || key == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("set_i8"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
@@ -140,6 +155,7 @@ esp_err_t platform_storage_get_blob(const char *ns,
|
||||
if (ns == NULL || key == NULL || out == NULL || out_len == 0U) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_blob"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -171,6 +187,7 @@ esp_err_t platform_storage_get_u8(const char *ns, const char *key, uint8_t *out)
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_u8"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -188,6 +205,7 @@ esp_err_t platform_storage_get_i8(const char *ns, const char *key, int8_t *out)
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_i8"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -205,6 +223,7 @@ esp_err_t platform_storage_get_u32(const char *ns, const char *key, uint32_t *ou
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_u32"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -222,6 +241,7 @@ esp_err_t platform_storage_get_u64(const char *ns, const char *key, uint64_t *ou
|
||||
if (ns == NULL || key == NULL || out == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_u64"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -249,6 +269,7 @@ esp_err_t platform_storage_get_string(const char *ns,
|
||||
if (ns == NULL || key == NULL || out == NULL || out_len == 0U) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("get_string"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = open_storage_readonly(ns, &handle);
|
||||
@@ -280,6 +301,7 @@ esp_err_t platform_storage_erase(const char *ns, const char *key)
|
||||
if (ns == NULL || key == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(ensure_storage_ready("erase"), TAG, "storage not ready");
|
||||
|
||||
nvs_handle_t handle = 0;
|
||||
esp_err_t err = nvs_open(ns, NVS_READWRITE, &handle);
|
||||
|
||||
Reference in New Issue
Block a user