当前位置: 移动技术网 > 网络运营>服务器>Linux > 单独编译Linux内核源码中的驱动为可加载模块

单独编译Linux内核源码中的驱动为可加载模块

2020年08月14日  | 移动技术网网络运营  | 我要评论
单独编译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为例说明。

  1. 找到相应控制宏()

grep cp210x.o drivers/usb/serial/ -r | grep Makefile

drivers/usb/serial/Makefile:obj-$(CONFIG_USB_SERIAL_CP210X) += cp210x.o

找到控制宏为CONFIG_USB_SERIAL_CP210X

  1. 在make命令中给宏赋值CONFIG_USB_SERIAL_CP210X=m
  2. 完整编译命令

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网