Memory Locations

Problems

...

Images of the board

About

what/where

About firmware

About devtools

tool

flashing with openOCD

OpenOCD created by Dominic Rath is a gdb-server and flash-utility for ARM-Controllers. It supports ARM7 and ARM9 controllers. Wiggler-type and FTDI2232-based devices can be used as hardware-interfaces. Supported host-plattforms are Linux/Unix-systems or MS-Windows-systems (native and cygwin).

Michael Fischer has created a page on which he describes how OpenOCD can be used together with the GNU-debugger (gdb, Insight-gdb, ddd etc.). The following section will describe methods how to use the flash-programming functionality in OpenOCD.

OpenOCD is under heavy development and it's difficult to keep this page up to date. But the developers maintain a documentation. If you are building OpenOCD yourself you can create the document with make pdf. Some tools are needed to create it (I use MiKTeX). Read esp. the chapter Deprecated/Removed Commands of the document if you get error-messages when using the configuration/scripts shown below.
Flash-programming with OpenOCD

OpenOCD supports flash programming on NXP/Philips LPC2000, Atmel AT91SAM7 and ST STR7 ARM7-controllers (version SVN100). Flash-programming can be done by accessing the OpenOCD-telnet-server but I prefer a method where the flash programming is automated. This is very convenient when working with make. If everything is setup correctly a simple make program will transfer the binary-code into the flash-memory.

Installing OpenOCD on a MS-Windows-System

The methodes described in this small introduction have been tested in a Windows 2000 system with a Wiggler-type JTAG-interface (Olimex ARM-JTAG) and a FTDI2232-based hardware (i.e. JTAGKEY, WINARM-JTAG). The usage of OpenOCD is basicly the same on Linux/Unix-systems.

You can get the latest OpenOCD source-code from the berliOS SVN-system and compile and install it yourself. For MS-Windows Michael Fischer provides a precompiled version which includes a setup-software.

On "modern" MS-Windows-systems like NT, 2000 or XP a special driver must be installed for Wiggler-type hardware interface. This driver is called giveio and is included in the binary distribution from Michael Fischer. The setup-software will ask you if the driver should be installed. But it can also be installed lateron with install-giveio.bat (Administrator priviledges needed for installation only). For FTDI FT2232 based interfaces like the ones from Amontec, Olimex, Signalyzer and myevertool.de the FTDI-drivers must be installed. M. Fischer's package includes the drivers for some devices (the main difference is the VID/PID the "real" hardware-drivers are those available from FTDI with additional inf-files).

Basicly three files are needed for an automated flash-programming:

openocd.exe itself (giveio has to be installed when using a Wiggler-type hardware on Win32-systems, the FTDI driver has to be installed when using FT2232-based hardware). Michael Fischer decided to create two binaries one for Wiggler-type hardware connected to the parallel-port and one for FT2232-based devices.
a config-file with definitions of the hardware-interface (i.e. a Wiggler-type interface) and the target-controller
a script-file with the flash-commands

Writing NXP/Philips LPC2000 internal flash-memory

All files mentioned in this section are available for download (see below). A simple example-application is also included in the file archive. Target-controller is a NXP LPC2138 on a Keil LPC2130-board. But the basic method can be used for all LPC2000 controllers after minimal changes.

In addition to the three files basicly needed for the automated flash programming I have added some small "glue"-files to make configuration and usage a little easier.

The first file openocd_install_info.cmd is simple "batch-file" to set some variables. All cmd-files are made for MS Windows OS but Unix-Users will get the idea how to create own "shell-scripts". The locations of the OpenOCD binaries and the used JTAG-interface are given in the file:

rem -
rem Modify this to the installed OpenOCD-binaries
rem The following is for the precompiled binaries from Michael Fischer
rem with sources from OpenOCD SVN-version 100 installed on a
rem PC running Windows-2000 (german)
rem -
set OOCD_INSTALLDIR=C:\Programme\openocd-2006re100\bin
set OOCD_BIN_FTDI=%OOCD_INSTALLDIR%\openocd-ftd2xx.exe
set OOCD_BIN_PP=%OOCD_INSTALLDIR%\openocd-pp.exe

