5

I am using Qemu to learn some linux kernel development/hacking and wanted to debug the boot process of Linux (2.6.34.3). I have compiled for the ARM versatile platform and is using Codesourcerys arm-none-eabi crosscompiler. I am using Eclipse as the environment to build and debug using gdbserver.

So I have manged to successfully build and run the kernel in qemu but the problem is that I dont see any source code in the debugger at the boot process(at address 0), I can only see the disassembly code. However, when it switches to virtual memory at init/main.c (address over 0xC0000000), the source code appears and I can see the source code and step through and over code. Why is that? I want that from the beginning.

Anyone have any tips on how to debug the boot process of Linux? All the guides in google shows how to debug the kernel, but they all show from start_kernel() (located in init/main.c) and not from the beginning of the boot process (in arch/arm/boot/compressed/head.S). Anyone with experience help please, thank you!

Looked into the System.map in the root folder and there is only symbols for stuff from c0004000 (where the virtual address start). I load vmlinux into gdbserver to get debug information, Maybe thats why theres no source?

0

3 Answers 3

7

The Linux kernel uses a 2-step booting processing (and this does not include any boot loader like u-Boot ...). You can better understand this especially by looking into 2 .lds files (detailed below) for linking:

  1. arch/arm/boot/compressed/vmlinux.lds.in, which generates arch/arm/boot/compressed/vmlinux.lds.

    Along with other .o files in arch/arm/boot/compressed, a vmlinux is generated inside this folder.

    You can use arm-none-eabi-nm -a -n arch/arm/boot/compressed/vmlinux to see the symbols for this stage. All addresses are physical addresses.

    These symbols are NOT included in System.map

  2. The second vmlinux is generated by kernel .o files and arch/arm/kernel/vmlinux.lds (note: the path is different)

I hope this explains why you can not see the booting source code in Eclipse.

Sign up to request clarification or add additional context in comments.

1 Comment

Why is the 2 stage booting needed? Where does the switch happen? As of v4.16, arch/arm/boot/compressed/vmlinux.lds.in was renamed to arch/arm/boot/compressed/vmlinux.lds.S
2

linux kernel is too complex to understand(for a beginner).
Why dont use use a smaller OS like xv6:

OS is small, sourcecode is about 8000 lines
used by many universities
based on V6(unix),
boot process is the same except that its less complicated than that of linux.
Appendix B of the xv6 book deals with boot process(its short and sweet).You can run gdb on qemu and see the boot process, the main files to check out for are bootasm.S(in assembler) and bootmain.c.

This is much simpler and easier to do and understand when compared to linux.(atleast for beginners).There are assingmennts on , setting up qemu , using gdb ,tracking the boot process , doing changes to the source code etc in the link given.Give it a shot :)

Cheers,
sharan

1 Comment

Thanks for the tip, I have debugged other boot processes of my other projects like baremetal applications and freeRTOS. I'm very eager to learn Linux now :) Worst case I have to read assembly through the boot process:/
0

head.S is written in assembly, not C. That's what the .S suffix indicates.

1 Comment

Yeah, but in my other embedded projects, I can also debug assembly code with the source file beside me and step through and step over. I want that for the Linux boot also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.