1
0
mirror of https://github.com/preble/libpinproc synced 2026-02-24 18:25:23 +01:00

Added .p-roc file format version check so that p.roc file format changes won't be misinterpreted.

This commit is contained in:
Gerry Stellenberg
2011-06-28 11:24:07 -05:00
parent 5c61bd2bf0
commit 23a0d02803

View File

@@ -1930,11 +1930,13 @@ int checkPROCFile() {
unsigned char data;
int i=0,file_i=0;
int min_board_rev, max_board_rev;
int temp, num_header_words;
int temp, num_header_words, proc_file_version;
if (!fscanf(in, "%x\n", &temp)) return 0;
num_header_words = (int)(0x012345678 - temp);
if (!fscanf(in, "%x\n", &temp)) return 0;
proc_file_version = (int)(-1 - temp);
if (!fscanf(in, "%x\n", &temp)) return 0;
file_i = (int)(-1 - temp);
//fprintf(stderr, "\nbyte count: %d, %x", file_i, temp);
if (!fscanf(in, "%x\n", &temp)) return 0;
@@ -1962,6 +1964,11 @@ int checkPROCFile() {
(board_rev & 0x20) >> 3 |
(board_rev & 0x10) >> 1;
if (proc_file_version != 0) {
fprintf(stderr, "\nERROR: Invalid .p-roc file.");
return 0;
}
// Check for valid board ID and rev
if (board_id != file_board_id) {
fprintf(stderr, "\nERROR: This image is not compatible with the P-ROC board (ID: %x)", board_id);
@@ -2072,11 +2079,11 @@ int main( int argc, char** argv )
// Check for .p-roc file
if (strstr(pzXsvfFileName, ".p-roc")) {
fprintf(stderr, "\nP-ROC file format detected\n");
fprintf(stderr, "\nP-ROC file format detected\n.");
in = fopen( pzXsvfFileName, "rb" );
if ( !in ) {
fprintf(stderr, "ERROR: Cannot open file %s\n", pzXsvfFileName );
fprintf(stderr, "ERROR: Cannot open file %s\n.", pzXsvfFileName );
iErrorCode = XSVF_ERRORCODE( XSVF_ERROR_UNKNOWN );
}
else {
@@ -2096,10 +2103,10 @@ int main( int argc, char** argv )
}
// Check for .p-roc file
else if (strstr(pzXsvfFileName, ".xsvf")) {
fprintf(stderr, "\nXSVF file format detected\n");
fprintf(stderr, "\nXSVF file format detected.\n");
in = fopen( pzXsvfFileName, "rb" );
if ( !in ) {
fprintf(stderr, "ERROR: Cannot open file %s\n", pzXsvfFileName );
fprintf(stderr, "ERROR: Cannot open file %s\n.", pzXsvfFileName );
iErrorCode = XSVF_ERRORCODE( XSVF_ERROR_UNKNOWN );
}
else {
@@ -2112,8 +2119,8 @@ int main( int argc, char** argv )
}
}
else {
fprintf(stderr, "\nUnsupported file format.");
printUsage(argv[5]);
fprintf(stderr, "\nERROR: Unsupported file format.\n");
printUsage(argv[0]);
}
}