rem The used interface either FTDI(=WinARM-JTAG, JTAGKEY etc.) or PP(="Wiggler")
set OOCD_INTERFACE=FTDI
rem set OOCD_INTERFACE=PP

set OOCD_EXE=%OOCD_BIN_FTDI%
set OOCD_CFG=openocd_lpc2138_flash_ftdi.cfg
goto LAB_DOIT

LAB_PP

set OOCD_EXE=%OOCD_BIN_PP%
set OOCD_CFG=openocd_lpc2138_flash_wiggler.cfg

LAB_DOIT

rem set OOCD_DBG=-d 1

%OOCD_EXE% %OOCD_DBG% -f %OOCD_CFG%

LAB_END

rem pause

As you can see the script just calls the "install-info" so set the configuration-variables after that it calls the OpenOCD-binary with the config-file for the used (configured) JTAG-hardware.

The files openocd_lpc2138_flash_ftdi.cfg and openocd_lpc2138_flash_wigger.cfg are basicly the same and just differ in the interface-defintion-section. Here just the configuration for FTDI FT2232-based hardware is shown. The configuration-file for Wiggler-type hardware can be found in the file-archive. In the content listed below you will notice that the jtag_speed has been set to 3, this has been found out by "try and error", the settings 0,1 and 2 did not work form me with a JTAGKEY and WinARM-JTAG (in the cfg for the Wiggler-hardware jtag_speed 0 has been used and worked reliably).

The example is a small program for a NXP LPC2138 on Keil LPC2138 evaluation board. But it should be rather portable and can be used for other NXP-controllers with minor modifications. Souce-code, linker-scripts, makefile and OpenOCD-config/-script are included. [Download] (zip, timestamp 20061013)
NXP LPC23xx/24xx

Newer versions of OpenOCD offer TCL-scripting. The following configuration uses scripting and will not work with older versions of OpenOCD. Please read the comments below for further information.

OpenOCD configuration for LPC23xx/LPC24xx

tested with:

- OpenOCD SVN971 (MinGW)

- LPC2378

- Olimex LPC2378-STK

- Amontec JTAGKey

Interface/"cable"

either

script interface/jtagkey.cfg

or

interface ft2232

ft2232_device_desc "Amontec JTAGkey A"

ft2232_layout jtagkey

ft2232_vid_pid 0x0403 0xcff8

or pass through command line with -f or -c

slow and verbose during init:

debug_level 3
fast disable
jtag_speed 100

delays on reset lines

jtag_nsrst_delay 200
jtag_ntrst_delay 200

use combined on interfaces or targets that can't set TRST/SRST separately

interface/jtagkey.cfg is a file from the OpenOCD "library". OpenOCD startes searching files on directory level "above" openocd.exe on MS Windows systems (default configuration). So if openocd.exe is located for example in C:\myutils\emb\bin\ the file jtagkey.cfg should be located in C:\myutils\emb\interface\. If you do not have the file at hand, you may uncomment the interface lines in the configuration file given above.

Of cause any other interface-file from the interface-library, a self written interface-file or a interface-section in the openocd.cfg can be configured too when using other interfaces like for example a "Wiggler". But I have just tested with the cable from Amontec.

Also note that my user-defined commands for flashing do include a verify command. This will fail if OpenOCD has calculated the checksum at flash-address 0x00000014 on-the-fly during flash-programming because of the option calc_checksum given at the bank defintion and the value in the load-image (hex, elf, bin file) does not match the calculated value. Verification failure can be avoided by setting the correct checksum in the assembler-code (.word <checksum> at "reserved" entry in table) so load-image and flash-content after write will match. I do not recomment to remove the calc_checksum option or to disable verify because the target will not start from flash after reset if the checksum at 0x14 is invalid and problems during flash-programming may not be detected.

These settings are for a Debug-Configuration with flash-memory-update in Eclipse using the "Eclipse C/C++ GDB Hardware Debugging" plugin (that's _not_ Zylin's plugin)

BTW: the Target Managment Terminal is a useful Eclipse-plugin which offers serial-communication and telnet from inside Eclipse (a "View"). Can be used to communicate with OpenOCD and for "printf-debugging" via UART. Make sure to install the RXTX End-User Runtime from COM-port access on Win32.
Writing Atmel AT91SAM7S internal flash-memory

