makefile:编译源文件的方法。
Kconfig:配置。
.config:编译内核所依据的配置。
makefile
(1)直接编译
obj -y +=xxx.o
表示由xxx.c或xxx.s编译得到xxx.o并直接编进内核。
(2)条件编译
obj -$(CONFIG_HELLO) +=xxx.o
根据.config文件的CONFIG_XXX来决定文件是否编进内核。
(3)模块编译
obj-m +=xxx.o
表示xxx作为模块编译,即执行make modules时才会被编译。
Kconfig
bool布尔类型、 tristate三态(内建、模块、移除)、string字符串、 hex十六进制、integer整型。
作用:决定make menuconfig时展示的配置。
select:反向依赖关系,该选项选中时,同时选中select后面定义的那一项。
.config
配置内核方式有3种:
(1)make menuconfig
(2)make xxx_defconfig
(3)直接修改.config
写一个简单的入口函数输出hello world的驱动并编译进内核。
步骤:
(1)在drivers目录下新建hello文件夹,里面实现hello.c、Makefile、Kconfig。
hello.c:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
static int first_drv_init(void)
{
printk("------------------hello world !--------------------");
return 0;
}
static void first_drv_exit(void)
{
printk("------------------exit hello world!--------------------");
}
module_init(first_drv_init);
module_exit(first_drv_exit);
Makefile:
obj-$(CONFIG_HELLO) += hello.o
Kconfig:
config HELLO
tristate “Hello Worldfor fengyuwuzu”
help
Hello forfengyuwuzu
config HELLO决定名字:CONFIG_HELLO。
Hello World for fengyuwuzu:决定了在make menuconfig时显示的名字
修改上一级的Makefile、Kconfig。
Makefile:
obj-y += hello/
Kconfig:
source “drivers/hello/Kconfig”
原文链接:https://blog.csdn.net/thisway_diy/article/details/76981113