fileio: fileio_size() can now fail
[openocd.git] / src / target / target.c
index 3bf6824be289a496643aa2342bb763573f51a8cf..82cbbff547340b767c192828c38c4b2d1190090a 100644 (file)
@@ -70,6 +70,7 @@ extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
 extern struct target_type dsp563xx_target;
 extern struct target_type testee_target;
+extern struct target_type avr32_ap7k_target;
 
 static struct target_type *target_types[] =
 {
@@ -90,12 +91,14 @@ static struct target_type *target_types[] =
        &avr_target,
        &dsp563xx_target,
        &testee_target,
+       &avr32_ap7k_target,
        NULL,
 };
 
 struct target *all_targets = NULL;
 static struct target_event_callback *target_event_callbacks = NULL;
 static struct target_timer_callback *target_timer_callbacks = NULL;
+static const int polling_interval = 100;
 
 static const Jim_Nvp nvp_assert[] = {
        { .name = "assert", NVP_ASSERT },
@@ -862,7 +865,7 @@ static int target_init(struct command_context *cmd_ctx)
                return retval;
 
        retval = target_register_timer_callback(&handle_target,
-                       100, 1, cmd_ctx->interp);
+                       polling_interval, 1, cmd_ctx->interp);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1800,6 +1803,9 @@ static int sense_handler(void)
        return ERROR_OK;
 }
 
+static int backoff_times = 0;
+static int backoff_count = 0;
+
 /* process target state changes */
 static int handle_target(void *priv)
 {
@@ -1862,6 +1868,14 @@ 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.
         */
@@ -1878,17 +1892,26 @@ static int handle_target(void *priv)
                        /* polling may fail silently until the target has been examined */
                        if ((retval = target_poll(target)) != ERROR_OK)
                        {
-                               /* FIX!!!!! If we add a LOG_INFO() here to output a line in GDB
-                                * *why* we are aborting GDB, then we'll spam telnet when the
-                                * poll is failing persistently.
-                                *
-                                * If we could implement an event that detected the
-                                * target going from non-pollable to pollable, we could issue
-                                * an error only upon the transition.
+                               /* 100ms polling interval. Increase interval between polling up to 5000ms */
+                               if (backoff_times * polling_interval < 5000)
+                               {
+                                       backoff_times *= 2;
+                                       backoff_times++;
+                               }
+                               LOG_USER("Polling target failed, GDB will be halted. Polling again in %dms", backoff_times * polling_interval);
+
+                               /* Tell GDB to halt the debugger. This allows the user to
+                                * run monitor commands to handle the situation.
                                 */
                                target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
                                return retval;
                        }
+                       /* Since we succeeded, we reset backoff count */
+                       if (backoff_times > 0)
+                       {
+                               LOG_USER("Polling succeeded again");
+                       }
+                       backoff_times = 0;
                }
        }
 
@@ -2625,9 +2648,13 @@ COMMAND_HANDLER(handle_dump_image_command)
 
        if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
        {
+               int filesize;
+               retval = fileio_size(&fileio, &filesize);
+               if (retval != ERROR_OK)
+                       return retval;
                command_print(CMD_CTX,
-                               "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)fileio.size,
-                               duration_elapsed(&bench), duration_kbps(&bench, fileio.size));
+                               "dumped %ld bytes in %fs (%0.3f KiB/s)", (long)filesize,
+                               duration_elapsed(&bench), duration_kbps(&bench, filesize));
        }
 
        return retval;
@@ -2703,7 +2730,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
                if (verify)
                {
                        /* calculate checksum of image */
-                       image_calculate_checksum(buffer, buf_cnt, &checksum);
+                       retval = image_calculate_checksum(buffer, buf_cnt, &checksum);
+                       if (retval != ERROR_OK)
+                       {
+                               free(buffer);
+                               break;
+                       }
 
                        retval = target_checksum_memory(target, image.sections[i].base_address, buf_cnt, &mem_checksum);
                        if (retval != ERROR_OK)
@@ -2769,6 +2801,10 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
                free(buffer);
                image_size += buf_cnt;
        }
+       if (diffs > 0)
+       {
+               command_print(CMD_CTX, "No more differences found.");
+       }
 done:
        if (diffs > 0)
        {
@@ -5266,7 +5302,7 @@ static const struct command_registration target_exec_command_handlers[] = {
                .usage = "filename [offset [type]]",
        },
        {
-               .name = "ocd_mem2array",
+               .name = "mem2array",
                .mode = COMMAND_EXEC,
                .jim_handler = jim_mem2array,
                .help = "read 8/16/32 bit memory and return as a TCL array "
@@ -5274,7 +5310,7 @@ static const struct command_registration target_exec_command_handlers[] = {
                .usage = "arrayname bitwidth address count",
        },
        {
-               .name = "ocd_array2mem",
+               .name = "array2mem",
                .mode = COMMAND_EXEC,
                .jim_handler = jim_array2mem,
                .help = "convert a TCL array to memory locations "

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)