加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 钦州站长网 (https://www.0777zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux安装驱动命令

发布时间:2022-11-12 11:01:11 所属栏目:Linux 来源:
导读:  第一种:直接把驱动程序编译进内核,最终连接成zIMage uImage文件。

  举个例子来说明如何把驱动程序文件编译进内核:

  在这里先说明一下,驱动程序分类很多,char(字符设备) block(块设备) input(
  第一种:直接把驱动程序编译进内核,最终连接成zIMage uImage文件。
 
  举个例子来说明如何把驱动程序文件编译进内核:
 
  在这里先说明一下,驱动程序分类很多,char(字符设备) block(块设备) input(输入设备) network(网络接口) 等等……
 
  eg:我们要在/home/mykernel/linux-3.0.1/drivers/input输入设备的驱动添加一个新的输入设备的驱动程序zhenmingyang.c
 
  需要修改2个文件:Kconfig 和 Makefile
 
  1、touch zhenmingyang.c
 
  2、vi Kconfig //配置Kconfig的目的是为了在make menuconfig时linux 驱动,在对应的选择目录下有新增的zhenmingyang-menuconfig选项。 Kconfig 所在目录:/home/mykernel/linux-3.0.1/drivers/input
 
  修改Kconfig 仿照其他config xxxxxxx 增加一个配置项
 
  config ZHENMINGYANG
 
  bool "zhenmingyang-menuconfig"
 
  3.make menuconfig ARCH=arm
 
  在menuconfig中把新增的zhenmingyang-menuconfig选上。
 
  说明:大写的ZHENMINGYANG是配置结果显示在linux内核的根目录/home/mykernel/linux-3.0.1 下的.config文件里。
 
  .config 文件内容
 
  # Input device support
 
  #
 
  CONFIG_INPUT=y
 
  CONFIG_INPUT_FF_MEMLESS=y
 
  CONFIG_ZHENMINGYANG=y // 在。config中通过make menuconfig选择zhenmingyang-menuconfig它后自动生成的配置、
 
  # CONFIG_INPUT_POLLDEV is not set
 
  4、修改Makefile
 
  makefile所在目录:/home/mykernel/linux-3.0.1/drivers/input
 
  仿照其他新增如下内容:
 
  obj-$(CONFIG_ZHENMINGYANG) += zhenmingyang.o//$(CONFIG_ZHENMINGYANG) 是在make menuconfig后生成的。config文件中生成的,见步骤3
 
  obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o
 
  5、make zImage ARCH=arm CROSS_COMPILE=arm-linux-
 
  第二种:驱动程序编译成modules模块,通过insmod 、rmmod等命令安装、卸载等操作
 
  1、touch hello.c
 
  2、编写Makefile (关键),内容如下:
 
  ifneq ($(KERNELRELEASE),)
 
  obj-m := hello.o //-m 编译为模块 -y 编译进内核 -n不编译 hello。o指定编译生成的目标文件名
 
  else
 
  KDIR :=/lib/modules/3.2.0-48-generic-pae/build //KDIR 这个路径很重要不能弄错,
 
  all:
 
  make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux- //在板子上运行模块需指定ARCH和交叉编译前缀arm-linux-
 
  clean:
 
  rm -f *.ko *.o *.mod.o *.mod.c *.symvers
 
  endif
 
  3、make
 
  生成hello。ko的内核模块文件。
 
  insmod hello。ko //安装模块
 
  lsmod //查看模块
 
  rmmod hello //卸载模块 直接指定模块名,不需要扩展名!
 
  上面的例子是单文件的Makefile,在编译多文件的内核模块时只需要改一个地方即可。
 
  obj-m := hello.o //-m 编译为模块 -y 编译进内核 -n不编译 hello。o指定编译生成的目标文件名
 
  hello-objs :=a.o b.o c.o
 
  其他不变。
 
  hello.c源文件,模块的源文件没有main函数的
 
  #include #include static int hello_init(void) { printk(KERN_WARNING"helle world inti\n"); return 0; } static void hello_exit(void) { printk(KERN_INFO"Goog bye,heelo\n"); } module_init(hello_init); module_exit(hello_exit)
 

(编辑:PHP编程网 - 钦州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!