OpenOCD - LPC2148 Flash Programming

Is it possible to break an LPC2148 header board irrevocably? I have the low-budget Olimex version with no serial (only USB for power and JTAG for everything else). These boards come with a demo USB program so when you plug them into a Windoze USB port, they emulate a mouse that moves in a square.

I managed to use OpenOCD and GDB to download various programs to RAM, then execute them, then I erased the Flash. So far, so good: the Flash is all 0xFFFFFFFF, so (as I understand it) the board boots up into the Philips serial bootloader. I was still able (I think) to download programs to RAM and run them.

Next, I tried to use OpenOCD to write a program to Flash. Apparently it didn’t work (maybe because I didn’t have the program in the right binary format?) but I can no longer talk to the board with OpenOCD. When I run OpenOCD, it either SEGFAULTs or says:

dhm@voxan$ openocd/openocd-preview-20060213/src/openocd -debug 3
Error:   jtag.c:986 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch
dhm@voxan$ openocd/openocd-preview-20060213/src/openocd -debug 3
Error:   arm7_9_common.c:536 arm7_9_poll(): JTAG queue failed while reading EmbeddedICE status register
dhm@voxan$ openocd/openocd-preview-20060213/src/openocd -debug 3
Error:   jtag.c:986 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch

I’ve tried a few other tools as well (Rowley CrossLoader, Macgraigor OpenOCD in a VMWare virtual machine) and they all seem to have trouble talking to the board via the Wiggler.

Could I have broken the header board? Is there any way to get back to completely erased Flash so I can play with OpenOCD some more?

(This is on Linux, btw.)

Thanks!

Phew, not borken. I grounded P0.14, forcing the ISP bootloader to start, and the JTAG started working again. Now, back to figuring out how to build binaries OpenOCD can download to Flash.

Y’know, I wonder if the problem was, OpenOCD programmed my incorrectly-formatted file, then set the correct checksum in the interrupt vector block. (Of course, since the file was formatted wrong, the vectors were random garbage.) But the ISP bootloader would see the correct checksum, map in the Flash vectors, and call the reset location. This would go off into space randomly, but none of the other vectors (undefined instruction, SWI, prefetch abort, data abort, etc) had any recovery code either. Ergo: who knows what happens.

Hello,

yeah, it’s likely that this is what happened.

OpenOCD shouldn’t be able to destroy the bootloader, as it uses only the specified IAP interface provided by Philips.

OpenOCD expects a plain binary image. You can use GNU’s objcopy to turn an ELF image into a plain binary:

arm-none-eabi-objcopy -O binary main.out main.bin

where main.out is the ELF file, and main.bin is the resulting binary.

Regards,

Dominic

Dominic:
OpenOCD expects a plain binary image. You can use GNU’s objcopy to turn an ELF image into a plain binary:

arm-none-eabi-objcopy -O binary main.out main.bin

Works great! It's a little fiddly to get Flash erased and then the program burned (sometimes I have to reset or power-cycle the LPC2148 board, or ground P0.14, something like that) but I've successfully burned and then executed a program.

Next problem: GDB.

With RAM-loaded programs, GDB works OK. I use “target remote :3333” to talk to OpenOCD, then “restore a.out” to make GDB load the program into RAM. From there, I can set hardware breakpoints, run, jump to an address, etc. (E.g. I use “jump *0x40000000” to start running the program.)

With Flash-loaded programs, GDB doesn’t work. I can still connect to OpenOCD and examine Flash memory, and GDB knows all the symbol values, but I can’t get it to start executing.

“jump *0x0” says “The program is not being run.”

“run” says “Don’t know how to run. Try ‘help target’.”

“help target” doesn’t give me anything useful.

Is it possible to debug Flash code using OpenOCD and GDB?

I’m going to try putting the code in a loop like:

int i = *(int *)0x40000000;
while (i == *(volatile int *)0x40000000) ;

Then when I get connected with GDB, I’ll change the contents of RAM at 0x40000000 and (I hope) catch the program when it breaks out of the loop. (I’ve actually got this coded & compiled, but I’m having trouble with OpenOCD again, so I can’t tell whether it’s been written to Flash correctly.)

UPDATE:

This works!