target: Remove soft_reset_halt_imp
[openocd.git] / src / target / target.c
index c71c536030f867ea980835e4abeeabebbb0316b6..7e3975695404dfc5cb5e3b7587fb29010abe5639 100644 (file)
@@ -87,7 +87,7 @@ extern struct target_type dsp563xx_target;
 extern struct target_type dsp5680xx_target;
 extern struct target_type testee_target;
 extern struct target_type avr32_ap7k_target;
-extern struct target_type stm32_stlink_target;
+extern struct target_type hla_target;
 
 static struct target_type *target_types[] = {
        &arm7tdmi_target,
@@ -110,7 +110,7 @@ static struct target_type *target_types[] = {
        &dsp5680xx_target,
        &testee_target,
        &avr32_ap7k_target,
-       &stm32_stlink_target,
+       &hla_target,
        NULL,
 };
 
@@ -379,9 +379,9 @@ struct target *get_target(const char *id)
 
        /* try as tcltarget name */
        for (target = all_targets; target; target = target->next) {
-               if (target->cmd_name == NULL)
+               if (target_name(target) == NULL)
                        continue;
-               if (strcmp(id, target->cmd_name) == 0)
+               if (strcmp(id, target_name(target)) == 0)
                        return target;
        }
 
@@ -395,7 +395,7 @@ struct target *get_target(const char *id)
        for (target = all_targets; target; target = target->next) {
                if (target->target_number == (int)num) {
                        LOG_WARNING("use '%s' as target identifier, not '%u'",
-                                       target->cmd_name, num);
+                                       target_name(target), num);
                        return target;
                }
        }
@@ -677,18 +677,18 @@ static int target_read_memory_imp(struct target *target, uint32_t address,
        return target->type->read_memory_imp(target, address, size, count, buffer);
 }
 
-static int target_soft_reset_halt_imp(struct target *target)
+static int target_soft_reset_halt(struct target *target)
 {
        if (!target_was_examined(target)) {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
        }
-       if (!target->type->soft_reset_halt_imp) {
+       if (!target->type->soft_reset_halt) {
                LOG_ERROR("Target %s does not support soft_reset_halt",
                                target_name(target));
                return ERROR_FAIL;
        }
-       return target->type->soft_reset_halt_imp(target);
+       return target->type->soft_reset_halt(target);
 }
 
 /**
@@ -822,6 +822,7 @@ int target_run_flash_async_algorithm(struct target *target,
                uint32_t entry_point, uint32_t exit_point, void *arch_info)
 {
        int retval;
+       int timeout = 0;
 
        /* Set up working area. First word is write pointer, second word is read pointer,
         * rest is fifo data area. */
@@ -893,9 +894,19 @@ int target_run_flash_async_algorithm(struct target *target,
                         * less than buffer size / flash speed. This is very unlikely to
                         * run when using high latency connections such as USB. */
                        alive_sleep(10);
+
+                       /* to stop an infinite loop on some targets check and increment a timeout
+                        * this issue was observed on a stellaris using the new ICDI interface */
+                       if (timeout++ >= 500) {
+                               LOG_ERROR("timeout waiting for algorithm, a target reset is recommended");
+                               return ERROR_FLASH_OPERATION_FAILED;
+                       }
                        continue;
                }
 
+               /* reset our timeout */
+               timeout = 0;
+
                /* Limit to the amount of data we actually want to write */
                if (thisrun_bytes > count * block_size)
                        thisrun_bytes = count * block_size;
@@ -971,7 +982,7 @@ int target_add_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
        if ((target->state != TARGET_HALTED) && (breakpoint->type != BKPT_HARD)) {
-               LOG_WARNING("target %s is not halted", target->cmd_name);
+               LOG_WARNING("target %s is not halted", target_name(target));
                return ERROR_TARGET_NOT_HALTED;
        }
        return target->type->add_breakpoint(target, breakpoint);
@@ -981,7 +992,7 @@ int target_add_context_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target %s is not halted", target->cmd_name);
+               LOG_WARNING("target %s is not halted", target_name(target));
                return ERROR_TARGET_NOT_HALTED;
        }
        return target->type->add_context_breakpoint(target, breakpoint);
@@ -991,7 +1002,7 @@ int target_add_hybrid_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target %s is not halted", target->cmd_name);
+               LOG_WARNING("target %s is not halted", target_name(target));
                return ERROR_TARGET_NOT_HALTED;
        }
        return target->type->add_hybrid_breakpoint(target, breakpoint);
