Running and Debugging the Kernel in the Emulator
After the build process is finished, we can run and debug the kernel in the Android emulator. The compressed kernel image can be found at arch/arm/boot/zImage. This image can be used to run the kernel in the emulator. The image file vmlinux is in ELF format; it can be used by gdb to get the debug symbol. We give the following command to start the Android emulator using our own kernel image:
$ emulator -verbose -show-kernel -netfast -avd hd2 -qemu -serial stdio -s -S -kernel arch/arm/boot/zImage
After the emulator is running, we can start the gdb debugger to debug the kernel. We will use the graphical interface ddd to start the gdb debugger; it produces a more user-friendly environment. In the following command line, we tell ddd to use arm-eabi-gdb as the debugger and vmlinux as the binary image:
$ ddd --debugger arm-eabi-gdb vmlinux
After gdb starts, it needs to connect to the gdbserver in the emulator using the command target remote localhost:1234. To track the boot-up progress, we can set a breakpoint at the function start_kernel:
GNU DDD 3.3.12 (i686-pc-linux-gnu), by Dorothea Lütkehaus and Andreas Zeller. Copyright © 1995-1999 Technische Universität Braunschweig, Germany. Copyright © 1999-2001 Universität Passau, Germany. Copyright © 2001 Universität des Saarlandes, Germany. Copyright © 2001-2004 Free Software Foundation, Inc. Reading symbols from /home/sgye/src/Android/goldfish/vmlinux...done. (gdb) target remote localhost:1234 0x00000000 in ?? () (gdb) b start_kernel Breakpoint 1 at 0xc0008858: file init/main.c, line 531. (gdb) c
After starting the process, gdb will stop at start_kernel, as shown in Figure 10.2.
Figure 10.2 Boot-up stop at start_kernel
After the system boots up, a console like that shown in Figure 10.3 appears. The entire Android system should be ready to use at this point. From here, we boot the kernel in the Android emulator directly. In the next few sections, we will boot this kernel using U-Boot.
Figure 10.3 Linux console after boot-up