U-Boot在PXA255上的移植及其在BDI2000中的调试

U-Boot移植
=========

 
1, 创建目录/文件
[young@localhost u-boot-1.1.2]$ ls board/glacier
Makefile  config.mk  flash.c  glacier.c  memsetup.S  u-boot.lds
[young@localhost u-boot-1.1.2]$ ls cpu/pxa
Makefile   cpu.c  i2c.c  interrupts.c  config.mk  mmc.c pxafb.c  serial.c  start.S
[young@localhost u-boot-1.1.2]$ ls include/configs/glacier.h
include/configs/glacier.h
 
2, 添加配置
Makefile
#########################################################################
## XScale Systems
#########################################################################
glacier_config  :       unconfig
        @./mkconfig $(@:_config=) arm pxa glacier
 # params: TARGET ARCH CPU BOARD
 
3, Configure
make glacier_config
 
4, 编译
make
(要重新配置make distclean先)
 
 
 
 
 

U-Boot在BDI2000上的调试(RAM)
==========================


1, 配置编译选项, 生成调试信息
注意去掉-gstabs, 我们需要dwarf-2格式的调试信息, -g3与-gdwarf-2用于宏定义调试
config.mk (根目录下)
DBGFLAGS= -ggdb -gdwarf-2 -g3 -DDEBUG
AFLAGS_DEBUG := 

 
2, 修改reloacte地址(TEXT_BASE)
[young@localhost u-boot-1.1.2]$ cat board/glacier/config.mk
TEXT_BASE = 0xa3080000
 
关于这个TEXT_BASE, 它是U-Boot的连接地址:
[young@localhost u-boot-1.1.2]$ cat config.mk |grep -w LDFLAGS
LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
U-Boot reset后会从flash重定位到RAM中的TEXT_BASE处, 相关代码:
[young@localhost u-boot-1.1.2]$ cat cpu/pxa/start.S | grep -A15 relocate:
relocate:                               /* relocate U-Boot to RAM           */
        adr     r0, _start              /* r0 <- current position of code   */
        ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */
        cmp     r0, r1                  /* don't reloc during debug         */
        beq     stack_setup
 
        ldr     r2, _armboot_start
        ldr     r3, _bss_start
        sub     r2, r3, r2              /* r2 <- size of armboot            */
        add     r2, r0, r2              /* r2 <- source end address         */
 
copy_loop:
        ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
        stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
        cmp     r0, r2                  /* until source end addreee [r2]    */
        ble     copy_loop
 

3, 编译后将image利用BDI load到TEXT_BASE (ram)中, 并停靠在程序起始处
BDM-Jtag $ load 0xa3080000 u-boot.bin bin
BDM-Jtag $ ci
BDM-Jtag $ ti 0xa3080000
 
4, Host中GDB配置
HOST中启动gdb, 装入带有调试信息的ELF文件。为方便调试, 先在当前目录下创建gdb的配置
文件.gdbinit
[young@localhost u-boot-1.1.2]$ cat .gdbinit
# gdbinit file
# @author: Young
# @date: Feb., 16, 2006
 
#add-symbol-file u-boot 0xa3080000
target remote bdi:2001
 
define zcon
detach
target remote bdi:2001
end
 
define zmi
info macro $arg0
end
 
define zme
macro expand $arg0
end
 
5, 启动GDB
[young@localhost u-boot-1.1.2]$ arm-linux-gdb u-boot
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
reset () at /home/young/xscale/u-boot-1.1.2/cpu/pxa/start.S:102
102             mrs     r0,cpsr                 /* set the cpu to SVC32 mode        */
(gdb) b memsetup
Breakpoint 1 at 0xa3080444: file /home/young/xscale/u-boot-1.1.2/board/glacier/memsetup.S, line 49.
(gdb) c
Continuing.
 
Breakpoint 1, memsetup () at /home/young/xscale/u-boot-1.1.2/board/glacier/memsetup.S:49
49          mov      r10, lr
(gdb) l
44       */
45
46      .globl memsetup
47      memsetup:
48
49          mov      r10, lr
50
51             
52
53              /* all in inputs */
(gdb)
54              ldr             r0,     =GPDR0
55              ldr             r1,     =0
56              str             r1,   [r0]
57
58              ldr             r0,     =GPDR1
59              ldr             r1,     =0
60              str             r1,   [r0]
61
62              ldr             r0,     =GPDR2
63              ldr             r1,     =0
(gdb) b start_armboot
Breakpoint 2 at 0xa3080c08: file board.c, line 265.
(gdb) c
Continuing.
 
Breakpoint 2, start_armboot () at board.c:265
265             gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
(gdb) list
260             init_fnc_t **init_fnc_ptr;
261             char *s;
262             struct glacier_tag_table *tag_table;
263
264             /* Pointer is writable since we allocated a register for it */
265             gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
266             /* compiler optimization barrier needed for GCC >= 3.4 */
267             __asm__ __volatile__("": : :"memory");
268
269             memset ((void*)gd, 0, sizeof (gd_t));
(gdb) zmi CFG_MALLOC_LEN
Defined at /home/young/xscale/u-boot-1.1.2/include/configs/glacier.h:56
  included at /home/young/xscale/u-boot-1.1.2/include/config.h:2
  included at /home/young/xscale/u-boot-1.1.2/include/common.h:35
  included at /home/young/xscale/u-boot-1.1.2/lib_arm/board.c:28
