1、【更新】RT-Thread Demo 中使用的 EasyFlash 库至最新版本。

Signed-off-by: armink <armink.ztl@gmail.com>
pull/4/head
armink 9 years ago
parent 63aae48ac2
commit 4d84b97abf

@ -67,9 +67,9 @@ if (!(EXPR)) \
while (1); \
}
/* EasyFlash software version number */
#define EF_SW_VERSION "1.09.16"
#define EF_SW_VERSION "2.08.26"
typedef struct _eflash_env{
typedef struct _ef_env{
char *key;
char *value;
}ef_env, *ef_env_t;
@ -86,10 +86,10 @@ typedef enum {
/* the flash sector current status */
typedef enum {
FLASH_SECTOR_EMPTY,
FLASH_SECTOR_USING,
FLASH_SECTOR_FULL,
}FlashSecrorStatus;
EF_SECTOR_EMPTY,
EF_SECTOR_USING,
EF_SECTOR_FULL,
}EfSecrorStatus;
/* easyflash.c */
EfErrCode easyflash_init(void);
@ -127,7 +127,7 @@ 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);
FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_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 */

@ -188,10 +188,8 @@ EfErrCode ef_env_set_default(void){
*/
static uint32_t get_env_system_addr(void) {
#ifndef EF_ENV_USING_PFS_MODE
EF_ASSERT(env_start_addr);
return env_start_addr;
#else
EF_ASSERT(cur_load_area_addr);
return cur_load_area_addr;
#endif
}
@ -307,8 +305,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(env_start_addr);
if (*key == NULL) {
EF_INFO("Flash ENV name must be not empty!\n");
return NULL;

@ -192,7 +192,6 @@ EfErrCode ef_env_set_default(void){
* @return ENV start address in flash
*/
static uint32_t get_env_start_addr(void) {
EF_ASSERT(env_start_addr);
return env_start_addr;
}
/**

@ -94,7 +94,7 @@ EfErrCode ef_log_init(void) {
*/
static void find_start_and_end_addr(void) {
size_t cur_size = 0;
FlashSecrorStatus cur_sec_status, last_sec_status;
EfSecrorStatus cur_sec_status, last_sec_status;
uint32_t cur_using_sec_addr = 0;
/* all status sector counts */
size_t empty_sec_counts = 0, using_sec_counts = 0, full_sector_counts = 0;
@ -112,15 +112,15 @@ static void find_start_and_end_addr(void) {
cur_sec_status = ef_get_sector_status(log_area_start_addr + cur_size, EF_ERASE_MIN_SIZE);
/* compare last and current status */
switch (last_sec_status) {
case FLASH_SECTOR_EMPTY: {
case EF_SECTOR_EMPTY: {
switch (cur_sec_status) {
case FLASH_SECTOR_EMPTY:
case EF_SECTOR_EMPTY:
break;
case FLASH_SECTOR_USING:
case EF_SECTOR_USING:
EF_DEBUG("Error: Log area error! Now will clean all log area.\n");
ef_log_clean();
return;
case FLASH_SECTOR_FULL:
case EF_SECTOR_FULL:
EF_DEBUG("Error: Log area error! Now will clean all log area.\n");
ef_log_clean();
return;
@ -128,19 +128,19 @@ static void find_start_and_end_addr(void) {
empty_sec_counts++;
break;
}
case FLASH_SECTOR_USING: {
case EF_SECTOR_USING: {
switch (cur_sec_status) {
case FLASH_SECTOR_EMPTY:
case EF_SECTOR_EMPTY:
/* like state 1 */
cur_log_sec_state = 1;
log_start_addr = log_area_start_addr;
cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE;
break;
case FLASH_SECTOR_USING:
case EF_SECTOR_USING:
EF_DEBUG("Error: Log area error! Now will clean all log area.\n");
ef_log_clean();
return;
case FLASH_SECTOR_FULL:
case EF_SECTOR_FULL:
/* like state 2 */
cur_log_sec_state = 2;
log_start_addr = log_area_start_addr + cur_size;
@ -150,9 +150,9 @@ static void find_start_and_end_addr(void) {
using_sec_counts++;
break;
}
case FLASH_SECTOR_FULL: {
case EF_SECTOR_FULL: {
switch (cur_sec_status) {
case FLASH_SECTOR_EMPTY:
case EF_SECTOR_EMPTY:
/* like state 1 */
if (cur_log_sec_state == 2) {
EF_DEBUG("Error: Log area error! Now will clean all log area.\n");
@ -166,7 +166,7 @@ static void find_start_and_end_addr(void) {
cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE;
}
break;
case FLASH_SECTOR_USING:
case EF_SECTOR_USING:
if(total_sec_num <= 2) {
/* like state 1 */
cur_log_sec_state = 1;
@ -181,7 +181,7 @@ static void find_start_and_end_addr(void) {
}
}
break;
case FLASH_SECTOR_FULL:
case EF_SECTOR_FULL:
break;
}
full_sector_counts++;
@ -192,11 +192,11 @@ static void find_start_and_end_addr(void) {
}
/* the last sector status counts */
if (cur_sec_status == FLASH_SECTOR_EMPTY) {
if (cur_sec_status == EF_SECTOR_EMPTY) {
empty_sec_counts++;
} else if (cur_sec_status == FLASH_SECTOR_USING) {
} else if (cur_sec_status == EF_SECTOR_USING) {
using_sec_counts++;
} else if (cur_sec_status == FLASH_SECTOR_FULL) {
} else if (cur_sec_status == EF_SECTOR_FULL) {
full_sector_counts++;
}

@ -106,15 +106,15 @@ uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size)
*
* @return the flash sector current status
*/
FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) {
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 == addr) {
return FLASH_SECTOR_EMPTY;
} else if (cur_using_addr < addr + sec_size - 4) {
return FLASH_SECTOR_USING;
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 FLASH_SECTOR_FULL;
return EF_SECTOR_USING;
}
}
@ -127,37 +127,38 @@ FlashSecrorStatus ef_get_sector_status(uint32_t addr, size_t sec_size) {
* @return current flash sector using end address
*/
uint32_t ef_find_sec_using_end_addr(uint32_t addr, size_t sec_size) {
size_t start, continue_ff;
/* counts continuous 0xFF */
for (start = 0; start < sec_size; start++) {
if (*(uint8_t *) (addr + start) == 0xFF) {
/* make sure it is not the last byte */
if (start < sec_size - 1) {
/* start counts */
for (continue_ff = 1; continue_ff < sec_size - start; continue_ff++) {
if (*(uint8_t *) (addr + start + continue_ff) != 0xFF) {
start += continue_ff;
break;
}
}
/* all sector counts finish */
if (continue_ff == sec_size - start) {
/* must be word alignment */
if (start % 4 != 0) {
start = (start / 4 + 1) * 4;
}
break;
}
/* 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 ((start == 0) && (continue_ff == sec_size)) {
if (continue_ff == sec_size) {
/* from 0 to sec_size all sector is 0xFF, so the sector is empty */
return addr;
} else if (start < sec_size) {
/* form start to sec_size all area is 0xFF, so it's used part of the sector */
return addr + start;
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;

Loading…
Cancel
Save