Skip to content

Commit 337f790

Browse files
committed
bug fix of assert happen in PSRAM
1 parent 1837a03 commit 337f790

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

components/soc/esp32/include/soc/soc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
#define DR_REG_AES_BASE 0x3ff01000
7676
#define DR_REG_RSA_BASE 0x3ff02000
7777
#define DR_REG_SHA_BASE 0x3ff03000
78-
#define DR_REG_DPORT_END 0x3ff03FFC
78+
#define DR_REG_FLASH_MMU_TABLE_PRO 0x3ff10000
79+
#define DR_REG_FLASH_MMU_TABLE_APP 0x3ff12000
80+
#define DR_REG_DPORT_END 0x3ff13FFC
7981
#define DR_REG_UART_BASE 0x3ff40000
8082
#define DR_REG_SPI1_BASE 0x3ff42000
8183
#define DR_REG_SPI0_BASE 0x3ff43000

components/spi_flash/flash_mmap.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
5858
Returns true if cache was flushed.
5959
*/
60+
6061
static bool spi_flash_ensure_unmodified_region(size_t start_addr, size_t length);
6162

6263
typedef struct mmap_entry_{
@@ -78,10 +79,12 @@ static void IRAM_ATTR spi_flash_mmap_init()
7879
if (s_mmap_page_refcnt[0] != 0) {
7980
return; /* mmap data already initialised */
8081
}
81-
82+
83+
DPORT_STALL_OTHER_CPU_START();
8284
for (int i = 0; i < REGIONS_COUNT * PAGES_PER_REGION; ++i) {
8385
uint32_t entry_pro = DPORT_PRO_FLASH_MMU_TABLE[i];
8486
uint32_t entry_app = DPORT_APP_FLASH_MMU_TABLE[i];
87+
8588
if (entry_pro != entry_app) {
8689
// clean up entries used by boot loader
8790
entry_pro = DPORT_FLASH_MMU_TABLE_INVALID_VAL;
@@ -94,6 +97,7 @@ static void IRAM_ATTR spi_flash_mmap_init()
9497
DPORT_APP_FLASH_MMU_TABLE[i] = DPORT_FLASH_MMU_TABLE_INVALID_VAL;
9598
}
9699
}
100+
DPORT_STALL_OTHER_CPU_END();
97101
}
98102

99103
esp_err_t IRAM_ATTR spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_memory_t memory,
@@ -175,13 +179,15 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
175179
for (start = region_begin; start < end; ++start) {
176180
int pageno = 0;
177181
int pos;
182+
DPORT_STALL_OTHER_CPU_START();
178183
for (pos = start; pos < start + page_count; ++pos, ++pageno) {
179184
int table_val = (int) DPORT_PRO_FLASH_MMU_TABLE[pos];
180185
uint8_t refcnt = s_mmap_page_refcnt[pos];
181186
if (refcnt != 0 && table_val != pages[pageno]) {
182187
break;
183188
}
184189
}
190+
DPORT_STALL_OTHER_CPU_END();
185191
// whole mapping range matched, bail out
186192
if (pos - start == page_count) {
187193
break;
@@ -195,6 +201,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
195201
} else {
196202
// set up mapping using pages
197203
uint32_t pageno = 0;
204+
DPORT_STALL_OTHER_CPU_START();
198205
for (int i = start; i != start + page_count; ++i, ++pageno) {
199206
// sanity check: we won't reconfigure entries with non-zero reference count
200207
assert(s_mmap_page_refcnt[i] == 0 ||
@@ -209,7 +216,7 @@ esp_err_t IRAM_ATTR spi_flash_mmap_pages(int *pages, size_t page_count, spi_flas
209216
}
210217
++s_mmap_page_refcnt[i];
211218
}
212-
219+
DPORT_STALL_OTHER_CPU_END();
213220
LIST_INSERT_HEAD(&s_mmap_entries_head, new_entry, entries);
214221
new_entry->page = start;
215222
new_entry->count = page_count;
@@ -250,13 +257,15 @@ void IRAM_ATTR spi_flash_munmap(spi_flash_mmap_handle_t handle)
250257
// for each page, decrement reference counter
251258
// if reference count is zero, disable MMU table entry to
252259
// facilitate debugging of use-after-free conditions
260+
DPORT_STALL_OTHER_CPU_START();
253261
for (int i = it->page; i < it->page + it->count; ++i) {
254262
assert(s_mmap_page_refcnt[i] > 0);
255263
if (--s_mmap_page_refcnt[i] == 0) {
256264
DPORT_PRO_FLASH_MMU_TABLE[i] = INVALID_ENTRY_VAL;
257265
DPORT_APP_FLASH_MMU_TABLE[i] = INVALID_ENTRY_VAL;
258266
}
259267
}
268+
DPORT_STALL_OTHER_CPU_END();
260269
LIST_REMOVE(it, entries);
261270
break;
262271
}
@@ -369,7 +378,9 @@ uint32_t spi_flash_cache2phys(const void *cached)
369378
/* cached address was not in IROM or DROM */
370379
return SPI_FLASH_CACHE2PHYS_FAIL;
371380
}
381+
DPORT_STALL_OTHER_CPU_START();
372382
uint32_t phys_page = DPORT_PRO_FLASH_MMU_TABLE[cache_page];
383+
DPORT_STALL_OTHER_CPU_END();
373384
if (phys_page == INVALID_ENTRY_VAL) {
374385
/* page is not mapped */
375386
return SPI_FLASH_CACHE2PHYS_FAIL;
@@ -396,13 +407,16 @@ const void *spi_flash_phys2cache(uint32_t phys_offs, spi_flash_mmap_memory_t mem
396407
base = VADDR1_START_ADDR;
397408
page_delta = 64;
398409
}
399-
410+
411+
DPORT_STALL_OTHER_CPU_START();
400412
for (int i = start; i < end; i++) {
401413
if (DPORT_PRO_FLASH_MMU_TABLE[i] == phys_page) {
402414
i -= page_delta;
403415
intptr_t cache_page = base + (SPI_FLASH_MMU_PAGE_SIZE * i);
416+
DPORT_STALL_OTHER_CPU_END();
404417
return (const void *) (cache_page | (phys_offs & (SPI_FLASH_MMU_PAGE_SIZE-1)));
405418
}
406419
}
420+
DPORT_STALL_OTHER_CPU_END();
407421
return NULL;
408422
}

0 commit comments

Comments
 (0)