- Work on fixing erase check. Many implementations are plain broken.
[openocd.git] / src / target / target.c
index f098ef3484ec648d82dd5ccae7b56aa996dc8aac..f90834d1bd8263c006922ed4e8d843022fa3b041 100644 (file)
@@ -284,21 +284,16 @@ int target_process_reset(struct command_context_s *cmd_ctx)
                                        break;
                        } 
                }
-               switch (target->reset_mode)
-               {
-                       case RESET_HALT:
-                       case RESET_INIT:
-                               target->type->prepare_reset_halt(target);
-                               break;
-                       default:
-                               break;
-               }
                target = target->next;
        }
        
        target = targets;
        while (target)
        {
+               /* we have no idea what state the target is in, so we
+                * have to drop working areas
+                */
+               target_free_all_working_areas_restore(target, 0);
                target->type->assert_reset(target);
                target = target->next;
        }
@@ -343,6 +338,8 @@ int target_process_reset(struct command_context_s *cmd_ctx)
        }
        jtag_execute_queue();
        
+       LOG_DEBUG("Waiting for halted stated as approperiate");
+       
        /* Wait for reset to complete, maximum 5 seconds. */    
        gettimeofday(&timeout, NULL);
        timeval_add_time(&timeout, 5, 0);
@@ -355,14 +352,18 @@ int target_process_reset(struct command_context_s *cmd_ctx)
                target = targets;
                while (target)
                {
+                       LOG_DEBUG("Polling target");
                        target->type->poll(target);
-                       if ((target->reset_mode == RESET_RUN_AND_INIT) || (target->reset_mode == RESET_RUN_AND_HALT))
+                       if ((target->reset_mode == RESET_RUN_AND_INIT) || 
+                                       (target->reset_mode == RESET_RUN_AND_HALT) ||
+                                       (target->reset_mode == RESET_HALT) ||
+                                       (target->reset_mode == RESET_INIT))
                        {
                                if (target->state != TARGET_HALTED)
                                {
                                        if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec)))
                                        {
-                                               LOG_USER("Timed out waiting for reset");
+                                               LOG_USER("Timed out waiting for halt after reset");
                                                goto done;
                                        }
                                        /* this will send alive messages on e.g. GDB remote protocol. */
@@ -384,6 +385,16 @@ int target_process_reset(struct command_context_s *cmd_ctx)
        /* We want any events to be processed before the prompt */
        target_call_timer_callbacks_now();
 
+       /* if we timed out we need to unregister these handlers */
+       target = targets;
+       while (target)
+       {
+               target_unregister_timer_callback(target_run_and_halt_handler, target);
+               target = target->next;
+       }
+       target_unregister_event_callback(target_init_handler, cmd_ctx);
+                               
+       
        jtag->speed(jtag_speed_post_reset);
        
        return retval;
@@ -722,12 +733,12 @@ int target_alloc_working_area(struct target_s *target, u32 size, working_area_t
        return ERROR_OK;
 }
 
-int target_free_working_area(struct target_s *target, working_area_t *area)
+int target_free_working_area_restore(struct target_s *target, working_area_t *area, int restore)
 {
        if (area->free)
                return ERROR_OK;
        
-       if (target->backup_working_area)
+       if (restore&&target->backup_working_area)
                target->type->write_memory(target, area->address, 4, area->size / 4, area->backup);
        
        area->free = 1;
@@ -739,14 +750,19 @@ int target_free_working_area(struct target_s *target, working_area_t *area)
        return ERROR_OK;
 }
 
-int target_free_all_working_areas(struct target_s *target)
+int target_free_working_area(struct target_s *target, working_area_t *area)
+{
+       return target_free_working_area_restore(target, area, 1);
+}
+
+int target_free_all_working_areas_restore(struct target_s *target, int restore)
 {
        working_area_t *c = target->working_areas;
 
        while (c)
        {
                working_area_t *next = c->next;
-               target_free_working_area(target, c);
+               target_free_working_area_restore(target, c, restore);
                
                if (c->backup)
                        free(c->backup);
@@ -761,6 +777,11 @@ int target_free_all_working_areas(struct target_s *target)
        return ERROR_OK;
 }
 
+int target_free_all_working_areas(struct target_s *target)
+{
+       return target_free_all_working_areas_restore(target, 1); 
+}
+
 int target_register_commands(struct command_context_s *cmd_ctx)
 {
        register_command(cmd_ctx, NULL, "target", handle_target_command, COMMAND_CONFIG, NULL);

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)