Skip to content

Commit cef8e4f

Browse files
committed
Update on 23 Oct 2023. Expand to see details.
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
1 parent e1a2752 commit cef8e4f

13 files changed

+812
-130
lines changed

common/inc/lx_api.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* APPLICATION INTERFACE DEFINITION RELEASE */
2727
/* */
2828
/* lx_api.h PORTABLE C */
29-
/* 6.2.1 */
29+
/* 6.3.0 */
3030
/* AUTHOR */
3131
/* */
3232
/* William E. Lamie, Microsoft Corporation */
@@ -79,7 +79,13 @@
7979
/* modified NAND logic, */
8080
/* added new driver interface */
8181
/* and user extension, */
82-
/* resulting in version 6.2.1 */
82+
/* resulting in version 6.2.1 */
83+
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
84+
/* made LX_NOR_SECTOR_SIZE */
85+
/* configurable, added mapping */
86+
/* bitmap and obsolete count */
87+
/* cache for NOR flash, */
88+
/* resulting in version 6.3.0 */
8389
/* */
8490
/**************************************************************************/
8591

@@ -191,8 +197,8 @@ typedef unsigned long long ULONG64;
191197
/* Define basic constants for the LevelX Stack. */
192198
#define AZURE_RTOS_LEVELX
193199
#define LEVELX_MAJOR_VERSION 6
194-
#define LEVELX_MINOR_VERSION 2
195-
#define LEVELX_PATCH_VERSION 1
200+
#define LEVELX_MINOR_VERSION 3
201+
#define LEVELX_PATCH_VERSION 0
196202

197203

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

234240
#define LX_NOR_FLASH_OPENED ((ULONG) 0x4E4F524F)
235241
#define LX_NOR_FLASH_CLOSED ((ULONG) 0x4E4F5244)
242+
#ifndef LX_NOR_SECTOR_SIZE
236243
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
244+
#endif
237245
#define LX_NOR_FLASH_MIN_LOGICAL_SECTOR_OFFSET 1
238246
#define LX_NOR_FLASH_MAX_LOGICAL_SECTOR_OFFSET 2
239247
#ifndef LX_NOR_FLASH_MAX_ERASE_COUNT_DELTA
@@ -246,6 +254,11 @@ typedef unsigned long long ULONG64;
246254
#ifndef LX_NOR_EXTENDED_CACHE_SIZE
247255
#define LX_NOR_EXTENDED_CACHE_SIZE 8 /* Maximum number of extended cache sectors. */
248256
#endif
257+
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
258+
#ifndef LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
259+
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
260+
#endif
261+
#endif
249262

250263

251264
/* Define the mask for the hash index into the sector mapping cache table. The sector mapping cache is divided
@@ -566,6 +579,7 @@ typedef struct LX_NOR_FLASH_STRUCT
566579
ULONG lx_nor_flash_mapped_physical_sectors;
567580
ULONG lx_nor_flash_obsolete_physical_sectors;
568581
ULONG lx_nor_flash_minimum_erase_count;
582+
ULONG lx_nor_flash_minimum_erased_blocks;
569583
ULONG lx_nor_flash_maximum_erase_count;
570584

571585
ULONG lx_nor_flash_free_block_search;
@@ -616,6 +630,15 @@ typedef struct LX_NOR_FLASH_STRUCT
616630
lx_nor_flash_extended_cache[LX_NOR_EXTENDED_CACHE_SIZE];
617631
ULONG lx_nor_flash_extended_cache_hits;
618632
ULONG lx_nor_flash_extended_cache_misses;
633+
#ifdef LX_NOR_ENABLE_MAPPING_BITMAP
634+
ULONG *lx_nor_flash_extended_cache_mapping_bitmap;
635+
ULONG lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector;
636+
#endif
637+
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
638+
LX_NOR_OBSOLETE_COUNT_CACHE_TYPE
639+
*lx_nor_flash_extended_cache_obsolete_count;
640+
ULONG lx_nor_flash_extended_cache_obsolete_count_max_block;
641+
#endif
619642
#endif
620643

621644
#ifdef LX_THREAD_SAFE_ENABLE

common/inc/lx_user_sample.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* PORT SPECIFIC C INFORMATION RELEASE */
2727
/* */
2828
/* lx_user.h PORTABLE C */
29-
/* 6.2.1 */
29+
/* 6.3.0 */
3030
/* */
3131
/* AUTHOR */
3232
/* */
@@ -50,7 +50,12 @@
5050
/* resulting in version 6.1.7 */
5151
/* 03-08-2023 Xiuwen Cai Modified comment(s), and */
5252
/* added new NAND options, */
53-
/* resulting in version 6.2.1 */
53+
/* resulting in version 6.2.1 */
54+
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
55+
/* added options for mapping , */
56+
/* bitmap cache and obsolete */
57+
/* count cache, */
58+
/* resulting in version 6.3.0 */
5459
/* */
5560
/**************************************************************************/
5661

