From: oharboe Date: Sun, 30 Aug 2009 17:30:14 +0000 (+0000) Subject: David Brownell start phasing out integers as target IDs X-Git-Tag: v0.3.0-rc0~301 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=d879faa3cb8200c1c31e1a52c42e9bbacb9fac40 David Brownell start phasing out integers as target IDs git-svn-id: svn://svn.berlios.de/openocd/trunk@2650 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- diff --git a/doc/openocd.texi b/doc/openocd.texi index 14dec6d215..8b679705f9 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2365,6 +2365,10 @@ are examples; and there are many more. Several commands let you examine the list of targets: @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}. The highest numbered target is @math{N - 1}. @example @@ -2390,6 +2394,9 @@ foreach t [target names] @{ @end deffn @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. This command returns the name of the target at index @var{number}. @example @@ -2711,8 +2718,7 @@ For example, if you wanted to summarize information about all the targets you might use something like this: @example -for @{ set x 0 @} @{ $x < [target count] @} @{ incr x @} @{ - set name [target number $x] +foreach name [target names] @{ set y [$name cget -endian] set z [$name cget -type] puts [format "Chip %d is %s, Endian: %s, type: %s" \ diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index 04790617fa..315a3f3ffd 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -20,20 +20,30 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ****************************************************************************/ -/*************************************************************************************************************************************************************************************** +/*************************************************************************** * * New flash setup command: * -* flash bank [ ] +* flash bank +* [ +* +* +* ] * * - 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: -* 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 !!! ==== -****************************************************************************************************************************************************************************************/ +* ==== RECOMMENDED (covers clock speed) ============ +* flash bank at91sam7 0x00100000 0 0 4 $_TARGETNAME AT91SAM7XC256 1 16 64 256 3 25000 +* (if auto-detect fails; provides clock spec) +* 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 #include "config.h" @@ -734,16 +744,6 @@ static int at91sam7_protect_check(struct flash_bank_s *bank) return ERROR_OK; } -/*************************************************************************************************************************************************************************************** -# flash bank [ ] -# - 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) { flash_bank_t *t_bank = bank; diff --git a/src/flash/orion_nand.c b/src/flash/orion_nand.c index 6b50f1fb9a..dc9d78c537 100644 --- a/src/flash/orion_nand.c +++ b/src/flash/orion_nand.c @@ -198,7 +198,7 @@ int orion_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, uint8_t ale, cle; if (argc != 3) { - LOG_ERROR("arguments must be: \n"); + LOG_ERROR("arguments must be: \n"); return ERROR_NAND_DEVICE_INVALID; } diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 14b209205a..b85f47682c 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -128,7 +128,7 @@ add_help_text script " - filename of OpenOCD script (tcl) to run" # Handle GDB 'R' packet. Can be overriden by configuration script, # but it's not something one would expect target scripts to do # 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 # one target reset halt diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 48144f2665..948e44bae9 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2156,7 +2156,9 @@ int gdb_input_inner(connection_t *connection) /* handle extended restart packet */ breakpoint_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; default: /* ignore unkown packets */ @@ -2230,17 +2232,23 @@ int gdb_init(void) } else { + unsigned short port = gdb_port; + while (target) { gdb_service = malloc(sizeof(gdb_service_t)); 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), - gdb_port + target->target_number); + port); target = target->next; + port++; } } diff --git a/src/target/target.c b/src/target/target.c index 381e774e88..b6ea655516 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -249,22 +249,6 @@ target_state_name( target_t *t ) 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 */ static int new_target_number(void) { @@ -346,14 +330,19 @@ target_t *get_target(const char *id) return target; } + /* It's OK to remove this fallback sometime after August 2010 or so */ + /* no match, try as number */ unsigned num; if (parse_uint(id, &num) != ERROR_OK) return NULL; 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 NULL; @@ -374,11 +363,6 @@ static target_t *get_target_by_num(int num) 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 *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); break; 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) { Jim_SetResult_sprintf(goi.interp, "expected: target number ?NUMBER?"); return JIM_ERR; @@ -4395,23 +4381,25 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (e != JIM_OK) { return JIM_ERR; } - { - target_t *t; - t = get_target_by_num(w); - 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; + for (x = 0, target = all_targets; target; target = target->next, x++) { + if (target->target_number == w) + break; } + 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: if (goi.argc != 0) { Jim_WrongNumArgs(goi.interp, 0, goi.argv, ""); return JIM_ERR; } - Jim_SetResult(goi.interp, - Jim_NewIntObj(goi.interp, max_target_number())); + for (x = 0, target = all_targets; target; target = target->next, x++) + continue; + Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, x)); return JIM_OK; } diff --git a/src/target/target.h b/src/target/target.h index 9894aca99e..509bfd2a22 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -120,7 +120,7 @@ typedef struct target_s { target_type_t *type; /* target type definition (name, access functions) */ 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 */ const char *variant; /* what varient of this chip is it? */ 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 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); /**