This post shows how to set up an efficient ARM or x86 Linux Kernel development environment in about 15 minutes using QEMU, Vim and cscope to find, change, recompile and test a Linux kernel change in 12 seconds (on my machine in a VirtualBox VM).
Environment I Used
Setup
1. Install Cscope using [instructions]
2. Follow either the ARM [arm-instructions] and/or x86 [x86-instructions] to build the Linux kernel and BusyBox and boot them on QEMU
3. Open a terminal and type vi ~/envset.sh
4. Create an environment, type i then paste:
...for ARM:
export STAGE=$HOME/tla
export TOP=$STAGE/teeny-linux
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
export KBUILD_OUTPUT=$TOP/obj/linux-arm-versatile_defconfig
export MAKEFLAGS=j2
export CSCOPE_DB=$KBUILD_OUTPUT/cscope.out
...for x86 enter:
export STAGE=$HOME/tl
export TOP=$STAGE/teeny-linux
export KBUILD_OUTPUT=$TOP/obj/linux-x86-allnoconfig
export MAKEFLAGS=j2
export CSCOPE_DB=$KBUILD_OUTPUT/cscope.out
5. Type :w then :q
Recompile the Kernel and Cscope, Run Kernel
1. Change into the kernel directory:
For ARM type cd ~/tla/linux-4.10.6
For x86 type cd ~/tl/linux-4.10.6
2. Type source ~/envset.sh
3. Type make cscope to build the cscope index
Note: rerun when source changes
4. Type make to build the kernel
Note: rerun when source changes
5. Run the kernel in QEMU
For ARM type:
For x86 type:
6. Type Control-a x to quit QEMU
Browse Code Quickly
1. Open a new terminal
2. Change into the kernel directory:
For ARM type cd ~/tla/linux-4.10.6
For x86 type cd ~/tl/linux-4.10.6
3. Type source ~/envset.sh
4. Type vi init/main.c
5. Type Control-\ and:
s (symbol) to find all references to the token under cursor
g (global) find global definition(s) of the token under cursor
c (calls) find all calls to the function name under cursor
t (text) find all instances of the text under cursor
e (egrep) egrep search for the word under cursor
f (file) open the filename under cursor
i (includes) find files that include the filename under cursor
d (called) find functions that function under cursor calls
6. Type Control-t to jump back (works for each jump forward)
Hack Code
Follow [link] to set up Vim to hack Linux kernel code
References