EmbeddedRelated.com
Forums

Programming FLASH via JTAG - OpenOCD

Started by Gaspar Pollano January 30, 2008
Hi everybody!

Im trying to load my code into the FLASH memory of an LPC2148 via
JTAG using OpenOCD.
Im using Yagarto (Eclipse + OpenOCD) to do the work.

There is any way to configure the OpenOCD to erase *only* the sectors
of FLASH that would be filled with the code?

Doing some research I found the command "flash auto_erase" on th
OpenOCD pdf, but dont seems to work for me...

Actually I use this script to load the FLASH:

____________file____________________
# Sript to Load the FLASH
#daemon configuration
telnet_port 4444
gdb_port 3333

#interface
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG A"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 3

#use combined on interfaces or targets that can't set TRST/SRST
separately
reset_config trst_and_srst srst_pulls_trst

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask,
IDCODE)
jtag_device 4 0x1 0xf 0xe

#target configuration
daemon_startup reset

#target
#target arm7tdmi
target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
run_and_halt_time 0 30
# flash programming
#----------------------

#flash auto_erase on
#commented out because doesnt work

target_script 0 reset scripts\flash_prog.ocd

working_area 0 0x40000000 0x4000 nobackup

#flash configuration
#flash bank lpc2000 0 0
flash bank lpc2000 0x0 0x7D000 0 0 0 lpc2000_v2 12000 calc_checksum
__________end of file__________________
As you can see, the script call to flash_prog.ocd which code is:

____file_______
sleep 500
poll
flash probe 0
flash erase 0 0 9
flash write_image output.bin 0x0 bin
resume 0x00
sleep 500
shutdown
___end of file______

Note the line "flash erase 0 0 9". This line will be deleted if
"flash auto_erase" work, because OpenOCD will erase only the
necessary sectors. Otherwise, i must check if my code fits on 9
sectors, or erase all the sectors just in case...

For the FLASH programming via JTAG Im using the OLIMEX USB OCD.

Thanks in advance!

Gaspar from Argentina.

An Engineer's Guide to the LPC2100 Series

Dear Sir,

I am Rajesh Mahapatra, a new member to your group. I am working in a company which has projects on ARM7. I have completed an Embedded system course and new to this field. This is for the first time I am working with 32-bit microcontrollers but earlier worked on 8-bit microcontroller.
Please guide me how to start programing in ARM 32-bit microcontroller. I have some fundamental knowledge regarding 32 bit. Also I want to know that we write programs in user mode then is it necessary for us to go to supervisory, undef ,etc modes. OR the controller goes it by own.

please guide me how to start with 32-bit.

Thanks and with regards,
Rajesh Mahapatra
Gaspar Pollano wrote:
Hi everybody!

Im trying to load my code into the FLASH memory of an LPC2148 via
JTAG using OpenOCD.
Im using Yagarto (Eclipse + OpenOCD) to do the work.

There is any way to configure the OpenOCD to erase *only* the sectors
of FLASH that would be filled with the code?

Doing some research I found the command "flash auto_erase" on th
OpenOCD pdf, but dont seems to work for me...

Actually I use this script to load the FLASH:

____________file____________________
# Sript to Load the FLASH
#daemon configuration
telnet_port 4444
gdb_port 3333

#interface
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG A"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 3

#use combined on interfaces or targets that can't set TRST/SRST
separately
reset_config trst_and_srst srst_pulls_trst

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask,
IDCODE)
jtag_device 4 0x1 0xf 0xe

#target configuration
daemon_startup reset

#target
#target arm7tdmi
target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
run_and_halt_time 0 30

# flash programming
#----------------------

#flash auto_erase on
#commented out because doesnt work

target_script 0 reset scripts\flash_prog.ocd

working_area 0 0x40000000 0x4000 nobackup

#flash configuration
#flash bank lpc2000 0 0
flash bank lpc2000 0x0 0x7D000 0 0 0 lpc2000_v2 12000 calc_checksum
__________end of file__________________

As you can see, the script call to flash_prog.ocd which code is:

____file_______
sleep 500
poll
flash probe 0
flash erase 0 0 9
flash write_image output.bin 0x0 bin
resume 0x00
sleep 500
shutdown
___end of file______

Note the line "flash erase 0 0 9". This line will be deleted if
"flash auto_erase" work, because OpenOCD will erase only the
necessary sectors. Otherwise, i must check if my code fits on 9
sectors, or erase all the sectors just in case...

For the FLASH programming via JTAG Im using the OLIMEX USB OCD.

Thanks in advance!

Gaspar from Argentina.

---------------------------------
Save all your chat conversations. Find them online.
--- In l..., rajesh mahapatra wrote:
>
> Dear Sir,
>
> I am Rajesh Mahapatra, a new member to your group. I
>am working in a company which has projects on ARM7. I have completed
>an Embedded system course and new to this field. This is for the >first
>time I am working with 32-bit microcontrollers but earlier worked on
>8-bit microcontroller.
> Please guide me how to start programing in ARM 32-bit
>microcontroller. I have some fundamental knowledge regarding 32 bit.

Jim Lynch's tutorial is a good place to start. This link is for Atmel
ARM7 devices, but much of it is applicable to NXP also.

http://www.atmel.com/dyn/resources/prod_documents/atmel_tutorial_source.zip

>Also I want to know that we write programs in user mode then is it
>necessary for us to go to supervisory, undef ,etc modes. OR the
>controller goes it by own.
>

Only the exception vector mode switching is automatic. An automatic
switch from user mode to supervisory mode would defeat the purpose of
having user mode restrictions. For many embedded applications, where
the entire application comes from one developer, the restrictions in
user mode are usually not necessary, so ARM can be left in supervisory
mode after startup.

