armink-rtt-pkgs / easyflash Goto Github PK
View Code? Open in Web Editor NEWLightweight embedded flash memory library. Make flash to be a small KV database. | 嵌入式 Flash 存储器库,让 Flash 成为小型 KV 数据库
License: MIT License
Lightweight embedded flash memory library. Make flash to be a small KV database. | 嵌入式 Flash 存储器库,让 Flash 成为小型 KV 数据库
License: MIT License
void ef_iterator_env(void *arg1, void *arg2, bool (*callback)(env_meta_data_t env, void *arg1, void *arg2))
{
struct env_meta_data env;
if (!init_ok) {
EF_INFO("ENV isn't initialize OK.\n");
return;
}
/* lock the ENV cache */
ef_port_env_lock();
env_iterator(&env, arg1, arg2, callback);
/* unlock the ENV cache */
ef_port_env_unlock();
}
/**
Print ENV.
*/
void ef_print_env(void)
{
size_t using_size = 0;
ef_iterator_env(&using_size, NULL, print_env_cb);
ef_print("\nmode: next generation\n");
ef_print("size: %lu/%lu bytes.\n", using_size + (SECTOR_NUM - EF_GC_EMPTY_SEC_THRESHOLD) * SECTOR_HDR_DATA_SIZE,
ENV_AREA_SIZE - SECTOR_SIZE * EF_GC_EMPTY_SEC_THRESHOLD);
}
ef_log.c
文件内的 log_index2addr
函数使用存在隐藏风险,建议可以优化
当给 log_index2addr
传入的参数index
的值 大于 2倍LOG_AREA_SIZE
时,回导致计算出来的flash物理地址错误
建议将返回值计算
return log_start_addr + index + header_total_offset - LOG_AREA_SIZE;
修改为
return (log_start_addr + index + header_total_offse)t % LOG_AREA_SIZE;
尽管此函数仅由ef_log_read
调用,且ef_log_read
函数内做了EF_ASSERT(index < cur_using_size);
判断,目前整体是安全的,但是此函数是不安全的,为防止后续其他函数调用是引入风险,建议修改
ENV_AREA_SIZE
没有办法设置,现在我直接改了ef_cfg.h
,但这样太不稳定了。(包是用pkgs下载的)
还有配置方面的一些问题,比如现在很多配置的检查是用这样的方式实现的:
#if EF_ENV_CACHE_TABLE_SIZE > 0xFFFF
#error "The ENV cache table size must less than 0xFFFF"
#endif
而另一些是assert,实际上都可以用assert,这样有机会把它们定义成某种在应用早期计算的全局变量,可以更灵活。
ef_env_init()
中的EF_ASSERT(ENV_AREA_SIZE % EF_ERASE_MIN_SIZE == 0);
没有什么必要,我需要专门算ENV_AREA_SIZE ,但其实并不会导致什么问题,只是最后有一些空间浪费了而已。
ef_port_read/write/erase调用fal_partition相关函数时,地址变量传递不正确。
以ef_port_read为例:
该函数的声明如下:
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size);
其参数addr是一个绝对地址变量。
fal_partition_read函数的声明如下:
int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t *buf, size_t size)
其参数addr是一个相对地址变量。
所以调用fal_partition_read的方式应改为这样:
fal_partition_read(part, addr - stm32f2_onchip_flash.addr - part->offset, (uint8_t *)buf, size);
Although FAL support multiple partitions for multiple physical flash devices, only one partation could be used when porting FAL to EasyFlash.
EasyFlash uses one static global partation descriptor in ef_port.c or ef_fal_port.c, and the api doesn't support passing different partation names or partation descriptors. This is not flexible enough when we got several flash chips (in-chip and off-chip). Only one partation in one chip could be managed by EF.
One way to solve this with least changes is to modify the ef_port_xxx apis, passing partation descriptor or partation name or something else into it, and each function block (env, iap, log...) passes different partation params to port apis. But this makes EF and FAL couples tighter. A more abstract descriptor might be added in EF implementation.
芯片:STM32L496RGT,使用fal组件和easyflash。flash驱动用的是rtt的drv_flash_l4.c
fal层分区是(0-1000KB)APP、(1000-1024KB)PARAMS。fal层初始化成功,因为曾经移植过littlefs,这部分比较熟悉。
easyflash格式化head不知道是不是成功了,如下:
Read data success. Start from 0x00000000, size is 200. The data is:
Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[00000000] 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000010] FF FF FF FF FF FF FF FF 00 FF FF FF FF FF FF FF ................
[00000020] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000030] 45 46 34 30 FF FF FF FF FF FF FF FF 00 00 00 00 EF40............
[00000040] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000050] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000060] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000070] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000080] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[00000090] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[000000A0] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[000000B0] FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ................
[000000C0] FF FF FF FF FF FF FF FF ........
easyflash的menuconfig配置大致如下:
use ENV
Erase MIN:2048;Write MIN:64bits;Start addr:0
Version:V4.1.0
问题是:初始化默认环境变量时,会从offset=8开始写入flash,而这里已经被head写过了,因此HAL_FLASH_Program函数失败了。
大致看了下代码,了解到写环境变量时将申请flash块地址,而这个申请是easyflash管理的,在不清楚原理的情况下不敢贸然改动。
想请教的是,easyflash移植到L4系列中是否有问题的地方?
类似数据库主键作为Key,JSON或者struct作Value,提供查询接口,字段值的过滤比较排序等函数由用户编写,当作参数传入,实现自定义的过滤排序等,那就完全是一个NoSQL数据库了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.