From 5a96158322b4b7e8289dfd429af3e7b15a99d173 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 8 Dec 2008 18:13:36 +0100 Subject: * Implement and test direct file FIASCO flash - openfiasco receives options for grepping for pieces and be verbose - fixed flashing order using grep options xloader, secondary, kernel, initfs, rootfs - Tested and working - Added parser for the hw revision string * Autodetect device hw revision and setup the subversion string on the fly. --- src/console.c | 7 ++++++- src/fiasco.c | 50 +++++++++++++++++++++++++++++++------------------- src/flash.c | 10 ++++++++++ src/main.c | 46 +++++++++++++++++++++++++++++++++++++++++----- src/main.h | 2 +- src/query.c | 21 +++++++++++---------- src/query.h | 2 +- 7 files changed, 101 insertions(+), 37 deletions(-) diff --git a/src/console.c b/src/console.c index 3206903..7098f36 100644 --- a/src/console.c +++ b/src/console.c @@ -46,8 +46,13 @@ void cmd_help(char *line) void cmd_info(char *line) { + char *p, str[128]; get_sw_version(); - get_hw_revision(); // get hardware revision: + get_hw_revision(str, 128); // get hardware revision: + p = strstr(str, "hw_rev:"); + if (p) // TODO: delimit string by comma + printf("SubVersionString autodetected: '%s'\n", p+7); + else printf("SubVersionString autodetected: (error)\n"); get_root_device(); // only for flashing get_usb_mode(); get_rd_mode(); diff --git a/src/fiasco.c b/src/fiasco.c index 192238f..a521270 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -29,7 +29,7 @@ int (*fiasco_callback)(struct header_t *header) = NULL; -int openfiasco(char *name) +int openfiasco(char *name, char *piece_grep, int v) { struct header_t header; unsigned char buf[128]; @@ -38,6 +38,7 @@ int openfiasco(char *name) unsigned int namelen; off_t off, here; int i,j; + header.fd = open(name, O_RDONLY); if (header.fd == -1) { @@ -60,8 +61,9 @@ int openfiasco(char *name) memset(buf,'\0', 128); read(header.fd, buf, namelen); - printf("Fiasco version: %2d\n", buf[3]); + if (v) printf("Fiasco version: %2d\n", buf[3]); strcpy(header.fwname, (char *)buf+6); + if (v) for(i=6;i (%s) %s\n", piece_grep, header.name); + if (fiasco_callback != NULL) { + fiasco_callback(&header); + free(header.data); + continue; + } else { + // ??huh + } } // XXX dup lseek(header.fd, off, SEEK_SET); lseek(header.fd, header.size, SEEK_CUR); } - return 0; + return close(header.fd); } void fiasco_data_read(struct header_t *header) diff --git a/src/flash.c b/src/flash.c index 0915f4c..94c7f29 100644 --- a/src/flash.c +++ b/src/flash.c @@ -86,6 +86,16 @@ void flash_image(const char *filename, const char *piece, const char *version) unsigned char nolofiller[128]; ushort hash = do_hash_file(filename); + if (piece == NULL) { + //exit(1); + piece = fpid_file(filename); + if (piece == NULL) { + printf("Unknown piece type\n"); + return; + } + printf("Piece type: %s\n", piece); + } + if (version) vlen = strlen(version)+1; diff --git a/src/main.c b/src/main.c index 21be4b4..a5e18fd 100644 --- a/src/main.c +++ b/src/main.c @@ -159,17 +159,41 @@ void unpack_fiasco_image(char *file) { printf("Dumping firmware pieces to disk.\n"); fiasco_callback = &unpack_callback; - openfiasco( file ); + openfiasco(file, NULL ,1); } int fiasco_flash(char *file) { + char *p,version[64]; + + if (connect_via_usb()) { + fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n"); + return 0; + } + + // if (info) + cmd_info(""); + check_nolo_order(); get_sw_version(); + get_hw_revision(version, 44); + + if (subverstr == NULL) { + p = strstr(version, "hw_rev:"); + if (p) { + subverstr = strdup(p+7); + // TODO: delimit string by comma + printf("SubVersionString autodetected: '%s'\n", subverstr); + } + } get_nolo_version(); fiasco_callback = &flash_callback; - openfiasco( file ); + openfiasco(file, "xloader", 0); + openfiasco(file, "secondary", 0); + openfiasco(file, "kernel", 0); + openfiasco(file, "initfs", 0); + openfiasco(file, "rootfs", 0); return 0; } @@ -277,7 +301,8 @@ int main(int argc, char **argv) usb_mode = atoi(optarg); break; case 'F': - return fiasco_flash(optarg); + fiasco_image = optarg; + break; case 'd': sscanf(optarg, "%04hx:%04hx", &supported_devices[SUPPORTED_DEVICES-2].vendor_id, @@ -350,6 +375,9 @@ int main(int argc, char **argv) if (qmode) return queue_mode(); + if (!unpack && fiasco_image) + return fiasco_flash(fiasco_image); + if (identify) return 0; @@ -395,10 +423,18 @@ int main(int argc, char **argv) cmd_info(""); if (pcs_n) { - int c; - + char version[64]; check_nolo_order(); get_sw_version(); + get_hw_revision(version, 44); + if (subverstr == NULL) { + char *p = strstr(version, "hw_rev:"); + if (p) { + subverstr = strdup(p+7); + // TODO: delimit string by comma + printf("SubVersionString autodetected: '%s'\n", subverstr); + } + } get_nolo_version(); for(c=0;c19) - printf("%c", string[i]); + for(i=0;i<44&&i19) { + if (i>0 && string[i-1]<19) + str[j++] = (++mod%2)?':':','; + str[j++] = string[i]; } } - printf("'\n"); + printf("HW revision string: '%s'\n", str); return 0; } diff --git a/src/query.h b/src/query.h index 03ee963..4d18253 100644 --- a/src/query.h +++ b/src/query.h @@ -16,7 +16,7 @@ int set_rd_mode(unsigned short mode); int get_rd_flags(); int set_rd_flags(unsigned short flags); -int get_hw_revision(); +int get_hw_revision(char *str, int len); int get_root_device(); int set_root_device(unsigned short); -- cgit v1.2.3