extensions icon indicating copy to clipboard operation
extensions copied to clipboard

[Feature request] GPU driver for Raspberry Pi 4

Open jvanthienen-gluo opened this issue 9 months ago • 14 comments

Enable v3d (or vc4?) driver support for Raspberry Pi 4 to provide /dev/dri access, required for graphical applications (e.g., Flutter apps via flutter-pi) running in containers with /dev/dri mapped as a volume.

Proposed Implementation:

  1. Customize the kernel with CONFIG_DRM_V3D=m in config-arm64.
  2. Develop a module/extension here to implement the v3d driver.

Note: These are initial estimates with limited knowledge of this codebase and may require further investigation/validation.

jvanthienen-gluo avatar Mar 05 '25 17:03 jvanthienen-gluo

That's a good plan, you can see recent PR to pkgs/extensions which add nfsd driver as an example.

smira avatar Mar 05 '25 17:03 smira

Tried implementing it. It still needs testing. I'm currently trying to build a custom image for testing the v3d functionallity.

Relevant pkgs PR: https://github.com/siderolabs/pkgs/pull/1182 Relevant extensions PR: https://github.com/siderolabs/extensions/pull/643

jvanthienen-gluo avatar Mar 11 '25 10:03 jvanthienen-gluo

I can't seem to get the GPU to work (getting /dev/dri to be available). There is probably and hopefully something small I'm looking over.

I enabled the usage of vc4 and v3d as a kernel module in the kernel in the pkgs repository:

Relevant pkgs fork: https://github.com/jvanthienen-gluo/pkgs

# kernel/build/config-arm64
CONFIG_DRM_V3D=m
CONFIG_DRM_VC4=m
CONFIG_DRM_VC4_HDMI_CEC=y

Secondly I created an extension that implements these 2 kernel modules:

Relevant extensions fork: https://github.com/jvanthienen-gluo/extensions

kernel/drivers/gpu/drm/v3d/v3d.ko
kernel/drivers/gpu/drm/vc4/vc4.ko

Then I looked into the sbc-raspberrypi overlay for overlaying the correct firmware files:

Relevant repository: https://github.com/siderolabs/sbc-raspberrypi

When enabling dtoverlay=vc4-kms-v3d, I can see that the output of the display has the correct colors, so this does something. But /dev/dri isn't available either.

There is one thing I noticed that may need further investigation: There are no vc4 or v3d kernel logs. Not even with a kernel with build-in vc4 and v3d.

jvanthienen-gluo avatar Mar 13 '25 08:03 jvanthienen-gluo

if compiled as modules it needs to be loaded explicity via .machine.kernel.modules

frezbo avatar Mar 13 '25 09:03 frezbo

Good point, I didn't do that yet. But that doesn't explain why running a kernel with build-in vc4 and v3d doesn't work either?

Build-in kernel config:

# kernel/build/config-arm64
CONFIG_DRM_V3D=y
CONFIG_DRM_VC4=y
CONFIG_DRM_VC4_HDMI_CEC=y

jvanthienen-gluo avatar Mar 14 '25 08:03 jvanthienen-gluo

I’m working on this system extension for Talos Linux to add dtoverlay=vc4-kms-v3d to the Raspberry Pi’s config.txt file for GPU support. What’s the recommended approach for implementing this as an extension? Would it be best to include a script to modify the boot partition on first boot (I don't like this approach), or is there a more integrated method of overlaying/appending to the config.txt file? The boot partition is harder to modify I think from a System Extension standpoint? Any advice or examples would be greatly appreciated. Thanks!

jvanthienen-gluo avatar Mar 21 '25 14:03 jvanthienen-gluo

config.txt is managed by https://github.com/siderolabs/sbc-raspberrypi, and it even supports customizing it on image build.

smira avatar Mar 21 '25 14:03 smira

Yes that is correct, I currently do the following in the profile for the imager, and this works:

...
overlay:
  name: rpi_generic
  image:
    imageRef: ghcr.io/siderolabs/sbc-raspberrypi:v0.1.3
  options:
    configTxtAppend: dtoverlay=vc4-kms-v3d
...

However, I don't see how I translate it to an system extension, to enable/disable this config line (as a system extension).

jvanthienen-gluo avatar Mar 21 '25 14:03 jvanthienen-gluo

You can't do that as a system extension, only via the SBC repo. You might add a flag "gpu: true" or something more simple, but SBC doesn't know about system extensions and vice versa.

smira avatar Mar 21 '25 14:03 smira

Ok I see, so it's on the image level only, no way around it? Maybe it's a better idea to create 2 targets for the raspberry pi 4 then? One without the GPU support and one with GPU support? So a user can select from within Sidero Labs Omni Raspberry Pi 4 Model B and Raspberry Pi 4 Model B GPU and can then enable/disable the system extension or have this be integrated by default on the GPU image? I'm just thinking off the top of my head.

jvanthienen-gluo avatar Mar 21 '25 14:03 jvanthienen-gluo

Right now there's no such support. I think documentation might be a better way for now, later on we can think of making "packages" which bundle options and extensions, for example.

smira avatar Mar 21 '25 14:03 smira

Alright, firmware wise this is indeed fine for now. Only issue is that a user cannot (conveniently) add the extra overlay options from within Omni and only via the Imager or Image Factory itself.

But a user can currently create a suitable image when copying the kernel parameters from Omni and using configTxtAppend: dtoverlay=vc4-kms-v3d in the Imager or Image Factory.

I will mention this in the description of the System Extension. Documentation will be added here as an extra example of a Pi 4 image with GPU + System Extension?

jvanthienen-gluo avatar Mar 21 '25 15:03 jvanthienen-gluo

Probably here.

smira avatar Mar 21 '25 15:03 smira

Update: Relevant pkgs PR: https://github.com/siderolabs/pkgs/pull/1196 Relevant extensions PR: https://github.com/siderolabs/extensions/pull/659

Relevant docs PR: https://github.com/siderolabs/talos/pull/10622

jvanthienen-gluo avatar Mar 27 '25 14:03 jvanthienen-gluo