@@ -113,15 +118,39 @@
113118

114119
/* #define LX_STANDALONE_ENABLE */
115120

116-
/* Define user extension for NOR flash control block. */
121+
/* 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. */
117122
/*
118123
#define LX_NOR_FLASH_USER_EXTENSION ????
119124
*/
120125

121-
/* Define user extension for NAND flash control block. */
126+
/* 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. */
122127
/*
123128
#define LX_NAND_FLASH_USER_EXTENSION ????
124129
*/
125130

131+
/* Determine if logical sector mapping bitmap should be enabled in extended cache.
132+
Cache memory will be allocated to sector mapping bitmap first. One bit can be allocated for each physical sector. */
133+
/*
134+
#define LX_NOR_ENABLE_MAPPING_BITMAP
135+
*/
136+
137+
/* Determine if obsolete count cache should be enabled in extended cache.
138+
Cache memory will be allocated to obsolete count cache after the mapping bitmap if enabled,
139+
and the rest of the cache memory is allocated to sector cache. */
140+
/*
141+
#define LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
142+
*/
143+
144+
/* Defines obsolete count cache element size. If number of sectors per block is greater than 256, use USHORT instead of UCHAR. */
145+
/*
146+
#define LX_NOR_OBSOLETE_COUNT_CACHE_TYPE UCHAR
147+
*/
148+
149+
/* Define the logical sector size for NOR flash. The sector size is in units of 32-bit words.
150+
This sector size should match the sector size used in file system. */
151+
/*
152+
#define LX_NOR_SECTOR_SIZE (512/sizeof(ULONG))
153+
*/
154+
126155
#endif
127156

common/src/fx_nor_flash_simulator_driver.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ LX_NOR_FLASH nor_flash;
3636
the fx_media_open call.
3737
3838
fx_media_format(&ram_disk,
39-
_fx_nor_sim_driver, // Driver entry
40-
FX_NULL, // Unused
41-
media_memory, // Media buffer pointer
42-
sizeof(media_memory), // Media buffer size
43-
"MY_NOR_DISK", // Volume Name
44-
1, // Number of FATs
45-
32, // Directory Entries
46-
0, // Hidden sectors
47-
120, // Total sectors
48-
512, // Sector size
49-
1, // Sectors per cluster
50-
1, // Heads
51-
1); // Sectors per track
39+
_fx_nor_sim_driver, // Driver entry
40+
FX_NULL, // Unused
41+
media_memory, // Media buffer pointer
42+
sizeof(media_memory), // Media buffer size
43+
"MY_NOR_DISK", // Volume Name
44+
1, // Number of FATs
45+
32, // Directory Entries
46+
0, // Hidden sectors
47+
120, // Total sectors
48+
LX_NOR_SECTOR_SIZE * sizeof(ULONG), // Sector size
49+
1, // Sectors per cluster
50+
1, // Heads
51+
1); // Sectors per track
5252
5353
*/
5454

@@ -231,7 +231,7 @@ UINT status;
231231

232232
/* Move to the next entries. */
233233
logical_sector++;
234-
destination_buffer = destination_buffer + 512;
234+
destination_buffer = destination_buffer + media_ptr -> fx_media_bytes_per_sector;
235235
}
236236

237237
/* Successful driver request. */
@@ -265,7 +265,7 @@ UINT status;
265265

266266
/* Move to the next entries. */
267267
logical_sector++;
268-
source_buffer = source_buffer + 512;
268+
source_buffer = source_buffer + media_ptr -> fx_media_bytes_per_sector;
269269
}
270270

271271
/* Successful driver request. */
@@ -428,6 +428,15 @@ UINT status;
428428
case FX_DRIVER_BOOT_WRITE:
429429
{
430430

431+
/* Make sure the media bytes per sector equals to the LevelX logical sector size. */
432+
if (media_ptr -> fx_media_bytes_per_sector != (LX_NOR_SECTOR_SIZE) * sizeof(ULONG))
433+
{
434+
435+
/* Sector size mismatch, return error. */
436+
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
437+
break;
438+
}
439+
431440
/* Write the boot record and return to the caller. */
432441

433442
/* Setup the source buffer. */

common/src/lx_nand_flash_format.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/* FUNCTION RELEASE */
4141
/* */
4242
/* _lx_nand_flash_format PORTABLE C */
43-
/* 6.2.1 */
43+
/* 6.3.0 */
4444
/* AUTHOR */
4545
/* */
4646
/* Xiuwen Cai, Microsoft Corporation */
@@ -87,7 +87,12 @@
8787
/* */
8888
/* DATE NAME DESCRIPTION */
8989
/* */
90-
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
90+
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
91+
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
92+
/* avoided clearing user */
93+
/* extension in flash control */
94+
/* block, */
95+
/* resulting in version 6.3.0 */
9196
/* */
9297
/**************************************************************************/
9398
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
@@ -102,8 +107,8 @@ UCHAR *page_buffer_ptr;
102107

103108
LX_PARAMETER_NOT_USED(name);
104109

105-
/* Clear the NAND flash control block. */
106-
LX_MEMSET(nand_flash, 0, sizeof(LX_NAND_FLASH));
110+
/* Clear the NAND flash control block. User extension is not cleared. */
111+
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));
107112

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

