Skip to content

fix(FrFTL): correct flash page state tracking to prevent unnecessary wear and improve error handling - #7584

Merged
pfeerick merged 3 commits into
mainfrom
richardclli/fix-ftl-wear-level
Aug 4, 2026
Merged

fix(FrFTL): correct flash page state tracking to prevent unnecessary wear and improve error handling#7584
pfeerick merged 3 commits into
mainfrom
richardclli/fix-ftl-wear-level

Conversation

@richardclli

@richardclli richardclli commented Jul 24, 2026

Copy link
Copy Markdown
Member

This fix aligned to the changes in the standalone FTL project: https://github.com/richardclli/Flash-Translation-Layer
The changes already tested against heavy workload of FAT file access and modification based on a set of EdgeTX SDcard images for 1000 rounds to ensure integrity. The testing code is in the standalone project.

Summary by CodeRabbit

  • Bug Fixes
    • Improved flash page state tracking during erase operations, including non-block-aligned cases.
    • Correctly detects when pages are already erased and records the updated state to avoid unnecessary erase requirements.
    • Refined handling of unknown page states during write/trim by deferring erase checks to the point where page state is set.
    • Improved resilience by returning failure promptly when page metadata or required TT buffers cannot be loaded during read/write flows.

@richardclli richardclli self-assigned this Jul 24, 2026
@richardclli richardclli added this to the 2.11.7 milestone Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

FrFTL centralizes erased-page detection, records successful partial erases, validates translation-table loads and page-info reads, and resolves at least 16 translation-table pages during writes and trims. Initialization spacing is adjusted without logic changes.

Changes

FrFTL state and maintenance

Layer / File(s) Summary
Erase state handling
radio/src/drivers/frftl.cpp
ERASE_REQUIRED updates detect already-erased flash, unknown pages defer detection, and successful non-block-aligned erases record the page as ERASED.
Operation state resolution and validation
radio/src/drivers/frftl.cpp
Writes and trims resolve at least 16 translation-table pages; TT/MTT loads and page-info reads now return failure immediately when unavailable.
Initialization formatting
radio/src/drivers/frftl.cpp
Spacing is adjusted in the initialization cleanup region without changing logic.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is relevant and includes testing details, but it omits the required "Fixes #" and "Summary of changes:" sections. Add the required template sections, include the related issue number after "Fixes #", and summarize the specific code changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the FrFTL page-state tracking fix and its goals of reducing wear and improving error handling.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch richardclli/fix-ftl-wear-level

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/drivers/frftl.cpp`:
- Around line 162-166: Remove the redundant isFlashErased probe from the
ERASE_REQUIRED branch in setPhysicalPageState. Reuse the result already obtained
by resolveUnknownState, or introduce a setter variant that accepts the known
erase status, while preserving the existing ERASED transition behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1df9361c-bbb6-4e3f-9b1d-b05aaa122415

📥 Commits

Reviewing files that changed from the base of the PR and between 1b12ee9 and 852a07c.

📒 Files selected for processing (1)
  • radio/src/drivers/frftl.cpp

Comment thread radio/src/drivers/frftl.cpp
@richardclli richardclli added backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also. labels Jul 24, 2026
@richardclli
richardclli force-pushed the richardclli/fix-ftl-wear-level branch from a847f68 to 0bc0bf5 Compare July 24, 2026 07:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/thirdparty/stb`:
- Line 1: Update the radio/src/thirdparty/stb submodule checkout to commit
5c205738, matching the repository’s committed gitlink, and ensure the updated
submodule state is staged and pushed consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 633d4080-41d4-4e73-a3d4-481e3c20efce

📥 Commits

Reviewing files that changed from the base of the PR and between a847f68 and 0bc0bf5.

📒 Files selected for processing (2)
  • radio/src/drivers/frftl.cpp
  • radio/src/thirdparty/stb

Comment thread radio/src/thirdparty/stb Outdated
@richardclli
richardclli force-pushed the richardclli/fix-ftl-wear-level branch from 0bc0bf5 to f65aae1 Compare July 24, 2026 07:43
@richardclli richardclli changed the title fix(FrFTL): Fixes can further reduce wearing level fix(FrFTL): Fix a bug that can reduce wearing level Jul 24, 2026
@richardclli
richardclli marked this pull request as draft July 24, 2026 08:20
@richardclli richardclli changed the title fix(FrFTL): Fix a bug that can reduce wearing level fix(FrFTL): Fix a bug that can reduce wearing level, and some other potential bugs Jul 24, 2026
@richardclli
richardclli marked this pull request as ready for review July 24, 2026 08:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/drivers/frftl.cpp`:
- Around line 701-711: Update lockTTPages so locking and staging
translation-table buffers is failure atomic: when ttPageNo > 0, load and
validate the master page before mutating the initially loaded buffer, or
preserve and restore its prior state if the master load fails. Ensure any false
return leaves both buffers unchanged while retaining the existing successful
locking behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c4d3a36a-04db-4b96-9f8c-91898ba0e567

📥 Commits

Reviewing files that changed from the base of the PR and between f65aae1 and c19c52e.

📒 Files selected for processing (1)
  • radio/src/drivers/frftl.cpp

Comment thread radio/src/drivers/frftl.cpp
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #7586

coderabbitai Bot added a commit that referenced this pull request Jul 24, 2026
Docstrings generation was requested by @coderabbitai[bot].

* #7584 (comment)

The following files were modified:

* `radio/src/drivers/frftl.cpp`
@richardclli
richardclli marked this pull request as draft July 25, 2026 02:02
@richardclli
richardclli marked this pull request as ready for review July 25, 2026 02:05
@richardclli
richardclli force-pushed the richardclli/fix-ftl-wear-level branch from 2b3445b to f732f2d Compare July 25, 2026 03:47
@richardclli

Copy link
Copy Markdown
Member Author

@pfeerick How come code rabbit will automatically generate docstrings for me?

@richardclli
richardclli force-pushed the richardclli/fix-ftl-wear-level branch from f732f2d to f0ec8db Compare July 25, 2026 06:04
@richardclli
richardclli marked this pull request as draft July 27, 2026 04:13
@richardclli
richardclli marked this pull request as ready for review July 27, 2026 05:00
@richardclli

Copy link
Copy Markdown
Member Author

This can merge now, already did extensive load test and everything is intact.

@pfeerick pfeerick changed the title fix(FrFTL): Fix a bug that can reduce wearing level, and some other potential bugs fix(FrFTL): correct flash page state tracking to prevent unnecessary wear and improve error handling Aug 4, 2026
@pfeerick
pfeerick merged commit 992096f into main Aug 4, 2026
42 checks passed
@pfeerick
pfeerick deleted the richardclli/fix-ftl-wear-level branch August 4, 2026 23:33
pfeerick pushed a commit that referenced this pull request Aug 5, 2026
pfeerick pushed a commit that referenced this pull request Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants