a) 安装VMware — just do it.
b) 安装arm-elf-gcc toolset — we can get it from: http://www.gnuarm.com/
c) 安装JLINK软件 — just get it from SEGGER website.
d) 实现2440 gdb 启动脚本:
1) 参阅JLinkGDBServer文档,如下:
文件: UM08005_JLinkGDBServer.pdf 大小: 509KB
本文要用到的相关文件下载在Linux公社的1号FTP服务器里,下载地址:
FTP地址:ftp://www.linuxidc.com
用户名:www.linuxidc.com
密码:www.muu.cc
在 2011年LinuxIDC.com\3月\搭建GCC+JLINK开发调试环境(裸机调试)
下载方法见 http://www.linuxidc.net/thread-1187-1-1.html
2) 此gdb启动脚本的主要任务是初始化内存控制器,禁止WatchDog,禁止中断。
参考JLinkGDBServer文档后,经测试,以下代码可以正常工作:
##main function defined for initial the S3C2440 CPU.
define reset_2440
monitor endian little ##little endian, should be the same as your application.
##copied from JLinkGDBServer Document.
monitor reset ##reset the S3C2440
monitor reg cpsr = 0xd3 ##setup cpsr register.
monitor speed auto ##Link Speed.
##translated from VIVI S3C2440 version.
#disable watchdog
monitor MemU32 0x53000000 = 0
#disalbe interrupt — int-mask register
monitor MemU32 0x4A000008 = 0xFFFFFFFF
#disalbe interrupt — int-sub-mask register
monitor MemU32 0x4A00001C = 0x7FFF ## vivi set it as 0x7FF, why???
#initialize system clocks — locktime register
monitor long 0x4C000000 = 0xFF000000
#initialize system clocks — clock-divn register
monitor long 0x4C000014 = 0x5 #CLKDVIN_400_148
#initialize system clocks — mpll register
monitor long 0x4C000004 = 0x7f021 #default clock
#setup memory controller
monitor MemU32 0x48000000 = 0x22111110 #conw
monitor MemU32 0x48000004 = 0x00000700 #bank0
monitor MemU32 0x48000008 = 0x00000700 #bank1
monitor MemU32 0x4800000c = 0x00000700 #bank2
monitor MemU32 0x48000010 = 0x00000700 #bank3
monitor MemU32 0x48000014 = 0x00000700 #bank4
monitor MemU32 0x48000018 = 0x00000700 #bank5
monitor MemU32 0x4800001c = 0x00018009 #bank6
monitor MemU32 0x48000020 = 0x00018009 #bank7
monitor MemU32 0x48000024 = 0x008e04eb #vREFRESH
monitor MemU32 0x48000028 = 0xB2 #vBANKSIZE — 128M/128M — should
according to the physical
memory size? — 0xB0 ??
monitor MemU32 0x4800002c = 0x30 #vMRSRB6
monitor MemU32 0x48000030 = 0x30 #vMRSRB7
end
##main function defined for connect to the TARGET.
##arg0 = IP address.
##arg1 = PORT number of JLINK gdb server.
define connect_jei
if $argc == 2
target remote $arg0:$arg1
reset_2440
end
end
3) 脚本做好以后,以下命令为怎样使用该脚本—假设该脚本名字为targets.cmd,编译出的程序文件为main.out
arm-elf-gdb -x targets.cmd -ex “connect_jei 192.168.1.168 2331” main.out
然后在gdb命令行中输入以下命令即可调试了:
load
b main
c
4) 实现2440 C语言启动基本配置,用汇编实现。
在启动代码中,我们只需要设置SP,FP寄存器即可。
代码如下:
.global _start
.extern main
.text
_start:
mov r11, #0x0 @@fp
mov sp, #0x31000000 @@sp = 0x30000000+16M
1: bl main @@call main()
b 1b @@loop forever.
.end
同时需要实现的是Link脚本,如下:
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
. = 0x30000000;
.text :
{
*(.text)
}
. = ALIGN(8192);
.data :
{
*(.data)
}
.bss :
{
*(.bss)
}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}
main.c 内容如下:
int main(void)
{
int i = 0;
while(1)
{
i++;
}
return 0;
}
makefile 如下:
AS = arm-elf-as
CC = arm-elf-gcc
LD = arm-elf-ld
ROM = arm-elf-objcopy
DAS = arm-elf-objdump
AFLG = -mcpu=arm920t -g -mlittle-endian
INSIGHT = arm-elf-insight
GDB = arm-elf-gdb
all:
$(AS) $(AFLG) init.S -o init.o
$(CC) $(AFLG) -c main.c -o main.o
$(LD) -g -EL -nostdlib -Bstatic -Tlink.lds init.o main.o -o main.out
$(ROM) -O binary -R .comment -R .note -S main.out main.bin
$(DAS) –architecture=arm -D main.out > dump.txt
debug:
$(GDB) -x targets.cmd -ex “connect_jei $(TARGET) $(PORT)” main.out
insight:
$(INSIGHT) -x targets.cmd -ex “connect_jei $(TARGET) $(PORT)” main.out
在使用make debug 以及make insight 之前,需要设中级TARGET以及PORT变量。
完整的开发源码包如下:
文件: 2440_gdb_test.rar
大小: 6KB
直接用命令行调用GDB调试的命令如下:
arm-elf-gdb -x targets.cmd -ex “connect_jei 192.168.1.168( 这个ip 换成自己 pc的ip 或者localhost ,by imjacob) 2331” main.out
然后在gdb命令窗口中输入如下命令即可调试:
load
b _start
b main (应为 _main,by imjacob)
c