Merge branch 'master' of https://github.com/zrw269113179/EasyFlash into iterator

# Conflicts:
#	easyflash/src/ef_env.c
pull/92/head
brand 6 years ago
commit 87c6562b99

@ -30,75 +30,24 @@
#ifndef EASYFLASH_H_ #ifndef EASYFLASH_H_
#define EASYFLASH_H_ #define EASYFLASH_H_
#include <ef_cfg.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <ef_cfg.h>
#include <ef_def.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* EasyFlash debug print function. Must be implement by user. */
#ifdef PRINT_DEBUG
#define EF_DEBUG(...) ef_log_debug(__FILE__, __LINE__, __VA_ARGS__)
#else
#define EF_DEBUG(...)
#endif
/* EasyFlash routine print function. Must be implement by user. */
#define EF_INFO(...) ef_log_info(__VA_ARGS__)
/* EasyFlash assert for developer. */
#define EF_ASSERT(EXPR) \
if (!(EXPR)) \
{ \
EF_DEBUG("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \
while (1); \
}
/**
* ENV version number defined by user.
* Please change it when your firmware add a new ENV to default_env_set.
*/
#ifndef EF_ENV_VER_NUM
#define EF_ENV_VER_NUM 0
#endif
/* EasyFlash software version number */
#define EF_SW_VERSION "4.0.99"
#define EF_SW_VERSION_NUM 0x40099
typedef struct _ef_env {
char *key;
void *value;
size_t value_len;
} ef_env, *ef_env_t;
/* EasyFlash error code */
typedef enum {
EF_NO_ERR,
EF_ERASE_ERR,
EF_READ_ERR,
EF_WRITE_ERR,
EF_ENV_NAME_ERR,
EF_ENV_NAME_EXIST,
EF_ENV_FULL,
EF_ENV_INIT_FAILED,
} EfErrCode;
/* the flash sector current status */
typedef enum {
EF_SECTOR_EMPTY,
EF_SECTOR_USING,
EF_SECTOR_FULL,
} EfSecrorStatus;
/* easyflash.c */ /* easyflash.c */
EfErrCode easyflash_init(void); EfErrCode easyflash_init(void);
#ifdef EF_USING_ENV #ifdef EF_USING_ENV
/* only supported on ef_env.c */ /* only supported on ef_env.c */
size_t ef_get_env_blob(const char *key, void *value_buf, size_t buf_len, size_t *saved_value_len); size_t ef_get_env_blob(const char *key, void *value_buf, size_t buf_len, size_t *saved_value_len);
bool ef_get_env_obj(const char *key, env_node_obj_t env);
size_t ef_read_env_value(env_node_obj_t env, uint8_t *value_buf, size_t buf_len);
EfErrCode ef_set_env_blob(const char *key, const void *value_buf, size_t buf_len); EfErrCode ef_set_env_blob(const char *key, const void *value_buf, size_t buf_len);
/* ef_env.c, ef_env_legacy_wl.c and ef_env_legacy.c */ /* ef_env.c, ef_env_legacy_wl.c and ef_env_legacy.c */
@ -117,7 +66,7 @@ void ef_env_iterator_to_first(void);
char *ef_env_iterator_now_name(void); char *ef_env_iterator_now_name(void);
size_t ef_env_iterator_now_value_len(void); size_t ef_env_iterator_now_value_len(void);
size_t ef_env_iterator_now_value(void *value_buf, size_t buf_len); size_t ef_env_iterator_now_value(void *value_buf, size_t buf_len);
char* ef_env_iterator_next(size_t *value_len); env_node_obj_t ef_env_iterator_next(size_t *value_len);
#endif #endif
#ifdef EF_USING_IAP #ifdef EF_USING_IAP

@ -0,0 +1,124 @@
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2019, Armink, <armink.ztl@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Function: It is the definitions head file for this library.
* Created on: 2019-11-20
*/
#ifndef EF_DEF_H_
#define EF_DEF_H_
#ifdef __cplusplus
extern "C" {
#endif
/* EasyFlash software version number */
#define EF_SW_VERSION "4.0.99"
#define EF_SW_VERSION_NUM 0x40099
/*
* ENV version number defined by user.
* Please change it when your firmware add a new ENV to default_env_set.
*/
#ifndef EF_ENV_VER_NUM
#define EF_ENV_VER_NUM 0
#endif
/* the ENV max name length must less then it */
#ifndef EF_ENV_NAME_MAX
#define EF_ENV_NAME_MAX 32
#endif
/* EasyFlash debug print function. Must be implement by user. */
#ifdef PRINT_DEBUG
#define EF_DEBUG(...) ef_log_debug(__FILE__, __LINE__, __VA_ARGS__)
#else
#define EF_DEBUG(...)
#endif
/* EasyFlash routine print function. Must be implement by user. */
#define EF_INFO(...) ef_log_info(__VA_ARGS__)
/* EasyFlash assert for developer. */
#define EF_ASSERT(EXPR) \
if (!(EXPR)) \
{ \
EF_DEBUG("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \
while (1); \
}
typedef struct _ef_env {
char *key;
void *value;
size_t value_len;
} ef_env, *ef_env_t;
/* EasyFlash error code */
typedef enum {
EF_NO_ERR,
EF_ERASE_ERR,
EF_READ_ERR,
EF_WRITE_ERR,
EF_ENV_NAME_ERR,
EF_ENV_NAME_EXIST,
EF_ENV_FULL,
EF_ENV_INIT_FAILED,
} EfErrCode;
/* the flash sector current status */
typedef enum {
EF_SECTOR_EMPTY,
EF_SECTOR_USING,
EF_SECTOR_FULL,
} EfSecrorStatus;
enum env_status {
ENV_UNUSED,
ENV_PRE_WRITE,
ENV_WRITE,
ENV_PRE_DELETE,
ENV_DELETED,
ENV_ERR_HDR,
ENV_STATUS_NUM,
};
typedef enum env_status env_status_t;
struct env_node_obj {
env_status_t status; /**< ENV node status, @see node_status_t */
bool crc_is_ok; /**< ENV node CRC32 check is OK */
uint8_t name_len; /**< name length */
uint32_t magic; /**< magic word(`K`, `V`, `4`, `0`) */
uint32_t len; /**< ENV node total length (header + name + value), must align by EF_WRITE_GRAN */
uint32_t value_len; /**< value length */
char name[EF_ENV_NAME_MAX]; /**< name */
struct {
uint32_t start; /**< ENV node start address */
uint32_t value; /**< value start address */
} addr;
};
typedef struct env_node_obj *env_node_obj_t;
#ifdef __cplusplus
}
#endif
#endif /* EF_DEF_H_ */

@ -1,7 +1,7 @@
/* /*
* This file is part of the EasyFlash Library. * This file is part of the EasyFlash Library.
* *
* Copyright (c) 2015, Armink, <armink.ztl@gmail.com> * Copyright (c) 2015-2019, Armink, <armink.ztl@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -64,8 +64,6 @@ EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) {
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) { EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
EF_ASSERT(size % 4 == 0);
/* You can add your code under here. */ /* You can add your code under here. */
return result; return result;
@ -105,8 +103,6 @@ EfErrCode ef_port_erase(uint32_t addr, size_t size) {
EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) { EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
EF_ASSERT(size % 4 == 0);
/* You can add your code under here. */ /* You can add your code under here. */
return result; return result;

@ -39,11 +39,6 @@
#error "the write gran can be only setting as 1, 8, 32 and 64" #error "the write gran can be only setting as 1, 8, 32 and 64"
#endif #endif
/* the ENV max name length must less then it */
#ifndef EF_ENV_NAME_MAX
#define EF_ENV_NAME_MAX 32
#endif
/* magic word(`E`, `F`, `4`, `0`) */ /* magic word(`E`, `F`, `4`, `0`) */
#define SECTOR_MAGIC_WORD 0x30344645 #define SECTOR_MAGIC_WORD 0x30344645
/* magic word(`K`, `V`, `4`, `0`) */ /* magic word(`K`, `V`, `4`, `0`) */
@ -156,17 +151,6 @@ enum sector_dirty_status
}; };
typedef enum sector_dirty_status sector_dirty_status_t; typedef enum sector_dirty_status sector_dirty_status_t;
enum env_status
{
ENV_UNUSED,
ENV_PRE_WRITE,
ENV_WRITE,
ENV_PRE_DELETE,
ENV_DELETED,
ENV_ERR_HDR,
ENV_STATUS_NUM,
};
typedef enum env_status env_status_t;
struct sector_hdr_data struct sector_hdr_data
{ {
@ -208,32 +192,15 @@ struct env_hdr_data
}; };
typedef struct env_hdr_data *env_hdr_data_t; typedef struct env_hdr_data *env_hdr_data_t;
struct env_meta_data
{
env_status_t status; /**< ENV node status, @see node_status_t */
bool crc_is_ok; /**< ENV node CRC32 check is OK */
uint8_t name_len; /**< name length */
uint32_t magic; /**< magic word(`K`, `V`, `4`, `0`) */
uint32_t len; /**< ENV node total length (header + name + value), must align by EF_WRITE_GRAN */
uint32_t value_len; /**< value length */
char name[EF_ENV_NAME_MAX]; /**< name */
struct
{
uint32_t start; /**< ENV node start address */
uint32_t value; /**< value start address */
} addr;
};
typedef struct env_meta_data *env_meta_data_t;
struct env_iterator_obj struct env_iterator_obj
{ {
struct sector_meta_data sector; struct sector_meta_data sector;
struct env_meta_data env; struct env_node_obj env;
}; };
typedef struct env_iterator_obj *env_iterator_obj_t; typedef struct env_iterator_obj *env_iterator_obj_t;
struct env_cache_node struct env_cache_node {
{
uint16_t name_crc; /**< ENV name's CRC32 low 16bit value */ uint16_t name_crc; /**< ENV name's CRC32 low 16bit value */
uint16_t active; /**< ENV node access active degree */ uint16_t active; /**< ENV node access active degree */
uint32_t addr; /**< ENV node address */ uint32_t addr; /**< ENV node address */
@ -569,7 +536,7 @@ static uint32_t find_next_env_addr(uint32_t start, uint32_t end)
{ {
#ifndef EF_BIG_ENDIAN /* Little Endian Order */ #ifndef EF_BIG_ENDIAN /* Little Endian Order */
magic = buf[i] + (buf[i + 1] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24); magic = buf[i] + (buf[i + 1] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);
#else // Big Endian Order #else /* Big Endian Order */
magic = buf[i + 3] + (buf[i + 2] << 8) + (buf[i + 1] << 16) + (buf[i] << 24); magic = buf[i + 3] + (buf[i + 2] << 8) + (buf[i + 1] << 16) + (buf[i] << 24);
#endif #endif
if (magic == ENV_MAGIC_WORD && (start + i - ENV_MAGIC_OFFSET) >= start_bak) if (magic == ENV_MAGIC_WORD && (start + i - ENV_MAGIC_OFFSET) >= start_bak)
@ -582,7 +549,7 @@ static uint32_t find_next_env_addr(uint32_t start, uint32_t end)
return FAILED_ADDR; return FAILED_ADDR;
} }
static uint32_t get_next_env_addr(sector_meta_data_t sector, env_meta_data_t pre_env) static uint32_t get_next_env_addr(sector_meta_data_t sector, env_node_obj_t pre_env)
{ {
uint32_t addr = FAILED_ADDR; uint32_t addr = FAILED_ADDR;
@ -629,7 +596,7 @@ static uint32_t get_next_env_addr(sector_meta_data_t sector, env_meta_data_t pre
return addr; return addr;
} }
static EfErrCode read_env(env_meta_data_t env) static EfErrCode read_env(env_node_obj_t env)
{ {
struct env_hdr_data env_hdr; struct env_hdr_data env_hdr;
uint8_t buf[32]; uint8_t buf[32];
@ -731,10 +698,8 @@ static EfErrCode read_sector_meta_data(uint32_t addr, sector_meta_data_t sector,
if (sector->status.store == SECTOR_STORE_EMPTY) if (sector->status.store == SECTOR_STORE_EMPTY)
{ {
sector->remain = SECTOR_SIZE - SECTOR_HDR_DATA_SIZE; sector->remain = SECTOR_SIZE - SECTOR_HDR_DATA_SIZE;
} } else if (sector->status.store == SECTOR_STORE_USING) {
else if (sector->status.store == SECTOR_STORE_USING) struct env_node_obj env_meta;
{
struct env_meta_data env_meta;
#ifdef EF_ENV_USING_CACHE #ifdef EF_ENV_USING_CACHE
if (get_sector_from_cache(addr, &sector->empty_env)) if (get_sector_from_cache(addr, &sector->empty_env))
@ -817,8 +782,8 @@ static uint32_t get_next_sector_addr(sector_meta_data_t pre_sec)
} }
} }
static void env_iterator(env_meta_data_t env, void *arg1, void *arg2, static void env_iterator(env_node_obj_t env, void *arg1, void *arg2,
bool (*callback)(env_meta_data_t env, void *arg1, void *arg2)) bool (*callback)(env_node_obj_t env, void *arg1, void *arg2))
{ {
struct sector_meta_data sector; struct sector_meta_data sector;
uint32_t sec_addr; uint32_t sec_addr;
@ -853,7 +818,7 @@ static void env_iterator(env_meta_data_t env, void *arg1, void *arg2,
} }
} }
static bool find_env_cb(env_meta_data_t env, void *arg1, void *arg2) static bool find_env_cb(env_node_obj_t env, void *arg1, void *arg2)
{ {
const char *key = arg1; const char *key = arg1;
bool *find_ok = arg2; bool *find_ok = arg2;
@ -872,7 +837,7 @@ static bool find_env_cb(env_meta_data_t env, void *arg1, void *arg2)
return false; return false;
} }
static bool find_env_no_cache(const char *key, env_meta_data_t env) static bool find_env_no_cache(const char *key, env_node_obj_t env)
{ {
bool find_ok = false; bool find_ok = false;
@ -881,7 +846,7 @@ static bool find_env_no_cache(const char *key, env_meta_data_t env)
return find_ok; return find_ok;
} }
static bool find_env(const char *key, env_meta_data_t env) static bool find_env(const char *key, env_node_obj_t env)
{ {
bool find_ok = false; bool find_ok = false;
@ -924,7 +889,7 @@ static bool ef_is_str(uint8_t *value, size_t len)
static size_t get_env(const char *key, void *value_buf, size_t buf_len, size_t *value_len) static size_t get_env(const char *key, void *value_buf, size_t buf_len, size_t *value_len)
{ {
struct env_meta_data env; struct env_node_obj env;
size_t read_len = 0; size_t read_len = 0;
if (find_env(key, &env)) if (find_env(key, &env))
@ -950,6 +915,34 @@ static size_t get_env(const char *key, void *value_buf, size_t buf_len, size_t *
return read_len; return read_len;
} }
/**
* Get a ENV object by key name
*
* @param key ENV name
* @param env ENV object
*
* @return TRUE: find the ENV is OK, else return false
*/
bool ef_get_env_obj(const char *key, env_node_obj_t env)
{
bool find_ok = false;
if (!init_ok) {
EF_INFO("ENV isn't initialize OK.\n");
return 0;
}
/* lock the ENV cache */
ef_port_env_lock();
find_ok = find_env(key, env);
/* unlock the ENV cache */
ef_port_env_unlock();
return find_ok;
}
/** /**
* Get a blob ENV value by key name. * Get a blob ENV value by key name.
* *
@ -1014,8 +1007,46 @@ char *ef_get_env(const char *key)
return NULL; return NULL;
} }
static EfErrCode write_env_hdr(uint32_t addr, env_hdr_data_t env_hdr) /**
* read the ENV value by ENV object
*
* @param env ENV object
* @param value_buf the buffer for store ENV value
* @param buf_len buffer length
*
* @return the actually read size on successful
*/
size_t ef_read_env_value(env_node_obj_t env, uint8_t *value_buf, size_t buf_len)
{ {
size_t read_len = 0;
EF_ASSERT(env);
EF_ASSERT(value_buf);
if (!init_ok) {
EF_INFO("ENV isn't initialize OK.\n");
return 0;
}
if (env->crc_is_ok) {
/* lock the ENV cache */
ef_port_env_lock();
if (buf_len > env->value_len) {
read_len = env->value_len;
} else {
read_len = buf_len;
}
ef_port_read(env->addr.value, (uint32_t *) value_buf, read_len);
/* unlock the ENV cache */
ef_port_env_unlock();
}
return read_len;
}
static EfErrCode write_env_hdr(uint32_t addr, env_hdr_data_t env_hdr) {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
/* write the status will by write granularity */ /* write the status will by write granularity */
result = write_status(addr, env_hdr->status_table, ENV_STATUS_NUM, ENV_PRE_WRITE); result = write_status(addr, env_hdr->status_table, ENV_STATUS_NUM, ENV_PRE_WRITE);
@ -1184,8 +1215,7 @@ static uint32_t alloc_env(sector_meta_data_t sector, size_t env_size)
return empty_env; return empty_env;
} }
static EfErrCode del_env(const char *key, env_meta_data_t old_env, bool complete_del) static EfErrCode del_env(const char *key, env_node_obj_t old_env, bool complete_del) {
{
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
uint32_t dirty_status_addr; uint32_t dirty_status_addr;
static bool last_is_complete_del = false; static bool last_is_complete_del = false;
@ -1197,9 +1227,8 @@ static EfErrCode del_env(const char *key, env_meta_data_t old_env, bool complete
#endif #endif
/* need find ENV */ /* need find ENV */
if (!old_env) if (!old_env) {
{ struct env_node_obj env;
struct env_meta_data env;
/* find ENV */ /* find ENV */
if (find_env(key, &env)) if (find_env(key, &env))
{ {
@ -1246,7 +1275,7 @@ static EfErrCode del_env(const char *key, env_meta_data_t old_env, bool complete
/* /*
* move the ENV to new space * move the ENV to new space
*/ */
static EfErrCode move_env(env_meta_data_t env) static EfErrCode move_env(env_node_obj_t env)
{ {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
uint8_t status_table[ENV_STATUS_TABLE_SIZE]; uint8_t status_table[ENV_STATUS_TABLE_SIZE];
@ -1259,11 +1288,9 @@ static EfErrCode move_env(env_meta_data_t env)
del_env(NULL, env, false); del_env(NULL, env, false);
} }
if ((env_addr = alloc_env(&sector, env->len)) != FAILED_ADDR) if ((env_addr = alloc_env(&sector, env->len)) != FAILED_ADDR) {
{ if (in_recovery_check) {
if (in_recovery_check) struct env_node_obj env_bak;
{
struct env_meta_data env_bak;
char name[EF_ENV_NAME_MAX + 1] = { 0 }; char name[EF_ENV_NAME_MAX + 1] = { 0 };
strncpy(name, env->name, env->name_len); strncpy(name, env->name, env->name_len);
/* check the ENV in flash is already create success */ /* check the ENV in flash is already create success */
@ -1390,9 +1417,10 @@ size_t f_env_iterator_now_value(void *value_buf, size_t buf_len)
* @brief Get next blob ENV * @brief Get next blob ENV
* *
* @param value_len ENV blob buffer length * @param value_len ENV blob buffer length
* @return char* 0:Traversal complete nonzero:ENV name * @return char* 0:Traversal complete nonzero:ENV
*/ */
char* ef_env_iterator_next(size_t *value_len) env_node_obj_t ef_env_iterator_next(size_t *value_len)
//char* ef_env_iterator_next(size_t *value_len)
{ {
uint32_t sec_addr; uint32_t sec_addr;
ef_port_env_lock(); ef_port_env_lock();
@ -1426,7 +1454,7 @@ _next:
*value_len = _g_env_iter_obj.env.value_len; *value_len = _g_env_iter_obj.env.value_len;
} }
ef_port_env_unlock(); ef_port_env_unlock();
return _g_env_iter_obj.env.name; return &_g_env_iter_obj.env;
} }
else else
{ {
@ -1465,7 +1493,7 @@ static bool gc_check_cb(sector_meta_data_t sector, void *arg1, void *arg2)
static bool do_gc(sector_meta_data_t sector, void *arg1, void *arg2) static bool do_gc(sector_meta_data_t sector, void *arg1, void *arg2)
{ {
struct env_meta_data env; struct env_node_obj env;
if (sector->check_ok && (sector->status.dirty == SECTOR_DIRTY_TRUE || sector->status.dirty == SECTOR_DIRTY_GC)) if (sector->check_ok && (sector->status.dirty == SECTOR_DIRTY_TRUE || sector->status.dirty == SECTOR_DIRTY_GC))
{ {
@ -1683,7 +1711,7 @@ EfErrCode ef_del_and_save_env(const char *key)
static EfErrCode set_env(const char *key, const void *value_buf, size_t buf_len) static EfErrCode set_env(const char *key, const void *value_buf, size_t buf_len)
{ {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
static struct env_meta_data env; static struct env_node_obj env;
static struct sector_meta_data sector; static struct sector_meta_data sector;
bool env_is_found = false; bool env_is_found = false;
@ -1850,7 +1878,7 @@ __exit:
return result; return result;
} }
static bool print_env_cb(env_meta_data_t env, void *arg1, void *arg2) static bool print_env_cb(env_node_obj_t env, void *arg1, void *arg2)
{ {
bool value_is_str = true, print_value = false; bool value_is_str = true, print_value = false;
size_t *using_size = arg1; size_t *using_size = arg1;
@ -1918,7 +1946,7 @@ __reload:
*/ */
void ef_print_env(void) void ef_print_env(void)
{ {
struct env_meta_data env; struct env_node_obj env;
size_t using_size = 0; size_t using_size = 0;
if (!init_ok) if (!init_ok)
@ -1951,9 +1979,8 @@ static void env_auto_update(void)
if (get_env(VER_NUM_ENV_NAME, &saved_ver_num, sizeof(size_t), NULL) > 0) if (get_env(VER_NUM_ENV_NAME, &saved_ver_num, sizeof(size_t), NULL) > 0)
{ {
/* check version number */ /* check version number */
if (saved_ver_num != setting_ver_num) if (saved_ver_num != setting_ver_num) {
{ struct env_node_obj env;
struct env_meta_data env;
size_t i, value_len; size_t i, value_len;
struct sector_meta_data sector; struct sector_meta_data sector;
EF_DEBUG("Update the ENV from version %d to %d.\n", saved_ver_num, setting_ver_num); EF_DEBUG("Update the ENV from version %d to %d.\n", saved_ver_num, setting_ver_num);
@ -2015,7 +2042,7 @@ static bool check_and_recovery_gc_cb(sector_meta_data_t sector, void *arg1, void
return false; return false;
} }
static bool check_and_recovery_env_cb(env_meta_data_t env, void *arg1, void *arg2) static bool check_and_recovery_env_cb(env_node_obj_t env, void *arg1, void *arg2)
{ {
/* recovery the prepare deleted ENV */ /* recovery the prepare deleted ENV */
if (env->crc_is_ok && env->status == ENV_PRE_DELETE) if (env->crc_is_ok && env->status == ENV_PRE_DELETE)
@ -2036,7 +2063,7 @@ static bool check_and_recovery_env_cb(env_meta_data_t env, void *arg1, void *arg
{ {
uint8_t status_table[ENV_STATUS_TABLE_SIZE]; uint8_t status_table[ENV_STATUS_TABLE_SIZE];
/* the ENV has not write finish, change the status to error */ /* the ENV has not write finish, change the status to error */
//TODO 绘制异常处理的状态装换图 //TODO <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬װ<EFBFBD><EFBFBD>ͼ
write_status(env->addr.start, status_table, ENV_STATUS_NUM, ENV_ERR_HDR); write_status(env->addr.start, status_table, ENV_STATUS_NUM, ENV_ERR_HDR);
return true; return true;
} }
@ -2052,7 +2079,7 @@ static bool check_and_recovery_env_cb(env_meta_data_t env, void *arg1, void *arg
EfErrCode ef_load_env(void) EfErrCode ef_load_env(void)
{ {
EfErrCode result = EF_NO_ERR; EfErrCode result = EF_NO_ERR;
struct env_meta_data env; struct env_node_obj env;
struct sector_meta_data sector; struct sector_meta_data sector;
size_t check_failed_count = 0; size_t check_failed_count = 0;

Loading…
Cancel
Save