Skip to content

Instantly share code, notes, and snippets.

@pszemraj
Last active January 31, 2025 00:42
Show Gist options
  • Save pszemraj/3b7252b346c8a6c9c5630bee8ea5e749 to your computer and use it in GitHub Desktop.
Save pszemraj/3b7252b346c8a6c9c5630bee8ea5e749 to your computer and use it in GitHub Desktop.

raspberry pi amd gpu

https://www.jeffgeerling.com/blog/2024/amd-radeon-pro-w7700-running-on-raspberry-pi

install prereqs

Install all needed dependencies for kernel compilation:

sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev crossbuild-essential-arm64 libelf-dev

This installs the essential packages needed for kernel compilation on Raspberry Pi OS. You should now be able to run make menuconfig successfully.

guide

Based on Jeff Geerling's guide, here are the steps you need to follow:

  1. First, edit the boot config to enable PCIe Gen 3:
sudo nano /boot/firmware/config.txt

Add this line at the bottom:

dtparam=pciex1_gen=3
  1. Install the required package for kernel compilation:
sudo apt install libncurses-dev
  1. Clone and patch the kernel:
git clone --depth=1 https://github.com/raspberrypi/linux
cd linux
wget -O amdgpu-pi5.patch https://github.com/geerlingguy/linux/pull/8.patch
git apply -v amdgpu-pi5.patch
  1. Configure the kernel with menuconfig to enable AMD GPU support:
make menuconfig

You'll need to navigate through the menus to select AMD GPU support.

  1. Compile the kernel (this will take a while):
make -j6 Image.gz modules dtbs
  1. Apply Coreforge's memory optimization:
wget https://gist.githubusercontent.com/Coreforge/91da3d410ec7eb0ef5bc8dee24b91359/raw/b4848d1da9fff0cfcf7b601713efac1909e408e8/memcpy_unaligned.c
gcc -shared -fPIC -o memcpy.so memcpy_unaligned.c
sudo mv memcpy.so /usr/local/lib/memcpy.so
sudo nano /etc/ld.so.preload

Add this line to ld.so.preload:

/usr/local/lib/memcpy.so
  1. Install AMD firmware:
sudo apt install firmware-amd-graphics
  1. Reboot the Pi

Would you like me to explain any of these steps in more detail? For example, I can help walk you through the menuconfig navigation for enabling AMD GPU support.

According to the guide, after saving the menuconfig settings, the next steps are:

  1. Build the kernel (since you're doing this natively on a Pi 5, use):
make -j6 Image.gz modules dtbs
  1. Install the modules:
sudo make -j6 modules_install
  1. Install the kernel and Device Tree blobs (backing up your original kernel):
sudo cp /boot/firmware/$KERNEL.img /boot/firmware/$KERNEL-backup.img
sudo cp arch/arm64/boot/Image.gz /boot/firmware/$KERNEL.img
sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/overlays/
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/
  1. Reboot to use your new kernel:
sudo reboot

Note that the first step (make -j6) will take quite a while on the Pi.

@pszemraj
Copy link
Author

checking 6.6.y

When you clone the kernel repository, you can specify exactly which branch you want. Let me explain how to ensure you're on the right version.

First, let's check what branch you're currently on:

cd linux
git branch

To specifically get the 6.6.y branch that was used for the patch, you'll want to:

  1. Remove your current linux directory (since we want a fresh start):
cd ..
rm -rf linux
  1. Clone specifically the 6.6.y branch:
git clone --depth=1 --branch rpi-6.6.y https://github.com/raspberrypi/linux

The --branch rpi-6.6.y part is crucial here - it tells Git to specifically check out the 6.6.y branch that the patch was designed for. The --depth=1 part means we only get the latest commit from that branch, making the download much faster.

After this, when you apply the patch:

cd linux
wget -O amdgpu-pi5.patch https://github.com/geerlingguy/linux/pull/8.patch
git apply -v amdgpu-pi5.patch

It should work more reliably because you're starting from the same base version that the patch was created against. Would you like to try these steps to get a fresh start with the correct kernel version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment