iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 6
0
Software Development

系統架構秘辛:了解RISC-V 架構底層除錯器的秘密!系列 第 6

Day 06: [Lab] 簡簡單單新增OpenOCD Command

0. 前言

經過上篇對OpenOCD整體架構有了基本的了解,
本篇是第二篇的Lab,談點輕鬆的事情,讓我們試著在OpenOCD中,練習加一個Command!!
原本是想要加個Hello World Command,不過看起來已經被做完嘞~~
  
  
  

1. 環境需求

同Day 3的Lab

  • ARM相關開發版,這篇用的是STM32F429I-DISCOVERY,單純剛好手邊有,另外上面有自帶ST-LINK/V2~!
      
      
      

2. 目標

建立一個Command用來查詢該Target在內部的configure,並印在OpenOCD的Console上!
簡單吧,其實是一時之間也想不到可以做啥 囧
  
  
  

3. Coding

首先,在src/target/hla_target.c中來註冊我們新增的Command

static const struct command_registration adapter_command_handlers[] = {                                                         
        {
                .chain = arm_command_handlers,
        },
        {
                .chain = armv7m_trace_command_handlers,
        },
        {
                .name = "query",
                .handler = handle_cortex_m_query_command,
                .mode = COMMAND_EXEC,
                .help = "query cortex_m configure",
                .usage = "",
        },
        COMMAND_REGISTRATION_DONE
};

在原先command chain後面加上我們需要的Command!

然後是實作的部分,直接快轉,一樣放在src/target/hla_target.c中:

COMMAND_HANDLER(handle_cortex_m_query_command)
{
        LOG_DEBUG("Hello World\n");     //編註: 練習一下Day05的內容

        struct target *target = get_current_target(CMD_CTX);

        printf("[Gernal Info]\n");
        printf("coreid    : %d\n", target->coreid);
        printf("endian    : %s\n", (target->endianness == 0x1)?"Big Endian":"Little Endian");
        printf("examined!?: %s\n", (target->examined)? "Yes":"No");

        printf("\n\n[Working area]\n");
        printf("Working-area  : %d\n", target->working_area);
        printf("Work-area-phys: 0x%08X\n", target->working_area_phys);

        return ERROR_OK;
}

時光飛逝,瞬間完成!
記得存檔!
  
  
  

4. 測試

終於寫完啦!!
現在要編譯OpenOCD,然後再來測試一下我們熱騰騰加上的Command!

如果忘記怎麼編譯,請參考Day 02: 簡介OpenOCD背景與編譯

./build.sh build src

然後去泡杯咖啡休息一下,或是去系統架構秘辛:了解RISC-V 架構底層除錯器的秘密! 系列點個訂閱按個讚!

編譯完成後,那就準備開始執行啦!!!

Day 03: [Lab] 簡單操作OpenOCD的opneocd.cfg,我們就直接拿來用吧!

不過記得在裡面加上一行:

log_output test.log

把Log導向檔案中!
然後就可以來執行OpenOCD

./openocd -f openocd.cfg

一樣,我們用Telnet來測試這個Command
如果忘記如何操作的話,可以回顧一下Day 03: [Lab] 簡單操作OpenOCD的#3.1.1 Telnet Connect!!

輸入stm32f4x.cpu query來執行看看!!

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> stm32f4x.cpu query
>

成果如下:

Open On-Chip Debugger 0.10.0+dev-00161-g6c719f0-dirty (2017-12-24-15:20)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
[Gernal Info]
coreid    : 0
endian    : Little Endian
examined!?: Yes


[Working area]
Working-area  : 0
Work-area-phys: 0x20000000

  
  
  

99. 結語

第二篇Lab,一樣是淺顯的介紹OpenOCD,主要內容是回顧過去幾篇講解的內容,
明天開始的文章,將開始介紹這次鐵人賽的主題"RISC-V"架構&其背後的程式實作!
  
  
  

參考資料

  1. Day 03: [Lab] 簡單操作OpenOCD
  2. Programming STM32 F2, F4 ARMs under Linux: A Tutorial from Scratch

上一篇
Day 05: OpenOCD 軟體架構
下一篇
Day 07: RISC-V Introduction
系列文
系統架構秘辛:了解RISC-V 架構底層除錯器的秘密!30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言