The files and setup needed to write the internal flash-memory of an AT91SAM7 controller are basicly the same as described in the previous section. The file-archive includes all needed files together with some example code (download link below). According to a message in the OpenOCD-forum the procedure can also be used to program AT91SAM7X256/AT91SAM7XC256.

The example is prepared to be used with the precompiled OpenOCD binaries from Michale Fischer (link below). and includes a set of files to make usage and configuration as easy as possible (hopefully).

The first file openocd_install_info.cmd is simple "batch-file" to set some variables. All cmd-files are made for MS Windows OS but Unix-Users will get the idea how to create own "shell-scripts". The locations of the OpenOCD binaries and the used JTAG-interface are given in the file:

rem -
rem Modify this to the installed OpenOCD-binaries
rem The following is for the precompiled binaries from Michael Fischer
rem with sources from OpenOCD SVN-version 100 installed on a
rem PC running Windows-2000 (german)
rem -
set OOCD_INSTALLDIR=C:\Programme\openocd-2006re100\bin
set OOCD_BIN_FTDI=%OOCD_INSTALLDIR%\openocd-ftd2xx.exe
set OOCD_BIN_PP=%OOCD_INSTALLDIR%\openocd-pp.exe

rem The used interface either FTDI(=WinARM-JTAG, JTAGKEY etc.) or PP(="Wiggler")
set OOCD_INTERFACE=FTDI
rem set OOCD_INTERFACE=PP

OpenOCD is called from openocd_go_flash.cmd

set OOCD_EXE=%OOCD_BIN_FTDI%
set OOCD_CFG=openocd_at91sam7s_flash_ftdi.cfg
goto LAB_DOIT

LAB_PP

set OOCD_EXE=%OOCD_BIN_PP%
set OOCD_CFG=openocd_at91sam7s_flash_wiggler.cfg

LAB_DOIT

rem set OOCD_DBG=-d 3

%OOCD_EXE% %OOCD_DBG% -f %OOCD_CFG%

LAB_END

rem pause

As you can see the script just calls the "install-info" so set the configuration-variables after this it calls the OpenOCD-binary with the config-file for the used (configured) JTAG-hardware.

The files openocd_at91sam7s_flash_ftdi.cfg and openocd_at91sam7s_flash_wigger.cfg are basicly the same and just differ in the interface-defintion-section. Here just the configuration for FTDI FT2232-based hardware. The configuration-file for Wiggler-type hardware can be found in the file archive.

The file openocd_at91sam7s_flash.script includes the commands which are called on reset (since reset_and_init is given as parameter for target). The register-writes to init "ecr" have been found in the openocd-package. I have just adapted them to the default frequency used on most boards for USB-compatiblity when using the AT91SAM7S-series. If you use another target and it does not work for you just remove the lines starting with mww.

The example is a small program for an AT91SAM7S64 or AT91SAM7S256 on an Atmel AT91SAM7-EK or OX SAM7-EK evaluation-board. Souce-code, linker-scripts, makefile and OpenOCD-config/-script are included. [Download] (zip, timestamp 20061013)

If the lockbits are set (i.e. if SAM-BA has been used before) they have to be cleared with the flash protect command. Start OpenOCD (see openocd_go_debug.cmd in the archive), connect to OpenOCD by telnet (telnet localhost 4444) and use the command flash info 0 to determine the number of lockbits (output after lockbits:, i.e. 16). Unprotect with the command flash protect 0 0 <number of lockbits-1> off (i.e. flash protect 0 0 15 off).

Manual erase of the flash should be done for the complete flash. Use the command flash erase 0 0 <number of sections-1> (i.e. flash erase 0 0 15). Usualy it's not needed to erase manualy since the SAM7 flash-programming-functions in OpenOCD already do this automaticly during flash write.

