Browse Source

[fal] Add blocks mechanism to fal. (#8252)

guo 1 year ago
parent
commit
6d7e393ce9
2 changed files with 23 additions and 1 deletions
  1. 11 0
      components/fal/inc/fal_def.h
  2. 12 1
      components/fal/src/fal_flash.c

+ 11 - 0
components/fal/inc/fal_def.h

@@ -73,6 +73,16 @@ if (!(EXPR))                                                                   \
 #define FAL_DEV_NAME_MAX 24
 #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
 {
     char name[FAL_DEV_NAME_MAX];
@@ -95,6 +105,7 @@ struct fal_flash_dev
        1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
        0 will not take effect. */
     size_t write_gran;
+    struct flash_blk blocks[FAL_DEV_BLK_MAX];
 };
 typedef struct fal_flash_dev *fal_flash_dev_t;
 

+ 12 - 1
components/fal/src/fal_flash.c

@@ -27,7 +27,7 @@ static uint8_t init_ok = 0;
  */
 int fal_flash_init(void)
 {
-    size_t i;
+    size_t i, j, offset;
 
     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.",
                 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);
+        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;