Skip to content

Instantly share code, notes, and snippets.

@dlareau
Created December 2, 2024 04:11
Show Gist options
  • Save dlareau/726df299369ec6f91c920c0be6f6c98a to your computer and use it in GitHub Desktop.
Save dlareau/726df299369ec6f91c920c0be6f6c98a to your computer and use it in GitHub Desktop.
Installing the Coral dual edge TPU drivers on synology

Driver Installation

Notes

  1. These instructions are provided in a manner that assumes you know what you're doing (at least a little bit). They don't go into extreme detail, and they won't help you troubleshoot if you've broken something.
  2. I'm not responsible if you do break something. Try these instructions at your own risk. They worked for me, and hopefully they'll work for you too.
  3. These instructions are based on my experience doing this for the synology RS1221+. They are somewhat generalized in that I will call out where there are architecture specific choices made, but if they don't work for you because you have a different model, i'm sorry.
  4. There may be a better way to do this. I know my way around a makefile because of an old job I had working in C, but compiling drivers is still kinda foreign to me. If theres some better way to do some part of this (or all of it) I likely didn't do that becuase I didn't know it was an option.

Instructions

Setup

  1. Install Entware. We'll be needing things like gcc, make, etc..., so a package manager is a must and these instructions use Entware. If you have some other way of getting those packages and don't like Entware, you could try that.

I followed the installation instructions here: https://www.technorabilia.com/using-entware-on-synology-nas/ but the commands *I* used for *my* NAS (aka, x86_64 specific) are below.

mkdir -p /volume1/@Entware/opt /opt

mount -o bind /volume1/@Entware/opt /opt

wget -O - http://bin.entware.net/x64-k3.2/installer/generic.sh | /bin/sh

Lastly: set up boot task in scheduler as described by the link
  1. Install packages. We'll need a couple of packages. I installed the following using opkg install because I knew I would need them.
opkg install git git-http gcc

I also installed the following on the reocmmendation for general compilation tools from the Entware wiki. They may or may not be needed, but I installed them, so I'm listing them in case they were used.

opkg install binutils busybox gawk ldd make sed tar

opkg install coreutils-install diffutils ldconfig patch pkg-config --force-overwrite

Making the supporting files

The drivers need certain kernel modules to compile properly.

Note: Looking back on this, maybe all it needed was the source files, but I don't want to troubleshoot others attempts to recreate this effort, so I'm gonna list every step I took even if it might not be needed.

Unless noted otherwise, these steps were all run on my personal computer, not my synology box. I mostly did that because I didn't know what this step would entail, and the enviroment is limited on the synology. It is possible that this could be done on the synology to save the copy step at the end, but I'm not sure.

  1. Download the appropriate linux-4.4.x file.

    a) Visit https://archive.synology.com/download/ToolChain/Synology%20NAS%20GPL%20Source

    b) Select your version of synology software, I used 7.2-64570

    c) Find your version of linux-4.4.x.txz based on your chip. I have an AMD Ryzen V1500 so I use the v1000 file.

  2. Extract the tar file

  3. Copy the appropriate config file out of synoconfigs into `.config. Again because of my chip I ran:

cp synoconfigs/v1000 .config
  1. Fudge the version? This was a bit odd. My synology was on Kernel version 4.4.302+ (you can get this by running uname -r on your machine). The existing files I downloaded were for version 4.4.302. I tried all of this once and was met with an error at the end when inserting the kernel driver because those two didn't match. So what I'm actually documenting here is my second attempt, and in that second attempt, I had to edit line 4 of the Makefile from
EXTRAVERSION = 

to

EXTRAVERSION = +
  1. build it!

    a) Run make menuconfig. This will bring up an interface, but I didn't need to make any changes. Just hit save.

    b) Run make modules. This will take a moment.

  2. Copy over the files. I used tar to bundle the whole linux-4.4.x directory and used scp to copy it over to my synology, but any way you get it over works. Its a NAS after all, you probably have something set up.

  3. Un-tar the directory on the synology, and place it somewhere reasonable.

  4. Link it into place. The latter steps will expect the files to be at /lib/modules/$(uname -r)/build. You could maybe just put the files you brought over into that location, but I knew I was iterating at this point, so I linked them into place using

ln -s /path/to/linux-4.4.x/ /lib/modules/$(uname -r)/build

Build the driver

  1. Get the driver files. The driver we'll be making is the "Gasket" driver, so we'll get the source files by running
git clone https://github.com/google/gasket-driver.git
  1. within the gasket-driver/src directory, run make. It shouldn't take too long and if it worked it should generate the two files we need gasket.ko and apex.ko.

  2. Insert the kernel modules. Run

insmod gasket.ko

insmod apex.ko

There may be some warnings about untrusted kernel modules, that doesn't seem to be an issue.

  1. Check if it worked. Running lsmod | grep gasket should get you something like gasket 79046 11 apex,[permanent], Live 0xffffffffa0089000 (OE) in return, and running ls /dev | grep apex should show the two apex devices (assuming the dual TPU).

Success?

If that all worked, you should now be good to pass those devices /dev/apex_0 and /dev/apex_1 into a docker container (I did all of this to be able to use frigate) or use them however you want.

Note: The insmod commands from the above step 3 do seem to be temporary. I haven't done the research yet if I just need to automate running those commands at boot or if there is a place I can put the .ko files where they will be automatically loaded.

Hopefully this helped someone like me who was sick of being told to give up on using the non-USB TPU I had lying around while the only thing stopping me was a lack of drivers.

@henrykuijpers
Copy link

@dlareau Do you know if this will work on the DS1618+ too? Do I need additional hardware, besides the Coral TPU M.2 B+M?

@dlareau
Copy link
Author

dlareau commented Dec 2, 2024

I don't see any immediate reason it wouldn't. When it comes to architecture specifics, it looks like the DS1618+ uses a Intel Atom C3538 which after some googling means you'll want the "Denverton" file from the synology archive.

If I'm reading the specs right, like mine, your NAS does have a PCIe slot, but no M.2 slot. Which means you'll need the M.2 adapter card:
https://www.bhphotovideo.com/c/product/1569136-REG/synology_m2d20_m_2_adapter_card.html
If you don't already have a reason to have the adapter card, I would unfortunately say that it isn't worth getting it just for this, just getting a USB coral device is cheaper. I went through all the trouble because I already had the M.2 adapter card because of my need for an SSD cache drive.

@dlareau
Copy link
Author

dlareau commented Dec 2, 2024

Oh, apparently this also exists? https://www.makerfabs.com/dual-edge-tpu-adapter.html
That might work with synology, but it would be a gamble. I have no proof it works.

@geozar
Copy link

geozar commented Dec 22, 2024

Hi , thanks for the guide .
Noob question i am at the part that you downoad the linux file (on your pc? what system you run?)
and run the cp command onyour pc ?

@dmekhov
Copy link

dmekhov commented Jan 9, 2025

@dlareau have you face with

scripts/mod/modpost: /lib64/libc.so.6: version `GLIBC_2.38' not found (required by scripts/mod/modpost)

?

@dmekhov
Copy link

dmekhov commented Jan 9, 2025

@dlareau have you face with

scripts/mod/modpost: /lib64/libc.so.6: version `GLIBC_2.38' not found (required by scripts/mod/modpost)

?

ccflags-y += -Wno-error=implicit-int in Makefile with build on my PC solved it

@dmekhov
Copy link

dmekhov commented Jan 10, 2025

And if you build everything at PC - you don't need Entware and etc on your NAS.
You can just copy compiled drivers from PC to NAS

@DimaGepard
Copy link

Worked for me for DS920+. Thank you!

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