For those who use an AT91SAM7X controller: I have got an e-mail from David Jander: [...]The AT91SAM7X introduced bootloader selection via NVM-bits in flash. An empty part (or one that has been erased using the ERASE pin), will programm fine with OpenOCD using your instructions (adjusting the obvious bits for SAM7X), but the application will never run! That is because NVM-bit2 (boot selection) has to be set. AFAIK this can only be done using SAM-BA (the proprietary ATMEL tool) right now, since OpenOCD doesn't support NVM bits yet (please correct me if I'm wrong... I whish I was).[...]. David has not been wrong when he wrote his e-mail. But the situation has changed in the meantime. Later versions of OpenOCD offer a command to set/clear NVM-bits. This has been confirmed by Uwe Bonnes for the SVN-Version 90/31.8.2006. The command is at91sam7 gpnvm <num> <bit> <set|clear> where <num> is the flash-bank number as given in the config-file, <bit> and <set|clear> is obvious. Example: at91sam7 gpnvm 0 2 set. Verify the state of the gpnvm-bits after a manual flash erase.
Writing ST STR71x internal flash-memory

The basic approach is the same as already presented for the other targets.

The configuration-file - here for an FT2232-based device connected to a STR710:

You may have to "unprotect" the flash using the flash protect command thru the telnet-interface once. Please read the Flash-Programming Application-Note available from st.com!

Currently I just provide a small example-package with demonstrates how the internal flash of a STR710 can be programmed using OpenOCD. You can download the demo-package including the OpenOCD configuration, programming-script and a small example-application here. The method has been tested with the ST STR710 evaluation-board.
Programming external CFI flash-memories

OpenOCD also suppots programming of external flash memories. The following example has been created for an STMicro STR710 controller and has been tested with the external flash-memory ST M28W320B (4Mbytes) as on the STR710 evaluation-board. But the approach is rather general and should be easily portable to other targets.

rem Filename: openocd_setup.cmd

rem set OOCD_INSTALLDIR=C:\Programme\openocd-2006re100\bin
rem set OOCD_EXE=%OOCD_INSTALLDIR%\openocd-ftd2xx.exe
rem set OOCD_EXE=%OOCD_INSTALLDIR%\openocd-pp.exe

set OOCD_INSTALLDIR=C:\WinARM\utils\OpenOCD
set OOCD_EXE=%OOCD_INSTALLDIR%\openocd.exe

rem The used interface either FTDI(=WinARM-JTAG, JTAGKEY etc.) or PP(="Wiggler")
set OOCD_INTERFACE=ftdi
rem set OOCD_INTERFACE=pp

set OOCD_TARGET=str710
rem set OOCD_OPT=-d 2
set OOCD_OPT=

set OOCD_DBG_CONFIG=openocd_dbg_%OOCD_TARGET%_%OOCD_INTERFACE%.cfg
set OOCD_FLASH_CONFIG=openocd_flash_%OOCD_TARGET%_%OOCD_INTERFACE%.cfg
set OOCD_FLASH_CFI_CONFIG=openocd_flash_cfi_%OOCD_INTERFACE%.cfg

Starting openocd_start_flash_cfi.cmd will first execute openocd_setup.cmd to read in the general setup (OpenOCD install-path, used interface etc.) and set some environment variables. These variables are used to determine the paramater for openocd.exe which is called by the openocd_start_flash_cfi.cmd too. Both cmd-files are made for MS-Windows OS but can be easily ported to Unix/Linux "shell-scripts". OpenOCD will start and read the openocd_flash_cfi_ftdi.cfg script and after initalisiation of the JTAG-interface it will reset the target ARM and process the commands listed in the openocd_flash_cfi.script file. The cfg-file is currently prepared for a JTAGkey (or the compatible WinARM-JTAG) but can be easily adapted to other FTDI2232-based interfaces or parallel-port interfaces ("Wigglers") by modifing the interface-section in the cfg-file. Examples on this and other pages may serve as templates.

[Download] a zip-archive which includes the cmd-, cfg- and script-files together with an example-application source-code

And yes, the described method can be used to install uClinux on the STR710 eval-board (I have tested this "here"). The bootloader available in the Code-Package for ST's application-note AN2119 "Getting Started with uClinux for STR71x" can be uploaded to the external flash using OpenOCD.
Create the OpenOCD configuration- and reset-script "on the fly"

Here a approach to create the needed configuration-script and the reset-script which inlcude the flash-programming command "on the fly" in a makefile

The following file uses the makefile-syntax. Basicly it's a makefile but it gets included from the application's makefile. I have choosen this approach since including everything in a single makefile would be a little confusing. This example demonstrates the setup to flash the internal flash-memory of an STMicrosystems STR710 but can be adapted to other targets easily. The content of the file oocd_flashing.mk: