Skip to content

Fix Pi 5 driver selection crash when only libgpiod.so.3 is installed#2490

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-inconsistent-behavior-pi5
Open

Fix Pi 5 driver selection crash when only libgpiod.so.3 is installed#2490
Copilot wants to merge 3 commits intomainfrom
copilot/fix-inconsistent-behavior-pi5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

The RaspberryPi5 case in GetBestDriverForBoardOnLinux() hardcodes LibGpiodDriver.GetAvailableChips() (V1 ABI, requires libgpiod.so.2), which crashes on recent Pi OS images that only ship libgpiod.so.3. Meanwhile, unmapped Pi 5 revisions fall through to UnixDriver.Create() which handles this gracefully — so rev 1.0 crashes but rev 1.1 works.

Changes

  • GpioController.cs: Pi 5 case now uses GpioDriver.TryCreate() to try LibGpiodDriver (V1) first, then fall back to LibGpiodV2Driver (V2 ABI), reusing the same common function already used by UnixDriver.Create(). A small CreatePi5Driver helper finds the RP1 chip (54 lines) and creates the driver via a factory delegate.
  • RaspberryBoardInfo.cs: Added firmware code 0x4171 (Pi 5 rev 1.1) to the RaspberryPi5 mapping so it gets proper Pi 5 driver selection instead of falling through to Unknown
// Before: crashes if libgpiod.so.2 is missing
var chips = LibGpiodDriver.GetAvailableChips();

// After: uses GpioDriver.TryCreate() to try V1, then V2
if (GpioDriver.TryCreate(() => CreatePi5Driver(LibGpiodDriver.GetAvailableChips(), id => new LibGpiodDriver(id)), out GpioDriver? pi5Driver))
{
    return pi5Driver;
}

if (GpioDriver.TryCreate(() => CreatePi5Driver(LibGpiodV2Driver.GetAvailableChips(), id => new LibGpiodV2Driver(id)), out pi5Driver))
{
    return pi5Driver;
}

…so.3 is installed

- Add Pi 5 rev 1.1 firmware code (0x4171) to board model mapping
- Fix Pi 5 driver selection to try LibGpiodDriver (V1/libgpiod.so.2) first,
  then fall back to LibGpiodV2Driver (V2/libgpiod.so.3), matching the
  graceful fallback pattern used elsewhere in the codebase

Agent-Logs-Url: https://github.com/dotnet/iot/sessions/a5e2c635-cb09-4a00-a38e-62450f138d7a

Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
@dotnet-policy-service dotnet-policy-service Bot added the area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins label Apr 2, 2026
Copilot AI changed the title [WIP] Fix inconsistent behavior for Pi 5 rev 1.0 and 1.1 Fix Pi 5 driver selection crash when only libgpiod.so.3 is installed Apr 2, 2026
Copilot AI requested a review from krwq April 2, 2026 16:29
Copilot finished work on behalf of krwq April 2, 2026 16:29
@pgrawehr
Copy link
Copy Markdown
Contributor

@copilot Instead of duplicating the logic of GpioDriver.Create() try to use a common function.

…of duplicating try/catch logic

Agent-Logs-Url: https://github.com/dotnet/iot/sessions/935a874e-b4c1-454d-ae3d-f30aa5eb8da6

Co-authored-by: pgrawehr <13809874+pgrawehr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 11, 2026

@copilot Instead of duplicating the logic of GpioDriver.Create() try to use a common function.

Refactored in d2c526b to use GpioDriver.TryCreate() with a small CreatePi5Driver helper, matching the same pattern as UnixDriver.Create(). The manual try/catch blocks are gone.

Copilot AI requested a review from pgrawehr April 11, 2026 13:23
@krwq krwq marked this pull request as ready for review April 16, 2026 15:35
@krwq krwq enabled auto-merge (squash) April 16, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behavior for Pi 5 rev 1.0 vs 1.1 when only libgpiod.so.3[.x.x] is installed

4 participants