#define CFG_MALLOC_LEN (CFG_ENV_SIZE + 128*1024)
(gdb) zme CFG_MALLOC_LEN
expands to: (0x20000 + 128*1024)
(gdb) p CFG_MALLOC_LEN
$1 = 262144
 
 
 

U-Boot在ROM中的调试
==================


如果U-Boot事先烧写在flash中, 而不是手工load到ram里, 这样的话调试起来稍微麻烦些.
如果代码连接到ram, 且是在运行中被reloacate到ram, 则只有relocate以后的代码才可以
用gdb调试, 而这之前的代码是运行在flash上的. 由于其连接到的地址(ram)与代码在flash
中的运行地址不同, gdb无法插入断点, 也就不能用它来调试. 至于relocate以前的代码,
要么用bdi单独调试, 要么直接连接到flash中, 然后用gdb调试.
 
[young@localhost u-boot-1.1.2]$ arm-linux-objdump -t u-boot|grep start_armboot
a30800c4 l       .text  00000000 _start_armboot
a3080c04 g     F .text  000001bc start_armboot
 
1, 先将image写入到flash, 并设置断点
BDM-Jtag $ erase 0 0x20000 2
BDM-Jtag $ prog 0 u-boot.bin bin
BDM-Jtag $ res
BDM-Jtag $ ci
BDM-Jtag $ bi 0xa3080c04 //在relocate以后设置断点
BDM-Jtag $ go
 
2, 用gdb调试relocate以后的代码
[young@localhost u-boot-1.1.2]$ arm-linux-gdb u-boot
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
start_armboot () at board.c:256
256     {
(gdb) monitor ci
(gdb) b
Breakpoint 1 at 0xa3080c04: file board.c, line 256.
(gdb) n
265             gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
(gdb)
 
3, 调试reloacate之前的代码, 可以利用BDI的ti/info/rdall命令单步跟踪, 或者用bi/go。 不过这时
gdb派不上用场了
 
可先反汇编代码
[young@localhost u-boot-1.1.2]$ arm-linux-objdump -D u-boot > da
[young@localhost u-boot-1.1.2]$ vi da
...
a308004c <_bss_end>:
a308004c:       a30cf4f4        tstgep  ip, #-201326592 ; 0xf4000000
 
a3080050 <reset>:
a3080050:       e10f0000        mrs     r0, CPSR
a3080054:       e3c0001f        bic     r0, r0, #31     ; 0x1f
a3080058:       e3800013        orr     r0, r0, #19     ; 0x13
a308005c:       e129f000        msr     CPSR_fc, r0
a3080060:       eb00001d        bl      a30800dc <cpu_init_crit>
...
在reloacate之前这些指令的运行地址是a3080ABC - TEXT_BASE = ABC, 因此以下断点
都设置在ABC处, 而不是a3080ABC
BDM-Jtag $ res
    Core state        : debug mode (ARM)
    Debug entry cause : Single Step
    Current PC        : 0x00000054
    Current CPSR      : 0x080000d3 (Supervisor)
BDM-Jtag $ ti //单步走
    Core number       : 0
    Core state        : debug mode (ARM)
    Debug entry cause : Single Step
    Current PC        : 0x00000058
    Current CPSR      : 0x080000d3 (Supervisor)
BDM-Jtag $ rda //查看寄存器
         User     FIQ     Superv   Abort     IRQ      Undef
GPR00: 080000c0 080000c0 080000c0 080000c0 080000c0 080000c0
GPR01: 00000400 00000400 00000400 00000400 00000400 00000400
GPR02: 00000806 00000806 00000806 00000806 00000806 00000806
...
PC   : 00000058
CPSR : 080000d3
SPSR :          f80000ff 080000d3 68000013 88000053 f80000ff
BDM-Jtag $ ti
    Core number       : 0
    Core state        : debug mode (ARM)
    Debug entry cause : Single Step
    Current PC        : 0x0000005c
    Current CPSR      : 0x080000d3 (Supervisor)
BDM-Jtag $ ci //设置断点前先清楚断点
BDM-Jtag $ bi 0x800dc //在cpu_init_crit处设置断点
Breakpoint identification is 0
BDM-Jtag $ go //continue
BDM-Jtag $ info
    Core number       : 0
    Core state        : debug mode (ARM)
    Debug entry cause : Inst Breakpoint
    Current PC        : 0x000800dc
    Current CPSR      : 0x680000d3 (Supervisor)
BDM-Jtag $
 
4, 修改TEXT_BASE直接连接到flash, 然后用gdb调试
如果relocate前代码量较大, 也可以先把TEXT_BASE置为0, 这样指令的
连接地址为flash, 便可以用gdb调试, 但并非所有代码都能在flash里运行
(比如初始化flash中的flash probe部分), 所以可以在relocate代码过后再把
TEXT_BASE改回来, 用gdb在ram中调试.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值