***************************************************************************** * CONFIGURATION FLAGS * * * * * * Copyright (c) 2001 Daniel P. Bovet, Marco Cesati, and Cosimo Comella * * Permission is granted to copy, distribute and/or modify this document * * under the terms of the GNU Free Documentation License, Version 1.1, * * published by the Free Software Foundation; with no Invariant Sections, * * with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the * * license is included in the file named LICENSE. * * * * (version 1.1) * ***************************************************************************** The kernel can be configured in an almost infinite number of ways thanks to hundreds of compilation flags of the form CONFIG_XXX. These compilation flags are used in two distinct ways: - inside the kernel code (conditional compilation statements) - inside a makefile (conditional makefile) Let us review briefly each of them. Conditional compilation statements look like: #ifdef CONFIG_XXX .... #endif All the C statements included between #ifdef and #endif are compiled only if the CONFIG_XXX configuration flag is set. Before compiling a C file, the compiler preprocesses it and removes all the #ifdef and #endif statements. The resulting file is a plain C file. When removing the #ifdef and #endif statements, the preprocessor makes use of a configuration file that specifies the value of each configuration flag. When compiling the Linux kernel, the gcc compiler relies on the linux/.config file. This file, which is updated each time you run "make menuconfig", is a text file of lines of the type: #CONFIG_XXX is not set or: CONFIG_YYY = y The meaning is obvious: CONFIG_XXX is considered as not defined while CONFIG_YYY is considered as defined. Conditional makefiles also make a wide use of configuration flags to decide whether to compile subdirectories. Consider, for instance, the Makefile of the linux/drivers directory. If your PC does not have a SCSI bus, you will have set the CONFIG_SCSI flag to 'N' and all the kernel code that handles the SCSI bus won't be compiled because the Makefile of drivers includes the following lines: ... subdir-y := parport char block net sound misc media cdrom .... subdir-$(CONFIG_SCSI) += scsi .... As a result, the *.c files included in the drivers/scsi subdirectory will be compiled only if CONFIG_SCSI is set. ***************************************************************************** * ADDING A NEW CONFIGURATION FLAG * ***************************************************************************** As potential kernel hackers, we shall need to add our own configuration flags. This can be done quite easily by modifying two files: linux/arch/i386/config.in and linux/Documentation/Configure.help. As usual, we shall proceed by means of examples. Let's assume we wish to add a new option called CONFIG_HWCACHE_DISABLE as a new option in the Kernel hacking menu. ***************************************************************************** * STEP 1: update the linux/arch/i386/config.in file * ***************************************************************************** replace: bool 'Kernel debugging' CONFIG_DEBUG_KERNEL if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then bool ' Debug memory allocations' CONFIG_DEBUG_SLAB bool ' Memory mapped I/O debugging' CONFIG_DEBUG_IOVIRT bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE fi with: bool 'Kernel debugging' CONFIG_DEBUG_KERNEL if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then bool ' Debug memory allocations' CONFIG_DEBUG_SLAB bool ' Memory mapped I/O debugging' CONFIG_DEBUG_IOVIRT bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE bool ' Hardware cache disabling' CONFIG_HWCACHE_DISABLE fi ***************************************************************************** * STEP 2: update the linux/Documentation/Configure.help file * * ***************************************************************************** add right after: CONFIG_MAGIC_SYSRQ If you say Y here, you will have some control over the system even if the system crashes for example during kernel debugging (e.g., you will be able to flush the buffer cache to disk, reboot the system immediately or dump some status information). This is accomplished by pressing various keys while holding SysRq (Alt+PrintScreen). It also works on a serial console (on PC hardware at least), if you send a BREAK and then within 5 seconds a command keypress. The keys are documented in Documentation/sysrq.txt. Don't say Y unless you really know what this hack does. the following lines: Kernel Debug Variables Support CONFIG_HWCACHE_DISABLE If you say Y here, you will have some control over the CPU hardware cache. More precisely, a new system call denoted as cacheset() may be issued by programs with root privilege to enable or disable the CPU hardware cache. ***************************************************************************** * STEP 3: run menuconfig and test it * ***************************************************************************** a) run menuconfig and select the CONFIG_HWCACHE_DISABLE option in the kernel hacking menu b) save the new configuration flag by answering 'Y' to: "Do you wish to save your new kernel configuration?" As a result, the .config file is updated or created if it did not exist. c) run menuconfig a second time and check whether the help for the new option is correctly displayed d) read the linux/.config file to see whether CONFIG_HWCACHE_DISABLE is properly defined