@@ -1007,7 +1018,7 @@ int target_add_watchpoint(struct target *target,
                struct watchpoint *watchpoint)
 {
        if (target->state != TARGET_HALTED) {
-               LOG_WARNING("target %s is not halted", target->cmd_name);
+               LOG_WARNING("target %s is not halted", target_name(target));
                return ERROR_TARGET_NOT_HALTED;
        }
        return target->type->add_watchpoint(target, watchpoint);
@@ -1088,9 +1099,6 @@ static int target_init_one(struct command_context *cmd_ctx,
        type->read_memory_imp = target->type->read_memory;
        type->read_memory = target_read_memory_imp;
 
-       type->soft_reset_halt_imp = target->type->soft_reset_halt;
-       type->soft_reset_halt = target_soft_reset_halt_imp;
-
        /* Sanity-check MMU support ... stub in what we must, to help
         * implement it in stages, but warn if we need to do so.
         */
@@ -1405,6 +1413,7 @@ static void target_split_working_area(struct working_area *area, uint32_t size)
                new_wa->size = area->size - size;
                new_wa->address = area->address + size;
                new_wa->backup = NULL;
+               new_wa->user = NULL;
                new_wa->free = true;
 
                area->next = new_wa;
@@ -1493,6 +1502,7 @@ int target_alloc_working_area_try(struct target *target, uint32_t size, struct w
                        new_wa->size = target->working_area_size & ~3UL; /* 4-byte align */
                        new_wa->address = target->working_area;
                        new_wa->backup = NULL;
+                       new_wa->user = NULL;
                        new_wa->free = true;
                }
 
@@ -1536,6 +1546,9 @@ int target_alloc_working_area_try(struct target *target, uint32_t size, struct w
        c->free = false;
        *area = c;
 
+       /* user pointer */
+       c->user = area;
+
        print_wa_layout(target);
 
        return ERROR_OK;
@@ -1586,6 +1599,13 @@ static int target_free_working_area_restore(struct target *target, struct workin
        LOG_DEBUG("freed %"PRIu32" bytes of working area at address 0x%08"PRIx32,
                        area->size, area->address);
 
+       /* mark user pointer invalid */
+       /* TODO: Is this really safe? It points to some previous caller's memory.
+        * How could we know that the area pointer is still in that place and not
+        * some other vital data? What's the purpose of this, anyway? */
+       *area->user = NULL;
+       area->user = NULL;
+
        target_merge_working_areas(target);
 
        print_wa_layout(target);
@@ -1613,6 +1633,8 @@ static void target_free_all_working_areas_restore(struct target *target, int res
                        if (restore)
                                target_restore_working_area(target, c);
                        c->free = true;
+                       *c->user = NULL; /* Same as above */
+                       c->user = NULL;
                }
                c = c->next;
        }
@@ -2139,9 +2161,6 @@ static int sense_handler(void)
        return ERROR_OK;
 }
 
-static int backoff_times;
-static int backoff_count;
-
 /* process target state changes */
 static int handle_target(void *priv)
 {
@@ -2197,13 +2216,6 @@ static int handle_target(void *priv)
                recursive = 0;
        }
 
-       if (backoff_times > backoff_count) {
-               /* do not poll this time as we failed previously */
-               backoff_count++;
-               return ERROR_OK;
-       }
-       backoff_count = 0;
-
        /* Poll targets for state changes unless that's globally disabled.
         * Skip targets that are currently disabled.
         */
@@ -2213,18 +2225,26 @@ static int handle_target(void *priv)
                if (!target->tap->enabled)
                        continue;
 
+               if (target->backoff.times > target->backoff.count) {
+                       /* do not poll this time as we failed previously */
+                       target->backoff.count++;
+                       continue;
+               }
+               target->backoff.count = 0;
+
                /* only poll target if we've got power and srst isn't asserted */
                if (!powerDropout && !srstAsserted) {
                        /* polling may fail silently until the target has been examined */
                        retval = target_poll(target);
                        if (retval != ERROR_OK) {
                                /* 100ms polling interval. Increase interval between polling up to 5000ms */
-                               if (backoff_times * polling_interval < 5000) {
-                                       backoff_times *= 2;
-                                       backoff_times++;
+                               if (target->backoff.times * polling_interval < 5000) {
+                                       target->backoff.times *= 2;
+                                       target->backoff.times++;
                                }
-                               LOG_USER("Polling target failed, GDB will be halted. Polling again in %dms",
-                                               backoff_times * polling_interval);
+                               LOG_USER("Polling target %s failed, GDB will be halted. Polling again in %dms",
+                                               target_name(target),
+                                               target->backoff.times * polling_interval);
 
                                /* Tell GDB to halt the debugger. This allows the user to
                                 * run monitor commands to handle the situation.
@@ -2233,9 +2253,9 @@ static int handle_target(void *priv)
                                return retval;
                        }
                        /* Since we succeeded, we reset backoff count */
-                       if (backoff_times > 0)
-                               LOG_USER("Polling succeeded again");
-                       backoff_times = 0;
+                       if (target->backoff.times > 0)
+                               LOG_USER("Polling target %s succeeded again", target_name(target));
+                       target->backoff.times = 0;
                }
        }
 
@@ -2475,7 +2495,7 @@ COMMAND_HANDLER(handle_soft_reset_halt_command)
 
        LOG_USER("requesting target halt and executing a soft reset");
 
-       target->type->soft_reset_halt(target);
+       target_soft_reset_halt(target);
 
        return ERROR_OK;
 }
@@ -4884,6 +4904,15 @@ static int target_create(Jim_GetOptInfo *goi)
                        /* found */
                        break;
                }
+
+               /* check for deprecated name */
+               if (target_types[x]->deprecated_name) {
+                       if (0 == strcmp(cp, target_types[x]->deprecated_name)) {
+                               /* found */
+                               LOG_WARNING("target name is deprecated use: \'%s\'", target_types[x]->name);
+                               break;
+                       }
+               }
        }
        if (target_types[x] == NULL) {
                Jim_SetResultFormatted(goi->interp, "Unknown target type %s, try one of ", cp);
@@ -5039,7 +5068,7 @@ static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv
        struct command_context *cmd_ctx = current_command_context(interp);
        assert(cmd_ctx != NULL);
 
-       Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1);
+       Jim_SetResultString(interp, target_name(get_current_target(cmd_ctx)), -1);
        return JIM_OK;
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)