David Brownell <david-b@pacbell.net> start phasing out integers as target IDs

git-svn-id: svn://svn.berlios.de/openocd/trunk@2650 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
oharboe 2009-08-30 17:30:14 +00:00
parent 4b9bdd664a
commit d879faa3cb
7 changed files with 62 additions and 61 deletions

View File

@ -2365,6 +2365,10 @@ are examples; and there are many more.
Several commands let you examine the list of targets: Several commands let you examine the list of targets:
@deffn Command {target count} @deffn Command {target count}
@emph{Note: target numbers are deprecated; don't use them.
They will be removed shortly after August 2010, including this command.
Iterate target using @command{target names}, not by counting.}
Returns the number of targets, @math{N}. Returns the number of targets, @math{N}.
The highest numbered target is @math{N - 1}. The highest numbered target is @math{N - 1}.
@example @example
@ -2390,6 +2394,9 @@ foreach t [target names] @{
@end deffn @end deffn
@deffn Command {target number} number @deffn Command {target number} number
@emph{Note: target numbers are deprecated; don't use them.
They will be removed shortly after August 2010, including this command.}
The list of targets is numbered starting at zero. The list of targets is numbered starting at zero.
This command returns the name of the target at index @var{number}. This command returns the name of the target at index @var{number}.
@example @example
@ -2711,8 +2718,7 @@ For example, if you wanted to summarize information about
all the targets you might use something like this: all the targets you might use something like this:
@example @example
for @{ set x 0 @} @{ $x < [target count] @} @{ incr x @} @{ foreach name [target names] @{
set name [target number $x]
set y [$name cget -endian] set y [$name cget -endian]
set z [$name cget -type] set z [$name cget -type]
puts [format "Chip %d is %s, Endian: %s, type: %s" \ puts [format "Chip %d is %s, Endian: %s, type: %s" \

View File

@ -20,20 +20,30 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/ ****************************************************************************/
/*************************************************************************************************************************************************************************************** /***************************************************************************
* *
* New flash setup command: * New flash setup command:
* *
* flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_number> [<target_name> <banks> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>] * flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_id>
* [<chip_type> <banks>
* <sectors_per_bank> <pages_per_sector>
* <page_size> <num_nvmbits>
* <ext_freq_khz>]
* *
* <ext_freq_khz> - MUST be used if clock is from external source, * <ext_freq_khz> - MUST be used if clock is from external source,
* CAN be used if main oscillator frequency is known (recomended) * CAN be used if main oscillator frequency is known (recommended)
* Examples: * Examples:
* flash bank at91sam7 0x00100000 0 0 4 0 0 AT91SAM7XC256 1 16 64 256 3 25000 ==== RECOMENDED ============ * ==== RECOMMENDED (covers clock speed) ============
* flash bank at91sam7 0 0 0 0 0 0 0 0 0 0 0 0 25000 (auto-detection, except for clock) ==== RECOMENDED ============ * flash bank at91sam7 0x00100000 0 0 4 $_TARGETNAME AT91SAM7XC256 1 16 64 256 3 25000
* flash bank at91sam7 0x00100000 0 0 4 0 0 AT91SAM7XC256 1 16 64 256 3 0 ==== NOT RECOMENDED !!! ==== * (if auto-detect fails; provides clock spec)
* flash bank at91sam7 0 0 0 0 0 (old style, full auto-detection) ==== NOT RECOMENDED !!! ==== * flash bank at91sam7 0 0 0 0 $_TARGETNAME 0 0 0 0 0 0 25000
****************************************************************************************************************************************************************************************/ * (auto-detect everything except the clock)
* ==== NOT RECOMMENDED !!! (clock speed is not configured) ====
* flash bank at91sam7 0x00100000 0 0 4 $_TARGETNAME AT91SAM7XC256 1 16 64 256 3 0
* (if auto-detect fails)
* flash bank at91sam7 0 0 0 0 $_TARGETNAME
* (old style, auto-detect everything)
****************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -734,16 +744,6 @@ static int at91sam7_protect_check(struct flash_bank_s *bank)
return ERROR_OK; return ERROR_OK;
} }
/***************************************************************************************************************************************************************************************
# flash bank <driver> <base_addr> <size> <chip_width> <bus_width> <target_number> [<target_name> <banks> <sectors_per_bank> <pages_per_sector> <page_size> <num_nvmbits> <ext_freq_khz>]
# <ext_freq_khz> - MUST be used if clock is from external source
# CAN be used if main oscillator frequency is known
# Examples:
# flash bank at91sam7 0x00100000 0 0 4 0 0 AT91SAM7XC256 1 16 64 256 3 25000 ==== RECOMENDED ============
# flash bank at91sam7 0 0 0 0 0 0 0 0 0 0 0 0 25000 (auto-detection, except for clock) ==== RECOMENDED ============
# flash bank at91sam7 0x00100000 0 0 4 0 0 AT91SAM7XC256 1 16 64 256 3 0 ==== NOT RECOMENDED !!! ====
# flash bank at91sam7 0 0 0 0 0 (old style, full auto-detection) ==== NOT RECOMENDED !!! ====
****************************************************************************************************************************************************************************************/
static int at91sam7_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) static int at91sam7_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
{ {
flash_bank_t *t_bank = bank; flash_bank_t *t_bank = bank;

View File

@ -198,7 +198,7 @@ int orion_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
uint8_t ale, cle; uint8_t ale, cle;
if (argc != 3) { if (argc != 3) {
LOG_ERROR("arguments must be: <target_number> <NAND_address>\n"); LOG_ERROR("arguments must be: <target_id> <NAND_address>\n");
return ERROR_NAND_DEVICE_INVALID; return ERROR_NAND_DEVICE_INVALID;
} }

View File

@ -128,7 +128,7 @@ add_help_text script "<filename> - filename of OpenOCD script (tcl) to run"
# Handle GDB 'R' packet. Can be overriden by configuration script, # Handle GDB 'R' packet. Can be overriden by configuration script,
# but it's not something one would expect target scripts to do # but it's not something one would expect target scripts to do
# normally # normally
proc ocd_gdb_restart {target_num} { proc ocd_gdb_restart {target_id} {
# Fix!!! we're resetting all targets here! Really we should reset only # Fix!!! we're resetting all targets here! Really we should reset only
# one target # one target
reset halt reset halt

View File

@ -2156,7 +2156,9 @@ int gdb_input_inner(connection_t *connection)
/* handle extended restart packet */ /* handle extended restart packet */
breakpoint_clear_target(gdb_service->target); breakpoint_clear_target(gdb_service->target);
watchpoint_clear_target(gdb_service->target); watchpoint_clear_target(gdb_service->target);
command_run_linef(connection->cmd_ctx, "ocd_gdb_restart %d", get_num_by_target(target)); command_run_linef(connection->cmd_ctx,
"ocd_gdb_restart %s",
target->cmd_name);
break; break;
default: default:
/* ignore unkown packets */ /* ignore unkown packets */
@ -2230,17 +2232,23 @@ int gdb_init(void)
} }
else else
{ {
unsigned short port = gdb_port;
while (target) while (target)
{ {
gdb_service = malloc(sizeof(gdb_service_t)); gdb_service = malloc(sizeof(gdb_service_t));
gdb_service->target = target; gdb_service->target = target;
add_service("gdb", CONNECTION_TCP, gdb_port + target->target_number, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service); add_service("gdb", CONNECTION_TCP,
port, 1,
gdb_new_connection, gdb_input,
gdb_connection_closed, gdb_service);
LOG_DEBUG("gdb service for target %s at port %i", LOG_DEBUG("gdb service for target %s at TCP port %i",
target_get_name(target), target_get_name(target),
gdb_port + target->target_number); port);
target = target->next; target = target->next;
port++;
} }
} }

View File

@ -249,22 +249,6 @@ target_state_name( target_t *t )
return cp; return cp;
} }
static int max_target_number(void)
{
target_t *t;
int x;
x = -1;
t = all_targets;
while (t) {
if (x < t->target_number) {
x = (t->target_number) + 1;
}
t = t->next;
}
return x;
}
/* determine the number of the new target */ /* determine the number of the new target */
static int new_target_number(void) static int new_target_number(void)
{ {
@ -346,14 +330,19 @@ target_t *get_target(const char *id)
return target; return target;
} }
/* It's OK to remove this fallback sometime after August 2010 or so */
/* no match, try as number */ /* no match, try as number */
unsigned num; unsigned num;
if (parse_uint(id, &num) != ERROR_OK) if (parse_uint(id, &num) != ERROR_OK)
return NULL; return NULL;
for (target = all_targets; target; target = target->next) { for (target = all_targets; target; target = target->next) {
if (target->target_number == (int)num) if (target->target_number == (int)num) {
LOG_WARNING("use '%s' as target identifier, not '%u'",
target->cmd_name, num);
return target; return target;
}
} }
return NULL; return NULL;
@ -374,11 +363,6 @@ static target_t *get_target_by_num(int num)
return NULL; return NULL;
} }
int get_num_by_target(target_t *query_target)
{
return query_target->target_number;
}
target_t* get_current_target(command_context_t *cmd_ctx) target_t* get_current_target(command_context_t *cmd_ctx)
{ {
target_t *target = get_target_by_num(cmd_ctx->current_target); target_t *target = get_target_by_num(cmd_ctx->current_target);
@ -4387,6 +4371,8 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return target_create(&goi); return target_create(&goi);
break; break;
case TG_CMD_NUMBER: case TG_CMD_NUMBER:
/* It's OK to remove this mechanism sometime after August 2010 or so */
LOG_WARNING("don't use numbers as target identifiers; use names");
if (goi.argc != 1) { if (goi.argc != 1) {
Jim_SetResult_sprintf(goi.interp, "expected: target number ?NUMBER?"); Jim_SetResult_sprintf(goi.interp, "expected: target number ?NUMBER?");
return JIM_ERR; return JIM_ERR;
@ -4395,23 +4381,25 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (e != JIM_OK) { if (e != JIM_OK) {
return JIM_ERR; return JIM_ERR;
} }
{ for (x = 0, target = all_targets; target; target = target->next, x++) {
target_t *t; if (target->target_number == w)
t = get_target_by_num(w); break;
if (t == NULL) {
Jim_SetResult_sprintf(goi.interp,"Target: number %d does not exist", (int)(w));
return JIM_ERR;
}
Jim_SetResultString(goi.interp, t->cmd_name, -1);
return JIM_OK;
} }
if (target == NULL) {
Jim_SetResult_sprintf(goi.interp,
"Target: number %d does not exist", (int)(w));
return JIM_ERR;
}
Jim_SetResultString(goi.interp, target->cmd_name, -1);
return JIM_OK;
case TG_CMD_COUNT: case TG_CMD_COUNT:
if (goi.argc != 0) { if (goi.argc != 0) {
Jim_WrongNumArgs(goi.interp, 0, goi.argv, "<no parameters>"); Jim_WrongNumArgs(goi.interp, 0, goi.argv, "<no parameters>");
return JIM_ERR; return JIM_ERR;
} }
Jim_SetResult(goi.interp, for (x = 0, target = all_targets; target; target = target->next, x++)
Jim_NewIntObj(goi.interp, max_target_number())); continue;
Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, x));
return JIM_OK; return JIM_OK;
} }

View File

@ -120,7 +120,7 @@ typedef struct target_s
{ {
target_type_t *type; /* target type definition (name, access functions) */ target_type_t *type; /* target type definition (name, access functions) */
const char *cmd_name; /* tcl Name of target */ const char *cmd_name; /* tcl Name of target */
int target_number; /* generaly, target index but may not be in order */ int target_number; /* DO NOT USE! field to be removed in 2010 */
jtag_tap_t *tap; /* where on the jtag chain is this */ jtag_tap_t *tap; /* where on the jtag chain is this */
const char *variant; /* what varient of this chip is it? */ const char *variant; /* what varient of this chip is it? */
target_event_action_t *event_action; target_event_action_t *event_action;
@ -250,7 +250,6 @@ extern int target_call_timer_callbacks(void);
extern int target_call_timer_callbacks_now(void); extern int target_call_timer_callbacks_now(void);
extern target_t* get_current_target(struct command_context_s *cmd_ctx); extern target_t* get_current_target(struct command_context_s *cmd_ctx);
extern int get_num_by_target(target_t *query_target);
extern target_t *get_target(const char *id); extern target_t *get_target(const char *id);
/** /**