disable polling continuous polling during reset
[openocd.git] / src / target / target.c
index 2209612cf180a2ef03c26b2560604a173d2653f2..a5447aa6cc7c75dfbd35e080543c7c4df49f54fd 100644 (file)
@@ -34,6 +34,7 @@
 #endif
 
 #include "target.h"
+#include "target_type.h"
 #include "target_request.h"
 #include "time_support.h"
 #include "register.h"
@@ -41,8 +42,6 @@
 #include "image.h"
 #include "jtag.h"
 
-#include <inttypes.h>
-
 
 static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
@@ -435,9 +434,18 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo
                return ERROR_FAIL;
        }
 
+       /* disable polling during reset to make reset event scripts
+        * more predictable, i.e. dr/irscan & pathmove in events will
+        * not have JTAG operations injected into the middle of a sequence.
+        */
+       int save_poll = target_continous_poll;
+       target_continous_poll = 0;
+
        sprintf( buf, "ocd_process_reset %s", n->name );
        retval = Jim_Eval( interp, buf );
 
+       target_continous_poll = save_poll;
+
        if(retval != JIM_OK) {
                Jim_PrintErrorMessage(interp);
                return ERROR_FAIL;
@@ -467,6 +475,11 @@ static int default_examine(struct target_s *target)
        return ERROR_OK;
 }
 
+int target_examine_one(struct target_s *target)
+{
+       return target->type->examine(target);
+}
+
 /* Targets that correctly implement init+examine, i.e.
  * no communication with target during init:
  *
@@ -475,15 +488,21 @@ static int default_examine(struct target_s *target)
 int target_examine(void)
 {
        int retval = ERROR_OK;
-       target_t *target = all_targets;
-       while (target)
+       target_t *target;
+
+       for (target = all_targets; target; target = target->next)
        {
-               if ((retval = target->type->examine(target))!=ERROR_OK)
+               if (!target->tap->enabled)
+                       continue;
+               if ((retval = target_examine_one(target)) != ERROR_OK)
                        return retval;
-               target = target->next;
        }
        return retval;
 }
+const char *target_get_name(struct target_s *target)
+{
+       return target->type->name;
+}
 
 static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
 {
@@ -536,6 +555,45 @@ int target_write_memory(struct target_s *target,
 {
        return target->type->write_memory(target, address, size, count, buffer);
 }
+int target_bulk_write_memory(struct target_s *target,
+               u32 address, u32 count, u8 *buffer)
+{
+       return target->type->bulk_write_memory(target, address, count, buffer);
+}
+
+int target_add_breakpoint(struct target_s *target,
+               struct breakpoint_s *breakpoint)
+{
+       return target->type->add_breakpoint(target, breakpoint);
+}
+int target_remove_breakpoint(struct target_s *target,
+               struct breakpoint_s *breakpoint)
+{
+       return target->type->remove_breakpoint(target, breakpoint);
+}
+
+int target_add_watchpoint(struct target_s *target,
+               struct watchpoint_s *watchpoint)
+{
+       return target->type->add_watchpoint(target, watchpoint);
+}
+int target_remove_watchpoint(struct target_s *target,
+               struct watchpoint_s *watchpoint)
+{
+       return target->type->remove_watchpoint(target, watchpoint);
+}
+
+int target_get_gdb_reg_list(struct target_s *target,
+               struct reg_s **reg_list[], int *reg_list_size)
+{
+       return target->type->get_gdb_reg_list(target, reg_list, reg_list_size);
+}
+int target_step(struct target_s *target,
+               int current, u32 address, int handle_breakpoints)
+{
+       return target->type->step(target, current, address, handle_breakpoints);
+}
+
 
 int target_run_algorithm(struct target_s *target,
                int num_mem_params, mem_param_t *mem_params,
@@ -580,7 +638,7 @@ int target_init(struct command_context_s *cmd_ctx)
 
                if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
                {
-                       LOG_ERROR("target '%s' init failed", target->type->name);
+                       LOG_ERROR("target '%s' init failed", target_get_name(target));
                        return retval;
                }
 
@@ -1418,6 +1476,12 @@ static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd,
                        command_print(cmd_ctx,"Target: %s is unknown, try one of:\n", args[0] );
                        goto DumpTargets;
                }
+               if (!target->tap->enabled) {
+                       command_print(cmd_ctx,"Target: TAP %s is disabled, "
+                                       "can't be the current target\n",
+                                       target->tap->dotted_name);
+                       return ERROR_FAIL;
+               }
 
                cmd_ctx->current_target = target->target_number;
                return ERROR_OK;
@@ -1425,19 +1489,32 @@ static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd,
 DumpTargets:
 
        target = all_targets;
-       command_print(cmd_ctx, "    CmdName    Type       Endian     AbsChainPos Name          State     ");
-       command_print(cmd_ctx, "--  ---------- ---------- ---------- ----------- ------------- ----------");
+       command_print(cmd_ctx, "    TargetName         Type       Endian TapName            State       ");
+       command_print(cmd_ctx, "--  ------------------ ---------- ------ ------------------ ------------");
        while (target)
        {
-               /* XX: abcdefghij abcdefghij abcdefghij abcdefghij */
-               command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %10d %14s %s",
+               const char *state;
+               char marker = ' ';
+
+               if (target->tap->enabled)
+                       state = Jim_Nvp_value2name_simple(nvp_target_state,
+                                       target->state)->name;
+               else
+                       state = "tap-disabled";
+
+               if (cmd_ctx->current_target == target->target_number)
+                       marker = '*';
+
+               /* keep columns lined up to match the headers above */
+               command_print(cmd_ctx, "%2d%c %-18s %-10s %-6s %-18s %s",
                                          target->target_number,
+                                         marker,
                                          target->cmd_name,
-                                         target->type->name,
-                                         Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
-                                         target->tap->abs_chain_position,
+                                         target_get_name(target),
+                                         Jim_Nvp_value2name_simple(nvp_target_endian,
+                                                               target->endianness)->name,
                                          target->tap->dotted_name,
-                                         Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name );
+                                         state);
                target = target->next;
        }
 
