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
@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
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" \
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/
-/***************************************************************************************************************************************************************************************
+/***************************************************************************
*
* 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,
-* 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"
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)
{
flash_bank_t *t_bank = bank;
uint8_t ale, cle;
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;
}
# 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
/* 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 */
}
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++;
}
}
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)
{
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;
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);
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;
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, "<no parameters>");
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;
}
{
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;
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);
/**