内核代码:helloworld.c
静态编译:将helloworld.c和zImage编译在一起
动态编译,模块化编译:将helloworld.c和zImage分开编译,将helloworld.c编译成对应的二进制文件,默认以ko结尾,例如helloworld.ko
内核编译借助Kconfig和Makefile,Kconfig和Makefile的选择关键看helloworld.c放置在哪个目录下,例如将helloworld.c放置在内核源码的drivers/char/
修改Kconfig:
vim drivers/char/Kconfig,添加:
config HELLOWORLD
tristate "hello,world"
--help---
"this is my first kernel module"
注意:config HELLOWORLD最终生成的给Makefile使用的配置项:CONFIG_HELLOWORLD(才是Kconfig和Makefile连接的桥梁)
修改Makefile文件:
obj-$(COFNIG_HELLOWORLD) += helloworld.o
每当make menuconfig进行配置时,如果选择为*
obj-y += helloworld.o //静态编译
如果选择为M
obj-m += helloworld.o //动态编译-》helloworld.ko