/* 如下筆記針對RHEL6爲平臺,針對2440開發的安裝過程,其餘發行版需稍做修改 */linux
1. 安裝gdb server(arm-linux-gdb-7.5.tar.gz),直接解壓後biuld-all,編譯後會在/opt目錄下自動生成/arm-linux-gdb目錄,裏面包含gdb的可執行文件。而後:ubuntu
export PATH=$PATH:/opt/arm-linux-gdb/bin/ /* 添加的環境變量環境變量必須位於 */bash
source /root/.bashrc /* 交叉工具鏈前,並且需另外export */eclipse
2. 安裝JLink調試工具(JLink_Linux_V434a.tgz),具體步驟ide
tar xzvf JLink_Linux_V434a.tgz工具
cp -d libjlinkarm.so* /usr/lib -f插件
cp 45-jlink.rules /etc/udev/rules.d/
debug
最後接上開發板,打開電源,運行JLinkGDBserver調試
/* 出現的問題 */server
按照上述步驟,在RHEL6上是木有任何問題的,但換做ubuntu 14.4上運行JLinkGDBserver的時候就會報
error while loading shared libraries: libusb-0.1.so.4: cannot open shared object file: No such file or directory
缺乏了libusb-0.1.so.4庫文件,因而在/usr/lib中找,確實找不到。曾經嘗試把/lib/x86_64-linux-gnu/libusb-0.1.so.4拷貝到/usr/lib/,運行JLinkGDBserver後又報
error while loading shared libraries: libusb-0.1.so.4: wrong ELF class: ELFCLASS64
估計是64bit和32bit的兼容性問題,因而把原來在RHEL6中的libusb-0.1.so.4拷貝過來,丟到ubuntu 14.04中的/usr/lib中,再運行JLinkGDBserver,成功啓動。
3. 安裝Eclipse
3.1 上 https://www.eclipse.org/downloads/ 選擇一個C/C++的IDE並安裝(如今最新出的的neon還沒試過,反正MARS是沒問題的)。
3.2 安裝zylin基於JLink V8的調試插件
在eclipse任務欄,Help->Install New Software,
Work with: http://opensource.zylin.com/zylincdt,選中並Next,完成安裝後重啓eclipse
3.3 建立工程目錄,選擇Makefile with Existing Code,打開選中已有工程的目錄(當中包含源碼*.c *.S 以及Makefile),而最後調試的其實就是編譯出來的.elf文件,所以若是沒有.elf文件,則要make一個。
3.4 對Debug調試器進行配置包括:
3.4.1 點擊Debug按鈕的側面箭頭,選擇debug configuration
3.4.2 雙擊右邊的Zylin Embedded Debug Native
3.4.3 選中新建的配置,右邊debugger標籤,把arm-elf-gdb更改成arm-linux-gdb(上文的gdb7.5安裝就是爲了在這完成的debug準備工做),選擇要調試的.elf文件(要是沒有,得make一個),並把Stop on startup at:main的鉤去掉。
3.4.4 在Commands標籤中,Initialize Command的空白處輸入初始化命令
4. 最後把PC(USB)與開發板(JTAG)經過JLink鏈接好,在Linux中啓動JLinkGDBserver(所以須要兩個終端,一個用來啓動JLinkGDBserver,另外一個用來啓動eclipse),顯示connected,把開發板調至NORFLASH端,啓動開發板,在eclipse中,點擊debug,debug程序開始執行,並能F5單步調試,實驗成功。
/* 如下爲Initialize Command中的內容,僅供參考 */
# connect to the J-Link gdb server
target remote localhost:2331
# Set JTAG speed to 30 kHz
monitor endian little
monitor speed 30
# Reset the target
monitor reset
monitor sleep 10
#
# CPU core initialization (to be done by user)
#
# Set the processor mode
monitor reg cpsr = 0xd3
#config MMU 配置MMU
#flush v3/v4 cache
monitor cp15 7, 7, 0, 0 = 0x0
#/* flush v4 TLB 協處理器*/
monitor cp15 8, 7, 0, 0 = 0x0
#disable MMU stuff and caches
monitor cp15 1, 0, 0, 0 =0x1002
#Peri port setup
monitor cp15 15, 2, 0, 4 = 0x70000013
#disable watchdog kangear 關閉看門狗
monitor MemU32 0x53000000 = 0x00000000
monitor sleep 10
#disable interrupt kangear 關閉中斷
monitor MemU32 0x4A000008 = 0xffffffff
monitor MemU32 0x4A00001C = 0x7fff
#set clock
#initialize system clocks --- locktime register
monitor MemU32 0x4C000000 = 0xFF000000
#initialize system clocks --- clock-divn register
monitor MemU32 0x4C000014 = 0x5 #CLKDVIN_400_148
#initialize system clocks --- mpll register
monitor MemU32 0x4C000004 = 0x7f021 #default clock
#config sdram
monitor MemU32 0x53000000 0x00000000
monitor MemU32 0x4A000008 0xFFFFFFFF
monitor MemU32 0x4A00001C 0x000007FF
monitor MemU32 0x53000000 0x00000000
monitor MemU32 0x56000050 0x000055AA
monitor MemU32 0x4C000014 0x00000007
monitor MemU32 0x4C000000 0x00FFFFFF
monitor MemU32 0x4C000004 0x00061012
monitor MemU32 0x4C000008 0x00040042
monitor MemU32 0x48000000 0x22111120
monitor MemU32 0x48000004 0x00002F50
monitor MemU32 0x48000008 0x00000700
monitor MemU32 0x4800000C 0x00000700
monitor MemU32 0x48000010 0x00000700
monitor MemU32 0x48000014 0x00000700
monitor MemU32 0x48000018 0x0007FFFC
monitor MemU32 0x4800001C 0x00018005
monitor MemU32 0x48000020 0x00018005
monitor MemU32 0x48000024 0x008E0459
monitor MemU32 0x48000028 0x00000032
monitor MemU32 0x4800002C 0x00000030
monitor MemU32 0x48000030 0x00000030
# Setup GDB for faster downloads
#set remote memory-write-packet-size 1024
monitor speed auto
break _start
load