Beispiel #1
0
void
readmem( bus_t *bus, FILE *f, uint32_t addr, uint32_t len )
{
	uint32_t step;
	uint64_t a;
	int bc = 0;
#define BSIZE 4096
	uint8_t b[BSIZE];
	bus_area_t area;
	uint64_t end;

	if (!bus) {
		printf( _("Error: Missing bus driver!\n") );
		return;
	}

	bus_prepare( bus );

	if (bus_area( bus, addr, &area ) != 0) {
		printf( _("Error: Bus width detection failed\n") );
		return;
	}
	step = area.width / 8;

	if (step == 0) {
		printf( _("Unknown bus width!\n") );
		return;
	}

	addr = addr & (~(step - 1));
	len = (len + step - 1) & (~(step - 1));

	printf( _("address: 0x%08X\n"), addr );
	printf( _("length:  0x%08X\n"), len );

	if (len == 0) {
		printf( _("length is 0.\n") );
		return;
	}

	a = addr;
	end = a + len;
	printf( _("reading:\n") );
	bus_read_start( bus, addr );
	for (a += step; a <= end; a += step) {
		uint32_t data;
		int j;

		if (a < addr + len)
			data = bus_read_next( bus, a );
		else
			data = bus_read_end( bus );

		for (j = step; j > 0; j--)
			if (big_endian)
				b[bc++] = (data >> ((j - 1) * 8)) & 0xFF;
			else {
				b[bc++] = data & 0xFF;
				data >>= 8;
			}

		if ((bc >= BSIZE) || (a >= end) ) {
			printf( _("addr: 0x%08X"), a );
			printf( "\r" );
			fflush( stdout );
			fwrite( b, bc, 1, f );
			bc = 0;
		}
	}
Beispiel #2
0
int
jedec_detect( bus_t *bus, uint32_t adr, cfi_array_t **cfi_array )
{
	unsigned int bw;		/* bus width */
	int ba;				/* bus width address multiplier */
	bus_area_t area;
	int mid;
	int did;
	cfi_query_structure_t *cfi;

	if (!cfi_array || !bus)
		return -1;		/* invalid parameters */

	*cfi_array = calloc( 1, sizeof (cfi_array_t) );
	if (!*cfi_array)
		return -2;		/* out of memory */

	(*cfi_array)->bus = bus;
	(*cfi_array)->address = adr;
	if (bus_area( bus, adr, &area ) != 0)
		return -8;		/* bus width detection failed */
	bw = area.width;
	if (bw != 8 && bw != 16 && bw != 32)
		return -3;		/* invalid bus width */
	(*cfi_array)->bus_width = ba = bw / 8;
	(*cfi_array)->cfi_chips = calloc( ba, sizeof (cfi_chip_t *) );
	if (!(*cfi_array)->cfi_chips)
		return -2;		/* out of memory */

	/* Query flash. */
	bus_write( bus, 0x0, 0xf0 );
	bus_write( bus, 0xaaa, 0xaa );
	bus_write( bus, 0x555, 0x55 );
	bus_write( bus, 0xaaa, 0x90 );
	mid = bus_read( bus, 0x0);
	did = bus_read( bus, 0x2);
	bus_write( bus, 0x0, 0xf0 );

	printf( "%s: mid %x, did %x\n", __FUNCTION__, mid, did );
	if (mid != 0x01)
		return -1;

	(*cfi_array)->cfi_chips[0] = calloc( 1, sizeof (cfi_chip_t) );
	if (!(*cfi_array)->cfi_chips[0])
		return -2;	/* out of memory */

	cfi = &(*cfi_array)->cfi_chips[0]->cfi;

	cfi->identification_string.pri_id_code = CFI_VENDOR_AMD_SCS;
	cfi->identification_string.pri_vendor_tbl = NULL;
	cfi->identification_string.alt_id_code = 0;
	cfi->identification_string.alt_vendor_tbl = NULL;

	cfi->device_geometry.number_of_erase_regions = 4;
	cfi->device_geometry.erase_block_regions =
		malloc( cfi->device_geometry.number_of_erase_regions * sizeof (cfi_erase_block_region_t) );
	if (!cfi->device_geometry.erase_block_regions)
		return -2;	/* out of memory */

	cfi->device_geometry.erase_block_regions[0].erase_block_size = 16 * 1024;
	cfi->device_geometry.erase_block_regions[0].number_of_erase_blocks = 1;
	cfi->device_geometry.erase_block_regions[1].erase_block_size = 8 * 1024;
	cfi->device_geometry.erase_block_regions[1].number_of_erase_blocks = 2;
	cfi->device_geometry.erase_block_regions[2].erase_block_size = 32 * 1024;
	cfi->device_geometry.erase_block_regions[2].number_of_erase_blocks = 1;
	cfi->device_geometry.erase_block_regions[3].erase_block_size = 64 * 1024;
	cfi->device_geometry.erase_block_regions[3].number_of_erase_blocks = 15;

	return 0;
}
Beispiel #3
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;
}
Beispiel #4
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;
}