Hacking linux for your sound card

Moderator: flatmax

Post Reply
flatmax
Posts: 603
Joined: Sat Jul 23, 2016 11:39 pm

Hacking linux for your sound card

Post by flatmax » Wed Oct 04, 2017 7:32 am

You want to hack Linux so that you can mod your sound card machine driver OR codec ... perhaps you want to create your own sound card ?

This post will detail how to align your Linux kernel source code to your running kernel version (on your Pi). It will then give the commands to cross compile (build) the system on your desktop. It then gets you on the path of installing the compiled code into your Pi's file system so that it loads and runs.

In this case, we will talk about recompiling the Audio Injector Octo machine driver.

Fist thing is to install build prereqs on your build computer like this (on debian or ubuntu) :

Code: Select all

sudo apt install gcc-arm-linux-gnueabihf
Find which linux version you are using on the Pi (ssh to your Pi and execute the following) :

Code: Select all

cat /proc/version
Clone the linux kernel from github for the Pi :

Code: Select all

git clone https://github.com/raspberrypi/linux.git
Change to the linux directory which you just downloaded :

Code: Select all

cd linux
Now here is the first trick. You need to be using the same source code as the linux version on your Pi. So lets find the suitable Linux version and its matching github commit. Lets say for example you had version 4.9.45 :

Code: Select all

$ ssh pi@192.168.0.114 'cat /proc/version'
Linux version 4.9.45-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #1031 SMP Fri Aug 25 19:02:16 BST 2017
You need to find the linux commit for version 4.9.45. You can do that by scrolling through the history, here is where I found it :

Code: Select all

https://github.com/raspberrypi/linux/commits/rpi-4.9.y?after=8af328b2e65c58f5d7153b03a18f314a371c8fd1+349
I then click on the history item "Linux 4.9.45" and copy the commit code on the right : 3ce72830a8c8bba33c37ebe4bee71ac3177451b0
I can now checkout the correct linux source code version to match my kernel :

Code: Select all

git checkout 3ce72830a8c8bba33c37ebe4bee71ac3177451b0
OK at this point, the source code matches the kernel version. I can now compile the kernel like so. First configure the build :

Code: Select all

export KERNEL=kernel7
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
Now compile the kernel (add argument -j 4 to speed up the build) :

Code: Select all

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
Once it compiles, modify the driver as you like and compile it again.

Once you are happy and want to test it out, you need to copy the ko module over to the Pi. I do it like so :

Code: Select all

export VER='4.9.45'
export HOST='192.168.0.114'
scp ./sound/soc/bcm/snd-soc-audioinjector-octo-soundcard.ko pi@$HOST:
ssh pi@$HOST 'sudo mv snd-soc-audioinjector-octo-soundcard.ko /lib/modules/'$VER'-v7+/kernel/sound/soc/bcm/'
You have now copied over the kernel module and put it into place on the system for it to be loaded. At this point you can either rmmod and modprobe again or simply reboot ...

Code: Select all

ssh pi@$HOST 'sudo reboot'
There you go, you should be running your new kernel module for the octo. If you want to be sure, add output to the module which you can see in dmesg.

Matt
Checkout the next kickstarter campaign - the Ultra 2 : https://kck.st/2xwM3DL
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

ScottJones
Posts: 5
Joined: Mon Dec 04, 2017 7:21 pm

Re: Hacking linux for your sound card

Post by ScottJones » Thu Jan 04, 2018 2:16 pm

This post is really helpful for me. I was not knowing how to hack Linux for my sound card. The best thing I liked is your way of giving instructions. I am really satisfied with the set of instructions given by you. Check out the post right here. I was able to align my Linux kernel source code to the running kernel version.

Ivan
Posts: 11
Joined: Thu Jan 11, 2018 10:33 pm

Re: Hacking linux for your sound card

Post by Ivan » Sun Jan 14, 2018 12:48 pm

I just purchased one of your octo cards.
do you have a ready-to-go image for the raspberry pi so I can download and be sure the sd card is optimally configured for your board without having to go through all these steps and not be 100% sure things will work out right?

flatmax
Posts: 603
Joined: Sat Jul 23, 2016 11:39 pm

Re: Hacking linux for your sound card

Post by flatmax » Mon Jan 15, 2018 8:25 pm

Ivan wrote:
Sun Jan 14, 2018 12:48 pm
I just purchased one of your octo cards.
do you have a ready-to-go image for the raspberry pi so I can download and be sure the sd card is optimally configured for your board without having to go through all these steps and not be 100% sure things will work out right?
Hi there,
Thanks for purchasing.
This thread isn't for the standard Octo setup.

There is an automated setup package available which makes it easy, please see these instructions for the Octo here :
http://forum.audioinjector.net/viewtopic.php?f=9&t=1222

thanks
Matt
Checkout the next kickstarter campaign - the Ultra 2 : https://kck.st/2xwM3DL
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests