コード例 #1
0
ファイル: openocd.c プロジェクト: unnamet/estick-jtag
/* normally this is the main() function entry, but if OpenOCD is linked
 * into application, then this fn will not be invoked, but rather that
 * application will have it's own implementation of main(). */
int openocd_main(int argc, char *argv[])
{
	int ret;

	/* initialize commandline interface */
	command_context_t *cmd_ctx;

	cmd_ctx = setup_command_handler();

#if BUILD_IOUTIL
	if (ioutil_init(cmd_ctx) != ERROR_OK)
	{
		return EXIT_FAILURE;
	}
#endif

	LOG_OUTPUT("\n\nBUGS? Read http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS\n\n\n");

	print_version();

	command_context_mode(cmd_ctx, COMMAND_CONFIG);
	command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);

	if (parse_cmdline_args(cmd_ctx, argc, argv) != ERROR_OK)
		return EXIT_FAILURE;

	ret = parse_config_file(cmd_ctx);
	if ( (ret != ERROR_OK) && (ret != ERROR_COMMAND_CLOSE_CONNECTION) )
		return EXIT_FAILURE;

#if BUILD_HTTPD
	if (httpd_start()!=ERROR_OK)
		return EXIT_FAILURE;
#endif

	if (ret != ERROR_COMMAND_CLOSE_CONNECTION)
	{
		command_context_mode(cmd_ctx, COMMAND_EXEC);
		if (command_run_line(cmd_ctx, "init")!=ERROR_OK)
			return EXIT_FAILURE;

		/* handle network connections */
		server_loop(cmd_ctx);
	}

	/* shut server down */
	server_quit();

#if BUILD_HTTPD
	httpd_stop();
#endif

	unregister_all_commands(cmd_ctx);

	/* free commandline interface */
	command_done(cmd_ctx);


	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: openocd.c プロジェクト: EmuxEvans/openocd
/* normally this is the main() function entry, but if OpenOCD is linked
 * into application, then this fn will not be invoked, but rather that
 * application will have it's own implementation of main(). */
int openocd_main(int argc, char *argv[])
{
	int ret;

	/* initialize commandline interface */
	struct command_context *cmd_ctx;

	cmd_ctx = setup_command_handler(NULL);

	if (util_init(cmd_ctx) != ERROR_OK)
		return EXIT_FAILURE;

	if (ioutil_init(cmd_ctx) != ERROR_OK)
		return EXIT_FAILURE;

	LOG_OUTPUT("For bug reports, read\n\t"
		"http://openocd.sourceforge.net/doc/doxygen/bugs.html"
		"\n");

	command_context_mode(cmd_ctx, COMMAND_CONFIG);
	command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);

	/* Start the executable meat that can evolve into thread in future. */
	ret = openocd_thread(argc, argv, cmd_ctx);

	unregister_all_commands(cmd_ctx, NULL);

	/* free commandline interface */
	command_done(cmd_ctx);

	adapter_quit();

	return ret;
}
コード例 #3
0
ファイル: telnet_server.c プロジェクト: IoTToolchain/OpenOCD
static int telnet_new_connection(struct connection *connection)
{
	struct telnet_connection *telnet_connection;
	struct telnet_service *telnet_service = connection->service->priv;
	int i;

	telnet_connection = malloc(sizeof(struct telnet_connection));

	if (!telnet_connection) {
		LOG_ERROR("Failed to allocate telnet connection.");
		return ERROR_FAIL;
	}

	connection->priv = telnet_connection;

	/* initialize telnet connection information */
	telnet_connection->closed = 0;
	telnet_connection->line_size = 0;
	telnet_connection->line_cursor = 0;
	telnet_connection->option_size = 0;
	telnet_connection->prompt = strdup("> ");
	telnet_connection->state = TELNET_STATE_DATA;

	/* output goes through telnet connection */
	command_set_output_handler(connection->cmd_ctx, telnet_output, connection);

	/* negotiate telnet options */
	telnet_write(connection, negotiate, strlen(negotiate));

	/* print connection banner */
	if (telnet_service->banner) {
		telnet_write(connection, telnet_service->banner, strlen(telnet_service->banner));
		telnet_write(connection, "\r\n", 2);
	}

	/* the prompt is always placed at the line beginning */
	telnet_write(connection, "\r", 1);
	telnet_prompt(connection);

	/* initialize history */
	for (i = 0; i < TELNET_LINE_HISTORY_SIZE; i++)
		telnet_connection->history[i] = NULL;
	telnet_connection->next_history = 0;
	telnet_connection->current_history = 0;
	telnet_load_history(telnet_connection);

	log_add_callback(telnet_log_callback, connection);

	return ERROR_OK;
}
コード例 #4
0
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;
}