w60x openocd debugging guide

46
Beijing Winner Microelectronics Co., Ltd. 1 W60X OpenOCD Debugging Guide V0.1 Beijing Winner Microelectronics Co., Ltd. Address: 18 th Floor, Yindu Building, No.67, Fucheng Road, Haidian District, Beijing ,China Tel: +86-10-62161900 Website: www.winnermicro.com

Upload: others

Post on 25-Jan-2022

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

1

W60X OpenOCD Debugging Guide

V0.1

Beijing Winner Microelectronics Co., Ltd.

Address: 18th Floor, Yindu Building, No.67, Fucheng Road, Haidian District, Beijing ,China

Tel: +86-10-62161900

Website: www.winnermicro.com

Page 2: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

1

Document History

Version Completion Date Revision Record Author Auditor

V0.1 2018-11-16 Initial release LiLm

Page 3: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

2

Content

Document History ................................................................................................................................................ 1

Content ................................................................................................................................................................. 2

1 Introduction .................................................................................................................................................. 4

1.1 Purpose ......................................................................................................................................... 4

1.2 Readers ......................................................................................................................................... 4

1.3 Term Definition ............................................................................................................................ 4

2 Quick Start: How to use Eclipse+OpenOCD to debug W60X. .................................................................... 5

2.1 How to Connect W60X ................................................................................................................ 5

2.2 Instal Eclipse ................................................................................................................................ 5

2.3 Download Source Code of W60X_SDK ...................................................................................... 5

2.4 Import SDK project to Eclipse ..................................................................................................... 5

2.5 Config OpenOCD to Start Up .................................................................................................... 12

2.6 Config Eclipse Debugging Function .......................................................................................... 17

2.7 Compiling SDK Source Code with Optimization Level ............................................................ 22

2.8 Compile SDK ............................................................................................................................. 24

2.9 Start to Debug ............................................................................................................................. 26

2.10 Stop Debugging .......................................................................................................................... 30

2.11 Compile Release Firmware ........................................................................................................ 31

2.12 Update Firmware through UART Port ....................................................................................... 32

3 OpenOCD Using Guide .............................................................................................................................. 32

3.1 OpenOCD Introduction .............................................................................................................. 32

3.2 Install OpenOCD ........................................................................................................................ 33

3.2.1 Install libusb ....................................................................................................................... 34

3.2.2 Install HIDAPI library ........................................................................................................ 34

3.2.3 Install OpenOCD ................................................................................................................ 35

3.3 Debugging with OpenOCD Command Lines ............................................................................. 36

3.3.1 Start up OpenOCD with JLINK Simulator ......................................................................... 36

3.3.2 Start up OpenOCS with CMSIS-DAP Simulator ............................................................... 38

3.3.3 Host Computer Connects with OpenOCD .......................................................................... 39

3.3.4 Common Commands .......................................................................................................... 40

3.3.5 Gdb Debugging Examples .................................................................................................. 41

4 Appendix .................................................................................................................................................... 44

Page 4: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

3

4.1 Install zylincdt to Eclipse ........................................................................................................... 44

Page 5: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

4

1 Introduction

1.1 Purpose

This document introduces how to use GDB to debug with OpenOCD in Eclipse and how can W60X

developers deal with single step debugging with OpenOCD.

1.2 Readers

The developers with W60X.

1.3 Term Definition

OpenOCD:Open On-Chip Debugger

Page 6: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

5

2 Quick Start: How to use Eclipse+OpenOCD to debug W60X.

2.1 How to Connect W60X

JTAG simulator should be used with OpenOCD debugging. Choose one type of JTAG simulator (such as

JLINK or CMSIS-DAP and so on) and connect the JTAG simulator to W60X. Following figure is the

connecting method:

TMS(pb6)

W600 TCK(pb7) GND

VDD33

TMS

TCK JTAG仿真器GND VREF

After connected, W60X powers on, and connect JTAG simulator to host computer.

Different JTAG simulator has different driver. For JLINK simulator, users can refer to chapter 3.3.1 to install

the driver. For CMSIS-DAP simulator, no driver should be installed. For other JTAG simulators, please

install the driver by yourselves.

2.2 Instal Eclipse

Download the compressed package from http://www.winnermicro.com/html/1/156/158/497.html. It provides

Eclipse (integrated zylincdt plug-in unit), Cygwin(OpenOCD has been installed), Cross compiling

tools(arm-none-eabi-gcc) etc.

Discompressed the package and read the ReadMe.txt firstly. Then double-click W60X_IDE.exe to start up

configured Eclipse.

2.3 Download Source Code of W60X_SDK

The SDK package can be downloaded from http://www.winnermicro.com. The Version number supported

OpenOCD should be G3.1 or higher version.

2.4 Import SDK project to Eclipse

Following figures are importing setps:

Page 7: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

6

Page 8: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

7

Page 9: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

8

After the SDK has imported, the compiler script directory should be redirected to the directory where

Makefileis located. Followings are operation steps:

Page 10: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

9

Page 11: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

10

Page 12: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

11

Page 13: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

12

2.5 Config OpenOCD to Start Up

Following is how to start up OpenOCD with Eclipse. The advantage of this operation is that users don’t have

to open a Cygwin window to start OpenOCD.

Page 14: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

13

Double-click Create:

Page 15: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

14

OpenOCD configuration files should be filled out according to the type of JTAG simulator. Different JTAGE

simulator has different configuration files. We have provided with JLINK and CMSIS-DAP.

The configuration files are in the directory of /usr/local/share/openocd/scripts/board/ in Cygwin with the

names W60X_jlink.cfg and W60X_cmsis-dap.cfg.

Following example is for using CMSIS-DAP:

Page 16: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

15

Click Run to start OpenOCD. After starting up successfully, following information will display in console

window:

Page 17: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

16

If the SWD debugging function is disable in W60X SDK, the W60X will be unrecognized during starting

OpenOCD. Please modify the firmware and try again.

Then clik following icon to start:

Page 18: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

17

2.6 Config Eclipse Debugging Function

Right click on the SDK in project management window, choose Debug Configurations:

Page 19: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

18

Double-click to create a new debugging configuration:

Page 20: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

19

The name should be same with the project so as to distinguish other projects:

Page 21: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

20

The debugger in use is arm-none-eabi-gdb. The cross compiling tools have been installed in the integrated

package with the directory /opt/arm-none-eabi-gcc/ in Cygwin.

Following is the configuration environment:

Page 22: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

21

Page 23: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

22

The command for initial is:

target remote localhost:3333

monitor reset halt

monitor flash write_image erase /cygdrive/c/workdir/WM_SDK/Bin/W60X_DBG.img 0x08010000

file ./Tools/GNU/W60X.elf

Address of W60X’s debugging firmware is from 0x08010000 in Flash. So please don’t destroy the data in

Flash.

The two paths in the command should be filled by actual project paths. The path of W60X_DBG.img should

be the absolute path. Symbol table file W60X.elf should be the relative path.

Others can be used with default values, and then click Apply to save the configurations.

2.7 Compiling SDK Source Code with Optimization Level

In order to use symbol tables for single-step debugging, the optimization should be modified from -Os to -g:

Page 24: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

23

Page 25: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

24

Save file to complete the change.

2.8 Compile SDK

Page 26: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

25

Page 27: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

26

2.9 Start to Debug

OpenOCD should be running before start to debug and then doing following operation:

Page 28: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

27

Choose Yes when following prompt appears:

Page 29: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

28

After the firmware has updated completely, the following prompt will appear:

Click F8 to execute Resume command, and the icon will stop at main():

Page 30: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

29

Now users can start to degug.

Other debugging command can be used in the Run menu:

Page 31: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

30

Users can click on toolbar icon for shortcut operation. Please refer to chapter 2.2 Install Eclipse.

2.10 Stop Debugging

For stopping debugging, users can stop gdb or stop OpenOCD.

Page 32: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

31

2.11 Compile Release Firmware

The optimization level should be -Os when compiling formal firmware:

Page 33: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

32

Users can decide to enable or disable SWD function by themselves (call the function wm_swd_config(0)).

2.12 Update Firmware through UART Port

W60X firmware can be updated through UART port. Users can refer to < WM_W60X_Firmware Update

Guide.pdf> from http://www.winnermicro.com/html/1/156/158/497.html.

3 OpenOCD Using Guide

3.1 OpenOCD Introduction

OpenOCD is an open source JTAG program in host computer. OpenOCD can connect to embedded device

through JTAG simulator and can provide general debugging commands for host computer.

Page 34: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

33

OpenOCD has supported following JTAG simulators:

AICE, ARM-JTAG-EW, ARM-USB-OCD, ARM-USB-TINY, AT91RM9200, axm0432,

BCM2835, Bus Blaster, Buspirate, Chameleon, CMSIS-DAP, Cortino, DENX,

Digilent JTAG-SMT2, DLC 5, DLP-USB1232H, embedded projects, eStick,

FlashLINK, FlossJTAG, Flyswatter, Flyswatter2, Gateworks, Hoegl, ICDI,

ICEBear, J-Link, JTAG VPI, JTAGkey, JTAGkey2, JTAG-lock-pick, KT-Link,

Lisa/L, LPC1768-Stick, MiniModule, NGX, NXHX, OOCDLink, Opendous,

