Exemplo n.º 1
0
void FpgaGatherVersion(char *dst, int len)
{
	char *fpga_info;
	unsigned int fpga_info_len;
	dst[0] = 0;
	if(!bitparse_find_section('e', &fpga_info, &fpga_info_len)) {
		strncat(dst, "FPGA image: legacy image without version information", len-1);
	} else {
		strncat(dst, "FPGA image built", len-1);
		/* USB packets only have 48 bytes data payload, so be terse */
#if 0
		if(bitparse_find_section('a', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
			strncat(dst, " from ", len-1);
			strncat(dst, fpga_info, len-1);
		}
		if(bitparse_find_section('b', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
			strncat(dst, " for ", len-1);
			strncat(dst, fpga_info, len-1);
		}
#endif
		if(bitparse_find_section('c', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
			strncat(dst, " on ", len-1);
			strncat(dst, fpga_info, len-1);
		}
		if(bitparse_find_section('d', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
			strncat(dst, " at ", len-1);
			strncat(dst, fpga_info, len-1);
		}
	}
}
Exemplo n.º 2
0
static int FpgaGatherVersion(FILE *infile, char* infile_name, char *dst, int len)
{
	unsigned int fpga_info_len;
	char tempstr[40] = {0x00};
	
	dst[0] = '\0';

	for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
		if (fgetc(infile) != bitparse_fixed_header[i]) {
			fprintf(stderr, "Invalid FPGA file. Aborting...\n\n");
			return(EXIT_FAILURE);
		}
	}

	strncat(dst, basename(infile_name), len-1);
	// if (bitparse_find_section(infile, 'a', &fpga_info_len)) {
		// for (uint16_t i = 0; i < fpga_info_len; i++) {
			// char c = (char)fgetc(infile);
			// if (i < sizeof(tempstr)) {
				// tempstr[i] = c;
			// }
		// }
		// strncat(dst, tempstr, len-1);
	// }
	strncat(dst, " built", len-1);
	if (bitparse_find_section(infile, 'b', &fpga_info_len)) {
		strncat(dst, " for ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)fgetc(infile);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	if (bitparse_find_section(infile, 'c', &fpga_info_len)) {
		strncat(dst, " on ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)fgetc(infile);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	if (bitparse_find_section(infile, 'd', &fpga_info_len)) {
		strncat(dst, " at ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)fgetc(infile);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	return 0;
}
Exemplo n.º 3
0
void FpgaDownloadAndGo(void)
{
	/* Check for the new flash image format: Should have the .bit file at &_binary_fpga_bit_start
	 */
	if(bitparse_init(&_binary_fpga_bit_start, &_binary_fpga_bit_end)) {
		/* Successfully initialized the .bit parser. Find the 'e' section and
		 * send its contents to the FPGA.
		 */
		char *bitstream_start;
		unsigned int bitstream_length;
		if(bitparse_find_section('e', &bitstream_start, &bitstream_length)) {
			DownloadFPGA(bitstream_start, bitstream_length, 0);

			return; /* All done */
		}
	}

	/* Fallback for the old flash image format: Check for the magic marker 0xFFFFFFFF
	 * 0xAA995566 at address 0x102000. This is raw bitstream with a size of 336,768 bits
	 * = 10,524 uint32_t, stored as uint32_t e.g. little-endian in memory, but each DWORD
	 * is still to be transmitted in MSBit first order. Set the invert flag to indicate
	 * that the DownloadFPGA function should invert every 4 byte sequence when doing
	 * the bytewise download.
	 */
	if( *(uint32_t*)0x102000 == 0xFFFFFFFF && *(uint32_t*)0x102004 == 0xAA995566 )
		DownloadFPGA((char*)0x102000, 10524*4, 1);
}
Exemplo n.º 4
0
//----------------------------------------------------------------------------
// Check which FPGA image is currently loaded (if any). If necessary 
// decompress and load the correct (HF or LF) image to the FPGA
//----------------------------------------------------------------------------
void FpgaDownloadAndGo(int bitstream_version)
{
	z_stream compressed_fpga_stream;
	uint8_t output_buffer[OUTPUT_BUFFER_LEN];
	
	// check whether or not the bitstream is already loaded
	if (downloaded_bitstream == bitstream_version)
		return;

	// make sure that we have enough memory to decompress
	BigBuf_free();
	
	if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
		return;
	}

	unsigned int bitstream_length;
	if(bitparse_find_section(bitstream_version, 'e', &bitstream_length, &compressed_fpga_stream, output_buffer)) {
		DownloadFPGA(bitstream_version, bitstream_length, &compressed_fpga_stream, output_buffer);
		downloaded_bitstream = bitstream_version;
	}

	inflateEnd(&compressed_fpga_stream);
}	
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Gather version information from FPGA image. Needs to decompress the begin 
// of the respective (HF or LF) image.
// Note: decompression makes use of (i.e. overwrites) BigBuf[]. It is therefore
// advisable to call this only once and store the results for later use.
//-----------------------------------------------------------------------------
void FpgaGatherVersion(int bitstream_version, char *dst, int len)
{
	unsigned int fpga_info_len;
	char tempstr[40];
	z_stream compressed_fpga_stream;
	uint8_t output_buffer[OUTPUT_BUFFER_LEN];
	
	dst[0] = '\0';

	// ensure that we can allocate enough memory for decompression:
	BigBuf_free();

	if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
		return;
	}

	if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		if (!memcmp("fpga_lf", tempstr, 7))
			strncat(dst, "LF ", len-1);
		else if (!memcmp("fpga_hf", tempstr, 7))
			strncat(dst, "HF ", len-1);
	}
	strncat(dst, "FPGA image built", len-1);
	if(bitparse_find_section(bitstream_version, 'b', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
		strncat(dst, " for ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	if(bitparse_find_section(bitstream_version, 'c', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
		strncat(dst, " on ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	if(bitparse_find_section(bitstream_version, 'd', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
		strncat(dst, " at ", len-1);
		for (uint16_t i = 0; i < fpga_info_len; i++) {
			char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
			if (i < sizeof(tempstr)) {
				tempstr[i] = c;
			}
		}
		strncat(dst, tempstr, len-1);
	}
	
	strncat(dst, "\n", len-1);

	inflateEnd(&compressed_fpga_stream);
}