From 309d2bd91b658ea01591c4c43e02924147e3cfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Tue, 30 Jun 2026 09:48:42 -0400 Subject: [PATCH] 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 --- common/src/lx_nor_flash_driver_block_erase.c | 2 +- test/regression/levelx_nor_flash_test_cache.c | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/common/src/lx_nor_flash_driver_block_erase.c b/common/src/lx_nor_flash_driver_block_erase.c index c430129..9ca8269 100644 --- a/common/src/lx_nor_flash_driver_block_erase.c +++ b/common/src/lx_nor_flash_driver_block_erase.c @@ -107,7 +107,7 @@ ULONG cache_entry_end_value; cache_entry_start_value = (ULONG)cache_entry_start; 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. */ diff --git a/test/regression/levelx_nor_flash_test_cache.c b/test/regression/levelx_nor_flash_test_cache.c index 1911640..1317b0e 100644 --- a/test/regression/levelx_nor_flash_test_cache.c +++ b/test/regression/levelx_nor_flash_test_cache.c @@ -264,6 +264,7 @@ void thread_0_entry(ULONG thread_input) ULONG i, j, sector; #ifndef LX_NOR_DISABLE_EXTENDED_CACHE ULONG read_count; +ULONG *last_sector_address; #endif UINT status; @@ -280,6 +281,9 @@ ULONG *word_ptr; LX_MEMSET(&nor_sim_flash, 0, sizeof(nor_sim_flash)); status = zero_base_nor_initialize(&nor_sim_flash); 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; 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"); #endif