* Apply Pali Rohár patch fixing RX51 Fiasco Image parsing

This commit is contained in:
pancake committed 2011-12-16 16:17:17 +01:00
1 parent b0f69c8b6b
commit 04f9369ace
1 file changed
+27 -16
+27 -16
View File
@@ -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);
for(i=0;buf[0]!=0x54;i++) {
j = read(header.fd, buf, 1);
if (j == -1) {
printf("Cannot find next FIASCO header\n");
return close(header.fd); return close(header.fd);
if (buf[0] == 0x54 /*&& buf[1] == 0x04*/ && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00)
break;
lseek(header.fd, -6, SEEK_CUR);
++i;
} }
} if (i && v) printf("Skipping %d padding bytes\n", i);
if (v) printf("Skipping %d padding bytes\n", i);
lseek(header.fd, -1, SEEK_CUR); if (read(header.fd, buf+7, 2)<2)
continue; 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))) {
if (piece_grep)
printf("==> (%s) %s\n", piece_grep, header.name); 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);