OpenJTAG, Openmoko, OpenRD, OSBDM, Presto, Redbee, RLink, SheevaPlug

devkit, Stellaris evkits, ST-LINK (SWO tracing supported),

STM32-PerformanceStick, STR9-comStick, sysfsgpio, TUMPA, Turtelizer,

ULINK, USB-A9260, USB-Blaster, USB-JTAG, USBprog, VPACLink, VSLLink,

Wiggler, XDS100v2, Xverve

OpenOCD has supported following CPU core:

ARM11, ARM7, ARM9, AVR32, Cortex-A, Cortex-R, Cortex-M, LS102x-SAP,

Feroceon/Dragonite, DSP563xx, DSP5680xx, EnSilica eSi-RISC, FA526, MIPS

EJTAG, NDS32, XScale, Intel Quark

OpenOCD has supported following Flash:

ADUC702x, AT91SAM, ATH79, AVR, CFI, DSP5680xx, EFM32, EM357, eSi-TSMC,

FM3, FM4, Kinetis, LPC8xx/LPC1xxx/LPC2xxx/LPC541xx, LPC2900, LPCSPIFI,

Marvell QSPI, Milandr, NIIET, NuMicro, PIC32mx, PSoC4, PSoC5LP, SiM3x,

Stellaris, STM32, STMSMI, STR7x, STR9x, nRF51; NAND controllers of

AT91SAM9, LPC3180, LPC32xx, i.MX31, MXC, NUC910, Orion/Kirkwood,

S3C24xx, S3C6400, XMC1xxx, XMC4xxx

3.2 Install OpenOCD

The operations in this chapter are all based on Cygwin environment in Windows. After the Cygwin has been

installed, double-click cygwin\Cygwin.bat to open a Cygwin shell window, all the following operations are

Page 35: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

34

based in this shell window.

According to OpenOCD official documentation requirement, compilation must depend on:

So users need to test the Cygwin environment and install unsupported items.

3.2.1 Install libusb

Some simulators for OpenOCD need libsub. So the libsub should be installed before compiling OpenOCD

(W60X has provided this lib).

Installation steps for libusb:

1. Download source code package from https://libusb.info and decompress.

2. Entry source code menu.

3. Execute ./configure --prefix=/usr/ to generate Makefile.

4. Execute make compiling.

5. Execute make install.

3.2.2 Install HIDAPI library

Many users use CMSIS-DAP simulator, so W60X has supported this type of simulator. HIDAPI library should

be installed for OpenOCD when users use CMSIS-DAP simulator (W60X has provided this lib).

Installation steps for HIDAPI library:

1. Execute git clone https://github.com/signal11/hidapi.git to download source code.

2. Entry source code menu.

Page 36: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

35

3. Execute ./bootstrap to generate configure file.

4. Execute ./configure --prefix=/usr to generate Makefile.

5. Exectue make to compile.

6. Execute make install.

3.2.3 Install OpenOCD

1. Download OpenOCD Source Code:

Download source code package from http://www.winnermicro.com. Current version is

W60X_openocd_0.10.0_r1。

2. Execute ./configure --enable-cmsis-dap --disable-werror to generate Makefile.

If some error occurs, users have to repare the lack of items. The -enable-cmsis-dap needn’t to be

selected if CMSIS-DAP simulator is no use.

Following is the print information after testing:

Page 37: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

36

3. Execute compiling command to start compilation.

make

4. Execute installation command to install OpenOCD to the system path.

make install

OpenOCD’s default installation path is /usr/local/bin, the path for configuration file is /usr/local/share/openocd.

A configuration file named W60X.cfg will appeared in the path /usr/local/share/openocd/scripts/target and

OpenOCD will use it.

3.3 Debugging with OpenOCD Command Lines

3.3.1 Start up OpenOCD with JLINK Simulator

1. Install driver

JLINK’s official driver can’t be used for OpenOCD. The usable driver should be download from

http://zadig.akeo.ie:

Page 38: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

37

2. Create configuration file

If the source code package is not downloaded from git, such configuration file may have been

installed already in OpenOCD. So following steps can be ignored.

Create a new txt file in /usr/local/share/openocd/scripts/board with the name W60X_jlink_cfg.

Open the txt file and input following content:

Save and create a configuration file for OpenOCD connecting JLINK.

3. Execute openocd.exe -f /usr/local/share/openocd/scripts/board/W60X_jlink.cfg -s

Page 39: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

38

/usr/local/share/openocd/scripts/ in shell window of Cygwin. Following information will appear after

OpenOCD starting successfully:

3.3.2 Start up OpenOCS with CMSIS-DAP Simulator

1. Create configuration file

If the source code package is not downloaded from git, such configuration file may have been

