Covered NOR cache block erase boundary

Invalidate extended cache entries that end exactly at the erased block boundary and cover the last-sector case in the zero-base regression test.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Frédéric Desbiens
2026-06-30 10:04:02 -04:00
co-authored by Codex
parent 6122a080be
commit 309d2bd91b
2 changed files with 52 additions and 1 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ ULONG cache_entry_end_value;
cache_entry_start_value = (ULONG)cache_entry_start; cache_entry_start_value = (ULONG)cache_entry_start;
cache_entry_end_value = cache_entry_start_value + (LX_NOR_SECTOR_SIZE * sizeof(ULONG)); cache_entry_end_value = cache_entry_start_value + (LX_NOR_SECTOR_SIZE * sizeof(ULONG));
if ((block_start_address <= cache_entry_start_value) && (block_end_address > cache_entry_end_value)) if ((block_start_address <= cache_entry_start_value) && (block_end_address >= cache_entry_end_value))
{ {
/* Yes, this cache entry is in the block to be erased so invalidate it. */ /* Yes, this cache entry is in the block to be erased so invalidate it. */
@@ -264,6 +264,7 @@ void thread_0_entry(ULONG thread_input)
ULONG i, j, sector; ULONG i, j, sector;
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
ULONG read_count; ULONG read_count;
ULONG *last_sector_address;
#endif #endif
UINT status; UINT status;
@@ -280,6 +281,9 @@ ULONG *word_ptr;
LX_MEMSET(&nor_sim_flash, 0, sizeof(nor_sim_flash)); LX_MEMSET(&nor_sim_flash, 0, sizeof(nor_sim_flash));
status = zero_base_nor_initialize(&nor_sim_flash); status = zero_base_nor_initialize(&nor_sim_flash);
nor_zero_base_memory[0] = 0x12345678; nor_zero_base_memory[0] = 0x12345678;
/* MISRA C:2012 Rule 11.6 deviation: this test driver intentionally
treats NOR flash addresses as logical offset tokens. */
last_sector_address = (ULONG *)(LX_NOR_SECTOR_SIZE * sizeof(ULONG));
nor_zero_base_driver_read_count = 0; nor_zero_base_driver_read_count = 0;
if (status == LX_SUCCESS) if (status == LX_SUCCESS)
@@ -362,6 +366,53 @@ ULONG *word_ptr;
} }
} }
nor_zero_base_memory[LX_NOR_SECTOR_SIZE] = 0xABCDEF01;
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
if ((status != LX_SUCCESS) || (readbuffer[0] != 0xABCDEF01) || (nor_zero_base_driver_read_count != (read_count + 2)))
{
printf("FAILED!\n");
#ifdef BATCH_TEST
exit(1);
#endif
while(1)
{
}
}
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
if ((status != LX_SUCCESS) || (readbuffer[0] != 0xABCDEF01) || (nor_zero_base_driver_read_count != (read_count + 2)))
{
printf("FAILED!\n");
#ifdef BATCH_TEST
exit(1);
#endif
while(1)
{
}
}
read_count = nor_zero_base_driver_read_count;
status = _lx_nor_flash_driver_block_erase(&nor_sim_flash, 0, 0);
if (status == LX_SUCCESS)
{
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
}
if ((status != LX_SUCCESS) || (readbuffer[0] != LX_ALL_ONES) || (nor_zero_base_driver_read_count != (read_count + 1)))
{
printf("FAILED!\n");
#ifdef BATCH_TEST
exit(1);
#endif
while(1)
{
}
}
printf("SUCCESS!\n"); printf("SUCCESS!\n");
#endif #endif