利用qemu学习嵌入式linux(二)—— Debug U-Boot

一,编译并运行

qemu可以模拟很多开发板,这儿选定了一款vexpress-a9,建立以下工作目录

mkdir ~/qemu
cd ~/qemu
mkdir vexpress-a9
cd vexpress-a9

以后,所有基于vexpress-a9板子的实验都会在该目录进行

首先,去ftp://ftp.denx.de/pub/u-boot/下载最新版本U-Boot,u-boot-2015.10.tar.bz2

解压:tar zxvf u-boot-2015.10.tar.bz2

cd u-boot-2015.10

由于使用了gcc-arm-linux-gnu编译器,需要在Makefile中指定ARCH及CROSS_COMPILE

vi Makefile

增加以下两行

ARCH ?= arm
CROSS_COMPILE ?= arm-none-eabi-

觉得有必要的话,也可以在config.mk文件下增加-ggdb参数:

PLATFORM_CPPFLAGS := -ggdb

保存,然后编译

make vexpress_ca9x4_defconfig
make

ls的结果如下:

[llp@llp u-boot-2015.10]$ ls
api        disk      include      MAKEALL   snapshot.commit  u-boot.cfg
arch       doc       Kbuild       Makefile  System.map       u-boot.lds
board      drivers   Kconfig      net       test             u-boot.map
common     dts       lib          post      tools            u-boot.srec
config.mk  examples  Licenses     README    u-boot
configs    fs        MAINTAINERS  scripts   u-boot.bin

此时,直接执行这条命令就能跑u-boot了

qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot

 

二,CodeBlocks图形调试环境

首先启动一个支持gdb的qemu机器

qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot -s -S

增加的几个参数定义:
-S              freeze CPU at startup (use 'c' to start execution)
-s              shorthand for -gdb tcp::1234

然后打开codeblocks,配置settings->compiler(可不配置),指向arm-none-eabi-

配置setting->debuger,指向arm-none-eabi-gdb,另外勾选下do not run the debugee,可以防止程序直接运行

接下来新建一个空的工程,将u-boot目录下所有的.c;.h;.s;.S文件导入(有心情可以把没用的删掉,我是懒得烦了)

右击工程名,打开properties,在debugger标签下,配置下remote connection,填入localhost及1234即可。

这样之后,直接点击调试小图标就可以开始调试uboot了,默认暂停在b reset这儿,可以按F7单步。

三,Relocating之后的处理

relocation之后的断点需要重新定位symbols,可以参考http://www.denx.de/wiki/view/DULG/DebuggingUBoot

对于这块a9板,可以用这个命令add-symbol-file u-boot 0x6FF83000,然后就能对上relocating之后的代码了。

原文地址:https://www.cnblogs.com/leop/p/5109347.html