How to Build Kernel Module for CP2102 Serial Module

Some CP2102 device is recognized as “VeriFone Inc Verifone USB to Modem”, doesn’t register Serial support. It’s hardware driver issue. You can build a new cp210x module to solve this issue.

Get kernel source code

I use Linux mainline kernel source. My Debian has 6.12.12 kernel.

wget https://mirror.nju.edu.cn/kernel.org/linux/kernel/v6.x/linux-6.12.12.tar.xz

unpack to ~/fromsource/linux-6.12.12/

I think the debian source pkg should also work.

Modify the cp210x driver’s source code

You need to add support for your device in the source code. First get the USB vendor ID and product ID. You can get it from kernel log (journalctl -k |tail) or lsusb command. Kernel log is usually like “idVendor=11ca, idProduct=0211, bcdDevice=1.00”, lsusb output is like “Bus 007 Device 005: ID 11ca:0211 VeriFone Inc Verifone USB to Modem”. In my example, vendor ID is 11ca, product ID is 0211. Now you need to modify the source code at ~/fromsource/linux-6.12.12/drivers/usb/serial/cp210x.c

add
{ USB_DEVICE(0x11CA, 0x0211) },

between all those device vendor ID, product ID lines.

Build the cp210x module

Install some dependencies: pahole and resolve_btfids.

sudo apt install pahole libelf-dev

cd ~/fromsource/linux-6.12.12/
cd ./tools/bpf/resolve_btfids
make
ls -l resolve_btfids
sudo mkdir -p /usr/src/linux-headers-`uname -r`/tools/bpf/resolve_btfids
sudo ln -s $(realpath resolve_btfids) /usr/src/linux-headers-`uname -r`/tools/bpf/resolve_btfids

To avoid Skipping BTF generation for xxx Error:

sudo cp /sys/kernel/btf/vmlinux /usr/lib/modules/`uname -r`/build/

Now it’s time to build the cp210x kernel module.

cd ~/fromsource/linux-6.12.12/drivers/usb/serial/
make -C /lib/modules/`uname -r`/build M=$PWD
ls -l cp210x.ko

Install and load cp210x module

# install cp210x
sudo cp usbserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko
sudo cp cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko
# you must update module dependency map after cp new file to kernel
# module dir. otherwise, you will get "unknown symbol in module" error.
sudo depmod -a

# load cp210x
sudo modprobe cp210x

Now plugin your device, you should have /dev/ttyUSB0

In kernel log you should see

Nov 29 00:25:26 agem10.dev.emacsos.com kernel: usbcore: registered new interface driver usbserial_generic
Nov 29 00:25:26 agem10.dev.emacsos.com kernel: usbserial: USB Serial support registered for generic
Nov 29 00:25:28 agem10.dev.emacsos.com kernel: usbcore: registered new interface driver cp210x
Nov 29 00:25:28 agem10.dev.emacsos.com kernel: usbserial: USB Serial support registered for cp210x
Nov 29 00:25:28 agem10.dev.emacsos.com kernel: cp210x 7-1.2:1.0: cp210x converter detected
Nov 29 00:25:28 agem10.dev.emacsos.com kernel: usb 7-1.2: cp210x converter now attached to ttyUSB0

Now the device is fully working.

Scroll to Top