Learning operating system development using Linux kernel and Raspberry Pi

View on GitHub

1.3: Kernel build system

After we examined Linux kernel structure, it worth spending some time investigating how we can build and run it. Linux also uses make utility to build the kernel, though Linux makefile is much more complicated. Before we will take a look at the makefile, let’s learn some important concepts about Linux build system, which is called “kbuild”.

A few essential kbuild concepts

Building the kernel

Now, that we learned some important concepts about the Linux build system, let’s try to figure out what exactly is going on after you type make command. This process is very complicated and includes a lot of details, most of which we will skip. Our goal will be to answer 2 questions.

  1. How exactly are source files compiled into object files?
  2. How are object files linked into the OS image?

We are going to tackle the second question first.

Build stage

  $(subdir-ym):
      $(Q)$(MAKE) $(build)=$@

This target just triggers execution of the scripts/Makefile.build in one of the nested subfolders.

Conclusion

Wow, it was a long journey inside kernel build system internals! Still, we skipped a lot of details and, for those who want to learn more about the subject, I can recommend to read the following document and continue reading Makefiles source code. Let me now emphasize the important points, that you should take as a take-home message from this chapter.

  1. How .c files are compiled into object files.
  2. How object files are combined into built-in.o files.
  3. How recursive build pick up all child built-in.o files and combines them into a single one.
  4. How vmlinux is linked from all top-level built-in.o files.

My main goal was that after reading this chapter you will gain a general understanding of all above points.

Previous Page

1.2 Kernel Initialization: Linux project structure

Next Page

1.4 Kernel Initialization: Linux startup sequence