Skip to content

Commit 4005a42

Browse files
authored
Merging changes for the v.6.5.1.202602 release (#75)
2 parents a46b74f + 123218c commit 4005a42

22 files changed

Lines changed: 1234 additions & 2 deletions

common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_sources(${PROJECT_NAME} PRIVATE
2323
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format_extended.c
2424
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c
2525
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c
26+
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_logical_group_compact.c
2627
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
2728
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
2829
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c

common/inc/lx_api.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ typedef unsigned long long ULONG64;
149149
#define AZURE_RTOS_LEVELX
150150
#define LEVELX_MAJOR_VERSION 6
151151
#define LEVELX_MINOR_VERSION 5
152-
#define LEVELX_PATCH_VERSION 0
153-
#define LEVELX_BUILD_VERSION 202601
152+
#define LEVELX_PATCH_VERSION 1
153+
#define LEVELX_BUILD_VERSION 202602
154154
#define LEVELX_HOTFIX_VERSION ' '
155155

156156

@@ -274,6 +274,17 @@ typedef unsigned long long ULONG64;
274274
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
275275
#endif
276276

277+
/* When LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE is defined, sector releases from full blocks
278+
are deferred when free block count exceeds the threshold below (opt-in, default: off).
279+
Requires pages_per_block <= 4095 (bit 12 is reserved for COMPACTION_PENDING flag). */
280+
/* #define LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
281+
282+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
283+
#ifndef LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD
284+
#define LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD 10u
285+
#endif
286+
#endif
287+
277288
#ifndef LX_UTILITY_SHORT_SET
278289
#define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value)
279290
#endif
@@ -328,6 +339,11 @@ typedef unsigned long long ULONG64;
328339
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
329340
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
330341
#define LX_NAND_BLOCK_STATUS_MAPPING_PRESENT 0x1000u
342+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
343+
/* Repurpose the otherwise-unused MAPPING_PRESENT bit to signal a block whose compaction
344+
has been deferred. Only valid when pages_per_block <= 4095. */
345+
#define LX_NAND_BLOCK_STATUS_COMPACTION_PENDING LX_NAND_BLOCK_STATUS_MAPPING_PRESENT
346+
#endif
331347
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
332348
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
333349
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
@@ -402,6 +418,12 @@ typedef struct LX_NAND_FLASH_STRUCT
402418
USHORT *lx_nand_flash_block_list;
403419
ULONG lx_nand_flash_block_list_size;
404420
ULONG lx_nand_flash_free_block_list_tail;
421+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
422+
/* Parallel to block_mapping_table: physical block with pending compaction for a group,
423+
or LX_NAND_BLOCK_UNMAPPED when no compaction is pending. */
424+
USHORT *lx_nand_flash_block_compaction_table;
425+
ULONG lx_nand_flash_block_compaction_table_size;
426+
#endif
405427
ULONG lx_nand_flash_mapped_block_list_head;
406428

407429
ULONG lx_nand_flash_metadata_block_number;
@@ -771,6 +793,9 @@ UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buf
771793
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page);
772794
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer);
773795
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer);
796+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
797+
UINT _lx_nand_flash_logical_group_compact(LX_NAND_FLASH *nand_flash, ULONG logical_group);
798+
#endif
774799

775800
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash);
776801
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);

common/src/lx_nand_flash_block_allocate.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* SPDX-License-Identifier: MIT
1010
**************************************************************************/
1111

12+
// Some portions generated by Copilot (Sonnet 4.6).
1213

1314
/**************************************************************************/
1415
/**************************************************************************/
@@ -75,6 +76,43 @@ UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
7576
if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
7677
{
7778

79+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
80+
{
81+
82+
ULONG lg;
83+
UINT compact_status;
84+
85+
/* Emergency compaction: find any pending compaction and execute it to
86+
reclaim the old full block. */
87+
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
88+
{
89+
90+
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
91+
{
92+
93+
compact_status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
94+
95+
if (compact_status == LX_SUCCESS)
96+
{
97+
98+
/* Retry the allocation after compaction freed a block. */
99+
if (nand_flash -> lx_nand_flash_free_block_list_tail > 0)
100+
{
101+
102+
nand_flash -> lx_nand_flash_free_block_list_tail--;
103+
*block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail];
104+
return(LX_SUCCESS);
105+
}
106+
}
107+
108+
/* Attempt only one compaction per allocate call. */
109+
break;
110+
}
111+
}
112+
113+
}
114+
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
115+
78116
/* Empty list, return error. */
79117
return(LX_NO_BLOCKS);
80118
}

common/src/lx_nand_flash_block_data_move.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* SPDX-License-Identifier: MIT
1010
**************************************************************************/
1111

12+
// Some portions generated by Copilot (Sonnet 4.6).
1213

1314
/**************************************************************************/
1415
/**************************************************************************/
@@ -111,6 +112,33 @@ ULONG block_mapping_index;
111112
return(LX_ERROR);
112113
}
113114

115+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
116+
/* If this logical group has a pending compaction source, redirect the
117+
data move to a full logical-group compact to correctly merge data from
118+
both source blocks. */
119+
if (nand_flash -> lx_nand_flash_block_compaction_table[block_mapping_index] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
120+
{
121+
122+
/* Return the pre-allocated new_block to the free list. */
123+
status = _lx_nand_flash_block_status_set(nand_flash, new_block, LX_NAND_BLOCK_STATUS_FREE);
124+
125+
if (status)
126+
{
127+
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
128+
return(LX_ERROR);
129+
}
130+
131+
_lx_nand_flash_free_block_list_add(nand_flash, new_block);
132+
133+
/* Restore block_mapping_index to the mapped list; mapped_block_list_get
134+
already removed it before this function was called. */
135+
_lx_nand_flash_mapped_block_list_add(nand_flash, block_mapping_index);
136+
137+
/* Perform full compaction merge of both source blocks. */
138+
return(_lx_nand_flash_logical_group_compact(nand_flash, block_mapping_index));
139+
}
140+
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
141+
114142
/* Set new block status to allocated for now. */
115143
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
116144

common/src/lx_nand_flash_defragment.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* SPDX-License-Identifier: MIT
1010
**************************************************************************/
1111

12+
// Some portions generated by Copilot (Sonnet 4.6).
1213

1314
/**************************************************************************/
1415
/**************************************************************************/
@@ -72,10 +73,38 @@
7273
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash)
7374
{
7475

76+
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
77+
78+
UINT status;
79+
ULONG lg;
80+
81+
/* Compact every logical group that has a deferred compaction pending. */
82+
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
83+
{
84+
85+
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
86+
{
87+
88+
status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
89+
90+
/* On error, continue to compact remaining groups. */
91+
if (status)
92+
{
93+
_lx_nand_flash_system_error(nand_flash, status, lg, 0);
94+
}
95+
}
96+
}
97+
98+
return(LX_SUCCESS);
99+
100+
#else
101+
75102
LX_PARAMETER_NOT_USED(nand_flash);
76103

77104
/* Return not supported. */
78105
return(LX_NOT_SUPPORTED);
106+
107+
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
79108
}
80109

81110

0 commit comments

Comments
 (0)