본문 바로가기
프로그램.../프로....Kernel

[Kernel-Make] the Kernel Build System (kbuild)

by 크크다스 2014. 10. 31.
반응형

= Cf> http://www.linuxjournal.com/content/kbuild-linux-kernel-build-system

= 요약> 새로 Kernel 모듈을 삽입할 때는 아래의 순서대로 한다.

. 다음사항들을 정의한다.

SYMBOL : epdg => EPDG

모듈 삽입 위치 : net/ipv4

모듈 소스명 : epdg.c

. 다음 순서로 생성, 설정 및 빌드한다.

삽입 위치의 Kbuild에 모듈 내용 추가

Kernel make 위치에서 "make  menuconfig" => .config => gen> include/generated/autoconf.h

삽입위치의 Makefile에 모듈에 해당하는 라인 추가 : obj-$(CONFIG_COIN) += epdg.o

소스코드 작성(SYMBOL반영)

Building

= Cf>

- Documentation/kbuild

- Documentation/kbuild/makefiles.txt.

. the Kernel Build System (kbuild)

......

The Linux Kernel Build System has four main components:

  • Config symbols: compilation options that can be used to compile code conditionally in source files and to decide which objects to include in a kernel image or its modules.

  • Kconfig files: define each config symbol and its attributes, such as its type, description and dependencies. Programs that generate an option menu tree (for example, make menuconfig) read the menu entries from these files.

  • .config file: stores each config symbol's selected value. You can edit this file manually or use one of the many make configuration targets, such as menuconfig and xconfig, that call specialized programs to build a tree-like menu and automatically update (and create) the .config file for you.

  • Makefiles: normal GNU makefiles that describe the relationship between source files and the commands needed to generate each make target, such as kernel images and modules.


= Detail

  • Config symbols

    • kinds : boolean(true or false) / tristate(yes, no or module)
  • Kconfig files:

    • menuconfig (scripts/kconfig/mconf), gconfig (scripts/kconfig/gconf)

  • .config file:

    • All config symbol values are saved in a special file called .config

    • can change it without needing any specialized tool
  • Makefiles: normal GNU makefiles that describe the relationship between source files and the commands needed to generate each make target, such as kernel images and modules.

= Sample ... How to Add driver into Linux Kernel

To add a feature to a Linux kernel (such as the coin driver), you need to do three things:

  1. Put the source file(s) in a place that makes sense, such as drivers/net/wireless for Wi-Fi devices or fs for a new filesystem.

    1. ==> put the coin.c source file in drivers/char
  2. Update the Kconfig for the subdirectory (or subdirectories) where you put the files with config symbols that allow you to choose to include the feature.

    1. ==> add two configuration symbols to the drivers/char/Kconfig file
  3. Update the Makefile for the subdirectory where you put the files, so the build system can compile your code conditionally.

  4. scripts/kconfig/conf Kconfig 

    1. ==> include/generated/autoconf.h

    2. ==> every gcc compile instruction includesit

    3. ==> symbols can be used in any source file in the kernel

#define IS_ENABLED(CONFIG_COIN) 

#define IS_BUILTIN(CONFIG_COIN)

#define IS_MODULE(CONFIG_COIN)

= The kernel build system's two main tasks

. kernel binary image : obj-y

. kernel modules : obj-m

    1. Just add a line in drivers/char/Makefile:

obj-$(CONFIG_COIN)    += coin.o   <== .config에 정의된 대로 할당

......

Figure 2 summarizes the kernel build process, and the output of the git diff --stat command shows the files you have modified to include the driver:


drivers/char/Kconfig  |   16 +++++++++
drivers/char/Makefile |    1 +
drivers/char/coin.c   |   89 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 0 deletions(-)

Figure 2. Kernel Build Proces


반응형