Flash Programming with arm-elf-insight and openocd

Hi

I am using an LPC2148 and am trying to program the flash. I am using the Amontec JTAGKey as well. The following is my makefile, script file and config file…am i doing something wrong here? It connects to the device when i type in "openocd -f “FLASH lpc2xxx_jtagkey.cfg” but I can’t download the scriptfile as the source as i get the error:

“flash.c :499 handle_flash_write_command(): couldn’t stat() main.bin : No such file or diectory”


makefile


##############################################################################################

Start of default section

Create ROM-image (final)

RUN_MODE=ROM_RUN

Create RAM-Image (debugging)

#RUN_MODE=RAM_RUN

TRGT = arm-elf-

CC = $(TRGT)gcc

CP = $(TRGT)objcopy

AS = $(TRGT)gcc -x assembler-with-cpp

BIN = $(CP) -O binary

MCU = arm7tdmi

SUBMDL = lpc2106

List all default C defines here, like -D_DEBUG=1

DDEFS =

List all default ASM defines here, like -D_DEBUG=1

DADEFS =

List all default directories to look for include files here

DINCDIR =

List the default directory to look for the libraries here

DLIBDIR =

List all default libraries here

DLIBS =

End of default section

##############################################################################################

##############################################################################################

Start of user section

Define project name here

PROJECT = lpc_uart

Define linker script file here

LDSCRIPT= lpc2106-RAM.ld

List all user C define here, like -D_DEBUG=1

UDEFS = -D$(RUN_MODE)

Define ASM defines here

UADEFS = -D$(RUN_MODE)

List C source files here

SRC = main.c uart.c

List ASM source files here

ASRC = crt0.S

List all user directories here

UINCDIR =

List the user directory to look for the libraries here

ULIBDIR =

List all user libraries here

ULIBS =

Define optimisation level here

OPT = -O0

End of user defines

##############################################################################################

INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))

LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))

DEFS = $(DDEFS) $(UDEFS)

ADEFS = $(DADEFS) $(UADEFS)

OBJS = $(ASRC:.S=.o) $(SRC:.c=.o)

LIBS = $(DLIBS) $(ULIBS)

MCFLAGS = -mcpu=$(MCU)

ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(<:.S=.lst) $(ADEFS)

CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)

LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,–cref,–no-warn-mismatch $(LIBDIR)

Generate dependency information

CPFLAGS += -MD -MP -MF .dep/$(@F).d

makefile rules

all: $(OBJS) $(PROJECT).elf $(PROJECT).bin

program: $(TARGET).bin

@echo

@echo “Programming with OPENOCD”

C:\Program Files\openocd-2006re88\openocd -f “FLASH lpc2xxx_jtagkey.cfg”

%o : %c

$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@

%o : %S

$(AS) -c $(ASFLAGS) $< -o $@

%elf: $(OBJS)

$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@

%bin: %elf

$(BIN) $< $@

clean:

-rm -f $(OBJS)

-rm -f $(PROJECT).elf

-rm -f $(PROJECT).map

-rm -f $(PROJECT).bin

-rm -f $(SRC:.c=.c.bak)

-rm -f $(SRC:.c=.lst)

-rm -f $(ASRC:.S=.S.bak)

-rm -f $(ASRC:.S=.lst)

