Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dataslayermedia/714ec5a9601249d9ee754919dea49c7e to your computer and use it in GitHub Desktop.
Save dataslayermedia/714ec5a9601249d9ee754919dea49c7e to your computer and use it in GitHub Desktop.
Install Coral AI PCIe Edge TPU on Raspberry Pi 5
#!/bin/bash
cd /
sudo apt update
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install libedgetpu1-std
sudo apt install -y devscripts debhelper
sudo apt install dkms
sudo apt-get install dh-dkms
# Clone the Gasket driver repository
sudo git clone https://github.com/google/gasket-driver.git
# Change directory to the cloned repository
cd gasket-driver
# Build the Gasket driver package
sudo debuild -us -uc -tc -b
# Go back to the parent directory
cd ..
# Install the built Gasket driver package
sudo dpkg -i gasket-dkms_1.0-18_all.deb
sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
sudo groupadd apex
sudo adduser $USER apex
# Update the boot configuration for Raspberry Pi
echo "kernel=kernel8.img" | sudo tee -a /boot/firmware/config.txt
# Back up the Device Tree Blob (DTB)
sudo cp /boot/firmware/bcm2712-rpi-5-b.dtb /boot/firmware/bcm2712-rpi-5-b.dtb.bak
# Decompile the DTB into a DTS file
sudo dtc -I dtb -O dts /boot/firmware/bcm2712-rpi-5-b.dtb -o ~/test.dts
# Modify the Device Tree Source (DTS)
sudo sed -i '/pcie@110000 {/,/};/{/msi-parent = <[^>]*>;/{s/msi-parent = <[^>]*>;/msi-parent = <0x67>;/}}' ~/test.dts
# Recompile the DTS back into a DTB
sudo dtc -I dts -O dtb ~/test.dts -o ~/test.dtb
# Replace the old DTB with the new one
sudo mv ~/test.dtb /boot/firmware/bcm2712-rpi-5-b.dtb
sudo reboot now
@MappyMatty
Copy link

MappyMatty commented Apr 17, 2025

I'm using a Raspberry Pi 5 with a Pineboards HatDrive! AI and Google Coral M.2 Accelerator A+E Key.
Unfortunately, this is now a dead link: https://pineboards.io/blogs/tutorials/how-to-configure-the-google-coral-edge-tpu-on-the-raspberry-pi-5
I'm trying to install the gasket driver but it's failing using the following 2 methods.
Method 1:
sudo apt-get install gasket-dkms -y

Error:

Setting up gasket-dkms (1.0-18) ...
Loading new gasket-1.0 DKMS files...
Deprecated feature: REMAKE_INITRD (/usr/src/gasket-1.0/dkms.conf)
Building for 6.12.20+rpt-rpi-v8
Building initial module for 6.12.20+rpt-rpi-v8
Deprecated feature: REMAKE_INITRD (/var/lib/dkms/gasket/1.0/source/dkms.conf)
Error! Bad return status for module build on kernel: 6.12.20+rpt-rpi-v8 (aarch64)
Consult /var/lib/dkms/gasket/1.0/build/make.log for more information.
dpkg: error processing package gasket-dkms (--configure):
 installed gasket-dkms package post-installation script subprocess returned error exit status 10
Errors were encountered while processing:
 gasket-dkms
E: Sub-process /usr/bin/dpkg returned an error code (1)

Contents of the referenced log file:

DKMS make.log for gasket-1.0 for kernel 6.12.20+rpt-rpi-v8 (aarch64)
Thu 17 Apr 21:40:34 BST 2025
make: Entering directory '/usr/src/linux-headers-6.12.20+rpt-rpi-v8'
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_core.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_ioctl.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_interrupt.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_page_table.o
/var/lib/dkms/gasket/1.0/build/gasket_interrupt.c: In function 'gasket_handle_interrupt':
/var/lib/dkms/gasket/1.0/build/gasket_interrupt.c:161:17: error: too many arguments to function 'eventfd_signal'
  161 |                 eventfd_signal(ctx, 1);
      |                 ^~~~~~~~~~~~~~
In file included from /var/lib/dkms/gasket/1.0/build/gasket_interrupt.h:11,
                 from /var/lib/dkms/gasket/1.0/build/gasket_interrupt.c:4:
/usr/src/linux-headers-6.12.20+rpt-common-rpi/include/linux/eventfd.h:87:20: note: declared here
   87 | static inline void eventfd_signal(struct eventfd_ctx *ctx)
      |                    ^~~~~~~~~~~~~~
make[2]: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/scripts/Makefile.build:249: /var/lib/dkms/gasket/1.0/build/gasket_interrupt.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/var/lib/dkms/gasket/1.0/build/gasket_core.c:1375:19: error: 'no_llseek' undeclared here (not in a function); did you mean 'noop_llseek'?
 1375 |         .llseek = no_llseek,
      |                   ^~~~~~~~~
      |                   noop_llseek
