Skip to content

Commit

Permalink
flash/esp: create mem_map from constant indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
erhankur committed Jan 30, 2023
1 parent 4349b9b commit 6b6b7f3
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/flash/nor/esp_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,26 +966,21 @@ int esp_algo_flash_probe(struct flash_bank *bank)
* have zero size to allow correct memory map with non zero RAM region */
irom_base = drom_base = esp_algo_flash_get_size(bank);
} else {
for (uint32_t i = 0; i < flash_map.maps_num; i++) {
if (esp_info->is_irom_address(flash_map.maps[i].load_addr)) {
irom_flash_base = flash_map.maps[i].phy_addr &
~(esp_info->sec_sz - 1);
irom_base = flash_map.maps[i].load_addr &
~(esp_info->sec_sz - 1);
irom_sz = flash_map.maps[i].size;
if (irom_sz & (esp_info->sec_sz - 1))
irom_sz = (irom_sz & ~(esp_info->sec_sz - 1)) +
esp_info->sec_sz;
} else if (esp_info->is_drom_address(flash_map.maps[i].load_addr)) {
drom_flash_base = flash_map.maps[i].phy_addr &
~(esp_info->sec_sz - 1);
drom_base = flash_map.maps[i].load_addr &
~(esp_info->sec_sz - 1);
drom_sz = flash_map.maps[i].size;
if (drom_sz & (esp_info->sec_sz - 1))
drom_sz = (drom_sz & ~(esp_info->sec_sz - 1)) +
esp_info->sec_sz;
}
/* flash map index 0 belongs to drom */
if (esp_info->is_drom_address(flash_map.maps[0].load_addr)) {
drom_flash_base = flash_map.maps[0].load_addr & ~(esp_info->sec_sz - 1);
drom_base = flash_map.maps[0].load_addr & ~(esp_info->sec_sz - 1);
drom_sz = flash_map.maps[0].size;
if (drom_sz & (esp_info->sec_sz - 1))
drom_sz = (drom_sz & ~(esp_info->sec_sz - 1)) + esp_info->sec_sz;
}
/* flash map index 1 belongs to irom */
if (flash_map.maps_num > 1 && esp_info->is_irom_address(flash_map.maps[1].load_addr)) {
irom_flash_base = flash_map.maps[1].phy_addr & ~(esp_info->sec_sz - 1);
irom_base = flash_map.maps[1].load_addr & ~(esp_info->sec_sz - 1);
irom_sz = flash_map.maps[1].size;
if (irom_sz & (esp_info->sec_sz - 1))
irom_sz = (irom_sz & ~(esp_info->sec_sz - 1)) + esp_info->sec_sz;
}
}

Expand All @@ -1009,7 +1004,7 @@ int esp_algo_flash_probe(struct flash_bank *bank)
LOG_INFO("Using flash bank '%s' size %d KB", bank->name, bank->size / 1024);

if (bank->size) {
/* Bank size can be 0 for IRON/DROM emulated banks when there is no app in flash */
/* Bank size can be 0 for IROM/DROM emulated banks when there is no app in flash */
bank->num_sectors = bank->size / esp_info->sec_sz;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
if (bank->sectors == NULL) {
Expand Down

0 comments on commit 6b6b7f3

Please sign in to comment.