Consolidate target selection code into single get_target() that handles both names and numbers. Provided by David Brownell <david-b@pacbell.net>
git-svn-id: svn://svn.berlios.de/openocd/trunk@1804 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
+2
-2
@@ -164,10 +164,10 @@ static int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char
|
||||
bank->sectors[i].is_protected = 0;
|
||||
}
|
||||
|
||||
info->target = get_target_by_num(strtoul(args[5], NULL, 0));
|
||||
info->target = get_target(args[5]);
|
||||
if (info->target == NULL)
|
||||
{
|
||||
LOG_ERROR("no target '%i' configured", (int)strtoul(args[5], NULL, 0));
|
||||
LOG_ERROR("target '%s' not defined", args[5]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
return ERROR_OK;
|
||||
|
||||
+2
-2
@@ -261,9 +261,9 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if ((target = get_target_by_num(strtoul(args[5], NULL, 0))) == NULL)
|
||||
if ((target = get_target(args[5])) == NULL)
|
||||
{
|
||||
LOG_ERROR("target %lu not defined", strtoul(args[5], NULL, 0));
|
||||
LOG_ERROR("target '%s' not defined", args[5]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,10 +71,10 @@ static int lpc3180_nand_device_command(struct command_context_s *cmd_ctx, char *
|
||||
lpc3180_info = malloc(sizeof(lpc3180_nand_controller_t));
|
||||
device->controller_priv = lpc3180_info;
|
||||
|
||||
lpc3180_info->target = get_target_by_num(strtoul(args[1], NULL, 0));
|
||||
lpc3180_info->target = get_target(args[1]);
|
||||
if (!lpc3180_info->target)
|
||||
{
|
||||
LOG_ERROR("no target '%s' configured", args[1]);
|
||||
LOG_ERROR("target '%s' not defined", args[1]);
|
||||
return ERROR_NAND_DEVICE_INVALID;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -795,9 +795,9 @@ static int mflash_bank_command(struct command_context_s *cmd_ctx, char *cmd, cha
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if ((target = get_target_by_num(strtoul(args[7], NULL, 0))) == NULL)
|
||||
if ((target = get_target(args[7])) == NULL)
|
||||
{
|
||||
LOG_ERROR("target %lu not defined", strtoul(args[7], NULL, 0));
|
||||
LOG_ERROR("target '%s' not defined", args[7]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,9 +210,9 @@ int orion_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
|
||||
}
|
||||
|
||||
device->controller_priv = hw;
|
||||
hw->target = get_target_by_num(strtoul(args[1], NULL, 0));
|
||||
hw->target = get_target(args[1]);
|
||||
if (!hw->target) {
|
||||
LOG_ERROR("no target '%s' configured", args[1]);
|
||||
LOG_ERROR("target '%s' not defined", args[1]);
|
||||
free(hw);
|
||||
return ERROR_NAND_DEVICE_INVALID;
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ s3c24xx_nand_device_command(struct command_context_s *cmd_ctx, char *cmd,
|
||||
|
||||
device->controller_priv = s3c24xx_info;
|
||||
|
||||
s3c24xx_info->target = get_target_by_num(strtoul(args[1], NULL, 0));
|
||||
s3c24xx_info->target = get_target(args[1]);
|
||||
if (s3c24xx_info->target == NULL) {
|
||||
LOG_ERROR("no target '%s' configured", args[1]);
|
||||
LOG_ERROR("target '%s' not defined", args[1]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return s3c24xx_info;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -372,11 +372,11 @@ static int handle_etb_config_command(struct command_context_s *cmd_ctx, char *cm
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
target = get_target_by_num(strtoul(args[0], NULL, 0));
|
||||
target = get_target(args[0]);
|
||||
|
||||
if (!target)
|
||||
{
|
||||
LOG_ERROR("target number '%s' not defined", args[0]);
|
||||
LOG_ERROR("target '%s' not defined", args[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -1205,11 +1205,10 @@ static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cm
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
target = get_target_by_num(strtoul(args[0], NULL, 0));
|
||||
|
||||
target = get_target(args[0]);
|
||||
if (!target)
|
||||
{
|
||||
LOG_ERROR("target number '%s' not defined", args[0]);
|
||||
LOG_ERROR("target '%s' not defined", args[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ static int handle_etm_dummy_config_command(struct command_context_s *cmd_ctx, ch
|
||||
armv4_5_common_t *armv4_5;
|
||||
arm7_9_common_t *arm7_9;
|
||||
|
||||
target = get_target_by_num(strtoul(args[0], NULL, 0));
|
||||
target = get_target(args[0]);
|
||||
|
||||
if (!target)
|
||||
{
|
||||
LOG_ERROR("target number '%s' not defined", args[0]);
|
||||
LOG_ERROR("target '%s' not defined", args[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -711,10 +711,11 @@ int image_open(image_t *image, char *url, char *type_string)
|
||||
}
|
||||
else if (image->type == IMAGE_MEMORY)
|
||||
{
|
||||
target_t *target = get_target_by_num(strtoul(url, NULL, 0));
|
||||
if (target==NULL)
|
||||
target_t *target = get_target(url);
|
||||
|
||||
if (target == NULL)
|
||||
{
|
||||
LOG_ERROR("Target '%s' does not exist", url);
|
||||
LOG_ERROR("target '%s' not defined", url);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
+32
-23
@@ -320,8 +320,36 @@ void target_buffer_set_u8(target_t *target, u8 *buffer, u8 value)
|
||||
*buffer = value;
|
||||
}
|
||||
|
||||
/* return a pointer to a configured target; id is name or number */
|
||||
target_t *get_target(const char *id)
|
||||
{
|
||||
target_t *target;
|
||||
char *endptr;
|
||||
int num;
|
||||
|
||||
/* try as tcltarget name */
|
||||
for (target = all_targets; target; target = target->next) {
|
||||
if (target->cmd_name == NULL)
|
||||
continue;
|
||||
if (strcmp(id, target->cmd_name) == 0)
|
||||
return target;
|
||||
}
|
||||
|
||||
/* no match, try as number */
|
||||
num = strtoul(id, &endptr, 0);
|
||||
if (*endptr != 0)
|
||||
return NULL;
|
||||
|
||||
for (target = all_targets; target; target = target->next) {
|
||||
if (target->target_number == num)
|
||||
return target;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* returns a pointer to the n-th configured target */
|
||||
target_t* get_target_by_num(int num)
|
||||
static target_t *get_target_by_num(int num)
|
||||
{
|
||||
target_t *target = all_targets;
|
||||
|
||||
@@ -1333,35 +1361,16 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
|
||||
|
||||
static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
||||
{
|
||||
char *cp;
|
||||
target_t *target = all_targets;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* try as tcltarget name */
|
||||
for( target = all_targets ; target ; target = target->next ){
|
||||
if( target->cmd_name ){
|
||||
if( 0 == strcmp( args[0], target->cmd_name ) ){
|
||||
/* MATCH */
|
||||
goto Match;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* no match, try as number */
|
||||
|
||||
int num = strtoul(args[0], &cp, 0 );
|
||||
if( *cp != 0 ){
|
||||
/* then it was not a number */
|
||||
command_print( cmd_ctx, "Target: %s unknown, try one of:\n", args[0] );
|
||||
goto DumpTargets;
|
||||
}
|
||||
|
||||
target = get_target_by_num( num );
|
||||
if( target == NULL ){
|
||||
target = get_target(args[0]);
|
||||
if (target == NULL) {
|
||||
command_print(cmd_ctx,"Target: %s is unknown, try one of:\n", args[0] );
|
||||
goto DumpTargets;
|
||||
}
|
||||
Match:
|
||||
|
||||
cmd_ctx->current_target = target->target_number;
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
+1
-1
@@ -371,7 +371,7 @@ 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_by_num(int num);
|
||||
extern target_t *get_target(const char *id);
|
||||
|
||||
extern int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer);
|
||||
extern int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer);
|
||||
|
||||
@@ -56,8 +56,5 @@ arm7_9 fast_memory_access enable
|
||||
arm7_9 dcc_downloads enable
|
||||
|
||||
# trace setup
|
||||
# FIXME we ought to be able to say "... config $_TARGETNAME ..."
|
||||
# (not "config 0") facilitating additional targets (e.g. other chips)
|
||||
etm config 0 16 normal full etb
|
||||
etb config 0 $_CHIPNAME.etb
|
||||
|
||||
etm config $_TARGETNAME 16 normal full etb
|
||||
etb config $_TARGETNAME $_CHIPNAME.etb
|
||||
|
||||
+5
-4
@@ -3147,9 +3147,9 @@ int xscale_handle_debug_handler_command(struct command_context_s *cmd_ctx, char
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
if ((target = get_target_by_num(strtoul(args[0], NULL, 0))) == NULL)
|
||||
if ((target = get_target(args[0])) == NULL)
|
||||
{
|
||||
LOG_ERROR("no target '%s' configured", args[0]);
|
||||
LOG_ERROR("target '%s' not defined", args[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
@@ -3187,9 +3187,10 @@ int xscale_handle_cache_clean_address_command(struct command_context_s *cmd_ctx,
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if ((target = get_target_by_num(strtoul(args[0], NULL, 0))) == NULL)
|
||||
target = get_target(args[0]);
|
||||
if (target == NULL)
|
||||
{
|
||||
LOG_ERROR("no target '%s' configured", args[0]);
|
||||
LOG_ERROR("target '%s' not defined", args[0]);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user