如何在Ubuntu 17.10上编译qmi_wwan驱动?仅编译相关源文件方法
Hey there! Let's walk through compiling your modified qmi_wwan driver for your 4G LTE MIFI on Ubuntu 17.10, including the crucial part of building only the relevant source files instead of the entire kernel—no need to waste time on unnecessary builds.
1. Set Up the Compilation Environment
First, you need all the tools and matching kernel headers to build kernel modules. The headers are non-negotiable because your driver has to align exactly with the kernel you’re running. Run this command to install everything:
sudo apt update && sudo apt install build-essential linux-headers-$(uname -r) git
The $(uname -r) part automatically grabs your current kernel version, so you don’t have to look it up manually.
2. Get the Relevant Kernel Source Files
You don’t need the entire kernel source tree, but grabbing the specific directory for USB network drivers will make things easier. Ubuntu 17.10 uses the 4.13.x kernel series, so clone the matching Ubuntu kernel repo:
# Replace "xx" with the minor version from your kernel (check with uname -r) git clone --depth 1 -b ubuntu-4.13.0-xx-generic git://kernel.ubuntu.com/ubuntu/ubuntu-artful.git
Once cloned, navigate to the directory where qmi_wwan lives:
cd ubuntu-artful/drivers/net/usb/
Now replace the original qmi_wwan.c (and any modified header files, if you changed those) with your custom version.
3. Compile Only the qmi_wwan Module (Skip Full Kernel Build)
This is the part you care about—building just your modified driver, not the whole kernel. Run this command from the usb/ directory:
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
Let me break that down:
-C /lib/modules/$(uname -r)/build: Points to your kernel’s build/headers directoryM=$(pwd): Tells the kernel Makefile to focus on the current directory’s filesmodules: The target to generate kernel module files
When it finishes, you’ll see a qmi_wwan.ko file in the directory—that’s your compiled driver.
4. Test the Modified Driver
Before making it permanent, test if it works with your MIFI:
- Unload the existing qmi_wwan module (if it’s loaded):
sudo rmmod qmi_wwan - Load your custom module:
sudo insmod qmi_wwan.ko - Verify it loaded correctly and detected your device:
- Check loaded modules:
lsmod | grep qmi_wwan - Check kernel logs for device recognition:
dmesg | tail -20
Look for lines likeqmi_wwan 1-2:1.0: cdc-wdm0: USB WDM deviceor references to your MIFI model—those mean success.
- Check loaded modules:
5. Optional: Make the Driver Persistent (After Successful Testing)
If everything works, replace the system’s default qmi_wwan module so it loads automatically on boot:
sudo cp qmi_wwan.ko /lib/modules/$(uname -r)/kernel/drivers/net/usb/ sudo depmod -a
Quick Notes
- Double-check that your kernel headers match your running kernel—if they don’t, the module will fail to load.
- If you modified any header files (not just
qmi_wwan.c), make sure those are placed in the correct include directories before compiling. - If you hit compile errors, read the output carefully—most issues are missing dependencies or syntax tweaks in your modified code.
内容的提问来源于stack exchange,提问作者artificerpi

