Skip to content

Update stale Build HAT firmware and make version/signature reads timing-independent#2554

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-build-hat-firmware-error
Draft

Update stale Build HAT firmware and make version/signature reads timing-independent#2554
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-build-hat-firmware-error

Conversation

Copilot AI commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Instantiating a Brick throws IOException: BuildHat firmware signture error from GetBuildHatInformation(), even when the Python library has already flashed firmware. Two causes: the firmware bundled with the binding is stale (2021), and version/signature parsing depends on serial timing that breaks on faster boards (e.g. Raspberry Pi 5).

Changes

  • Refreshed bundled firmware (src/devices/BuildHat/data/{firmware.bin,signature.bin,version}) to the current official build 1737564117 (2025-01-22), matching the binaries shipped by RaspberryPiFoundation/python-build-hat (md5sums verified identical).
  • Made GetRawVersion/GetRawSignature timing-independent. They previously used ReadExisting / a fixed count of ReadLine calls, which races against the device on fast hosts. They now read whole lines (blocking on the \r\n terminator) until the expected marker appears, skipping interleaved echo, prompt, and asynchronous port lines — the same strategy the Python library uses.
private string GetRawSignature()
{
    PortWrite("signature\r");
    return PortReadUntil(FirmwareSignature);
}

// Reads lines until one contains the marker, tolerating echo/prompt/async lines.
private string PortReadUntil(string marker)
{
    const int MaximumLines = 10;
    string line = string.Empty;
    for (int i = 0; i < MaximumLines; i++)
    {
        line = PortReadLine();
        if (line.Contains(marker))
        {
            break;
        }
    }

    return line;
}

Notes

  • Contains (not StartsWith) is kept deliberately, consistent with the existing marker checks in this file and safe if the firmware prepends a prompt to the answer line.
  • Build HAT firmware is only auto-flashed from the bootloader; a device already running older firmware is not re-flashed (matches current behavior). Version-mismatch re-flashing is out of scope here.

@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jun 2, 2026
Copilot AI changed the title [WIP] Fix Build HAT firmware signature error on initialization Update stale Build HAT firmware and make version/signature reads timing-independent Jun 2, 2026
Copilot AI requested a review from raffaeler June 2, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is the Raspberry Pi Build HAT firmware in this repository stale?

2 participants