installed already in OpenOCD. So following steps can be ignored.

Create a new txt file in /usr/local/share/openocd/scripts/board with the name W60X_cmsis-dap.cfg.

Open the txt file and input following content:

Save and create a configuration file for OpenOCD connecting CMSIS-DAP.

Page 40: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

39

4. Execute openocd.exe -f /usr/local/share/openocd/scripts/board/W60X_cmsis-dap.cfg -s

/usr/local/share/openocd/scripts/ in shell window of Cygwin. Following information will appear after

OpenOCD starting successfully:

3.3.3 Host Computer Connects with OpenOCD

After starting up successfully, OpenOCD can be connected with telnet or gdb. The port number of telnet is

4444, the port number of gdb is 3333.

Ctrl+C can stop the running of OpenOCD. After OpenOCD starting up, shell window should keep opening to

ensure OpenOCD’s normal operation and ensure telnet or gdb’s normal debugging.

3.3.3.1 Connect by telnet

Windows system comes with telnel client. Users can open a command prompt window and input telnet

localhost 4444 or telnet 127.0.0.1 4444 to connect with OpenOCD daemon.

Page 41: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

40

Then users can input commands in command lines:

3.3.3.2 Connect by gdb

The gdb of W60X’s cross compiling tool is arm-none-eabi-gdb, and the download address is:

https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major.

If user use W60X’s integrated package, such tools has already been in the package and can be used directly.

Input command arm-none-eabi-gdb into shell window of Cygwin and the gdb will start up. Then users can

input the debugging commands:

3.3.4 Common Commands

The following table lists some common commands of OpenOCD. Users can also input help command to view

all the currently supported commands.

All the commands can be input directly for telnet. For gdb, users should add monitor before the commands.

Target State Handling Commands

poll Query current target’s status

Page 42: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

41

halt Interrupt target’s running

resume [address] Resume target’s running. If the address is specified,

programme will run from this address.

step [address] Single-step operation. If the address is specified,

programme will execute one command from this address.

reset Reset target.

Breakpoint Commands

bp <addr> <length> [hw] Set breakpoint at <addr>, command length is <length>,

[hw] means hardware breakpoint.

rbp <addr> Delete breakpoint at <addr>.

Memory Access Commands

mdw ['phys'] <addr> [count] Show the word (4 bytes) counts from physical address.

mdh ['phys'] <addr> [count] Show the short (2 bytes) counts from physical address.

mdb ['phys'] <addr> [count] Show the byte counts from physical address.

mww ['phys'] <addr> <value> Write a word (4 bytes) to physical address with the

<value>.

mwh ['phys'] <addr> <value> Write a short (2 bytes) to physical address with the

<value>.

mwb ['phys'] <addr> <value> Write a byte to physical address with the <value>.

flash write_image [erase] [unlock] filename [offset [file_type]]

Write the firmware’s filename to the offset of flash address.

More detailed commands of OpenOCD can be referred from http://openocd.org/documentation/.

3.3.5 Gdb Debugging Examples

This chapter provides an example with gdb single-step debugging. Let users start to debug with W60X.

Firmware and symbol table are required for single-step debugging. Users can refer to chapter “2.8 Complie

SDK” to generate such files.

In this example, we use CMSIS-DAP simulator to connect with W60X and then start up OpenOCD in Cygwin:

Page 43: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

42

Then create a new Cygwin window and execute arm-none-eabi-gdb:

Then connect the OpenOCD’s daemon with target remote localhost:3333:

Input “monitor reset halt” to reset and stop working of CPU:

Then input “monitor flash write_image erase /cygdrive/g/temp/W60X_SDK_G3.0Final/image/W60X.dbg

0x08010000” to update firmware to flash:

Then input “file ./image/W60X.out” to load the symbol table:

Then input “b main” to set a breakpoint, so as to stop at main function:

Page 44: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

43

At last, input “c” to let programme start running:

Then it will stop at main function:

Then usesrs can input “n” to debug with single-step:

Input “p libc_sem” and the pointer address will be printed out:

Using “set libc_sem=0x100” to modify the pointer address:

About more detailed debugging skills of gdb, users can refer to the document from

http://sourceware.org/gdb/current/onlinedocs/gdb/.

Page 45: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

44

4 Appendix

4.1 Install zylincdt to Eclipse

Using plug-in Zylincdt can support debugging with embedded GDB in Eclipse. The W60X integrated package

has provided this plug-in.

This plug-in can be download from http://opensource.zylin.com/zylincdt, following is installation steps:

Page 46: W60X OpenOCD Debugging Guide

Beijing Winner Microelectronics Co., Ltd.

45

Some warning maybe appeare during installation. At last the tools will prompt to reset Eclipse, following the

instruction is OK.