diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 262 |
1 files changed, 149 insertions, 113 deletions
@@ -58,7 +58,6 @@ char *root_devices[] = { NULL }; - void show_title() { printf("0xFFFF v%s // The Free Fiasco Firmware Flasher\n", VERSION); @@ -68,39 +67,48 @@ void show_usage() { int i; show_title(); + #if HAVE_USB - printf("Over USB:\n"); - printf(" -b [arg] boots the kernel with arguments\n"); - printf(" -c console prompt mode\n"); - printf(" -d [vid:pid] injects a usb device into the supported list\n"); - printf(" -D [0|1|2] sets the root device to flash (0), mmc (1) or usb (2)\n"); - printf(" -f <flags> set the given RD flags (see '-f help')\n"); - printf(" -i show device information (let standby mode)\n"); - printf(" -l list supported usb device ids\n"); - printf(" -p [[p%%]file] piece-of-firmware %% file-where-this-piece-is\n"); - printf(" -r [0|1] disable/enable R&D mode\n"); - printf(" -R reboot the omap board\n"); - printf(" -U [0|1] disable/enable the usb host mode\n"); + printf ("Over USB:\n" + " -b [arg] boots the kernel with arguments\n" + " -c console prompt mode\n" + " -d [vid:pid] injects a usb device into the supported list\n" + " -D [0|1|2] sets the root device to flash (0), mmc (1) or usb (2)\n" + " -f <flags> set the given RD flags (see '-f help')\n" + " -i show device information (let standby mode)\n" + " -l list supported usb device ids\n" + " -p format piece-of-firmware\n" + " piece format: [[[[dev:[hw:]]ver:]type:]file[%%layout]\n" + " hw is device HW revision\n" + " dev is device name string\n" + " ver is image version string\n" + " type is image type\n" + " file is image file name\n" + " layout is file name for layout file\n" + " -r [0|1] disable/enable R&D mode\n" + " -R reboot the omap board\n" + " -U [0|1] disable/enable the usb host mode\n"); #endif #if HAVE_SQUEUE printf(" -Q enter shared queues server mode (for gui or remote)\n"); #endif - printf("Local stuff:\n"); - printf(" -s [serial] serial port console (minicom like terminal)\n"); - printf(" -h show this help message\n"); - printf(" -S [subversion] unpacks/flash pieces matching this sub-version information\n"); - printf(" -n do not flash or write to disk (simulation)\n"); - printf(" -C [/dev/mtd] check bad blocks on mtd\n"); - printf(" -e [path] dump/extract pieces to path\n"); - printf(" -F [fiasco] flash a fiasco firmware image\n"); - printf(" -H [file] calculate hash for file\n"); - printf(" -I [piece] identify a firmware piece\n"); - printf(" -P [new-fiasco] creates a new fiasco package, pieces as arguments\n"); - printf(" -u [fiasco] unpack target fiasco image\n"); - printf(" -v be verbose and noisy\n"); - printf(" -V show 0xFFFF version information\n"); - printf(" -x extract configuration entries from /dev/mtd1\n"); - printf("Pieces are: "); + printf ("Local stuff:\n" + " -s [serial] serial port console (minicom like terminal)\n" + " -h show this help message\n" + " -S [subversion] unpacks/flash pieces matching this sub-version information\n" + " -n do not flash or write to disk (simulation)\n" + " -C [/dev/mtd] check bad blocks on mtd\n" + " -e [path] dump/extract pieces to path\n" + " -F [fiasco] flash a fiasco firmware image\n" + " -H [file] calculate hash for file\n" + " -I [piece] identify a firmware piece\n" + " -P [new-fiasco] creates a new fiasco package, pieces as arguments\n" + " optional argument 'version:<version>'\n" + " -u [fiasco] unpack target fiasco image\n" + " -v be verbose and noisy\n" + " -V show 0xFFFF version information\n" + " -x extract configuration entries from /dev/mtd1\n" + "Pieces are: "); for(i=0;pieces[i];i++) printf("%s ", pieces[i]); printf("\n"); // serial port support is not yet done (cold flash is for flashing the 8kB nand) // TODO: commandline shell prompt for nolo comm @@ -117,7 +125,7 @@ int unpack_callback(struct header_t *header) if (strchr(header->name, ',') != NULL) { if (!strstr(header->name, subverstr)) { printf("Skipping '%s' does not matches -S subversion\n", - header->name); + header->name); return 1; } } @@ -125,12 +133,22 @@ int unpack_callback(struct header_t *header) if (nomode) 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"); if (fd == NULL) { printf("Cannot open file.\n"); return 1; } - fwrite(header->data, header->size, 1, fd); + if (fwrite(header->data, header->size, 1, fd) != 1) + printf("Writing failed\n"); fclose(fd); return 0; @@ -147,9 +165,11 @@ int flash_callback(struct header_t *header) return 1; } - type = (char *)fpid_file(header->name); + type = header->type; + if (!type[0]) + type = (char *)fpid_file(header->name); printf("\nFlashing %s (%s)\n", header->name, type); - flash_image(header->name, type, NULL); + flash_image(header->name, type, header->device, header->hwrevs, header->version); return 0; } @@ -158,7 +178,7 @@ void unpack_fiasco_image(char *file) { printf("Dumping firmware pieces to disk.\n"); fiasco_callback = &unpack_callback; - openfiasco(file, NULL ,1); + openfiasco(file, NULL, NULL, NULL, NULL, 0); } int fiasco_flash(const char *file) @@ -166,10 +186,10 @@ int fiasco_flash(const char *file) char *p; char version[64]; - if (connect_via_usb()) { - fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n"); - return 0; - } + if (connect_via_usb()) { + fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n"); + return 0; + } // if (info) cmd_info(""); @@ -190,11 +210,11 @@ int fiasco_flash(const char *file) printf("\n"); fiasco_callback = &flash_callback; - openfiasco(file, "xloader", 0); - openfiasco(file, "secondary", 0); - openfiasco(file, "kernel", 0); - openfiasco(file, "initfs", 0); - openfiasco(file, "rootfs", 0); + openfiasco(file, "xloader", NULL, NULL, NULL, 0); + openfiasco(file, "secondary", NULL, NULL, NULL, 0); + openfiasco(file, "kernel", NULL, NULL, NULL, 0); + openfiasco(file, "initfs", NULL, NULL, NULL, 0); + openfiasco(file, "rootfs", NULL, NULL, NULL, 0); return 0; } @@ -203,67 +223,75 @@ int fiasco_flash(const char *file) int connect_via_usb() { static char pbc[]={'/','-','\\', '|'}; - struct usb_device_descriptor udd; - struct devices it_device; + struct usb_device_descriptor udd; + struct devices it_device; int c = 0; // usb_set_debug(5); usb_init(); - /* Tries to get access to the Internet Tablet and retries - * if any of the neccessary steps fail. - * - * Note: While a proper device may be found on the bus it may - * not be in the right state to be accessed (e.g. the Nokia is - * not in the boot stage any more). - */ + /* Tries to get access to the Internet Tablet and retries + * if any of the neccessary steps fail. + * + * Note: While a proper device may be found on the bus it may + * not be in the right state to be accessed (e.g. the Nokia is + * not in the boot stage any more). + */ while(!dev) { usleep(0xc350); // 0.5s - - if(!usb_device_found(&udd, &it_device)) { + + if(!usb_device_found(&udd, &it_device)) { printf("\rWaiting for device... %c", pbc[++c%4]); fflush(stdout); continue; } - /* open device */ - if(!(dev = usb_open(device))) { - perror("usb_open"); - return 1; - } - - if ( usb_claim_interface(dev, 2) < 0) { - //device->config->interface->altsetting->bInterfaceNumber) < 0) { // 2 or 0 - D perror("usb_claim_interface"); - - // Something is broken if closing fails. - if(usb_close(dev)) { - perror("usb_close"); - return 1; - } + /* open device */ + if(!(dev = usb_open(device))) { + perror("usb_open"); + return 1; + } - dev = NULL; +#if 1 +{ +char name[32]; +name[0] = '\0'; +usb_get_driver_np(dev, 2, name, sizeof(name)); +printf ("Driver: %s\n", name); +usb_detach_kernel_driver_np(dev, 2); +} +#endif + if (usb_claim_interface(dev, 2) < 0) { + //device->config->interface->altsetting->bInterfaceNumber) < 0) { // 2 or 0 + perror("usb_claim_interface"); - // Try again later. - continue; - } + // Something is broken if closing fails. + if(usb_close(dev)) { + perror("usb_close"); + return 1; + } + dev = NULL; + // Try again later.? + exit(1); + } - if (usb_set_altinterface(dev, 1) <0) { //device->config->interface->altsetting->bAlternateSetting) < 0) { - D perror("usb_set_altinterface"); + if (usb_set_altinterface(dev, 1) <0) { //device->config->interface->altsetting->bAlternateSetting) < 0) { + perror("usb_set_altinterface"); - // Something is broken if closing fails. - if(usb_close(dev)) { - perror("usb_close"); - return 1; - } + // Something is broken if closing fails. + if(usb_close(dev)) { + perror("usb_close"); + return 1; + } - dev = NULL; - // Try again later. - continue; - } - } + dev = NULL; + // Try again later. + continue; + } + break; + } - printf("found %s (%04x:%04x)\n", it_device.name, + printf("found %s (%04x:%04x)\n", it_device.name, it_device.vendor_id, it_device.product_id); /* go go go! */ @@ -278,11 +306,12 @@ int connect_via_usb() int main(int argc, char **argv) { int c; + const char *type; while((c = getopt(argc, argv, "QC:cp:PvVhRu:ib:U:r:e:ld:I:D:f:F:s:xH:S:n")) != -1) { switch(c) { case 'H': - printf("xorpair: %04x\n", do_hash_file(optarg)); + printf("xorpair: %04x\n", do_hash_file(optarg, NULL)); return 0; case 'x': return dump_config(); @@ -306,8 +335,8 @@ int main(int argc, char **argv) break; case 'd': sscanf(optarg, "%04hx:%04hx", - &supported_devices[SUPPORTED_DEVICES-2].vendor_id, - &supported_devices[SUPPORTED_DEVICES-2].product_id); + &supported_devices[SUPPORTED_DEVICES-2].vendor_id, + &supported_devices[SUPPORTED_DEVICES-2].product_id); supported_devices[SUPPORTED_DEVICES-2].name = strdup("user"); break; case 'D': @@ -315,14 +344,14 @@ int main(int argc, char **argv) break; case 'f': if (!strcmp(optarg,"help")) { - printf("* Flags are composed of:\n"); - printf(" 0x02 - disable OMAP watchdog (possibly)\n"); - printf(" 0x04 - disable RETU watchdog (possibly)\n"); - printf(" 0x08 - disable lifeguard reset\n"); - printf(" 0x10 - enable serial console\n"); - printf(" 0x20 - disable USB timeout\n"); - exit(1); - } + printf("* Flags are composed of:\n"); + printf(" 0x02 - disable OMAP watchdog (possibly)\n"); + printf(" 0x04 - disable RETU watchdog (possibly)\n"); + printf(" 0x08 - disable lifeguard reset\n"); + printf(" 0x10 - enable serial console\n"); + printf(" 0x20 - disable USB timeout\n"); + exit(1); + } rd_flags = (unsigned short) strtoul(optarg, NULL, 16); break; case 'r': @@ -356,7 +385,10 @@ int main(int argc, char **argv) case 'P': return fiasco_pack(optind, argv); case 'I': - printf("%s: %s\n", fpid_file(optarg), optarg); + type = fpid_file(optarg); + printf("%s: %s\n", type, optarg); + if (type && strcmp(type, "fiasco") == 0) + openfiasco(optarg, NULL, NULL, NULL, NULL, 1); identify = 1; break; case 'C': @@ -383,7 +415,7 @@ int main(int argc, char **argv) return 0; // flags ok? - if ( (fiasco_image == NULL) + if ( (fiasco_image == NULL) && (boot_cmdline == NULL) && (reverseto == NULL) && (pcs_n == 0) @@ -396,15 +428,19 @@ int main(int argc, char **argv) { printf("# The Free Fiasco Firmware Flasher v"VERSION"\n" - "0xFFFF [-chinlQRvVx] [-C mtd-dev] [-d vid:pid] [-D 0|1|2] [-e path] [-f flags]\n" - " [-F fiasco] [-H hash-file] [-I piece] [-p [piece%%]file]] [-r 0|1] [-S subver]\n" - " [-s serial-dev] [-u fiasco-image] [-U 0|1] | [-P new-fiasco] [piece1] [2] ..\n"); + "0xFFFF [-chinlQRvVx] [-C mtd-dev] [-d vid:pid] [-D 0|1|2] [-e path] [-f flags]\n" + " [-F fiasco] [-H hash-file] [-I piece] [-p [piece%%]file]] [-r 0|1] [-S subver]\n" + " [-s serial-dev] [-u fiasco-image] [-U 0|1] | [-P new-fiasco] [piece1] [2] ..\n"); return 1; } if (unpack) { - if (reverseto) - chdir(reverseto); + if (reverseto) { + if (chdir(reverseto) < 0) { + printf("Error: Cannot change directory to %s\n", reverseto); + return 1; + } + } unpack_fiasco_image(fiasco_image); return 0; } @@ -415,14 +451,14 @@ int main(int argc, char **argv) } #if HAVE_USB - if (connect_via_usb()) { - fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n"); - return 0; - } + if (connect_via_usb()) { + fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n"); + return 0; + } // if (info) cmd_info(""); - + if (pcs_n) { char version[64]; check_nolo_order(); @@ -440,15 +476,15 @@ int main(int argc, char **argv) for(c=0;c<pcs_n;c++) { printf("Flashing %s (%s)\n", pcs[c].type, pcs[c].name); - flash_image(pcs[c].name, pcs[c].type, pcs[c].vers); + flash_image(pcs[c].name, pcs[c].type, pcs[c].device, pcs[c].hwrevs, pcs[c].version); } } if (rd_mode != -1) - set_rd_mode(rd_mode); - + set_rd_mode(rd_mode); + if (rd_flags != -1) - set_rd_flags(rd_flags); + set_rd_flags(rd_flags); if (root_device != -1) set_root_device(root_device); |