Skip to content

SPI Flash: Critical protocol inconsistencies and write verification bug in spi_flash.c #630

Description

@kaabia

Describe the bug

This issue reports several critical inconsistencies and a major logic error in the wolfBOOT SPI Flash driver (src/spi_flash.c) affecting robustness, compliance, and write integrity:

  1. Write Verification Bug: The logic in spi_flash_write_sb used an error-prone method to verify the data write, leading to potential misreporting of successful writes when data corruption might have occurred.

  2. Missing Write Enable (WREN) Protocol: The spi_flash_probe function attempted to write to the Status Register (WRSR) to clear block protection without first issuing the mandatory flash_write_enable() (WREN) command. This is a severe protocol violation, preventing reliable configuration of the flash device.

  3. Robustness Gaps: The erase functions lacked a necessary defensive wait_busy() call immediately following flash_write_enable(), potentially leading to race conditions where the erase operation begins before the command is fully processed.

Area: Drivers, SPI Flash, Protocol Compliance

Steps to reproduce

The bugs are protocol compliance and logic errors verifiable via static code analysis.

Write:

  1. Protocol Violation: Examine spi_flash_probe() and note the missing flash_write_enable() call immediately preceding the WRSR command, violating the standard SPI Flash write protocol.

  2. Verification Bug: Examine spi_flash_write_sb() and observe the non-standard, error-prone verification logic which should be a simple (read_value == written_value).

  3. Robustness Gap: Examine the erase functions and note the missing wait_busy() call after the initial flash_write_enable(), which could lead to unreliable erase operations.

Additional Context

Fix Proposal is presented in the following PR: #627

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions