最近在看内核启动代码,但是在串口初始化之前不能打印任何信息,也没有在线调试工具很是痛苦。想起了以前看u-boot时会产生一个u-boot.dis文件,这里面是u-boot运行时的反汇编代码。能不能把内核的代码也产生这个zImage.dis文件呢?
因为内核的代码是arch/arm/boot/compressed/(head.o + misc.o + piggy.o)生成的,而piggy.o又包含了arch/arm/boot/zImage,而arch/arm/boot/zImage只是一个raw 二进制的文件,所以可以把内核想像成 head.o + misc.o +piggy.o + 一块大的数据四部分组成,即三个.c源文件+一大块我们不关心的数据。
要想产生zImage.dis文件,编译时必须加上-g选项,因为就三个文件,所以可以手动编译,命令如下:
点击(此处)折叠或打开
-
/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.head.o.d -nostdinc -isystem /opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -Iinclude -I/root/opt/EmbedSky/linux-2.6.30.4/arch/arm/include -include include/linux/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/include -Iarch/arm/mach-s3c2410/include -Iarch/arm/mach-s3c2400/include -Iarch/arm/mach-s3c2412/include -Iarch/arm/mach-s3c2440/include -Iarch/arm/mach-s3c2442/include -Iarch/arm/mach-s3c2443/include -Iarch/arm/plat-s3c24xx/include -Iarch/arm/plat-s3c/include -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -Wa,-march=all -g -c -o arch/arm/boot/compressed/head.o arch/arm/boot/compressed/head.S
-
-
gzip -f -9 < arch/arm/boot/compressed/../Image > arch/arm/boot/compressed/piggy.gz
-
-
/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.o.d -nostdinc -isystem /opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -Iinclude -I/root/opt/EmbedSky/linux-2.6.30.4/arch/arm/include -include include/linux/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/include -Iarch/arm/mach-s3c2410/include -Iarch/arm/mach-s3c2400/include -Iarch/arm/mach-s3c2412/include -Iarch/arm/mach-s3c2440/include -Iarch/arm/mach-s3c2442/include -Iarch/arm/mach-s3c2443/include -Iarch/arm/plat-s3c24xx/include -Iarch/arm/plat-s3c/include -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -Wa,-march=all -g -c -o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/piggy.S
-
-
/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.misc.o.d -nostdinc -isystem /opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -Iinclude -I/root/opt/EmbedSky/linux-2.6.30.4/arch/arm/include -include include/linux/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/include -Iarch/arm/mach-s3c2410/include -Iarch/arm/mach-s3c2400/include -Iarch/arm/mach-s3c2412/include -Iarch/arm/mach-s3c2440/include -Iarch/arm/mach-s3c2442/include -Iarch/arm/mach-s3c2443/include -Iarch/arm/plat-s3c24xx/include -Iarch/arm/plat-s3c/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -fno-delete-null-pointer-checks -O2 -marm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -Uarm -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fpic -fno-builtin -Dstatic= -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(misc)" -D"KBUILD_MODNAME=KBUILD_STR(misc)" -g -c -o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/misc.c
-
-
/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-ld -EL --defsym zreladdr=0x30008000 --defsym params_phys=0x30000100 -p --no-undefined -X /opt/EmbedSky/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/armv4t/libgcc.a -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/misc.o -o arch/arm/boot/compressed/vmlinux
-
-
/*最后objdump把带-g调试信息的vmlinx产生反汇编文件zImge.dis*/
-
/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-objdump -d arch/arm/boot/compressed/vmlinux > ./zImage.dis
上面的一大长串编译命令,可以在编译时make V=1,然后把打印信息保存在一个文件compile.log中,然后在compile.log的最后找到以上命令串,然后稍微修改一下(加上-g和-Iarch/arm/include)就可以了。
就可以生成zImage.dis文件了,里面正是开头部分的反汇编形式。
-
1
-
2 arch/arm/boot/compressed/vmlinux: file format elf32-littlearm
-
3
-
4
-
5 Disassembly of section .text:
-
6
-
7 00000000 <start>:
-
8 0: e1a00000 nop (mov r0,r0)
-
9 4: e1a00000 nop (mov r0,r0)
-
10 8: e1a00000 nop (mov r0,r0)
-
11 c: e1a00000 nop (mov r0,r0)
-
12 10: e1a00000 nop (mov r0,r0)
-
13 14: e1a00000 nop (mov r0,r0)
-
14 18: e1a00000 nop (mov r0,r0)
-
15 1c: e1a00000 nop (mov r0,r0)
-
16 20: ea000002 b 30 <_text+0x30>
-
17 24: 016f2818 .word 0x016f2818
-
18 28: 00000000 .word 0x00000000
-
19 2c: 001d6048 .word 0x001d6048
继续看代码。
阅读(3102) | 评论(0) | 转发(0) |