- Work on fixing erase check. Many implementations are plain broken.
[openocd.git] / src / target / target.c
index 8f785dd302b0ce7f995131ce417ddab9b4ef4381..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);
@@ -1069,9 +1090,9 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx,  NULL, "mdh", handle_md_command, COMMAND_EXEC, "display memory half-words <addr> [count]");
        register_command(cmd_ctx,  NULL, "mdb", handle_md_command, COMMAND_EXEC, "display memory bytes <addr> [count]");
        
-       register_command(cmd_ctx,  NULL, "mww", handle_mw_command, COMMAND_EXEC, "write memory word <addr> <value>");
-       register_command(cmd_ctx,  NULL, "mwh", handle_mw_command, COMMAND_EXEC, "write memory half-word <addr> <value>");
-       register_command(cmd_ctx,  NULL, "mwb", handle_mw_command, COMMAND_EXEC, "write memory byte <addr> <value>");
+       register_command(cmd_ctx,  NULL, "mww", handle_mw_command, COMMAND_EXEC, "write memory word <addr> <value> [count]");
+       register_command(cmd_ctx,  NULL, "mwh", handle_mw_command, COMMAND_EXEC, "write memory half-word <addr> <value> [count]");
+       register_command(cmd_ctx,  NULL, "mwb", handle_mw_command, COMMAND_EXEC, "write memory byte <addr> <value> [count]");
        
        register_command(cmd_ctx,  NULL, "bp", handle_bp_command, COMMAND_EXEC, "set breakpoint <address> <length> [hw]");      
        register_command(cmd_ctx,  NULL, "rbp", handle_rbp_command, COMMAND_EXEC, "remove breakpoint <adress>");
@@ -1804,36 +1825,59 @@ int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
 {
        u32 address = 0;
        u32 value = 0;
-       int retval;
+       int count = 1;
+       int i;
+       int wordsize;
        target_t *target = get_current_target(cmd_ctx);
        u8 value_buf[4];
 
-       if (argc < 2)
-               return ERROR_OK;
+        if ((argc < 2) || (argc > 3))
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
        address = strtoul(args[0], NULL, 0);
        value = strtoul(args[1], NULL, 0);
+       if (argc == 3)
+               count = strtoul(args[2], NULL, 0);
+
 
        switch (cmd[2])
        {
                case 'w':
+                       wordsize = 4;
                        target_buffer_set_u32(target, value_buf, value);
-                       retval = target->type->write_memory(target, address, 4, 1, value_buf);
                        break;
                case 'h':
+                       wordsize = 2;
                        target_buffer_set_u16(target, value_buf, value);
-                       retval = target->type->write_memory(target, address, 2, 1, value_buf);
                        break;
                case 'b':
+                       wordsize = 1;
                        value_buf[0] = value;
-                       retval = target->type->write_memory(target, address, 1, 1, value_buf);
                        break;
                default:
-                       return ERROR_OK;
+                       return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       if (retval!=ERROR_OK)
+       for (i=0; i<count; i++)
        {
-               LOG_ERROR("Failure examining memory");
+               int retval;
+               switch (wordsize)
+               {
+                       case 4:
+                               retval = target->type->write_memory(target, address + i*wordsize, 4, 1, value_buf);
+                               break;
+                       case 2:
+                               retval = target->type->write_memory(target, address + i*wordsize, 2, 1, value_buf);
+                               break;
+                       case 1:
+                               retval = target->type->write_memory(target, address + i*wordsize, 1, 1, value_buf);
+                       break;
+                       default:
+                       return ERROR_OK;
+               }
+               if (retval!=ERROR_OK)
+               {
+                       return retval;
+               }
        }
 
        return ERROR_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)