BuildingKernelModule - Manouchehri/smi2021 GitHub Wiki
Summary
Description of how to build and install the kernel module
Introduction
This document is an attempt to describe how to build and install the kernel module for the EasyCap
device.
If you encounter any problems, please direct your questions to the easycap-somagic mailing-list.
UPDATED Sunday 28. Sept. 2014
This page is outdated! I'm in the process of uploading my kernel-repo to github. You can find it here: https://github.com/jonjonarnearne/smi2021
When the upload is done, you can clone the repo and just skip to BuildingKernelModule#Compile
Prerequisites
All developement and testing of this driver has been done on a computer running OpenSUSE. If you are running another distribution, you'll have to figure out how to install a custom built kernel in your distribution to install the driver.
You will of course also need:
- git
- gcc/make and friends
- wget
- VLC (for testing the device)
- available hard-disk space for the kernel tree
- The firmware for your
EasyCap
device installed in /lib/firmware
NOTE FOR FIRMWARE: The firmware should be called smi2021_3c.bin where 3c should be exchanged for your version of the device.
Documentation
This module will only work on a relative new kernel. I think the module will compile on any kernel version > 3.7.0, but I might be wrong.
If you have the kernel-source for your current kernel, and it's newer than 3.7, you might be able to just build the module without building the whole kernel. I'll come back to how to do that at the end of this document.
Fetch the kernel
If you don't have the kernel source tree on your computer, now is the time to download it.
(This is from http://git.linuxtv.org/media_tree.git)
git clone git://github.com/torvalds/linux.git v4l-dvb
cd v4l-dvb
git remote add linuxtv git://linuxtv.org/media_tree.git
git remote update
git checkout -b media-master remotes/linuxtv/master
This will download the whole kernel, and also the media-tree into a directory called "v4l-dvb" under your current directory.
All commands from here on should be typed while you are in the linux source-tree unless specified otherwise.
If you are already tracking Linus' kernel-tree, or are using your distribution's current kernel-tree, you don't have to download the media-tree, but then you will need up to six additional patches to build the module (These patches should not be necessary after kernel version 3.12)
Download the patch with the smi2021 driver module
I've submitted the latest driver module verison to the linux-media mailing-list on September 9th 2013. This is added to linuxtv.org's patchwork. We just download the patch from there:
wget --no-check-certificate https://patchwork.linuxtv.org/patch/20010/mbox/ -O smi2021v3.patch
You can also download the file from a web-browser, visit this link: https://patchwork.linuxtv.org/patch/20010/
Download as mbox, and make sure to save it into the root of the kernel source-tree, and name it smi2021v3.patch
Add the module to the kernel-tree
Type these commands while you are in the root of the kernel source-tree.
git checkout -b smi2021v3
git am smi2021v3.patch
If you didn't get any error messages, the smi2021 driver should now be added to your kernel source-tree. You can confirm this by checking if you have a folder called smi2021 under drivers/media/usb/
If you downloaded the media-tree, you can now skip to BuildingKernelModule#Compile
Add supporting modules
You can skip this paragraph if you downloaded the media-master tree in the start of this howto
The smi2021 driver is depending on the saa7115 module. I had to add some changes to that module to make the driver work. We will have to download and install 3 or 6 more patches before we can build the kernel.
If your kernel-tree is older than 3.11, you will first need these three patches.
wget --no-check-certificate https://patchwork.linuxtv.org/patch/18233/mbox/ -O saa7115-0001.patch
wget --no-check-certificate https://patchwork.linuxtv.org/patch/18232/mbox/ -O saa7115-0002.patch
wget --no-check-certificate https://patchwork.linuxtv.org/patch/18368/mbox/ -O saa7115-0003.patch
If your kernel-tree is older than 3.12 - and you didn't download the media-master tree - you will need these three patches.
wget --no-check-certificate https://patchwork.linuxtv.org/patch/19535/mbox/ -O saa7115-0004.patch
wget --no-check-certificate https://patchwork.linuxtv.org/patch/19536/mbox/ -O saa7115-0005.patch
wget --no-check-certificate https://patchwork.linuxtv.org/patch/19537/mbox/ -O saa7115-0006.patch
When you have downloaded the needed patches, you apply them to the kernel-tree.
git am saa7115-000*
This should apply all three or six patches.
In module source code hardcoded kernel version check.
If you apply patch - remove that check from smi2021_main.c
string 40-42:
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
# error We only support 3.12 and above series kernels
#endif
You are now ready to compile the kernel.
Compile
First, we copy the configuration of your current kernel.
zcat /proc/config.gz > .config
Then we check that we can compile the smi2021 module
make menuconfig
Device drivers --->
Multimedia support --->
Media USB Adapters --->
Find the entry called "Somagic SMI2021 USB video/audio capture support
".
Check that it's marked with <M>
, if not, press m
to mark it as a module or y
to compile it into the kernel.
Check the config for other options you would like, exit and save the config.
Now, type make.
make
or if you have a computer with more processors, type
make -j4
where the number after -j
should be the number of processors you have +1.
This will eat all resources, and speed up the compile.
Now, just wait, and hope you've done everything correct (and that I didn't forget anything).
When the compile ends, and there are no errors, we install the modules.
sudo make modules_install
This should complete in a few minutes, and then we are ready to install the kernel.
Install the new kernel
THIS IS DISTRIBUTION SPECIFIC, I CAN ONLY SHOW HOW THIS IS DONE FOR OpenSUSE
The kernel binary is hidden in arch/x86/boot/
and is called bzImage.
Grub-conf needs this file to have a specific name.
The version numbers we add to the files should of course be changed so they match the version of the kernel you are compiling 3.11.0-rc7 is just an example
First we copy this file to the current directory so we can rename it.
cp arch/x86/boot/bzImage .
mv bzImage vmlinuz-3.11.0-rc7-0.0-smi2021
We also need the file called System.map to have this version number
cp System.map System.map-3.11.0-rc7-0.0-smi2021
Then we move the files to /boot
sudo mv vmlinuz-3.11.0-rc7-0.0-smi2021 /boot
sudo mv System.map-3.11.0-rc7-0.0-smi2021 /boot
Now we need to make the initrd (ramdisk)
cd /boot
sudo mkinitrd -v -k vmlinuz-3.11.0-rc7-0.0-smi2021 -i initrd-3.11.0-rc7-0.0-smi2021 -M /boot/System.map-3.11.0-rc7-0.0-smi2021
Then we add this kernel to grub
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-mkconfig should detect the new kernel and add it to the configurations.
You can now reboot your computer. Make sure you select the correct kernel from the grub menu.
After the computer has booted, you can insert your EasyCap
device, and you should see a message like this in the kernel log (dmesg
):
smi2021 2-1.1:1.0: Somagic Easy-Cap Video Grabber
Compile smi2021 module only
This is how you just compile the module, without having to compile the whole kernel.
This will only work if the kernel source-tree is the same version as the kernel you are currently running
First you will need to patch your kernel tree with the smi2021v3.patch, and the three or six saa7115 patches as described above.
Then you will have to build both the saa7115 module and the smi2021 module. These commands are typed when you are in the root of the kernel-source tree.
make M=drivers/media/i2c modules
make M=drivers/media/usb/smi2021 modules
Then we install the modules.
sudo /sbin/insmod drivers/media/i2c/saa7115.ko
sudo /sbin/insmod drivers/media/usb/smi2021/smi2021.ko
If you get errors about missing symbols when trying to insmod the saa7115 module,
this is probably because the saa7115 module needs some other modules that aren't loaded yet. We can force them to be loaded if do this before the insmod saa7115
command:
sudo /sbin/modprobe saa7115
sudo /sbin/rmmod saa7115
You should now be able to insert your EasyCap
, and you will see this line in your kernel log:
smi2021 2-1.1:1.0: Somagic Easy-Cap Video Grabber
Testing the driver
Insert your device, and type this:
vlc v4l2:///dev/videoX :v4l2-standard= :input-slave=alsa://plughw:X,0
In /dev/videoX
, the X
is the number of the device, on my computer it's 1, because my web_cam is 0, but it might be any number.
You can get a list of video devices by typing
ls /dev/video*
You can figure out the value of plughw:X,X
by typing:
arecord -l
This should give you a list like this:
**** List of CAPTURE Hardware Devices ****
card 0: MID [HDA Intel MID], device 0: 92HD73C1X5 Analog [92HD73C1X5 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: MID [HDA Intel MID], device 2: 92HD73C1X5 Alt Analog [92HD73C1X5 Alt Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: smi2021Audio [smi2021 Audio], device 0: smi2021 Audio [Somagic smi2021 Capture]
Subdevices: 1/1
Subdevice #0: subdevice #0
Where you see that card2 is smi2021Audio
, so the audio-device is plughw:2,0
.
That's it. If you have any problems, or detect some errors in the document, say so in the mailing-list.