Added option to use only image pieces for specific device / hw revision
This commit is contained in:
1 parent
418f3cfd4b
commit
eac07b18d9
3 files changed
+55
-14
No files matched your search
+38
-6
@@ -32,7 +32,7 @@ char *strdup(const char *s);
|
|||||||
|
|
||||||
int (*fiasco_callback)(struct header_t *header) = NULL;
|
int (*fiasco_callback)(struct header_t *header) = NULL;
|
||||||
|
|
||||||
int openfiasco(const char *name, const char *piece_grep, int v)
|
int openfiasco(const char *name, const char *type, const char *device, const char *hwrev, const char *version, int v)
|
||||||
{
|
{
|
||||||
struct header_t header;
|
struct header_t header;
|
||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
@@ -42,6 +42,7 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
unsigned int blockcount;
|
unsigned int blockcount;
|
||||||
off_t off, here;
|
off_t off, here;
|
||||||
int subsections;
|
int subsections;
|
||||||
|
int match;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
@@ -251,7 +252,7 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
strcat(header.name, "-");
|
strcat(header.name, "-");
|
||||||
strcat(header.name, header.version);
|
strcat(header.name, header.version);
|
||||||
}
|
}
|
||||||
/* callback */
|
|
||||||
off = lseek(header.fd, 0, SEEK_CUR);
|
off = lseek(header.fd, 0, SEEK_CUR);
|
||||||
if (v) {
|
if (v) {
|
||||||
printf(" version: %s\n", header.version);
|
printf(" version: %s\n", header.version);
|
||||||
@@ -260,10 +261,39 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
printf(" name: %s\n", header.name);
|
printf(" name: %s\n", header.name);
|
||||||
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)
|
match = 1;
|
||||||
printf("==> (%s) %s\n", piece_grep, header.name);
|
|
||||||
else
|
if (match && type && strcmp(header.type, type) != 0)
|
||||||
|
match = 0;
|
||||||
|
|
||||||
|
if (match && device && strcmp(header.device, device) != 0)
|
||||||
|
match = 0;
|
||||||
|
|
||||||
|
if (match && version && strcmp(header.version, version) != 0)
|
||||||
|
match = 0;
|
||||||
|
|
||||||
|
if (match && hwrev) {
|
||||||
|
char *tmp1 = malloc(strlen(header.hwrevs)+3);
|
||||||
|
char *tmp2 = malloc(strlen(hwrev)+3);
|
||||||
|
|
||||||
|
if (!tmp1 || !tmp2) {
|
||||||
|
printf("malloc error\n");
|
||||||
|
return close(header.fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(tmp1, ",%s,", header.hwrevs);
|
||||||
|
sprintf(tmp2, ",%s,", hwrev);
|
||||||
|
|
||||||
|
if (!strstr(tmp1, tmp2))
|
||||||
|
match = 0;
|
||||||
|
|
||||||
|
free(tmp1);
|
||||||
|
free(tmp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* callback */
|
||||||
|
if (match) {
|
||||||
printf("==> %s\n", header.name);
|
printf("==> %s\n", header.name);
|
||||||
if (fiasco_callback != NULL) {
|
if (fiasco_callback != NULL) {
|
||||||
fiasco_callback(&header);
|
fiasco_callback(&header);
|
||||||
@@ -277,6 +307,8 @@ int openfiasco(const char *name, const char *piece_grep, int v)
|
|||||||
} else {
|
} else {
|
||||||
// ??huh
|
// ??huh
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
printf("ignored %s\n", header.name);
|
||||||
}
|
}
|
||||||
// XXX dup
|
// XXX dup
|
||||||
lseek(header.fd, off, SEEK_SET);
|
lseek(header.fd, off, SEEK_SET);
|
||||||
|
|||||||
+16
-7
@@ -224,6 +224,15 @@ int unpack_callback(struct header_t *header)
|
|||||||
if (nomode)
|
if (nomode)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
printf("Unpacking file: %s\n", header->name);
|
||||||
|
printf(" type: %s\n", header->type);
|
||||||
|
if (header->device[0]) printf(" device: %s\n", header->device);
|
||||||
|
if (header->hwrevs[0]) printf(" hw revisions: %s\n", header->hwrevs);
|
||||||
|
if (header->version[0]) printf(" version: %s\n", header->version);
|
||||||
|
if (header->layout) printf(" layout file: %s\n", header->layout);
|
||||||
|
printf(" size: %d\n", header->size);
|
||||||
|
printf(" hash: %04x\n", header->hash);
|
||||||
|
|
||||||
fd = fopen(header->name, "wb");
|
fd = fopen(header->name, "wb");
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
printf("Cannot open file.\n");
|
printf("Cannot open file.\n");
|
||||||
@@ -260,7 +269,7 @@ void unpack_fiasco_image(char *file)
|
|||||||
{
|
{
|
||||||
printf("Dumping firmware pieces to disk.\n");
|
printf("Dumping firmware pieces to disk.\n");
|
||||||
fiasco_callback = &unpack_callback;
|
fiasco_callback = &unpack_callback;
|
||||||
openfiasco(file, NULL ,1);
|
openfiasco(file, NULL, NULL, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fiasco_flash(const char *file)
|
int fiasco_flash(const char *file)
|
||||||
@@ -292,11 +301,11 @@ int fiasco_flash(const char *file)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
fiasco_callback = &flash_callback;
|
fiasco_callback = &flash_callback;
|
||||||
openfiasco(file, "xloader", 0);
|
openfiasco(file, "xloader", NULL, NULL, NULL, 0);
|
||||||
openfiasco(file, "secondary", 0);
|
openfiasco(file, "secondary", NULL, NULL, NULL, 0);
|
||||||
openfiasco(file, "kernel", 0);
|
openfiasco(file, "kernel", NULL, NULL, NULL, 0);
|
||||||
openfiasco(file, "initfs", 0);
|
openfiasco(file, "initfs", NULL, NULL, NULL, 0);
|
||||||
openfiasco(file, "rootfs", 0);
|
openfiasco(file, "rootfs", NULL, NULL, NULL, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -470,7 +479,7 @@ int main(int argc, char **argv)
|
|||||||
type = fpid_file(optarg);
|
type = fpid_file(optarg);
|
||||||
printf("%s: %s\n", type, optarg);
|
printf("%s: %s\n", type, optarg);
|
||||||
if (type && strcmp(type, "fiasco") == 0)
|
if (type && strcmp(type, "fiasco") == 0)
|
||||||
openfiasco(optarg, NULL, 1);
|
openfiasco(optarg, NULL, NULL, NULL, NULL, 1);
|
||||||
identify = 1;
|
identify = 1;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ extern char *modes[];
|
|||||||
extern char *root_devices[];
|
extern char *root_devices[];
|
||||||
|
|
||||||
// fiasco
|
// fiasco
|
||||||
int openfiasco(const char *name, const char *grep, int v);
|
int openfiasco(const char *name, const char *type, const char *device, const char *hwrev, const char *version, int v);
|
||||||
int fiasco_new(const char *filename, const char *name);
|
int fiasco_new(const char *filename, const char *name);
|
||||||
void fiasco_data_read(struct header_t *header);
|
void fiasco_data_read(struct header_t *header);
|
||||||
int fiasco_add_eof(int fd);
|
int fiasco_add_eof(int fd);
|
||||||
|
|||||||
Reference in new issue
Block a user