mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-14 20:48:51 +08:00
Compare commits
44
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1751446fb0 | ||
|
|
c27eb52bd2 | ||
|
|
c03223909a | ||
|
|
9bf1c24243 | ||
|
|
6a534bed34 | ||
|
|
4585b92f15 | ||
|
|
63ed12cfd6 | ||
|
|
a1761869fd | ||
|
|
5783f64fe1 | ||
|
|
47b2a17d4b | ||
|
|
0f7dd521e5 | ||
|
|
b5dcbff38c | ||
|
|
7d1ef20acf | ||
|
|
04e385f3d5 | ||
|
|
7c5d83d794 | ||
|
|
24eb7d8692 | ||
|
|
058b242a9a | ||
|
|
a3c9691d89 | ||
|
|
f5a55077ad | ||
|
|
656d1490f4 | ||
|
|
8e1d00b591 | ||
|
|
f8899e5d6d | ||
|
|
acc5190739 | ||
|
|
79cbf4019f | ||
|
|
2a963969bc | ||
|
|
1317123fdc | ||
|
|
814a8a346c | ||
|
|
34616e26e7 | ||
|
|
f840cf4ce6 | ||
|
|
ec683ddf14 | ||
|
|
1d6706dfa9 | ||
|
|
6809f87fdd | ||
|
|
9b766d144f | ||
|
|
fb4b913dc2 | ||
|
|
01517ad256 | ||
|
|
9f85e68bd1 | ||
|
|
bc8f7f3623 | ||
|
|
3ca016c042 | ||
|
|
4e747beb15 | ||
|
|
151863ad7c | ||
|
|
d7b2a72452 | ||
|
|
e432e2cfa2 | ||
|
|
0ea87a458d | ||
|
|
f8ab75e3ee |
@@ -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
|
||||||
|
|||||||
+69
-11
@@ -1,14 +1,72 @@
|
|||||||
# Contributing
|
# Contributing to Eclipse ThreadX
|
||||||
|
|
||||||
This project welcomes contributions and suggestions. Most contributions require you to
|
Thanks for your interest in this project.
|
||||||
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
|
|
||||||
and actually do, grant us the rights to use your contribution. For details, visit
|
|
||||||
https://cla.microsoft.com.
|
|
||||||
|
|
||||||
When you submit a pull request, a CLA-bot will automatically determine whether you need
|
## Project description
|
||||||
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
|
|
||||||
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
|
|
||||||
|
|
||||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
Eclipse ThreadX provides a vendor-neutral, open source, safety certified OS for
|
||||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
real-time applications published on under a permissive license. The Eclipse
|
||||||
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
ThreadX suite encompasses:
|
||||||
|
* ThreadX - advanced real-time operating system (RTOS) designed specifically for deeply embedded applications
|
||||||
|
* NetX Duo - advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications
|
||||||
|
* FileX - high-performance, FAT-compatible file system that’s fully integrated with ThreadX kernel
|
||||||
|
* GUIX - provides a complete, embedded graphical user interface (GUI) library
|
||||||
|
* USBX - high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with ThreadX kernel
|
||||||
|
* LevelX - Flash Wear Leveling for FileX and stand-alone purposes
|
||||||
|
* GuiX Studio - design environment, facilitating the creation and maintenance of all graphical elements for GUIX
|
||||||
|
* TraceX - analysis tool that provides a graphical view of real-time system events to better understand the behavior of real-time systems
|
||||||
|
|
||||||
|
Project site: https://projects.eclipse.org/projects/iot.threadx
|
||||||
|
|
||||||
|
## Terms of Use
|
||||||
|
|
||||||
|
This repository is subject to the Terms of Use of the Eclipse Foundation
|
||||||
|
https://www.eclipse.org/legal/termsofuse.php
|
||||||
|
|
||||||
|
## Developer resources
|
||||||
|
|
||||||
|
Information regarding source code management, builds, coding standards, and more.
|
||||||
|
https://projects.eclipse.org/projects/iot.threadx/developer
|
||||||
|
|
||||||
|
The project maintains the following source code repositories
|
||||||
|
|
||||||
|
* https://github.com/eclipse-threadx/.github
|
||||||
|
* https://github.com/eclipse-threadx/cmsis-packs
|
||||||
|
* https://github.com/eclipse-threadx/filex
|
||||||
|
* https://github.com/eclipse-threadx/getting-started
|
||||||
|
* https://github.com/eclipse-threadx/guix
|
||||||
|
* https://github.com/eclipse-threadx/levelx
|
||||||
|
* https://github.com/eclipse-threadx/netxduo
|
||||||
|
* https://github.com/eclipse-threadx/rtos-docs
|
||||||
|
* https://github.com/eclipse-threadx/samples
|
||||||
|
* https://github.com/eclipse-threadx/threadx
|
||||||
|
* https://github.com/eclipse-threadx/threadx-learn-samples
|
||||||
|
* https://github.com/eclipse-threadx/tracex
|
||||||
|
* https://github.com/eclipse-threadx/usbx
|
||||||
|
|
||||||
|
## Eclipse Development Process
|
||||||
|
|
||||||
|
This Eclipse Foundation open project is governed by the Eclipse Foundation
|
||||||
|
Development Process and operates under the terms of the Eclipse IP Policy.
|
||||||
|
|
||||||
|
* https://eclipse.org/projects/dev_process
|
||||||
|
* https://www.eclipse.org/org/documents/Eclipse_IP_Policy.pdf
|
||||||
|
|
||||||
|
## Eclipse Contributor Agreement
|
||||||
|
|
||||||
|
In order to be able to contribute to Eclipse Foundation projects you must electronically sign the Eclipse Contributor Agreement (ECA).
|
||||||
|
https://www.eclipse.org/legal/ECA.php
|
||||||
|
|
||||||
|
The ECA provides the Eclipse Foundation with a permanent record that you agree
|
||||||
|
that each of your contributions will comply with the commitments documented in
|
||||||
|
the Developer Certificate of Origin (DCO). Having an ECA on file associated with
|
||||||
|
the email address matching the "Author" field of your contribution's Git commits
|
||||||
|
fulfills the DCO's requirement that you sign-off on your contributions.
|
||||||
|
|
||||||
|
For more information, please see the Eclipse Committer Handbook:
|
||||||
|
https://www.eclipse.org/projects/handbook/#resources-commit
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
Contact the project developers via the project's "dev" list.
|
||||||
|
https://accounts.eclipse.org/mailing-list/threadx-dev
|
||||||
|
|||||||
+17
-245
@@ -1,249 +1,21 @@
|
|||||||
MICROSOFT SOFTWARE LICENSE TERMS
|
MIT License
|
||||||
|
|
||||||
MICROSOFT AZURE RTOS
|
Copyright (c) 2024 - present Microsoft Corporation
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
These license terms are an agreement between you and Microsoft Corporation (or
|
The above copyright notice and this permission notice shall be included in all
|
||||||
one of its affiliates). They apply to the software named above and any Microsoft
|
copies or substantial portions of the Software.
|
||||||
services or software updates (except to the extent such services or updates are
|
|
||||||
accompanied by new or additional terms, in which case those different terms
|
|
||||||
apply prospectively and do not alter your or Microsoft’s rights relating to
|
|
||||||
pre-updated software or services). IF YOU COMPLY WITH THESE LICENSE TERMS, YOU
|
|
||||||
HAVE THE RIGHTS BELOW. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS.
|
|
||||||
|
|
||||||
1. INSTALLATION AND USE RIGHTS.
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
a) General. You may (I) install, use and modify the software and (ii) install and use the included Microsoft
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
Applications (if any), each solely for internal development, testing and evaluation purposes.
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
Distribution or production use is governed by the license terms set forth in
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
Section 2. You may also obtain distribution or production use rights through a separate agreement with
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
Microsoft.
|
SOFTWARE.
|
||||||
|
|
||||||
b) Contributions. Microsoft welcomes contributions to this software. In the event
|
|
||||||
that you make a contribution to this software you will be required to agree to a
|
|
||||||
Contributor License Agreement (CLA) declaring that you have the right to, and
|
|
||||||
actually do, grant Microsoft the rights to use your contribution. For details,
|
|
||||||
visit https://cla.microsoft.com.
|
|
||||||
|
|
||||||
c) Included Microsoft Applications. The software may include other Microsoft
|
|
||||||
applications which are governed by the licenses embedded in or made available
|
|
||||||
with those applications.
|
|
||||||
|
|
||||||
d) Third Party Components. The software may include third party components with
|
|
||||||
separate legal notices or governed by other agreements, as may be described
|
|
||||||
within the software or in the ThirdPartyNotices file(s) accompanying the
|
|
||||||
software.
|
|
||||||
|
|
||||||
e) Competitive Benchmarking. If you are a direct competitor, and you access or use
|
|
||||||
the software for purposes of competitive benchmarking, analysis, or intelligence
|
|
||||||
gathering, you waive as against Microsoft, its subsidiaries, and its affiliated
|
|
||||||
companies (including prospectively) any competitive use, access, and
|
|
||||||
benchmarking test restrictions in the terms governing your software to the
|
|
||||||
extent your terms of use are, or purport to be, more restrictive than
|
|
||||||
Microsoft’s terms. If you do not waive any such purported restrictions in the
|
|
||||||
terms governing your software, you are not allowed to access or use this
|
|
||||||
software, and will not do so.
|
|
||||||
|
|
||||||
2. DISTRIBUTION AND PRODUCTION USE. If you have obtained and/or are developing on
|
|
||||||
microprocessor(s) and/or microcontroller(s) (“hardware”) listed in the file
|
|
||||||
named “LICENSED-HARDWARE.txt” included in the repository and/or distributed with
|
|
||||||
the software you have the following rights in and to the software solely when
|
|
||||||
used in combination with the hardware. In the event hardware is not listed in
|
|
||||||
the LICENSED-HARDWARE.txt file, you do not have the rights in this Section 2.
|
|
||||||
|
|
||||||
a) Distribution and Production Use Rights.
|
|
||||||
|
|
||||||
i. You may use the software in production (e.g. program the modified or unmodified
|
|
||||||
software to devices you own or control) and distribute (i.e. make available to
|
|
||||||
third parties) the modified or unmodified binary image produced from this code.
|
|
||||||
|
|
||||||
ii. You may permit your device distributors or developers to copy and distribute the
|
|
||||||
binary image as programmed or to be programmed to your devices.
|
|
||||||
|
|
||||||
iii. You may redistribute the unmodified or modified source to your device
|
|
||||||
distributors or developers. Modifications must be clearly marked. Any
|
|
||||||
redistribution in source code form must contain this license and any other
|
|
||||||
licenses that accompany the software.
|
|
||||||
|
|
||||||
b) Requirements. For any code you distribute, you must:
|
|
||||||
|
|
||||||
i. when distributed in binary form, except as embedded in a device, include with
|
|
||||||
such distribution the terms of this agreement;
|
|
||||||
ii. when distributed in source code form to distributors or developers of your
|
|
||||||
devices, include with such distribution the terms of this agreement; and
|
|
||||||
iii. indemnify, defend and hold harmless Microsoft from any claims, including claims arising from any High Risk Uses, and inclusive of attorneys’ fees, related to the distribution or use of your devices that include the software, except to the extent that any intellectual property claim is based solely on the unmodified software.
|
|
||||||
|
|
||||||
c) Restrictions. You may not:
|
|
||||||
i. use or modify the software to create competing real time operating system
|
|
||||||
software;
|
|
||||||
|
|
||||||
ii. remove any copyright notices or licenses contained in the software;
|
|
||||||
|
|
||||||
iii. use Microsoft’s trademarks or trade dress in your application in any way that
|
|
||||||
suggests your device or application comes from or is endorsed by Microsoft;
|
|
||||||
|
|
||||||
iv. transfer individual components, specific libraries, classes, functions or code
|
|
||||||
fragments of the software separately for purposes unrelated to the software; or
|
|
||||||
|
|
||||||
v. use or distribute the software in any way that would subject the software or
|
|
||||||
Microsoft’s intellectual property or technology to any other license terms.
|
|
||||||
|
|
||||||
3. SCOPE OF LICENSE. The software is licensed, not sold. Microsoft reserves all
|
|
||||||
other rights. Unless applicable law gives you more rights despite this
|
|
||||||
limitation, you will not (and have no right to):
|
|
||||||
|
|
||||||
a) remove, minimize, block, or modify any notices of Microsoft or its suppliers in
|
|
||||||
the software;
|
|
||||||
|
|
||||||
b) use the software in any way that is against the law or to create or propagate
|
|
||||||
malware; or
|
|
||||||
|
|
||||||
c) share, publish, distribute, or lease the software (except as permitted in
|
|
||||||
Section 2 above), or provide the software as a stand-alone offering for others
|
|
||||||
to use.
|
|
||||||
|
|
||||||
4. DATA. This software may interact with other Microsoft products that collect data
|
|
||||||
that is transmitted to Microsoft. To learn more about how Microsoft processes
|
|
||||||
personal data we collect, please see the Microsoft Privacy Statement at
|
|
||||||
https://go.microsoft.com/fwlink/?LinkId=248681.
|
|
||||||
|
|
||||||
5. EXPORT RESTRICTIONS. You must comply with all domestic and international export
|
|
||||||
laws and regulations that apply to the software, which include restrictions on
|
|
||||||
destinations, end users, and end use. For further information on export
|
|
||||||
restrictions, visit https://aka.ms/exporting.
|
|
||||||
|
|
||||||
6. SUPPORT SERVICES. Microsoft is not obligated under this agreement to provide any
|
|
||||||
support services for the software. Any support provided is “as is”, “with all
|
|
||||||
faults”, and without warranty of any kind.
|
|
||||||
|
|
||||||
7. UPDATES. Microsoft may periodically update the software. You may obtain updates
|
|
||||||
only from Microsoft or Microsoft-authorized sources. Updates may not include or
|
|
||||||
support all existing software features, services, or peripheral devices.
|
|
||||||
|
|
||||||
8. TERMINATION. Without prejudice to any other rights, Microsoft may terminate this
|
|
||||||
agreement if you fail to comply with any of its terms or conditions. In such
|
|
||||||
event, you must destroy all copies of the software and all of its component
|
|
||||||
parts.
|
|
||||||
|
|
||||||
9. ENTIRE AGREEMENT. This agreement, and any other terms Microsoft may provide for
|
|
||||||
supplements, updates, or third-party applications, is the entire agreement for
|
|
||||||
the software. To the extent you have entered into a separate agreement with
|
|
||||||
Microsoft relating specifically to the software, the terms in such agreement
|
|
||||||
shall control.
|
|
||||||
|
|
||||||
10. APPLICABLE LAW AND PLACE TO RESOLVE DISPUTES. If you acquired the software in
|
|
||||||
the United States or Canada, the laws of the state or province where you live
|
|
||||||
(or, if a business, where your principal place of business is located) govern
|
|
||||||
the interpretation of this agreement, claims for its breach, and all other
|
|
||||||
claims (including consumer protection, unfair competition, and tort claims),
|
|
||||||
regardless of conflict of laws principles. If you acquired the software in any
|
|
||||||
other country, its laws apply. If U.S. federal jurisdiction exists, you and
|
|
||||||
Microsoft consent to exclusive jurisdiction and venue in the federal court in
|
|
||||||
King County, Washington for all disputes heard in court. If not, you and
|
|
||||||
Microsoft consent to exclusive jurisdiction and venue in the Superior Court of
|
|
||||||
King County, Washington for all disputes heard in court.
|
|
||||||
|
|
||||||
11. CONSUMER RIGHTS; REGIONAL VARIATIONS. This agreement describes certain legal
|
|
||||||
rights. You may have other rights, including consumer rights, under the laws of
|
|
||||||
your state or country. Separate and apart from your relationship with Microsoft,
|
|
||||||
you may also have rights with respect to the party from which you acquired the
|
|
||||||
software. This agreement does not change those other rights if the laws of your
|
|
||||||
state or country do not permit it to do so. For example, if you acquired the
|
|
||||||
software in one of the below regions, or mandatory country law applies, then the
|
|
||||||
following provisions apply to you:
|
|
||||||
|
|
||||||
a) Australia. You have statutory guarantees under the Australian Consumer Law and
|
|
||||||
nothing in this agreement is intended to affect those rights.
|
|
||||||
|
|
||||||
b) Germany and Austria.
|
|
||||||
|
|
||||||
i. Warranty. The properly licensed software will perform substantially as
|
|
||||||
described in any Microsoft materials that accompany the software. However,
|
|
||||||
Microsoft gives no contractual guarantee in relation to the licensed software.
|
|
||||||
|
|
||||||
ii. Limitation of Liability. In case of intentional conduct, gross negligence,
|
|
||||||
claims based on the Product Liability Act, as well as, in case of death or
|
|
||||||
personal or physical injury, Microsoft is liable according to the statutory law.
|
|
||||||
|
|
||||||
|
|
||||||
Subject to the foregoing clause ii., Microsoft will only be liable for slight
|
|
||||||
negligence if Microsoft is in breach of such material contractual obligations,
|
|
||||||
the fulfillment of which facilitate the due performance of this agreement, the
|
|
||||||
breach of which would endanger the purpose of this agreement and the compliance
|
|
||||||
with which a party may constantly trust in (so-called "cardinal obligations").
|
|
||||||
In other cases of slight negligence, Microsoft will not be liable for slight
|
|
||||||
negligence.
|
|
||||||
12. DISCLAIMER OF WARRANTY.
|
|
||||||
a) THE SOFTWARE IS LICENSED “AS IS.” YOU BEAR THE RISK OF
|
|
||||||
USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES, OR CONDITIONS. TO
|
|
||||||
THE EXTENT PERMITTED UNDER APPLICABLE LAWS, MICROSOFT EXCLUDES ALL IMPLIED
|
|
||||||
WARRANTIES, INCLUDING MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
||||||
NON-INFRINGEMENT.
|
|
||||||
b) HIGH RISK USE DISCLAIMER. WARNING: THE SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE WHERE FAILURE OR FAULT OF ANY KIND OF THE SOFTWARE COULD RESULT IN DEATH OR SERIOUS BODILY INJURY, OR IN PHYSICAL OR ENVIRONMENTAL DAMAGE (“collectively High Risk Use”). Accordingly, You must design and implement your hardware and software such that, in the event of any interruption, defect, error, or other failure of the software, the safety of people, property, and the environment are not reduced below a level that is reasonable, appropriate, and legal, whether in general or for a specific industry. Your High Risk Use of the software is at Your own risk.
|
|
||||||
|
|
||||||
13. LIMITATION ON AND EXCLUSION OF DAMAGES. IF YOU HAVE ANY BASIS FOR RECOVERING
|
|
||||||
DAMAGES DESPITE THE PRECEDING DISCLAIMER OF WARRANTY, YOU CAN RECOVER FROM
|
|
||||||
MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT
|
|
||||||
RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL,
|
|
||||||
INDIRECT, OR INCIDENTAL DAMAGES.
|
|
||||||
|
|
||||||
This limitation applies to (a) anything related to the software, services,
|
|
||||||
content (including code) on third party Internet sites, or third party
|
|
||||||
applications; and (b) claims for breach of contract, warranty, guarantee, or
|
|
||||||
condition; strict liability, negligence, or other tort; or any other claim; in
|
|
||||||
each case to the extent permitted by applicable law.
|
|
||||||
|
|
||||||
It also applies even if Microsoft knew or should have known about the
|
|
||||||
possibility of the damages. The above limitation or exclusion may not apply to
|
|
||||||
you because your state, province, or country may not allow the exclusion or
|
|
||||||
limitation of incidental, consequential, or other damages.
|
|
||||||
|
|
||||||
Please note: As this software is distributed in Canada, some of the clauses in
|
|
||||||
this agreement are provided below in French.
|
|
||||||
|
|
||||||
Remarque: Ce logiciel étant distribué au Canada, certaines des clauses dans ce
|
|
||||||
contrat sont fournies ci-dessous en français.
|
|
||||||
|
|
||||||
EXONÉRATION DE GARANTIE.
|
|
||||||
a) Le logiciel visé par une licence est offert « tel quel
|
|
||||||
». Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft
|
|
||||||
n’accorde aucune autre garantie expresse. Vous pouvez bénéficier de droits
|
|
||||||
additionnels en vertu du droit local sur la protection des consommateurs, que ce
|
|
||||||
contrat ne peut modifier. La ou elles sont permises par le droit locale, les
|
|
||||||
garanties implicites de qualité marchande, d’adéquation à un usage particulier
|
|
||||||
et d’absence de contrefaçon sont exclues.
|
|
||||||
b) CLAUSE D’EXCLUSION DE RESPONSABILITÉ RELATIVE À L’UTILISATION À HAUT RISQUE.
|
|
||||||
AVERTISSEMENT: LE LOGICIEL N’EST PAS CONÇU OU DESTINÉ À ÊTRE UTILISÉ LORSQU’UNE
|
|
||||||
DÉFAILLANCE OU UN DÉFAUT DE QUELQUE NATURE QUE CE SOIT POURRAIT ENTRAÎNER LA
|
|
||||||
MORT OU DES BLESSURES CORPORELLES GRAVES, OU DES DOMMAGES PHYSIQUES OU
|
|
||||||
ENVIRONNEMENTAUX (« Utilisation à haut risque »). Par conséquent, vous devez concevoir et mettre en
|
|
||||||
œuvre votre équipement et votre logiciel de manière à ce que, en cas d’interruption, de défaut, d’erreur
|
|
||||||
ou de toute autre défaillance du logiciel, la sécurité des personnes, des biens et de l’environnement ne
|
|
||||||
soit pas réduite en dessous d’un niveau raisonnable, approprié et légal, que ce soit en général ou pour
|
|
||||||
un secteur spécifique. Votre utilisation à haut risque du logiciel est à vos propres risques.
|
|
||||||
|
|
||||||
LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE RESPONSABILITÉ POUR LES
|
|
||||||
DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une
|
|
||||||
indemnisation en cas de dommages directs uniquement à hauteur de 5,00 $ US. Vous
|
|
||||||
ne pouvez prétendre à aucune indemnisation pour les autres dommages, y compris
|
|
||||||
les dommages spéciaux, indirects ou accessoires et pertes de bénéfices.
|
|
||||||
|
|
||||||
Cette limitation concerne:
|
|
||||||
|
|
||||||
•tout ce qui est relié au logiciel, aux services ou au contenu (y compris le
|
|
||||||
code) figurant sur des sites Internet tiers ou dans des programmes tiers; et
|
|
||||||
|
|
||||||
•les réclamations au titre de violation de contrat ou de garantie, ou au titre
|
|
||||||
de responsabilité stricte, de négligence ou d’une autre faute dans la limite
|
|
||||||
autorisée par la loi en vigueur.
|
|
||||||
|
|
||||||
Elle s’applique également, même si Microsoft connaissait ou devrait connaître
|
|
||||||
l’éventualité d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la
|
|
||||||
limitation de responsabilité pour les dommages indirects, accessoires ou de
|
|
||||||
quelque nature que ce soit, il se peut que la limitation ou l’exclusion
|
|
||||||
ci-dessus ne s’appliquera pas à votre égard.
|
|
||||||
|
|
||||||
EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous
|
|
||||||
pourriez avoir d’autres droits prévus par les lois de votre pays. Le présent
|
|
||||||
contrat ne modifie pas les droits que vous confèrent les lois de votre pays si
|
|
||||||
celles-ci ne le permettent pas.
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
LICENSED HARDWARE LIST
|
|
||||||
|
|
||||||
Last Updated: 2023-02-10
|
|
||||||
|
|
||||||
Microsoft has entered into OEM Agreements with manufacturers of the following
|
|
||||||
microprocessors and microcontrollers (the “hardware”) to enable those
|
|
||||||
manufacturers to include and distribute Azure RTOS in certain hardware. If you
|
|
||||||
have obtained and/or are developing on microprocessor(s) and/or
|
|
||||||
microcontroller(s) (“hardware”) listed below you inherit the “Distribution and
|
|
||||||
Production Use” rights in Section 2 of the Microsoft Software License Terms for
|
|
||||||
Microsoft Azure RTOS. If hardware is not listed below, you do not have those
|
|
||||||
rights.
|
|
||||||
|
|
||||||
|
|
||||||
STMicroelectronics:
|
|
||||||
|
|
||||||
STM32 MCUs
|
|
||||||
STM32 MPUs
|
|
||||||
|
|
||||||
MediaTek:
|
|
||||||
|
|
||||||
MT3620 MCU (Azure Sphere)
|
|
||||||
|
|
||||||
Microchip:
|
|
||||||
|
|
||||||
PIC 32-bit MCUs
|
|
||||||
SAM 32-bit MCUs
|
|
||||||
SAM 32-bit MPUs
|
|
||||||
|
|
||||||
NXP:
|
|
||||||
|
|
||||||
i.MX RT10xx and RT116x/7x series crossover MCUs
|
|
||||||
LPC5500 series
|
|
||||||
MCX N series
|
|
||||||
|
|
||||||
Renesas:
|
|
||||||
|
|
||||||
Synergy Platform
|
|
||||||
RX Family of MCUs
|
|
||||||
RA Family of MCUs
|
|
||||||
RZ Family of MPUs
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
More coming soon. Please check back frequently for updates.
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
# Azure RTOS LevelX
|
# Eclipse ThreadX LevelX
|
||||||
|
|
||||||
LevelX provides NAND and NOR flash wear leveling facilities to embedded applications. Since both NAND and NOR flash memory can only be erased a finite number of times, it’s critical to distribute the flash memory use evenly. This is typically called **wear leveling** and is the purpose behind LevelX. LevelX presents to the user an array of logical sectors that are mapped to physical flash memory inside of LevelX. Applications may use LevelX in conjunction with FileX or may read/write logical sectors directly. LevelX is designed for fault tolerance. Flash updates are performed in a multiple-step process that can be interrupted in each step. LevelX automatically recovers to the optimal state during the next operation.
|
LevelX provides NAND and NOR flash wear leveling facilities to embedded applications. Since both NAND and NOR flash memory can only be erased a finite number of times, it’s critical to distribute the flash memory use evenly. This is typically called **wear leveling** and is the purpose behind LevelX. LevelX presents to the user an array of logical sectors that are mapped to physical flash memory inside of LevelX. Applications may use LevelX in conjunction with FileX or may read/write logical sectors directly. LevelX is designed for fault tolerance. Flash updates are performed in a multiple-step process that can be interrupted in each step. LevelX automatically recovers to the optimal state during the next operation.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Azure RTOS LevelX as part of Azure RTOS has been integrated to the semiconductor's SDKs and development environment. You can develop using the tools of choice from [STMicroelectronics](https://www.st.com/content/st_com/en/campaigns/x-cube-azrtos-azure-rtos-stm32.html), [NXP](https://www.nxp.com/design/software/embedded-software/azure-rtos-for-nxp-microcontrollers:AZURE-RTOS), [Renesas](https://github.com/renesas/azure-rtos) and [Microchip](https://mu.microchip.com/get-started-simplifying-your-iot-design-with-azure-rtos).
|
LevelX as part of Eclipse ThreadX has been integrated to the semiconductor's SDKs and development environment. You can develop using the tools of choice from [STMicroelectronics](https://www.st.com/content/st_com/en/campaigns/x-cube-azrtos-azure-rtos-stm32.html), [NXP](https://www.nxp.com/design/software/embedded-software/azure-rtos-for-nxp-microcontrollers:AZURE-RTOS), [Renesas](https://github.com/renesas/azure-rtos) and [Microchip](https://mu.microchip.com/get-started-simplifying-your-iot-design-with-azure-rtos).
|
||||||
|
|
||||||
See [Overview of Azure RTOS LevelX](https://learn.microsoft.com/azure/rtos/levelx/overview-levelx) for the high-level overview, and all documentation and APIs can be found in: [Azure RTOS LevelX documentation](https://learn.microsoft.com/azure/rtos/levelx/).
|
See [Overview of Eclipse ThreadX LevelX](https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/levelx/index.md) for the high-level overview.
|
||||||
|
|
||||||
## Repository Structure and Usage
|
## Repository Structure and Usage
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ See [Overview of Azure RTOS LevelX](https://learn.microsoft.com/azure/rtos/level
|
|||||||
├── LICENSE.txt # License terms
|
├── LICENSE.txt # License terms
|
||||||
├── LICENSE-HARDWARE.txt # Licensed hardware from semiconductors
|
├── LICENSE-HARDWARE.txt # Licensed hardware from semiconductors
|
||||||
├── CONTRIBUTING.md # Contribution guidance
|
├── CONTRIBUTING.md # Contribution guidance
|
||||||
└── SECURITY.md # Microsoft repo security guidance
|
└── SECURITY.md # Repo security guidance
|
||||||
|
|
||||||
### Branches & Releases
|
### Branches & Releases
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ The master branch has the most recent code with all new features and bug fixes.
|
|||||||
|
|
||||||
## Component dependencies
|
## Component dependencies
|
||||||
|
|
||||||
The main components of Azure RTOS are each provided in their own repository, but there are dependencies between them, as shown in the following graph. This is important to understand when setting up your builds.
|
The main components of Eclipse ThreadX are each provided in their own repository, but there are dependencies between them, as shown in the following graph. This is important to understand when setting up your builds.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ The main components of Azure RTOS are each provided in their own repository, but
|
|||||||
|
|
||||||
### Building and using the library
|
### Building and using the library
|
||||||
|
|
||||||
Instruction for building the LevelX as static library using Arm GNU Toolchain and CMake. If you are using toolchain and IDE from semiconductor, you might follow its own instructions to use Azure RTOS components as explained in the [Getting Started](#getting-started) section.
|
Instruction for building the LevelX as static library using Arm GNU Toolchain and CMake. If you are using toolchain and IDE from semiconductor, you might follow its own instructions to use Eclipse ThreadX components as explained in the [Getting Started](#getting-started) section.
|
||||||
|
|
||||||
1. Install the following tools:
|
1. Install the following tools:
|
||||||
|
|
||||||
@@ -95,14 +95,14 @@ Instruction for building the LevelX as static library using Arm GNU Toolchain an
|
|||||||
1. Cloning the repo.
|
1. Cloning the repo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone --recursive https://github.com/azure-rtos/levelx.git
|
$ git clone --recursive https://github.com/eclipse-threadx/levelx.git
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Define the features and addons you need in `lx_user.h` and build together with the component source code. You can refer to [`lx_user_sample.h`](https://github.com/azure-rtos/levelx/blob/master/common/inc/lx_user_sample.h) as an example.
|
1. Define the features and addons you need in `lx_user.h` and build together with the component source code. You can refer to [`lx_user_sample.h`](https://github.com/azure-rtos/levelx/blob/master/common/inc/lx_user_sample.h) as an example.
|
||||||
|
|
||||||
1. Building as a static library
|
1. Building as a static library
|
||||||
|
|
||||||
Each component of Azure RTOS comes with a composable CMake-based build system that supports many different MCUs and host systems. Integrating any of these components into your device app code is as simple as adding a git submodule and then including it in your build using the CMake `add_subdirectory()`.
|
Each component of Eclipse ThreadX comes with a composable CMake-based build system that supports many different MCUs and host systems. Integrating any of these components into your device app code is as simple as adding a git submodule and then including it in your build using the CMake `add_subdirectory()`.
|
||||||
|
|
||||||
While the typical usage pattern is to include LevelX into your device code source tree to be built & linked with your code, you can compile this project as a standalone static library to confirm your build is set up correctly.
|
While the typical usage pattern is to include LevelX into your device code source tree to be built & linked with your code, you can compile this project as a standalone static library to confirm your build is set up correctly.
|
||||||
|
|
||||||
@@ -114,31 +114,23 @@ Instruction for building the LevelX as static library using Arm GNU Toolchain an
|
|||||||
$ cmake --build ./build
|
$ cmake --build ./build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Professional support
|
|
||||||
|
|
||||||
[Professional support plans](https://azure.microsoft.com/support/options/) are available from Microsoft. For community support and others, see the [Resources](#resources) section below.
|
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
License terms for using Azure RTOS are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information. No additional license fees are required for deploying Azure RTOS on hardware defined in the [LICENSED-HARDWARE.txt](./LICENSED-HARDWARE.txt) file. If you are using hardware not listed in the file or having licensing questions in general, please contact Microsoft directly at https://aka.ms/azrtos-license.
|
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
|
||||||
|
|
||||||
The following are references to additional Azure RTOS resources:
|
The following are references to additional Eclipse ThreadX resources:
|
||||||
|
|
||||||
- **Product introduction and white papers**: https://azure.com/rtos
|
- **Product introduction**: https://github.com/eclipse-threadx/rtos-docs
|
||||||
- **General technical questions**: https://aka.ms/QnA/azure-rtos
|
- **Product issues and bugs, or feature requests**: https://github.com/eclipse-threadx/levelx/issues
|
||||||
- **Product issues and bugs, or feature requests**: https://github.com/azure-rtos/levelx/issues
|
- **TraceX Installer**: https://aka.ms/azrtos-tracex-installer
|
||||||
- **Licensing and sales questions**: https://aka.ms/azrtos-license
|
|
||||||
- **Product roadmap and support policy**: https://aka.ms/azrtos/lts
|
|
||||||
- **Blogs and videos**: http://msiotblog.com and https://aka.ms/iotshow
|
|
||||||
- **Azure RTOS TraceX Installer**: https://aka.ms/azrtos-tracex-installer
|
|
||||||
|
|
||||||
You can also check [previous questions](https://stackoverflow.com/questions/tagged/azure-rtos+levelx) or ask new ones on StackOverflow using the `azure-rtos` and `levelx` tags.
|
You can also check [previous questions](https://stackoverflow.com/questions/tagged/azure-rtos+levelx) or ask new ones on StackOverflow using the `threadx` and `levelx` tags.
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
Azure RTOS provides OEMs with components to secure communication and to create code and data isolation using underlying MCU/MPU hardware protection mechanisms. It is ultimately the responsibility of the device builder to ensure the device fully meets the evolving security requirements associated with its specific use case.
|
Eclipse ThreadX provides OEMs with components to secure communication and to create code and data isolation using underlying MCU/MPU hardware protection mechanisms. It is ultimately the responsibility of the device builder to ensure the device fully meets the evolving security requirements associated with its specific use case.
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
|
|||||||
+12
-27
@@ -1,35 +1,20 @@
|
|||||||
## Security
|
# Security Policy
|
||||||
|
|
||||||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
## Supported Versions
|
||||||
|
|
||||||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 6.4.x | :white_check_mark: |
|
||||||
|
|
||||||
## Reporting Security Issues
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
**Please do not report security vulnerabilities through public GitHub issues.**
|
If you think you have found a vulnerability in <project> you can report it using one of the following ways:
|
||||||
|
|
||||||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
* Contact the [Eclipse Foundation Security Team](mailto:security@eclipse-foundation.org)
|
||||||
|
* [Report a Vulnerability](https://github.com/eclipse-threadx/levelx/security/advisories/new)
|
||||||
|
|
||||||
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
|
You can find more information about reporting and disclosure at the [Eclipse Foundation Security page](https://www.eclipse.org/security/).
|
||||||
|
|
||||||
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
## Security Policy
|
||||||
|
|
||||||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
This project follows [Eclipse Foundation Vulnerability Reporting Policy](https://www.eclipse.org/security/policy/).
|
||||||
|
|
||||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
||||||
* Full paths of source file(s) related to the manifestation of the issue
|
|
||||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
||||||
* Any special configuration required to reproduce the issue
|
|
||||||
* Step-by-step instructions to reproduce the issue
|
|
||||||
* Proof-of-concept or exploit code (if possible)
|
|
||||||
* Impact of the issue, including how an attacker might exploit the issue
|
|
||||||
|
|
||||||
This information will help us triage your report more quickly.
|
|
||||||
|
|
||||||
## Preferred Languages
|
|
||||||
|
|
||||||
We prefer all communications to be in English.
|
|
||||||
|
|
||||||
## Policy
|
|
||||||
|
|
||||||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ 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_mapped_block_list_add.c
|
${CMAKE_CURRENT_LIST_DIR}/src/lx_nand_flash_mapped_block_list_add.c
|
||||||
@@ -30,6 +31,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 +54,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
|
||||||
|
|||||||
+33
-14
@@ -1,13 +1,13 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
* Portion Copyright (c) 2025 STMicroelectronics
|
||||||
/* */
|
*
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* This program and the accompanying materials are made available under the
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* terms of the MIT License which is available at
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* and in the root directory of this software. */
|
*
|
||||||
/* */
|
* SPDX-License-Identifier: MIT
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
/* APPLICATION INTERFACE DEFINITION RELEASE */
|
/* APPLICATION INTERFACE DEFINITION RELEASE */
|
||||||
/* */
|
/* */
|
||||||
/* lx_api.h PORTABLE C */
|
/* lx_api.h PORTABLE C */
|
||||||
/* 6.4.0 */
|
/* 6.4.1 */
|
||||||
/* AUTHOR */
|
/* AUTHOR */
|
||||||
/* */
|
/* */
|
||||||
/* William E. Lamie, Microsoft Corporation */
|
/* William E. Lamie, Microsoft Corporation */
|
||||||
@@ -89,6 +89,9 @@
|
|||||||
/* 12-31-2023 Xiuwen Cai Modified comment(s), */
|
/* 12-31-2023 Xiuwen Cai Modified comment(s), */
|
||||||
/* added configuration checks, */
|
/* added configuration checks, */
|
||||||
/* resulting in version 6.4.0 */
|
/* resulting in version 6.4.0 */
|
||||||
|
/* 03-01-2024 Tiejun Zhou Modified comment(s), */
|
||||||
|
/* update version number, */
|
||||||
|
/* resulting in version 6.4.1 */
|
||||||
/* */
|
/* */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
@@ -201,7 +204,9 @@ typedef unsigned long long ULONG64;
|
|||||||
#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 4
|
||||||
#define LEVELX_PATCH_VERSION 0
|
#define LEVELX_PATCH_VERSION 5
|
||||||
|
#define LEVELX_BUILD_VERSION 202504
|
||||||
|
#define LEVELX_HOTFIX_VERSION ' '
|
||||||
|
|
||||||
|
|
||||||
/* Define general LevelX Constants. */
|
/* Define general LevelX Constants. */
|
||||||
@@ -526,7 +531,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
|
||||||
@@ -535,6 +539,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;
|
||||||
@@ -664,7 +670,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;
|
||||||
@@ -723,8 +730,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
|
||||||
@@ -741,7 +750,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
|
||||||
@@ -757,7 +768,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);
|
||||||
@@ -772,7 +789,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);
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -91,7 +90,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,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
* Copyright (c) 2025 STMicroelectronics
|
||||||
/* */
|
*
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* This program and the accompanying materials are made available under the
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* terms of the MIT License which is available at
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* and in the root directory of this software. */
|
*
|
||||||
/* */
|
* SPDX-License-Identifier: MIT
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -40,7 +40,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 */
|
||||||
@@ -65,224 +65,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;
|
UINT status;
|
||||||
UCHAR block_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,279 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2024 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 */
|
||||||
|
/** */
|
||||||
|
/** 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,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
+14
-451
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -55,6 +54,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*/
|
||||||
@@ -67,15 +67,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
@@ -96,438 +88,9 @@
|
|||||||
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,536 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
|
*
|
||||||
|
* 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_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 */
|
||||||
|
/* */
|
||||||
|
/* 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_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_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,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -291,7 +290,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. */
|
||||||
@@ -310,7 +309,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,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
+75
-880
@@ -1,13 +1,13 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
* Portion Copyright (c) 2025 STMicroelectronics
|
||||||
/* */
|
*
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* This program and the accompanying materials are made available under the
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* terms of the MIT License which is available at
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* and in the root directory of this software. */
|
*
|
||||||
/* */
|
* SPDX-License-Identifier: MIT
|
||||||
/**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -34,879 +34,74 @@
|
|||||||
|
|
||||||
#include "lx_api.h"
|
#include "lx_api.h"
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* FUNCTION RELEASE */
|
||||||
|
/* */
|
||||||
|
/* _lx_nor_flash_open 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 */
|
||||||
|
/* */
|
||||||
|
/* OUTPUT */
|
||||||
|
/* */
|
||||||
|
/* return status */
|
||||||
|
/* */
|
||||||
|
/* CALLS */
|
||||||
|
/* lx_nor_flash_open_extended() */
|
||||||
|
/* */
|
||||||
|
/* CALLED BY */
|
||||||
|
/* */
|
||||||
|
/* 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 */
|
||||||
|
/* 11-09-2020 William E. Lamie Modified comment(s), */
|
||||||
|
/* fixed compiler warnings, */
|
||||||
|
/* resulting in version 6.1.2 */
|
||||||
|
/* 12-30-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 */
|
||||||
|
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
||||||
|
/* added new driver interface, */
|
||||||
|
/* resulting in version 6.2.1 */
|
||||||
|
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
|
||||||
|
/* added count for minimum */
|
||||||
|
/* erased blocks, added */
|
||||||
|
/* obsolete count cache, */
|
||||||
|
/* avoided clearing user */
|
||||||
|
/* extension in flash control */
|
||||||
|
/* block, */
|
||||||
|
/* resulting in version 6.3.0 */
|
||||||
|
/* 10-21-2025 Modified comment(s) */
|
||||||
|
/* call the extended equivalent */
|
||||||
|
/* API */
|
||||||
|
|
||||||
/**************************************************************************/
|
|
||||||
/* */
|
|
||||||
/* FUNCTION RELEASE */
|
|
||||||
/* */
|
|
||||||
/* _lx_nor_flash_open 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 */
|
|
||||||
/* */
|
|
||||||
/* 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 */
|
|
||||||
/* */
|
|
||||||
/* 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 */
|
|
||||||
/* 11-09-2020 William E. Lamie Modified comment(s), */
|
|
||||||
/* fixed compiler warnings, */
|
|
||||||
/* resulting in version 6.1.2 */
|
|
||||||
/* 12-30-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 */
|
|
||||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added new driver interface, */
|
|
||||||
/* resulting in version 6.2.1 */
|
|
||||||
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
|
|
||||||
/* added count for minimum */
|
|
||||||
/* erased blocks, added */
|
|
||||||
/* obsolete count cache, */
|
|
||||||
/* avoided clearing user */
|
|
||||||
/* extension in flash control */
|
|
||||||
/* block, */
|
|
||||||
/* resulting in version 6.3.0 */
|
|
||||||
/* */
|
|
||||||
/**************************************************************************/
|
|
||||||
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,914 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 */
|
||||||
|
/* */
|
||||||
|
/* 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 */
|
||||||
|
/* 11-09-2020 William E. Lamie Modified comment(s), */
|
||||||
|
/* fixed compiler warnings, */
|
||||||
|
/* resulting in version 6.1.2 */
|
||||||
|
/* 12-30-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 */
|
||||||
|
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
||||||
|
/* added new driver interface, */
|
||||||
|
/* resulting in version 6.2.1 */
|
||||||
|
/* 10-31-2023 Xiuwen Cai Modified comment(s), */
|
||||||
|
/* added count for minimum */
|
||||||
|
/* erased blocks, added */
|
||||||
|
/* obsolete count cache, */
|
||||||
|
/* avoided clearing user */
|
||||||
|
/* extension in flash control */
|
||||||
|
/* block, */
|
||||||
|
/* resulting in version 6.3.0 */
|
||||||
|
/* */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
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,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
/**************************************************************************/
|
/***************************************************************************
|
||||||
/* */
|
* Copyright (c) 2024 Microsoft Corporation
|
||||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
*
|
||||||
/* */
|
* This program and the accompanying materials are made available under the
|
||||||
/* This software is licensed under the Microsoft Software License */
|
* terms of the MIT License which is available at
|
||||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
* https://opensource.org/licenses/MIT.
|
||||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
*
|
||||||
/* and in the root directory of this software. */
|
* SPDX-License-Identifier: MIT
|
||||||
/* */
|
**************************************************************************/
|
||||||
/**************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
LevelX
|
||||||
|
|
||||||
|
For version 6 and higher, please refer to the release notes on GitHub at https://github.com/eclipse-threadx/levelx/releases.
|
||||||
|
Below is the revision history for 5.x.
|
||||||
|
|
||||||
|
|
||||||
|
08/15/2019 LevelX generic code version 5.6. This release includes the
|
||||||
|
following major features:
|
||||||
|
|
||||||
|
Files are modified to fix compiler warnings:
|
||||||
|
demo_filex_nand_flash.c
|
||||||
|
demo_filex_nor_flash.c
|
||||||
|
lx_nand_flash_256byte_ecc_check.c
|
||||||
|
lx_nand_flash_256byte_ecc_compute.c
|
||||||
|
|
||||||
|
|
||||||
|
10/10/2018 LevelX generic code version 5.5. This release includes the following
|
||||||
|
modifications:
|
||||||
|
|
||||||
|
lx_api.h Removed compiler warnings, added extended NOR cache
|
||||||
|
support, new APIs, and new constants.
|
||||||
|
lx_nand_flash_256byte_ecc_check.c Removed compiler warnings.
|
||||||
|
lx_nand_flash_256byte_ecc_compute.c Removed compiler warnings.
|
||||||
|
lx_nand_flash_block_obsoleted_check.c Added logic to mark the beginning of block erase.
|
||||||
|
lx_nand_flash_block_reclaim.c Removed compiler warnings, and added logic to mark
|
||||||
|
the beginning of block erase.
|
||||||
|
lx_nand_flash_logical_sector_find.c Removed compiler warnings, and added logic to use
|
||||||
|
and maintain the last found page.
|
||||||
|
lx_nand_flash_next_block_to_erase_find.c Removed compiler warnings.
|
||||||
|
lx_nand_flash_open.c Added logic to detect start of a block erase that
|
||||||
|
was interrupted, removed system error call for more
|
||||||
|
than one page being obsoleted since this can happen
|
||||||
|
normally, removed compiler warnings, and added logic
|
||||||
|
to initialize the last found page.
|
||||||
|
lx_nand_flash_partial_defragment.c Added file in this release.
|
||||||
|
lx_nand_flash_sector_release.c Removed compiler warnings.
|
||||||
|
lx_nand_flash_sector_write.c Removed compiler warnings.
|
||||||
|
lx_nor_flash_block_reclaim.c Removed direct driver access for erases/reads/writes,
|
||||||
|
removed compiler warnings, and added logic to mark
|
||||||
|
the beginning of block erase.
|
||||||
|
lx_nor_flash_driver_block_erase.c Added file in this release.
|
||||||
|
lx_nor_flash_driver_read.c Added file in this release.
|
||||||
|
lx_nor_flash_driver_write.c Added file in this release.
|
||||||
|
lx_nor_flash_extended_cache_enable.c Added file in this release.
|
||||||
|
lx_nor_flash_logical_sector_find.c Removed direct driver access for reads, removed compiler
|
||||||
|
warnings, and added logic to use and maintain the last
|
||||||
|
found sector/block.
|
||||||
|
lx_nor_flash_next_block_to_erase_find.c Removed compiler warnings, and removed direct driver
|
||||||
|
access for reads.
|
||||||
|
lx_nor_flash_open.c Removed direct driver access for erases/reads/writes,
|
||||||
|
added logic to detect start of a block erase that was
|
||||||
|
interrupted, removed system error call for more than
|
||||||
|
one page being obsoleted since this can happen normally,
|
||||||
|
removed compiler warnings, and added logic to initialize
|
||||||
|
the last found sector/block.
|
||||||
|
lx_nor_flash_partial_defragment.c Added file in this release.
|
||||||
|
lx_nor_flash_physical_sector_allocate.c Removed direct driver access for reads/writes.
|
||||||
|
lx_nor_flash_sector_read.c Removed direct driver access for reads/writes.
|
||||||
|
lx_nor_flash_sector_release.c Removed direct driver access for reads/writes.
|
||||||
|
lx_nor_flash_sector_write.c Removed direct driver access for reads/writes.
|
||||||
|
lx_nor_flash_simulator.c Removed compiler warnings.
|
||||||
|
lx*.c Changed comments and copyright header, and added
|
||||||
|
conditional around disabling ThreadX error checking.
|
||||||
|
lx*.h Changed comments and copyright header.
|
||||||
|
|
||||||
|
05/01/2018 LevelX generic code version 5.4. This release includes the following
|
||||||
|
modifications:
|
||||||
|
|
||||||
|
lx_api.h Added NOR flash RAM buffer, added bit constant
|
||||||
|
for both NOR and NAND flash to indicate when
|
||||||
|
mapping write is valid, added diagnostic counter
|
||||||
|
for tracking when incomplete mapping is detected
|
||||||
|
on open, add added new error code when driver
|
||||||
|
does not supply a sector/page RAM buffer.
|
||||||
|
fx_nand_flash_simulated_driver.c Added error checking, and corrected sector
|
||||||
|
read/write processing.
|
||||||
|
fx_nor_flash_simulator_driver.c Added error checking.
|
||||||
|
lx_nand_flash_block_reclaim.c Added clearing of additional bit to indicate when
|
||||||
|
mapping is valid, and corrected logic that could
|
||||||
|
cause a newly mapped sector to be erased.
|
||||||
|
lx_nand_flash_logical_sector_find.c Added logic to make sure the sector mapping is valid.
|
||||||
|
lx_nand_flash_next_block_to_erase_find.c Added logic to improve search for free sectors.
|
||||||
|
lx_nand_flash_open.c Added logic to detect and handle a mapping entry
|
||||||
|
interrupted before completion, and added logic to
|
||||||
|
ensure there is a page buffer supplied by the
|
||||||
|
driver.
|
||||||
|
lx_nand_flash_sector_release.c Added reclaim logic to help increase free sectors.
|
||||||
|
lx_nand_flash_sector_write.c Added clearing of additional bit to indicate when
|
||||||
|
mapping is valid.
|
||||||
|
lx_nor_flash_block_reclaim.c Added clearing of additional bit to indicate when
|
||||||
|
mapping is valid, added logic to read NOR sector
|
||||||
|
into RAM buffer if direct NOR access is not possible,
|
||||||
|
and corrected logic that could cause a newly mapped
|
||||||
|
sector to be erased.
|
||||||
|
lx_nor_flash_logical_sector_find.c Added logic to make sure the sector mapping is valid.
|
||||||
|
lx_nor_flash_next_block_to_erase_find.c Added logic to improve search for free sectors.
|
||||||
|
lx_nor_flash_open.c Added logic to detect and handle a mapping entry
|
||||||
|
interrupted before completion, and added logic to
|
||||||
|
ensure there is a sector buffer supplied by the
|
||||||
|
driver if LX_DIRECT_READ is not specified.
|
||||||
|
lx_nor_flash_sector_release.c Added reclaim logic to help increase free sectors.
|
||||||
|
lx_nor_flash_sector_write.c Added clearing of additional bit to indicate when
|
||||||
|
mapping is valid, and removed optimization to ensure
|
||||||
|
atomic sector write.
|
||||||
|
lx_nor_flash_simulator.c Added logic to supply RAM buffer for reading
|
||||||
|
sector when LX_DIRECT_READ is not specified,
|
||||||
|
and removed write attempt to already written
|
||||||
|
sector, since this is no longer required.
|
||||||
|
fx*.c Changed comments and copyright header.
|
||||||
|
lx*.c Changed comments and copyright header.
|
||||||
|
lx*.h Changed comments and copyright header.
|
||||||
|
|
||||||
|
11/01/2017 LevelX generic code version 5.3. This release includes the following
|
||||||
|
modifications:
|
||||||
|
|
||||||
|
lx_nand_flash_block_full_update.c Added check to make sure the block is
|
||||||
|
actually full.
|
||||||
|
lx_nand_flash_block_reclaim.c Added support for direct logical sector
|
||||||
|
cache.
|
||||||
|
lx_nand_flash_logical_sector_find.c Added adjustment of mapped sectors when
|
||||||
|
examining the mapped list, added support
|
||||||
|
for direct logical sector cache.
|
||||||
|
lx_nand_flash_open.c Added support for direct logical sector cache,
|
||||||
|
and updated diagnostics.
|
||||||
|
lx_nand_flash_physical_page_allocate.c Added adjustment of the search pointer for
|
||||||
|
next allocate request.
|
||||||
|
lx_nand_flash_sector_mapping_cache_invalidate.c Added support for direct logical sector cache.
|
||||||
|
lx_nand_flash_sector_release.c Added logic to update the page 0 mapping list
|
||||||
|
if present.
|
||||||
|
lx_nand_flash_sector_write.c Added logic to update the page 0 mapping list
|
||||||
|
if present, and added check to make sure the
|
||||||
|
new mapping wasn't moved, added direct logical
|
||||||
|
sector cache.
|
||||||
|
fx*.c Changed comments and copyright header.
|
||||||
|
lx*.c Changed comments and copyright header.
|
||||||
|
lx*.h Changed comments and copyright header.
|
||||||
|
|
||||||
|
03/01/2017 LevelX generic code version 5.2. This release includes the following
|
||||||
|
modifications:
|
||||||
|
|
||||||
|
lx_nand_flash_block_full_update.c Reduced the number of words accessed in
|
||||||
|
page 0, added driver interface layer,
|
||||||
|
and modified the extra bytes usage in
|
||||||
|
page 0 to support block valid-full-empty.
|
||||||
|
lx_nand_flash_block_obsoleted_check.c Added file in this release.
|
||||||
|
lx_nand_flash_block_reclaim.c Added logic to update page 0 on a full
|
||||||
|
block update, added driver interface layer,
|
||||||
|
and added additional diagnostic information.
|
||||||
|
lx_nand_flash_driver_block_erase.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_block_erased_verify.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_block_status_get.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_block_status_set.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_extra_bytes_get.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_extra_bytes_set.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_page_erased_verify.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_read.c Added file in this release.
|
||||||
|
lx_nand_flash_driver_write.c Added file in this release.
|
||||||
|
lx_nand_flash_extended_cache_enable.c Added file in this release.
|
||||||
|
lx_nand_flash_logical_sector_find.c Reduced the number of words accessed in
|
||||||
|
page 0, corrected check for valid sector
|
||||||
|
mapping list, added max mapped sector logic,
|
||||||
|
added driver interface layer, and added logic
|
||||||
|
to use and maintain the last found sector block.
|
||||||
|
lx_nand_flash_next_block_to_erase_find.c Reduced the number of words accessed in page 0,
|
||||||
|
and added driver interface layer.
|
||||||
|
lx_nand_flash_open.c Reduced the number of words accessed in page 0,
|
||||||
|
added driver interface layer, added additional
|
||||||
|
diagnostic information, added logic to initialize
|
||||||
|
the maximum mapped logical sector, and added
|
||||||
|
initialization of the last found sector block.
|
||||||
|
lx_nand_flash_physical_page_allocate.c Reduced the number of words accessed in page 0,
|
||||||
|
added driver interface layer, and added logic
|
||||||
|
to use page 0's extra bytes to determine if
|
||||||
|
block has available pages.
|
||||||
|
lx_nand_flash_sector_read.c Added driver interface layer.
|
||||||
|
lx_nand_flash_sector_release.c Added logic to maintain the maximum mapped
|
||||||
|
sector, and added driver interface layer.
|
||||||
|
lx_nand_flash_sector_write.c Added call to see if the block is completely
|
||||||
|
obsoleted, added logic to remember the maximum
|
||||||
|
mapped sector, and added driver interface layer.
|
||||||
|
fx_nand_flash_simulator_driver.c Removed sector packing by requiring sector and
|
||||||
|
cluster size to match, and added release sector
|
||||||
|
support.
|
||||||
|
fx*.c Changed comments and copyright header.
|
||||||
|
lx*.c Changed comments and copyright header.
|
||||||
|
lx*.h Changed comments and copyright header.
|
||||||
|
|
||||||
|
08/01/2016 LevelX generic code version 5.1. This release includes the following
|
||||||
|
modifications:
|
||||||
|
|
||||||
|
lx_nor_flash_physical_sector_allocate.c Corrected problem with more than 32 sectors per
|
||||||
|
flash block.
|
||||||
|
fx*.c Changed comments and copyright header.
|
||||||
|
lx*.c Changed comments and copyright header.
|
||||||
|
lx*.h Changed comments and copyright header.
|
||||||
|
|
||||||
|
01/22/2015 Initial LevelX generic code version 5.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(regression_test LANGUAGES C)
|
project(regression_test LANGUAGES C)
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
# if threadx repo does not exist, clone it
|
# if threadx repo does not exist, clone it
|
||||||
[ -d threadx ] || git clone https://github.com/azure-rtos/threadx.git --depth 1
|
[ -d threadx ] || git clone https://github.com/eclipse-threadx/threadx.git --depth 1
|
||||||
[ -d filex ] || git clone https://github.com/azure-rtos/filex.git --depth 1
|
[ -d filex ] || git clone https://github.com/eclipse-threadx/filex.git --depth 1
|
||||||
[ -f .run.sh ] || ln -sf threadx/scripts/cmake_bootstrap.sh .run.sh
|
[ -f .run.sh ] || ln -sf threadx/scripts/cmake_bootstrap.sh .run.sh
|
||||||
./.run.sh $*
|
./.run.sh $*
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -21,7 +21,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 +69,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 +141,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 +1283,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);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,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 +73,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 +264,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 +1426,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 +1575,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