Consolidate target selection code into single get_target() that handles both names...
authorkc8apf <kc8apf@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 18 May 2009 04:44:28 +0000 (04:44 +0000)
committerkc8apf <kc8apf@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Mon, 18 May 2009 04:44:28 +0000 (04:44 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@1804 b42882b7-edfa-0310-969c-e2dbd0fdcd60

15 files changed:
doc/openocd.texi
src/flash/ecos.c
src/flash/flash.c
src/flash/lpc3180_nand_controller.c
src/flash/mflash.c
src/flash/orion_nand.c
src/flash/s3c24xx_nand.c
src/target/etb.c
src/target/etm.c
src/target/etm_dummy.c
src/target/image.c
src/target/target.c
src/target/target.h
src/target/target/ti_dm355.cfg
src/target/xscale.c

index 52df9df8e1c64a2b042a0d851ac08fed6bb0ad89..9eabf41407f40c7858be79d44d4e93405b204798 100644 (file)
@@ -881,6 +881,8 @@ If the chip has 2 targets, use the names @b{_TARGETNAME0},
 At no time should the name ``target0'' (the default target name if
 none was specified) be used. The name ``target0'' is a hard coded name
 - the next target on the board will be some other number.
+In the same way, avoid using target numbers even when they are
+permitted; use the right target name(s) for your board.
 
 The user (or board file) should reasonably be able to:
 
@@ -1702,7 +1704,8 @@ tap which then connects to the TDI pin.
 @item @b{Note: Deprecated} - Index Numbers
 @* Prior to 28/nov/2008, JTAG taps where numbered from 0..N this
 feature is still present, however its use is highly discouraged and
-should not be counted upon.
+should not be counted upon.  Update all of your scripts to use
+TAP names rather than numbers.
 @item @b{Multiple chips}
 @* If your board has multiple chips, you should be
 able to @b{source} two configuration files, in the proper order, and
@@ -2045,8 +2048,8 @@ jtag configure DOTTED.NAME -event tap-disable @{
 @itemize @bullet
 @item @b{NAME}
 @* Is the name of the debug target. By convention it should be the tap
-DOTTED.NAME, this name is also used to create the target object
-command.
+DOTTED.NAME.  This name is also used to create the target object
+command, and in other places the target needs to be identified.
 @item @b{TYPE}
 @* Specifies the target type, i.e.: ARM7TDMI, or Cortex-M3. Currently supported targets are:
 @comment START types
@@ -2254,7 +2257,7 @@ The @b{flash bank} command is used to configure one or more flash chips (or bank
 
 @example
 @b{flash bank} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}>
-<@var{bus_width}> <@var{target#}> [@var{driver_options ...}]
+<@var{bus_width}> <@var{target}> [@var{driver_options ...}]
 @end example
 @cindex flash bank
 @*Configures a flash bank at <@var{base}> of <@var{size}> bytes and <@var{chip_width}>
@@ -2274,8 +2277,9 @@ perhaps configure a GPIO pin that controls the ``write protect'' pin
 on the flash chip.
 
 @b{flash bank cfi} <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}>
-<@var{target#}> [@var{jedec_probe}|@var{x16_as_x8}]
-@*CFI flashes require the number of the target they're connected to as an additional
+<@var{target}> [@var{jedec_probe}|@var{x16_as_x8}]
+@*CFI flashes require the name or number of the target they're connected to
+as an additional
 argument. The CFI driver makes use of a working area (specified for the target)
 to significantly speed up operation. 
 
@@ -2289,12 +2293,13 @@ The @var{jedec_probe} option is used to detect certain non-CFI flash ROMs, like
 @subsubsection lpc2000 options
 @cindex lpc2000 options
 
-@b{flash bank lpc2000} <@var{base}> <@var{size}> 0 0 <@var{target#}> <@var{variant}>
+@b{flash bank lpc2000} <@var{base}> <@var{size}> 0 0 <@var{target}> <@var{variant}>
 <@var{clock}> [@var{calc_checksum}]
 @*LPC flashes don't require the chip and bus width to be specified. Additional
 parameters are the <@var{variant}>, which may be @var{lpc2000_v1} (older LPC21xx and LPC22xx)
-or @var{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx), the number
-of the target this flash belongs to (first is 0), the frequency at which the core
+or @var{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx),
+the name or number of the target this flash belongs to (first is 0),
+the frequency at which the core
 is currently running (in kHz - must be an integral number), and the optional keyword
 @var{calc_checksum}, telling the driver to calculate a valid checksum for the exception
 vector table. 
@@ -2303,20 +2308,20 @@ vector table.
 @subsubsection at91sam7 options
 @cindex at91sam7 options
 
-@b{flash bank at91sam7} 0 0 0 0 <@var{target#}>
-@*AT91SAM7 flashes only require the @var{target#}, all other values are looked up after
+@b{flash bank at91sam7} 0 0 0 0 <@var{target}>
+@*AT91SAM7 flashes only require the @var{target}, all other values are looked up after
 reading the chip-id and type. 
 
 @subsubsection str7 options
 @cindex str7 options
 
-@b{flash bank str7x} <@var{base}> <@var{size}> 0 0 <@var{target#}> <@var{variant}>
+@b{flash bank str7x} <@var{base}> <@var{size}> 0 0 <@var{target}> <@var{variant}>
 @*variant can be either STR71x, STR73x or STR75x. 
 
 @subsubsection str9 options
 @cindex str9 options
 
-@b{flash bank str9x} <@var{base}> <@var{size}> 0 0 <@var{target#}>
+@b{flash bank str9x} <@var{base}> <@var{size}> 0 0 <@var{target}>
 @*The str9 needs the flash controller to be configured prior to Flash programming, e.g.
 @example
 str9x flash_config 0 4 2 0 0x80000
@@ -2325,7 +2330,7 @@ This will setup the BBSR, NBBSR, BBADR and NBBADR registers respectively.
 
 @subsubsection str9 options (str9xpec driver)
 
-@b{flash bank str9xpec} <@var{base}> <@var{size}> 0 0 <@var{target#}>
+@b{flash bank str9xpec} <@var{base}> <@var{size}> 0 0 <@var{target}>
 @*Before using the flash commands the turbo mode must be enabled using str9xpec
 @option{enable_turbo} <@var{num>.}
 
@@ -2335,25 +2340,25 @@ Use the standard str9 driver for programming. @xref{STR9 specific commands}.
 @subsubsection Stellaris (LM3Sxxx) options
 @cindex Stellaris (LM3Sxxx) options
 
-@b{flash bank stellaris} <@var{base}> <@var{size}> 0 0 <@var{target#}>
-@*Stellaris flash plugin only require the @var{target#}. 
+@b{flash bank stellaris} <@var{base}> <@var{size}> 0 0 <@var{target}>
+@*Stellaris flash plugin only require the @var{target}.
 
 @subsubsection stm32x options
 @cindex stm32x options
 
-@b{flash bank stm32x} <@var{base}> <@var{size}> 0 0 <@var{target#}>
-@*stm32x flash plugin only require the @var{target#}. 
+@b{flash bank stm32x} <@var{base}> <@var{size}> 0 0 <@var{target}>
+@*stm32x flash plugin only require the @var{target}.
 
 @subsubsection aduc702x options
 @cindex aduc702x options
 
-@b{flash bank aduc702x} 0 0 0 0 <@var{target#}>
-@*The aduc702x flash plugin works with Analog Devices model numbers ADUC7019 through ADUC7028.  The setup command only requires the @var{target#} argument (all devices in this family have the same memory layout).
+@b{flash bank aduc702x} 0 0 0 0 <@var{target}>
+@*The aduc702x flash plugin works with Analog Devices model numbers ADUC7019 through ADUC7028.  The setup command only requires the @var{target} argument (all devices in this family have the same memory layout).
 
 @subsection mFlash Configuration
 @cindex mFlash Configuration
 @b{mflash bank} <@var{soc}> <@var{base}> <@var{chip_width}> <@var{bus_width}>
-<@var{RST pin}> <@var{WP pin}> <@var{DPD pin}> <@var{target #}>
+<@var{RST pin}> <@var{WP pin}> <@var{DPD pin}> <@var{target}>
 @cindex mflash bank
 @*Configures a mflash for <@var{soc}> host bank at
 <@var{base}>. <@var{chip_width}> and <@var{bus_width}> are bytes
index 3c2b456b6c47a9ae1bf17b1ff06504023467e5f3..e1fa2d66c7a712092604c5121a4b63dacae4334b 100644 (file)
@@ -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;
index 4f4d272a4b77f8d240439240d4e627c099531640..ff66a396f557d911639717ef935320670e1c2298 100644 (file)
@@ -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;
        }
 
index 50846b92b261271ce953fe1782924f1b68be7c86..1cbd92043ebf48f17cfcb246d2997f4fa82547c2 100644 (file)
@@ -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;
        }
 
index 8913e1662aea1da556d4cd6588c945f843c5499d..5df5261df2800257baa74e039c6f3f49386c8c53 100644 (file)
@@ -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;
        }
 
index fb5a34037d22f0647305472c76853baed588eaad..f6f41f35b8af62e67778c240aac604bd2c4cbeb7 100644 (file)
@@ -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;
        }
index 291b658cdd3138912eada30804f57ac223b6b3de..a26ac2d9cb0b875294af93f6eeb8fc95ffa86341 100644 (file)
@@ -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;
 }
 
index 5f6e648e8c4104f1e004d8237542d9c7ca024ec7..9a265ad5ab4fd462037d831713023c75ef7c4a91 100644 (file)
@@ -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;
        }
 
index c54087a0b78c61a46d8c01dafc5a2529fd2f4ce3..5b83db893abaeea4abf8f7db92153ac429fc106f 100644 (file)
@@ -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;
        }
 
index ee4c3e691aba98f3019fb736ee36d6fdc33df5f7..4b84fd32061b64279e424f2e848c703e20fe00ca 100644 (file)
@@ -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;
        }
 
index 71939e79b92e6cb73bae40a7e8d3df44396e848b..d72680d1b763499646635c47a4cea7c7791db44e 100644 (file)
@@ -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;
                }
 
index 3ec28284e6da22a93662c51d2a1b891ee02e7786..7571e4e358fc763a2f8e2a8d83421c354a3cddf4 100644 (file)
@@ -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;
        }
index 4a6dde1addc88a0860a0d627394ee09436365539..1c1e10efc5625848aabf319c0c2d5849c78bccd2 100644 (file)
@@ -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);
index acf4b3040daf811f7deba06f23e30c6730d91a57..e4de1a58ad1b4d08ffde56a80a369f268cad7e94 100644 (file)
@@ -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
index abdbe866905564a2efbe3dabf86708d3cd4f27c9..3947da0b49974180f1622dbef347e4f1c6596eb7 100644 (file)
@@ -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;
        }