mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-15 04:55:33 +08:00
Compare commits
36
Commits
v6.4.1_rel
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f1cfdc181 | ||
|
|
37dd169031 | ||
|
|
4005a425b7 | ||
|
|
123218cc51 | ||
|
|
b9f54b87bb | ||
|
|
2e061ba319 | ||
|
|
bfb39676df | ||
|
|
a46b74fb8a | ||
|
|
b80f28e0e6 | ||
|
|
f98a5c4eb8 | ||
|
|
b9ba4a97bf | ||
|
|
fa1a8e5ff4 | ||
|
|
89c745fcf5 | ||
|
|
4782f22568 | ||
|
|
58dc81e83c | ||
|
|
1751446fb0 | ||
|
|
c27eb52bd2 | ||
|
|
c03223909a | ||
|
|
9bf1c24243 | ||
|
|
6a534bed34 | ||
|
|
4585b92f15 | ||
|
|
63ed12cfd6 | ||
|
|
a1761869fd | ||
|
|
5783f64fe1 | ||
|
|
47b2a17d4b | ||
|
|
0f7dd521e5 | ||
|
|
b5dcbff38c | ||
|
|
7d1ef20acf | ||
|
|
04e385f3d5 | ||
|
|
7c5d83d794 | ||
|
|
24eb7d8692 | ||
|
|
058b242a9a | ||
|
|
a3c9691d89 | ||
|
|
f5a55077ad | ||
|
|
656d1490f4 | ||
|
|
8e1d00b591 |
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve Azure RTOS.
|
about: Create a report to help us improve Eclipse ThreadX.
|
||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
@@ -13,7 +13,7 @@ A clear and concise description of what the bug is.
|
|||||||
Please also mention any information which could help others to understand
|
Please also mention any information which could help others to understand
|
||||||
the problem you're facing:
|
the problem you're facing:
|
||||||
- What target device are you using?
|
- What target device are you using?
|
||||||
- Which version of Azure RTOS?
|
- Which version of Eclipse ThreadX?
|
||||||
- What toolchain and environment?
|
- What toolchain and environment?
|
||||||
- What have you tried to diagnose or workaround this issue?
|
- What have you tried to diagnose or workaround this issue?
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest an idea or enhancement to existing feature for Azure RTOS.
|
about: Suggest an idea or enhancement to existing feature for Eclipse ThreadX.
|
||||||
title: ''
|
title: ''
|
||||||
labels: feature
|
labels: feature
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ assignees: ''
|
|||||||
---
|
---
|
||||||
|
|
||||||
**Is this request related to a particular hardware platform, SoC, board? Please describe.**
|
**Is this request related to a particular hardware platform, SoC, board? Please describe.**
|
||||||
Describe in details the hardware support being requested and why this support benefits Azure RTOS.
|
Describe in details the hardware support being requested and why this support benefits Eclipse ThreadX.
|
||||||
|
|
||||||
**Describe why you are asking for this support?**
|
**Describe why you are asking for this support?**
|
||||||
Describe why you are asking for this support.
|
Describe why you are asking for this support.
|
||||||
|
|
||||||
If this is a new board or SoC, please state whether you are willing to maintain the Azure RTOS support together with you.
|
If this is a new board or SoC, please state whether you are willing to maintain the Eclipse ThreadX support together with you.
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
Add any other context or graphics (drag-and-drop an image) about the hardware here.
|
Add any other context or graphics (drag-and-drop an image) about the hardware here.
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
pages: write
|
pages: write
|
||||||
id-token: write
|
id-token: write
|
||||||
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
|
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
|
||||||
# Set up the project
|
# Set up the project
|
||||||
project(levelx
|
project(levelx
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ Instruction for building the LevelX as static library using Arm GNU Toolchain an
|
|||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
License terms for using Eclipse ThreadX are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information.
|
License terms for using Eclipse ThreadX are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information for all content, incl. the history of this repo.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
|
|||||||
+30
-11
@@ -1,20 +1,39 @@
|
|||||||
# Security Policy
|
# Security Policy
|
||||||
|
|
||||||
|
This Eclipse Foundation Project adheres to the [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/).
|
||||||
|
|
||||||
|
## How To Report a Vulnerability
|
||||||
|
|
||||||
|
If you think you have found a vulnerability in this repository, please report it to us through coordinated disclosure.
|
||||||
|
|
||||||
|
**Please do not report security vulnerabilities through public issues, discussions, or change requests.**
|
||||||
|
|
||||||
|
Instead, [report it privately here](https://github.com/eclipse-threadx/levelx/security/advisories/new) on GitHub
|
||||||
|
|
||||||
|
You can find more information about reporting and disclosure at the [Eclipse Foundation Security page](https://www.eclipse.org/security/).
|
||||||
|
|
||||||
|
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
|
||||||
|
|
||||||
|
* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
|
||||||
|
* Affected version(s)
|
||||||
|
* Impact of the issue, including how an attacker might exploit the issue
|
||||||
|
* Step-by-step instructions to reproduce the issue
|
||||||
|
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||||
|
* Full paths of source file(s) related to the manifestation of the issue
|
||||||
|
* Configuration required to reproduce the issue
|
||||||
|
* Log files that are related to this issue (if possible)
|
||||||
|
* Proof-of-concept or exploit code (if possible)
|
||||||
|
|
||||||
|
This information will help us triage your report more quickly.
|
||||||
|
|
||||||
## Supported Versions
|
## Supported Versions
|
||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ------- | ------------------ |
|
| ------- | ------------------ |
|
||||||
| 6.4.x | :white_check_mark: |
|
| 6.5.x | :white_check_mark: |
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
Eclipse ThreadX publishes a release every quarter. There are no long-term support branches or backports to older releases.
|
||||||
|
|
||||||
If you think you have found a vulnerability in <project> you can report it using one of the following ways:
|
Normally, fixes for non-critical vulnerabilities will ship in a regularly scheduled quarterly release. If fixes for an urgent or critical vulnerability must ship quickly, then the project will publish a hotfix release of the affected component(s) without waiting for the next quarterly release.
|
||||||
|
|
||||||
* Contact the [Eclipse Foundation Security Team](mailto:security@eclipse-foundation.org)
|
You can learn more about the [project's release cadence in this blog post](https://blogs.eclipse.org/post/fr%C3%A9d%C3%A9ric-desbiens/eclipse-threadx-more-predictable-more-open).
|
||||||
* [Report a Vulnerability](https://github.com/eclipse-threadx/levelx/security/advisories/new)
|
|
||||||
|
|
||||||
You can find more information about reporting and disclosure at the [Eclipse Foundation Security page](https://www.eclipse.org/security/).
|
|
||||||
|
|
||||||
## Security Policy
|
|
||||||
|
|
||||||
This project follows [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/).
|
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_erase_count_set.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_extended_cache_enable.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_format_extended.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_free_block_list_add.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_initialize.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_logical_group_compact.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_get.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_remove.c
|
||||||
@@ -30,6 +32,7 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_build.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_metadata_write.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_open_extended.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_check.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_page_ecc_compute.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_partial_defragment.c
|
||||||
@@ -52,6 +55,8 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_logical_sector_find.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_next_block_to_erase_find.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_open_extended.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_format.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_partial_defragment.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_physical_sector_allocate.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nor_flash_sector_mapping_cache_invalidate.c
|
||||||
|
|||||||
+46
-59
@@ -1,5 +1,7 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
* Portion Copyright (c) 2025 STMicroelectronics
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -36,62 +38,6 @@
|
|||||||
/* high-performance LevelX. All service prototypes and data structure */
|
/* high-performance LevelX. All service prototypes and data structure */
|
||||||
/* definitions are defined in this file. */
|
/* definitions are defined in this file. */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), and */
|
|
||||||
/* updated product constants, */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 11-09-2020 William E. Lamie Modified comment(s), and */
|
|
||||||
/* added support for lx_user.h */
|
|
||||||
/* so user can specify values, */
|
|
||||||
/* resulting in version 6.1.2 */
|
|
||||||
/* 12-31-2020 William E. Lamie Modified comment(s), and */
|
|
||||||
/* updated product constants, */
|
|
||||||
/* resulting in version 6.1.3 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* added standalone support, */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 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 */
|
|
||||||
/* 01-31-2022 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* updated include order for */
|
|
||||||
/* standalone mode, */
|
|
||||||
/* resulting in version 6.1.10 */
|
|
||||||
/* 04-25-2022 William E. Lamie Modified comment(s), and */
|
|
||||||
/* updated product constants, */
|
|
||||||
/* resulting in version 6.1.11 */
|
|
||||||
/* 07-29-2022 William E. Lamie Modified comment(s), and */
|
|
||||||
/* updated product constants, */
|
|
||||||
/* resulting in version 6.1.12 */
|
|
||||||
/* 10-31-2022 Xiuwen Cai Modified comment(s), and */
|
|
||||||
/* updated product constants, */
|
|
||||||
/* resulting in version 6.2.0 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* modified NAND logic, */
|
|
||||||
/* added new driver interface */
|
|
||||||
/* and user extension, */
|
|
||||||
/* 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 */
|
|
||||||
/* 12-31-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added configuration checks, */
|
|
||||||
/* resulting in version 6.4.0 */
|
|
||||||
/* 03-01-2024 Tiejun Zhou Modified comment(s), */
|
|
||||||
/* update version number, */
|
|
||||||
/* resulting in version 6.4.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifndef LX_API_H
|
#ifndef LX_API_H
|
||||||
@@ -202,8 +148,10 @@ typedef unsigned long long ULONG64;
|
|||||||
/* Define basic constants for the LevelX Stack. */
|
/* Define basic constants for the LevelX Stack. */
|
||||||
#define AZURE_RTOS_LEVELX
|
#define AZURE_RTOS_LEVELX
|
||||||
#define LEVELX_MAJOR_VERSION 6
|
#define LEVELX_MAJOR_VERSION 6
|
||||||
#define LEVELX_MINOR_VERSION 4
|
#define LEVELX_MINOR_VERSION 5
|
||||||
#define LEVELX_PATCH_VERSION 1
|
#define LEVELX_PATCH_VERSION 1
|
||||||
|
#define LEVELX_BUILD_VERSION 202602
|
||||||
|
#define LEVELX_HOTFIX_VERSION ' '
|
||||||
|
|
||||||
|
|
||||||
/* Define general LevelX Constants. */
|
/* Define general LevelX Constants. */
|
||||||
@@ -326,6 +274,17 @@ typedef unsigned long long ULONG64;
|
|||||||
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
|
#define LX_NAND_FLASH_MAX_METADATA_BLOCKS 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* When LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE is defined, sector releases from full blocks
|
||||||
|
are deferred when free block count exceeds the threshold below (opt-in, default: off).
|
||||||
|
Requires pages_per_block <= 4095 (bit 12 is reserved for COMPACTION_PENDING flag). */
|
||||||
|
/* #define LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
#ifndef LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD
|
||||||
|
#define LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD 10u
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LX_UTILITY_SHORT_SET
|
#ifndef LX_UTILITY_SHORT_SET
|
||||||
#define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value)
|
#define LX_UTILITY_SHORT_SET(address, value) *((USHORT*)(address)) = (USHORT)(value)
|
||||||
#endif
|
#endif
|
||||||
@@ -380,6 +339,11 @@ typedef unsigned long long ULONG64;
|
|||||||
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
|
#define LX_NAND_BLOCK_STATUS_FULL 0x4000u
|
||||||
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
|
#define LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL 0x2000u
|
||||||
#define LX_NAND_BLOCK_STATUS_MAPPING_PRESENT 0x1000u
|
#define LX_NAND_BLOCK_STATUS_MAPPING_PRESENT 0x1000u
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Repurpose the otherwise-unused MAPPING_PRESENT bit to signal a block whose compaction
|
||||||
|
has been deferred. Only valid when pages_per_block <= 4095. */
|
||||||
|
#define LX_NAND_BLOCK_STATUS_COMPACTION_PENDING LX_NAND_BLOCK_STATUS_MAPPING_PRESENT
|
||||||
|
#endif
|
||||||
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
|
#define LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK 0x0FFFu
|
||||||
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
|
#define LX_NAND_BLOCK_STATUS_FREE 0xFFFFu
|
||||||
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
|
#define LX_NAND_BLOCK_STATUS_BAD 0xFF00u
|
||||||
@@ -454,6 +418,12 @@ typedef struct LX_NAND_FLASH_STRUCT
|
|||||||
USHORT *lx_nand_flash_block_list;
|
USHORT *lx_nand_flash_block_list;
|
||||||
ULONG lx_nand_flash_block_list_size;
|
ULONG lx_nand_flash_block_list_size;
|
||||||
ULONG lx_nand_flash_free_block_list_tail;
|
ULONG lx_nand_flash_free_block_list_tail;
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Parallel to block_mapping_table: physical block with pending compaction for a group,
|
||||||
|
or LX_NAND_BLOCK_UNMAPPED when no compaction is pending. */
|
||||||
|
USHORT *lx_nand_flash_block_compaction_table;
|
||||||
|
ULONG lx_nand_flash_block_compaction_table_size;
|
||||||
|
#endif
|
||||||
ULONG lx_nand_flash_mapped_block_list_head;
|
ULONG lx_nand_flash_mapped_block_list_head;
|
||||||
|
|
||||||
ULONG lx_nand_flash_metadata_block_number;
|
ULONG lx_nand_flash_metadata_block_number;
|
||||||
@@ -528,7 +498,6 @@ typedef struct LX_NAND_FLASH_STRUCT
|
|||||||
#endif
|
#endif
|
||||||
UCHAR *lx_nand_flash_page_buffer;
|
UCHAR *lx_nand_flash_page_buffer;
|
||||||
UINT lx_nand_flash_page_buffer_size;
|
UINT lx_nand_flash_page_buffer_size;
|
||||||
|
|
||||||
#ifdef LX_THREAD_SAFE_ENABLE
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
/* When this conditional is used, the LevelX code utilizes a ThreadX mutex for thread
|
/* When this conditional is used, the LevelX code utilizes a ThreadX mutex for thread
|
||||||
@@ -537,6 +506,8 @@ typedef struct LX_NAND_FLASH_STRUCT
|
|||||||
TX_MUTEX lx_nand_flash_mutex;
|
TX_MUTEX lx_nand_flash_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* user data pointer optionally passed by the application to the driver via the lx_nand_flash_open_extended */
|
||||||
|
VOID *lx_nand_flash_driver_info_ptr;
|
||||||
/* Define the NAND flash control block open next/previous pointers. */
|
/* Define the NAND flash control block open next/previous pointers. */
|
||||||
struct LX_NAND_FLASH_STRUCT *lx_nand_flash_open_next,
|
struct LX_NAND_FLASH_STRUCT *lx_nand_flash_open_next,
|
||||||
*lx_nand_flash_open_previous;
|
*lx_nand_flash_open_previous;
|
||||||
@@ -666,7 +637,8 @@ typedef struct LX_NOR_FLASH_STRUCT
|
|||||||
a higher layer. */
|
a higher layer. */
|
||||||
TX_MUTEX lx_nor_flash_mutex;
|
TX_MUTEX lx_nor_flash_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
/* user data pointer optionally passed by the application to the driver via the lx_nor_flash_open_extended */
|
||||||
|
VOID *lx_nor_flash_driver_info_ptr;
|
||||||
/* Define the NOR flash control block open next/previous pointers. */
|
/* Define the NOR flash control block open next/previous pointers. */
|
||||||
struct LX_NOR_FLASH_STRUCT *lx_nor_flash_open_next,
|
struct LX_NOR_FLASH_STRUCT *lx_nor_flash_open_next,
|
||||||
*lx_nor_flash_open_previous;
|
*lx_nor_flash_open_previous;
|
||||||
@@ -725,8 +697,10 @@ extern ULONG _lx_nor_flash_opened_cou
|
|||||||
#define lx_nand_flash_partial_defragment _lx_nand_flash_partial_defragment
|
#define lx_nand_flash_partial_defragment _lx_nand_flash_partial_defragment
|
||||||
#define lx_nand_flash_extended_cache_enable _lx_nand_flash_extended_cache_enable
|
#define lx_nand_flash_extended_cache_enable _lx_nand_flash_extended_cache_enable
|
||||||
#define lx_nand_flash_format _lx_nand_flash_format
|
#define lx_nand_flash_format _lx_nand_flash_format
|
||||||
|
#define lx_nand_flash_format_extended _lx_nand_flash_format_extended
|
||||||
#define lx_nand_flash_initialize _lx_nand_flash_initialize
|
#define lx_nand_flash_initialize _lx_nand_flash_initialize
|
||||||
#define lx_nand_flash_open _lx_nand_flash_open
|
#define lx_nand_flash_open _lx_nand_flash_open
|
||||||
|
#define lx_nand_flash_open_extended _lx_nand_flash_open_extended
|
||||||
#define lx_nand_flash_page_ecc_check _lx_nand_flash_page_ecc_check
|
#define lx_nand_flash_page_ecc_check _lx_nand_flash_page_ecc_check
|
||||||
#define lx_nand_flash_page_ecc_compute _lx_nand_flash_page_ecc_compute
|
#define lx_nand_flash_page_ecc_compute _lx_nand_flash_page_ecc_compute
|
||||||
#define lx_nand_flash_sector_read _lx_nand_flash_sector_read
|
#define lx_nand_flash_sector_read _lx_nand_flash_sector_read
|
||||||
@@ -743,7 +717,9 @@ extern ULONG _lx_nor_flash_opened_cou
|
|||||||
#define lx_nor_flash_partial_defragment _lx_nor_flash_partial_defragment
|
#define lx_nor_flash_partial_defragment _lx_nor_flash_partial_defragment
|
||||||
#define lx_nor_flash_extended_cache_enable _lx_nor_flash_extended_cache_enable
|
#define lx_nor_flash_extended_cache_enable _lx_nor_flash_extended_cache_enable
|
||||||
#define lx_nor_flash_initialize _lx_nor_flash_initialize
|
#define lx_nor_flash_initialize _lx_nor_flash_initialize
|
||||||
|
#define lx_nor_flash_format _lx_nor_flash_format
|
||||||
#define lx_nor_flash_open _lx_nor_flash_open
|
#define lx_nor_flash_open _lx_nor_flash_open
|
||||||
|
#define lx_nor_flash_open_extended _lx_nor_flash_open_extended
|
||||||
#define lx_nor_flash_sector_read _lx_nor_flash_sector_read
|
#define lx_nor_flash_sector_read _lx_nor_flash_sector_read
|
||||||
#define lx_nor_flash_sector_release _lx_nor_flash_sector_release
|
#define lx_nor_flash_sector_release _lx_nor_flash_sector_release
|
||||||
#define lx_nor_flash_sector_write _lx_nor_flash_sector_write
|
#define lx_nor_flash_sector_write _lx_nor_flash_sector_write
|
||||||
@@ -759,7 +735,13 @@ UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *m
|
|||||||
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
|
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||||
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
||||||
ULONG* memory_ptr, UINT memory_size);
|
ULONG* memory_ptr, UINT memory_size);
|
||||||
|
UINT _lx_nand_flash_format_extended(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||||
|
UINT(*nand_driver_initialize)(LX_NAND_FLASH*), VOID *nand_driver_info_ptr,
|
||||||
|
ULONG* memory_ptr, UINT memory_size);
|
||||||
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *), ULONG* memory_ptr, UINT memory_size);
|
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *), ULONG* memory_ptr, UINT memory_size);
|
||||||
|
UINT _lx_nand_flash_open_extended(LX_NAND_FLASH *nand_flash, CHAR *name,
|
||||||
|
UINT (*nand_driver_initialize)(LX_NAND_FLASH *), VOID *nand_driver_info_ptr,
|
||||||
|
ULONG* memory_ptr, UINT memory_size);
|
||||||
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer);
|
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer);
|
||||||
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer);
|
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer);
|
||||||
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks);
|
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks);
|
||||||
@@ -774,7 +756,9 @@ UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash);
|
|||||||
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash);
|
||||||
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size);
|
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size);
|
||||||
UINT _lx_nor_flash_initialize(void);
|
UINT _lx_nor_flash_initialize(void);
|
||||||
|
UINT _lx_nor_flash_format(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr);
|
||||||
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *));
|
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *));
|
||||||
|
UINT _lx_nor_flash_open_extended(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr);
|
||||||
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks);
|
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks);
|
||||||
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer);
|
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer);
|
||||||
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector);
|
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector);
|
||||||
@@ -809,6 +793,9 @@ UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buf
|
|||||||
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page);
|
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page);
|
||||||
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer);
|
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer);
|
||||||
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer);
|
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer);
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
UINT _lx_nand_flash_logical_group_compact(LX_NAND_FLASH *nand_flash, ULONG logical_group);
|
||||||
|
#endif
|
||||||
|
|
||||||
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash);
|
||||||
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);
|
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -39,23 +40,6 @@
|
|||||||
/* Note that all the defines in this file may also be made on the */
|
/* Note that all the defines in this file may also be made on the */
|
||||||
/* command line when building LevelX library and application objects. */
|
/* command line when building LevelX library and application objects. */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 11-09-2020 William E. Lamie Initial Version 6.1.2 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), and */
|
|
||||||
/* added standalone support, */
|
|
||||||
/* 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 */
|
|
||||||
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added options for mapping , */
|
|
||||||
/* bitmap cache and obsolete */
|
|
||||||
/* count cache, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifndef LX_USER_H
|
#ifndef LX_USER_H
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -116,19 +117,6 @@ VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr);
|
|||||||
/* */
|
/* */
|
||||||
/* FileX System Functions */
|
/* FileX System Functions */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* changed to use new API, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr)
|
VOID _fx_nand_flash_simulator_driver(FX_MEDIA *media_ptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -109,16 +110,6 @@ VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr);
|
|||||||
/* */
|
/* */
|
||||||
/* FileX System Functions */
|
/* FileX System Functions */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr)
|
VOID _fx_nor_flash_simulator_driver(FX_MEDIA *media_ptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,16 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* _lx_nand_flash_page_ecc_check NAND page check */
|
/* _lx_nand_flash_page_ecc_check NAND page check */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
UINT _lx_nand_flash_256byte_ecc_check(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
|
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
|
||||||
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
|
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* inverted output, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -65,12 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
|
UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
|
||||||
{
|
{
|
||||||
@@ -80,6 +76,43 @@ UINT _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
|
|||||||
if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
|
if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG lg;
|
||||||
|
UINT compact_status;
|
||||||
|
|
||||||
|
/* Emergency compaction: find any pending compaction and execute it to
|
||||||
|
reclaim the old full block. */
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
compact_status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
|
||||||
|
|
||||||
|
if (compact_status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Retry the allocation after compaction freed a block. */
|
||||||
|
if (nand_flash -> lx_nand_flash_free_block_list_tail > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
nand_flash -> lx_nand_flash_free_block_list_tail--;
|
||||||
|
*block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail];
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Attempt only one compaction per allocate call. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Empty list, return error. */
|
/* Empty list, return error. */
|
||||||
return(LX_NO_BLOCKS);
|
return(LX_NO_BLOCKS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -78,12 +80,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_block_data_move(LX_NAND_FLASH *nand_flash, ULONG new_block)
|
UINT _lx_nand_flash_block_data_move(LX_NAND_FLASH *nand_flash, ULONG new_block)
|
||||||
{
|
{
|
||||||
@@ -116,6 +112,33 @@ ULONG block_mapping_index;
|
|||||||
return(LX_ERROR);
|
return(LX_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* If this logical group has a pending compaction source, redirect the
|
||||||
|
data move to a full logical-group compact to correctly merge data from
|
||||||
|
both source blocks. */
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[block_mapping_index] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return the pre-allocated new_block to the free list. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, new_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, new_block);
|
||||||
|
|
||||||
|
/* Restore block_mapping_index to the mapped list; mapped_block_list_get
|
||||||
|
already removed it before this function was called. */
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash, block_mapping_index);
|
||||||
|
|
||||||
|
/* Perform full compaction merge of both source blocks. */
|
||||||
|
return(_lx_nand_flash_logical_group_compact(nand_flash, block_mapping_index));
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Set new block status to allocated for now. */
|
/* Set new block status to allocated for now. */
|
||||||
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
new_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -72,12 +73,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
|
UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
|
||||||
{
|
{
|
||||||
@@ -90,7 +85,7 @@ UINT _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector,
|
|||||||
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
/* Check the address range. */
|
/* Check the address range. */
|
||||||
if (block_mapping_index > nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table))
|
if (block_mapping_index >= nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Out of range, return an error. */
|
/* Out of range, return an error. */
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,12 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block)
|
UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,12 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status)
|
UINT _lx_nand_flash_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, ULONG block_status)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -64,16 +65,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash)
|
UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -73,16 +74,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* 12-31-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* fixed sequential checking */
|
|
||||||
/* logic, */
|
|
||||||
/* resulting in version 6.4.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status,
|
UINT _lx_nand_flash_data_page_copy(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG source_block, USHORT src_block_status,
|
||||||
ULONG destination_block, USHORT* dest_block_status_ptr, ULONG sectors)
|
ULONG destination_block, USHORT* dest_block_status_ptr, ULONG sectors)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -67,27 +69,42 @@
|
|||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* deprecated this API, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash)
|
UINT _lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
|
||||||
|
UINT status;
|
||||||
|
ULONG lg;
|
||||||
|
|
||||||
|
/* Compact every logical group that has a deferred compaction pending. */
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[lg] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
status = _lx_nand_flash_logical_group_compact(nand_flash, lg);
|
||||||
|
|
||||||
|
/* On error, continue to compact remaining groups. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, lg, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
LX_PARAMETER_NOT_USED(nand_flash);
|
LX_PARAMETER_NOT_USED(nand_flash);
|
||||||
|
|
||||||
/* Return not supported. */
|
/* Return not supported. */
|
||||||
return(LX_NOT_SUPPORTED);
|
return(LX_NOT_SUPPORTED);
|
||||||
|
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,20 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* removed cache support, */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
|
UINT _lx_nand_flash_driver_block_erase(LX_NAND_FLASH *nand_flash, ULONG block, ULONG erase_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block)
|
UINT _lx_nand_flash_driver_block_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -68,20 +69,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* removed cache support, */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag)
|
UINT _lx_nand_flash_driver_block_status_get(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR *bad_block_flag)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -68,20 +69,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* removed cache support, */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag)
|
UINT _lx_nand_flash_driver_block_status_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR bad_block_flag)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page)
|
UINT _lx_nand_flash_driver_page_erased_verify(LX_NAND_FLASH *nand_flash, ULONG block, ULONG page)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,12 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count)
|
UINT _lx_nand_flash_erase_count_set(LX_NAND_FLASH *nand_flash, ULONG block, UCHAR erase_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -69,19 +70,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* deprecated this API, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size)
|
UINT _lx_nand_flash_extended_cache_enable(LX_NAND_FLASH *nand_flash, VOID *memory, ULONG size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
* Copyright (c) 2025 STMicroelectronics
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -39,7 +41,7 @@
|
|||||||
/* FUNCTION RELEASE */
|
/* FUNCTION RELEASE */
|
||||||
/* */
|
/* */
|
||||||
/* _lx_nand_flash_format PORTABLE C */
|
/* _lx_nand_flash_format PORTABLE C */
|
||||||
/* 6.3.0 */
|
/* */
|
||||||
/* AUTHOR */
|
/* AUTHOR */
|
||||||
/* */
|
/* */
|
||||||
/* Xiuwen Cai, Microsoft Corporation */
|
/* Xiuwen Cai, Microsoft Corporation */
|
||||||
@@ -64,224 +66,21 @@
|
|||||||
/* return status */
|
/* return status */
|
||||||
/* */
|
/* */
|
||||||
/* CALLS */
|
/* CALLS */
|
||||||
/* */
|
/* _lx_nand_flash_format_extended */
|
||||||
/* (nand_driver_initialize) Driver initialize */
|
|
||||||
/* LX_MEMSET Initialize memory */
|
|
||||||
/* _lx_nand_flash_memory_initialize Initialize buffer */
|
|
||||||
/* _lx_nand_flash_driver_block_status_get */
|
|
||||||
/* Driver block status get */
|
|
||||||
/* _lx_nand_flash_driver_block_status_set */
|
|
||||||
/* Driver block status set */
|
|
||||||
/* _lx_nand_flash_metadata_build Build metadata */
|
|
||||||
/* _lx_nand_flash_metadata_write Write metadata */
|
|
||||||
/* _lx_nand_flash_driver_block_erase Driver block erase */
|
|
||||||
/* _lx_nand_flash_system_error System error handler */
|
|
||||||
/* tx_mutex_create Create thread-safe mutex */
|
|
||||||
/* */
|
/* */
|
||||||
/* CALLED BY */
|
/* CALLED BY */
|
||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 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,
|
UINT _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||||
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
|
||||||
ULONG* memory_ptr, UINT memory_size)
|
ULONG* memory_ptr, UINT memory_size)
|
||||||
{
|
{
|
||||||
|
|
||||||
ULONG block;
|
|
||||||
UCHAR block_status;
|
|
||||||
UINT status;
|
UINT status;
|
||||||
UCHAR *page_buffer_ptr;
|
|
||||||
|
|
||||||
LX_PARAMETER_NOT_USED(name);
|
status = _lx_nand_flash_format_extended(nand_flash, name, nand_driver_initialize, NULL, memory_ptr, memory_size);
|
||||||
|
|
||||||
/* Clear the NAND flash control block. User extension is not cleared. */
|
return status;
|
||||||
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);
|
|
||||||
|
|
||||||
/* Determine if we can support this NAND flash size. */
|
|
||||||
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
|
|
||||||
{
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if it is new LevelX NAND driver. */
|
|
||||||
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
|
|
||||||
{
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the spare data length. */
|
|
||||||
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
|
|
||||||
{
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate the number of words per block and per page. */
|
|
||||||
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
|
|
||||||
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
|
|
||||||
|
|
||||||
/* Calculate the total pages. */
|
|
||||||
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
|
|
||||||
|
|
||||||
/* Initialize memory buffer. */
|
|
||||||
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
return(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize block numbers. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
|
|
||||||
/* Initialize the block status buffer. */
|
|
||||||
LX_MEMSET(nand_flash -> lx_nand_flash_block_status_table, 0xFF, nand_flash -> lx_nand_flash_block_status_table_size);
|
|
||||||
|
|
||||||
/* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */
|
|
||||||
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* First, check to make sure this block is good. */
|
|
||||||
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this block bad? */
|
|
||||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, this block is bad. */
|
|
||||||
|
|
||||||
/* Increment the number of bad blocks. */
|
|
||||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
|
||||||
|
|
||||||
/* Save the block status. */
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
|
||||||
|
|
||||||
/* Continue to the next block. */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Erase the block. */
|
|
||||||
status = _lx_nand_flash_driver_block_erase(nand_flash, block, 0);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
|
|
||||||
/* Attempt to mark this block as bad. */
|
|
||||||
status = _lx_nand_flash_driver_block_status_set(nand_flash, block, LX_NAND_BAD_BLOCK);
|
|
||||||
|
|
||||||
/* Check for error in setting the block status. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the bad block count. */
|
|
||||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
|
||||||
|
|
||||||
/* Save the block status. */
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Allocate blocks for metadata. */
|
|
||||||
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number = block;
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_current = block;
|
|
||||||
}
|
|
||||||
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number = block;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = block;
|
|
||||||
}
|
|
||||||
else if (nand_flash -> lx_nand_flash_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_next = block;
|
|
||||||
}
|
|
||||||
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* There should be enough blocks for metadata. */
|
|
||||||
if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
return (LX_NO_BLOCKS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save the block status for metadata. */
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next;
|
|
||||||
|
|
||||||
/* Initialize the mapping table. */
|
|
||||||
LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size);
|
|
||||||
|
|
||||||
/* Build initial metadata. */
|
|
||||||
status = _lx_nand_flash_metadata_build(nand_flash);
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
/* Return error status. */
|
|
||||||
return(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get buffer for page data. */
|
|
||||||
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
|
||||||
|
|
||||||
/* Initialize the page buffer. */
|
|
||||||
LX_MEMSET(page_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page);
|
|
||||||
|
|
||||||
/* Set the next block numbers. */
|
|
||||||
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET], nand_flash -> lx_nand_flash_metadata_block_number_next);
|
|
||||||
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET], nand_flash -> lx_nand_flash_backup_metadata_block_number_next);
|
|
||||||
|
|
||||||
/* Save the next block numbers to metadata block. */
|
|
||||||
status = _lx_nand_flash_metadata_write(nand_flash, page_buffer_ptr, LX_NAND_PAGE_TYPE_BLOCK_LINK);
|
|
||||||
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
/* Return error status. */
|
|
||||||
return(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return a successful completion. */
|
|
||||||
return(LX_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,280 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
* Copyright (c) 2025 STMicroelectronics
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the MIT License which is available at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** LevelX Component */
|
||||||
|
/** */
|
||||||
|
/** NAND Flash */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#define LX_SOURCE_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Disable ThreadX error checking. */
|
||||||
|
|
||||||
|
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||||
|
#define LX_DISABLE_ERROR_CHECKING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Include necessary system files. */
|
||||||
|
|
||||||
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_format_extended PORTABLE C */
|
||||||
|
/* */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Xiuwen Cai, Microsoft Corporation */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function erases and formats a NAND flash. */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* name Name of NAND flash instance */
|
||||||
|
/* nand_driver_initialize Driver initialize */
|
||||||
|
/* nand_driver_info_ptr Driver user data pointer */
|
||||||
|
/* memory_ptr Pointer to memory used by the */
|
||||||
|
/* LevelX for this NAND. */
|
||||||
|
/* memory_size Size of memory - must at least*/
|
||||||
|
/* 7 * total block count + */
|
||||||
|
/* 2 * page size */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* return status */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* (nand_driver_initialize) Driver initialize */
|
||||||
|
/* LX_MEMSET Initialize memory */
|
||||||
|
/* _lx_nand_flash_memory_initialize Initialize buffer */
|
||||||
|
/* _lx_nand_flash_driver_block_status_get */
|
||||||
|
/* Driver block status get */
|
||||||
|
/* _lx_nand_flash_driver_block_status_set */
|
||||||
|
/* Driver block status set */
|
||||||
|
/* _lx_nand_flash_metadata_build Build metadata */
|
||||||
|
/* _lx_nand_flash_metadata_write Write metadata */
|
||||||
|
/* _lx_nand_flash_driver_block_erase Driver block erase */
|
||||||
|
/* _lx_nand_flash_system_error System error handler */
|
||||||
|
/* tx_mutex_create Create thread-safe mutex */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* Application Code */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
UINT _lx_nand_flash_format_extended(LX_NAND_FLASH* nand_flash, CHAR* name,
|
||||||
|
UINT(*nand_driver_initialize)(LX_NAND_FLASH*),VOID* nand_driver_info_ptr,
|
||||||
|
ULONG* memory_ptr, UINT memory_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG block;
|
||||||
|
UCHAR block_status;
|
||||||
|
UINT status;
|
||||||
|
UCHAR *page_buffer_ptr;
|
||||||
|
|
||||||
|
LX_PARAMETER_NOT_USED(name);
|
||||||
|
|
||||||
|
/* 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));
|
||||||
|
|
||||||
|
nand_flash -> lx_nand_flash_driver_info_ptr = nand_driver_info_ptr;
|
||||||
|
/* Call the flash driver's initialization function. */
|
||||||
|
(nand_driver_initialize)(nand_flash);
|
||||||
|
|
||||||
|
/* Determine if we can support this NAND flash size. */
|
||||||
|
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if it is new LevelX NAND driver. */
|
||||||
|
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the spare data length. */
|
||||||
|
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the number of words per block and per page. */
|
||||||
|
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
|
||||||
|
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
/* Calculate the total pages. */
|
||||||
|
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
/* Initialize memory buffer. */
|
||||||
|
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize block numbers. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
|
||||||
|
/* Initialize the block status buffer. */
|
||||||
|
LX_MEMSET(nand_flash -> lx_nand_flash_block_status_table, 0xFF, nand_flash -> lx_nand_flash_block_status_table_size);
|
||||||
|
|
||||||
|
/* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */
|
||||||
|
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* First, check to make sure this block is good. */
|
||||||
|
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this block bad? */
|
||||||
|
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, this block is bad. */
|
||||||
|
|
||||||
|
/* Increment the number of bad blocks. */
|
||||||
|
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||||
|
|
||||||
|
/* Save the block status. */
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
||||||
|
|
||||||
|
/* Continue to the next block. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Erase the block. */
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, block, 0);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
|
||||||
|
/* Attempt to mark this block as bad. */
|
||||||
|
status = _lx_nand_flash_driver_block_status_set(nand_flash, block, LX_NAND_BAD_BLOCK);
|
||||||
|
|
||||||
|
/* Check for error in setting the block status. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the bad block count. */
|
||||||
|
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||||
|
|
||||||
|
/* Save the block status. */
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Allocate blocks for metadata. */
|
||||||
|
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number = block;
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_current = block;
|
||||||
|
}
|
||||||
|
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number = block;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = block;
|
||||||
|
}
|
||||||
|
else if (nand_flash -> lx_nand_flash_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_next = block;
|
||||||
|
}
|
||||||
|
else if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There should be enough blocks for metadata. */
|
||||||
|
if (nand_flash -> lx_nand_flash_backup_metadata_block_number_next == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
return (LX_NO_BLOCKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the block status for metadata. */
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number_next] = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_backup_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[nand_flash -> lx_nand_flash_metadata_block_number] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number_next;
|
||||||
|
|
||||||
|
/* Initialize the mapping table. */
|
||||||
|
LX_MEMSET(nand_flash -> lx_nand_flash_block_mapping_table, 0xFF, nand_flash -> lx_nand_flash_block_mapping_table_size);
|
||||||
|
|
||||||
|
/* Build initial metadata. */
|
||||||
|
status = _lx_nand_flash_metadata_build(nand_flash);
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Return error status. */
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get buffer for page data. */
|
||||||
|
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
|
||||||
|
/* Initialize the page buffer. */
|
||||||
|
LX_MEMSET(page_buffer_ptr, 0xFF, nand_flash -> lx_nand_flash_bytes_per_page);
|
||||||
|
|
||||||
|
/* Set the next block numbers. */
|
||||||
|
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET], nand_flash -> lx_nand_flash_metadata_block_number_next);
|
||||||
|
LX_UTILITY_LONG_SET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET], nand_flash -> lx_nand_flash_backup_metadata_block_number_next);
|
||||||
|
|
||||||
|
/* Save the next block numbers to metadata block. */
|
||||||
|
status = _lx_nand_flash_metadata_write(nand_flash, page_buffer_ptr, LX_NAND_PAGE_TYPE_BLOCK_LINK);
|
||||||
|
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Return error status. */
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return a successful completion. */
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -65,12 +66,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block)
|
UINT _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -63,14 +64,6 @@ ULONG _lx_nand_flash_opened_count;
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_initialize(void)
|
UINT _lx_nand_flash_initialize(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,447 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the MIT License which is available at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** LevelX Component */
|
||||||
|
/** */
|
||||||
|
/** NAND Flash */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#define LX_SOURCE_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Disable ThreadX error checking. */
|
||||||
|
|
||||||
|
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||||
|
#define LX_DISABLE_ERROR_CHECKING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Include necessary system files. */
|
||||||
|
|
||||||
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_sector_find_in_block PORTABLE C */
|
||||||
|
/* 6.5.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This helper scans a block for a specific logical sector and returns */
|
||||||
|
/* the page number and kind (data / released / not found). */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* block Physical block number */
|
||||||
|
/* block_status Block status word */
|
||||||
|
/* logical_sector Logical sector to search for */
|
||||||
|
/* found_page Destination: page index found */
|
||||||
|
/* sector_kind Destination: kind (see below) */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* LX_SUCCESS Sector found; outputs set */
|
||||||
|
/* LX_NO_BLOCKS Sector not present in block */
|
||||||
|
/* LX_ERROR Driver error */
|
||||||
|
/* */
|
||||||
|
/* SECTOR KIND VALUES (written to *sector_kind) */
|
||||||
|
/* */
|
||||||
|
/* LX_NAND_PAGE_TYPE_USER_DATA Sector contains live data */
|
||||||
|
/* LX_NAND_PAGE_TYPE_USER_DATA_RELEASED Sector is tombstoned */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
static UINT _lx_nand_sector_find_in_block(LX_NAND_FLASH *nand_flash,
|
||||||
|
ULONG block,
|
||||||
|
USHORT block_status,
|
||||||
|
ULONG logical_sector,
|
||||||
|
LONG *found_page,
|
||||||
|
ULONG *sector_kind)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG available_pages;
|
||||||
|
LONG page;
|
||||||
|
ULONG spare_data1;
|
||||||
|
UINT status;
|
||||||
|
UCHAR *spare_buffer_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* Use page buffer as scratch for spare-only reads (per existing LevelX convention). */
|
||||||
|
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
|
||||||
|
/* Determine page count. */
|
||||||
|
available_pages = (block_status & LX_NAND_BLOCK_STATUS_FULL) ?
|
||||||
|
nand_flash -> lx_nand_flash_pages_per_block :
|
||||||
|
(block_status & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK);
|
||||||
|
|
||||||
|
if (block_status & LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scan newest-to-oldest so the first match is the authoritative version. */
|
||||||
|
for (page = (LONG)available_pages - 1; page >= 0; page--)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, LX_NULL, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, LX_NULL, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
spare_data1 = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||||
|
|
||||||
|
if ((spare_data1 & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Sector found; return its page index and kind. */
|
||||||
|
*found_page = page;
|
||||||
|
*sector_kind = spare_data1 & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK);
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Sequential block: page index == sector offset within group. */
|
||||||
|
page = (LONG)(logical_sector % nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
if ((ULONG)page < available_pages)
|
||||||
|
{
|
||||||
|
*found_page = page;
|
||||||
|
*sector_kind = LX_NAND_PAGE_TYPE_USER_DATA;
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*found_page = -1L;
|
||||||
|
return(LX_NO_BLOCKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_logical_group_compact PORTABLE C */
|
||||||
|
/* 6.5.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function completes a deferred full-block compaction created by */
|
||||||
|
/* the lazy sector-release path. It merges the tombstone block */
|
||||||
|
/* (current mapping) and the compaction-pending old block into a fresh */
|
||||||
|
/* destination block, then erases both source blocks. */
|
||||||
|
/* */
|
||||||
|
/* The tombstone block takes priority: if a sector appears in both */
|
||||||
|
/* blocks the tombstone block's version is used (newer). */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* logical_group Logical group index */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* LX_SUCCESS Compaction completed */
|
||||||
|
/* LX_ERROR / LX_NO_BLOCKS Error during compaction */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_sector_find_in_block Find sector in a block */
|
||||||
|
/* _lx_nand_flash_block_allocate Allocate a free block */
|
||||||
|
/* _lx_nand_flash_block_status_set Set block status */
|
||||||
|
/* _lx_nand_flash_block_mapping_set Update logical-to-physical map*/
|
||||||
|
/* _lx_nand_flash_mapped_block_list_remove Remove from mapped list */
|
||||||
|
/* _lx_nand_flash_mapped_block_list_add Add to mapped list */
|
||||||
|
/* _lx_nand_flash_free_block_list_add Return block to free list */
|
||||||
|
/* _lx_nand_flash_driver_block_erase Erase a block */
|
||||||
|
/* _lx_nand_flash_erase_count_set Record new erase count */
|
||||||
|
/* _lx_nand_flash_block_data_move Wear-level an over-erased blk */
|
||||||
|
/* _lx_nand_flash_system_error Internal system error handler */
|
||||||
|
/* lx_nand_flash_driver_pages_copy Copy a page between blocks */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_sector_release Lazy release pre-compact */
|
||||||
|
/* _lx_nand_flash_sector_write Pre-compact before block copy */
|
||||||
|
/* _lx_nand_flash_block_data_move Wear-level with pending compact*/
|
||||||
|
/* _lx_nand_flash_defragment Explicit defragment pass */
|
||||||
|
/* _lx_nand_flash_block_allocate Emergency compaction */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
UINT _lx_nand_flash_logical_group_compact(LX_NAND_FLASH *nand_flash, ULONG logical_group)
|
||||||
|
{
|
||||||
|
|
||||||
|
UINT status;
|
||||||
|
ULONG tombstone_block;
|
||||||
|
ULONG compaction_block;
|
||||||
|
ULONG dest_block;
|
||||||
|
USHORT tombstone_block_status;
|
||||||
|
USHORT compaction_block_status;
|
||||||
|
USHORT dest_block_status;
|
||||||
|
ULONG sector;
|
||||||
|
ULONG base_sector;
|
||||||
|
LONG source_page;
|
||||||
|
ULONG dest_page;
|
||||||
|
ULONG sector_kind;
|
||||||
|
UINT find_status;
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrieve the two source blocks. */
|
||||||
|
tombstone_block = nand_flash -> lx_nand_flash_block_mapping_table[logical_group];
|
||||||
|
compaction_block = nand_flash -> lx_nand_flash_block_compaction_table[logical_group];
|
||||||
|
tombstone_block_status = nand_flash -> lx_nand_flash_block_status_table[tombstone_block];
|
||||||
|
compaction_block_status = nand_flash -> lx_nand_flash_block_status_table[compaction_block];
|
||||||
|
|
||||||
|
/* Allocate a fresh destination block. */
|
||||||
|
status = _lx_nand_flash_block_allocate(nand_flash, &dest_block);
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_block_status = LX_NAND_BLOCK_STATUS_ALLOCATED;
|
||||||
|
dest_page = 0;
|
||||||
|
base_sector = logical_group * nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
/* Merge loop: iterate every sector in the logical group.
|
||||||
|
The tombstone block (current mapping) supersedes the compaction block. */
|
||||||
|
for (sector = base_sector;
|
||||||
|
sector < base_sector + nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
sector++)
|
||||||
|
{
|
||||||
|
|
||||||
|
source_page = -1L;
|
||||||
|
sector_kind = 0;
|
||||||
|
|
||||||
|
/* Search the tombstone block first (newer data). */
|
||||||
|
find_status = _lx_nand_sector_find_in_block(nand_flash, tombstone_block,
|
||||||
|
tombstone_block_status, sector,
|
||||||
|
&source_page, §or_kind);
|
||||||
|
if (find_status == LX_ERROR)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (find_status == LX_NO_BLOCKS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Not in tombstone block; try the compaction block (older data). */
|
||||||
|
find_status = _lx_nand_sector_find_in_block(nand_flash, compaction_block,
|
||||||
|
compaction_block_status, sector,
|
||||||
|
&source_page, §or_kind);
|
||||||
|
if (find_status == LX_ERROR)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((find_status == LX_SUCCESS) && (sector_kind == LX_NAND_PAGE_TYPE_USER_DATA))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Copy live data from compaction block to destination. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, compaction_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(compaction_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest_page != (sector % nand_flash -> lx_nand_flash_pages_per_block))
|
||||||
|
{
|
||||||
|
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_page++;
|
||||||
|
}
|
||||||
|
/* RELEASED or NOT_FOUND in compaction block: sector no longer exists, skip. */
|
||||||
|
}
|
||||||
|
else if ((find_status == LX_SUCCESS) && (sector_kind == LX_NAND_PAGE_TYPE_USER_DATA))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Copy live data from tombstone block to destination. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(nand_flash, tombstone_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_copy)(tombstone_block, (ULONG)source_page, dest_block, dest_page, 1, nand_flash -> lx_nand_flash_page_buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dest_page != (sector % nand_flash -> lx_nand_flash_pages_per_block))
|
||||||
|
{
|
||||||
|
dest_block_status |= LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_page++;
|
||||||
|
}
|
||||||
|
/* RELEASED (tombstone found in tombstone block): sector is gone, skip. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode page count into dest_block_status. */
|
||||||
|
dest_block_status = (USHORT)((dest_block_status & ~(USHORT)LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK) |
|
||||||
|
(dest_page & LX_NAND_BLOCK_STATUS_PAGE_NUMBER_MASK));
|
||||||
|
|
||||||
|
/* Commit destination block or discard it if the entire group was released. */
|
||||||
|
if (dest_page == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* All sectors released; destination block is unused. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, dest_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, dest_block);
|
||||||
|
dest_block = (ULONG)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, dest_block, dest_block_status);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, dest_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove tombstone block from the mapped list. */
|
||||||
|
_lx_nand_flash_mapped_block_list_remove(nand_flash, logical_group);
|
||||||
|
|
||||||
|
/* Persist the new mapping (or UNMAPPED if all sectors were released). */
|
||||||
|
_lx_nand_flash_block_mapping_set(nand_flash, logical_group * nand_flash -> lx_nand_flash_pages_per_block, dest_block);
|
||||||
|
|
||||||
|
/* Clear the in-RAM compaction table entry. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[logical_group] = (USHORT)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
|
||||||
|
/* Add destination block to the mapped list if it holds data. */
|
||||||
|
if (dest_block != (ULONG)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash, logical_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Erase tombstone block ---- */
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, tombstone_block,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] + 1);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, tombstone_block,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] + 1));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_erase_count_table[tombstone_block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_data_move(nand_flash, tombstone_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, tombstone_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, tombstone_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
status = _lx_nand_flash_free_block_list_add(nand_flash, tombstone_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- Clear COMPACTION_PENDING flag on the old block, then erase it ---- */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, compaction_block,
|
||||||
|
(USHORT)(nand_flash -> lx_nand_flash_block_status_table[compaction_block] &
|
||||||
|
~(USHORT)LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, compaction_block,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[compaction_block] + 1);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, compaction_block,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[compaction_block] + 1));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_erase_count_table[compaction_block] > LX_NAND_FLASH_MAX_ERASE_COUNT_DELTA)
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_data_move(nand_flash, compaction_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, compaction_block, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, compaction_block, 0);
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
status = _lx_nand_flash_free_block_list_add(nand_flash, compaction_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -65,12 +66,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,12 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index)
|
UINT _lx_nand_flash_mapped_block_list_get(LX_NAND_FLASH* nand_flash, ULONG *block_mapping_index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -65,12 +66,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -67,12 +69,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH *nand_flash, ULONG* memory_ptr, UINT memory_size)
|
UINT _lx_nand_flash_memory_initialize(LX_NAND_FLASH *nand_flash, ULONG* memory_ptr, UINT memory_size)
|
||||||
{
|
{
|
||||||
@@ -186,6 +182,48 @@ UINT buffer_size;
|
|||||||
return(LX_NO_MEMORY);
|
return(LX_NO_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG i;
|
||||||
|
ULONG compaction_table_entries;
|
||||||
|
|
||||||
|
/* Set memory size for block compaction table. Same element type as block_mapping_table. */
|
||||||
|
buffer_size = nand_flash -> lx_nand_flash_total_blocks * sizeof(*nand_flash -> lx_nand_flash_block_compaction_table);
|
||||||
|
|
||||||
|
/* Make sure the size is at least one page size. */
|
||||||
|
if (buffer_size < nand_flash -> lx_nand_flash_bytes_per_page)
|
||||||
|
{
|
||||||
|
buffer_size = nand_flash -> lx_nand_flash_bytes_per_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assign memory for block compaction table. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table = (USHORT*)(((UCHAR*)memory_ptr) + memory_offset);
|
||||||
|
|
||||||
|
/* Update block compaction table size. */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table_size = buffer_size;
|
||||||
|
|
||||||
|
/* Update memory offset. */
|
||||||
|
memory_offset += buffer_size;
|
||||||
|
|
||||||
|
/* Check if there is enough memory. */
|
||||||
|
if (memory_offset > memory_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No enough memory, return error. */
|
||||||
|
return(LX_NO_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize all compaction table entries to unmapped. (LX_MEMSET zero-fills the buffer
|
||||||
|
above, but LX_NAND_BLOCK_UNMAPPED is 0xFFFF, so explicit initialisation is required.) */
|
||||||
|
compaction_table_entries = buffer_size / sizeof(*nand_flash -> lx_nand_flash_block_compaction_table);
|
||||||
|
for (i = 0; i < compaction_table_entries; i++)
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[i] = (USHORT)LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Assign memory for page buffer. */
|
/* Assign memory for page buffer. */
|
||||||
nand_flash -> lx_nand_flash_page_buffer = ((UCHAR*)memory_ptr) + memory_offset;
|
nand_flash -> lx_nand_flash_page_buffer = ((UCHAR*)memory_ptr) + memory_offset;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -73,12 +74,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH *nand_flash)
|
UINT _lx_nand_flash_metadata_allocate(LX_NAND_FLASH *nand_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -64,12 +65,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH *nand_flash)
|
UINT _lx_nand_flash_metadata_build(LX_NAND_FLASH *nand_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -69,12 +70,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value)
|
UINT _lx_nand_flash_metadata_write(LX_NAND_FLASH *nand_flash, UCHAR* main_buffer, ULONG spare_value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
/* nand_flash NAND flash instance */
|
/* nand_flash NAND flash instance */
|
||||||
/* name Name of NAND flash instance */
|
/* name Name of NAND flash instance */
|
||||||
/* nand_driver_initialize Driver initialize */
|
/* nand_driver_initialize Driver initialize */
|
||||||
|
/* nand_driver_info_ptr User data pointer */
|
||||||
/* memory_ptr Pointer to memory used by the */
|
/* memory_ptr Pointer to memory used by the */
|
||||||
/* LevelX for this NAND. */
|
/* LevelX for this NAND. */
|
||||||
/* memory_size Size of memory - must at least*/
|
/* memory_size Size of memory - must at least*/
|
||||||
@@ -66,467 +68,19 @@
|
|||||||
/* */
|
/* */
|
||||||
/* CALLS */
|
/* CALLS */
|
||||||
/* */
|
/* */
|
||||||
/* (nand_driver_initialize) Driver initialize */
|
/* lx_nand_flash_open_extended Pass NULL as driver_info_ptr */
|
||||||
/* _lx_nand_flash_memory_initialize Initialize buffer */
|
|
||||||
/* _lx_nand_flash_driver_block_status_get */
|
|
||||||
/* Get block status */
|
|
||||||
/* lx_nand_flash_driver_pages_read Read pages */
|
|
||||||
/* _lx_nand_flash_free_block_list_add Add free block to list */
|
|
||||||
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
|
|
||||||
/* _lx_nand_flash_system_error System error handler */
|
|
||||||
/* tx_mutex_create Create thread-safe mutex */
|
|
||||||
/* */
|
/* */
|
||||||
/* CALLED BY */
|
/* CALLED BY */
|
||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 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 *),
|
UINT _lx_nand_flash_open(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
|
||||||
ULONG* memory_ptr, UINT memory_size)
|
ULONG* memory_ptr, UINT memory_size)
|
||||||
{
|
{
|
||||||
|
UINT status = LX_ERROR;
|
||||||
|
|
||||||
ULONG block;
|
status = _lx_nand_flash_open_extended(nand_flash, name, nand_driver_initialize, NULL, memory_ptr, memory_size);
|
||||||
ULONG page;
|
|
||||||
UCHAR block_status;
|
|
||||||
ULONG block_count;
|
|
||||||
UINT status;
|
|
||||||
LX_NAND_FLASH *tail_ptr;
|
|
||||||
LX_NAND_DEVICE_INFO *nand_device_info_page;
|
|
||||||
UCHAR *spare_buffer_ptr;
|
|
||||||
UCHAR *page_buffer_ptr;
|
|
||||||
ULONG page_type;
|
|
||||||
UCHAR page_index;
|
|
||||||
LX_INTERRUPT_SAVE_AREA
|
|
||||||
|
|
||||||
LX_PARAMETER_NOT_USED(name);
|
return status;
|
||||||
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
/* Determine if we can support this NAND flash size. */
|
|
||||||
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if it is new LevelX NAND driver. */
|
|
||||||
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the spare data length. */
|
|
||||||
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate the number of words per block and per page. */
|
|
||||||
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
|
|
||||||
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
|
|
||||||
|
|
||||||
/* Calculate the total pages. */
|
|
||||||
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
|
|
||||||
|
|
||||||
/* Initialize memory buffer. */
|
|
||||||
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
return(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize block numbers. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
|
|
||||||
/* Setup page buffer and spare buffer pointers. */
|
|
||||||
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
|
||||||
spare_buffer_ptr = page_buffer_ptr + nand_flash -> lx_nand_flash_bytes_per_page;
|
|
||||||
|
|
||||||
/* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */
|
|
||||||
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* First, check to make sure this block is good. */
|
|
||||||
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this block bad? */
|
|
||||||
if (block_status != LX_NAND_GOOD_BLOCK)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, this block is bad. */
|
|
||||||
|
|
||||||
/* Increment the number of bad blocks. */
|
|
||||||
nand_flash -> lx_nand_flash_bad_blocks++;
|
|
||||||
|
|
||||||
/* Save the block status. */
|
|
||||||
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
|
||||||
|
|
||||||
/* Continue to the next block. */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Call driver read function to read page 0. */
|
|
||||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
|
|
||||||
#else
|
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
|
|
||||||
/* Determine if the error is fatal. */
|
|
||||||
if (status != LX_NAND_ERROR_CORRECTED)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the page type. */
|
|
||||||
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
|
||||||
|
|
||||||
/* Check if the type is device info. */
|
|
||||||
if (page_type == LX_NAND_PAGE_TYPE_DEVICE_INFO)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Get the device info page. */
|
|
||||||
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
|
|
||||||
|
|
||||||
/* Check signature. */
|
|
||||||
if (nand_device_info_page -> lx_nand_device_info_signature1 == LX_NAND_DEVICE_INFO_SIGNATURE1 &&
|
|
||||||
nand_device_info_page -> lx_nand_device_info_signature2 == LX_NAND_DEVICE_INFO_SIGNATURE2)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Save the block numbers. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number = nand_device_info_page -> lx_nand_device_info_metadata_block_number;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number = nand_device_info_page -> lx_nand_device_info_backup_metadata_block_number;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if we have found the metadata block. */
|
|
||||||
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Not found, return an error. */
|
|
||||||
return (LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize metadata block numbers and lists. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number;
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number;
|
|
||||||
|
|
||||||
/* Found one metadata block. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_count = 1;
|
|
||||||
|
|
||||||
/* Clear searched block count. */
|
|
||||||
block_count = 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Initialize next block to unmapped. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
|
||||||
|
|
||||||
/* Loop to read pages in the metadata block. */
|
|
||||||
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call driver read function to read page. */
|
|
||||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, page, page_buffer_ptr, spare_buffer_ptr, 1);
|
|
||||||
#else
|
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, page, page_buffer_ptr, spare_buffer_ptr, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
|
||||||
|
|
||||||
/* Determine if the error is fatal. */
|
|
||||||
if (status != LX_NAND_ERROR_CORRECTED)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get page type and page index. */
|
|
||||||
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & (~LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK);
|
|
||||||
page_index = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK;
|
|
||||||
|
|
||||||
/* Process metadata page by type. */
|
|
||||||
switch (page_type)
|
|
||||||
{
|
|
||||||
case LX_NAND_PAGE_TYPE_DEVICE_INFO:
|
|
||||||
|
|
||||||
/* This page is for device info. */
|
|
||||||
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
|
|
||||||
|
|
||||||
/* Get the base erase count. */
|
|
||||||
nand_flash -> lx_nand_flash_base_erase_count = nand_device_info_page -> lx_nand_device_info_base_erase_count;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE:
|
|
||||||
|
|
||||||
/* Check if page index is valid. */
|
|
||||||
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_erase_count_table_size)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Invalid page index. Return an error. */
|
|
||||||
status = LX_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy page data to erase count table. */
|
|
||||||
LX_MEMCPY(nand_flash -> lx_nand_flash_erase_count_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page, /* Use case of memcpy is verified. */
|
|
||||||
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE:
|
|
||||||
|
|
||||||
/* Check if page index is valid. */
|
|
||||||
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_mapping_table_size)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Invalid page index. Return an error. */
|
|
||||||
status = LX_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy page data to block mapping table. */
|
|
||||||
LX_MEMCPY(nand_flash -> lx_nand_flash_block_mapping_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table), /* Use case of memcpy is verified. */
|
|
||||||
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE:
|
|
||||||
|
|
||||||
/* Check if page index is valid. */
|
|
||||||
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_status_table_size)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Invalid page index. Return an error. */
|
|
||||||
status = LX_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy page data to block status table. */
|
|
||||||
LX_MEMCPY(nand_flash -> lx_nand_flash_block_status_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table), /* Use case of memcpy is verified. */
|
|
||||||
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LX_NAND_PAGE_TYPE_FREE_PAGE:
|
|
||||||
|
|
||||||
/* Found a free page. Update current page. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_current_page = page;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_current_page = page;
|
|
||||||
|
|
||||||
/* Skip all the remaining pages. */
|
|
||||||
page = nand_flash -> lx_nand_flash_pages_per_block;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LX_NAND_PAGE_TYPE_BLOCK_LINK:
|
|
||||||
|
|
||||||
/* Found next blocks. Update next block numbers. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
|
|
||||||
|
|
||||||
/* Save block numbers in metadata block lists. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
|
|
||||||
|
|
||||||
/* Increase metadata block count. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_count++;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
/* Unknown type, return error. */
|
|
||||||
status = LX_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check status. */
|
|
||||||
if (status == LX_ERROR)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Error, break the loop. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if we have reached the last page. */
|
|
||||||
if (page == nand_flash -> lx_nand_flash_pages_per_block)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Move to next block. */
|
|
||||||
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number_next;
|
|
||||||
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
|
|
||||||
|
|
||||||
/* Make sure the block is valid. */
|
|
||||||
if (nand_flash -> lx_nand_flash_metadata_block_number_current == LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Error, break the loop. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the block to process. */
|
|
||||||
block = nand_flash -> lx_nand_flash_metadata_block_number_current;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increase the processed block number. */
|
|
||||||
block_count++;
|
|
||||||
|
|
||||||
/* If block count is larger than total blocks, there is an error. */
|
|
||||||
if (block_count >= nand_flash -> lx_nand_flash_total_blocks)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Break the loop. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 && status != LX_ERROR);
|
|
||||||
|
|
||||||
/* Check if metadata page is processed correctly. */
|
|
||||||
if (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 || status == LX_ERROR)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loop to build free and mapped block lists. */
|
|
||||||
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Check for free blocks. */
|
|
||||||
if (nand_flash -> lx_nand_flash_block_status_table[block] == LX_NAND_BLOCK_STATUS_FREE)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Add the block to free block list. */
|
|
||||||
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for mapped blocks. */
|
|
||||||
if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Add the block to free block list. */
|
|
||||||
_lx_nand_flash_mapped_block_list_add(nand_flash, block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LX_THREAD_SAFE_ENABLE
|
|
||||||
|
|
||||||
/* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs
|
|
||||||
in order to provide thread-safe operation. */
|
|
||||||
status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT);
|
|
||||||
|
|
||||||
/* Determine if the mutex creation encountered an error. */
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler, since this should not happen. */
|
|
||||||
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0);
|
|
||||||
|
|
||||||
/* Return error to caller. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Lockout interrupts. */
|
|
||||||
LX_DISABLE
|
|
||||||
|
|
||||||
/* At this point, the NAND flash has been opened successfully. Place the
|
|
||||||
NAND flash control block on the linked list of currently opened NAND flashes. */
|
|
||||||
|
|
||||||
/* Set the NAND flash state to open. */
|
|
||||||
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_OPENED;
|
|
||||||
|
|
||||||
/* Place the NAND flash control block on the list of opened NAND flashes. First,
|
|
||||||
check for an empty list. */
|
|
||||||
if (_lx_nand_flash_opened_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* List is not empty - other NAND flashes are open. */
|
|
||||||
|
|
||||||
/* Pickup tail pointer. */
|
|
||||||
tail_ptr = _lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous;
|
|
||||||
|
|
||||||
/* Place the new NAND flash control block in the list. */
|
|
||||||
_lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous = nand_flash;
|
|
||||||
tail_ptr -> lx_nand_flash_open_next = nand_flash;
|
|
||||||
|
|
||||||
/* Setup this NAND flash's opened links. */
|
|
||||||
nand_flash -> lx_nand_flash_open_previous = tail_ptr;
|
|
||||||
nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* The opened NAND flash list is empty. Add the NAND flash to empty list. */
|
|
||||||
_lx_nand_flash_opened_ptr = nand_flash;
|
|
||||||
nand_flash -> lx_nand_flash_open_next = nand_flash;
|
|
||||||
nand_flash -> lx_nand_flash_open_previous = nand_flash;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the opened NAND flash counter. */
|
|
||||||
_lx_nand_flash_opened_count++;
|
|
||||||
|
|
||||||
/* Restore interrupts. */
|
|
||||||
LX_RESTORE
|
|
||||||
|
|
||||||
/* Return a successful completion. */
|
|
||||||
return(LX_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,682 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the MIT License which is available at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** LevelX Component */
|
||||||
|
/** */
|
||||||
|
/** NAND Flash */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#define LX_SOURCE_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Disable ThreadX error checking. */
|
||||||
|
|
||||||
|
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||||
|
#define LX_DISABLE_ERROR_CHECKING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Include necessary system files. */
|
||||||
|
|
||||||
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nand_flash_open PORTABLE C */
|
||||||
|
/* 6.3.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* Xiuwen Cai, Microsoft Corporation */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function opens a NAND flash instance and ensures the */
|
||||||
|
/* NAND flash is in a coherent state. */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nand_flash NAND flash instance */
|
||||||
|
/* name Name of NAND flash instance */
|
||||||
|
/* nand_driver_initialize Driver initialize */
|
||||||
|
/* memory_ptr Pointer to memory used by the */
|
||||||
|
/* LevelX for this NAND. */
|
||||||
|
/* memory_size Size of memory - must at least*/
|
||||||
|
/* 7 * total block count + */
|
||||||
|
/* 2 * page size */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* return status */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* (nand_driver_initialize) Driver initialize */
|
||||||
|
/* _lx_nand_flash_memory_initialize Initialize buffer */
|
||||||
|
/* _lx_nand_flash_driver_block_status_get */
|
||||||
|
/* Get block status */
|
||||||
|
/* lx_nand_flash_driver_pages_read Read pages */
|
||||||
|
/* _lx_nand_flash_free_block_list_add Add free block to list */
|
||||||
|
/* _lx_nand_flash_mapped_block_list_add Add mapped block to list */
|
||||||
|
/* _lx_nand_flash_system_error System error handler */
|
||||||
|
/* tx_mutex_create Create thread-safe mutex */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* Application Code */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
UINT _lx_nand_flash_open_extended(LX_NAND_FLASH *nand_flash, CHAR *name, UINT (*nand_driver_initialize)(LX_NAND_FLASH *),
|
||||||
|
VOID *nand_driver_info_ptr, ULONG* memory_ptr, UINT memory_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG block;
|
||||||
|
ULONG page;
|
||||||
|
UCHAR block_status;
|
||||||
|
ULONG block_count;
|
||||||
|
UINT status;
|
||||||
|
LX_NAND_FLASH *tail_ptr;
|
||||||
|
LX_NAND_DEVICE_INFO *nand_device_info_page;
|
||||||
|
UCHAR *spare_buffer_ptr;
|
||||||
|
UCHAR *page_buffer_ptr;
|
||||||
|
ULONG page_type;
|
||||||
|
UCHAR page_index;
|
||||||
|
LX_INTERRUPT_SAVE_AREA
|
||||||
|
|
||||||
|
LX_PARAMETER_NOT_USED(name);
|
||||||
|
|
||||||
|
/* 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));
|
||||||
|
|
||||||
|
/* Pass the driver_info_ptr */
|
||||||
|
nand_flash -> lx_nand_flash_driver_info_ptr = nand_driver_info_ptr;
|
||||||
|
|
||||||
|
/* Call the flash driver's initialization function. */
|
||||||
|
(nand_driver_initialize)(nand_flash);
|
||||||
|
|
||||||
|
/* Determine if we can support this NAND flash size. */
|
||||||
|
if (nand_flash -> lx_nand_flash_pages_per_block > LX_NAND_MAX_PAGE_PER_BLOCK || nand_flash -> lx_nand_flash_total_blocks > LX_NAND_MAX_BLOCK_COUNT)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if it is new LevelX NAND driver. */
|
||||||
|
if (nand_flash -> lx_nand_flash_driver_pages_read == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_write == LX_NULL || nand_flash -> lx_nand_flash_driver_pages_copy == LX_NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the spare data length. */
|
||||||
|
if (nand_flash -> lx_nand_flash_spare_data1_length < sizeof(ULONG))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the number of words per block and per page. */
|
||||||
|
nand_flash -> lx_nand_flash_words_per_page = (nand_flash -> lx_nand_flash_bytes_per_page / sizeof(ULONG));
|
||||||
|
nand_flash -> lx_nand_flash_words_per_block = (nand_flash -> lx_nand_flash_words_per_page * nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
/* Calculate the total pages. */
|
||||||
|
nand_flash -> lx_nand_flash_total_pages = nand_flash -> lx_nand_flash_total_blocks * nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
/* Initialize memory buffer. */
|
||||||
|
status = _lx_nand_flash_memory_initialize(nand_flash, memory_ptr, memory_size);
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize block numbers. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
|
||||||
|
/* Setup page buffer and spare buffer pointers. */
|
||||||
|
page_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
spare_buffer_ptr = page_buffer_ptr + nand_flash -> lx_nand_flash_bytes_per_page;
|
||||||
|
|
||||||
|
/* Loop through the blocks to check for bad blocks and determine the minimum and maximum erase count for each good block. */
|
||||||
|
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* First, check to make sure this block is good. */
|
||||||
|
status = _lx_nand_flash_driver_block_status_get(nand_flash, block, &block_status);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this block bad? */
|
||||||
|
if (block_status != LX_NAND_GOOD_BLOCK)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, this block is bad. */
|
||||||
|
|
||||||
|
/* Increment the number of bad blocks. */
|
||||||
|
nand_flash -> lx_nand_flash_bad_blocks++;
|
||||||
|
|
||||||
|
/* Save the block status. */
|
||||||
|
nand_flash -> lx_nand_flash_block_status_table[block] = LX_NAND_BLOCK_STATUS_BAD;
|
||||||
|
|
||||||
|
/* Continue to the next block. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call driver read function to read page 0. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, 0, page_buffer_ptr, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
|
||||||
|
/* Determine if the error is fatal. */
|
||||||
|
if (status != LX_NAND_ERROR_CORRECTED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the page type. */
|
||||||
|
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||||
|
|
||||||
|
/* Check if the type is device info. */
|
||||||
|
if (page_type == LX_NAND_PAGE_TYPE_DEVICE_INFO)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Get the device info page. */
|
||||||
|
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
|
||||||
|
|
||||||
|
/* Check signature. */
|
||||||
|
if (nand_device_info_page -> lx_nand_device_info_signature1 == LX_NAND_DEVICE_INFO_SIGNATURE1 &&
|
||||||
|
nand_device_info_page -> lx_nand_device_info_signature2 == LX_NAND_DEVICE_INFO_SIGNATURE2)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Save the block numbers. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number = nand_device_info_page -> lx_nand_device_info_metadata_block_number;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number = nand_device_info_page -> lx_nand_device_info_backup_metadata_block_number;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we have found the metadata block. */
|
||||||
|
if (nand_flash -> lx_nand_flash_metadata_block_number == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Not found, return an error. */
|
||||||
|
return (LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize metadata block numbers and lists. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number;
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_metadata_block_number;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block[0] = (USHORT)nand_flash -> lx_nand_flash_backup_metadata_block_number;
|
||||||
|
|
||||||
|
/* Found one metadata block. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_count = 1;
|
||||||
|
|
||||||
|
/* Clear searched block count. */
|
||||||
|
block_count = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Initialize next block to unmapped. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_NAND_BLOCK_UNMAPPED;
|
||||||
|
|
||||||
|
/* Loop to read pages in the metadata block. */
|
||||||
|
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block ; page++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call driver read function to read page. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, page, page_buffer_ptr, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, page, page_buffer_ptr, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
|
||||||
|
/* Determine if the error is fatal. */
|
||||||
|
if (status != LX_NAND_ERROR_CORRECTED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get page type and page index. */
|
||||||
|
page_type = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & (~LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK);
|
||||||
|
page_index = LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_PAGE_NUMBER_MASK;
|
||||||
|
|
||||||
|
/* Process metadata page by type. */
|
||||||
|
switch (page_type)
|
||||||
|
{
|
||||||
|
case LX_NAND_PAGE_TYPE_DEVICE_INFO:
|
||||||
|
|
||||||
|
/* This page is for device info. */
|
||||||
|
nand_device_info_page = (LX_NAND_DEVICE_INFO*)page_buffer_ptr;
|
||||||
|
|
||||||
|
/* Get the base erase count. */
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count = nand_device_info_page -> lx_nand_device_info_base_erase_count;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LX_NAND_PAGE_TYPE_ERASE_COUNT_TABLE:
|
||||||
|
|
||||||
|
/* Check if page index is valid. */
|
||||||
|
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_erase_count_table_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Invalid page index. Return an error. */
|
||||||
|
status = LX_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy page data to erase count table. */
|
||||||
|
LX_MEMCPY(nand_flash -> lx_nand_flash_erase_count_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page, /* Use case of memcpy is verified. */
|
||||||
|
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE:
|
||||||
|
|
||||||
|
/* Check if page index is valid. */
|
||||||
|
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_mapping_table_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Invalid page index. Return an error. */
|
||||||
|
status = LX_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy page data to block mapping table. */
|
||||||
|
LX_MEMCPY(nand_flash -> lx_nand_flash_block_mapping_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table), /* Use case of memcpy is verified. */
|
||||||
|
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LX_NAND_PAGE_TYPE_BLOCK_STATUS_TABLE:
|
||||||
|
|
||||||
|
/* Check if page index is valid. */
|
||||||
|
if (((ULONG)page_index + 1) * nand_flash -> lx_nand_flash_bytes_per_page > nand_flash -> lx_nand_flash_block_status_table_size)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Invalid page index. Return an error. */
|
||||||
|
status = LX_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy page data to block status table. */
|
||||||
|
LX_MEMCPY(nand_flash -> lx_nand_flash_block_status_table + page_index * nand_flash -> lx_nand_flash_bytes_per_page / sizeof(*nand_flash -> lx_nand_flash_block_status_table), /* Use case of memcpy is verified. */
|
||||||
|
page_buffer_ptr, nand_flash -> lx_nand_flash_bytes_per_page);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LX_NAND_PAGE_TYPE_FREE_PAGE:
|
||||||
|
|
||||||
|
/* Found a free page. Update current page. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_current_page = page;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_current_page = page;
|
||||||
|
|
||||||
|
/* Skip all the remaining pages. */
|
||||||
|
page = nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LX_NAND_PAGE_TYPE_BLOCK_LINK:
|
||||||
|
|
||||||
|
/* Found next blocks. Update next block numbers. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_next = LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
|
||||||
|
|
||||||
|
/* Save block numbers in metadata block lists. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_MAIN_METADATA_OFFSET]);
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block[nand_flash -> lx_nand_flash_metadata_block_count] = (USHORT)LX_UTILITY_LONG_GET(&page_buffer_ptr[LX_NAND_BLOCK_LINK_BACKUP_METADATA_OFFSET]);
|
||||||
|
|
||||||
|
/* Increase metadata block count. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_count++;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
/* Unknown type, return error. */
|
||||||
|
status = LX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check status. */
|
||||||
|
if (status == LX_ERROR)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Error, break the loop. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we have reached the last page. */
|
||||||
|
if (page == nand_flash -> lx_nand_flash_pages_per_block)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Move to next block. */
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number_current = nand_flash -> lx_nand_flash_metadata_block_number_next;
|
||||||
|
nand_flash -> lx_nand_flash_backup_metadata_block_number_current = nand_flash -> lx_nand_flash_backup_metadata_block_number_next;
|
||||||
|
|
||||||
|
/* Make sure the block is valid. */
|
||||||
|
if (nand_flash -> lx_nand_flash_metadata_block_number_current == LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Error, break the loop. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the block to process. */
|
||||||
|
block = nand_flash -> lx_nand_flash_metadata_block_number_current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increase the processed block number. */
|
||||||
|
block_count++;
|
||||||
|
|
||||||
|
/* If block count is larger than total blocks, there is an error. */
|
||||||
|
if (block_count >= nand_flash -> lx_nand_flash_total_blocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Break the loop. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 && status != LX_ERROR);
|
||||||
|
|
||||||
|
/* Check if metadata page is processed correctly. */
|
||||||
|
if (nand_flash -> lx_nand_flash_metadata_block_current_page == 0 || status == LX_ERROR)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loop to build free and mapped block lists. */
|
||||||
|
for (block = 0; block < nand_flash -> lx_nand_flash_total_blocks; block++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Check for free blocks. */
|
||||||
|
if (nand_flash -> lx_nand_flash_block_status_table[block] == LX_NAND_BLOCK_STATUS_FREE)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Add the block to free block list. */
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for mapped blocks. */
|
||||||
|
if (nand_flash -> lx_nand_flash_block_mapping_table[block] != LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Add the block to free block list. */
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG blk;
|
||||||
|
ULONG lg;
|
||||||
|
USHORT blk_status;
|
||||||
|
|
||||||
|
/* Phase 1: Rebuild compaction table and recover from mid-release crashes.
|
||||||
|
Scan all blocks for COMPACTION_PENDING. */
|
||||||
|
for (blk = 0; blk < nand_flash -> lx_nand_flash_total_blocks; blk++)
|
||||||
|
{
|
||||||
|
|
||||||
|
blk_status = nand_flash -> lx_nand_flash_block_status_table[blk];
|
||||||
|
|
||||||
|
/* FREE (0xFFFF) and BAD (0xFF00) both have COMPACTION_PENDING bit set; skip them. */
|
||||||
|
if ((blk_status == LX_NAND_BLOCK_STATUS_FREE) || (blk_status == LX_NAND_BLOCK_STATUS_BAD))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blk_status & LX_NAND_BLOCK_STATUS_COMPACTION_PENDING)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Check if any logical group still maps to this physical block.
|
||||||
|
If so, the mapping update didn't happen — abort the lazy release. */
|
||||||
|
lg = nand_flash -> lx_nand_flash_total_blocks;
|
||||||
|
{
|
||||||
|
ULONG search_lg;
|
||||||
|
for (search_lg = 0; search_lg < nand_flash -> lx_nand_flash_total_blocks; search_lg++)
|
||||||
|
{
|
||||||
|
if (nand_flash -> lx_nand_flash_block_mapping_table[search_lg] == (USHORT)blk)
|
||||||
|
{
|
||||||
|
lg = search_lg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lg != nand_flash -> lx_nand_flash_total_blocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scenario A: crash after COMPACTION_PENDING set, before mapping updated.
|
||||||
|
Clear COMPACTION_PENDING to restore the block to its normal state. */
|
||||||
|
blk_status = (USHORT)(blk_status & (USHORT)(~LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
(void)_lx_nand_flash_block_status_set(nand_flash, blk, blk_status);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Scenario B: deferred compaction — scan block pages to find the LG. */
|
||||||
|
ULONG page;
|
||||||
|
ULONG spare_word;
|
||||||
|
ULONG found_lg;
|
||||||
|
UCHAR *spare_ptr;
|
||||||
|
|
||||||
|
spare_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
found_lg = nand_flash -> lx_nand_flash_total_blocks;
|
||||||
|
|
||||||
|
for (page = 0; page < nand_flash -> lx_nand_flash_pages_per_block; page++)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, blk, page, (UCHAR*)NULL, spare_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(blk, page, (UCHAR*)NULL, spare_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
spare_word = LX_UTILITY_LONG_GET(&spare_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]);
|
||||||
|
|
||||||
|
if ((spare_word & (~LX_NAND_PAGE_TYPE_USER_DATA_MASK)) == LX_NAND_PAGE_TYPE_USER_DATA)
|
||||||
|
{
|
||||||
|
found_lg = (spare_word & LX_NAND_PAGE_TYPE_USER_DATA_MASK) /
|
||||||
|
nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((found_lg != nand_flash -> lx_nand_flash_total_blocks) &&
|
||||||
|
(found_lg < nand_flash -> lx_nand_flash_total_blocks))
|
||||||
|
{
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[found_lg] = (USHORT)blk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Phase 2: Orphan block recovery — erase ALLOCATED blocks not referenced
|
||||||
|
by any mapping entry and not marked COMPACTION_PENDING. */
|
||||||
|
for (blk = 0; blk < nand_flash -> lx_nand_flash_total_blocks; blk++)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG found;
|
||||||
|
|
||||||
|
blk_status = nand_flash -> lx_nand_flash_block_status_table[blk];
|
||||||
|
|
||||||
|
if ((blk_status == LX_NAND_BLOCK_STATUS_FREE) || (blk_status == LX_NAND_BLOCK_STATUS_BAD))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blk_status & LX_NAND_BLOCK_STATUS_COMPACTION_PENDING)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(blk_status & LX_NAND_BLOCK_STATUS_ALLOCATED))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search for this block in the mapping table. */
|
||||||
|
found = LX_FALSE;
|
||||||
|
for (lg = 0; lg < nand_flash -> lx_nand_flash_total_blocks; lg++)
|
||||||
|
{
|
||||||
|
if (nand_flash -> lx_nand_flash_block_mapping_table[lg] == (USHORT)blk)
|
||||||
|
{
|
||||||
|
found = LX_TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Orphan block: erase and reclaim. */
|
||||||
|
status = _lx_nand_flash_driver_block_erase(nand_flash, blk,
|
||||||
|
nand_flash -> lx_nand_flash_base_erase_count +
|
||||||
|
nand_flash -> lx_nand_flash_erase_count_table[blk] + 1);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, blk, 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nand_flash_erase_count_set(nand_flash, blk,
|
||||||
|
(UCHAR)(nand_flash -> lx_nand_flash_erase_count_table[blk] + 1));
|
||||||
|
|
||||||
|
if (!status)
|
||||||
|
{
|
||||||
|
(void)_lx_nand_flash_block_status_set(nand_flash, blk, LX_NAND_BLOCK_STATUS_FREE);
|
||||||
|
_lx_nand_flash_free_block_list_add(nand_flash, blk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
|
/* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs
|
||||||
|
in order to provide thread-safe operation. */
|
||||||
|
status = tx_mutex_create(&nand_flash -> lx_nand_flash_mutex, "NAND Flash Mutex", TX_NO_INHERIT);
|
||||||
|
|
||||||
|
/* Determine if the mutex creation encountered an error. */
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler, since this should not happen. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, LX_SYSTEM_MUTEX_CREATE_FAILED, 0, 0);
|
||||||
|
|
||||||
|
/* Return error to caller. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Lockout interrupts. */
|
||||||
|
LX_DISABLE
|
||||||
|
|
||||||
|
/* At this point, the NAND flash has been opened successfully. Place the
|
||||||
|
NAND flash control block on the linked list of currently opened NAND flashes. */
|
||||||
|
|
||||||
|
/* Set the NAND flash state to open. */
|
||||||
|
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_OPENED;
|
||||||
|
|
||||||
|
/* Place the NAND flash control block on the list of opened NAND flashes. First,
|
||||||
|
check for an empty list. */
|
||||||
|
if (_lx_nand_flash_opened_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* List is not empty - other NAND flashes are open. */
|
||||||
|
|
||||||
|
/* Pickup tail pointer. */
|
||||||
|
tail_ptr = _lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous;
|
||||||
|
|
||||||
|
/* Place the new NAND flash control block in the list. */
|
||||||
|
_lx_nand_flash_opened_ptr -> lx_nand_flash_open_previous = nand_flash;
|
||||||
|
tail_ptr -> lx_nand_flash_open_next = nand_flash;
|
||||||
|
|
||||||
|
/* Setup this NAND flash's opened links. */
|
||||||
|
nand_flash -> lx_nand_flash_open_previous = tail_ptr;
|
||||||
|
nand_flash -> lx_nand_flash_open_next = _lx_nand_flash_opened_ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* The opened NAND flash list is empty. Add the NAND flash to empty list. */
|
||||||
|
_lx_nand_flash_opened_ptr = nand_flash;
|
||||||
|
nand_flash -> lx_nand_flash_open_next = nand_flash;
|
||||||
|
nand_flash -> lx_nand_flash_open_previous = nand_flash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the opened NAND flash counter. */
|
||||||
|
_lx_nand_flash_opened_count++;
|
||||||
|
|
||||||
|
/* Restore interrupts. */
|
||||||
|
LX_RESTORE
|
||||||
|
|
||||||
|
/* Return a successful completion. */
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,16 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* NAND flash driver */
|
/* NAND flash driver */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,16 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* NAND flash driver */
|
/* NAND flash driver */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -68,19 +69,6 @@
|
|||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* deprecated this API, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks)
|
UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -72,12 +74,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
|
UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
|
||||||
{
|
{
|
||||||
@@ -143,9 +139,9 @@ LONG page;
|
|||||||
|
|
||||||
/* Read a page. */
|
/* Read a page. */
|
||||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)buffer, spare_buffer_ptr, 1);
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
#else
|
#else
|
||||||
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)buffer, spare_buffer_ptr, 1);
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Check for an error from flash driver. */
|
/* Check for an error from flash driver. */
|
||||||
@@ -166,6 +162,26 @@ LONG page;
|
|||||||
/* Get the logical sector number from spare bytes, and check if it matches the addressed sector number. */
|
/* Get the logical sector number from spare bytes, and check if it matches the addressed sector number. */
|
||||||
if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
|
if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
|
||||||
{
|
{
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
|
/* Release the thread safe mutex. */
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
#ifdef LX_THREAD_SAFE_ENABLE
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
/* Release the thread safe mutex. */
|
/* Release the thread safe mutex. */
|
||||||
@@ -216,6 +232,76 @@ LONG page;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG logical_group;
|
||||||
|
ULONG old_block;
|
||||||
|
|
||||||
|
/* Check the compaction table for a deferred source block that might hold
|
||||||
|
the requested sector. The primary block (tombstone block) was already
|
||||||
|
scanned above; fall back to the old full block here. */
|
||||||
|
logical_group = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
|
||||||
|
|
||||||
|
if (nand_flash -> lx_nand_flash_block_compaction_table[logical_group] != (USHORT)LX_NAND_BLOCK_UNMAPPED)
|
||||||
|
{
|
||||||
|
|
||||||
|
old_block = nand_flash -> lx_nand_flash_block_compaction_table[logical_group];
|
||||||
|
|
||||||
|
/* Set spare buffer pointer. */
|
||||||
|
spare_buffer_ptr = (UCHAR*)nand_flash -> lx_nand_flash_page_buffer;
|
||||||
|
|
||||||
|
/* The compaction-pending block is always FULL; scan all pages in reverse. */
|
||||||
|
for (page = (LONG)nand_flash -> lx_nand_flash_pages_per_block - 1; page >= 0; page--)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, old_block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(old_block, (ULONG)page, (UCHAR*)NULL, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, old_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if this page matches the requested sector. */
|
||||||
|
if ((LX_UTILITY_LONG_GET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset]) & LX_NAND_PAGE_TYPE_USER_DATA_MASK) == logical_sector)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(nand_flash, old_block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_read)(old_block, (ULONG)page, (UCHAR*)buffer, NULL, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, old_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Sector hasn't been written. Simply fill the destination buffer with ones and return success. */
|
/* Sector hasn't been written. Simply fill the destination buffer with ones and return success. */
|
||||||
|
|
||||||
/* Setup pointer to users buffer. */
|
/* Setup pointer to users buffer. */
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -81,12 +83,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector)
|
UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector)
|
||||||
{
|
{
|
||||||
@@ -210,6 +206,119 @@ USHORT new_block_status;
|
|||||||
if (block_status & LX_NAND_BLOCK_STATUS_FULL)
|
if (block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* Lazy path: defer the copy+erase when enough free blocks are available.
|
||||||
|
The old block is kept as a compaction source; a new block holds only
|
||||||
|
the tombstone for the released sector. */
|
||||||
|
if (nand_flash -> lx_nand_flash_free_block_list_tail >
|
||||||
|
(ULONG)LX_NAND_FLASH_SECTOR_RELEASE_LAZY_THRESHOLD)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Allocate a new block for the tombstone. */
|
||||||
|
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
||||||
|
|
||||||
|
/* Check return status. */
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
|
/* Release the thread safe mutex. */
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set page buffer to all 0xFF (data = erased, sector is released). */
|
||||||
|
LX_MEMSET(nand_flash -> lx_nand_flash_page_buffer, 0xFF,
|
||||||
|
nand_flash -> lx_nand_flash_bytes_per_page +
|
||||||
|
nand_flash -> lx_nand_flash_spare_total_length);
|
||||||
|
|
||||||
|
/* Setup spare buffer pointer. */
|
||||||
|
spare_buffer_ptr = nand_flash -> lx_nand_flash_page_buffer +
|
||||||
|
nand_flash -> lx_nand_flash_bytes_per_page;
|
||||||
|
|
||||||
|
/* Save metadata block number in spare bytes if space allows. */
|
||||||
|
if (nand_flash -> lx_nand_flash_spare_data2_length >= sizeof(USHORT))
|
||||||
|
{
|
||||||
|
LX_UTILITY_SHORT_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data2_offset],
|
||||||
|
nand_flash -> lx_nand_flash_metadata_block_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set page type to USER_DATA_RELEASED. */
|
||||||
|
LX_UTILITY_LONG_SET(&spare_buffer_ptr[nand_flash -> lx_nand_flash_spare_data1_offset],
|
||||||
|
LX_NAND_PAGE_TYPE_USER_DATA_RELEASED | logical_sector);
|
||||||
|
|
||||||
|
/* Write the tombstone page to page 0 of the new block. */
|
||||||
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_write)(nand_flash, new_block, 0,
|
||||||
|
(UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1);
|
||||||
|
#else
|
||||||
|
status = (nand_flash -> lx_nand_flash_driver_pages_write)(new_block, 0,
|
||||||
|
(UCHAR*)nand_flash -> lx_nand_flash_page_buffer, spare_buffer_ptr, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set new block status: allocated, non-sequential, 1 page written. */
|
||||||
|
new_block_status = (USHORT)(LX_NAND_BLOCK_STATUS_ALLOCATED |
|
||||||
|
LX_NAND_BLOCK_STATUS_NON_SEQUENTIAL | 1u);
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, new_block, new_block_status);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, new_block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark old block as compaction-pending (persisted to flash).
|
||||||
|
Write order: tombstone written → new_block status set →
|
||||||
|
COMPACTION_PENDING set → mapping updated.
|
||||||
|
This ordering ensures safe crash recovery at open time. */
|
||||||
|
status = _lx_nand_flash_block_status_set(nand_flash, block,
|
||||||
|
(USHORT)(block_status | LX_NAND_BLOCK_STATUS_COMPACTION_PENDING));
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove old mapping before updating to new block. */
|
||||||
|
_lx_nand_flash_mapped_block_list_remove(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
/* Update logical-to-physical mapping to the new tombstone block. */
|
||||||
|
_lx_nand_flash_block_mapping_set(nand_flash, logical_sector, new_block);
|
||||||
|
|
||||||
|
/* Record the old block as the compaction source (RAM only; rebuilt at open). */
|
||||||
|
nand_flash -> lx_nand_flash_block_compaction_table[logical_sector / nand_flash -> lx_nand_flash_pages_per_block] = (USHORT)block;
|
||||||
|
|
||||||
|
/* Add new tombstone block to the mapped list. */
|
||||||
|
_lx_nand_flash_mapped_block_list_add(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Eager path (existing): allocate a new block and copy + erase immediately. */
|
||||||
|
|
||||||
/* Allocate a new block. */
|
/* Allocate a new block. */
|
||||||
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
status = _lx_nand_flash_block_allocate(nand_flash, &new_block);
|
||||||
|
|
||||||
@@ -392,6 +501,7 @@ USHORT new_block_status;
|
|||||||
/* Add the new block to mapped block list. */
|
/* Add the new block to mapped block list. */
|
||||||
_lx_nand_flash_mapped_block_list_add(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
_lx_nand_flash_mapped_block_list_add(nand_flash, logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
}
|
}
|
||||||
|
} /* end eager path else block */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -8,6 +9,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Copilot (Sonnet 4.6).
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -83,12 +85,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
|
UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer)
|
||||||
{
|
{
|
||||||
@@ -136,6 +132,42 @@ UINT copy_block = LX_FALSE;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE
|
||||||
|
/* If the block is full and has a pending compaction source, compact it now
|
||||||
|
before writing so the new data merges correctly with a single source block. */
|
||||||
|
if ((block != LX_NAND_BLOCK_UNMAPPED) && (block_status & LX_NAND_BLOCK_STATUS_FULL) &&
|
||||||
|
(nand_flash -> lx_nand_flash_block_compaction_table[logical_sector / nand_flash -> lx_nand_flash_pages_per_block] != (USHORT)LX_NAND_BLOCK_UNMAPPED))
|
||||||
|
{
|
||||||
|
|
||||||
|
status = _lx_nand_flash_logical_group_compact(nand_flash,
|
||||||
|
logical_sector / nand_flash -> lx_nand_flash_pages_per_block);
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
_lx_nand_flash_system_error(nand_flash, status, block, 0);
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Refresh block and block_status after compaction. */
|
||||||
|
status = _lx_nand_flash_block_find(nand_flash, logical_sector, &block, &block_status);
|
||||||
|
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (status != LX_NAND_ERROR_CORRECTED)
|
||||||
|
{
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
tx_mutex_put(&nand_flash -> lx_nand_flash_mutex);
|
||||||
|
#endif
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* LX_NAND_FLASH_ENABLE_LAZY_SECTOR_RELEASE */
|
||||||
|
|
||||||
/* Check if block is unmapped or block is full. */
|
/* Check if block is unmapped or block is full. */
|
||||||
if (block == LX_NAND_BLOCK_UNMAPPED || block_status & LX_NAND_BLOCK_STATUS_FULL)
|
if (block == LX_NAND_BLOCK_UNMAPPED || block_status & LX_NAND_BLOCK_STATUS_FULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -69,12 +70,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,12 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count)
|
UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG sector_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -69,12 +70,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer, ULONG sector_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -278,12 +279,17 @@ UINT ecc_status = LX_SUCCESS;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (spare_buffer)
|
||||||
|
{
|
||||||
|
|
||||||
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
#ifdef LX_NAND_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
status = _lx_nand_flash_simulator_extra_bytes_get(nand_flash, block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
status = _lx_nand_flash_simulator_extra_bytes_get(nand_flash, block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
||||||
#else
|
#else
|
||||||
status = _lx_nand_flash_simulator_extra_bytes_get(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
status = _lx_nand_flash_simulator_extra_bytes_get(block, page + i, spare_buffer + i * SPARE_BYTES_PER_PAGE, SPARE_BYTES_PER_PAGE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (ecc_status);
|
return (ecc_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
|
VOID _lx_nand_flash_system_error(LX_NAND_FLASH *nand_flash, UINT error_code, ULONG block, ULONG page)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -73,21 +74,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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)
|
UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -64,16 +65,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
|
UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,16 +68,6 @@
|
|||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash)
|
UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,19 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
|
UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
|
UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -67,19 +68,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
|
UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,28 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 12-31-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* fixed compiler warnings, */
|
|
||||||
/* resulting in version 6.1.3 */
|
|
||||||
/* 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 */
|
|
||||||
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added mapping bitmap cache, */
|
|
||||||
/* added obsolete count cache, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size)
|
UINT _lx_nor_flash_extended_cache_enable(LX_NOR_FLASH *nor_flash, VOID *memory, ULONG size)
|
||||||
{
|
{
|
||||||
@@ -290,7 +269,7 @@ ULONG block_word;
|
|||||||
|
|
||||||
/* Loop through the memory supplied and assign to cache entries. */
|
/* Loop through the memory supplied and assign to cache entries. */
|
||||||
i = 0;
|
i = 0;
|
||||||
while (cache_size >= LX_NOR_SECTOR_SIZE)
|
while ((cache_size >= LX_NOR_SECTOR_SIZE) && (i < LX_NOR_EXTENDED_CACHE_SIZE))
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Setup this cache entry. */
|
/* Setup this cache entry. */
|
||||||
@@ -309,7 +288,7 @@ ULONG block_word;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Save the number of cache entries. */
|
/* Save the number of cache entries. */
|
||||||
if(i > LX_NOR_EXTENDED_CACHE_SIZE)
|
if(i == LX_NOR_EXTENDED_CACHE_SIZE)
|
||||||
{
|
{
|
||||||
|
|
||||||
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;
|
nor_flash -> lx_nor_flash_extended_cache_entries = LX_NOR_EXTENDED_CACHE_SIZE;
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2025 Microsoft Corporation
|
||||||
|
* Copyright (c) 2025 STmicroelectronics
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the MIT License which is available at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** LevelX Component */
|
||||||
|
/** */
|
||||||
|
/** NOR Flash */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#define LX_SOURCE_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Disable ThreadX error checking. */
|
||||||
|
|
||||||
|
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||||
|
#define LX_DISABLE_ERROR_CHECKING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Include necessary system files. */
|
||||||
|
|
||||||
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nor_flash_format PORTABLE C */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function opens a NOR flash instance then erases all the non */
|
||||||
|
/* erased blocks, then writes the erase count */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nor_flash NOR flash instance */
|
||||||
|
/* name Name of NOR flash instance */
|
||||||
|
/* nor_driver_initialize Driver initialize */
|
||||||
|
/* nor_driver_info_ptr Drivier user data pointer */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* return status */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* (nor_driver_initialize) Driver initialize */
|
||||||
|
/* _lx_nor_flash_driver_read Driver read */
|
||||||
|
/* _lx_nor_flash_driver_write Driver write */
|
||||||
|
/* (lx_nor_flash_driver_block_erased_verify) */
|
||||||
|
/* NOR flash verify block erased */
|
||||||
|
/* _lx_nor_flash_driver_block_erase Driver block erase */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* Application Code */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
UINT _lx_nor_flash_format(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG l;
|
||||||
|
UINT status;
|
||||||
|
|
||||||
|
ULONG block_word;
|
||||||
|
ULONG *block_word_ptr;
|
||||||
|
|
||||||
|
LX_PARAMETER_NOT_USED(name);
|
||||||
|
|
||||||
|
/* Clear the NOR flash control block. User extension is not cleared. */
|
||||||
|
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
|
||||||
|
|
||||||
|
nor_flash -> lx_nor_flash_driver_info_ptr = nor_driver_info_ptr;
|
||||||
|
|
||||||
|
/* Call the flash driver's initialization function. */
|
||||||
|
(nor_driver_initialize)(nor_flash);
|
||||||
|
|
||||||
|
#ifndef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
|
||||||
|
supported. */
|
||||||
|
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
|
||||||
|
{
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_NO_MEMORY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
||||||
|
{
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
/* Check that the block is already erased */
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
|
||||||
|
#else
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the block is not erased, thus make sure to erase it */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
/* the max erase count is not needed just pass the value 0 */
|
||||||
|
status = _lx_nor_flash_driver_block_erase(nor_flash, l, 0);
|
||||||
|
/* Check for an error from flash driver */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check that the sector was correctly erased */
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
|
||||||
|
#else
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
|
||||||
|
#endif
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup the block word pointer to the first word of the first block */
|
||||||
|
block_word_ptr = nor_flash -> lx_nor_flash_base_address + l * nor_flash -> lx_nor_flash_words_per_block;
|
||||||
|
|
||||||
|
/* Setup the initial erase_count to 1 and mark the block as erased.
|
||||||
|
* When the lx_nor_flash_open() gets called only the erase count will be kept.
|
||||||
|
*/
|
||||||
|
block_word = ((ULONG)1 | LX_BLOCK_ERASED);
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -63,16 +64,6 @@ ULONG _lx_nor_flash_opened_count;
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_initialize(void)
|
UINT _lx_nor_flash_initialize(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -76,22 +77,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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 mapping bitmap cache, */
|
|
||||||
/* added obsolete count cache, */
|
|
||||||
/* optimized full obsoleted */
|
|
||||||
/* block searching logic, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_logical_sector_find(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG superceded_check, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
|
UINT _lx_nor_flash_logical_sector_find(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG superceded_check, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -71,22 +72,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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 mapping bitmap cache, */
|
|
||||||
/* added obsolete count cache, */
|
|
||||||
/* optimized full obsoleted */
|
|
||||||
/* block searching logic, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_next_block_to_erase_find(LX_NOR_FLASH *nor_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_sectors, ULONG *return_obsolete_sectors)
|
UINT _lx_nor_flash_next_block_to_erase_find(LX_NOR_FLASH *nor_flash, ULONG *return_erase_block, ULONG *return_erase_count, ULONG *return_mapped_sectors, ULONG *return_obsolete_sectors)
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-814
@@ -1,5 +1,7 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
|
* Portion Copyright (c) 2025 STMicroelectronics
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -33,8 +35,7 @@
|
|||||||
|
|
||||||
#include "lx_api.h"
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
/* */
|
||||||
/* FUNCTION RELEASE */
|
/* FUNCTION RELEASE */
|
||||||
/* */
|
/* */
|
||||||
@@ -60,16 +61,7 @@
|
|||||||
/* return status */
|
/* return status */
|
||||||
/* */
|
/* */
|
||||||
/* CALLS */
|
/* CALLS */
|
||||||
/* */
|
/* lx_nor_flash_open_extended() */
|
||||||
/* (nor_driver_initialize) Driver initialize */
|
|
||||||
/* _lx_nor_flash_driver_read Driver read */
|
|
||||||
/* _lx_nor_flash_driver_write Driver write */
|
|
||||||
/* (lx_nor_flash_driver_block_erased_verify) */
|
|
||||||
/* NOR flash verify block erased */
|
|
||||||
/* _lx_nor_flash_driver_block_erase Driver block erase */
|
|
||||||
/* _lx_nor_flash_logical_sector_find Find logical sector */
|
|
||||||
/* _lx_nor_flash_system_error System error handler */
|
|
||||||
/* tx_mutex_create Create thread-safe mutex */
|
|
||||||
/* */
|
/* */
|
||||||
/* CALLED BY */
|
/* CALLED BY */
|
||||||
/* */
|
/* */
|
||||||
@@ -102,810 +94,15 @@
|
|||||||
/* extension in flash control */
|
/* extension in flash control */
|
||||||
/* block, */
|
/* block, */
|
||||||
/* resulting in version 6.3.0 */
|
/* resulting in version 6.3.0 */
|
||||||
/* */
|
/* 10-21-2025 Modified comment(s) */
|
||||||
/**************************************************************************/
|
/* call the extended equivalent */
|
||||||
|
/* API */
|
||||||
|
|
||||||
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *))
|
UINT _lx_nor_flash_open(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *))
|
||||||
{
|
{
|
||||||
ULONG sectors_per_block;
|
UINT status = LX_ERROR;
|
||||||
ULONG sector_map_words;
|
|
||||||
ULONG bit_map_words;
|
|
||||||
ULONG bit_map_mask;
|
|
||||||
ULONG total_header_words;
|
|
||||||
ULONG header_sectors;
|
|
||||||
ULONG *block_word_ptr;
|
|
||||||
ULONG block_word;
|
|
||||||
ULONG temp;
|
|
||||||
ULONG free_sectors;
|
|
||||||
ULONG used_sectors;
|
|
||||||
ULONG *new_map_entry;
|
|
||||||
ULONG *new_sector_address;
|
|
||||||
ULONG erased_count, min_erased_count, max_erased_count, temp_erased_count, min_erased_blocks;
|
|
||||||
ULONG j, k, l;
|
|
||||||
UINT status;
|
|
||||||
#ifdef LX_FREE_SECTOR_DATA_VERIFY
|
|
||||||
ULONG *sector_word_ptr;
|
|
||||||
ULONG sector_word;
|
|
||||||
#endif
|
|
||||||
LX_NOR_FLASH *tail_ptr;
|
|
||||||
LX_INTERRUPT_SAVE_AREA
|
|
||||||
|
|
||||||
LX_PARAMETER_NOT_USED(name);
|
status = _lx_nor_flash_open_extended(nor_flash, name, nor_driver_initialize, NULL);
|
||||||
|
|
||||||
/* Clear the NOR flash control block. User extension is not cleared. */
|
return status;
|
||||||
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
|
|
||||||
|
|
||||||
/* Call the flash driver's initialization function. */
|
|
||||||
(nor_driver_initialize)(nor_flash);
|
|
||||||
|
|
||||||
#ifndef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
|
|
||||||
supported. */
|
|
||||||
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_NO_MEMORY);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Setup the offset to the free bit map. */
|
|
||||||
nor_flash -> lx_nor_flash_block_free_bit_map_offset = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG);
|
|
||||||
|
|
||||||
/* Calculate the number of bits we need in the free physical sector bit map. Subtract 1 to account for the
|
|
||||||
flash block header itself. The case where multiple physical sectors are needed for certain sized flash
|
|
||||||
devices is handled below. */
|
|
||||||
sectors_per_block = (nor_flash -> lx_nor_flash_words_per_block / LX_NOR_SECTOR_SIZE) - 1;
|
|
||||||
|
|
||||||
/* Calculate the number of words required for the sector map array. */
|
|
||||||
sector_map_words = sectors_per_block;
|
|
||||||
|
|
||||||
/* Calculate the number of words we need for the free physical sector bit map. */
|
|
||||||
bit_map_words = (sectors_per_block + 31)/ 32;
|
|
||||||
|
|
||||||
/* Save the number of bit map words. */
|
|
||||||
nor_flash -> lx_nor_flash_block_bit_map_words = bit_map_words;
|
|
||||||
|
|
||||||
/* Setup the offset (in words) to the array of physical sector mapping. */
|
|
||||||
nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset = nor_flash -> lx_nor_flash_block_free_bit_map_offset + bit_map_words;
|
|
||||||
|
|
||||||
/* Calculate the total number of words required for the flash block header. */
|
|
||||||
total_header_words = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG) + bit_map_words + sector_map_words;
|
|
||||||
|
|
||||||
/* Determine if more physical sectors are needed, which can happen on large devices. */
|
|
||||||
if (total_header_words <= LX_NOR_SECTOR_SIZE)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Round up to the size of 1 physical sector. */
|
|
||||||
total_header_words = LX_NOR_SECTOR_SIZE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Otherwise calculate how many header sectors are necessary. */
|
|
||||||
header_sectors = (total_header_words-1)/LX_NOR_SECTOR_SIZE;
|
|
||||||
|
|
||||||
/* Round up to the next sector. */
|
|
||||||
header_sectors++;
|
|
||||||
|
|
||||||
/* Compute the total header words, rounding to the next sector. */
|
|
||||||
total_header_words = header_sectors * LX_NOR_SECTOR_SIZE;
|
|
||||||
|
|
||||||
/* Adjust the number of sectors per block. */
|
|
||||||
sectors_per_block = sectors_per_block - (header_sectors - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save the offset to the sector area. */
|
|
||||||
nor_flash -> lx_nor_flash_block_physical_sector_offset = total_header_words;
|
|
||||||
|
|
||||||
/* Save the physical sectors per block and total physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_physical_sectors_per_block = sectors_per_block;
|
|
||||||
nor_flash -> lx_nor_flash_total_physical_sectors = nor_flash -> lx_nor_flash_total_blocks * sectors_per_block;
|
|
||||||
|
|
||||||
/* Build the free bit map mask, for the portion of the bit map that is less than 32 bits. */
|
|
||||||
if ((sectors_per_block % 32) != 0)
|
|
||||||
{
|
|
||||||
bit_map_mask = (ULONG)(1 << (sectors_per_block % 32));
|
|
||||||
bit_map_mask = bit_map_mask - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Exactly 32 sectors for the bit map mask. */
|
|
||||||
bit_map_mask = LX_ALL_ONES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save the free bit map mask in the control block. */
|
|
||||||
nor_flash -> lx_nor_flash_block_bit_map_mask = bit_map_mask;
|
|
||||||
|
|
||||||
/* Setup default values for the max/min erased counts. */
|
|
||||||
min_erased_count = LX_ALL_ONES;
|
|
||||||
min_erased_blocks = 0;
|
|
||||||
max_erased_count = 0;
|
|
||||||
|
|
||||||
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
|
||||||
flash base address. */
|
|
||||||
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
|
||||||
|
|
||||||
/* Loop through the blocks to determine the minimum and maximum erase count. */
|
|
||||||
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Pickup the first word of the block. If the flash manager has executed before, this word contains the
|
|
||||||
erase count for the block. Otherwise, if the word is 0xFFFFFFFF, this flash block was either erased
|
|
||||||
or this is the first time it was used. */
|
|
||||||
#ifdef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Read the word directly. */
|
|
||||||
block_word = *block_word_ptr;
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Is the block erased? */
|
|
||||||
if (((block_word & LX_BLOCK_ERASED) != LX_BLOCK_ERASED) && (block_word != LX_BLOCK_ERASE_STARTED))
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No, valid block. Isolate the erased count. */
|
|
||||||
erased_count = (block_word & LX_BLOCK_ERASE_COUNT_MASK);
|
|
||||||
|
|
||||||
/* Is the erased count the minimum? */
|
|
||||||
if (erased_count == min_erased_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, increment the minimum erased block count. */
|
|
||||||
min_erased_blocks++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this the new minimum? */
|
|
||||||
if (erased_count < min_erased_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, remember the new minimum. */
|
|
||||||
min_erased_count = erased_count;
|
|
||||||
|
|
||||||
/* Reset the minimum erased block count. */
|
|
||||||
min_erased_blocks = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this the new maximum? */
|
|
||||||
if (erased_count > max_erased_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, remember the new maximum. */
|
|
||||||
max_erased_count = erased_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to the next flash block. */
|
|
||||||
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we haven't found any erased counts, we can assume the flash is completely erased and needs to
|
|
||||||
be setup for the first time. */
|
|
||||||
if (min_erased_count == LX_ALL_ONES)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Indicate that this is the initial format. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_initial_format = LX_TRUE;
|
|
||||||
|
|
||||||
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
|
||||||
flash base address. */
|
|
||||||
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
|
||||||
|
|
||||||
/* Loop through the blocks to setup the flash the fist time. */
|
|
||||||
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Setup the free bit map that corresponds to the free physical sectors in this
|
|
||||||
block. Note that we only need to setup the portion of the free bit map that doesn't
|
|
||||||
have sectors associated with it. */
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (bit_map_words-1)) , &bit_map_mask, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup the initial erase count to 1. */
|
|
||||||
block_word = ((ULONG) 1);
|
|
||||||
|
|
||||||
/* Write the initial erase count for the block. */
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the overall minimum and maximum erase count. */
|
|
||||||
nor_flash -> lx_nor_flash_minimum_erase_count = 1;
|
|
||||||
nor_flash -> lx_nor_flash_minimum_erased_blocks = nor_flash -> lx_nor_flash_total_blocks;
|
|
||||||
nor_flash -> lx_nor_flash_maximum_erase_count = 1;
|
|
||||||
|
|
||||||
/* Update the number of free physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
|
|
||||||
|
|
||||||
/* Move to the next flash block. */
|
|
||||||
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* At this point, we have a previously managed flash structure. This needs to be traversed to prepare for the
|
|
||||||
current flash operation. */
|
|
||||||
|
|
||||||
/* Default the flash free sector search to an invalid value. */
|
|
||||||
nor_flash -> lx_nor_flash_free_block_search = nor_flash -> lx_nor_flash_total_blocks;
|
|
||||||
|
|
||||||
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
|
||||||
flash base address. */
|
|
||||||
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
|
||||||
|
|
||||||
/* Loop through the blocks. */
|
|
||||||
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* First, determine if this block has a valid erase count. */
|
|
||||||
#ifdef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Read the word directly. */
|
|
||||||
block_word = *block_word_ptr;
|
|
||||||
#else
|
|
||||||
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Is the block erased? */
|
|
||||||
if (((block_word & LX_BLOCK_ERASED) == LX_BLOCK_ERASED) || (block_word == LX_BLOCK_ERASE_STARTED))
|
|
||||||
{
|
|
||||||
|
|
||||||
/* This can happen if we were previously in the process of erasing the flash block and a
|
|
||||||
power interruption occurs. It should only occur once though. */
|
|
||||||
|
|
||||||
/* Is this the first time? */
|
|
||||||
if (nor_flash -> lx_nor_flash_diagnostic_erased_block)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No, this is a potential format error, since this should only happen once in a given
|
|
||||||
NOR flash format. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the erased block diagnostic. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_erased_block++;
|
|
||||||
|
|
||||||
/* Check to see if the block is erased. */
|
|
||||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
|
||||||
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
|
|
||||||
#else
|
|
||||||
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Is the block completely erased? */
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Is this the first time? */
|
|
||||||
if (nor_flash -> lx_nor_flash_diagnostic_re_erase_block)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No, this is a potential format error, since this should only happen once in a given
|
|
||||||
NOR flash format. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the erased block diagnostic. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_re_erase_block++;
|
|
||||||
|
|
||||||
/* No, the block is not fully erased, erase it again. */
|
|
||||||
status = _lx_nor_flash_driver_block_erase(nor_flash, l, max_erased_count);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup the free bit map that corresponds to the free physical sectors in this
|
|
||||||
block. Note that we only need to setup the portion of the free bit map that doesn't
|
|
||||||
have sectors associated with it. */
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (bit_map_words-1)) , &bit_map_mask, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the initial erase count for the block with upper bit set. */
|
|
||||||
temp_erased_count = (max_erased_count | LX_BLOCK_ERASED);
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erased_count, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the final initial erase count for the block. */
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &max_erased_count, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the number of free physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Calculate the number of free sectors from the free sector bit map. */
|
|
||||||
free_sectors = 0;
|
|
||||||
for (j = 0; j < bit_map_words; j++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Read this word of the free sector bit map. */
|
|
||||||
#ifdef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Read the word directly. */
|
|
||||||
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
|
|
||||||
#else
|
|
||||||
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Count the number of set bits (free sectors). */
|
|
||||||
for (k = 0; k < 32; k++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Is this sector free? */
|
|
||||||
if (block_word & 1)
|
|
||||||
{
|
|
||||||
/* Yes, this sector is free, increment the free sectors count. */
|
|
||||||
free_sectors++;
|
|
||||||
|
|
||||||
/* Determine if we need to update the search pointer. */
|
|
||||||
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Remember the block with free sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_free_block_search = l;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Shift down the free sector. */
|
|
||||||
block_word = block_word >> 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the number of free physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + free_sectors;
|
|
||||||
|
|
||||||
/* We need to now examine the mapping list. */
|
|
||||||
|
|
||||||
/* Calculate how many non-free sectors there are - this includes valid and obsolete sectors. */
|
|
||||||
used_sectors = sectors_per_block - free_sectors;
|
|
||||||
|
|
||||||
/* Now walk the list of logical-physical sector mapping. */
|
|
||||||
for (j = 0; j < sectors_per_block; j++)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Read this word of the sector mapping list. */
|
|
||||||
#ifdef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Read the word directly. */
|
|
||||||
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j);
|
|
||||||
#else
|
|
||||||
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if we are expecting to find a used sector. */
|
|
||||||
if (used_sectors)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, we expect this entry to be used. */
|
|
||||||
|
|
||||||
/* Is this sector in-use? */
|
|
||||||
if ((block_word & LX_NOR_LOGICAL_SECTOR_MASK) != LX_NOR_LOGICAL_SECTOR_MASK)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Determine if the valid bit is set and the superceded bit is clear. This indicates the block was
|
|
||||||
about to become obsolete. */
|
|
||||||
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) && ((block_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) == 0))
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/* Increment the being obsoleted count. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_sector_being_obsoleted++;
|
|
||||||
|
|
||||||
/* Save the currently mapped physical sectors. */
|
|
||||||
temp = nor_flash -> lx_nor_flash_mapped_physical_sectors;
|
|
||||||
|
|
||||||
/* Indicate all the physical sectors are mapped for the purpose of this search. */
|
|
||||||
nor_flash -> lx_nor_flash_mapped_physical_sectors = nor_flash -> lx_nor_flash_total_physical_sectors;
|
|
||||||
|
|
||||||
/* Yes, this block was about to become obsolete. Perform a search for a logical sector entry that
|
|
||||||
has both of these bits set. */
|
|
||||||
_lx_nor_flash_logical_sector_find(nor_flash, (block_word & LX_NOR_LOGICAL_SECTOR_MASK), LX_TRUE, &new_map_entry, &new_sector_address);
|
|
||||||
|
|
||||||
/* Restore the number of mapped physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_mapped_physical_sectors = temp;
|
|
||||||
|
|
||||||
/* Determine if the new logical sector entry is present. */
|
|
||||||
if (new_map_entry)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, make the current entry obsolete in favor of the new entry. */
|
|
||||||
block_word = block_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this the first time? */
|
|
||||||
if (nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No, this is a potential format error, since this should only happen once in a given
|
|
||||||
NOR flash format. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the obsoleted count. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine if the sector is free. */
|
|
||||||
else if (block_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* A free entry when there are still used sectors implies that the sector was allocated and a power interruption
|
|
||||||
took place prior to writing the new logical sector number into the list. */
|
|
||||||
|
|
||||||
/* Is this the first time? */
|
|
||||||
if (nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No, this is a potential format error, since this should only happen once in a given
|
|
||||||
NOR flash format. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write 0s out to this entry to invalidate the sector entry. */
|
|
||||||
block_word = 0;
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the number of mapping invalidates. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Yes, now determine if the sector is obsolete. */
|
|
||||||
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Increment the number of obsolete sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine if the mapping for this sector isn't yet valid. */
|
|
||||||
else if (block_word & LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Yes, a power interruption or reset occurred while the sector mapping entry was being written. */
|
|
||||||
|
|
||||||
/* Increment the number of obsolete sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
|
||||||
|
|
||||||
/* Increment the interrupted mapping counter. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_mapping_write_interrupted++;
|
|
||||||
|
|
||||||
/* Invalidate this entry - clearing valid bit, superceded bit and logical sector. */
|
|
||||||
block_word = 0;
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Increment the number of mapped physical sectors. */
|
|
||||||
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Decrease the number of used sectors. */
|
|
||||||
used_sectors--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* No more used sectors in this flash block. */
|
|
||||||
|
|
||||||
/* In this case the entry must be free or there is a serious NOR flash format error present. */
|
|
||||||
if (block_word != LX_NOR_PHYSICAL_SECTOR_FREE)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Increment the sector not free diagnostic. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_sector_not_free++;
|
|
||||||
|
|
||||||
/* NOR flash format. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
|
||||||
|
|
||||||
/* Write 0s out to this entry to invalidate the sector entry. */
|
|
||||||
block_word = 0;
|
|
||||||
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LX_FREE_SECTOR_DATA_VERIFY
|
|
||||||
|
|
||||||
/* Pickup address of the free sector data area. */
|
|
||||||
sector_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (j * LX_NOR_SECTOR_SIZE);
|
|
||||||
|
|
||||||
/* Determine if the data for this sector is free. */
|
|
||||||
for (k = 0; k < LX_NOR_SECTOR_SIZE; k++)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef LX_DIRECT_READ
|
|
||||||
|
|
||||||
/* Read the word directly. */
|
|
||||||
sector_word = *(sector_word_ptr);
|
|
||||||
#else
|
|
||||||
status = _lx_nor_flash_driver_read(nor_flash, (sector_word_ptr), §or_word, 1);
|
|
||||||
|
|
||||||
/* Check for an error from flash driver. Drivers should never return an error.. */
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, status);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determine if this word is not available. */
|
|
||||||
if (sector_word != LX_NOR_PHYSICAL_SECTOR_FREE)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Increment the sector data not free diagnostic. */
|
|
||||||
nor_flash -> lx_nor_flash_diagnostic_sector_data_not_free++;
|
|
||||||
|
|
||||||
/* This is a format error. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
|
||||||
|
|
||||||
/* Return an error. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to the next word in the sector. */
|
|
||||||
sector_word_ptr++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move to the next flash block. */
|
|
||||||
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the overall minimum and maximum erase count. */
|
|
||||||
nor_flash -> lx_nor_flash_minimum_erase_count = min_erased_count;
|
|
||||||
nor_flash -> lx_nor_flash_minimum_erased_blocks = min_erased_blocks;
|
|
||||||
nor_flash -> lx_nor_flash_maximum_erase_count = max_erased_count;
|
|
||||||
|
|
||||||
/* Determine if we need to update the free sector search pointer. */
|
|
||||||
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Just start at the beginning. */
|
|
||||||
nor_flash -> lx_nor_flash_free_block_search = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LX_THREAD_SAFE_ENABLE
|
|
||||||
|
|
||||||
/* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs
|
|
||||||
in order to provide thread-safe operation. */
|
|
||||||
status = tx_mutex_create(&nor_flash -> lx_nor_flash_mutex, "NOR Flash Mutex", TX_NO_INHERIT);
|
|
||||||
|
|
||||||
/* Determine if the mutex creation encountered an error. */
|
|
||||||
if (status != LX_SUCCESS)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Call system error handler, since this should not happen. */
|
|
||||||
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_MUTEX_CREATE_FAILED);
|
|
||||||
|
|
||||||
/* Return error to caller. */
|
|
||||||
return(LX_ERROR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Enable the sector mapping cache. */
|
|
||||||
nor_flash -> lx_nor_flash_sector_mapping_cache_enabled = LX_TRUE;
|
|
||||||
|
|
||||||
/* Initialize the last found block and sector markers. */
|
|
||||||
nor_flash -> lx_nor_flash_found_block_search = 0;
|
|
||||||
nor_flash -> lx_nor_flash_found_sector_search = 0;
|
|
||||||
|
|
||||||
/* Lockout interrupts. */
|
|
||||||
LX_DISABLE
|
|
||||||
|
|
||||||
/* At this point, the NOR flash has been opened successfully. Place the
|
|
||||||
NOR flash control block on the linked list of currently opened NOR flashes. */
|
|
||||||
|
|
||||||
/* Set the NOR flash state to open. */
|
|
||||||
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_OPENED;
|
|
||||||
|
|
||||||
/* Place the NOR flash control block on the list of opened NOR flashes. First,
|
|
||||||
check for an empty list. */
|
|
||||||
if (_lx_nor_flash_opened_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* List is not empty - other NOR flashes are open. */
|
|
||||||
|
|
||||||
/* Pickup tail pointer. */
|
|
||||||
tail_ptr = _lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous;
|
|
||||||
|
|
||||||
/* Place the new NOR flash control block in the list. */
|
|
||||||
_lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous = nor_flash;
|
|
||||||
tail_ptr -> lx_nor_flash_open_next = nor_flash;
|
|
||||||
|
|
||||||
/* Setup this NOR flash's opened links. */
|
|
||||||
nor_flash -> lx_nor_flash_open_previous = tail_ptr;
|
|
||||||
nor_flash -> lx_nor_flash_open_next = _lx_nor_flash_opened_ptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* The opened NOR flash list is empty. Add the NOR flash to empty list. */
|
|
||||||
_lx_nor_flash_opened_ptr = nor_flash;
|
|
||||||
nor_flash -> lx_nor_flash_open_next = nor_flash;
|
|
||||||
nor_flash -> lx_nor_flash_open_previous = nor_flash;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the opened NOR flash counter. */
|
|
||||||
_lx_nor_flash_opened_count++;
|
|
||||||
|
|
||||||
/* Restore interrupts. */
|
|
||||||
LX_RESTORE
|
|
||||||
|
|
||||||
/* Return a successful completion. */
|
|
||||||
return(LX_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,886 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2025 Microsoft Corporation
|
||||||
|
* Portion Copyright (c) 2025 STMicroelectronics
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the MIT License which is available at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
/** */
|
||||||
|
/** LevelX Component */
|
||||||
|
/** */
|
||||||
|
/** NOR Flash */
|
||||||
|
/** */
|
||||||
|
/**************************************************************************/
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#define LX_SOURCE_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Disable ThreadX error checking. */
|
||||||
|
|
||||||
|
#ifndef LX_DISABLE_ERROR_CHECKING
|
||||||
|
#define LX_DISABLE_ERROR_CHECKING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Include necessary system files. */
|
||||||
|
|
||||||
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nor_flash_open_extended PORTABLE C */
|
||||||
|
/* 6.3.0 */
|
||||||
|
/* AUTHOR */
|
||||||
|
/* */
|
||||||
|
/* William E. Lamie, Microsoft Corporation */
|
||||||
|
/* */
|
||||||
|
/* DESCRIPTION */
|
||||||
|
/* */
|
||||||
|
/* This function opens a NOR flash instance and ensures the NOR flash */
|
||||||
|
/* is in a coherent state. */
|
||||||
|
/* */
|
||||||
|
/* INPUT */
|
||||||
|
/* */
|
||||||
|
/* nor_flash NOR flash instance */
|
||||||
|
/* name Name of NOR flash instance */
|
||||||
|
/* nor_driver_initialize Driver initialize */
|
||||||
|
/* nor_driver_info_ptr Driver user data pointer */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* return status */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* */
|
||||||
|
/* (nor_driver_initialize) Driver initialize */
|
||||||
|
/* _lx_nor_flash_driver_read Driver read */
|
||||||
|
/* _lx_nor_flash_driver_write Driver write */
|
||||||
|
/* (lx_nor_flash_driver_block_erased_verify) */
|
||||||
|
/* NOR flash verify block erased */
|
||||||
|
/* _lx_nor_flash_driver_block_erase Driver block erase */
|
||||||
|
/* _lx_nor_flash_logical_sector_find Find logical sector */
|
||||||
|
/* _lx_nor_flash_system_error System error handler */
|
||||||
|
/* tx_mutex_create Create thread-safe mutex */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* Application Code */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
UINT _lx_nor_flash_open_extended(LX_NOR_FLASH *nor_flash, CHAR *name, UINT (*nor_driver_initialize)(LX_NOR_FLASH *), VOID *nor_driver_info_ptr)
|
||||||
|
{
|
||||||
|
ULONG sectors_per_block;
|
||||||
|
ULONG sector_map_words;
|
||||||
|
ULONG bit_map_words;
|
||||||
|
ULONG bit_map_mask;
|
||||||
|
ULONG total_header_words;
|
||||||
|
ULONG header_sectors;
|
||||||
|
ULONG *block_word_ptr;
|
||||||
|
ULONG block_word;
|
||||||
|
ULONG temp;
|
||||||
|
ULONG free_sectors;
|
||||||
|
ULONG used_sectors;
|
||||||
|
ULONG *new_map_entry;
|
||||||
|
ULONG *new_sector_address;
|
||||||
|
ULONG erased_count, min_erased_count, max_erased_count, temp_erased_count, min_erased_blocks;
|
||||||
|
ULONG j, k, l;
|
||||||
|
UINT status;
|
||||||
|
#ifdef LX_FREE_SECTOR_DATA_VERIFY
|
||||||
|
ULONG *sector_word_ptr;
|
||||||
|
ULONG sector_word;
|
||||||
|
#endif
|
||||||
|
LX_NOR_FLASH *tail_ptr;
|
||||||
|
LX_INTERRUPT_SAVE_AREA
|
||||||
|
|
||||||
|
LX_PARAMETER_NOT_USED(name);
|
||||||
|
|
||||||
|
/* Clear the NOR flash control block. User extension is not cleared. */
|
||||||
|
LX_MEMSET(nor_flash, 0, (ULONG)((UCHAR*)&(nor_flash -> lx_nor_flash_open_previous) - (UCHAR*)nor_flash) + sizeof(nor_flash -> lx_nor_flash_open_previous));
|
||||||
|
|
||||||
|
/* Pass the driver info ptr */
|
||||||
|
nor_flash -> lx_nor_flash_driver_info_ptr = nor_driver_info_ptr;
|
||||||
|
|
||||||
|
/* Call the flash driver's initialization function. */
|
||||||
|
(nor_driver_initialize)(nor_flash);
|
||||||
|
|
||||||
|
#ifndef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Determine if the driver supplied a RAM buffer for reading the NOR sector if direct read is not
|
||||||
|
supported. */
|
||||||
|
if (nor_flash -> lx_nor_flash_sector_buffer == LX_NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_NO_MEMORY);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup the offset to the free bit map. */
|
||||||
|
nor_flash -> lx_nor_flash_block_free_bit_map_offset = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG);
|
||||||
|
|
||||||
|
/* Calculate the number of bits we need in the free physical sector bit map. Subtract 1 to account for the
|
||||||
|
flash block header itself. The case where multiple physical sectors are needed for certain sized flash
|
||||||
|
devices is handled below. */
|
||||||
|
sectors_per_block = (nor_flash -> lx_nor_flash_words_per_block / LX_NOR_SECTOR_SIZE) - 1;
|
||||||
|
|
||||||
|
/* Calculate the number of words required for the sector map array. */
|
||||||
|
sector_map_words = sectors_per_block;
|
||||||
|
|
||||||
|
/* Calculate the number of words we need for the free physical sector bit map. */
|
||||||
|
bit_map_words = (sectors_per_block + 31)/ 32;
|
||||||
|
|
||||||
|
/* Save the number of bit map words. */
|
||||||
|
nor_flash -> lx_nor_flash_block_bit_map_words = bit_map_words;
|
||||||
|
|
||||||
|
/* Setup the offset (in words) to the array of physical sector mapping. */
|
||||||
|
nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset = nor_flash -> lx_nor_flash_block_free_bit_map_offset + bit_map_words;
|
||||||
|
|
||||||
|
/* Calculate the total number of words required for the flash block header. */
|
||||||
|
total_header_words = sizeof(LX_NOR_FLASH_BLOCK_HEADER)/sizeof(ULONG) + bit_map_words + sector_map_words;
|
||||||
|
|
||||||
|
/* Determine if more physical sectors are needed, which can happen on large devices. */
|
||||||
|
if (total_header_words <= LX_NOR_SECTOR_SIZE)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Round up to the size of 1 physical sector. */
|
||||||
|
total_header_words = LX_NOR_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Otherwise calculate how many header sectors are necessary. */
|
||||||
|
header_sectors = (total_header_words-1)/LX_NOR_SECTOR_SIZE;
|
||||||
|
|
||||||
|
/* Round up to the next sector. */
|
||||||
|
header_sectors++;
|
||||||
|
|
||||||
|
/* Compute the total header words, rounding to the next sector. */
|
||||||
|
total_header_words = header_sectors * LX_NOR_SECTOR_SIZE;
|
||||||
|
|
||||||
|
/* Adjust the number of sectors per block. */
|
||||||
|
sectors_per_block = sectors_per_block - (header_sectors - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the offset to the sector area. */
|
||||||
|
nor_flash -> lx_nor_flash_block_physical_sector_offset = total_header_words;
|
||||||
|
|
||||||
|
/* Save the physical sectors per block and total physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_physical_sectors_per_block = sectors_per_block;
|
||||||
|
nor_flash -> lx_nor_flash_total_physical_sectors = nor_flash -> lx_nor_flash_total_blocks * sectors_per_block;
|
||||||
|
|
||||||
|
/* Build the free bit map mask, for the portion of the bit map that is less than 32 bits. */
|
||||||
|
if ((sectors_per_block % 32) != 0)
|
||||||
|
{
|
||||||
|
bit_map_mask = (ULONG)(1 << (sectors_per_block % 32));
|
||||||
|
bit_map_mask = bit_map_mask - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Exactly 32 sectors for the bit map mask. */
|
||||||
|
bit_map_mask = LX_ALL_ONES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the free bit map mask in the control block. */
|
||||||
|
nor_flash -> lx_nor_flash_block_bit_map_mask = bit_map_mask;
|
||||||
|
|
||||||
|
/* Setup default values for the max/min erased counts. */
|
||||||
|
min_erased_count = LX_ALL_ONES;
|
||||||
|
min_erased_blocks = 0;
|
||||||
|
max_erased_count = 0;
|
||||||
|
|
||||||
|
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
||||||
|
flash base address. */
|
||||||
|
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
||||||
|
|
||||||
|
/* Loop through the blocks to determine the minimum and maximum erase count. */
|
||||||
|
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Pickup the first word of the block. If the flash manager has executed before, this word contains the
|
||||||
|
erase count for the block. Otherwise, if the word is 0xFFFFFFFF, this flash block was either erased
|
||||||
|
or this is the first time it was used. */
|
||||||
|
#ifdef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Read the word directly. */
|
||||||
|
block_word = *block_word_ptr;
|
||||||
|
#else
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is the block erased? */
|
||||||
|
if (((block_word & LX_BLOCK_ERASED) != LX_BLOCK_ERASED) && (block_word != LX_BLOCK_ERASE_STARTED))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No, valid block. Isolate the erased count. */
|
||||||
|
erased_count = (block_word & LX_BLOCK_ERASE_COUNT_MASK);
|
||||||
|
|
||||||
|
/* Is the erased count the minimum? */
|
||||||
|
if (erased_count == min_erased_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, increment the minimum erased block count. */
|
||||||
|
min_erased_blocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this the new minimum? */
|
||||||
|
if (erased_count < min_erased_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, remember the new minimum. */
|
||||||
|
min_erased_count = erased_count;
|
||||||
|
|
||||||
|
/* Reset the minimum erased block count. */
|
||||||
|
min_erased_blocks = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this the new maximum? */
|
||||||
|
if (erased_count > max_erased_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, remember the new maximum. */
|
||||||
|
max_erased_count = erased_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move to the next flash block. */
|
||||||
|
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we haven't found any erased counts, we can assume the flash is completely erased and needs to
|
||||||
|
be setup for the first time. */
|
||||||
|
if (min_erased_count == LX_ALL_ONES)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Indicate that this is the initial format. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_initial_format = LX_TRUE;
|
||||||
|
|
||||||
|
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
||||||
|
flash base address. */
|
||||||
|
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
||||||
|
|
||||||
|
/* Loop through the blocks to setup the flash the fist time. */
|
||||||
|
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Setup the free bit map that corresponds to the free physical sectors in this
|
||||||
|
block. Note that we only need to setup the portion of the free bit map that doesn't
|
||||||
|
have sectors associated with it. */
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (bit_map_words-1)) , &bit_map_mask, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup the initial erase count to 1. */
|
||||||
|
block_word = ((ULONG) 1);
|
||||||
|
|
||||||
|
/* Write the initial erase count for the block. */
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the overall minimum and maximum erase count. */
|
||||||
|
nor_flash -> lx_nor_flash_minimum_erase_count = 1;
|
||||||
|
nor_flash -> lx_nor_flash_minimum_erased_blocks = nor_flash -> lx_nor_flash_total_blocks;
|
||||||
|
nor_flash -> lx_nor_flash_maximum_erase_count = 1;
|
||||||
|
|
||||||
|
/* Update the number of free physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
|
||||||
|
|
||||||
|
/* Move to the next flash block. */
|
||||||
|
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* At this point, we have a previously managed flash structure. This needs to be traversed to prepare for the
|
||||||
|
current flash operation. */
|
||||||
|
|
||||||
|
/* Default the flash free sector search to an invalid value. */
|
||||||
|
nor_flash -> lx_nor_flash_free_block_search = nor_flash -> lx_nor_flash_total_blocks;
|
||||||
|
|
||||||
|
/* Setup the block word pointer to the first word of the first block, which is effectively the
|
||||||
|
flash base address. */
|
||||||
|
block_word_ptr = nor_flash -> lx_nor_flash_base_address;
|
||||||
|
|
||||||
|
/* Loop through the blocks. */
|
||||||
|
for (l = 0; l < nor_flash -> lx_nor_flash_total_blocks; l++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* First, determine if this block has a valid erase count. */
|
||||||
|
#ifdef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Read the word directly. */
|
||||||
|
block_word = *block_word_ptr;
|
||||||
|
#else
|
||||||
|
status = _lx_nor_flash_driver_read(nor_flash, block_word_ptr, &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is the block erased? */
|
||||||
|
if (((block_word & LX_BLOCK_ERASED) == LX_BLOCK_ERASED) || (block_word == LX_BLOCK_ERASE_STARTED))
|
||||||
|
{
|
||||||
|
|
||||||
|
/* This can happen if we were previously in the process of erasing the flash block and a
|
||||||
|
power interruption occurs. It should only occur once though. */
|
||||||
|
|
||||||
|
/* Is this the first time? */
|
||||||
|
if (nor_flash -> lx_nor_flash_diagnostic_erased_block)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No, this is a potential format error, since this should only happen once in a given
|
||||||
|
NOR flash format. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the erased block diagnostic. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_erased_block++;
|
||||||
|
|
||||||
|
/* Check to see if the block is erased. */
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(nor_flash, l);
|
||||||
|
#else
|
||||||
|
status = (nor_flash -> lx_nor_flash_driver_block_erased_verify)(l);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is the block completely erased? */
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Is this the first time? */
|
||||||
|
if (nor_flash -> lx_nor_flash_diagnostic_re_erase_block)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No, this is a potential format error, since this should only happen once in a given
|
||||||
|
NOR flash format. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the erased block diagnostic. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_re_erase_block++;
|
||||||
|
|
||||||
|
/* No, the block is not fully erased, erase it again. */
|
||||||
|
status = _lx_nor_flash_driver_block_erase(nor_flash, l, max_erased_count);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup the free bit map that corresponds to the free physical sectors in this
|
||||||
|
block. Note that we only need to setup the portion of the free bit map that doesn't
|
||||||
|
have sectors associated with it. */
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (bit_map_words-1)) , &bit_map_mask, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write the initial erase count for the block with upper bit set. */
|
||||||
|
temp_erased_count = (max_erased_count | LX_BLOCK_ERASED);
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erased_count, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write the final initial erase count for the block. */
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &max_erased_count, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the number of free physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + sectors_per_block;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Calculate the number of free sectors from the free sector bit map. */
|
||||||
|
free_sectors = 0;
|
||||||
|
for (j = 0; j < bit_map_words; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Read this word of the free sector bit map. */
|
||||||
|
#ifdef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Read the word directly. */
|
||||||
|
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j);
|
||||||
|
#else
|
||||||
|
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_free_bit_map_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Count the number of set bits (free sectors). */
|
||||||
|
for (k = 0; k < 32; k++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Is this sector free? */
|
||||||
|
if (block_word & 1)
|
||||||
|
{
|
||||||
|
/* Yes, this sector is free, increment the free sectors count. */
|
||||||
|
free_sectors++;
|
||||||
|
|
||||||
|
/* Determine if we need to update the search pointer. */
|
||||||
|
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Remember the block with free sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_free_block_search = l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Shift down the free sector. */
|
||||||
|
block_word = block_word >> 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the number of free physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + free_sectors;
|
||||||
|
|
||||||
|
/* We need to now examine the mapping list. */
|
||||||
|
|
||||||
|
/* Calculate how many non-free sectors there are - this includes valid and obsolete sectors. */
|
||||||
|
used_sectors = sectors_per_block - free_sectors;
|
||||||
|
|
||||||
|
/* Now walk the list of logical-physical sector mapping. */
|
||||||
|
for (j = 0; j < sectors_per_block; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Read this word of the sector mapping list. */
|
||||||
|
#ifdef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Read the word directly. */
|
||||||
|
block_word = *(block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j);
|
||||||
|
#else
|
||||||
|
status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Determine if we are expecting to find a used sector. */
|
||||||
|
if (used_sectors)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, we expect this entry to be used. */
|
||||||
|
|
||||||
|
/* Is this sector in-use? */
|
||||||
|
if ((block_word & LX_NOR_LOGICAL_SECTOR_MASK) != LX_NOR_LOGICAL_SECTOR_MASK)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Determine if the valid bit is set and the superceded bit is clear. This indicates the block was
|
||||||
|
about to become obsolete. */
|
||||||
|
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) && ((block_word & LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) == 0))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/* Increment the being obsoleted count. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_sector_being_obsoleted++;
|
||||||
|
|
||||||
|
/* Save the currently mapped physical sectors. */
|
||||||
|
temp = nor_flash -> lx_nor_flash_mapped_physical_sectors;
|
||||||
|
|
||||||
|
/* Indicate all the physical sectors are mapped for the purpose of this search. */
|
||||||
|
nor_flash -> lx_nor_flash_mapped_physical_sectors = nor_flash -> lx_nor_flash_total_physical_sectors;
|
||||||
|
|
||||||
|
/* Yes, this block was about to become obsolete. Perform a search for a logical sector entry that
|
||||||
|
has both of these bits set. */
|
||||||
|
_lx_nor_flash_logical_sector_find(nor_flash, (block_word & LX_NOR_LOGICAL_SECTOR_MASK), LX_TRUE, &new_map_entry, &new_sector_address);
|
||||||
|
|
||||||
|
/* Restore the number of mapped physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_mapped_physical_sectors = temp;
|
||||||
|
|
||||||
|
/* Determine if the new logical sector entry is present. */
|
||||||
|
if (new_map_entry)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, make the current entry obsolete in favor of the new entry. */
|
||||||
|
block_word = block_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID);
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is this the first time? */
|
||||||
|
if (nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No, this is a potential format error, since this should only happen once in a given
|
||||||
|
NOR flash format. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the obsoleted count. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_sector_obsoleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if the sector is free. */
|
||||||
|
else if (block_word == LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* A free entry when there are still used sectors implies that the sector was allocated and a power interruption
|
||||||
|
took place prior to writing the new logical sector number into the list. */
|
||||||
|
|
||||||
|
/* Is this the first time? */
|
||||||
|
if (nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No, this is a potential format error, since this should only happen once in a given
|
||||||
|
NOR flash format. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write 0s out to this entry to invalidate the sector entry. */
|
||||||
|
block_word = 0;
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the number of mapping invalidates. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_mapping_invalidated++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Yes, now determine if the sector is obsolete. */
|
||||||
|
if ((block_word & LX_NOR_PHYSICAL_SECTOR_VALID) == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Increment the number of obsolete sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if the mapping for this sector isn't yet valid. */
|
||||||
|
else if (block_word & LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Yes, a power interruption or reset occurred while the sector mapping entry was being written. */
|
||||||
|
|
||||||
|
/* Increment the number of obsolete sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_obsolete_physical_sectors++;
|
||||||
|
|
||||||
|
/* Increment the interrupted mapping counter. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_mapping_write_interrupted++;
|
||||||
|
|
||||||
|
/* Invalidate this entry - clearing valid bit, superceded bit and logical sector. */
|
||||||
|
block_word = 0;
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Increment the number of mapped physical sectors. */
|
||||||
|
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrease the number of used sectors. */
|
||||||
|
used_sectors--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* No more used sectors in this flash block. */
|
||||||
|
|
||||||
|
/* In this case the entry must be free or there is a serious NOR flash format error present. */
|
||||||
|
if (block_word != LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Increment the sector not free diagnostic. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_sector_not_free++;
|
||||||
|
|
||||||
|
/* NOR flash format. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_FORMAT);
|
||||||
|
|
||||||
|
/* Write 0s out to this entry to invalidate the sector entry. */
|
||||||
|
block_word = 0;
|
||||||
|
status = _lx_nor_flash_driver_write(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset + j), &block_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_FREE_SECTOR_DATA_VERIFY
|
||||||
|
|
||||||
|
/* Pickup address of the free sector data area. */
|
||||||
|
sector_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_block_physical_sector_offset) + (j * LX_NOR_SECTOR_SIZE);
|
||||||
|
|
||||||
|
/* Determine if the data for this sector is free. */
|
||||||
|
for (k = 0; k < LX_NOR_SECTOR_SIZE; k++)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef LX_DIRECT_READ
|
||||||
|
|
||||||
|
/* Read the word directly. */
|
||||||
|
sector_word = *(sector_word_ptr);
|
||||||
|
#else
|
||||||
|
status = _lx_nor_flash_driver_read(nor_flash, (sector_word_ptr), §or_word, 1);
|
||||||
|
|
||||||
|
/* Check for an error from flash driver. Drivers should never return an error.. */
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, status);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Determine if this word is not available. */
|
||||||
|
if (sector_word != LX_NOR_PHYSICAL_SECTOR_FREE)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Increment the sector data not free diagnostic. */
|
||||||
|
nor_flash -> lx_nor_flash_diagnostic_sector_data_not_free++;
|
||||||
|
|
||||||
|
/* This is a format error. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_INVALID_BLOCK);
|
||||||
|
|
||||||
|
/* Return an error. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move to the next word in the sector. */
|
||||||
|
sector_word_ptr++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move to the next flash block. */
|
||||||
|
block_word_ptr = block_word_ptr + (nor_flash -> lx_nor_flash_words_per_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the overall minimum and maximum erase count. */
|
||||||
|
nor_flash -> lx_nor_flash_minimum_erase_count = min_erased_count;
|
||||||
|
nor_flash -> lx_nor_flash_minimum_erased_blocks = min_erased_blocks;
|
||||||
|
nor_flash -> lx_nor_flash_maximum_erase_count = max_erased_count;
|
||||||
|
|
||||||
|
/* Determine if we need to update the free sector search pointer. */
|
||||||
|
if (nor_flash -> lx_nor_flash_free_block_search == nor_flash -> lx_nor_flash_total_blocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Just start at the beginning. */
|
||||||
|
nor_flash -> lx_nor_flash_free_block_search = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_THREAD_SAFE_ENABLE
|
||||||
|
|
||||||
|
/* If the thread safe option is enabled, create a ThreadX mutex that will be used in all external APIs
|
||||||
|
in order to provide thread-safe operation. */
|
||||||
|
status = tx_mutex_create(&nor_flash -> lx_nor_flash_mutex, "NOR Flash Mutex", TX_NO_INHERIT);
|
||||||
|
|
||||||
|
/* Determine if the mutex creation encountered an error. */
|
||||||
|
if (status != LX_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Call system error handler, since this should not happen. */
|
||||||
|
_lx_nor_flash_system_error(nor_flash, LX_SYSTEM_MUTEX_CREATE_FAILED);
|
||||||
|
|
||||||
|
/* Return error to caller. */
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable the sector mapping cache. */
|
||||||
|
nor_flash -> lx_nor_flash_sector_mapping_cache_enabled = LX_TRUE;
|
||||||
|
|
||||||
|
/* Initialize the last found block and sector markers. */
|
||||||
|
nor_flash -> lx_nor_flash_found_block_search = 0;
|
||||||
|
nor_flash -> lx_nor_flash_found_sector_search = 0;
|
||||||
|
|
||||||
|
/* Lockout interrupts. */
|
||||||
|
LX_DISABLE
|
||||||
|
|
||||||
|
/* At this point, the NOR flash has been opened successfully. Place the
|
||||||
|
NOR flash control block on the linked list of currently opened NOR flashes. */
|
||||||
|
|
||||||
|
/* Set the NOR flash state to open. */
|
||||||
|
nor_flash -> lx_nor_flash_state = LX_NOR_FLASH_OPENED;
|
||||||
|
|
||||||
|
/* Place the NOR flash control block on the list of opened NOR flashes. First,
|
||||||
|
check for an empty list. */
|
||||||
|
if (_lx_nor_flash_opened_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* List is not empty - other NOR flashes are open. */
|
||||||
|
|
||||||
|
/* Pickup tail pointer. */
|
||||||
|
tail_ptr = _lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous;
|
||||||
|
|
||||||
|
/* Place the new NOR flash control block in the list. */
|
||||||
|
_lx_nor_flash_opened_ptr -> lx_nor_flash_open_previous = nor_flash;
|
||||||
|
tail_ptr -> lx_nor_flash_open_next = nor_flash;
|
||||||
|
|
||||||
|
/* Setup this NOR flash's opened links. */
|
||||||
|
nor_flash -> lx_nor_flash_open_previous = tail_ptr;
|
||||||
|
nor_flash -> lx_nor_flash_open_next = _lx_nor_flash_opened_ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* The opened NOR flash list is empty. Add the NOR flash to empty list. */
|
||||||
|
_lx_nor_flash_opened_ptr = nor_flash;
|
||||||
|
nor_flash -> lx_nor_flash_open_next = nor_flash;
|
||||||
|
nor_flash -> lx_nor_flash_open_previous = nor_flash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the opened NOR flash counter. */
|
||||||
|
_lx_nor_flash_opened_count++;
|
||||||
|
|
||||||
|
/* Restore interrupts. */
|
||||||
|
LX_RESTORE
|
||||||
|
|
||||||
|
/* Return a successful completion. */
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -70,16 +71,6 @@
|
|||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks)
|
UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -70,16 +71,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
|
UINT _lx_nor_flash_physical_sector_allocate(LX_NOR_FLASH *nor_flash, ULONG logical_sector, ULONG **physical_sector_map_entry, ULONG **physical_sector_address)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -66,16 +67,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -74,19 +75,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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 mapping bitmap cache, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -74,20 +75,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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 mapping bitmap cache, */
|
|
||||||
/* added obsolete count cache, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
UINT _lx_nor_flash_sector_release(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -77,20 +78,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Application Code */
|
/* Application Code */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* 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 mapping bitmap cache, */
|
|
||||||
/* added obsolete count cache, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
UINT _lx_nor_flash_sector_write(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (c) 2024 Microsoft Corporation
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials are made available under the
|
* This program and the accompanying materials are made available under the
|
||||||
* terms of the MIT License which is available at
|
* terms of the MIT License which is available at
|
||||||
@@ -65,19 +66,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/* Internal LevelX */
|
/* Internal LevelX */
|
||||||
/* */
|
/* */
|
||||||
/* RELEASE HISTORY */
|
|
||||||
/* */
|
|
||||||
/* DATE NAME DESCRIPTION */
|
|
||||||
/* */
|
|
||||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
|
||||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* resulting in version 6.1 */
|
|
||||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
|
||||||
/* resulting in version 6.1.7 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
|
VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
||||||
and the NAND simulated driver. */
|
and the NAND simulated driver. */
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
/* This is a small demo of the high-performance FileX FAT file system with LevelX
|
||||||
and the NOR simulated driver. */
|
and the NOR simulated driver. */
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 Eclipse ThreadX contributors
|
||||||
|
#
|
||||||
|
# This program and the accompanying materials are made available under the
|
||||||
|
# terms of the MIT License which is available at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
$(dirname `realpath $0`)/../test/cmake/run.sh build all
|
$(dirname `realpath $0`)/../test/cmake/run.sh build all
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 Eclipse ThreadX contributors
|
||||||
|
#
|
||||||
|
# This program and the accompanying materials are made available under the
|
||||||
|
# terms of the MIT License which is available at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# Remove large folder
|
# Remove large folder
|
||||||
|
|||||||
Executable
+132
@@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# prepare_release.sh
|
||||||
|
# Prepares a LevelX release by updating version constants.
|
||||||
|
#
|
||||||
|
# Usage: prepare_release.sh <version>
|
||||||
|
# Example: prepare_release.sh 6.5.1.202602
|
||||||
|
# Hotfix: prepare_release.sh 6.5.1.202602a
|
||||||
|
#
|
||||||
|
# This script:
|
||||||
|
# 1. Creates branch release-<version>-preparation from dev
|
||||||
|
# 2. Updates version constants in common/inc/lx_api.h
|
||||||
|
# (commit: "Updated version number constants")
|
||||||
|
# (No port-specific version strings in this repository)
|
||||||
|
#
|
||||||
|
# Copyright (C) 2026 Eclipse ThreadX contributors
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||||
|
|
||||||
|
API_HEADER="${REPO_ROOT}/common/inc/lx_api.h"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Argument validation
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
printf "Usage: %s <version>\n" "$(basename "$0")" >&2
|
||||||
|
printf "Example: %s 6.5.1.202602\n" "$(basename "$0")" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION="$1"
|
||||||
|
|
||||||
|
if ! printf "%s" "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[a-z]?$'; then
|
||||||
|
printf "Error: Invalid version format '%s'.\n" "${VERSION}" >&2
|
||||||
|
printf "Expected: MAJOR.MINOR.PATCH.BUILD[hotfix_letter]\n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Parse version components
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
MAJOR=$(printf "%s" "${VERSION}" | cut -d. -f1)
|
||||||
|
MINOR=$(printf "%s" "${VERSION}" | cut -d. -f2)
|
||||||
|
PATCH=$(printf "%s" "${VERSION}" | cut -d. -f3)
|
||||||
|
BUILD_AND_HOTFIX=$(printf "%s" "${VERSION}" | cut -d. -f4)
|
||||||
|
BUILD=$(printf "%s" "${BUILD_AND_HOTFIX}" | sed -E 's/[a-z]+$//')
|
||||||
|
HOTFIX=$(printf "%s" "${BUILD_AND_HOTFIX}" | sed -E 's/^[0-9]+//')
|
||||||
|
|
||||||
|
if [ -z "${HOTFIX}" ]; then
|
||||||
|
HOTFIX_DEFINE="' '"
|
||||||
|
else
|
||||||
|
HOTFIX_DEFINE="'${HOTFIX}'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Read and display current version
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
CURR_MAJOR=$(grep -E "^#define LEVELX_MAJOR_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_MINOR=$(grep -E "^#define LEVELX_MINOR_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_PATCH=$(grep -E "^#define LEVELX_PATCH_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_BUILD=$(grep -E "^#define LEVELX_BUILD_VERSION" "${API_HEADER}" | awk '{print $NF}')
|
||||||
|
CURR_HOTFIX=$(grep -E "^#define LEVELX_HOTFIX_VERSION" "${API_HEADER}" | \
|
||||||
|
sed -E "s/.*'([^']*)'.*/\1/" | tr -d ' ')
|
||||||
|
|
||||||
|
if [ -z "${CURR_HOTFIX}" ]; then
|
||||||
|
CURR_VER="${CURR_MAJOR}.${CURR_MINOR}.${CURR_PATCH}.${CURR_BUILD}"
|
||||||
|
else
|
||||||
|
CURR_VER="${CURR_MAJOR}.${CURR_MINOR}.${CURR_PATCH}.${CURR_BUILD}${CURR_HOTFIX}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\nLevelX release preparation\n"
|
||||||
|
printf " Repository : %s\n" "${REPO_ROOT}"
|
||||||
|
printf " Current version : %s\n" "${CURR_VER}"
|
||||||
|
printf " Target version : %s\n\n" "${VERSION}"
|
||||||
|
printf "Proceed with update? [y/N] "
|
||||||
|
read -r CONFIRM
|
||||||
|
case "${CONFIRM}" in
|
||||||
|
y|Y) ;;
|
||||||
|
*)
|
||||||
|
printf "Aborted.\n"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Pre-flight checks
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
if ! git -C "${REPO_ROOT}" diff --quiet HEAD 2>/dev/null; then
|
||||||
|
printf "Error: Working tree has uncommitted changes. Commit or stash first.\n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Create feature branch from dev
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
BRANCH_NAME="release-${VERSION}-preparation"
|
||||||
|
printf "\nChecking out dev and pulling latest changes...\n"
|
||||||
|
git -C "${REPO_ROOT}" checkout dev
|
||||||
|
git -C "${REPO_ROOT}" pull origin dev
|
||||||
|
printf "Creating branch '%s'...\n" "${BRANCH_NAME}"
|
||||||
|
git -C "${REPO_ROOT}" checkout -b "${BRANCH_NAME}"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Update version constants
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
printf "\nUpdating version constants in %s...\n" "${API_HEADER}"
|
||||||
|
|
||||||
|
sed -i -E "s|(#define LEVELX_MAJOR_VERSION[[:space:]]+)[0-9]+|\1${MAJOR}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_MINOR_VERSION[[:space:]]+)[0-9]+|\1${MINOR}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_PATCH_VERSION[[:space:]]+)[0-9]+|\1${PATCH}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_BUILD_VERSION[[:space:]]+)[0-9]+|\1${BUILD}|" "${API_HEADER}"
|
||||||
|
sed -i -E "s|(#define LEVELX_HOTFIX_VERSION[[:space:]]+)'[^']*'|\1${HOTFIX_DEFINE}|" "${API_HEADER}"
|
||||||
|
|
||||||
|
git -C "${REPO_ROOT}" add "${API_HEADER}"
|
||||||
|
git -C "${REPO_ROOT}" commit -F - <<'COMMIT_EOF'
|
||||||
|
Updated version number constants
|
||||||
|
|
||||||
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
||||||
|
COMMIT_EOF
|
||||||
|
|
||||||
|
printf "Committed version constant updates.\n"
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
# Port version strings
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
printf "\nNo port-specific version strings in this repository. Skipping port commit.\n"
|
||||||
|
|
||||||
|
printf "\nRelease preparation complete.\n"
|
||||||
|
printf "Branch '%s' is ready for review.\n" "${BRANCH_NAME}"
|
||||||
@@ -1,2 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 Eclipse ThreadX contributors
|
||||||
|
#
|
||||||
|
# This program and the accompanying materials are made available under the
|
||||||
|
# terms of the MIT License which is available at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
$(dirname `realpath $0`)/../test/cmake/run.sh test all
|
$(dirname `realpath $0`)/../test/cmake/run.sh test all
|
||||||
@@ -1,4 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 Eclipse ThreadX contributors
|
||||||
|
#
|
||||||
|
# This program and the accompanying materials are made available under the
|
||||||
|
# terms of the MIT License which is available at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
cmake_policy(SET CMP0057 NEW)
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
project(regression_test LANGUAGES C)
|
project(regression_test LANGUAGES C)
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# Copyright (c) 2024 Microsoft Corporation
|
||||||
|
# Copyright (c) 2026 Eclipse ThreadX contributors
|
||||||
|
#
|
||||||
|
# This program and the accompanying materials are made available under the
|
||||||
|
# terms of the MIT License which is available at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
cmake_policy(SET CMP0057 NEW)
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
project(samples LANGUAGES C)
|
project(samples LANGUAGES C)
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/* Basic NOR flash tests... */
|
/* Basic NOR flash tests... */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/* Basic NOR flash tests... */
|
/* Basic NOR flash tests... */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -21,7 +32,6 @@ ULONG readbuffer[128];
|
|||||||
|
|
||||||
/* Define LevelX NOR flash simulator prototoypes. */
|
/* Define LevelX NOR flash simulator prototoypes. */
|
||||||
|
|
||||||
UINT _lx_nor_flash_simulator_erase_all(VOID);
|
|
||||||
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
||||||
|
|
||||||
|
|
||||||
@@ -70,12 +80,13 @@ UINT status;
|
|||||||
ULONG *word_ptr;
|
ULONG *word_ptr;
|
||||||
|
|
||||||
|
|
||||||
/* Erase the simulated NOR flash. */
|
/* format the simulated NOR flash. */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
/* Initialize LevelX. */
|
/* Initialize LevelX. */
|
||||||
_lx_nor_flash_initialize();
|
_lx_nor_flash_initialize();
|
||||||
|
|
||||||
|
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
|
|
||||||
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
||||||
printf("Test 1: Simple write-read 100 sectors...........");
|
printf("Test 1: Simple write-read 100 sectors...........");
|
||||||
|
|
||||||
@@ -141,10 +152,10 @@ ULONG *word_ptr;
|
|||||||
printf("Test 2: Write same sector 120 times.............");
|
printf("Test 2: Write same sector 120 times.............");
|
||||||
|
|
||||||
/* Reinitialize... */
|
/* Reinitialize... */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
|
|
||||||
lx_nor_flash_initialize();
|
lx_nor_flash_initialize();
|
||||||
|
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
|
|
||||||
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
|
|
||||||
for (j = 0; j < 128; j++)
|
for (j = 0; j < 128; j++)
|
||||||
@@ -1283,9 +1294,9 @@ ULONG *word_ptr;
|
|||||||
|
|
||||||
printf("Test 5: Randow write/read sector................");
|
printf("Test 5: Randow write/read sector................");
|
||||||
|
|
||||||
/* Erase the simulated NOR flash. */
|
/* format the simulated NOR flash. */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
|
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
/* Open the flash. */
|
/* Open the flash. */
|
||||||
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
/***************************************************************************/
|
||||||
|
/* Copyright (c) 2024 Microsoft Corporation */
|
||||||
|
/* Copyright (c) 2026 Eclipse ThreadX contributors */
|
||||||
|
/* */
|
||||||
|
/* This program and the accompanying materials are made available under */
|
||||||
|
/* the terms of the MIT License which is available at */
|
||||||
|
/* https://opensource.org/licenses/MIT. */
|
||||||
|
/* */
|
||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/* Basic NOR flash tests... */
|
/* Basic NOR flash tests... */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -24,7 +35,6 @@ UCHAR nor_cache_memory2[8192];
|
|||||||
|
|
||||||
/* Define LevelX NOR flash simulator prototoypes. */
|
/* Define LevelX NOR flash simulator prototoypes. */
|
||||||
|
|
||||||
UINT _lx_nor_flash_simulator_erase_all(VOID);
|
|
||||||
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
||||||
|
|
||||||
|
|
||||||
@@ -74,15 +84,13 @@ UINT status;
|
|||||||
ULONG *word_ptr;
|
ULONG *word_ptr;
|
||||||
|
|
||||||
|
|
||||||
/* Erase the simulated NOR flash. */
|
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
/* Initialize LevelX. */
|
/* Initialize LevelX. */
|
||||||
_lx_nor_flash_initialize();
|
_lx_nor_flash_initialize();
|
||||||
|
|
||||||
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
||||||
printf("Test 1: Simple write-read 100 sectors...........");
|
printf("Test 1: Simple write-read 100 sectors...........");
|
||||||
|
|
||||||
|
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
||||||
@@ -267,10 +275,9 @@ lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_
|
|||||||
printf("Test 2: Write same sector 120 times.............");
|
printf("Test 2: Write same sector 120 times.............");
|
||||||
|
|
||||||
/* Reinitialize... */
|
/* Reinitialize... */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
|
|
||||||
lx_nor_flash_initialize();
|
lx_nor_flash_initialize();
|
||||||
|
lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
||||||
@@ -1430,10 +1437,11 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
|
|||||||
|
|
||||||
printf("Test 5: Randow write/read sector................");
|
printf("Test 5: Randow write/read sector................");
|
||||||
|
|
||||||
/* Erase the simulated NOR flash. */
|
/*format the simulated NOR flash. */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
|
||||||
|
|
||||||
/* Open the flash. */
|
/* Open the flash. */
|
||||||
|
status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
|
||||||
@@ -1578,8 +1586,8 @@ status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, s
|
|||||||
|
|
||||||
printf("Test 6: Check lx_nor_flash_extended_cache_entries size................");
|
printf("Test 6: Check lx_nor_flash_extended_cache_entries size................");
|
||||||
|
|
||||||
/* Erase the simulated NOR flash. */
|
/* Format the simulated NOR flash. */
|
||||||
_lx_nor_flash_simulator_erase_all();
|
status = lx_nor_flash_format(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize, NULL);
|
||||||
|
|
||||||
/* Open the flash. */
|
/* Open the flash. */
|
||||||
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
|
||||||
|
|||||||
Reference in New Issue
Block a user