/var/lib/dkms/gasket/1.0/build/gasket_core.c: In function 'gasket_register_device':
/var/lib/dkms/gasket/1.0/build/gasket_core.c:1841:41: error: passing argument 1 of 'class_create' from incompatible pointer type [-Werror=incompatible-pointer-types]
 1841 |                 class_create(driver_desc->module, driver_desc->name);
      |                              ~~~~~~~~~~~^~~~~~~~
      |                                         |
      |                                         struct module *
In file included from /usr/src/linux-headers-6.12.20+rpt-common-rpi/include/linux/device.h:31,
                 from /usr/src/linux-headers-6.12.20+rpt-common-rpi/include/linux/cdev.h:8,
                 from /var/lib/dkms/gasket/1.0/build/gasket_core.h:11,
                 from /var/lib/dkms/gasket/1.0/build/gasket_core.c:12:
/usr/src/linux-headers-6.12.20+rpt-common-rpi/include/linux/device/class.h:228:54: note: expected 'const char *' but argument is of type 'struct module *'
  228 | struct class * __must_check class_create(const char *name);
      |                                          ~~~~~~~~~~~~^~~~
/var/lib/dkms/gasket/1.0/build/gasket_core.c:1841:17: error: too many arguments to function 'class_create'
 1841 |                 class_create(driver_desc->module, driver_desc->name);
      |                 ^~~~~~~~~~~~
/usr/src/linux-headers-6.12.20+rpt-common-rpi/include/linux/device/class.h:228:29: note: declared here
  228 | struct class * __must_check class_create(const char *name);
      |                             ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/scripts/Makefile.build:249: /var/lib/dkms/gasket/1.0/build/gasket_core.o] Error 1
make[1]: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/Makefile:1969: /var/lib/dkms/gasket/1.0/build] Error 2
make: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/Makefile:236: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.12.20+rpt-rpi-v8'

Method 2:

git clone https://github.com/google/gasket-driver.git
cd gasket-driver
sudo debuild -us -uc -tc -b
cd ..
sudo dpkg -i gasket-dkms_1.0-18_all.deb

Error:

Setting up gasket-dkms (1.0-18) ...
Loading new gasket-1.0 DKMS files...
Deprecated feature: REMAKE_INITRD (/usr/src/gasket-1.0/dkms.conf)
Building for 6.12.20+rpt-rpi-v8
Building initial module for 6.12.20+rpt-rpi-v8
Deprecated feature: REMAKE_INITRD (/var/lib/dkms/gasket/1.0/source/dkms.conf)
Error! Bad return status for module build on kernel: 6.12.20+rpt-rpi-v8 (aarch64)
Consult /var/lib/dkms/gasket/1.0/build/make.log for more information.
dpkg: error processing package gasket-dkms (--install):
 installed gasket-dkms package post-installation script subprocess returned error exit status 10
Errors were encountered while processing:
 gasket-dkms

Contents of the referenced log file:

DKMS make.log for gasket-1.0 for kernel 6.12.20+rpt-rpi-v8 (aarch64)
Thu 17 Apr 21:48:25 BST 2025
make: Entering directory '/usr/src/linux-headers-6.12.20+rpt-rpi-v8'
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_core.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_ioctl.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_interrupt.o
  CC [M]  /var/lib/dkms/gasket/1.0/build/gasket_page_table.o
/var/lib/dkms/gasket/1.0/build/gasket_core.c:1376:19: error: 'no_llseek' undeclared here (not in a function); did you mean 'noop_llseek'?
 1376 |         .llseek = no_llseek,
      |                   ^~~~~~~~~
      |                   noop_llseek
