提交 6e0d2cd3 编写于 作者: armink_ztl's avatar armink_ztl

1、【优化】Log 分区识别功能,大大提升 Log 分区初始化效率;

2、【删除】部分冗余断言;
3、【修复】几处单词拼写错误。
Signed-off-by: armink_ztl's avatararmink <armink.ztl@gmail.com>
上级 5927f69c
The MIT License (MIT)
Copyright (c) 2014-2016 Armink (armink.ztl@gmail.com)
Copyright (c) 2014-2017 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
......
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2014-2016, Armink, <armink.ztl@gmail.com>
* Copyright (c) 2014-2017, 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
......@@ -67,7 +67,7 @@ if (!(EXPR)) \
while (1); \
}
/* EasyFlash software version number */
#define EF_SW_VERSION "2.12.08"
#define EF_SW_VERSION "3.0.0"
typedef struct _ef_env{
char *key;
......@@ -128,8 +128,6 @@ size_t ef_log_get_used_size(void);
/* ef_utils.c */
uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size);
EfSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size);
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size);
/* ef_port.c */
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size);
......
......@@ -281,11 +281,11 @@ size_t ef_get_env_write_bytes(void) {
*/
static EfErrCode write_env(const char *key, const char *value) {
EfErrCode result = EF_NO_ERR;
size_t ker_len = strlen(key), value_len = strlen(value), env_str_len;
size_t key_len = strlen(key), value_len = strlen(value), env_str_len;
char *env_cache_bak = (char *)env_cache;
/* calculate ENV storage length, contain '=' and '\0'. */
env_str_len = ker_len + value_len + 2;
env_str_len = key_len + value_len + 2;
if (env_str_len % 4 != 0) {
env_str_len = (env_str_len / 4 + 1) * 4;
}
......@@ -298,8 +298,8 @@ static EfErrCode write_env(const char *key, const char *value) {
env_cache_bak += get_env_user_used_size();
/* copy key name */
memcpy(env_cache_bak, key, ker_len);
env_cache_bak += ker_len;
memcpy(env_cache_bak, key, key_len);
env_cache_bak += key_len;
/* copy equal sign */
*env_cache_bak = '=';
env_cache_bak++;
......@@ -310,7 +310,7 @@ static EfErrCode write_env(const char *key, const char *value) {
*env_cache_bak = '\0';
env_cache_bak ++;
/* fill '\0' for word alignment */
memset(env_cache_bak, 0, env_str_len - (ker_len + value_len + 2));
memset(env_cache_bak, 0, env_str_len - (key_len + value_len + 2));
set_env_end_addr(get_env_end_addr() + env_str_len);
/* ENV ram cache has changed */
env_cache_changed = true;
......
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2015-2016, Armink, <armink.ztl@gmail.com>
* Copyright (c) 2015-2017, 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
......@@ -214,7 +214,6 @@ static uint32_t get_env_start_addr(void) {
* @return current using data section address
*/
static uint32_t get_cur_using_data_addr(void) {
EF_ASSERT(cur_using_data_addr);
return cur_using_data_addr;
}
......@@ -233,7 +232,6 @@ static void set_cur_using_data_addr(uint32_t using_data_addr) {
* @return detail part start address
*/
static uint32_t get_env_detail_addr(void) {
EF_ASSERT(cur_using_data_addr);
return get_cur_using_data_addr() + ENV_PARAM_PART_BYTE_SIZE;
}
......@@ -348,8 +346,6 @@ static char *find_env(const char *key) {
char *env_start, *env_end, *env, *found_env = NULL;
size_t key_len = strlen(key), env_len;
EF_ASSERT(cur_using_data_addr);
if (*key == NULL) {
EF_INFO("Flash ENV name must be not empty!\n");
return NULL;
......
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2015-2016, Armink, <armink.ztl@gmail.com>
* Copyright (c) 2015-2017, 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
......@@ -258,7 +258,6 @@ EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) {
* @return size
*/
static uint32_t get_bak_app_start_addr(void) {
EF_ASSERT(bak_app_start_addr);
return bak_app_start_addr;
}
......
此差异已折叠。
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2015-2016, Armink, <armink.ztl@gmail.com>
* Copyright (c) 2015-2017, 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
......@@ -97,70 +97,3 @@ uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size)
return crc ^ ~0U;
}
/**
* Get this flash sector current status.
*
* @param addr sector address
* @param sec_size sector address
*
* @return the flash sector current status
*/
EfSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) {
uint32_t cur_using_addr = ef_find_sec_using_end_addr(addr, sec_size);
/* get current status by current using address */
if (cur_using_addr == 0 || cur_using_addr == addr - 4) {
return EF_SECTOR_EMPTY;
} else if (cur_using_addr == addr + sec_size - 4) {
return EF_SECTOR_FULL;
} else {
return EF_SECTOR_USING;
}
}
/**
* Find the current flash sector using end address by continuous 0xFF.
*
* @param addr sector address
* @param sec_size sector address
*
* @return current flash sector using end address
*/
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size) {
/* read section data buffer size */
#define READ_BUF_SIZE 32
uint32_t start = addr, continue_ff = 0, read_buf_size = 0, i;
uint8_t buf[READ_BUF_SIZE];
EF_ASSERT(READ_BUF_SIZE % 4 == 0);
/* counts continuous 0xFF which is end of sector */
while (start < addr + sec_size) {
if (start + READ_BUF_SIZE < addr + sec_size) {
read_buf_size = READ_BUF_SIZE;
} else {
read_buf_size = addr + sec_size - start;
}
ef_port_read(start, (uint32_t *)buf, read_buf_size);
for (i = 0; i < read_buf_size; i++) {
if (buf[i] == 0xFF) {
continue_ff++;
} else {
continue_ff = 0;
}
}
start += read_buf_size;
}
/* calculate current flash sector using end address */
if (continue_ff == sec_size) {
/* from 0 to sec_size all sector is 0xFF, so the sector is empty */
return addr >= 4 ? addr - 4 : 0;
} else if (continue_ff >= 4) {
/* form end_addr - 4 to sec_size length all area is 0xFF, so it's used part of the sector.
* the address must be word alignment. */
return (addr + sec_size - continue_ff) * 4 / 4 - 4;
} else {
/* all sector not has continuous 0xFF, alignment by word */
return addr + sec_size - 4;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册