X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=7763b95644d65d3dfce0d86e39e65e43dbde5112;hp=56e124f75f1785b42135469592010ccc52c69221;hb=6a2fd7cad507ef24a7dc4ce3c5f8b5351dd12656;hpb=3bade442b1f8c41895fba6428a850b20b7dd75c1 diff --git a/src/target/target.c b/src/target/target.c index 56e124f75f..7763b95644 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2,7 +2,7 @@ * Copyright (C) 2005 by Dominic Rath * * Dominic.Rath@gmx.de * * * - * Copyright (C) 2007,2008 Øyvind Harboe * + * Copyright (C) 2007-2009 Øyvind Harboe * * oyvind.harboe@zylin.com * * * * Copyright (C) 2008, Duane Ellis * @@ -84,6 +84,7 @@ extern target_type_t arm966e_target; extern target_type_t arm926ejs_target; extern target_type_t fa526_target; extern target_type_t feroceon_target; +extern target_type_t dragonite_target; extern target_type_t xscale_target; extern target_type_t cortexm3_target; extern target_type_t cortexa8_target; @@ -101,6 +102,7 @@ target_type_t *target_types[] = &arm926ejs_target, &fa526_target, &feroceon_target, + &dragonite_target, &xscale_target, &cortexm3_target, &cortexa8_target, @@ -155,7 +157,7 @@ static const Jim_Nvp nvp_target_event[] = { { .value = TARGET_EVENT_OLD_gdb_program_config , .name = "old-gdb_program_config" }, { .value = TARGET_EVENT_OLD_pre_resume , .name = "old-pre_resume" }, - { .value = TARGET_EVENT_EARLY_HALTED, .name = "early-halted" }, + { .value = TARGET_EVENT_GDB_HALT, .name = "gdb-halt" }, { .value = TARGET_EVENT_HALTED, .name = "halted" }, { .value = TARGET_EVENT_RESUMED, .name = "resumed" }, { .value = TARGET_EVENT_RESUME_START, .name = "resume-start" }, @@ -267,8 +269,6 @@ static int new_target_number(void) return x + 1; } -static int target_continuous_poll = 1; - /* read a uint32_t from a buffer in target memory endianness */ uint32_t target_buffer_get_u32(target_t *target, const uint8_t *buffer) { @@ -378,24 +378,57 @@ target_t* get_current_target(command_context_t *cmd_ctx) int target_poll(struct target_s *target) { + int retval; + /* We can't poll until after examine */ if (!target_was_examined(target)) { /* Fail silently lest we pollute the log */ return ERROR_FAIL; } - return target->type->poll(target); + + retval = target->type->poll(target); + if (retval != ERROR_OK) + return retval; + + if (target->halt_issued) + { + if (target->state == TARGET_HALTED) + { + target->halt_issued = false; + } else + { + long long t = timeval_ms() - target->halt_issued_time; + if (t>1000) + { + target->halt_issued = false; + LOG_INFO("Halt timed out, wake up GDB."); + target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); + } + } + } + + return ERROR_OK; } int target_halt(struct target_s *target) { + int retval; /* We can't poll until after examine */ if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); return ERROR_FAIL; } - return target->type->halt(target); + + retval = target->type->halt(target); + if (retval != ERROR_OK) + return retval; + + target->halt_issued = true; + target->halt_issued_time = timeval_ms(); + + return ERROR_OK; } int target_resume(struct target_s *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) @@ -434,13 +467,14 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo * 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_continuous_poll; - target_continuous_poll = 0; + bool save_poll = jtag_poll_get_enabled(); + + jtag_poll_set_enabled(false); sprintf(buf, "ocd_process_reset %s", n->name); retval = Jim_Eval(interp, buf); - target_continuous_poll = save_poll; + jtag_poll_set_enabled(save_poll); if (retval != JIM_OK) { Jim_PrintErrorMessage(interp); @@ -664,7 +698,6 @@ int target_init(struct command_context_s *cmd_ctx) { target->type->virt2phys = default_virt2phys; } - target->type->virt2phys = default_virt2phys; /* a non-invasive way(in terms of patches) to add some code that * runs before the type->write/read_memory implementation */ @@ -819,7 +852,7 @@ int target_call_event_callbacks(target_t *target, enum target_event event) if (event == TARGET_EVENT_HALTED) { /* execute early halted first */ - target_call_event_callbacks(target, TARGET_EVENT_EARLY_HALTED); + target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); } LOG_DEBUG("target event %i (%s)", @@ -1239,7 +1272,7 @@ int target_read_buffer(struct target_s *target, uint32_t address, uint32_t size, address += aligned; size -= aligned; } - + /*prevent byte access when possible (avoid AHB access limitations in some cases)*/ if(size >=2) { @@ -1656,6 +1689,15 @@ static int sense_handler(void) return ERROR_OK; } +static void target_call_event_callbacks_all(enum target_event e) { + target_t *target; + target = all_targets; + while (target) { + target_call_event_callbacks(target, e); + target = target->next; + } +} + /* process target state changes */ int handle_target(void *priv) { @@ -1674,6 +1716,7 @@ int handle_target(void *priv) int did_something = 0; if (runSrstAsserted) { + target_call_event_callbacks_all(TARGET_EVENT_GDB_HALT); Jim_Eval(interp, "srst_asserted"); did_something = 1; } @@ -1684,6 +1727,7 @@ int handle_target(void *priv) } if (runPowerDropout) { + target_call_event_callbacks_all(TARGET_EVENT_GDB_HALT); Jim_Eval(interp, "power_dropout"); did_something = 1; } @@ -1713,7 +1757,7 @@ int handle_target(void *priv) * Skip targets that are currently disabled. */ for (target_t *target = all_targets; - target_continuous_poll && target; + is_jtag_poll_safe() && target; target = target->next) { if (!target->tap->enabled) @@ -1724,7 +1768,10 @@ int handle_target(void *priv) { /* polling may fail silently until the target has been examined */ if ((retval = target_poll(target)) != ERROR_OK) + { + target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); return retval; + } } } @@ -1870,7 +1917,7 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha if (argc == 0) { command_print(cmd_ctx, "background polling: %s", - target_continuous_poll ? "on" : "off"); + jtag_poll_get_enabled() ? "on" : "off"); command_print(cmd_ctx, "TAP: %s (%s)", target->tap->dotted_name, target->tap->enabled ? "enabled" : "disabled"); @@ -1886,11 +1933,11 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha { if (strcmp(args[0], "on") == 0) { - target_continuous_poll = 1; + jtag_poll_set_enabled(true); } else if (strcmp(args[0], "off") == 0) { - target_continuous_poll = 0; + jtag_poll_set_enabled(false); } else { @@ -2334,7 +2381,7 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm break; } image_size += length; - command_print(cmd_ctx, "%u byte written at address 0x%8.8" PRIx32 "", + command_print(cmd_ctx, "%u bytes written at address 0x%8.8" PRIx32 "", (unsigned int)length, image.sections[i].base_address + offset); } @@ -3404,17 +3451,16 @@ void target_all_handle_event(enum target_event e) } } + +/* FIX? should we propagate errors here rather than printing them + * and continuing? + */ void target_handle_event(target_t *target, enum target_event e) { target_event_action_t *teap; - int done; - - teap = target->event_action; - done = 0; - while (teap) { + for (teap = target->event_action; teap != NULL; teap = teap->next) { if (teap->event == e) { - done = 1; LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s", target->target_number, target->cmd_name, @@ -3427,12 +3473,6 @@ void target_handle_event(target_t *target, enum target_event e) Jim_PrintErrorMessage(interp); } } - teap = teap->next; - } - if (!done) { - LOG_DEBUG("event: %d %s - no action", - e, - Jim_Nvp_value2name_simple(nvp_target_event, e)->name); } } @@ -3547,9 +3587,11 @@ static int target_configure(Jim_GetOptInfo *goi, target_t *target) } if (goi->isconfigure) { + bool replace = true; if (teap == NULL) { /* create new */ teap = calloc(1, sizeof(*teap)); + replace = false; } teap->event = n->value; Jim_GetOpt_Obj(goi, &o); @@ -3569,9 +3611,12 @@ static int target_configure(Jim_GetOptInfo *goi, target_t *target) */ Jim_IncrRefCount(teap->body); - /* add to head of event list */ - teap->next = target->event_action; - target->event_action = teap; + if (!replace) + { + /* add to head of event list */ + teap->next = target->event_action; + target->event_action = teap; + } Jim_SetEmptyResult(goi->interp); } else { /* get */ @@ -4021,7 +4066,8 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv) break; case TS_CMD_RESET: if (goi.argc != 2) { - Jim_WrongNumArgs(interp, 2, argv, "t | f|assert | deassert BOOL"); + Jim_WrongNumArgs(interp, 2, argv, + "([tT]|[fF]|assert|deassert) BOOL"); return JIM_ERR; } e = Jim_GetOpt_Nvp(&goi, nvp_assert, &n); @@ -4050,11 +4096,11 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv) /* do the assert */ if (n->value == NVP_ASSERT) { - target->type->assert_reset(target); + e = target->type->assert_reset(target); } else { - target->type->deassert_reset(target); + e = target->type->deassert_reset(target); } - return JIM_OK; + return (e == ERROR_OK) ? JIM_OK : JIM_ERR; case TS_CMD_HALT: if (goi.argc) { Jim_WrongNumArgs(goi.interp, 0, argv, "halt [no parameters]"); @@ -4062,8 +4108,8 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } if (!target->tap->enabled) goto err_tap_disabled; - target->type->halt(target); - return JIM_OK; + e = target->type->halt(target); + return (e == ERROR_OK) ? JIM_OK : JIM_ERR; case TS_CMD_WAITSTATE: /* params: statename timeoutmsecs */ if (goi.argc != 2) { @@ -4226,6 +4272,8 @@ static int target_create(Jim_GetOptInfo *goi) target->display = 1; + target->halt_issued = false; + /* initialize trace information */ target->trace_info = malloc(sizeof(trace_t)); target->trace_info->num_trace_points = 0; @@ -4532,7 +4580,7 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha fastload[i].length = length; image_size += length; - command_print(cmd_ctx, "%u byte written at address 0x%8.8x", + command_print(cmd_ctx, "%u bytes written at address 0x%8.8x", (unsigned int)length, ((unsigned int)(image.sections[i].base_address + offset))); }