* Apply Pali Rohár patch fixing RX51 Fiasco Image parsing
This commit is contained in:
1 parent
b0f69c8b6b
commit
04f9369ace
1 file changed
+29
-18
+29
-18
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2007-2009 pancake <pancake@youterm.com>
|
* Copyright (C) 2007-2011 pancake <pancake@youterm.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -37,7 +37,7 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
unsigned char *pdata, *pdataend;
|
unsigned char *pdata, *pdataend;
|
||||||
unsigned int namelen;
|
unsigned int namelen;
|
||||||
off_t off, here;
|
off_t off, here;
|
||||||
int i,j;
|
int i;
|
||||||
|
|
||||||
header.fd = open(name, O_RDONLY);
|
header.fd = open(name, O_RDONLY);
|
||||||
|
|
||||||
@@ -74,22 +74,20 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
/* walk the tree */
|
/* walk the tree */
|
||||||
while(1) {
|
while(1) {
|
||||||
here = lseek(header.fd, 0, SEEK_CUR);
|
here = lseek(header.fd, 0, SEEK_CUR);
|
||||||
if (read(header.fd, buf, 9) != 9)
|
|
||||||
break;
|
i = 0;
|
||||||
if (buf[0] != 0x54) { // 'T'
|
while(1) {
|
||||||
/* skipping some bytes */
|
if (read(header.fd, buf, 7)<7)
|
||||||
lseek(header.fd, -9, SEEK_CUR);
|
return close(header.fd);
|
||||||
for(i=0;buf[0]!=0x54;i++) {
|
if (buf[0] == 0x54 /*&& buf[1] == 0x04*/ && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00)
|
||||||
j = read(header.fd, buf, 1);
|
break;
|
||||||
if (j == -1) {
|
lseek(header.fd, -6, SEEK_CUR);
|
||||||
printf("Cannot find next FIASCO header\n");
|
++i;
|
||||||
return close(header.fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (v) printf("Skipping %d padding bytes\n", i);
|
|
||||||
lseek(header.fd, -1, SEEK_CUR);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (i && v) printf("Skipping %d padding bytes\n", i);
|
||||||
|
|
||||||
|
if (read(header.fd, buf+7, 2)<2)
|
||||||
|
break;
|
||||||
header.hash = buf[7]<<8|buf[8];
|
header.hash = buf[7]<<8|buf[8];
|
||||||
|
|
||||||
/* piece name */
|
/* piece name */
|
||||||
@@ -103,6 +101,12 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
} else if (v) printf(" %s\n", data);
|
} else if (v) printf(" %s\n", data);
|
||||||
strcpy(header.name, (char *)data);
|
strcpy(header.name, (char *)data);
|
||||||
|
|
||||||
|
if (v) {
|
||||||
|
printf(" header: ");
|
||||||
|
for (i=0; i<7;++i) printf(" 0x%.2X", (unsigned int)buf[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (read(header.fd, buf, 9)<9)
|
if (read(header.fd, buf, 9)<9)
|
||||||
break;
|
break;
|
||||||
memcpy(&header.size, buf,4);
|
memcpy(&header.size, buf,4);
|
||||||
@@ -136,6 +140,10 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
pdata = pdata+strlen((char*)pdata)+1;
|
pdata = pdata+strlen((char*)pdata)+1;
|
||||||
for(;*pdata=='\0' && pdata<pdataend; pdata++);
|
for(;*pdata=='\0' && pdata<pdataend; pdata++);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* End of comments, ignore one char and next is image data */
|
||||||
|
lseek(header.fd, 1, SEEK_CUR);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
strcpy(header.version, (char *)data);
|
strcpy(header.version, (char *)data);
|
||||||
if (read(header.fd, buf+8, 1)<1)
|
if (read(header.fd, buf+8, 1)<1)
|
||||||
@@ -148,7 +156,10 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
printf(" body-at: 0x%08x\n", (unsigned int)off);
|
printf(" body-at: 0x%08x\n", (unsigned int)off);
|
||||||
}
|
}
|
||||||
if (piece_grep==NULL || (strstr(header.name, piece_grep))) {
|
if (piece_grep==NULL || (strstr(header.name, piece_grep))) {
|
||||||
printf("==> (%s) %s\n", piece_grep, header.name);
|
if (piece_grep)
|
||||||
|
printf("==> (%s) %s\n", piece_grep, header.name);
|
||||||
|
else
|
||||||
|
printf("==> %s\n", header.name);
|
||||||
if (fiasco_callback != NULL) {
|
if (fiasco_callback != NULL) {
|
||||||
fiasco_callback(&header);
|
fiasco_callback(&header);
|
||||||
free(header.data);
|
free(header.data);
|
||||||
|
|||||||
Reference in new issue
Block a user