Kernel Build Notes

From eLinux.org
Revision as of 10:57, 1 June 2023 by Tim Bird (talk | contribs) (Created page with "Here are some notes on building a kernel for embedded systems: = help = Use "make help" to get a list of targets that are available in the kernel build system (the kernel sou...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Here are some notes on building a kernel for embedded systems:

help

Use "make help" to get a list of targets that are available in the kernel build system (the kernel source's native Makefile-based system)

setting the build output directory

If you don't specify one, the build artifacts are put into the current source directory.

You can use a different directory by setting KBUILD_OUTPUT (either in an environment variable, or on the make command line). This is particularly useful if you build using different configurations or architectures, from the same source tree.

Example: export KBUILD_OUTPUT=../test-build-bbb ; make ARCH=arm CROSS_COMPILE=... zImage

setting config

You can configure the kernel manually, or using a default config ("defconfig") from an existing file, or by automatically probing the system that the build is currently running on. (This can be useful for building only the modules that are in current use on your system - see 'make localmodconfig')

The following targets are for interactively, manually, setting the kernel config: config, nconfig, menuconfig, xconfig, gconfig, oldconfig

You can set the configuration for the kernel using a file using "make {defconfig-name}"

The list of available defconfigs is under arch/$ARCH/configs. In order to figure out the right defconfig for your board, you have to search online for build instructions. It is, unfortunately, not really feasible to figure it out on your own by looking at the config contents. Usually the name is a good hint.

The defconfig for a beaglebone black board is 'omap2plus_defconfig', so to make the

choosing the architecture and cross-compiler prefix

When you are doing a cross-build (building the kernel for an architecture other than the one you are on), you always need to specify the ARCH and CROSS_COMPILE variables, which indicate the machine architecture.

Common architectures to cross-build are: arm, aarch64, x86, x86_64, riscv, mips

The CROSS_COMPILE variable should be the prefix of the toolchain you are using. For example if you are building using the GNU toolchain collection, and specifically are using tools with the executable names: arm-linux-gnueabi-gcc, arm-linux-gnueabi-as, arm-linux-gnueabi-ld, etc., then your toolchain prefix is "arm-linux-gnueabi-". In particular, notice that the cross-compile toolchain prefix string includes the dash ("-") at the end.

Here is an example make line:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage

In general these variables need to be set on ever make command line (that is, every time make is invoked).

packaging kernel output