Skip to content

Commit

Permalink
Update on 23 Oct 2023. Expand to see details.
Browse files Browse the repository at this point in the history
f203c27 Update headers and readme for 6.3.0 release.
40d3d10 Avoid clearing user extension in flash control block on opening flash
689dcc1 Added obsolete count and mapping bitmap cache for NOR flash. optimized block seraching logic.
b183526 Enable weekly pipeline build to avoid CodeQL expiration
2eec506 Enable codeql in onebranch pipeline
  • Loading branch information
xiuwencai committed Oct 23, 2023
1 parent e1a2752 commit cef8e4f
Show file tree
Hide file tree
Showing 13 changed files with 812 additions and 130 deletions.
31 changes: 27 additions & 4 deletions common/inc/lx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* APPLICATION INTERFACE DEFINITION RELEASE */
/* */
/* lx_api.h PORTABLE C */
/* 6.2.1 */
/* 6.3.0 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -79,7 +79,13 @@
/* modified NAND logic, */
/* added new driver interface */
/* and user extension, */
/* resulting in version 6.2.1 */
/* resulting in version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* made LX_NOR_SECTOR_SIZE */
/* configurable, added mapping */
/* bitmap and obsolete count */
/* cache for NOR flash, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -191,8 +197,8 @@ typedef unsigned long long ULONG64;
/* Define basic constants for the LevelX Stack. */
#define AZURE_RTOS_LEVELX
#define LEVELX_MAJOR_VERSION 6
#define LEVELX_MINOR_VERSION 2
#define LEVELX_PATCH_VERSION 1
#define LEVELX_MINOR_VERSION 3
#define LEVELX_PATCH_VERSION 0


/* Define general LevelX Constants. */
Expand Down Expand Up @@ -233,7 +239,9 @@ typedef unsigned long long ULONG64;

#define LX_NOR_FLASH_OPENED ((ULONG) 0x4E4F524F)
#define LX_NOR_FLASH_CLOSED ((ULONG) 0x4E4F5244)
#ifndef LX_NOR_SECTOR_SIZE
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
#endif
#define LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET 1
#define LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET 2
#ifndef LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA
Expand All @@ -246,6 +254,11 @@ typedef unsigned long long ULONG64;
#ifndef LX_NOR_EXTENDED_CACHE_SIZE
#define LX_NOR_EXTENDED_CACHE_SIZE 8 /* Maximum number of extended cache sectors. */
#endif
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
#ifndef LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
#endif
#endif


/* Define the mask for the hash index into the sector mapping cache table. The sector mapping cache is divided
Expand Down Expand Up @@ -566,6 +579,7 @@ typedef struct LX_NOR_FLASH_STRUCT
ULONG lx_nor_flash_mapped_physical_sectors;
ULONG lx_nor_flash_obsolete_physical_sectors;
ULONG lx_nor_flash_minimum_erase_count;
ULONG lx_nor_flash_minimum_erased_blocks;
ULONG lx_nor_flash_maximum_erase_count;

ULONG lx_nor_flash_free_block_search;
Expand Down Expand Up @@ -616,6 +630,15 @@ typedef struct LX_NOR_FLASH_STRUCT
lx_nor_flash_extended_cache[LX_NOR_EXTENDED_CACHE_SIZE];
ULONG lx_nor_flash_extended_cache_hits;
ULONG lx_nor_flash_extended_cache_misses;
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
ULONG *lx_nor_flash_extended_cache_mapping_bitmap;
ULONG lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector;
#endif
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
*lx_nor_flash_extended_cache_obsolete_count;
ULONG lx_nor_flash_extended_cache_obsolete_count_max_block;
#endif
#endif

#ifdef LX_THREAD_SAFE_ENABLE
Expand Down
37 changes: 33 additions & 4 deletions common/inc/lx_user_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* PORT SPECIFIC C INFORMATION RELEASE */
/* */
/* lx_user.h PORTABLE C */
/* 6.2.1 */
/* 6.3.0 */
/* */
/* AUTHOR */
/* */
Expand All @@ -50,7 +50,12 @@
/* resulting in version 6.1.7 */
/* 03-08-2023 Xiuwen Cai Modified comment(s), and */
/* added new NAND options, */
/* resulting in version 6.2.1 */
/* resulting in version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* added options for mapping , */
/* bitmap cache and obsolete */
/* count cache, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -113,15 +118,39 @@

/* #define LX_STANDALONE_ENABLE */

/* Define user extension for NOR flash control block. */
/* Define user extension for NOR flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */
/*
#define LX_NOR_FLASH_USER_EXTENSION ????
*/

/* Define user extension for NAND flash control block. */
/* Define user extension for NAND flash control block. User extension is placed at the end of flash control block and it is not cleared on opening flash. */
/*
#define LX_NAND_FLASH_USER_EXTENSION ????
*/

/* Determine if logical sector mapping bitmap should be enabled in extended cache.
Cache memory will be allocated to sector mapping bitmap first. One bit can be allocated for each physical sector. */
/*
#define LX_NOR_ENABLE_MAPPING_BITMAP
*/

/* Determine if obsolete count cache should be enabled in extended cache.
Cache memory will be allocated to obsolete count cache after the mapping bitmap if enabled,
and the rest of the cache memory is allocated to sector cache. */
/*
#define LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
*/

/* Defines obsolete count cache element size. If number of sectors per block is greater than 256, use USHORT instead of UCHAR. */
/*
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
*/

/* Define the logical sector size for NOR flash. The sector size is in units of 32-bit words.
This sector size should match the sector size used in file system. */
/*
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
*/

#endif

