Skip to content

Commit af7b6b7

Browse files
EliteTKespressif-bot
authored andcommitted
fix(rom): Fix s2 and s3 Cache_Count_Flash_Pages rom function wrapper
The rom function on the s2 and s3 only counts one page for any pages which are mapped to page 0 of flash as the Cache_Flash_To_SPIRAM_Copy function attempts to map all flash page 0 mapped pages to one PSRAM page. As this function can be called for multiple regions, it needs to track if a page mapped to page 0 has previously been accounted for by a previous call. It does this using the page0_mapped in-out parameter. This logic contains an error: ``` if (*page0_mapped == 0) { // BUG: If page0_count is 0, 1 is still added count = valid_flash_count + 1 - page0_count; } else { count = valid_flash_count - page0_count; } *page0_mapped += page0_count; return count; ``` The current Cache_Count_Flash_Pages wrapper in the idf attempts to compensate for this bug by checking if the page0_mapped parameter was changed by a call to the function and reducing the count if it has not. This, however, will incorrectly over-compensate in situations where the initial value of page0_mapped was not zero as the code above only miscounts when it was zero. This patch addresses the issue in this wrapper function by correctly compensating for the bug only in cases where the final page0_mapped value is 0.
1 parent 79ee092 commit af7b6b7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

components/esp_rom/patches/esp_rom_cache_esp32s2_esp32s3.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
extern uint32_t rom_Cache_Count_Flash_Pages(uint32_t bus, uint32_t * page0_mapped);
2222
uint32_t Cache_Count_Flash_Pages(uint32_t bus, uint32_t * page0_mapped)
2323
{
24-
uint32_t page0_before_count = *page0_mapped;
2524
uint32_t flash_pages = 0;
2625
flash_pages = rom_Cache_Count_Flash_Pages(bus, page0_mapped);
2726

28-
/* No page mapped to page0, in this condition, the rom api will return
27+
/* No page mapped to page0 yet, in this condition, the rom api will return
2928
* unexpected value + 1.
3029
*/
31-
if (page0_before_count == *page0_mapped) {
30+
if (*page0_mapped == 0) {
3231
flash_pages--;
3332
}
3433
return flash_pages;

0 commit comments

Comments
 (0)