@@ -1702,9 +1779,11 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
        if (argc == 0)
        {
-               if((retval = target_poll(target)) != ERROR_OK)
+               command_print(cmd_ctx, "background polling: %s",
+                               target_continous_poll ?  "on" : "off");
+               if ((retval = target_poll(target)) != ERROR_OK)
                        return retval;
-               if((retval = target_arch_state(target)) != ERROR_OK)
+               if ((retval = target_arch_state(target)) != ERROR_OK)
                        return retval;
 
        }
@@ -1896,9 +1975,9 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
 
        const char *value_fmt;
        switch (size) {
-       case 4: value_fmt = "%8.8x"; break;
-       case 2: value_fmt = "%4.2x"; break;
-       case 1: value_fmt = "%2.2x"; break;
+       case 4: value_fmt = "%8.8x "; break;
+       case 2: value_fmt = "%4.2x "; break;
+       case 1: value_fmt = "%2.2x "; break;
        default:
                LOG_ERROR("invalid memory read size: %u", size);
                exit(-1);
@@ -1913,7 +1992,7 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
                                        "0x%8.8x: ", address + (i*size));
                }
 
-               u32 value;
+               u32 value=0;
                const u8 *value_ptr = buffer + i * size;
                switch (size) {
                case 4: value = target_buffer_get_u32(target, value_ptr); break;
@@ -3113,7 +3192,7 @@ void target_handle_event( target_t *target, enum target_event e )
                        LOG_DEBUG( "target: (%d) %s (%s) event: %d (%s) action: %s\n",
                                           target->target_number,
                                           target->cmd_name,
-                                          target->type->name,
+                                          target_get_name(target),
                                           e,
                                           Jim_Nvp_value2name_simple( nvp_target_event, e )->name,
                                           Jim_GetString( teap->body, NULL ) );
@@ -3202,7 +3281,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                        return JIM_ERR;
                                }
                        }
-                       Jim_SetResultString( goi->interp, target->type->name, -1 );
+                       Jim_SetResultString( goi->interp, target_get_name(target), -1 );
                        /* loop for more */
                        break;
                case TCFG_EVENT:
@@ -3345,7 +3424,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                        goto no_params;
                                }
                        }
-                       Jim_SetResult( interp, Jim_NewIntObj( goi->interp, target->working_area_size ) );
+                       Jim_SetResult(interp, Jim_NewIntObj(goi->interp, target->backup_working_area));
                        /* loop for more e*/
                        break;
 
@@ -3401,7 +3480,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                if( e != JIM_OK ){
                                        return e;
                                }
-                               tap = jtag_TapByJimObj( goi->interp, o );
+                               tap = jtag_tap_by_jim_obj( goi->interp, o );
                                if( tap == NULL ){
                                        return JIM_ERR;
                                }
@@ -3687,6 +3766,8 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                        Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
                        return JIM_ERR;
                }
+               if (!target->tap->enabled)
+                       goto err_tap_disabled;
                e = target->type->examine( target );
                if( e != ERROR_OK ){
                        Jim_SetResult_sprintf( interp, "examine-fails: %d", e );
@@ -3698,6 +3779,8 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                        Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
                        return JIM_ERR;
                }
+               if (!target->tap->enabled)
+                       goto err_tap_disabled;
                if( !(target_was_examined(target)) ){
                        e = ERROR_TARGET_NOT_EXAMINED;
                } else {
@@ -3725,6 +3808,8 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                if( e != JIM_OK ){
                        return e;
                }
+               if (!target->tap->enabled)
+                       goto err_tap_disabled;
                /* determine if we should halt or not. */
                target->reset_halt = !!a;
                /* When this happens - all workareas are invalid. */
@@ -3742,6 +3827,8 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                        Jim_WrongNumArgs( goi.interp, 0, argv, "halt [no parameters]");
                        return JIM_ERR;
                }
+               if (!target->tap->enabled)
+                       goto err_tap_disabled;
                target->type->halt( target );
                return JIM_OK;
        case TS_CMD_WAITSTATE:
@@ -3759,6 +3846,8 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                if( e != JIM_OK ){
                        return e;
                }
+               if (!target->tap->enabled)
+                       goto err_tap_disabled;
                e = target_wait_state( target, n->value, a );
                if( e != ERROR_OK ){
                        Jim_SetResult_sprintf( goi.interp,
@@ -3814,6 +3903,10 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                return JIM_OK;
        }
        return JIM_ERR;
+
+err_tap_disabled:
+       Jim_SetResult_sprintf(interp, "[TAP is disabled]");
+       return JIM_ERR;
 }
 
 static int target_create( Jim_GetOptInfo *goi )

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)