summaryrefslogtreecommitdiff
path: root/v4l2-apps/util
diff options
context:
space:
mode:
Diffstat (limited to 'v4l2-apps/util')
-rw-r--r--v4l2-apps/util/xc3028-firmware/firmware-tool.c63
1 files changed, 44 insertions, 19 deletions
diff --git a/v4l2-apps/util/xc3028-firmware/firmware-tool.c b/v4l2-apps/util/xc3028-firmware/firmware-tool.c
index da063ca77..de1262ceb 100644
--- a/v4l2-apps/util/xc3028-firmware/firmware-tool.c
+++ b/v4l2-apps/util/xc3028-firmware/firmware-tool.c
@@ -512,7 +512,7 @@ void list_firmware_desc(FILE *fp, struct firmware_description *desc)
fprintf(fp, "size: %u\n", desc->size);
}
-void list_firmware(struct firmware *f, unsigned int dump)
+void list_firmware(struct firmware *f, unsigned int dump, char *binfile)
{
unsigned int i = 0;
@@ -538,6 +538,28 @@ void list_firmware(struct firmware *f, unsigned int dump)
}
printf("\n");
}
+ if (binfile) {
+ char name[strlen(binfile)+4], *p;
+ p = strrchr(binfile,'.');
+ if (p) {
+ int n = p - binfile;
+ strncpy(name, binfile, n);
+ sprintf(name + n, "%03i", i);
+ strcat(name, p);
+ } else {
+ strcpy(name, binfile);
+ sprintf(name + strlen(name), "%03i", i);
+ }
+ FILE *fp;
+
+ fp = fopen(name,"w");
+ if (!fp) {
+ perror("Opening file to write");
+ return;
+ }
+ fwrite(f->desc[i].data, f->desc[i].size, 1, fp);
+ fclose(fp);
+ }
}
}
@@ -601,7 +623,7 @@ int seek_chunks(struct chunk_hunk *fhunk,
struct chunk_hunk *hunk = fhunk;
/* Method 3 vars */
static unsigned char *base_start = 0;
- int ini_sig = 8, sig_len = 14, end_sig = 10;
+ int ini_sig = 8, sig_len = 14, end_sig = 8;
/* Method 1a: Seek for a complete firmware */
for (p = seek; p < endp; p++) {
@@ -679,8 +701,12 @@ int seek_chunks(struct chunk_hunk *fhunk,
p = memmem (base_start, endp-base_start,
temp_data + fsize - end_sig, end_sig);
+ if (p)
+ p = memmem (p + end_sig, endp-base_start,
+ temp_data + fsize - end_sig, end_sig);
+
if (!p) {
- printf("Method3: found something that looks like a firmware start at %x\n",
+ printf("Found something that looks like a firmware start at %x\n",
base_start - seek);
base_start += ini_sig + sig_len;
@@ -689,7 +715,7 @@ int seek_chunks(struct chunk_hunk *fhunk,
p += end_sig;
- printf("Method3: found firmware at %x, size = %d\n",
+ printf("Found firmware at %x, size = %d\n",
base_start - seek, p - base_start);
hunk->data = NULL;
@@ -801,7 +827,7 @@ seek_next:
}
void seek_firmware(struct firmware *f, char *seek_file, char *write_file) {
- unsigned int i = 0, nfound = 0;
+ unsigned int i = 0, j, nfound = 0;
long size, rd = 0;
unsigned char *seek, *p, *endp, *p2, *endp2, *fpos;
/*FIXME: Calculate it, instead of using a hardcode value */
@@ -857,6 +883,8 @@ void seek_firmware(struct firmware *f, char *seek_file, char *write_file) {
} else {
nfound++;
printf("Found with method %d: Firmware %d ", found, i);
+ if (found == 2)
+ f->desc[i].size = hunks[i].size;
list_firmware_desc(stdout, &f->desc[i]);
}
}
@@ -872,16 +900,17 @@ void seek_firmware(struct firmware *f, char *seek_file, char *write_file) {
}
fprintf(fp, "%s", extract_header);
- for (i = 0; i < f->nr_desc; ++i) {
+ for (i = 0, j = -1; i < f->nr_desc; i++) {
struct chunk_hunk *hunk = &hunks[i];
if (!hunk->size)
continue;
+ j++;
if (hunk->hint_method)
fprintf(fp, "\n\t#\n\t# Guessed format ");
- fprintf(fp, "\n\t#\n\t# Firmware %d, ", i);
+ fprintf(fp, "\n\t#\n\t# Firmware %d, ", j);
list_firmware_desc(fp, &f->desc[i]);
fprintf(fp, "\t#\n\n");
@@ -892,19 +921,15 @@ void seek_firmware(struct firmware *f, char *seek_file, char *write_file) {
if (f->desc[i].type & HAS_IF)
fprintf(fp, "\twrite_le16(%d);\t\t\t# IF\n",
f->desc[i].int_freq);
- if (hunk->hint_method == 3)
- fprintf(fp, "\twrite_le32(%d);\t\t\t# Size\n",
- hunk->size);
- else
- fprintf(fp, "\twrite_le32(%d);\t\t\t# Size\n",
- f->desc[i].size);
+ fprintf(fp, "\twrite_le32(%d);\t\t\t# Size\n",
+ f->desc[i].size);
while (hunk) {
if (hunk->data) {
- int j;
+ int k;
fprintf(fp, "\tsyswrite(OUTFILE, ");
- for (j = 0; j < hunk->size; j++) {
- fprintf(fp, "chr(%d)", hunk->data[j]);
- if (j < hunk->size-1)
+ for (k = 0; k < hunk->size; k++) {
+ fprintf(fp, "chr(%d)", hunk->data[k]);
+ if (k < hunk->size-1)
fprintf(fp,".");
}
fprintf(fp,");\n");
@@ -930,7 +955,7 @@ void seek_firmware(struct firmware *f, char *seek_file, char *write_file) {
void print_usage(void)
{
printf("firmware-tool usage:\n");
- printf("\t firmware-tool --list [--dump] <firmware-file>\n");
+ printf("\t firmware-tool --list [--dump] [--write <bin-file>] <firmware-file>\n");
printf("\t firmware-tool --add <firmware-dump> <firmware-file>\n");
printf("\t firmware-tool --delete <index> <firmware-file>\n");
printf("\t firmware-tool --type <type> --index <i> <firmware-file>\n");
@@ -1054,7 +1079,7 @@ int main(int argc, char* argv[])
switch(action) {
case LIST_ACTION:
- list_firmware(f, dump);
+ list_firmware(f, dump, write_file);
break;
case ADD_ACTION: