|
|
|
@ -240,6 +240,8 @@ static size_t default_env_set_size = 0;
|
|
|
|
static bool init_ok = false;
|
|
|
|
static bool init_ok = false;
|
|
|
|
/* request a GC check */
|
|
|
|
/* request a GC check */
|
|
|
|
static bool gc_request = false;
|
|
|
|
static bool gc_request = false;
|
|
|
|
|
|
|
|
/* is in recovery check status when first reboot */
|
|
|
|
|
|
|
|
static bool in_recovery_check = false;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef EF_ENV_USING_CACHE
|
|
|
|
#ifdef EF_ENV_USING_CACHE
|
|
|
|
/* ENV cache table */
|
|
|
|
/* ENV cache table */
|
|
|
|
@ -482,6 +484,14 @@ static uint32_t find_next_env_addr(uint32_t start, uint32_t end)
|
|
|
|
uint32_t start_bak = start, i;
|
|
|
|
uint32_t start_bak = start, i;
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t magic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef EF_ENV_USING_CACHE
|
|
|
|
|
|
|
|
uint32_t empty_env;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (get_sector_from_cache(EF_ALIGN_DOWN(start, SECTOR_SIZE), &empty_env) && start == empty_env) {
|
|
|
|
|
|
|
|
return FAILED_ADDR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EF_ENV_USING_CACHE */
|
|
|
|
|
|
|
|
|
|
|
|
for (; start < end; start += (sizeof(buf) - sizeof(uint32_t))) {
|
|
|
|
for (; start < end; start += (sizeof(buf) - sizeof(uint32_t))) {
|
|
|
|
ef_port_read(start, (uint32_t *) buf, sizeof(buf));
|
|
|
|
ef_port_read(start, (uint32_t *) buf, sizeof(buf));
|
|
|
|
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
|
|
|
|
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
|
|
|
|
@ -1035,12 +1045,12 @@ static EfErrCode del_env(const char *key, env_meta_data_t old_env, bool complete
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
result = write_status(old_env->addr.start, status_table, ENV_STATUS_NUM, ENV_DELETED);
|
|
|
|
result = write_status(old_env->addr.start, status_table, ENV_STATUS_NUM, ENV_DELETED);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef EF_ENV_USING_CACHE
|
|
|
|
|
|
|
|
if (!last_is_complete_del && result == EF_NO_ERR) {
|
|
|
|
if (!last_is_complete_del && result == EF_NO_ERR) {
|
|
|
|
|
|
|
|
#ifdef EF_ENV_USING_CACHE
|
|
|
|
/* only delete the ENV in flash and cache when only using del_env(key, env, true) in ef_del_env() */
|
|
|
|
/* only delete the ENV in flash and cache when only using del_env(key, env, true) in ef_del_env() */
|
|
|
|
update_env_cache(key, strlen(key), FAILED_ADDR);
|
|
|
|
update_env_cache(key, strlen(key), FAILED_ADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EF_ENV_USING_CACHE */
|
|
|
|
#endif /* EF_ENV_USING_CACHE */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
last_is_complete_del = false;
|
|
|
|
last_is_complete_del = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1071,14 +1081,16 @@ static EfErrCode move_env(env_meta_data_t env)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((env_addr = alloc_env(§or, env->len)) != FAILED_ADDR) {
|
|
|
|
if ((env_addr = alloc_env(§or, env->len)) != FAILED_ADDR) {
|
|
|
|
struct env_meta_data env_bak;
|
|
|
|
if (in_recovery_check) {
|
|
|
|
char name[EF_ENV_NAME_MAX + 1] = { 0 };
|
|
|
|
struct env_meta_data env_bak;
|
|
|
|
strncpy(name, env->name, env->name_len);
|
|
|
|
char name[EF_ENV_NAME_MAX + 1] = { 0 };
|
|
|
|
/* check the ENV in flash is already create success */
|
|
|
|
strncpy(name, env->name, env->name_len);
|
|
|
|
if (find_env_no_cache(name, &env_bak)) {
|
|
|
|
/* check the ENV in flash is already create success */
|
|
|
|
/* already create success, don't need to duplicate */
|
|
|
|
if (find_env_no_cache(name, &env_bak)) {
|
|
|
|
result = EF_NO_ERR;
|
|
|
|
/* already create success, don't need to duplicate */
|
|
|
|
goto __exit;
|
|
|
|
result = EF_NO_ERR;
|
|
|
|
|
|
|
|
goto __exit;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return EF_ENV_FULL;
|
|
|
|
return EF_ENV_FULL;
|
|
|
|
@ -1680,6 +1692,8 @@ EfErrCode ef_load_env(void)
|
|
|
|
|
|
|
|
|
|
|
|
/* lock the ENV cache */
|
|
|
|
/* lock the ENV cache */
|
|
|
|
ef_port_env_lock();
|
|
|
|
ef_port_env_lock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
in_recovery_check = true;
|
|
|
|
/* check all sector header */
|
|
|
|
/* check all sector header */
|
|
|
|
sector_iterator(§or, SECTOR_STORE_UNUSED, &check_failed_count, NULL, check_sec_hdr_cb, false);
|
|
|
|
sector_iterator(§or, SECTOR_STORE_UNUSED, &check_failed_count, NULL, check_sec_hdr_cb, false);
|
|
|
|
/* all sector header check failed */
|
|
|
|
/* all sector header check failed */
|
|
|
|
@ -1698,6 +1712,8 @@ __retry:
|
|
|
|
goto __retry;
|
|
|
|
goto __retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
in_recovery_check = false;
|
|
|
|
|
|
|
|
|
|
|
|
/* unlock the ENV cache */
|
|
|
|
/* unlock the ENV cache */
|
|
|
|
ef_port_env_unlock();
|
|
|
|
ef_port_env_unlock();
|
|
|
|
|
|
|
|
|
|
|
|
|