common/src/lx_nand_flash_open.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/* FUNCTION RELEASE */
4141
/* */
4242
/* _lx_nand_flash_open PORTABLE C */
43-
/* 6.2.1 */
43+
/* 6.3.0 */
4444
/* AUTHOR */
4545
/* */
4646
/* Xiuwen Cai, Microsoft Corporation */
@@ -85,7 +85,12 @@
8585
/* */
8686
/* DATE NAME DESCRIPTION */
8787
/* */
88-
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
88+
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
89+
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
90+
/* avoided clearing user */
91+
/* extension in flash control */
92+
/* block, */
93+
/* resulting in version 6.3.0 */
8994
/* */
9095
/**************************************************************************/
9196
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
@@ -107,9 +112,9 @@ LX_INTERRUPT_SAVE_AREA
107112

108113
LX_PARAMETER_NOT_USED(name);
109114

110-
/* Clear the NAND flash control block. */
111-
LX_MEMSET(nand_flash, 0, sizeof(LX_NAND_FLASH));
112-
115+
/* Clear the NAND flash control block. User extension is not cleared. */
116+
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));
117+
113118
/* Call the flash driver's initialization function. */
114119
(nand_driver_initialize)(nand_flash);
115120

common/src/lx_nor_flash_block_reclaim.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/* FUNCTION RELEASE */
4141
/* */
4242
/* _lx_nor_flash_block_reclaim PORTABLE C */
43-
/* 6.1.7 */
43+
/* 6.3.0 */
4444
/* AUTHOR */
4545
/* */
4646
/* William E. Lamie, Microsoft Corporation */
@@ -83,6 +83,11 @@
8383
/* resulting in version 6.1 */
8484
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
8585
/* resulting in version 6.1.7 */
86+
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
87+
/* added count for minimum */
88+
/* erased blocks, added */
89+
/* obsolete count cache, */
90+
/* resulting in version 6.3.0 */
8691
/* */
8792
/**************************************************************************/
8893
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash)
@@ -156,7 +161,15 @@ UINT status;
156161
/* Return the error. */
157162
return(status);
158163
}
159-
164+
165+
/* Determine if the erase count is at the minimum. */
166+
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
167+
{
168+
169+
/* Yes, decrement the minimum erased block count. */
170+
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
171+
}
172+
160173
/* Increment the erase count. */
161174
erase_count++;
162175

@@ -225,6 +238,16 @@ UINT status;
225238
/* Update parameters of this flash. */
226239
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors;
227240
nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
241+
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
242+
243+
/* Check if the block is cached by obsolete count cache. */
244+
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
245+
{
246+
247+
/* Yes, clear the obsolete count for this block. */
248+
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
249+
}
250+
#endif
228251
}
229252
else
230253
{
@@ -489,6 +512,14 @@ UINT status;
489512
return(status);
490513
}
491514

515+
/* Determine if the erase count is at the minimum. */
516+
if (erase_count == nor_flash -> lx_nor_flash_minimum_erase_count)
517+
{
518+
519+
/* Yes, decrement the minimum erased block count. */
520+
nor_flash -> lx_nor_flash_minimum_erased_blocks--;
521+
}
522+
492523
/* Increment the erase count. */
493524
erase_count++;
494525

@@ -557,6 +588,16 @@ UINT status;
557588
/* Update parameters of this flash. */
558589
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors;
559590
nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors;
591+
#ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
592+
593+
/* Check if the block is cached by obsolete count cache. */
594+
if (erase_block < nor_flash -> lx_nor_flash_extended_cache_obsolete_count_max_block)
595+
{
596+
597+
/* Yes, clear the obsolete count for this block. */
598+
nor_flash -> lx_nor_flash_extended_cache_obsolete_count[erase_block] = 0;
599+
}
600+
#endif
560601
}
561602
}
562603

0 commit comments

Comments
 (0)