From fdf77999919b5adae95e54b3b93d453dd009b64b Mon Sep 17 00:00:00 2001 From: Yuxin Zhou Date: Wed, 13 Oct 2021 06:50:30 +0000 Subject: [PATCH] Release 6.1.9 --- common/inc/lx_api.h | 12 ++++- .../src/lx_nand_flash_block_obsoleted_check.c | 19 +++----- common/src/lx_nand_flash_block_reclaim.c | 32 +++----------- common/src/lx_nand_flash_open.c | 36 +++++---------- common/src/lx_nand_flash_simulator.c | 44 ++++++++++++++++++- .../src/lx_nor_flash_extended_cache_enable.c | 17 ++++++- 6 files changed, 90 insertions(+), 70 deletions(-) diff --git a/common/inc/lx_api.h b/common/inc/lx_api.h index e33072a..578012a 100644 --- a/common/inc/lx_api.h +++ b/common/inc/lx_api.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* lx_api.h PORTABLE C */ -/* 6.1.8 */ +/* 6.1.9 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -58,6 +58,10 @@ /* 08-02-2021 William E. Lamie Modified comment(s), and */ /* updated product constants, */ /* resulting in version 6.1.8 */ +/* 10-15-2021 Bhupendra Naphade Modified comment(s), */ +/* updated configuration for */ +/* nand flash */ +/* resulting in version 6.1.9 */ /* */ /**************************************************************************/ @@ -162,7 +166,7 @@ typedef unsigned long long ULONG64; #define AZURE_RTOS_LEVELX #define LEVELX_MAJOR_VERSION 6 #define LEVELX_MINOR_VERSION 1 -#define LEVELX_PATCH_VERSION 8 +#define LEVELX_PATCH_VERSION 9 /* Define general LevelX Constants. */ @@ -254,6 +258,10 @@ typedef unsigned long long ULONG64; #define LX_NAND_ERASE_COUNT_WRITE_SIZE (nand_flash -> lx_nand_flash_pages_per_block + 1) #endif +#ifndef LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE +#define LX_NAND_FLASH_MAPPING_LIST_UPDATE_DISABLE +#endif + /* Define the mask for the hash index into the NAND sector mapping cache table. The sector mapping cache is divided into 4 entry pieces that are indexed by the formula: diff --git a/common/src/lx_nand_flash_block_obsoleted_check.c b/common/src/lx_nand_flash_block_obsoleted_check.c index c339f82..792e040 100644 --- a/common/src/lx_nand_flash_block_obsoleted_check.c +++ b/common/src/lx_nand_flash_block_obsoleted_check.c @@ -40,7 +40,7 @@ /* FUNCTION RELEASE */ /* */ /* _lx_nand_flash_block_obsoleted_check PORTABLE C */ -/* 6.1.7 */ +/* 6.1.9 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -86,6 +86,10 @@ /* resulting in version 6.1 */ /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* resulting in version 6.1.7 */ +/* 10-15-2021 Bhupendra Naphade Modified comment(s), */ +/* removed multiple write */ +/* to page 0, */ +/* resulting in version 6.1.9 */ /* */ /**************************************************************************/ VOID _lx_nand_flash_block_obsoleted_check(LX_NAND_FLASH *nand_flash, ULONG block) @@ -316,21 +320,10 @@ UINT status; } /* Now store the erase count. */ - page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED); + page_word_ptr[0] = (erase_count); /* Write the erase count for the block. */ status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - - /* Check to see if the write was successful. */ - if (status == LX_SUCCESS) - { - - /* Now store the erase count. */ - page_word_ptr[0] = erase_count; - - /* Write the erase count for the block. */ - status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - } /* Check for an error from flash driver. */ if (status) diff --git a/common/src/lx_nand_flash_block_reclaim.c b/common/src/lx_nand_flash_block_reclaim.c index 8f1463f..43a7b4a 100644 --- a/common/src/lx_nand_flash_block_reclaim.c +++ b/common/src/lx_nand_flash_block_reclaim.c @@ -40,7 +40,7 @@ /* FUNCTION RELEASE */ /* */ /* _lx_nand_flash_block_reclaim PORTABLE C */ -/* 6.1.8 */ +/* 6.1.9 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -91,6 +91,10 @@ /* 08-02-2021 Bhupendra Naphade Modified comment(s), updated */ /* obselete page count check, */ /* resulting in version 6.1.8 */ +/* 10-15-2021 Bhupendra Naphade Modified comment(s), */ +/* removed multiple write */ +/* to page 0, */ +/* resulting in version 6.1.9 */ /* */ /**************************************************************************/ UINT _lx_nand_flash_block_reclaim(LX_NAND_FLASH *nand_flash) @@ -218,22 +222,11 @@ UINT status; } /* Now store the erase count. */ - page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED); + page_word_ptr[0] = (erase_count); /* Write the erase count for the block. */ status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - /* Check the status. */ - if (status == LX_SUCCESS) - { - - /* Now store the erase count. */ - page_word_ptr[0] = erase_count; - - /* Write the erase count for the block. */ - status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - } - /* Check for an error from flash driver. */ if (status) { @@ -578,21 +571,10 @@ UINT status; } /* Now store the erase count. */ - page_word_ptr[0] = (erase_count | LX_BLOCK_ERASED); + page_word_ptr[0] = (erase_count); /* Write the erase count for the block. */ status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - - /* Determine if the write was successful. */ - if (status == LX_SUCCESS) - { - - /* Now store the erase count. */ - page_word_ptr[0] = erase_count; - - /* Write the erase count for the block. */ - status = _lx_nand_flash_driver_write(nand_flash, erase_block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - } /* Check for an error from flash driver. */ if (status) diff --git a/common/src/lx_nand_flash_open.c b/common/src/lx_nand_flash_open.c index 68ad779..2397b7d 100644 --- a/common/src/lx_nand_flash_open.c +++ b/common/src/lx_nand_flash_open.c @@ -40,7 +40,7 @@ /* FUNCTION RELEASE */ /* */ /* _lx_nand_flash_open PORTABLE C */ -/* 6.1.7 */ +/* 6.1.9 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -94,6 +94,10 @@ /* resulting in version 6.1 */ /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* resulting in version 6.1.7 */ +/* 10-15-2021 Bhupendra Naphade Modified comment(s), */ +/* removed multiple write */ +/* to page 0, */ +/* resulting in version 6.1.9 */ /* */ /**************************************************************************/ UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *)) @@ -282,22 +286,11 @@ LX_INTERRUPT_SAVE_AREA } /* Setup the initial erase count to 1. */ - page_word_ptr[0] = (((ULONG) 1) | LX_BLOCK_ERASED); + page_word_ptr[0] = (((ULONG) 1)); /* Write the initial erase count for the block. */ status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - /* Check for status after the block erase. */ - if (status == LX_SUCCESS) - { - - /* Setup the initial erase count to 1. */ - page_word_ptr[0] = ((ULONG) 1); - - /* Write the initial erase count for the block. */ - status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - } - /* Check for an error from flash driver. */ if (status) { @@ -497,20 +490,11 @@ LX_INTERRUPT_SAVE_AREA /* Continue with next block. */ continue; } + + /* Write the final erase count for the block. */ + page_word_ptr[0] = max_erased_count; + status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, 1); - /* Write the initial erase count for the block. */ - page_word_ptr[0] = (max_erased_count | LX_BLOCK_ERASED); - status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - - /* Determine if the write was successful. */ - if (status == LX_SUCCESS) - { - - /* Write the initial erase count for the block. */ - page_word_ptr[0] = max_erased_count; - status = _lx_nand_flash_driver_write(nand_flash, block, 0, page_word_ptr, LX_NAND_ERASE_COUNT_WRITE_SIZE); - } - /* Check for an error from flash driver. */ if (status) { diff --git a/common/src/lx_nand_flash_simulator.c b/common/src/lx_nand_flash_simulator.c index e69449f..e190104 100644 --- a/common/src/lx_nand_flash_simulator.c +++ b/common/src/lx_nand_flash_simulator.c @@ -37,7 +37,6 @@ #define EXTRA_BYTE_POSITION 2 /* 2 is the extra bytes starting byte postion */ #define ECC_BYTE_POSITION 40 /* 40 is the ECC starting byte position */ - /* Definition of the spare area is relative to the block size of the NAND part and perhaps manufactures of the NAND part. Here are some common definitions: @@ -169,8 +168,14 @@ UINT _lx_nand_flash_simulator_write(ULONG block, ULONG page, ULONG *source, ULO { ULONG *flash_address; +UCHAR *flash_spare_address; +UINT bytes_computed; +UINT ecc_bytes =0; +UCHAR new_ecc_buffer[24]; +UCHAR *new_ecc_buffer_ptr = new_ecc_buffer; +UCHAR *ecc_buffer_ptr = new_ecc_buffer_ptr; +ULONG *page_ptr = &(nand_memory_area[block].physical_pages[page].memory[0]); - /* Increment the diag info. */ nand_block_diag[block].page_writes[page]++; if (nand_block_diag[block].page_writes[page] > nand_block_diag[block].max_page_writes[page]) @@ -192,6 +197,41 @@ ULONG *flash_address; *flash_address++ = *source++; } + /* Loop to compute the ECC over the entire NAND flash page. */ + bytes_computed = 0; + + while (bytes_computed < BYTES_PER_PHYSICAL_PAGE) + { + + /* Compute the ECC for this 256 byte piece of the page. */ + _lx_nand_flash_256byte_ecc_compute((UCHAR *)page_ptr, (UCHAR *)new_ecc_buffer_ptr); + + /* Move to the next 256 byte portion of the page. */ + bytes_computed = bytes_computed + 256; + + /* Move the page buffer forward. */ + page_ptr = page_ptr + 256; + + ecc_bytes = ecc_bytes + 3; + + /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ + new_ecc_buffer_ptr = new_ecc_buffer_ptr + 3; + } + + /* Setup destination pointer in the spare area. */ + flash_spare_address = (UCHAR *) &(nand_memory_area[block].physical_pages[page].spare[ECC_BYTE_POSITION]); + while(ecc_bytes--) + { + + /* Can the word be written? We can clear new bits, but just can't unclear + in a NAND device. */ + if ((*ecc_buffer_ptr & *flash_spare_address) != *ecc_buffer_ptr) + return(LX_INVALID_WRITE); + + /* Set an ecc byte in the spare area. */ + *flash_spare_address++ = *ecc_buffer_ptr++; + + } return(LX_SUCCESS); } diff --git a/common/src/lx_nor_flash_extended_cache_enable.c b/common/src/lx_nor_flash_extended_cache_enable.c index 3408de5..c7c1269 100644 --- a/common/src/lx_nor_flash_extended_cache_enable.c +++ b/common/src/lx_nor_flash_extended_cache_enable.c @@ -40,7 +40,7 @@ /* FUNCTION RELEASE */ /* */ /* _lx_nor_flash_extended_cache_enable PORTABLE C */ -/* 6.1.7 */ +/* 6.1.9 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -80,6 +80,10 @@ /* 06-02-2021 Bhupendra Naphade Modified comment(s), and */ /* updated product constants */ /* resulting in version 6.1.7 */ +/* 10-15-2021 Bhupendra Naphade Modified comment(s), and */ +/* added check for out of */ +/* bound memory access, */ +/* resulting in version 6.1.9 */ /* */ /**************************************************************************/ UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size) @@ -135,7 +139,16 @@ ULONG *cache_memory; } /* Save the number of cache entries. */ - nor_flash -> lx_nor_flash_extended_cache_entries = i; + if(i > LX_NOR_EXTENDED_CACHE_SIZE) + { + + nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE; + } + else + { + + nor_flash -> lx_nor_flash_extended_cache_entries = i; + } #ifdef LX_THREAD_SAFE_ENABLE