-rm -f .dep/*

Include the dependency files, should be the last of the makefile

-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

*** EOF ***


lpc2148.script


target remote localhost:3333

monitor sleep 500

monitor poll

monitor flash probe 0

monitor flash erase 0 0 0

monitor flash write 0 main.bin 0x0

monitor reset run

monitor sleep 500

monitor shutdown


FLASH lpc2xxx_jtagkey.cfg


#daemon configuration

telnet_port 4444

gdb_port 3333

#interface

interface ft2232

ft2232_device_desc “Amontec JTAGkey A”

ft2232_layout jtagkey

ft2232_vid_pid 0x0403 0xcff8

jtag_speed 4

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

reset_config trst_and_srst trst_pulls_srst

#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

working_area 0 0x40000000 0x4000 nobackup

#flash configuration

flash bank lpc2000 0x0 0x7d000 0 0 lpc2000_v2 0 12000 calc_checksum

So there is no file: main.bin in your working directory.

Take a look in the working directory and se what .bin files you have.

The makefile generates from make all, $(PROJECT).bin with PROJECT=lpc_uart ,

that would be lpc_uart.bin .

With make program the file $(TARGET).bin is a dependency, TARGET is usually

passed from the calling IDE.

Finally the openocd script lpc2148.script tries to do a flash write of main.bin

There must be only one .bin to remove confusion.

Regards

Magnus

Hi!

Yeah…I have an lpc_uart.bin file in my directory but after connecting the board…i go to “file->source” in arm-elf-insight and it still doesnt recognise the lpc_uart.bin file! I’m confused…which parts of my makefile should create the .bin file?

Make Program doesn work either…i get the error:

process_begin: CreateProcess((null), echo, …) failed.

make (e=2): The system cannot find the file specified.

make: *** [program] Error 2

That means there is something wrong with:

program: $(TARGET).bin

@echo

@echo “Programming with OPENOCD”

C:\Program Files\openocd-2006re88\openocd.exe -f “FLASH lpc2xxx_jtagkey.cfg”

?

Your problem is that either you let your IDE setup everything for you, and hope it works.

Or you must control and basically understand everything that is going on.

Fun but it takes some time.

So you have a lpc_uart.bin file. This is created by running make all.

(since PROJECT is lpc_uart).

You can download this to your board by either

  • change main.bin to lpc_uart.bin in the lpc2148.script

OR

  • rename lpc_uart.bin to main.bin

It is just a binary file of machinecode so its name has no effect after downloading.

When you try “make program” the variable TARGET must have a value, if the value is

main then I think the makefile will create main.elf and main.bin.

If you run make from the command line you must give target a value .

Under Linux, that I use, it is done with something like:

export TARGET=main

make program

In short your problem is the confusion between different tools, some of them

expect your program to be called main.elf, main.bin

Some think that the reasonable names are lpc_uart.elf lpc_uart.bin

Regards

Magnus

Hi Magnus!

ok…i just realised i forgot to add 1 line to my FLASH lpc2xxx_jtagkey.cfg file…so now some of it looks like this:

#target

#target arm7tdmi

target arm7tdmi little run_and_init 0 arm7tdmi-s_r4

target_script 0 reset lpc2148.script

run_and_halt_time 0 30

working_area 0 0x40000000 0x40000 nobackup


so in my command prompt i write:

openocd -f “FLASH lpc2xxx_jtagkey.cfg”

i response i get:

Info: openocd.c:82 main(): Open On-Chip Debugger (2006-08-17 17:00 CEST)

Info: target.c:219 target_init_handler(): executing reset script ‘lpc2148.script’

so this means openocd is working?

now in another command prompt i type in:

arm-elf-insight

(which opens it up…)

i click on RUN - it says connected

then i look for the source file …is it a gdb file? this is that i was using b 4…target remote localhost:3333

monitor reset

monitor sleep 500

monitor poll

monitor soft_reset_halt

monitor arm7_9 sw_bkpts enable

monitor mww 0xE01FC040 0x0002

monitor mdw 0xE01FC040

is this wrong?

oh yeah…also i left it as lpc_uart.bin!

ok update:

If you look at my makefile at the top…i have made TRGT to be arm-elf-

so i got arm-elf-.bin…and by making this the source i got this file to download to flash! yay!

except now for some reason i can’t debug my program when i RUN with lpc_uart.elf?

sorry…i mean the source file in arm-elf-insight was my script file

Your TARGET setting generates two files when you do “make program”

TARGET.elf and TARGET.bin

First the make program checks for the TARGET.bin file

program: $(TARGET).bin
@echo

This file is generated from the corresponding elf file in

%bin: %elf
$(BIN) $< $@

The bin file is generated from the compiled oject code by

%elf: $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@

So if TARGET is arm-elf- then you must write arm-elf-.bin to flash

and use arm-elf-.elf when debugging.

I suggest you change TARGET to lpc_uart to remove some of the confusion.

This is a better name for your program than arm-elf-

[Do make clean to remove old teporary files.]

Do make program.

Check in your working directory what .elf and .bin file you have and the timestap on then

Regards

Magnus

Thanks Magnus!

Starting to make some sense now…what about my .ld file…should I change it to lpc2106-ROM.ld? or do i have to make a new FLASH one?

I’m also getting this error when I do ‘make’

make: *** No rule to make target lpc_uart.elf', needed by all’. Stop.

Here is a paste of what i’m talking about: this is my Makefile:

TARGET = lpc_uart

Define project name here

PROJECT = lpc_uart

Define linker script file here

LDSCRIPT= lpc2106-ROM.ld

List all user C define here, like -D_DEBUG=1

UDEFS = -D$(RUN_MODE)

Define ASM defines here

UADEFS = -D$(RUN_MODE)

List C source files here

SRC = main.c uart.c

List ASM source files here

ASRC = crt0.S

List all user directories here

UINCDIR =

List the user directory to look for the libraries here

ULIBDIR =

List all user libraries here

ULIBS =

Define optimisation level here

OPT = -O0

End of user defines

##############################################################################################

INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))

LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))

DEFS = $(DDEFS) $(UDEFS)

ADEFS = $(DADEFS) $(UADEFS)

OBJS = $(ASRC:.S=.o) $(SRC:.c=.o)

LIBS = $(DLIBS) $(ULIBS)

MCFLAGS = -mcpu=$(MCU)

ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(<:.S=.lst) $(ADEFS)

CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)

LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,–cref,–no-warn-mismatch $(LIBDIR)

Generate dependency information

CPFLAGS += -MD -MP -MF .dep/$(@F).d

makefile rules

all: $(OBJS) $(TARGET).elf $(TARGET).hex

program: $(TARGET).bin

@echo

%o : %c

$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@

%o : %S

$(AS) -c $(ASFLAGS) $< -o $@

%bin: %elf

$(BIN) $< $@

%elf: $(OBJS)

$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@

clean:

-rm -f $(OBJS)

-rm -f $(TARGET).elf

-rm -f $(TARGET).map

-rm -f $(TARGET).hex

-rm -f $(SRC:.c=.c.bak)

-rm -f $(SRC:.c=.lst)

-rm -f $(ASRC:.S=.S.bak)

-rm -f $(ASRC:.S=.lst)

-rm -f .dep/*

Include the dependency files, should be the last of the makefile

-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

*** EOF ***

ok i added:

%hex: %elf

$(BIN) $< $@

and it compiled:) but now i am getting this message in arm-elf-insight: no idea what it means!

0x7fffd2c0 in ?? ()

target state: running

requesting target halt and executing a soft reset

Command target not found

Command monitor not found

Command monitor not found

Command monitor not found

Command monitor not found

Command monitor not found

Command monitor not found

Command monitor not found

Command monitor not found

software breakpoints enabled

error: access caused data abort, system possibly corrupted

0xe01fc040: 00000000

flash ‘lpc2000’ found at 0x00000000

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

_boot () at crt0.S:40

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

Current language: auto; currently asm

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

When you do “make program”, the make program regards TARGET.elf as an intermediate file and removes it after creating the TARGET.bin, if it did not exist before…

This is becuase only TARGET.bin is listed as a prerequisite on the line

program: $(TARGET).bin
@echo

So either you do first “make all”, note that the TARGET.elf is listed in

all: $(OBJS) $(TARGET).elf $(TARGET).hex 

and then run “make program”. This should give you both files :slight_smile:

OR change the line for program to:

program:  $(TARGET).elf  $(TARGET).bin
@echo

Regards

Magnus

Hi Magnus!

Yep I did that and when i type in ‘make program’ it says:

arm-elf-objcopy -O ihex lpc_uart.elf lpc_uart.bin

process_begin: CreateProcess((null), echo,…) failed

make (e=2): The system cannot find the file specified

make: *** [program] Error 2

Looks like arm-elf-objcopy works but the @echo command does not.

Does it produce the lpc_uart.bin file ?

Try removing the lines containg @echo.

What kind of a system os setup are you using ?

Regards

Magnus

kool…!

yep it does produce an lpc_uart.bin file which is excellent

and it also does the make program after i removed the @echo bit out!

i’m using this whole thing on XP and using openocd and arm-elf-insight on top of that!

so now when i load the gdb which is this:

target remote localhost:3333

monitor reset

monitor sleep 500

monitor poll

monitor soft_reset_halt

monitor arm7_9 sw_bkpts enable

monitor mww 0xE01FC040 0x0002

monitor mdw 0xE01FC040

monitor flash probe 0

monitor flash erase 0 0 0

monitor flash write 0 lpc_uart.bin 0x0

i get:

0xe01fc040: 00000000

flash ‘lpc2000’ found at 0x00000000

wrote file lpc_uart.bin to flash bank 0 at offset 0x00000000 in 0s 796809us

(Internal error: pc 0x0 in read in psymtab, but not in symtab.) x 5 lines

_boot () at crt0.S:40

(Internal error: pc 0x0 in read in psymtab, but not in symtab.)

Current language: auto; currently asm

(Internal error: pc 0x0 in read in psymtab, but not in symtab.) x8 lines

Does the above error mean it actually loaded it into flash but i can’t debug for some reason?

Yes it seems the flash writing is working ok.

echo is a unix command, probably missing in XP.

The debug error is because the debugger does not

find a symbol corresponding to the resetvector adress 0x0.

This is a gdb problem and happens often if the processor is halted before

the main C code starts in main().

I dont use Insight but probably someone else has the magic command to add to the

OpenOcd script to start up things correctly.

Regards magnus