Exemple #1
0
static int
cmd_part_run( char *params[] )
{
	unsigned int n;

	if (cmd_params( params ) != 2)
		return -1;

	if (!cmd_test_cable())
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (cmd_get_number( params[1], &n ))
		return -1;

	if (n >= chain->parts->len) {
		printf( _("%s: invalid part number\n"), "part" );
		return 1;
	}

	chain->active_part = n;

	return 1;
}
Exemple #2
0
static int
cmd_detect_run( char *params[] )
{
	if (cmd_params( params ) != 1)
		return -1;

	if (!cmd_test_cable())
		return 1;

	buses_free();
	parts_free( chain->parts );
	chain->parts = NULL;
	detect_parts( chain, JTAG_DATA_DIR );
	if (!chain->parts)
		return 1;
	if (!chain->parts->len) {
		parts_free( chain->parts );
		chain->parts = NULL;
		return 1;
	}
	parts_set_instruction( chain->parts, "SAMPLE/PRELOAD" );
	chain_shift_instructions( chain );
	chain_shift_data_registers( chain, 1 );
	parts_set_instruction( chain->parts, "BYPASS" );
	chain_shift_instructions( chain );

	return 1;
}
Exemple #3
0
static int
cmd_bus_run( chain_t *chain, char *params[] )
{
	unsigned int n;

	if (cmd_params( params ) != 2)
		return -1;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (cmd_get_number( params[1], &n ))
		return -1;

	if (n >= buses.len) {
		printf( _("%s: invalid bus number\n"), "bus" );
		return 1;
	}

	bus = buses.buses[n];

	return 1;
}
Exemple #4
0
static int
cmd_initbus_run( chain_t *chain, char *params[] )
{
	int i;

	if (cmd_params( params ) < 2)
		return -1;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len || chain->active_part < 0) {
		printf( _("%s: no active part\n"), "initbus" );
		return 1;
	}

	for (i = 0; bus_drivers[i] != NULL; i++) {
		if (strcasecmp( bus_drivers[i]->name, params[1] ) == 0) {
			bus_t *abus = bus_drivers[i]->new_bus( chain, bus_drivers[i], params );
			if (abus == NULL) {
				printf( _("bus alloc/attach failed!\n") );
				return 1;
			}
			buses_add( abus );
			if (bus_init( abus ) != URJTAG_STATUS_OK)
				printf( _("bus initialization failed!\n") );

			for (i = 0; i < buses.len; i++)
				if (buses.buses[i] == bus)
					break;
			if (i != buses.len - 1)
				printf( _("Initialized bus %d, active bus %d\n"), buses.len - 1, i );

			return 1;
		}
	}

	printf( _("Unknown bus: %s\n"), params[1] );

	return 1;
}
Exemple #5
0
static int
cmd_salias_run( chain_t *chain, char *params[] )
{
	part_t *part;
	signal_t *s;
	salias_t *sa;

	if (cmd_params( params ) != 3)
		return -1;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len) {
		printf( _("%s: no active part\n"), "signal" );
		return 1;
	}

	part = chain->parts->parts[chain->active_part];
	if (part_find_signal( part, params[1] ) != NULL) {
		printf( _("Signal '%s' already defined\n"), params[1] );
		return 1;
	}

	s = part_find_signal( part, params[2] );
	if (s == NULL) {
		printf( _("Signal '%s' not found\n"), params[2] );
		return 1;
	}

	sa = salias_alloc( params[1], s );
	if (!sa) {
		printf( _("out of memory\n") );
		return 1;
	}

	sa->next = part->saliases;
	part->saliases = sa;

	return 1;
}
Exemple #6
0
static int
cmd_shift_run( char *params[] )
{
	if (cmd_params( params ) != 2)
		return -1;

	if (!cmd_test_cable())
		return 1;

	if (strcmp( params[1], "ir" ) == 0) {
		chain_shift_instructions( chain );
		return 1;
	}
	if (strcmp( params[1], "dr" ) == 0) {
		chain_shift_data_registers( chain, 1 );
		return 1;
	}

	return -1;
}
Exemple #7
0
static int
cmd_eraseflash_run( chain_t *chain, char *params[] )
{
	uint32_t adr = 0;
	unsigned int number = 0;

	if (cmd_params( params ) != 3)
		return -1;
	if (!cmd_test_cable( chain ))
		return 1;
	if (!bus) {
		printf( _("Error: Bus driver missing.\n") );
		return 1;
	}
	if (cmd_get_number( params[1], &adr ))
		return -1;
	if (cmd_get_number( params[2], &number ))
		return -1;
	flasherase( bus, adr, number );

	return 1;
}
Exemple #8
0
static int
cmd_get_run( char *params[] )
{
	int data;
	signal_t *s;

	if (cmd_params( params ) != 3)
		return -1;

	if (strcmp( params[1], "signal") != 0)
		return -1;

	if (!cmd_test_cable())
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len) {
		printf( _("%s: no active part\n"), "get" );
		return 1;
	}

	s = part_find_signal( chain->parts->parts[chain->active_part], params[2] );
	if (!s) {
		printf( _("signal '%s' not found\n"), params[2] );
		return 1;
	}
	data = part_get_signal( chain->parts->parts[chain->active_part], s );
	if (data != -1)
		printf( _("%s = %d\n"), params[2], data );

	return 1;
}
Exemple #9
0
static int
cmd_print_run( chain_t *chain, char *params[] )
{
	char format[128];
#if HAVE_SWPRINTF
	wchar_t wformat[128];
#endif /* HAVE_SWPRINTF */
	wchar_t wheader[128];
	char header[128];
	int i;
	int noheader = 0;

	if (cmd_params( params ) > 2)
		return -1;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (cmd_params( params ) == 2) {
		if (strcasecmp( params[1], "bus") == 0)
			noheader = 1;

		if (strcasecmp( params[1], "signals") == 0) {

			printf("Signals:\n");
			part_t *part;
			signal_t *s;
			part = chain->parts->parts[chain->active_part];
			for(s = part->signals;s != NULL;s = s->next) {
				salias_t *sa;
				if(s->pin)printf("%s %s",s->name,s->pin);
					else printf("%s",s->name);
				if(s->input)printf("\tinput=%s",s->input->name);
				if(s->output)printf("\toutput=%s",s->output->name);

				for (sa = part->saliases; sa != NULL; sa = sa->next) {
					if (s == sa->signal)printf("\tsalias=%s",sa->name);
				}
				printf("\n");
			}
			return(1);
		}

		if (strcasecmp( params[1], "instructions") == 0) {
			part_t *part;
			instruction *inst;

			snprintf( format, 128, _(" Active %%-%ds %%-%ds"),
				MAXLEN_INSTRUCTION, MAXLEN_DATA_REGISTER );
#if HAVE_SWPRINTF
			if (mbstowcs( wformat, format, 128 ) == -1)
				printf( _("(%d) String conversion failed!\n"), __LINE__ );
			swprintf( wheader, 128, wformat, _("Instruction"), _("Register") );
			if (wcstombs( header, wheader, 128 ) == -1)
				printf( _("(%d) String conversion failed!\n"), __LINE__ );
#else /* HAVE_SWPRINTF */
			snprintf( header, 128, format, _("Instruction"), _("Register") );
			if (mbstowcs( wheader, header, 128 ) == -1)
				printf( _("(%d) String conversion failed!\n"), __LINE__ );
#endif /* HAVE_SWPRINTF */
			puts( header );

			for (i = 0; i < wcslen( wheader ); i++ )
				putchar( '-' );
			putchar( '\n' );

			snprintf( format, 128, _("   %%c    %%-%ds %%-%ds\n"),
				MAXLEN_INSTRUCTION, MAXLEN_DATA_REGISTER );

			part = chain->parts->parts[chain->active_part];
			for (inst = part->instructions; inst != NULL; inst = inst->next) {
				printf( format,
					inst == part->active_instruction
					? 'X'
					: ' ',
					inst->name, inst->data_register->name);
			}
			return(1);
		}
	}

	if (noheader == 0) {
		snprintf( format, 128, _(" No. %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds"), MAXLEN_MANUFACTURER, MAXLEN_PART, MAXLEN_STEPPING,
				MAXLEN_INSTRUCTION, MAXLEN_DATA_REGISTER );
#if HAVE_SWPRINTF
		if (mbstowcs( wformat, format, 128 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
		swprintf( wheader, 128, wformat, _("Manufacturer"), _("Part"), _("Stepping"), _("Instruction"), _("Register") );
		if (wcstombs( header, wheader, 128 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
#else /* HAVE_SWPRINTF */
		snprintf( header, 128, format, _("Manufacturer"), _("Part"), _("Stepping"), _("Instruction"), _("Register") );
		if (mbstowcs( wheader, header, 128 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
#endif /* HAVE_SWPRINTF */
		puts( header );

		for (i = 0; i < wcslen( wheader ); i++ )
			putchar( '-' );
		putchar( '\n' );
	}

	if (cmd_params( params ) == 1) {
		if (chain->parts->len > chain->active_part) {
			if(chain->parts->parts[chain->active_part]->alias)
				printf( _(" %3d %s "), chain->active_part,chain->parts->parts[chain->active_part]->alias );
			else
				printf( _(" %3d "), chain->active_part);

			part_print( chain->parts->parts[chain->active_part] );
		}
		if (bus != NULL) {
			int i;
			uint64_t a;
			bus_area_t area;

			for (i = 0; i < buses.len; i++)
				if (buses.buses[i] == bus)
					break;
			printf( _("\nActive bus:\n*%d: "), i );
			bus_printinfo( bus );

			for (a = 0; a < UINT64_C(0x100000000); a = area.start + area.length) {
				if (bus_area( bus, a, &area ) != URJTAG_STATUS_OK) {
					printf( _("Error in bus area discovery at 0x%08llX\n"), (long long unsigned int)a );
					break;
				}
				if (area.width != 0) {
					if (area.description != NULL)
						printf( _("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit, (%s)\n"), area.start,  (long long unsigned int)area.length, area.width, _(area.description) );
					else
						printf( _("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit\n"), area.start, (long long unsigned int)area.length, area.width );
				}
			}
		}

		return 1;
	}

	if (strcasecmp( params[1], "chain" ) == 0) {
		parts_print( chain->parts );
		return 1;
	}

	for (i = 0; i < buses.len; i++) {
		if (buses.buses[i] == bus)
			printf( _("*%d: "), i );
		else
			printf( _("%d: "), i );
		bus_printinfo( buses.buses[i] );
	}

	return 1;
}
Exemple #10
0
static int
cmd_print_run( char *params[] )
{
	char format[100];
#if HAVE_SWPRINTF
	wchar_t wformat[100];
#endif /* HAVE_SWPRINTF */
	wchar_t wheader[100];
	char header[100];
	int i;
	int noheader = 0;

	if (cmd_params( params ) > 2)
		return -1;

	if (!cmd_test_cable())
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (cmd_params( params ) == 2) {
		if ((strcmp( params[1], "chain" ) != 0) && (strcmp( params[1], "bus") != 0))
			return -1;
		if (strcmp( params[1], "bus") == 0)
			noheader = 1;
	}

	if (noheader == 0) {
		snprintf( format, 100, _(" No. %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds\n"), MAXLEN_MANUFACTURER, MAXLEN_PART, MAXLEN_STEPPING,
				MAXLEN_INSTRUCTION, MAXLEN_DATA_REGISTER );
#if HAVE_SWPRINTF
		if (mbstowcs( wformat, format, 100 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
		swprintf( wheader, 100, wformat, _("Manufacturer"), _("Part"), _("Stepping"), _("Instruction"), _("Register") );
		if (wcstombs( header, wheader, 100 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
#else /* HAVE_SWPRINTF */
		snprintf( header, 100, format, _("Manufacturer"), _("Part"), _("Stepping"), _("Instruction"), _("Register") );
		if (mbstowcs( wheader, header, 100 ) == -1)
			printf( _("(%d) String conversion failed!\n"), __LINE__ );
#endif /* HAVE_SWPRINTF */
		printf( header );

		for (i = 0; i < wcslen( wheader ); i++ )
			putchar( '-' );
		putchar( '\n' );
	}

	if (cmd_params( params ) == 1) {
		if (chain->parts->len > chain->active_part) {
			printf( _(" %3d "), chain->active_part );
			part_print( chain->parts->parts[chain->active_part] );
		}
		if (bus != NULL) {
			int i;
			uint64_t a;
			bus_area_t area;

			for (i = 0; i < buses.len; i++)
				if (buses.buses[i] == bus)
					break;
			printf( _("\nActive bus:\n*%d: "), i );
			bus_printinfo( bus );

			for (a = 0; a < UINT64_C(0x100000000); a = area.start + area.length) {
				if (bus_area( bus, a, &area ) != 0) {
					printf( _("Error in bus area discovery at 0x%08llX\n"), a );
					break;
				}
				if (area.width != 0) {
					if (area.description != NULL)
						printf( _("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit, (%s)\n"), area.start, area.length, area.width, _(area.description) );
					else
						printf( _("\tstart: 0x%08X, length: 0x%08llX, data width: %d bit\n"), area.start, area.length, area.width );
				}
			}
		}

		return 1;
	}

	if (strcmp( params[1], "chain" ) == 0) {
		parts_print( chain->parts );
		return 1;
	}

	for (i = 0; i < buses.len; i++) {
		if (buses.buses[i] == bus)
			printf( _("*%d: "), i );
		else
			printf( _("%d: "), i );
		bus_printinfo( buses.buses[i] );
	}

	return 1;
}
Exemple #11
0
static int
cmd_instruction_run( chain_t *chain, char *params[] )
{
	part_t *part;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len) {
		printf( _("%s: no active part\n"), "instruction" );
		return 1;
	}

	part = chain->parts->parts[chain->active_part];

	if (cmd_params( params ) == 2) {
		part_set_instruction( part, params[1] );
		if (part->active_instruction == NULL)
			printf( _("%s: unknown instruction '%s'\n"), "instruction", params[1] );
		return 1;
	}
	
	if (cmd_params( params ) == 3) {
		unsigned int len;

		if (strcasecmp( params[1], "length" ) != 0)
			return -1;

		if (part->instructions != NULL) {
			printf( _("instruction length is already set and used\n") );
			return 1;
		}

		if (cmd_get_number( params[2], &len ))
			return -1;

		part->instruction_length = len;
		return 1;
	}

	if (cmd_params( params ) == 4) {
		instruction *i;

		if (strlen( params[2] ) != part->instruction_length) {
			printf( _("invalid instruction length\n") );
			return 1;
		}

		if (part_find_instruction( part, params[1] ) != NULL) {
			printf( _("Instruction '%s' already defined\n"), params[1] );
			return 1;
		}

		i = instruction_alloc( params[1], part->instruction_length, params[2] );
		if (!i) {
			printf( _("out of memory\n") );
			return 1;
		}

		i->next = part->instructions;
		part->instructions = i;

		i->data_register = part_find_data_register( part, params[3] );
		if (i->data_register == NULL) {
			printf( _("unknown data register '%s'\n"), params[3] );
			return 1;
		}

		return 1;
	}

	return -1;
}
Exemple #12
0
static int
cmd_dr_run( chain_t *chain, char *params[] )
{
	int dir = 1;
	tap_register *r;

	if (cmd_params( params ) < 1 || cmd_params( params ) > 2)
		return -1;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len) {
		printf( _("%s: no active part\n"), "dr" );
		return 1;
	}

	if (chain->parts->parts[chain->active_part]->active_instruction == NULL) {
		printf( _("%s: part without active instruction\n"), "dr" );
		return 1;
	}
	if (chain->parts->parts[chain->active_part]->active_instruction->data_register == NULL) {
		printf( _("%s: part without active data register\n"), "dr" );
		return 1;
	}

	if (params[1]) {
		if (strcasecmp( params[1], "in" ) == 0)
			dir = 0;
		else if (strcasecmp( params[1], "out" ) == 0)
			dir = 1;
		else {
			unsigned int bit;
			if (strspn(params[1], "01") != strlen(params[1])) {
				return -1;
			}
			
			r = chain->parts->parts[chain->active_part]->active_instruction->data_register->in;
			if (r->len != strlen(params[1])) {
				printf( _("%s: register length mismatch\n"), "dr" );
				return 1;
			}
			for (bit = 0; params[1][bit]; bit++) {
				r->data[r->len - 1 - bit] = (params[1][bit] == '1');
			}
			
			dir = 0;
		}
	}

	if (dir)
		r = chain->parts->parts[chain->active_part]->active_instruction->data_register->out;
	else
		r = chain->parts->parts[chain->active_part]->active_instruction->data_register->in;
	printf( _("%s\n"), register_get_string( r ) );

	return 1;
}