版本 a71811dde239ee54d8e7a69bd644d0bdb43e5c39
Changes from a71811dde239ee54d8e7a69bd644d0bdb43e5c39 to b9ed60d7a3519b4be9aa4aeddedb303f13bca0af
---
title: Lab36: ELF
toc: no
...
預期目標
-------------
* 在 `STM32F429i Discovery</embedded/STM32F429>`_ 開發簡易 ELF loader
* 學習 OpenOCD 和 gdb
* 複習 `Week #7: ELF</embedded/2014q3w7>`_ 學習進度
預先準備
------------
* 確認 ``$PATH`` 可找到 `Lab 35</embedded/Lab35>`_ 設定的 GNU Toolchain
- ``arm-none-eabi-gcc -v`` 預期輸出 ``4.8.3-11ubuntu1`` 一類包含 ubuntu 的字串
- 若否,請重新設定 PATH 環境變數
* 確認 `STM32F429i Discovery</embedded/STM32F429>`_ 板子已經由 USB 線接上裝有 GNU/Linux 的開發環境,並確保 `Lab 35</embedded/Lab35>`_ 所提及的工具均已正確安裝,如 openocd 與 gdb
取得 ELF loader 並在 STM32 驗證
--------------------------------------------
* ``cd workspace`` # 假設工作目錄為 ``workspace``
* ``git clone https://github.com/embedded2014/elf-loader.git && elf-loader``
* 開啟兩個虛擬終端機,在其中一個終端機執行以下 ``make openocd``,預期輸出為
.. code-block:: prettyprint
CC main.c
CC start.c
LINK app.elf
text data bss dec hex filename
164 8 4 176 b0 app.elf
Creating list...
make[1]: Leaving directory '/home/jserv/NCKU/2014/elf-loader/app'
...
Launch OpenOCD for stm32f4discovery
Open On-Chip Debugger 0.9.0-dev-00105-ge1bc7f4 (2014-08-08-20:38)
...
* 在另外一個終端機執行 ``make run``
- ``cd workspace/elf-loader && make run``
* 切換到原本執行 OpenOCD 的視窗,可見到以下輸出 (請保持耐心)
.. code-block:: prettyprint
make[1]: Entering directory 'elfloader/app'
CLEAN
CC main.c
CC start.c
LINK app.elf
text data bss dec hex filename
164 8 4 176 b0 app.elf
Creating list...
make[1]: Leaving directory 'elfloader/app'
Launch OpenOCD for stm32f4discovery
Open On-Chip Debugger 0.9.0-dev-00105-ge1bc7f4 (2014-08-08-20:38)
...
ELF: Scan ELF indexs...
ELF: Examining section 1 .text
ELF: Examining section 2 .rel.text
ELF: Examining section 3 .rodata
...
ELF: Examining section 11 .symtab
ELF: Examining section 12 .strtab
ELF: Done
ELF: Relocating section .text
ELF: Offset Info Type Name
ELF: 00000034 00001202 R_ARM_ABS32 i
...
ELF: Relocating section .rodata
ELF: Offset Info Type Name
ELF: 00000038 00001502 R_ARM_ABS32 banner
...
ELF: symAddr=20000F48 relAddr=20000F8C
ELF: R_ARM_ABS32 relocated is 0x20000F54
Hello world on Oct 30 2014 at 17:28:11 (0)
...
Done
semihosting: *** application exited ***
* 看到 ``Hello world`` 字樣出現 10 次,表示 ``app/main.c`` 編譯與連結出來的 ``app-striped.elf`` 已正確載入並執行
參考資訊
------------
* `BeagleBoard OpenOCD<http://elinux.org/BeagleBoardOpenOCD>`_
* `GDB and OpenOCD<http://openocd.sourceforge.net/doc/html/GDB-and-OpenOCD.html>`_