added support for Tcl config scripts on the command line(use .tcl extension).
[openocd.git] / src / target / target.c
index 7ab7a7c69addf7c3e0d681a9ebd83867c5a4a232..0237fd669b4d6181c223ff3daf983ab5a619049c 100644 (file)
@@ -215,28 +215,35 @@ target_t* get_current_target(command_context_t *cmd_ctx)
        return target;
 }
 
+static void execute_script(struct command_context_s *cmd_ctx, char *reset_script)
+{
+       if (reset_script==NULL)
+               return;
+       FILE *script;
+       script = open_file_from_path(reset_script, "r");
+       if (!script)
+       {
+               LOG_ERROR("couldn't open script file %s", reset_script);
+               return;
+       }
+       
+       LOG_INFO("executing script '%s'", reset_script);
+       command_run_file(cmd_ctx, script, COMMAND_EXEC);
+       fclose(script);
+}
+
 /* Process target initialization, when target entered debug out of reset
  * the handler is unregistered at the end of this function, so it's only called once
  */
 int target_init_handler(struct target_s *target, enum target_event event, void *priv)
 {
-       FILE *script;
        struct command_context_s *cmd_ctx = priv;
        
-       if ((event == TARGET_EVENT_HALTED) && (target->reset_script))
+       if (event == TARGET_EVENT_HALTED)
        {
                target_unregister_event_callback(target_init_handler, priv);
 
-               script = open_file_from_path(target->reset_script, "r");
-               if (!script)
-               {
-                       LOG_ERROR("couldn't open script file %s", target->reset_script);
-                               return ERROR_OK;
-               }
-
-               LOG_INFO("executing reset script '%s'", target->reset_script);
-               command_run_file(cmd_ctx, script, COMMAND_EXEC);
-               fclose(script);
+               execute_script(cmd_ctx, target->reset_script);
 
                jtag_execute_queue();
        }
@@ -295,6 +302,13 @@ int target_process_reset(struct command_context_s *cmd_ctx)
 
        jtag->speed(jtag_speed);
 
+       target = targets;
+       while (target)
+       {
+               execute_script(cmd_ctx, target->pre_reset_script);
+               target = target->next;
+       }
+       
        if ((retval = jtag_init_reset(cmd_ctx)) != ERROR_OK)
                return retval;
        
@@ -394,18 +408,19 @@ int target_process_reset(struct command_context_s *cmd_ctx)
                target = target->next;
        }
        
+       if ((retval = jtag_execute_queue()) != ERROR_OK)
+       {
+               LOG_WARNING("JTAG communication failed while deasserting reset.");
+               retval = ERROR_OK;
+       }
+
        if (jtag_reset_config & RESET_SRST_PULLS_TRST)
        {
                /* If TRST was asserted we need to set up registers again */
                if ((retval = target_examine(cmd_ctx)) != ERROR_OK)
                        return retval;
-       }
+       }               
        
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
-               LOG_WARNING("JTAG communication failed while deasserting reset.");
-               retval = ERROR_OK;
-       }
        
        LOG_DEBUG("Waiting for halted stated as approperiate");
        
@@ -1135,6 +1150,23 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
        return retval;
 }
 
+int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank)
+{
+       int retval;
+       if (!target->type->examined)
+       {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
+       
+       if (target->type->blank_check_memory == 0)
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+       
+       retval = target->type->blank_check_memory(target, address, size, blank);
+                       
+       return retval;
+}
+
 int target_read_u32(struct target_s *target, u32 address, u32 *value)
 {
        u8 value_buf[4];
@@ -1371,7 +1403,9 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
 
                                *last_target_p = malloc(sizeof(target_t));
                                
-                               (*last_target_p)->type = target_types[i];
+                               /* allocate memory for each unique target type */
+                               (*last_target_p)->type = (target_type_t*)malloc(sizeof(target_type_t));
+                               *((*last_target_p)->type) = *target_types[i]; 
                                
                                if (strcmp(args[1], "big") == 0)
                                        (*last_target_p)->endianness = TARGET_BIG_ENDIAN;
@@ -1404,6 +1438,7 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
                                (*last_target_p)->run_and_halt_time = 1000; /* default 1s */
                                
                                (*last_target_p)->reset_script = NULL;
+                               (*last_target_p)->pre_reset_script = NULL;
                                (*last_target_p)->post_halt_script = NULL;
                                (*last_target_p)->pre_resume_script = NULL;
                                (*last_target_p)->gdb_program_script = NULL;
@@ -1470,12 +1505,18 @@ int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, c
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
        
-       if (strcmp(args[1], "reset") == 0)
+       if ((strcmp(args[1], "reset") == 0)||(strcmp(args[1], "post_reset") == 0))
        {
                if (target->reset_script)
                        free(target->reset_script);
                target->reset_script = strdup(args[2]);
        }
+       else if (strcmp(args[1], "pre_reset") == 0)
+       {
+               if (target->pre_reset_script)
+                       free(target->pre_reset_script);
+               target->pre_reset_script = strdup(args[2]);
+       }
        else if (strcmp(args[1], "post_halt") == 0)
        {
                if (target->post_halt_script)
@@ -2403,7 +2444,7 @@ int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
 
                while (watchpoint)
                {
-                       command_print(cmd_ctx, "address: 0x%8.8x, mask: 0x%8.8x, r/w/a: %i, value: 0x%8.8x, mask: 0x%8.8x", watchpoint->address, watchpoint->length, watchpoint->rw, watchpoint->value, watchpoint->mask);
+                       command_print(cmd_ctx, "address: 0x%8.8x, len: 0x%8.8x, r/w/a: %i, value: 0x%8.8x, mask: 0x%8.8x", watchpoint->address, watchpoint->length, watchpoint->rw, watchpoint->value, watchpoint->mask);
                        watchpoint = watchpoint->next;
                }
        } 

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)