make[2]: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/scripts/Makefile.build:249: /var/lib/dkms/gasket/1.0/build/gasket_core.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/Makefile:1969: /var/lib/dkms/gasket/1.0/build] Error 2
make: *** [/usr/src/linux-headers-6.12.20+rpt-common-rpi/Makefile:236: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.12.20+rpt-rpi-v8'

I'm not really sure what I'm looking at here but it looks as though the driver is incompatible with the kernel 6.12.20? What can I do to try to resolve this please? Any pointers gratefully received.

@MappyMatty
Copy link

In the morning, with a fresh head and new thoughts, I installed a new clean Linux raspberrypi 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux and did everything as written in https://pineboards.io/blogs/tutorials/how-to-configure-the-google-coral-edge-tpu-on-the-raspberry-pi-5 and wow, everything worked!

pi@raspberrypi:~ $ ls /dev/apex_*
/dev/apex_0  /dev/apex_1

@19leva89 My issue looks similar to yours? Please can you explain how you installed 6.6.31+rpt-rpi-v8? I used Raspberry Pi Imager to install the OS to my SD card and have 6.12.20+rpt-rpi-v8.

@lukaszraczylo
Copy link

@MappyMatty I've noticed the same issue after the kernel upgrade to 6.12.x.
I have attempted the following:

But then kept getting Couldn't reinit interrupts: -524 all the time, so after few hours I decided to run the model interference on CPU until the solution is found 🤷‍♂️

@MappyMatty
Copy link

Thanks @lukaszraczylo. I couldn’t see an open bug relating to gasket driver so I have added bug raspberrypi/linux#6799

@MappyMatty
Copy link

@lukaszraczylo I have built and installed the driver package using info found here: google/gasket-driver#36 which all seemed to work in terms of build and install. I deleted line 1376 .llseek = no_llseek,. However, when I update my Frigate config to use Coral the system doesn't behave - I can't view the System Metrics page to see the inference load switch from the CPU to the TPU, for example. Even login is temperamental. Disable the Coral in the Frigate config and restart Frigate and all back to normal - but with excessive load on the CPU hence trying to get Coral TPU installed.

@lukaszraczylo
Copy link

@MappyMatty That's exactly what I've hit as per my previous comment. dmesg kept throwing the Couldn't reiinit interrupts: -524 so I gave up, for now :)

@PedroViniciusMelo
Copy link

Hello everyone, any news? I'm facing the same problem. Couldn't reiinit interrupts: -524

@vasimv
Copy link

vasimv commented Apr 22, 2025

@MappyMatty I've noticed the same issue after the kernel upgrade to 6.12.x. I have attempted the following:

But then kept getting Couldn't reinit interrupts: -524 all the time, so after few hours I decided to run the model interference on CPU until the solution is found 🤷‍♂️

Got same problem on latest raspberrypi os with latest kernel. But when i've downgraded the kernel to 6.6.74+rpt-rpi-v8 - got it working, thought have to reload apex driver and rescan bus.

@MappyMatty
Copy link

I still have apex 0001.03.00.0: Couldn’t initialize interrupts: -524. I’m using a Pineboards HatDrive! AI with an NVMe drive as well as the Coral. Are others using this same board or other PCIe boards? Could this issue relate to the PCIe switch on the board? Struggling with this and close to giving up and exploring Hailo as an alternative…

@vasimv
Copy link

vasimv commented Apr 23, 2025

I still have apex 0001.03.00.0: Couldn’t initialize interrupts: -524. I’m using a Pineboards HatDrive! AI with an NVMe drive as well as the Coral. Are others using this same board or other PCIe boards? Could this issue relate to the PCIe switch on the board? Struggling with this and close to giving up and exploring Hailo as an alternative…

Well, i was getting same messages (couldn't initialize interrupts: -28 without applying dtoverlay=pineboards-hat-ai and -524 when applied) on 6.12 kernel. But when downgraded kernel to 6.6.74+rpt-rpi-v8 - these errors gone. Only problem is that i have rmmod apex/remove pci-e device/rescan pci/load apex mod after boot to get coral working. I have 52pi PCIe hat M02.

@PedroViniciusMelo
Copy link

PedroViniciusMelo commented Apr 23, 2025

I'm using a hat with two m2 slots from another brand but facing the same problem. Downgrading the kernel to a previous version worked just fine, I'll keep using it for now and never update if possible.

@MappyMatty
Copy link

Thanks. Can you please clarify the kernel downgrade process to 6.6.74+rpt-rpi-v8? Sorry for noob question!
I think I use rpi-config _firmware code_ but I’m confused about how I determine that firmware code.

@PedroViniciusMelo
Copy link

I had problems when downgrading using the sudo apt install --reinstall raspi-firmware given in the official docs Docs, so unfortunatly the easiest way for me was to reinstall the system using the Raspberry PI Imager (the installed version has the compatible kernel)

@vasimv
Copy link

vasimv commented Apr 23, 2025

Thanks. Can you please clarify the kernel downgrade process to 6.6.74+rpt-rpi-v8? Sorry for noob question! I think I use rpi-config _firmware code_ but I’m confused about how I determine that firmware code.

I've did that first time, had nice answer from google ai. But not sure if can be repeated as is. First, you have to install specific version "apt install linux-image-6.6.51+rpt-rpi-v8 linux-image-6.6.51+rpt-rpi-2712". Then set newest kernel on hold - "dpkg --get-selections |grep linux-image" and then "echo 'linux-image-6.12.20+rpt-rpi-v8 hold' | dpkg --set-selections" for both newest kernels. Remove old kernel packages by "apt remove linux-image-6.12.20+rpt-rpi-v8 linux-image-6.12.20+rpt-rpi-2712". And force reinstall old kernel version to get everything updated - "apt install --force linux-image-6.6.51+rpt-rpi-v8 linux-image-6.6.51+rpt-rpi-2712".

Probably good idea to remove gasket-dkms package before doing all of this as it can affect the whole process and install it after.

@MappyMatty
Copy link

Thanks @PedroViniciusMelo and @vasimv. When I create using Raspberry Pi Imager I get 6.12.20 presumably because the hosting RPi is on a later kernel version. I'll try the steps vasimv has outlined once I have some time and can backup my current setup.

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