+ /* if autoprobing, the tap list is still empty ... populate it! */
+ while (autoprobe && bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31) {
+ uint32_t idcode;
+ char buf[12];
+
+ /* Is there another TAP? */
+ idcode = buf_get_u32(idcode_buffer, bit_count, 32);
+ if (jtag_idcode_is_final(idcode))
+ break;
+
+ /* Default everything in this TAP except IR length.
+ *
+ * REVISIT create a jtag_alloc(chip, tap) routine, and
+ * share it with jim_newtap_cmd().
+ */
+ tap = calloc(1, sizeof *tap);
+ if (!tap)
+ return ERROR_FAIL;
+
+ sprintf(buf, "auto%d", tapcount++);
+ tap->chip = strdup(buf);
+ tap->tapname = strdup("tap");
+
+ sprintf(buf, "%s.%s", tap->chip, tap->tapname);
+ tap->dotted_name = strdup(buf);
+
+ /* tap->ir_length == 0 ... signifying irlen autoprobe */
+ tap->ir_capture_mask = 0x03;
+ tap->ir_capture_value = 0x01;
+
+ tap->enabled = true;
+
+ if ((idcode & 1) == 0) {
+ bit_count += 1;
+ tap->hasidcode = false;
+ } else {
+ bit_count += 32;
+ tap->hasidcode = true;
+ tap->idcode = idcode;
+
+ tap->expected_ids_cnt = 1;
+ tap->expected_ids = malloc(sizeof(uint32_t));
+ tap->expected_ids[0] = idcode;
+ }
+
+ LOG_WARNING("AUTO %s - use \"jtag newtap "
+ "%s %s -expected-id 0x%8.8" PRIx32 " ...\"",
+ tap->dotted_name, tap->chip, tap->tapname,
+ tap->idcode);
+
+ jtag_tap_init(tap);
+ }
+
+ /* After those IDCODE or BYPASS register values should be
+ * only the data we fed into the scan chain.
+ */
+ if (jtag_examine_chain_end(idcode_buffer, bit_count,
+ 8 * sizeof(idcode_buffer))) {
+ LOG_ERROR("double-check your JTAG setup (interface, "
+ "speed, missing TAPs, ...)");
+ return ERROR_JTAG_INIT_FAILED;
+ }
+
+ /* Return success or, for backwards compatibility if only
+ * some IDCODE values mismatched, a soft/continuable fault.
+ */
+ return retval;