command_context_t *setup_command_handler(void) { command_context_t *cmd_ctx; global_cmd_ctx = cmd_ctx = command_init(); register_command(cmd_ctx, NULL, "version", handle_version_command, COMMAND_EXEC, "show OpenOCD version"); /* register subsystem commands */ server_register_commands(cmd_ctx); telnet_register_commands(cmd_ctx); gdb_register_commands(cmd_ctx); tcl_register_commands(cmd_ctx); /* tcl server commands */ log_register_commands(cmd_ctx); jtag_register_commands(cmd_ctx); xsvf_register_commands(cmd_ctx); svf_register_commands(cmd_ctx); target_register_commands(cmd_ctx); flash_register_commands(cmd_ctx); nand_register_commands(cmd_ctx); pld_register_commands(cmd_ctx); mflash_register_commands(cmd_ctx); if (log_init(cmd_ctx) != ERROR_OK) { exit(-1); } LOG_DEBUG("log init complete"); LOG_OUTPUT( OPENOCD_VERSION "\n" ); register_command(cmd_ctx, NULL, "init", handle_init_command, COMMAND_ANY, "initializes target and servers - nop on subsequent invocations"); return cmd_ctx; }
static int romloader_openocd_connect(command_context_t **pptCmdCtx) { int iResult; command_context_t *cmd_ctx; target_t *target; wxString strCmd; wxString strMsg; size_t sizCfgCnt; size_t sizCfgMax; int iInitCnt; cmd_ctx = command_init(); /* register subsystem commands */ log_register_commands(cmd_ctx); jtag_register_commands(cmd_ctx); interpreter_register_commands(cmd_ctx); xsvf_register_commands(cmd_ctx); target_register_commands(cmd_ctx); /* init the log functions */ iResult = log_init(cmd_ctx); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to init log level: %d"), iResult); wxLogError(strMsg); } else { command_set_output_handler(cmd_ctx, romloader_openocd_default_output_handler, NULL); log_set_output_handler(romloader_openocd_log_printf, romloader_openocd_short_log_printf); cmd_ctx->mode = COMMAND_CONFIG; // set config sizCfgCnt = 0; sizCfgMax = astrInitCfg.GetCount(); while( sizCfgCnt<sizCfgMax ) { strCmd = astrInitCfg.Item(sizCfgCnt); wxLogMessage(wxT("command: ") + strCmd); iResult = command_run_line(cmd_ctx, strCmd.ToAscii()); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to set config: %d"), iResult); wxLogError(strMsg); strMsg = wxT("error line was: '") + strCmd + wxT("'"); wxLogError(strMsg); break; } ++sizCfgCnt; } if( iResult==ERROR_OK ) { cmd_ctx->mode = COMMAND_EXEC; iResult = jtag_init(cmd_ctx); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to init jtag: %d"), iResult); wxLogError(strMsg); } else { iResult = target_init(cmd_ctx); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to init jtag: %d"), iResult); wxLogError(strMsg); } else { wxMilliSleep(500); /* wait for target reset */ iInitCnt = 10; do { target_call_timer_callbacks(); wxMilliSleep(100); } while( --iInitCnt>0 ); target = get_current_target(cmd_ctx); if( target->state!=TARGET_HALTED ) { wxLogError(wxT("failed to halt the target")); iResult = ERROR_TARGET_NOT_HALTED; } else { // set config sizCfgCnt = 0; sizCfgMax = astrRunCfg.GetCount(); while( sizCfgCnt<sizCfgMax ) { strCmd = astrRunCfg.Item(sizCfgCnt); wxLogMessage(wxT("command: ") + strCmd); iResult = command_run_line(cmd_ctx, strCmd.ToAscii()); if( iResult!=ERROR_OK ) { strMsg.Printf(wxT("failed to run command: %d"), iResult); wxLogError(strMsg); strMsg = wxT("error line was: '") + strCmd + wxT("'"); wxLogError(strMsg); break; } ++sizCfgCnt; } if( iResult!=ERROR_OK ) { wxLogError(wxT("config failed!")); } } } } } } if( iResult!=ERROR_OK ) { // close connection romloader_openocd_close_instance(cmd_ctx); *pptCmdCtx = NULL; } else { // connection open, ok! *pptCmdCtx = cmd_ctx; } return iResult; }