Skip to content

Flashing refactoring#269

Merged
superg merged 3 commits intomainfrom
flashing_refactoring
Aug 2, 2025
Merged

Flashing refactoring#269
superg merged 3 commits intomainfrom
flashing_refactoring

Conversation

@superg
Copy link
Owner

@superg superg commented Aug 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced new firmware flashing support for TSST and SD616 drives.
    • Added a command for flashing SD-616F/T drive firmware.
  • Improvements

    • Updated flashing command descriptions for clarity in usage output.
    • Enhanced command handling for drive flashing operations.
  • Bug Fixes

    • Standardized naming for TSST flashing modes and related structures for consistency.
  • Other

    • Removed legacy MT1339 flashing implementation and replaced it with updated TSST-based logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 2, 2025

Walkthrough

This change refactors the firmware flashing logic for supported drives by removing the combined MT1339/SD616 flashing module and introducing two new modules: one for TSST protocol flashing and another specifically for SD616. Associated enums and struct names are updated for consistency, and command-handler mappings are revised accordingly.

Changes

Cohort / File(s) Change Summary
CMake Source List Update
CMakeLists.txt
Updated build sources: removed flash_mt1339.ixx, added flash_tsst.ixx and flash_sd616.ixx.
Removed MT1339/SD616 Flash Module
drive/flash_mt1339.ixx
Deleted module containing MT1339 and SD616 flashing logic and related exported functions.
New SD616 Flash Module
drive/flash_sd616.ixx
Added new module with exported function for SD616 firmware flashing and data rearrangement.
New TSST Flash Module
drive/flash_tsst.ixx
Added new module with TSST protocol firmware flashing logic and exported functions.
Command Handler and Import Updates
redumper.ixx
Updated imports and command-handler mappings to use new flash modules; changed "dump" command flag.
Enum/Struct Renaming for Consistency
scsi/mmc.ixx, scsi/cmd.ixx
Renamed FLASH_Tsst_ModeFLASH_TSST_Mode, CDB12_FlashTsstCDB12_FlashTSST, and updated enumerator names for clarity.
Usage String Updates
options.ixx
Revised usage descriptions for flash commands; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Context
    participant Options
    participant drive.flash.tsst
    participant drive.flash.sd616
    participant scsi.cmd

    User->>CLI: Invoke "flash::mt1339" or "flash::sd616"
    CLI->>Context: Prepare context
    CLI->>Options: Parse options
    alt flash::mt1339
        CLI->>drive.flash.tsst: redumper_flash_tsst(ctx, options)
        drive.flash.tsst->>scsi.cmd: flash_tsst(..., END_256KB)
    else flash::sd616
        CLI->>drive.flash.sd616: redumper_flash_sd616(ctx, options)
        drive.flash.sd616->>drive.flash.tsst: flash_tsst(..., END_128KB)
        drive.flash.tsst->>scsi.cmd: flash_tsst(...)
    end
    scsi.cmd-->>drive.flash.tsst: Status
    drive.flash.tsst-->>CLI: Success/Failure
    drive.flash.sd616-->>CLI: Success/Failure
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Add flashing for SD-616F/T #267: Refactored flashing logic by splitting the original MT1339 module into TSST and SD616 modules, directly aligning with the current modularization and command-handler updates.

Poem

In the warren of code, the modules split anew,
MT1339 hops aside, and TSST shines through.
SD616, now with its own burrow,
Enum names crisp as a carrot in the snow.
With flashing commands mapped and tidy,
This rabbit reviews with whiskers spry and sprightly! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20b6755 and 833186e.

📒 Files selected for processing (1)
  • drive/flash_sd616.ixx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • drive/flash_sd616.ixx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build (macos-14, 64)
  • GitHub Check: build (ubuntu-24.04, 64)
  • GitHub Check: build (ubuntu-24.04, 32)
  • GitHub Check: build (windows-2022, 64)
  • GitHub Check: build (windows-2022, 32)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch flashing_refactoring

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
drive/flash_sd616.ixx (1)

26-28: Verify firmware file size check.

The size check validates against 0x20000 (128KB) but the error message mentions "128Kb" (lowercase 'b'). While technically correct, consider using "128KB" for consistency with the hex constant and standard binary notation.

-        throw_line("failed to flash firmware, file is not 128Kb");
+        throw_line("failed to flash firmware, file is not 128KB");
drive/flash_tsst.ixx (2)

33-33: Verify mode selection logic.

The ternary operator chain for mode selection is correct but dense. Consider breaking it down for better readability:

-        FLASH_TSST_Mode mode = offset == 0 ? FLASH_TSST_Mode::START : (offset_next < firmware_data.size() ? FLASH_TSST_Mode::CONTINUE : end_mode);
+        FLASH_TSST_Mode mode;
+        if (offset == 0) {
+            mode = FLASH_TSST_Mode::START;
+        } else if (offset_next < firmware_data.size()) {
+            mode = FLASH_TSST_Mode::CONTINUE;
+        } else {
+            mode = end_mode;
+        }

51-51: Document the block size rationale.

The comment mentions the block size is from "the original flasher" but doesn't specify which device or protocol. Consider adding more context about why this specific value (0xFC00 = 64512 bytes) was chosen.

-    // block size is how much data is sent in one command, potentially it can vary but current value is taken from the original flasher
+    // block size is how much data is sent in one command, potentially it can vary
+    // current value (64512 bytes) is taken from the original MT1339 flasher
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0946425 and 20b6755.

📒 Files selected for processing (8)
  • CMakeLists.txt (1 hunks)
  • drive/flash_mt1339.ixx (0 hunks)
  • drive/flash_sd616.ixx (1 hunks)
  • drive/flash_tsst.ixx (1 hunks)
  • options.ixx (1 hunks)
  • redumper.ixx (2 hunks)
  • scsi/cmd.ixx (1 hunks)
  • scsi/mmc.ixx (1 hunks)
💤 Files with no reviewable changes (1)
  • drive/flash_mt1339.ixx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build (macos-14, 64)
  • GitHub Check: build (ubuntu-24.04, 32)
  • GitHub Check: build (ubuntu-24.04, 64)
  • GitHub Check: build (windows-2022, 64)
  • GitHub Check: build (windows-2022, 32)
🔇 Additional comments (12)
scsi/mmc.ixx (2)

815-821: LGTM! Improved naming consistency and clarity.

The renaming from FLASH_Tsst_Mode to FLASH_TSST_Mode improves consistency, and the enum value changes (END_SAMSUNGEND_128KB, ENDEND_256KB) make the purpose more explicit and descriptive.


824-835: LGTM! Consistent struct naming.

The struct rename from CDB12_FlashTsst to CDB12_FlashTSST maintains consistency with the enum naming changes above.

CMakeLists.txt (1)

139-140: LGTM! Good modularization approach.

Replacing the single drive/flash_mt1339.ixx with separate drive/flash_tsst.ixx and drive/flash_sd616.ixx modules improves separation of concerns and aligns with the refactoring objectives.

redumper.ixx (3)

29-29: LGTM! Import aligns with new module structure.

Adding the import for drive.flash.sd616 is consistent with the modular refactoring approach.


151-151: LGTM! Command handler updated correctly.

The command handler for "flash::mt1339" correctly uses redumper_flash_tsst from the new TSST flashing module.


139-139: Verify the dump command GENERATE flag change.

The dump command's GENERATE flag changed from false to true. This change is not mentioned in the AI summary and appears unrelated to the flashing refactoring. Please confirm this change is intentional.

Likely an incorrect or invalid review comment.

options.ixx (1)

354-355: LGTM! Improved command descriptions.

The updated descriptions are more concise and grammatically correct, changing from "drive firmware flasher Firmwares" to "flashes drive firmware".

scsi/cmd.ixx (1)

547-555: LGTM! Type names updated consistently.

The function correctly uses the renamed types FLASH_TSST_Mode and CDB12_FlashTSST to maintain consistency with the changes in scsi/mmc.ixx. The function logic remains unchanged.

drive/flash_sd616.ixx (2)

37-37: LGTM: Proper integration with flash_tsst.

The call to flash_tsst correctly uses the rearranged firmware data, appropriate block size (64KB), and the correct mode (END_128KB) for SD616 devices.


30-35: Critical: Confirm firmware data rearrangement aligns with SD616 specification

File: drive/flash_sd616.ixx
Lines: 30–35

    // rearrange firmware data to match the expected layout
    std::vector<uint8_t> firmware_data(0x30000);
    std::copy(firmware_file.begin(), firmware_file.begin() + block_size, firmware_data.begin());
    std::copy(firmware_file.begin() + block_size, firmware_file.begin() + block_size * 2 - 0x800, firmware_data.begin() + block_size + 0x400);
    std::copy(firmware_file.begin() + block_size * 2 - 0x800, firmware_file.begin() + block_size * 2, firmware_data.begin() + block_size * 2);
    std::copy(firmware_file.begin() + block_size + 0x400, firmware_file.begin() + block_size * 2 - 0x800, firmware_data.begin() + block_size * 2 + 0x800);

Summary of observed layout (block_size = 0x10000):

  • firmware_data total size: 0x30000 (192 KB)
  • Copy 1: [0x00000, 0x10000) → [0x00000, 0x10000)
  • Copy 2: [0x10000, 0x1F800) → [0x10400, 0x1FC00) (0xF800 bytes)
  • Copy 3: [0x1F800, 0x20000) → [0x20000, 0x20800) (0x0800 bytes)
  • Copy 4: [0x10400, 0x1F800) → [0x20800, 0x2FC00) (0xF400 bytes)

This produces three 1 KB gaps at:
• [0x10000, 0x10400)
• [0x1FC00, 0x20000)
• [0x2FC00, 0x30000)

Please verify that these offsets, duplicate source ranges, and padding gaps exactly match the SD616 firmware memory map. If they do, add a reference to the layout spec or an inline diagram; otherwise adjust the offsets or merge copy ranges. Also ensure unit tests or validation vectors cover this rearrangement.

drive/flash_tsst.ixx (2)

24-44: LGTM: Well-structured flashing logic with proper error handling.

The flash_tsst function implements a robust flashing protocol with:

  • Proper chunking of firmware data into configurable blocks
  • Correct mode progression (START → CONTINUE → end_mode)
  • Comprehensive error handling with SCSI status checks
  • Progress logging for user feedback

The logic correctly handles edge cases where firmware size is smaller than block size.


46-56: LGTM: Clean wrapper function.

The redumper_flash_tsst function provides a clean interface for MT1339 flashing, properly delegating to the core flash_tsst function with appropriate parameters.

@superg superg merged commit 09e32f0 into main Aug 2, 2025
8 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 7, 2025
This was referenced Dec 6, 2025
@superg superg deleted the flashing_refactoring branch December 12, 2025 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant