static int main_2 ( int argc, char * argv[] ) { try { // This application does not output large number of text messages, // and, if logging is turned off, the user should see the log messages straight away. // Therefore, turn off buffering on stdout and stderr. Afterwards, there is no need // to call fflush( stdout/stderr ) any more. if ( 0 != setvbuf( stdout, NULL, _IONBF, 0 ) ) throw std::runtime_error( format_errno_msg( errno, "Cannot turn off buffering on stdout: " ) ); if ( 0 != setvbuf( stderr, NULL, _IONBF, 0 ) ) throw std::runtime_error( format_errno_msg( errno, "Cannot turn off buffering on stderr: " ) ); bsdl_init(); cable_setup(); if ( parse_args( argc, argv ) ) { config_set_trace( trace_jtag_bit_data ); char * server_port_first_err_char; const long int gdb_rsp_server_port = strtol( port, &server_port_first_err_char, 10 ); if ( *server_port_first_err_char ) { throw std::runtime_error( format_msg( "Failed to parse GDB RSP server port from the given parameter \"%s\".", port ) ); // This alternative code issues a warning and takes a default port number: // printf( "Failed to parse GDB RSP server port \'%s\', using default \'%s\'.\n", port, default_port ); // gdb_rsp_server_port = strtol( default_port, &server_port_first_err_char, 10 ); // if ( *server_port_first_err_char ) // throw std::runtime_error( "Error retrieving the TCP port for the GDB RSP server." ); } cable_init(); // Initialize a new connection to the or1k board, and make sure we are really connected. configure_chain(); #ifdef ENABLE_JSP long int jspserverport; jspserverport = strtol(jspport,&s,10); if(*s) { printf("Failed to get JSP server port \'%s\', using default \'%s\'.\n", jspport, default_jspport); serverPort = strtol(default_jspport,&s,10); if(*s) { printf("Failed to get default JSP port, exiting.\n"); return -1; } } jsp_init(jspserverport); jsp_server_start(); #endif printf("The GDB to JTAG bridge is up and running.\n"); // If you update the signal list, please update the help text too. install_signal_handler( SIGINT , exit_signal_handler ); install_signal_handler( SIGHUP , exit_signal_handler ); install_signal_handler( SIGPIPE, ignore_signal_handler ); // Otherwise, writing to a socket may kill us with a SIGPIPE signal. handle_rsp( gdb_rsp_server_port, listen_on_all_addrs ? false : true, trace_rsp ? true : false, trace_jtag_bit_data ? true : false, &s_exit_request ); if ( s_exit_request ) { printf( "Quitting after receiving signal number %d.\n", s_received_signal_number ); } cable_close(); } bsdl_terminate(); return 0; } catch ( ... ) { bsdl_terminate(); throw; } }
static int cmd_cable_run( chain_t *chain, char *params[] ) { cable_t *cable; int i; int paramc = cmd_params( params ); /* we need at least one parameter for 'cable' command */ if (paramc < 2) return -1; /* maybe old syntax was used? search connection type driver */ for (i = 0; parport_drivers[i]; i++) if (strcasecmp( params[1], parport_drivers[i]->type ) == 0) break; if (parport_drivers[i] != 0) { /* Old syntax was used. Swap params. */ printf( _("Note: the 'cable' command syntax changed, please read the help text\n") ); if (paramc >= 4) { char *tmparam; tmparam = params[3]; params[3] = params[2]; params[2] = params[1]; params[1] = tmparam; } else return -1; } /* search cable driver list */ for (i = 0; cable_drivers[i]; i++) if (strcasecmp( params[1], cable_drivers[i]->name ) == 0) break; if (!cable_drivers[i]) { printf( _("Unknown cable type: %s\n"), params[1] ); return 1; } if (paramc >= 3) { if (strcasecmp( params[2], "help" ) == 0) { cable_drivers[i]->help(cable_drivers[i]->name); return 1; } } if (bus) { bus_free( bus ); bus = NULL; } chain_disconnect( chain ); cable = calloc(1, sizeof(cable_t) ); if (!cable) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); return 1; } cable->driver = cable_drivers[i]; if ( cable->driver->connect( ++params, cable ) ) { printf( _("Error: Cable connection failed!\n") ); free( cable ); return 1; } chain->cable = cable; if (cable_init( chain->cable )) { printf( _("Error: Cable initialization failed!\n") ); chain_disconnect( chain ); return 1; } chain_set_trst( chain, 0 ); chain_set_trst( chain, 1 ); tap_reset( chain ); return 1; }