Skip to content

steami: Fix READ_SECTOR command argument length and address.#1

Merged
nedseb merged 4 commits intorelease_letssteamfrom
fix/read-sector-bugs
Mar 16, 2026
Merged

steami: Fix READ_SECTOR command argument length and address.#1
nedseb merged 4 commits intorelease_letssteamfrom
fix/read-sector-bugs

Conversation

@nedseb
Copy link
Copy Markdown

@nedseb nedseb commented Mar 16, 2026

Summary

Three bugs in the STeaMi flash I2C bridge that affect data integrity:

Bug 1: READ_SECTOR argument length mismatch (steami32.c)

The I2C layer expects 2 argument bytes for READ_SECTOR, but the task handler checks task_rx_len == 1. Since task_rx_len is always 2, the command always fails.

Fix: Check task_rx_len == 2 and reconstruct sector number from both bytes.

Bug 2: READ_SECTOR hardcoded address (steami_flash.c)

steami_flash_read_sector() ignores sector_number and always reads from address 0.

Fix: Use sector_number * STEAMI_FLASH_SECTOR as the read offset.

Bug 3: WRITE_DATA page boundary corruption (steami32.c)

In TASK_WRITE_DATA_WRITE, bytes_wrote is a local variable reinitialized to 0 on each 30ms hook call. When a write crosses a 256-byte flash page boundary, append_file writes only the remaining bytes in the current page. On the next hook iteration, bytes_wrote is 0 again, so the remaining data is written from the start of the buffer instead of the correct offset. This causes data corruption every ~256 bytes.

Fix: Replace local bytes_wrote with a persistent task_rx_offset variable, reset when a new WRITE_DATA command arrives.

Impact: ~1 line in 12 is corrupted in a typical CSV write workload (22-byte lines, 256-byte pages).

Related

Test plan

  • Build firmware for STeaMi board
  • Flash updated DAPLink firmware
  • Write a test file via I2C (WRITE_DATA command)
  • Read back sectors via READ_SECTOR and verify content matches
  • Verify no data corruption at page boundaries with 300-row CSV test

@nedseb nedseb requested a review from Copilot March 16, 2026 12:58
@nedseb nedseb self-assigned this Mar 16, 2026
@nedseb nedseb added the bug Something isn't working label Mar 16, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the READ_SECTOR I2C command so it can correctly select and read the requested 256-byte sector/page from external flash, aligning the task handler with the I2C layer’s declared argument length.

Changes:

  • Fix TASK_READ_SECTOR to accept 2 argument bytes and reconstruct a 16-bit sector number.
  • Fix steami_flash_read_sector() to use sector_number when computing the flash read address/length.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
source/board/steami/steami_flash.c Reads the correct flash address for the requested sector instead of always reading from 0.
source/board/steami/steami32.c Updates READ_SECTOR task handling to accept 2 bytes and interpret them as a sector number.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/board/steami/steami32.c Outdated
Comment thread source/board/steami/steami_flash.c Outdated
- Use STEAMI_FLASH_SECTOR constant instead of hardcoded 256 for TX data length
- Use STEAMI_FLASH_FILE_ADDR base offset in steami_flash_read_sector for consistency
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 633cc4d697

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread source/board/steami/steami_flash.c
Limit sector_number bound check to STEAMI_FLASH_FILE_SIZE / STEAMI_FLASH_SECTOR
(32752) instead of STEAMI_FLASH_NB_SECTOR (32768) to prevent reading into the
reserved filename sector.
@nedseb nedseb merged commit 270b2f1 into release_letssteam Mar 16, 2026
@nedseb nedseb deleted the fix/read-sector-bugs branch March 16, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants