Program external flash with OpenOCD fails

Hi,

I have an external flash (Spansion S29GL128N90) connected to a NXP LPC2478 microcontroller. Everytime when I try to flash this external flash I get the following error from OpenOCD (Version 0.4.0):

Flash Manufacturer/Device: 0x0001 0x227e 
error writing to flash at address 0x80000000 at offset 0x00000000 (-902) 
Command handler execution failed in procedure 'flash' called at file "command.c", line 650 called at file "command.c", line 361

Command used:

monitor flash write_image erase ./bin/Debug/We-Res.hex 0x00 ihex

The flash is connected to the EMI and seems to works fine. OpenOCD is able to erase the flash and I am able to read the data, that I have written previously with the following commands:

monitor flash erase_sector 1 0 10
monitor flash fillw 0x80000000 0x12345678 0x1000

This is the flash configuration that I have added to the original OpenOCD LP2478 config file:

flash bank $_FLASHNAME2 cfi 0x80000000 0x1000000 2 2 $_TARGETNAME

So what is wrong with the write_image command? any ideas?

Just quick thoughts,

You need to have the clock freq set to a reasonable (“correct”) value to ensure writing to flash works. You need to add to config file similar to below…

#flash bank <base_addr> <chip_width> <bus_width> <target_number> [<target_name> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]

flash bank $_FLASHNAME at91sam7 0 0 0 0 0 0 0 0 0 0 0 0 18432

You may also have to set other parameters such as delays etc.

Here is part of a cfg file for any chip

jtag_khz 500

LPC2888 Target related

if { [info exists CHIPNAME] } {

set _CHIPNAME $CHIPNAME

} else {

set _CHIPNAME lpc2888

}

if { [info exists ENDIAN] } {

set _ENDIAN $ENDIAN

} else {

set _ENDIAN little

}

#set _CPUTAPID 0x00000000

if { [info exists CPUTAPID ] } {

set _CPUTAPID $CPUTAPID

} else {

force an error till we get a good number

set _CPUTAPID 0x00000000

}

Define the _TARGETNAME

set _TARGETNAME [format “%s.cpu” $_CHIPNAME]

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

reset_config trst_and_srst

jtag_ntrst_delay 200

jtag_nsrst_delay 200

#jtag scan chain

#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

#target arm7tdmi

target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME -endian little -variant arm7tdmi-s_r4

working_area 0 0x00400000 32768 nobackup

$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x0038000 -work-area-size 0x8000 -work-area-backup 0

#flash bank <base_addr> <chip_width> <bus_width> <target_number> [<target_name> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]

flash bank lpc288x 0 0 0 0 $_TARGETNAME 12000000

Hope this helps.

Ernest

Further to previous post

RTFM http://openocd.berlios.de/doc/html/Flash-Commands.html

12.1 Flash Configuration Commands

— Config Command: flash bank name driver base size chip_width bus_width target [driver_options]

Configures a flash bank which provides persistent storage for addresses from base to base + size - 1. These banks will often be visible to GDB through the target’s memory map. In some cases, configuring a flash bank will activate extra commands; see the driver-specific documentation.

  • name … may be used to reference the flash bank in other flash commands. A number is also available.

  • driver … identifies the controller driver associated with the flash bank being declared. This is usually cfi for external flash, or else the name of a microcontroller with embedded flash memory. See Flash Driver List.

  • base … Base address of the flash chip.

  • size … Size of the chip, in bytes. For some drivers, this value is detected from the hardware.

  • chip_width … Width of the flash chip, in bytes; ignored for most microcontroller drivers.

  • bus_width … Width of the data bus used to access the chip, in bytes; ignored for most microcontroller drivers.

  • target … Names the target used to issue commands to the flash controller.

  • driver_options … drivers may support, or require, additional parameters. See the driver-specific documentation for more information.

Note: This command is not available after OpenOCD initialization has completed. Use it in board specific configuration files, not interactively.

Ernest