--Dave
Hi everybody!

(I rewrote my post, since the replies are no focused on the topic
treated, Rajesh Mahapatra: Jim Lynch also has a manual to start with
LPC ARM's, is a good place to start like Dave say. I also suggest you
use ALDS for start wich are good coded and better comented drivers,
look at http://bas.woodpecker.gotdns.org/ALDS.php)

Now, Back on topic...

Im trying to load my code into the FLASH memory of an LPC2148 via
JTAG using OpenOCD.
Im using Yagarto (Eclipse + OpenOCD) to do the work.

There is any way to configure the OpenOCD to erase *only* the sectors
of FLASH that would be filled with the code?

Doing some research I found the command "flash auto_erase" on th
OpenOCD pdf, but dont seems to work for me...

Actually I use this script to load the FLASH:

____________file____________________
# Sript to Load the FLASH
#daemon configuration
telnet_port 4444
gdb_port 3333

#interface
interface ft2232
ft2232_device_desc "Olimex OpenOCD JTAG A"
ft2232_layout "olimex-jtag"
ft2232_vid_pid 0x15BA 0x0003
jtag_speed 3

#use combined on interfaces or targets that can't set TRST/SRST
separately
reset_config trst_and_srst srst_pulls_trst

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask,
IDCODE)
jtag_device 4 0x1 0xf 0xe

#target configuration
daemon_startup reset

#target
#target arm7tdmi
target arm7tdmi little run_and_init 0 arm7tdmi-s_r4
run_and_halt_time 0 30

# flash programming
#----------------------

#flash auto_erase on
#commented out because doesnt work

target_script 0 reset scripts\flash_prog.ocd

working_area 0 0x40000000 0x4000 nobackup

#flash configuration
#flash bank lpc2000 0 0
flash bank lpc2000 0x0 0x7D000 0 0 0 lpc2000_v2 12000 calc_checksum
__________end of file__________________

As you can see, the script call to flash_prog.ocd which code is:

____file_______
sleep 500
poll
flash probe 0
flash erase 0 0 9
flash write_image output.bin 0x0 bin
resume 0x00
sleep 500
shutdown
___end of file______

Note the line "flash erase 0 0 9". This line will be deleted if
"flash auto_erase" work, because OpenOCD will erase only the
necessary sectors. Otherwise, i must check if my code fits on 9
sectors, or erase all the sectors just in case...

For the FLASH programming via JTAG Im using the OLIMEX USB OCD.

Thanks in advance!

Gaspar from Argentina.
> As you can see, the script call to flash_prog.ocd which code is:
>
> ____file_______
> sleep 500
> poll
> flash probe 0
> flash erase 0 0 9
> flash write_image output.bin 0x0 bin
> resume 0x00
> sleep 500
> shutdown
> ___end of file______
>

I have no idea how to get OpenOCD to do what you want.

But I'll bet I could add a little tweak to the Makefile to use
arm-elf-size to get the .text and .data sizes and then use some other
utility (awk or perl or some c code) to dynamically create
flash_prog.ocd.

Richard
Hello Gasper!

UrJTAG is a "current" branch of the OpenOCD JTAG tools. As OpenOCD
have not been deveoped for some time, hackers decided to take over
this project. So UrJTAG is a work in progress, but will bring internel
redesign, a lot of features, new cables support, etc. Then it will
again become OpenOCD back probably.

Here is the project page:
http://urjtag.sourceforge.net/

Have look at mailing list They will surely know how to answer Your question :)

Greetings! :)
Tomek

--
CeDeROM, http://www.tomek.cedro.info
Hi,

MIght be wrong here, but it seems to me UrJTAG in a reincarnation of
openwince, and has nothing to do with openOCD. It's more aimed at FPGA and
CPLD jtagging, and seems to lack lpc2000 support..

On Friday 01 February 2008 09:58:22 CeDeROM wrote:
> Hello Gasper!
>
> UrJTAG is a "current" branch of the OpenOCD JTAG tools. As OpenOCD
> have not been deveoped for some time, hackers decided to take over
> this project. So UrJTAG is a work in progress, but will bring internel
> redesign, a lot of features, new cables support, etc. Then it will
> again become OpenOCD back probably.
>
> Here is the project page:
> http://urjtag.sourceforge.net/
>
> Have look at mailing list They will surely know how to answer Your question
> :)
>
> Greetings! :)
> Tomek
That is correct, my error! Too many data processing, crc is failing.
Although this will be great tool for firmware dump/upload from any
jtag enabled device, I hope :)
Greetings!
Tomek
--
CeDeROM, http://www.tomek.cedro.info
> MIght be wrong here, but it seems to me UrJTAG in a reincarnation of
> openwince, and has nothing to do with openOCD.

That's right. UrJTAG is a descendant of the openwince JTAG tools, and
only related thematically to OpenOCD.

UrJTAG doesn't contain any ARM debug support yet. However, as OpenOCD,
it contains code to communicate with chips over JTAG using various
cables, from parport-cables over FT2232 up to proprietary cables like
Altera USB-Blaster, Segger J-Link, or Xilinx Platform Cable USB.

And it contains code to program attached flash chips if it has a bus
driver for the target CPU. Currently, there are bus drivers that
inject code to the target using EJTAG (for MIPS CPUs), but most of
them use boundary scan.

NXP LPC* chips unfortunately don't allow boundary scan. JTAG can be
used for access to the ARM debug core only. Maybe sometime in future a
bus driver similar to the EJTAG one (injecting code to access
registers and memory) will be integrated in UrJTAG for arbitrary
ARM7/9/CortexM1/M3/... CPUs.

Regards,
Kolja