2013/04/27

使用 OpenOCD and JTAG Adaptor 調適 ARM Cortex a9 CPU


Topic:
說明如何入門 OpenOCD 和 JTAG Adaptor 
當作ICD(In Circuit Debugger)來調適 ARM Cortex-a9 CPU

Tools:
*OpenOCD: Open Source, offical web, user Guides
*JTAG Adaptor: OpenJTAG (from 100ask 百問網).


聲明:
這邊只是記錄我的學習心得,對於商品的特殊編號或機密我都沒有提到。
沒有任何廣告、公開秘密、毀謗等意圖。
有提到的也是公開的資訊,在我的REF中都有特別說明出處與來源。
如果貴司仍覺不妥,請來信告知。儘快修改。
我也不負任何法律責任,
舉例說明:我說可以用,結果你買了一個,結果不能用,我不會賠你錢。XD

Disclaimer:
Here is just the record of my study without any commercial activity.I don't mention any special number or confidential information for specific product. It is published/open information even I do. And those can be found in my reference list.If you (or your company) still feel uncomfortable with this, PLEASE let me know (e-mail or leave the mesage). I will remove or modify them as soon as possible, Thanks.

I won't be liable for any damage.
For example,once you bought a adaptor because I told you it can work well here, I won't pay indemnity if it can't work.


 

1.安裝最新OpenOCD(0.6.1)並更新OpenJTAG驅動
100ask所提供的OpenOCD 0.4.x的是經過window compiler所產生的Windows執行檔,也沒有帶有原始碼。(但是好心的帶有GUI介面)。但我們必須選用最新的OpenOCD軟體,我目前選用v0.6.1。至於為什麼要用0.6.x而不能用舊的0.4.x,似乎是0.6.x裡面開始有cortex-a8/9相關的target config,所以我認定OpenOCD於這裡開始開始有支援a9系列。但新抓的0.6.1中當然沒有帶有100ask OpenJtag 的驅動程式,還須自己編譯。所以你也不能直接上網抓取OpenOCD 0.6.1的Windows執行檔。

OpenOCD 0.6.0 : Windows binary 執行檔(可能無法直接連接OpenJTAG)
OpenOCD 0.6.0 : Source code

結論是:
a. 自己抓取最新OpenOCD 0.6.1 原始碼來編譯。
b. 更新OpenJTAG驅動(about ft2232)
c. 其實我是照著這個網站做的(http://blog.csdn.net/fhq1989312/article/details/6791907)


2.寫Interface Config file (for specific JTAG Adaptor)
因為是買100ask的OpenJTAG,他本就有附帶Interface Config file,named "openjtag.cfg"。
內文我就不張貼了~反正網路上很多,(以免觸犯甚麼法)
(Just google "openjtag.cfg")


3.寫Target Config file (for your target/board)
這部分我先聲明,其實我也非啥能手,我就是看著Cortex-a8/a9的相關電路板的target config寫出來的。(ex: omap3530, omap4430, omap4460。這些在下載的OpenOCD source code裡面都有)但是我不是照抄,我簡化了很多沒用到的東西,少了很多event。

主要就是以下步驟:

source [find openjtag.cfg]  //JTAG adaptor (這樣就不需要每次都還要 -f openjtag.cfg)
jtag newtap $_CHIPNAME dap -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
target create $_TARGETNAME cortex_a8 -endian $_ENDIAN -chain-position $_CHIPNAME.dap

Q:為什麼你知道 -irxxx 的參數值(ex: -irlen 4 -ircapture 0x1 -irmask 0xf)?
A:因為其他cortex a8/9範例都是這樣寫的,可以去翻ARMv7手冊但是比較費工

Q:TAP value我不知道怎麼設定?! (ex: $_CPUTAPID=??)
A:其實你亂輸入,OpenOCD的錯誤訊息反而會吐出他想要的值。給個參考: $_CPUTAPID=0x4BA00477(嘿)

Q:"$"是甚麼意思:
A:變數,填入你的命名或值,請用以下格式
    if { [info exists ENDIAN] } {
       set  _ENDIAN $ENDIAN
    } else {
       # this defaults to a little-endian
       set  _ENDIAN little
    }

耶耶~犯規!!
不是說要調是cortex-a9嗎?以上的target config是a8來著的。

其實不然,舉例說明,omap4460裡面有顆cortex-a9的處理器,但是他能把他宣告成a8處理器。
再看看OpenOCD的support list,你也看不見a9。

command: target types
arm7tdmi arm9tdmi arm920t arm720t arm966e arm946e arm926ejs fa526 feroceon dragonite xscale cortex_m3 cortex_a8 arm11 mips_m4k avr dsp563xx dsp5680xx testee avr32_ap7k stm32_stlink

但是,實際上我爬的點文,似乎a8和a9是可以共用的。
甚至有網友認為為何不把"cortex a8"的字眼改成"cortex a"就好,
依照一些mail list與我的經驗(因為我有試出來),我的認知是可以相容的。

最後,你可能還要在控制其他的chip(像是omap3530還有個DSP)或是components(flash)。
有了入門,應該比較好再繼續寫其他內容到target config中。


4.開啟OpenOCD作為Daemon
照理說你 $sudo make install後,會安裝到/usr/bin之下。
在你的config檔目錄下:

openocd -f target_config.cfg [-f jtag_adaptor.cfg] [-f your_script.cfg]

反正-f 後面就是相關的config檔,你喜歡寫成一個檔或是一個檔只寫一個指令都隨便你。(善用source [find openjtag.cfg])
但是通常都是一個寫明jtag adaptor的interface.cfg、一個寫明target的target.cfg、一個自己寫好的script檔script.cfg.

如果有Error就修改;反之如果OK~他只是一個daemon/server,請不要直接對它下指令。
OpenOCD內建telnet server (listen port 4444 as default) 與 gdbserver (listen port 3333 as default),請連接他們來下指令。

5.開啟telnet
開啟telnet連回本機port 4444 (i.e. 127.0.0.1:4444),就可以連到openOCD daemon/server,
請以openOCD指令控制板子,如: poll, halt, resume, reg, load_image... etc.
Download OpenOCD quick command card

6.開啟GDB
開啟gdb連回本機port 3333 (i.e. target remote 127.0.0.1:3333),就可以連到openOCD daemon/server,
請以gdb指令控制板子,如: load, list, info, break,  ... etc.
Download GDB quick command card

如果還是想用OpenOCD的指令,外加個monitor就好,
舉例說: monitor mdw phys 0x0 (mdw 是OpenOCD看記憶體的指令)

7.TBD
安裝這些東西就是想取代一些貴的ICE/ICD,主要功用應該是初始化記憶體(來放bootloader)、燒寫Flash或是除錯的應用。日後再談吧! 
  a. ram init
  b. flash
  c. gdb + gdbserver + eclipse(as GUI)


REF:
[1] http://linuxonarm.blogspot.tw/2012/12/openocde-and-gdb-on-windows-7.html
[2] http://arttools.blogspot.tw/2009/09/debugging-on-cortex-a8-system.html
[3] http://blog.csdn.net/fhq1989312/article/details/6791907
[4] http://permalink.gmane.org/gmane.comp.debugging.openocd.devel/15739


2 則留言: