| 110 | } |
| 111 | |
| 112 | static int check_and_update_part_cache(const struct fal_partition *table, rt_size_t len) |
| 113 | { |
| 114 | const struct fal_flash_dev *flash_dev = NULL; |
| 115 | rt_size_t i; |
| 116 | |
| 117 | #ifndef FAL_PART_HAS_TABLE_CFG |
| 118 | if (part_flash_cache) |
| 119 | { |
| 120 | rt_free(part_flash_cache); |
| 121 | } |
| 122 | part_flash_cache = rt_malloc(len * sizeof(struct part_flash_info)); |
| 123 | if (part_flash_cache == NULL) |
| 124 | { |
| 125 | LOG_E("Initialize failed! No memory for partition table cache"); |
| 126 | return -2; |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | for (i = 0; i < len; i++) |
| 131 | { |
| 132 | flash_dev = fal_flash_device_find(table[i].flash_name); |
| 133 | if (flash_dev == NULL) |
| 134 | { |
| 135 | LOG_D("Warning: Do NOT found the flash device(%s).", table[i].flash_name); |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | if (table[i].offset >= (long)flash_dev->len) |
| 140 | { |
| 141 | LOG_E("Initialize failed! Partition(%s) offset address(%ld) out of flash bound(<%d).", |
| 142 | table[i].name, table[i].offset, flash_dev->len); |
| 143 | partition_table_len = 0; |
| 144 | |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | part_flash_cache[i].flash_dev = flash_dev; |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Initialize all flash partition on FAL partition table |
no test coverage detected