Skip to content

Commit

Permalink
fix: Fixed that rainmaker cannot work due to default the removal of r…
Browse files Browse the repository at this point in the history
…maker_mfg partition

- Use new mfg_nvs partition to storage the configurations of rainmaker
- Closes https://jira.espressif.com:8443/browse/ESPAT-1711
  • Loading branch information
ustccw committed Jul 27, 2023
1 parent 8c0eaf3 commit e47397a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/rainmaker/at_rainmaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,13 @@ esp_err_t esp_rmaker_factory_init(void)
return ESP_OK;
}

// manufacturing nvs partition is already initialized, and used for storing default esp-rainmaker configurations
at_mfg_params_storage_mode_t mode = at_get_mfg_params_storage_mode();
if (mode == AT_PARAMS_IN_MFG_NVS) {
esp_rmaker_storage_init_done = true;
return ESP_OK;
}

const esp_partition_t *partition = esp_at_custom_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, RAINMAKER_PRE_CFG_PARTITION);
esp_err_t err = nvs_flash_init_partition_ptr(partition);

Expand All @@ -2146,8 +2153,15 @@ void *esp_rmaker_factory_get(const char *key)
if ((err = nvs_open(RAINMAKER_PRE_NAMESPACE, NVS_READONLY, &handle)) == ESP_OK) {
ESP_LOGD(TAG, "NVS open for %s %s success", RAINMAKER_PRE_NAMESPACE, key);
} else {
if ((err = nvs_open_from_partition(RAINMAKER_PRE_CFG_PARTITION, RAINMAKER_PRE_NAMESPACE,
NVS_READONLY, &handle)) != ESP_OK) {
at_mfg_params_storage_mode_t mode = at_get_mfg_params_storage_mode();
const char *p_partition_name = NULL;
if (mode == AT_PARAMS_IN_MFG_NVS) {
extern const char *g_at_mfg_nvs_name;
p_partition_name = g_at_mfg_nvs_name;
} else {
p_partition_name = RAINMAKER_PRE_CFG_PARTITION;
}
if ((err = nvs_open_from_partition(p_partition_name, RAINMAKER_PRE_NAMESPACE, NVS_READONLY, &handle)) != ESP_OK) {
ESP_LOGD(TAG, "NVS open for %s %s %s failed with error %d", RAINMAKER_PRE_CFG_PARTITION, RAINMAKER_PRE_NAMESPACE, key, err);
return NULL;
}
Expand Down

0 comments on commit e47397a

Please sign in to comment.