X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fjtag.c;h=8bc19112ca5ee41e7d11dd8178dd9dfe9ca52404;hb=f84c78a2e1994ef8efcdd8768dc2a6b0ee363189;hp=0bc1c4ffbe3dafad2befcb3b45d3ee341f3ec1c0;hpb=d8421f276689ee48cb190921119ecca10559a136;p=openocd.git diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index 0bc1c4ffbe..8bc19112ca 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -97,8 +97,9 @@ static bool hasKHz = false; #if BUILD_ECOSBOARD == 1 extern jtag_interface_t zy1000_interface; -#endif - +#elif defined(BUILD_MINIDRIVER_DUMMY) + extern jtag_interface_t minidummy_interface; +#else // standard drivers #if BUILD_PARPORT == 1 extern jtag_interface_t parport_interface; #endif @@ -154,11 +155,21 @@ static bool hasKHz = false; #if BUILD_ARMJTAGEW == 1 extern jtag_interface_t armjtagew_interface; #endif +#endif // standard drivers +/** + * The list of built-in JTAG interfaces, containing entries for those + * drivers that were enabled by the @c configure script. + * + * The list should be defined to contain either one minidriver interface + * or some number of standard driver interfaces, never both. + */ jtag_interface_t *jtag_interfaces[] = { #if BUILD_ECOSBOARD == 1 &zy1000_interface, -#endif +#elif defined(BUILD_MINIDRIVER_DUMMY) + &minidummy_interface, +#else // standard drivers #if BUILD_PARPORT == 1 &parport_interface, #endif @@ -201,6 +212,7 @@ jtag_interface_t *jtag_interfaces[] = { #if BUILD_ARMJTAGEW == 1 &armjtagew_interface, #endif +#endif // standard drivers NULL, }; @@ -221,7 +233,6 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, ch static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); @@ -242,10 +253,10 @@ int jtag_tap_count(void) return jtag_num_taps; } -int jtag_tap_count_enabled(void) +unsigned jtag_tap_count_enabled(void) { jtag_tap_t *t; - int n; + unsigned n; n = 0; t = jtag_all_taps(); @@ -995,6 +1006,11 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg, EXTRACT_MFG(idcode), EXTRACT_PART(idcode), EXTRACT_VER(idcode) ); } +static bool jtag_idcode_is_final(u32 idcode) +{ + return idcode == 0x000000FF || idcode == 0xFFFFFFFF; +} + /** * This helper checks that remaining bits in the examined chain data are * all as expected, but a single JTAG device requires only 64 bits to be @@ -1008,7 +1024,7 @@ static void jtag_examine_chain_end(u8 *idcodes, unsigned count, unsigned max) { u32 idcode = buf_get_u32(idcodes, count, 32); // do not trigger the warning if the data looks good - if (!triggered && (idcode == 0x000000FF || idcode == 0xFFFFFFFF)) + if (!triggered && jtag_idcode_is_final(idcode)) continue; LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x", count, idcode); @@ -1016,14 +1032,51 @@ static void jtag_examine_chain_end(u8 *idcodes, unsigned count, unsigned max) } } +static bool jtag_examine_chain_match_tap(const struct jtag_tap_s *tap) +{ + if (0 == tap->expected_ids_cnt) + { + /// @todo Enable LOG_INFO to ask for reports about unknown TAP IDs. +#if 0 + LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap->idcode) + LOG_INFO("Please report the chip name and reported ID code to the openocd project"); +#endif + return true; + } + + /* Loop over the expected identification codes and test for a match */ + u8 ii; + for (ii = 0; ii < tap->expected_ids_cnt; ii++) + { + if (tap->idcode == tap->expected_ids[ii]) + break; + } + + /* If none of the expected ids matched, log an error */ + if (ii != tap->expected_ids_cnt) + { + LOG_INFO("JTAG Tap/device matched"); + return true; + } + jtag_examine_chain_display(LOG_LVL_ERROR, "got", + tap->dotted_name, tap->idcode); + for (ii = 0; ii < tap->expected_ids_cnt; ii++) + { + char msg[32]; + snprintf(msg, sizeof(msg), "expected %hhu of %hhu", + ii + 1, tap->expected_ids_cnt); + jtag_examine_chain_display(LOG_LVL_ERROR, msg, + tap->dotted_name, tap->expected_ids[ii]); + } + return false; +} + /* Try to examine chain layout according to IEEE 1149.1 §12 */ static int jtag_examine_chain(void) { - jtag_tap_t *tap; u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4]; - int bit_count; - int device_count = 0; + unsigned device_count = 0; jtag_examine_chain_execute(idcode_buffer, JTAG_MAX_CHAIN_SIZE); @@ -1031,20 +1084,21 @@ static int jtag_examine_chain(void) return ERROR_JTAG_INIT_FAILED; /* point at the 1st tap */ - tap = jtag_tap_next_enabled(NULL); - if( tap == NULL ){ + jtag_tap_t *tap = jtag_tap_next_enabled(NULL); + if (tap == NULL) + { LOG_ERROR("JTAG: No taps enabled?"); return ERROR_JTAG_INIT_FAILED; } - for (bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;) + for (unsigned bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;) { u32 idcode = buf_get_u32(idcode_buffer, bit_count, 32); if ((idcode & 1) == 0) { /* LSB must not be 0, this indicates a device in bypass */ LOG_WARNING("Tap/Device does not have IDCODE"); - idcode=0; + idcode = 0; bit_count += 1; } @@ -1055,7 +1109,7 @@ static int jtag_examine_chain(void) * as AVR will output all 1's instead of TDI input value at * end of chain. */ - if ((idcode == 0x000000FF)||(idcode == 0xFFFFFFFF)) + if (jtag_idcode_is_final(idcode)) { jtag_examine_chain_end(idcode_buffer, bit_count + 32, JTAG_MAX_CHAIN_SIZE * 32); @@ -1074,49 +1128,21 @@ static int jtag_examine_chain(void) tap->idcode = idcode; - if (0 == tap->expected_ids_cnt) - { - // @todo Enable LOG_INFO to ask for reports about unknown TAP IDs. -#if 0 - LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap->idcode) - LOG_INFO("Please report the chip name and reported ID code to the openocd project"); -#endif - tap = jtag_tap_next_enabled(tap); - continue; - } - /* Loop over the expected identification codes and test for a match */ - u8 ii; - for (ii = 0; ii < tap->expected_ids_cnt; ii++) { - if (tap->idcode == tap->expected_ids[ii]) { - break; - } - } + // ensure the TAP ID does matches what was expected + if (!jtag_examine_chain_match_tap(tap)) + return ERROR_JTAG_INIT_FAILED; - /* If none of the expected ids matched, log an error */ - if (ii != tap->expected_ids_cnt) - { - LOG_INFO("JTAG Tap/device matched"); - tap = jtag_tap_next_enabled(tap); - continue; - } - jtag_examine_chain_display(LOG_LVL_ERROR, "got", - tap->dotted_name, tap->idcode); - for (ii = 0; ii < tap->expected_ids_cnt; ii++) { - char msg[20]; - snprintf(msg, 20, "expected %hhu of %hhu", - ii + 1, tap->expected_ids_cnt); - jtag_examine_chain_display(LOG_LVL_ERROR, msg, - tap->dotted_name, tap->expected_ids[ii]); - } - return ERROR_JTAG_INIT_FAILED; + tap = jtag_tap_next_enabled(tap); } /* see if number of discovered devices matches configuration */ if (device_count != jtag_tap_count_enabled()) { - LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d", - device_count, jtag_tap_count_enabled(), jtag_tap_count()); - LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)"); + LOG_ERROR("number of discovered devices in JTAG chain (%i) " + "does not match (enabled) configuration (%i), total taps: %d", + device_count, jtag_tap_count_enabled(), jtag_tap_count()); + LOG_ERROR("check the config file and ensure proper JTAG communication" + " (connections, speed, ...)"); return ERROR_JTAG_INIT_FAILED; } @@ -1638,8 +1664,6 @@ int jtag_register_commands(struct command_context_s *cmd_ctx) register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command, COMMAND_EXEC, "print current scan chain configuration"); - register_command(cmd_ctx, NULL, "endstate", handle_endstate_command, - COMMAND_EXEC, "finish JTAG operations in "); register_command(cmd_ctx, NULL, "jtag_reset", handle_jtag_reset_command, COMMAND_EXEC, "toggle reset lines "); register_command(cmd_ctx, NULL, "runtest", handle_runtest_command, @@ -2118,7 +2142,6 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, ch return ERROR_OK; } - static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int retval=ERROR_OK; @@ -2195,26 +2218,6 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, } -static int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) -{ - if (argc < 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - tap_state_t state = tap_state_by_name(args[0]); - if (state < 0) - { - command_print( cmd_ctx, "Invalid state name: %s\n", args[0] ); - return ERROR_COMMAND_SYNTAX_ERROR; - } - jtag_set_end_state(state); - jtag_execute_queue(); - - command_print(cmd_ctx, "current endstate: %s", - tap_state_name(cmd_queue_end_state)); - - return ERROR_OK; -} - static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { int trst = -1;