X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fjtag%2Fjtag.c;h=cd4b255a90ae07ab6e95262a3bbaa098223a3c56;hb=e6f42eaeb64c0bb6447426f454ed0cedd89b484d;hp=8ebd92b109629d9b1a10b37ad2195cebf1a81b30;hpb=b22ae9006ba052f6cafb6c5a3336d342974c0f95;p=fw%2Fopenocd diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index 8ebd92b10..cd4b255a9 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -156,7 +156,11 @@ static int hasKHz = 0; #if BUILD_PARPORT == 1 extern jtag_interface_t parport_interface; #endif - + +#if BUILD_DUMMY == 1 + extern jtag_interface_t dummy_interface; +#endif + #if BUILD_FT2232_FTD2XX == 1 extern jtag_interface_t ft2232_interface; #endif @@ -189,6 +193,10 @@ static int hasKHz = 0; extern jtag_interface_t usbprog_interface; #endif +#if BUILD_JLINK == 1 + extern jtag_interface_t jlink_interface; +#endif + jtag_interface_t *jtag_interfaces[] = { #if BUILD_ECOSBOARD == 1 &eCosBoard_interface, @@ -196,6 +204,9 @@ jtag_interface_t *jtag_interfaces[] = { #if BUILD_PARPORT == 1 &parport_interface, #endif +#if BUILD_DUMMY == 1 + &dummy_interface, +#endif #if BUILD_FT2232_FTD2XX == 1 &ft2232_interface, #endif @@ -219,6 +230,9 @@ jtag_interface_t *jtag_interfaces[] = { #endif #if BUILD_USBPROG == 1 &usbprog_interface, +#endif +#if BUILD_JLINK == 1 + &jlink_interface, #endif NULL, }; @@ -660,8 +674,8 @@ int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields, scan_field_t *fields, void MINIDRIVER(interface_jtag_add_dr_out)(int device_num, int num_fields, - int *num_bits, - u32 *value, + const int *num_bits, + const u32 *value, enum tap_state end_state) { int i; @@ -916,15 +930,15 @@ void jtag_add_reset(int req_tlr_or_trst, int req_srst) */ if ((jtag_reset_config & RESET_HAS_SRST)&& (jtag_reset_config & RESET_HAS_TRST)&& - ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)&& - ((jtag_reset_config & RESET_TRST_PULLS_SRST)==0)) + ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)) { if (((req_tlr_or_trst&&!jtag_trst)|| (!req_tlr_or_trst&&jtag_trst))&& ((req_srst&&!jtag_srst)|| (!req_srst&&jtag_srst))) { - LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined"); + // FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... + //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined"); } } @@ -1246,7 +1260,13 @@ enum scan_type jtag_scan_type(scan_command_t *cmd) int MINIDRIVER(interface_jtag_execute_queue)(void) { int retval; - + + if (jtag==NULL) + { + LOG_ERROR("No JTAG interface configured yet. Issue 'init' command in startup scripts before communicating with targets."); + return ERROR_FAIL; + } + retval = jtag->execute_queue(); cmd_queue_free(); @@ -1482,6 +1502,9 @@ int jtag_register_commands(struct command_context_s *cmd_ctx) int jtag_interface_init(struct command_context_s *cmd_ctx) { + if (jtag) + return ERROR_OK; + if (!jtag_interface) { /* nothing was previously specified by "interface" command */ @@ -1491,10 +1514,8 @@ int jtag_interface_init(struct command_context_s *cmd_ctx) if(hasKHz) { /*stay on "reset speed"*/ - if (jtag_interface->khz(speed1, &speed1) == ERROR_OK) - jtag_speed = speed1; - if (jtag_interface->khz(speed2, &speed2) == ERROR_OK) - jtag_speed_post_reset = speed2; + jtag_interface->khz(speed1, &jtag_speed); + jtag_interface->khz(speed2, &jtag_speed_post_reset); hasKHz = 0; } @@ -1511,12 +1532,10 @@ static int jtag_init_inner(struct command_context_s *cmd_ctx) { int validate_tries = 0; jtag_device_t *device; + int retval; - LOG_DEBUG("-"); + LOG_DEBUG("Init JTAG chain"); - if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK) - return ERROR_JTAG_INIT_FAILED; - device = jtag_devices; jtag_ir_scan_size = 0; jtag_num_devices = 0; @@ -1528,7 +1547,8 @@ static int jtag_init_inner(struct command_context_s *cmd_ctx) } jtag_add_tlr(); - jtag_execute_queue(); + if ((retval=jtag_execute_queue())!=ERROR_OK) + return retval; /* examine chain first, as this could discover the real chain layout */ if (jtag_examine_chain() != ERROR_OK) @@ -1554,6 +1574,10 @@ static int jtag_init_inner(struct command_context_s *cmd_ctx) int jtag_init_reset(struct command_context_s *cmd_ctx) { int retval; + + if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK) + return retval; + LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / tms"); /* Reset can happen after a power cycle. @@ -1594,6 +1618,9 @@ int jtag_init_reset(struct command_context_s *cmd_ctx) int jtag_init(struct command_context_s *cmd_ctx) { + int retval; + if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK) + return retval; if (jtag_init_inner(cmd_ctx)==ERROR_OK) { return ERROR_OK; @@ -1608,6 +1635,11 @@ static int default_khz(int khz, int *jtag_speed) return ERROR_FAIL; } +static int default_speed_div(int speed, int *khz) +{ + return ERROR_FAIL; +} + int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int i; @@ -1638,6 +1670,10 @@ int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char { jtag_interface->khz = default_khz; } + if (jtag_interface->speed_div == NULL) + { + jtag_interface->speed_div = default_speed_div; + } return ERROR_OK; } } @@ -1834,7 +1870,11 @@ int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char /* this command can be called during CONFIG, * in which case jtag isn't initialized */ if (jtag) + { + jtag->speed_div(jtag_speed, &speed1); + jtag->speed_div(jtag_speed_post_reset, &speed2); jtag->speed(cur_speed); + } } command_print(cmd_ctx, "jtag_speed: %d, %d", jtag_speed, jtag_speed_post_reset); @@ -1845,34 +1885,45 @@ int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char * { LOG_DEBUG("handle jtag khz"); - if ((argc<1) || (argc>2)) + if (argc>2) return ERROR_COMMAND_SYNTAX_ERROR; - if (argc >= 1) - speed1 = speed2 = strtoul(args[0], NULL, 0); - if (argc == 2) - speed2 = strtoul(args[1], NULL, 0); - - if (jtag != NULL) + if(argc != 0) { - int cur_speed = 0; - LOG_DEBUG("have interface set up"); - int speed_div1, speed_div2; - if (jtag->khz(speed1, &speed_div1)!=ERROR_OK) - return ERROR_OK; - if (jtag->khz(speed2, &speed_div2)!=ERROR_OK) - return ERROR_OK; - + if (argc >= 1) - cur_speed = jtag_speed = jtag_speed_post_reset = speed_div1; + speed1 = speed2 = strtoul(args[0], NULL, 0); if (argc == 2) - cur_speed = jtag_speed_post_reset = speed_div2; - - jtag->speed(cur_speed); - } else - { - hasKHz = 1; + speed2 = strtoul(args[1], NULL, 0); + + if (jtag != NULL) + { + int cur_speed = 0; + LOG_DEBUG("have interface set up"); + int speed_div1, speed_div2; + if (jtag->khz(speed1, &speed_div1)!=ERROR_OK) + { + speed1 = speed2 = 0; + return ERROR_OK; + } + if (jtag->khz(speed2, &speed_div2)!=ERROR_OK) + { + speed1 = speed2 = 0; + return ERROR_OK; + } + + if (argc >= 1) + cur_speed = jtag_speed = jtag_speed_post_reset = speed_div1; + if (argc == 2) + cur_speed = jtag_speed_post_reset = speed_div2; + + jtag->speed(cur_speed); + } else + { + hasKHz = 1; + } } + command_print(cmd_ctx, "jtag_khz: %d, %d", speed1, speed2); return ERROR_OK; } @@ -1930,7 +1981,7 @@ int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char return ERROR_COMMAND_SYNTAX_ERROR; } - if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK) + if (jtag_interface_init(cmd_ctx) != ERROR_OK) return ERROR_JTAG_INIT_FAILED; jtag_add_reset(trst, srst);