Let’s say I want to use printk()
within arch/x86/boot/string.c
before compiling the kernel. Which header file do I have to include so that the linker knows where to find printk()
? I tried #include <linux/kernel.h>
and #include <linux/printk.h>
but I always get errors during make bzImage
telling me the linker does not find printk
:
arch/x86/boot/compressed/string.o: In function `memcmp`: string.c:(.text+0x19): undefined reference to `printk`
Advertisement
Answer
You are trying to instrument the boot stage of the kernel. It has its own really small library and doesn’t have any headers like linux/printk.h
available. The function is called printf()
and it’s implemented in arch/x86/boot/printf.c.
The output of this function goes to the channel whatever defined in BIOS (int 10h) and, if asked, to the legacy (you can’t use UART which has 32-bit I/O, for example) serial line. For the details refer to the printf.c source file.