39 changes: 24 additions & 15 deletions common/src/fx_nor_flash_simulator_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ LX_NOR_FLASH nor_flash;
the fx_media_open call.
fx_media_format(&ram_disk,
_fx_nor_sim_driver, // Driver entry
FX_NULL, // Unused
media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size
"MY_NOR_DISK", // Volume Name
1, // Number of FATs
32, // Directory Entries
0, // Hidden sectors
120, // Total sectors
512, // Sector size
1, // Sectors per cluster
1, // Heads
1); // Sectors per track
_fx_nor_sim_driver, // Driver entry
FX_NULL, // Unused
media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size
"MY_NOR_DISK", // Volume Name
1, // Number of FATs
32, // Directory Entries
0, // Hidden sectors
120, // Total sectors
LX_NOR_SECTOR_SIZE * sizeof(ULONG), // Sector size
1, // Sectors per cluster
1, // Heads
1); // Sectors per track
*/

Expand Down Expand Up @@ -231,7 +231,7 @@ UINT status;

/* Move to the next entries. */
logical_sector++;
destination_buffer = destination_buffer + 512;
destination_buffer = destination_buffer + media_ptr -> fx_media_bytes_per_sector;
}

/* Successful driver request. */
Expand Down Expand Up @@ -265,7 +265,7 @@ UINT status;

/* Move to the next entries. */
logical_sector++;
source_buffer = source_buffer + 512;
source_buffer = source_buffer + media_ptr -> fx_media_bytes_per_sector;
}

/* Successful driver request. */
Expand Down Expand Up @@ -428,6 +428,15 @@ UINT status;
case FX_DRIVER_BOOT_WRITE:
{

/* Make sure the media bytes per sector equals to the LevelX logical sector size. */
if (media_ptr -> fx_media_bytes_per_sector != (LX_NOR_SECTOR_SIZE) * sizeof(ULONG))
{

/* Sector size mismatch, return error. */
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
break;
}

/* Write the boot record and return to the caller. */

/* Setup the source buffer. */
Expand Down
13 changes: 9 additions & 4 deletions common/src/lx_nand_flash_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* FUNCTION RELEASE */
/* */
/* _lx_nand_flash_format PORTABLE C */
/* 6.2.1 */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Xiuwen Cai, Microsoft Corporation */
Expand Down Expand Up @@ -87,7 +87,12 @@
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* avoided clearing user */
/* extension in flash control */
/* block, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
Expand All @@ -102,8 +107,8 @@ UCHAR *page_buffer_ptr;

LX_PARAMETER_NOT_USED(name);

/* Clear the NAND flash control block. */
LX_MEMSET(nand_flash, 0, sizeof(LX_NAND_FLASH));
/* Clear the NAND flash control block. User extension is not cleared. */
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));

/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);
Expand Down
15 changes: 10 additions & 5 deletions common/src/lx_nand_flash_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* FUNCTION RELEASE */
/* */
/* _lx_nand_flash_open PORTABLE C */
/* 6.2.1 */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Xiuwen Cai, Microsoft Corporation */
Expand Down Expand Up @@ -85,7 +85,12 @@
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* avoided clearing user */
/* extension in flash control */
/* block, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
Expand All @@ -107,9 +112,9 @@ LX_INTERRUPT_SAVE_AREA

LX_PARAMETER_NOT_USED(name);

/* Clear the NAND flash control block. */
LX_MEMSET(nand_flash, 0, sizeof(LX_NAND_FLASH));
/* Clear the NAND flash control block. User extension is not cleared. */
LX_MEMSET(nand_flash, 0, (ULONG)((UCHAR*)&(nand_flash -> lx_nand_flash_open_previous) - (UCHAR*)nand_flash) + sizeof(nand_flash -> lx_nand_flash_open_previous));

/* Call the flash driver's initialization function. */
(nand_driver_initialize)(nand_flash);

Expand Down
45 changes: 43 additions & 2 deletions common/src/lx_nor_flash_block_reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* FUNCTION RELEASE */
/* */
/* _lx_nor_flash_block_reclaim PORTABLE C */
/* 6.1.7 */
/* 6.3.0 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -83,6 +83,11 @@
/* resulting in version 6.1 */
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
/* resulting in version 6.1.7 */
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
/* added count for minimum */
/* erased blocks, added */
/* obsolete count cache, */
/* resulting in version 6.3.0 */
/* */
/**************************************************************************/
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash)
Expand Down Expand Up @@ -156,7 +161,15 @@ UINT status;
/* Return the error. */
return(status);
}


/* Determine if the erase count is at the minimum. */
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
{

/* Yes, decrement the minimum erased block count. */
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
}

/* Increment the erase count. */
erase_count++;

Expand Down Expand Up @@ -225,6 +238,16 @@ UINT status;
/* Update parameters of this flash. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors;
nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE

/* Check if the block is cached by obsolete count cache. */
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
{

/* Yes, clear the obsolete count for this block. */
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
}
#endif
}
else
{
Expand Down Expand Up @@ -489,6 +512,14 @@ UINT status;
return(status);
}

/* Determine if the erase count is at the minimum. */
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
{

/* Yes, decrement the minimum erased block count. */
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
}

/* Increment the erase count. */
erase_count++;

Expand Down Expand Up @@ -557,6 +588,16 @@ UINT status;
/* Update parameters of this flash. */
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors;
nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE

/* Check if the block is cached by obsolete count cache. */
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
{

/* Yes, clear the obsolete count for this block. */
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
}
#endif
}
}

Expand Down
Loading

0 comments on commit cef8e4f

Please sign in to comment.