[fal] Add blocks mechanism to fal. (#8252)
This commit is contained in:
parent
3aa19af301
commit
6d7e393ce9
|
@ -73,6 +73,16 @@ if (!(EXPR)) \
|
||||||
#define FAL_DEV_NAME_MAX 24
|
#define FAL_DEV_NAME_MAX 24
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FAL_DEV_BLK_MAX
|
||||||
|
#define FAL_DEV_BLK_MAX 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct flash_blk
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
size_t count;
|
||||||
|
};
|
||||||
|
|
||||||
struct fal_flash_dev
|
struct fal_flash_dev
|
||||||
{
|
{
|
||||||
char name[FAL_DEV_NAME_MAX];
|
char name[FAL_DEV_NAME_MAX];
|
||||||
|
@ -95,6 +105,7 @@ struct fal_flash_dev
|
||||||
1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
|
1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
|
||||||
0 will not take effect. */
|
0 will not take effect. */
|
||||||
size_t write_gran;
|
size_t write_gran;
|
||||||
|
struct flash_blk blocks[FAL_DEV_BLK_MAX];
|
||||||
};
|
};
|
||||||
typedef struct fal_flash_dev *fal_flash_dev_t;
|
typedef struct fal_flash_dev *fal_flash_dev_t;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ static uint8_t init_ok = 0;
|
||||||
*/
|
*/
|
||||||
int fal_flash_init(void)
|
int fal_flash_init(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i, j, offset;
|
||||||
|
|
||||||
if (init_ok)
|
if (init_ok)
|
||||||
{
|
{
|
||||||
|
@ -47,6 +47,17 @@ int fal_flash_init(void)
|
||||||
log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||||
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
|
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
|
||||||
device_table[i]->blk_size);
|
device_table[i]->blk_size);
|
||||||
|
offset = 0;
|
||||||
|
for (j = 0; j < FAL_DEV_BLK_MAX; j ++)
|
||||||
|
{
|
||||||
|
const struct flash_blk *blk = &device_table[i]->blocks[j];
|
||||||
|
size_t blk_len = blk->count * blk->size;
|
||||||
|
if (blk->count == 0 || blk->size == 0)
|
||||||
|
break;
|
||||||
|
log_d(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||||
|
j, device_table[i]->addr + offset, blk_len, blk->size);
|
||||||
|
offset += blk_len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_ok = 1;
|
init_ok = 1;
|
||||||
|
|
Loading…
Reference in New Issue