您的位置:首页 > 其它

ubuntu下使用qemu模拟ARM(六)------驱动程序编译进内核方法

2017-02-02 11:35 477 查看
有两种方法可以编译自己写的驱动程序。
第一种方法:加入单个文件到驱动目录下

1.将helloworld_nodir.c的驱动源文件拷到/qemu_arm/linux-kernel/linux-3.16.39/drivers/char目录下

2.修改/qemu_arm/linux-kernel/linux-3.16.39/drivers/char/Kconfig文件.

    打开Kconfig在 source "drivers/tty/Kconfig"后添加以下信息:

        config HELLO_WORLD_NODIR
tristate "hello world no dir "
default y
help
 It test how to add module to kernel
 If unsure, it is safe to say Y.

3.修改此驱动目录下的Makefile文件,加入对驱动源码的编译:

obj-$(CONFIG_HELLO_WORLD_NODIR) += helloworld_nodir.o

4.make menuconfig 

             Device Drivers  ---> 

             Character devices  ---> 

                           <*> hello world no dir 

5. 编译内核即可。

第二种方法:在驱动目录下建立新的目录

1.新建一个目录如下:

/qemu_arm/linux-kernel/linux-3.16.39/drivers/char/helloworld

2.将文件helloworld_dir.c拷到/qemu_arm/linux-kernel/linux-3.16.39/drivers/char/helloworld文件夹下面

3.在hellowrold目录下面建一个文件, Kconfig,注意K要大写

4.在文件中输入如下内容:

menu "Hello World new dir"

config HELLO_WORLD_DIR
tristate "hello world new dir"
default n
help
It test how to add module to kernel
If unsure, it is safe to say Y.

endmenu

5.在hellowrold目录下面建一个文件,Makefile并写入如下内容

obj-$(CONFIG_HELLO_WORLD_DIR) += helloworld_dir.o

6.修改hellowrold上级目录char里的Makefile文件

增加:obj-$(CONFIG_HELLO_WORLD_DIR) += helloworld/

6、修改hellowrold上级目录char里的Kconfig文件

增加:source "drivers/char/helloworld/Kconfig"

7。make menuconfig

Device Drivers  --->

Character devices  --->

Hello World new dir  ---> 

 <M> hello world new dir 

8.编译内核

参考文章:
http://blog.csdn.net/u011164819/article/details/49998597 http://www.linuxidc.com/Linux/2015-05/118021.htm http://www.cnblogs.com/hnrainll/archive/2011/06/22/2087569.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