$ wget http://busybox.net/downloads/busybox-1.18.5.tar.bz2; tar xvf busybox-1.18.5.tar.bz2
$ cd busybox-1.18.5; make menuconfig
$ make; make install
====== 編程 ======
===== 交叉編譯 =====
- 安裝交叉編譯工具鏈。Windows 安裝 [[https://launchpad.net/gcc-arm-embedded|GNU Tools for ARM Embedded Processors]]。
$ sudo apt-get install gcc-arm-none-eabi
$ sudo apt-get install gdb-arm-none-eabi
$ sudo dpkg -i --force-overwrite /var/cache/apt/archives/gdb-arm-none-eabi_7.0.1-2_i386.deb
* [[http://stackoverflow.com/questions/14921463/how-to-install-cross-compiler-on-ubuntu-12-04-lts-for-microprocessor-sa1100|How to install cross compiler (on ubuntu 12.04 LTS) for microprocessor SA1100?]]
* [[http://www.cnx-software.com/2012/01/31/debugging-embedded-linux-with-gdbserver-and-insight-gdb-gui/|Debugging Embedded Linux with GDBserver and Insight (gdb GUI)]]
* [[https://answers.launchpad.net/gcc-arm-embedded/+question/193998|do the tools supprt ARM7 and ARM9 architectures]]
- 編譯程式。
* [[http://shukra.cedt.iisc.ernet.in/edwiki/EmSys:Starting_Cortex-M3_Development_Using_the_GNU_Tool_Chain_-_Part_1|EmSys:Starting Cortex-M3 Development Using the GNU Tool Chain - Part 1]]
* [[http://stackoverflow.com/questions/19944441/make-executable-binary-file-from-elf-using-gnu-objcopy|Make Executable Binary File From Elf Using GNU objcopy]]
* [[http://shukra.cedt.iisc.ernet.in/edwiki/EmSys:Starting_Cortex-M3_Development_Using_the_GNU_Tool_Chain_-_Part_2|EmSys:Starting Cortex-M3 Development Using the GNU Tool Chain - Part 2]]
===== 注意事項 =====
* [[http://embeddedgurus.com/barr-code/2009/03/coding-standard-rule-4-use-volatile-whenever-possible/|Coding Standard Rule #4: Use volatile Whenever Possible]]
====== 除錯 ======
--------------------------- ------------------
| TCP/IP | | |
| gdb <--------> gdbserver | <---> Probe (ICE) <----> | debugee |
| | USB JTAG | |
| (Host PC) | | (Target Board) |
--------------------------- ------------------
* [[wp>In-circuit emulator|ICE]]
* 實現基本除錯功能,如: 斷點和單步,供上層使用。
* [[wp>Joint Test Action Group|JTAG]]
* 目標平台會提供 JTAG 埠 ([[http://en.wikipedia.org/wiki/Joint_Test_Action_Group#Communications_model|Test Access Ports (TAP)]],必須包含 TMS、TCK TDI、和 TDO 四根針腳) 供 Probe (ICE) 連接,JTAG 埠再進一步控制 CPU。
* [[wp>Serial Peripheral Interface Bus|SPI]]
* [[http://wiki.csie.ncku.edu.tw/embedded/SPI|NCKU CSIE WIKI: SPI]]
* 透過 Qemu 運行程序。
# 或是透過 Ctrl + Alt + 2 喚起 monitor 視窗,輸出 gdbserver,等待 GDB 連接。
$ qemu-system-arm -M lm3s6965evb --kernel test.bin --serial null -nographic -S -s
$ arm-none-eabi-gdb test.elf
(gdb) target remote :1234
* [[http://shukra.cedt.iisc.ernet.in/edwiki/EmSys:Starting_Cortex-M3_Development_Using_the_GNU_Tool_Chain_-_Part_1|EmSys:Starting Cortex-M3 Development Using the GNU Tool Chain - Part 1]]
* [[http://stackoverflow.com/questions/19944441/make-executable-binary-file-from-elf-using-gnu-objcopy|Make Executable Binary File From Elf Using GNU objcopy]]
* [[http://shukra.cedt.iisc.ernet.in/edwiki/EmSys:Starting_Cortex-M3_Development_Using_the_GNU_Tool_Chain_-_Part_2|EmSys:Starting Cortex-M3 Development Using the GNU Tool Chain - Part 2]]
* [[http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/|QEMU – Emulating Raspberry Pi the easy way (Linux or Windows!)]]
* Windows 上調用 GDB 會出現底下錯誤:
* [[http://sourceforge.net/p/gnuarmeclipse/support-requests/42/|The system tried to join a drive to a directory on a joined drive]]
* 透過 OpenOCD 連接至目標除錯。
$ openocd.exe -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg
$ arm-none-eabi-gdb test.elf
(gdb) target remote localhost:3333
(gdb) monitor reset halt
(gdb) load
(gdb) break main
(gdb) continue
* [[http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22|Minimal semihosted ARM Cortex-M "Hello World"]]
* [[http://sourceforge.net/p/openocd/mailman/message/33395116/|[OpenOCD-devel] Build OpenOCD on Windows]]
====== 術語 ======
* [[wp>Flash Memory]]
* [[wp>EEPROM]]
* ULINK/JLINK: 俗稱 Probe。PC 端透過 Probe 和版子溝通。
* [[http://blog.csdn.net/u011318735/article/details/12449515|JLINK、JTAG、ULINK、STLINK的区别]]
* PC 端透過 ULINK/JLINK/STLINK 裝置連接到有提供 JTAG 接口的目標平台上,進行偵錯。
* [[http://www.keil.com/ulink2/|ULINK]]: ARM
* The Keil ULINK2 Debug Adapter connects your PC's USB port to your target system (via JTAG, SWD, or OCDS) and allows you to program and debug embedded programs on target hardware.
* [[https://www.segger.com/jlink-debug-probes.html|J-Link]]: [[wp>https://en.wikipedia.org/wiki/Segger_Microcontroller_Systems|SEGGER]]
* [[http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168?sc=internet/evalboard/product/251168.jsp|ST-LINK]]: 意法半導體 ([[wp>STMicroelectronics]])
* 除錯協定
* JTAG: [[wp>Joint Test Action Group]]
* [[http://www.zeroplus.com.tw/software_download/200910ZEROPLUS_JTAG_11.pdf|JTAG 量測技術大觀]]
* [[http://www.xjtag.com/support-jtag/jtag-technical-guide.php|JTAG – A technical overview]]
* 描述接口硬體需要具備的針腳 (必須包含 TMS、TCK TDI、和 TDO 四根針腳),和內部狀態轉換流程。
* 目標平台上可以有多個 TAP,通常以串聯形式 (daisy chain) 存在,通常又稱 scan chain。下圖中共有三個 TAP 被串聯。{{ http://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Jtag_chain.svg/654px-Jtag_chain.svg.png }}
* SWD: [[wp>Joint_Test_Action_Group#Serial_Wire_Debug|Serial Wire Debug]]。可與 JTAG 共用相同硬體接口,但作用針腳改為 SWDIO 和 SWCLK。
* [[http://www.support.code-red-tech.com/CodeRedWiki/HardwareDebugConnections|SWD / JTAG Connectors and Pinout]]
* [[https://www.segger.com/interface-description.html|J-Link Debug Probes Interface description]]
* [[http://www.eeboard.com/evaluation/%E6%AD%A3%E7%89%88%E4%B8%8E%E9%AB%98%E4%BB%BF%E4%B9%8B%E9%97%B4%E7%9A%84%E5%AF%B9%E5%86%B3-ulink2/|正版与高仿之间的对决–ULINK2]]
* [[https://developer.mbed.org/handbook/CMSIS-DAP|CMSIS-DAP]] 與 JTAG 和 SWD 的關係。{{ https://developer.mbed.org/media/uploads/samux/xcmsis-dap-6.png.pagespeed.ic.CoJTAX2YvN.png }}
* PC 端 (Host computer) 上,懂 CMSIS-DAP 的除錯器 (CMSIS-DAP compliant),透過 USB 埠和懂 CMSIS-DAP 的接口 (CMSIS-DAP interface) 溝通。
* 懂 CMSIS-DAP 的接口 (CMSIS-DAP interface),再透過 JTAG 或是 SWD 和目標平台溝通。
* 接口可以是獨立的 Probe (Link),或是整合進目標平台。
====== 外部連結 ======
* [[http://gordenhao.pixnet.net/blog/post/29189867|U-Boot 簡介]]
* [[http://www.busybox.net/|BusyBox]]
* [[http://embeddedgurus.com/|Embedded Gurus]]
* [[http://www.bravegnu.org/gnu-eprog/index.html|Embedded Programming with the GNU Toolchain]]
* [[http://www.state-machine.com/arm/Building_bare-metal_ARM_with_GNU.pdf|Building Bare-Metal ARM Systems with GNU]]