单独编译Linux内核源码中的驱动为可加载模块
程序员文章站
2022-06-21 19:17:17
单独编译Linux内核源码中的驱动为可加载模块首先,看看编译kernel源码的帮助信息:make ARCH=arm help...... modules - Build all modules...
单独编译Linux内核源码中的驱动为可加载模块
首先,看看编译kernel源码的帮助信息:
make ARCH=arm help
......
modules - Build all modules
modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
firmware_install- Install all firmware to INSTALL_FW_PATH
(default: $(INSTALL_MOD_PATH)/lib/firmware)
dir/ - Build all files in dir and below
dir/file.[ois] - Build specified target only
dir/file.ll - Build the LLVM assembly file
(requires compiler support for LLVM assembly generation)
dir/file.lst - Build specified mixed source/assembly target only
(requires a recent binutils and recent build (System.map))
dir/file.ko - Build module including final link
......
帮助信息中可以直接在make中带路经或者最终链接的ko。
然后,以usb串口驱动cp210x为例说明。
- 找到相应控制宏()
grep cp210x.o drivers/usb/serial/ -r | grep Makefile
drivers/usb/serial/Makefile:obj-$(CONFIG_USB_SERIAL_CP210X) += cp210x.o
找到控制宏为CONFIG_USB_SERIAL_CP210X
;
- 在make命令中给宏赋值
CONFIG_USB_SERIAL_CP210X=m
- 完整编译命令
make ARCH=arm CONFIG_USB_SERIAL_CP210X=m drivers/usb/serial/cp210x.ko
or
make ARCH=arm CONFIG_USB_SERIAL_CP210X=m drivers/usb/serial/
或者直接修改Makefile,这具有破坏性,如果是调试无所谓了。
上面的第2步修改如下:
drivers/usb/serial/Makefile:obj-$(CONFIG_USB_SERIAL_CP210X) += cp210x.o
改成:
drivers/usb/serial/Makefile:obj-m += cp210x.o
本文地址:https://blog.csdn.net/EricYaaang/article/details/107938937