I’m new at kernel programming and trying to do a “Hello World” example. I added the following code to init/main.c in start_kernel()
#ifdef HELLO
printk("Hello World");
#endif
Now to my question. How do i define HELLO in the boot parameters using qemu?
You need to define
HELLOat compile time, (either with-DHELLOas a compiler flag or#define HELLOsomewhere), otherwise the compiler never even sees theprintkcall and no code for it gets emitted.You can’t make the C compiler get re-run at early stage boot time based on the boot parameters, which is what you’d need to do to change
HELLOthere.The kernel is no different than any other C program in this respect – preprocessor directives are handled really early on in compilation.
You can setup parameters with this helper macro that are a regular variable that can be set a boot and tested at runtime (not compile time) with a plain old
ifstatement.