X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=70130d9127d68fe59c7f3267066d410ea5501a22;hb=cfd79e96a6436cea427245a2c2f18fd52001898b;hp=abf8bfd9bbe08427f28927907762315aca293ccb;hpb=e03f3c57a52b36eac18a673fd3515b5ebac3f08d;p=openocd.git diff --git a/src/target/target.c b/src/target/target.c index abf8bfd9bb..70130d9127 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -37,11 +37,11 @@ #include "target_type.h" #include "target_request.h" #include "breakpoints.h" -#include "time_support.h" +#include #include "register.h" #include "trace.h" #include "image.h" -#include "jtag.h" +#include static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, Jim_Obj *const *argv); @@ -90,7 +90,7 @@ struct target *all_targets = NULL; struct target_event_callback *target_event_callbacks = NULL; struct target_timer_callback *target_timer_callbacks = NULL; -const Jim_Nvp nvp_assert[] = { +static const Jim_Nvp nvp_assert[] = { { .name = "assert", NVP_ASSERT }, { .name = "deassert", NVP_DEASSERT }, { .name = "T", NVP_ASSERT }, @@ -100,7 +100,7 @@ const Jim_Nvp nvp_assert[] = { { .name = NULL, .value = -1 } }; -const Jim_Nvp nvp_error_target[] = { +static const Jim_Nvp nvp_error_target[] = { { .value = ERROR_TARGET_INVALID, .name = "err-invalid" }, { .value = ERROR_TARGET_INIT_FAILED, .name = "err-init-failed" }, { .value = ERROR_TARGET_TIMEOUT, .name = "err-timeout" }, @@ -178,7 +178,7 @@ static const Jim_Nvp nvp_target_event[] = { { .name = NULL, .value = -1 } }; -const Jim_Nvp nvp_target_state[] = { +static const Jim_Nvp nvp_target_state[] = { { .name = "unknown", .value = TARGET_UNKNOWN }, { .name = "running", .value = TARGET_RUNNING }, { .name = "halted", .value = TARGET_HALTED }, @@ -187,7 +187,7 @@ const Jim_Nvp nvp_target_state[] = { { .name = NULL, .value = -1 }, }; -const Jim_Nvp nvp_target_debug_reason [] = { +static const Jim_Nvp nvp_target_debug_reason [] = { { .name = "debug-request" , .value = DBG_REASON_DBGRQ }, { .name = "breakpoint" , .value = DBG_REASON_BREAKPOINT }, { .name = "watchpoint" , .value = DBG_REASON_WATCHPOINT }, @@ -198,7 +198,7 @@ const Jim_Nvp nvp_target_debug_reason [] = { { .name = NULL, .value = -1 }, }; -const Jim_Nvp nvp_target_endian[] = { +static const Jim_Nvp nvp_target_endian[] = { { .name = "big", .value = TARGET_BIG_ENDIAN }, { .name = "little", .value = TARGET_LITTLE_ENDIAN }, { .name = "be", .value = TARGET_BIG_ENDIAN }, @@ -206,7 +206,7 @@ const Jim_Nvp nvp_target_endian[] = { { .name = NULL, .value = -1 }, }; -const Jim_Nvp nvp_reset_modes[] = { +static const Jim_Nvp nvp_reset_modes[] = { { .name = "unknown", .value = RESET_UNKNOWN }, { .name = "run" , .value = RESET_RUN }, { .name = "halt" , .value = RESET_HALT }, @@ -214,6 +214,19 @@ const Jim_Nvp nvp_reset_modes[] = { { .name = NULL , .value = -1 }, }; +const char *debug_reason_name(struct target *t) +{ + const char *cp; + + cp = Jim_Nvp_value2name_simple(nvp_target_debug_reason, + t->debug_reason)->name; + if (!cp) { + LOG_ERROR("Invalid debug reason: %d", (int)(t->debug_reason)); + cp = "(*BUG*unknown*BUG*)"; + } + return cp; +} + const char * target_state_name( struct target *t ) { @@ -787,6 +800,23 @@ int target_init(struct command_context *cmd_ctx) return ERROR_OK; } +COMMAND_HANDLER(handle_target_init_command) +{ + if (CMD_ARGC != 0) + return ERROR_COMMAND_SYNTAX_ERROR; + + static bool target_initialized = false; + if (target_initialized) + { + LOG_INFO("'target init' has already been called"); + return ERROR_OK; + } + target_initialized = true; + + LOG_DEBUG("Initializing targets..."); + return target_init(CMD_CTX); +} + int target_register_event_callback(int (*callback)(struct target *target, enum target_event event, void *priv), void *priv) { struct target_event_callback **callbacks_p = &target_event_callbacks; @@ -2124,8 +2154,9 @@ static void handle_md_output(struct command_context *cmd_ctx, case 2: value_fmt = "%4.2x "; break; case 1: value_fmt = "%2.2x "; break; default: + /* "can't happen", caller checked */ LOG_ERROR("invalid memory read size: %u", size); - exit(-1); + return; } for (unsigned i = 0; i < count; i++) @@ -4573,6 +4604,12 @@ static int jim_target_count(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } static const struct command_registration target_subcommand_handlers[] = { + { + .name = "init", + .mode = COMMAND_CONFIG, + .handler = &handle_target_init_command, + .help = "initialize targets", + }, { .name = "create", .mode = COMMAND_ANY,