简体   繁体   中英

Boot parameters in qemu

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 HELLO at compile time, (either with -DHELLO as a compiler flag or #define HELLO somewhere), otherwise the compiler never even sees the printk call 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 HELLO there.

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 if statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM