Figured out the steps to compile this kernel module. The version on the website, silabs.com is apparently too old to be used with newer kernels (3.4+).
I was able to compile a newer version of the file, cp210x.c
, that I found over on kernel.org for my particular version of the kernel, using the Makefile
provided in the VCP Driver Source.
Building cp210x for your kernel version
baseline your kernel
First make note of your major & minor numbers for your kernel you have (i.e. 3.4, 3.5, etc.).
$ uname -r
3.5.0-19-generic
Incidentally I'm on Ubuntu 12.10:
$ lsb_release -r
Release: 12.10
Install the kernel headers & build tools for your kernel version:
sudo apt-get install linux-headers-$(uname -r) build-essential
Get the VCP bundle from silabs.com
Now make yourself a little work area for all this:
mkdir -p $HOME/cp210x && cd $HOME/cp210x
Download the VCP Driver Source:
wget http://www.silabs.com/Support%20Documents/Software/Linux_3.x.x_VCP_Driver_Source.zip
unzip Linux_3.x.x_VCP_Driver_Source.zip
cd Linux_3.x.x_VCP_Driver_Source
mv cp210x.c cp210x.c_orig
Get kernel.org cp210x.c
Now download the appropriate version of cp210x.c for your kernel:
$ wget https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/drivers/usb/serial/cp210x.c?h=linux-3.5.y -O cp210x.c
NOTE: You can browse the different versions of the kernel here.
Compile
Now we compile using make
:
$ make
make -C /lib/modules/3.5.0-19-generic/build M=/home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-19-generic'
CC [M] /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.mod.o
LD [M] /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-19-generic'
Deploy
Now move any pre-existing cp210x.ko
kernel out of the way:
sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko.orig
Now copy the newly built kernel module, cp210x.ko
in it's place:
sudo cp cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko
Load
Now make sure the previous cp210x.ko
kernel module wasn't loaded:
$ lsmod | grep cp210x
$
If it is, unload it:
sudo rmmod cp210x
Now let's load our new cp210x.ko
module:
sudo modprobe cp210x
Test
Confirm that it loaded correctly:
$ lsmod |grep cp210x
cp210x 21822 0
usbserial 42355 1 cp210x
Also check dmesg
for any issues:
$ dmesg | tail
...
...
[979772.614394] usbcore: registered new interface driver usbserial
[979772.614410] usbcore: registered new interface driver usbserial_generic
[979772.614456] USB Serial support registered for generic
[979772.614461] usbserial: USB Serial Driver core
[979772.614810] usbcore: registered new interface driver cp210x
[979772.614822] USB Serial support registered for cp210x
Compiling usbserial kernel module
The OP asked about how to accomplish compiling the usbserial.ko
module as well, given it's needed by the applications in order to make use of the cp210x kernel module. Here are those instructions.
First make note of which kernel version you're using:
uname -r
3.5.0-19-generic
So we're using 3.5.0, next install the kernel source:
sudo apt-get install linux-source-3.5.0
Now let's make ourselves a work area:
mkdir -p $HOME/src && cd $HOME/src
Unpack the kernel source into our work area:
tar jxvf /usr/src/linux-source-3.5.0.tar.bz2
Now let's compile usbserial.ko
:
$ cd linux-source-3.5.0/drivers/usb/serial
$ make -C /usr/src/linux-headers-`uname -r` M=`pwd` modules
make: Entering directory `/usr/src/linux-headers-3.5.0-19-generic'
CC [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usb-serial.o
...
...
LD [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.o
...
...
CC /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.mod.o
LD [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.ko
...
...
make: Leaving directory `/usr/src/linux-headers-3.5.0-19-generic'
Check that usbserial.ko
was built:
ls -l |grep usbserial
-rw-r--r-- 1 root root 74822 May 15 09:20 usbserial.ko
-rw-r--r-- 1 root root 4120 May 15 09:20 usbserial.mod.c
-rw-r--r-- 1 root root 8840 May 15 09:20 usbserial.mod.o
-rw-r--r-- 1 root root 74724 May 15 09:20 usbserial.o
Now let's install it, load it, and test it:
# move old driver out of the way
$ mv /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko.orig
# copy newly built one in
$ cp usbserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/.
# confirm `usbserial.ko` isn't loaded
$ lsmod | grep usbserial
$
# load it
$ modprobe usbserial
# confirm
$ lsmod |grep usbserial
usbserial 42355 0
# check dmesg log
$ dmesg | tail -4
[1195955.210920] usbcore: registered new interface driver usbserial
[1195955.210970] usbcore: registered new interface driver usbserial_generic
[1195955.211002] USB Serial support registered for generic
[1195955.211069] usbserial: USB Serial Driver core
References