Makefile Kconfig 内核配置 内核裁剪

来源:互联网 发布:数据库处理 编辑:程序博客网 时间:2024/06/06 03:09

假设我们要在内核源代码 drivers 目录下如下用于 test driver 的树型目录:

|----test
|---- cpu
|---- cpu.c
|---- test.c
|---- test_client.c
|---- test_ioctl.c
|---- test_proc.c
|---- test_queue.c

  在内核中增加目录和子目录,我们需为相应的新增目录创建 Kconfig 和 Makefile 文件,而新增目录的父目录中的 Kconfig 和 Makefile 文件也需要修改,以便新增的 Kconfig 和 Makefile 文件能被引用.

  在新增的 test 目录下,应包含如下 Kconfig 文件:

  #

  # TEST driver configuration

  #

  menu "Test Driver "

  comment "Test Driver"

  config TEST

  bool "TEST suport"

  config TEST_USER

  tristate "TEST user-space interface"

  depends on TEST

  endmenu

  由于 TEST driver 对于内核来说是新的功能,所以首先需要创建一个菜单 TEST Driver ;然后显示 "TEST support " ,等待用户选择;接下来判断用户是否选择了 TEST Driver ,如果是 (CONFIG_TEST=y),则进一步显示子功能:用户接口与CPU功能支持;由于用户接口功能可以被编译成内核模块,所以这里的询问语句使用了 tristate.

  为了使这个 Kconfig 文件能起作用,需要修改 drivers/Kconfig 文件,增加以下内容:

  source "drivers/test/Kconfig"

  脚本中的 source 意味着引用新的 Kconfig 文件.在新增的 test 目录下,应该包含如下 Makefile 文件:

  #drivers/test/Makefile

  #

  #Makefile for the TEST

  #

  obj-$(CONFIG_TEST) += test.o test_queue.o test_client.o

  obj-$(CONFIG_TEST_USER) += test_ioctl.o

  obj-$(CONFIG_PROC_FS) += test_proc.o

  obj-$(CONFIG_TEST_CPU) += cpu/

  该脚本根据配置变量的取值构建 obj-* 列表.由于 test 目录中包含一个子目录 cpu ,当CONFIG_TEST_CPU=y 时,需要将 cpu 目录加入列表.

  test 目录中的 cpu 目录也需包含如下的 Makefile 文件:

  # drivers/test/cpu/Makefile

  #

  # Makefile for the TEST cpu

  #

  obj-$(CONFIG_TEST_CPU) += cpu.o

  为了使得整个 test 目录能够被编译命令作用到, test 目录父目录中的 Makefile 文件也需新增如下脚本:

  obj-$(CONFIG_TEST) += test/

  增加了 Kconfig 和 Makefile 文件之后的新的 test 树型目录如下所示:

|----test
|---- cpu
|---- cpu.c
|---- Makefile
|---- test.c
|---- test_client.c
|---- test_ioctl.c
|---- test_proc.c
|---- test_queue.c
|---- Makefile
|---- Kconfig

  这样整个工作就算完成了

原创粉丝点击