OpenOCD [svn 724] and dual targets fails

I’ve got a board with 2 Stellaris, and openocd locks up if I try it with both targets activated.

It works fine if only one ‘target’ is active, as soon as I activate two 'target; lines it loops, eating 100% CPU and needs a control-c

Here is the config file.

#interface
interface ft2232
ft2232_device_desc "Amontec JTAGkey"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0xcff8
jtag_nsrst_delay 100
jtag_ntrst_delay 100
jtag_speed 6

reset_config srst_only

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

# the luminary variant causes a software reset rather than asserting SRST
# this stops the debug registers from being cleared
# this will be fixed in later revisions of silicon
#target cortex_m3 little reset_halt 0 lm3s
target cortex_m3 little reset_halt 1 lm3s

# 4k working area at base of ram
#working_area 0 0x20000000 0x4000 nobackup
working_area 1 0x20000000 0x4000 nobackup

#flash configuration
#flash bank stellaris 0 0 0 0 0
flash bank stellaris 1 0 0 0 0

Could you provide a full log?

I have just done a quick test with a stm32 and str73 on the same chain - that works ok.

just for testing change the reset type to run_and_halt.

Cheers

Spen

Actually I found the problem; the ->target field of the target structure get sets to a struct of function pointer that is /supposed/ to be read-only, but is changed by another piece of code to implement the _imp paradigm. So when you have another target /of the same type/ on the chain the _imp paradigm thing replaces it’s own function pointer to call… itself.

I change it so it mallocs+copy the function pointer block instead of using the global one, so the _imp thing doesn’t go and clobber the globals.

I can provide a patch tomorrow; I’m not at the workstation today.

Here’s the patch, from my git copy, from my up to date git-svn tree.

From a941dc969ceaa8dc37e5e54e8f5cf9be9efabdff Mon Sep 17 00:00:00 2001
From: Michel <michel.pollet@peavey-eu.com>
Date: Tue, 1 Jul 2008 11:28:37 +0100
Subject: [PATCH] Fix a problem related to having two targets of the same type

---
 trunk/src/target/target.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/trunk/src/target/target.c b/trunk/src/target/target.c
index 1be4885..62ab485 100644
--- a/trunk/src/target/target.c
+++ b/trunk/src/target/target.c
@@ -1402,9 +1402,11 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
 				}
 
 				*last_target_p = malloc(sizeof(target_t));
-				
-				(*last_target_p)->type = target_types[i];
-				
+
+				// copy the global struct in a local copy, as these pointers can be changed
+				(*last_target_p)->type = (target_type_t *)malloc(sizeof(target_type_t));
+				*((*last_target_p)->type) = *target_types[i];
+
 				if (strcmp(args[1], "big") == 0)
 					(*last_target_p)->endianness = TARGET_BIG_ENDIAN;
 				else if (strcmp(args[1], "little") == 0)
-- 
1.5.5.1.357.g1af8b

committed, many thanks.

If you have any more patches etc, then it would be easier to use the dev mailing list.

https://lists.berlios.de/mailman/listin … evelopment

Cheers

Spen