From 01a7da1d95fc37c2c28d94ef7519117a7f7f3903 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Thu, 9 Aug 2012 21:02:20 +0200 Subject: Rename flash.c to nolo.c --- src/Makefile | 2 +- src/flash.c | 222 --------------------------------------------------------- src/main.h | 10 +-- src/nolo.c | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/nolo.h | 27 +++++++ 5 files changed, 260 insertions(+), 230 deletions(-) delete mode 100644 src/flash.c create mode 100644 src/nolo.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 8760fb5..eb70167 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ include ../config.mk -OBJ=main.o hexdump.o dump.o flash.o serial.o qmode.o +OBJ=main.o hexdump.o dump.o nolo.o serial.o qmode.o OBJ+=query.o utils.o console.o OBJ+=squeue/squeue.o OBJ+=image.o fiasco.o device.o usb-device.o cold-flash.o diff --git a/src/flash.c b/src/flash.c deleted file mode 100644 index 503fa40..0000000 --- a/src/flash.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if HAVE_USB -#include "main.h" -#include "hexdump.h" -#include -#include -#include - -#include "image.h" - -/*void check_nolo_order_failed() -{ - fprintf(stderr, "\nERROR: Provide xloader before the secondary. NOLO disagrees anything else.\n"); - fprintf(stderr, "Use: -p xloader.bin -p secondary.bin\n"); - exit(1); -}*/ - -void query_error_message() -{ - /* query error message */ - int len = 0; - char nolomsg[2048]; - memset(nolomsg, '\0', 2048); - usb_control_msg(dev, 192, 5, 0, 0, nolomsg, 2048, 2000); - nolomsg[2047] = '\0'; - printf("\nNOLO says:\n"); - if (nolomsg[0] == '\0') { - printf(" (.. silence ..)\n"); - } else { - dump_bytes((unsigned char *)nolomsg, 128); - do { - printf(" - %s\n", nolomsg+len); - len+=strlen(nolomsg+len)+1; - } while(nolomsg[len]!='\0'); - } -} - -/*void check_nolo_order() -{ - int i, xlo = 0; - - for(i=0;itype); - const char * version = image->version; - ushort hash = image->hash; - -// 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 (piece != NULL) { - if (!strcmp(piece, "fiasco")) { - fiasco_flash(filename); - return; - } - }*/ - - if (version) - vlen = strlen(version)+1; - -// fd = fopen(filename, "rb"); -// if (fd == NULL) { -// printf("Cannot open file\n"); -// exit(1); -// } - /* cook flash query */ - memset(fquery, '\x00', 27); // reset buffer - memcpy(fquery, "\x2e\x19\x01\x01", 4); // header - //memcpy(fquery+5, "\xbf\x6b", 2); // some magic (modified crc16???) - memcpy(fquery+5, &hash, 2); - tmp = fquery[5]; fquery[5] = fquery[6]; fquery[6] = tmp; - memcpy(fquery+7, piece, strlen(piece)); // XXX ??!?? - - printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]); -// size = get_file_size(filename); - size = image->size; - bsize[0] = (size & 0xff000000) >> 24; - bsize[1] = (size & 0x00ff0000) >> 16; - bsize[2] = (size & 0x0000ff00) >> 8; - bsize[3] = (size & 0x000000ff); - printf("size: %lld (%02x %02x %02x %02x)\n", - size, bsize[0], bsize[1], bsize[2], bsize[3]); - memcpy(fquery+0x13, &bsize, 4); - if (vlen) memcpy(fquery+27, version, vlen); - - if (!strcmp(piece, "rootfs")) - request = 85; - else request = 68; - - //dump_bytes(fquery, 27+vlen); - if (usb_control_msg(dev, CMD_WRITE, request, 0, 0, (char *)fquery, 27+vlen, 2000) <0) { - query_error_message(); - perror("flash_image.header"); - exit(1); - } - - /*/ cook and bulk nollo filler */ - memset(&nolofiller, '\xff', 128); - memcpy(nolofiller+0x00, "NOLO filler", 11); - memcpy(nolofiller+0x40, "NOLO filler", 11); - usb_bulk_write(dev, 2, (char *)nolofiller, 128, 5000); - usb_bulk_write(dev, 2, (char *)nolofiller, 0, 5000); - - /*/ bulk write image here */ - printf("[=] Bulkwriting the %s piece...\n", piece); - fflush(stdout); - - #define BSIZE 0x20000 - - for(off = 0; offBSIZE) bsize = BSIZE; -// bread = fread(buf, bsize, 1, fd); - bread = image_read(image, buf, bsize); - if (bread != 1) - printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize); - bread = usb_bulk_write(dev, 2, buf, bsize, 5000); - if (bread == 64) { - query_error_message(); -// fclose(fd); - return; - } - progressbar(off, size); - if (bread<0) { - printf("\n"); - perror(" -ee- "); -// fclose(fd); - return; - } - fflush(stdout); - } -// fclose(fd); - /*/ EOF */ - usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000); - progressbar(1, 1); - printf("\n"); - - // index = 4???? - if (!strcmp(piece, "rootfs")) { - if (usb_control_msg(dev, CMD_WRITE, 82, 0, 0, (char *)fquery, 0, 30000)<0) { - fprintf(stderr, "Oops. Invalid checksum?\n"); - exit(1); - } - } else { - int t = 0; - if (!strcmp(piece, "secondary")) - t = 1; - else - if (!strcmp(piece, "kernel")) - t = 3; - else - if (!strcmp(piece, "initfs")) - t = 4; - if (!strcmp(piece, "xloader")) - printf("xloader flashed not commiting until secondary arrives...\n"); - else - if (usb_control_msg(dev, CMD_WRITE, 80, 0, t, (char *)fquery, 0, 10000)<0) { - fprintf(stderr, "Oops. Invalid checksum?\n"); - exit(1); - } - } - - // unknown query !! :"" - if (usb_control_msg(dev, CMD_WRITE, 67, 0, 0, (char *)fquery, 0, 2000)<0) { - fprintf(stderr, "Oops, the flash was denied or so :/\n"); - exit(1); - } - printf("Flash done succesfully.\n"); -} -#endif diff --git a/src/main.h b/src/main.h index e88264e..e26b0a4 100644 --- a/src/main.h +++ b/src/main.h @@ -21,7 +21,6 @@ struct image; int queue_mode(); int reverse_extract_pieces(char *dir); //void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version); -void flash_image(struct image * image); int fiasco_read_image(char *file); //void check_nolo_order(); extern struct usb_dev_handle *dev; @@ -39,7 +38,7 @@ void eprintf(const char *format, ...); #if HAVE_USB #include -int fiasco_flash(const char *file); +//int fiasco_flash(const char *file); extern struct usb_device *device; extern struct usb_dev_handle *dev; int is_valid_device(struct usb_device_descriptor *udd); @@ -59,9 +58,6 @@ int dump_config(); extern int verbose; #define D if (verbose) -#define CMD_WRITE 64 -#define CMD_QUERY 192 - /*struct piece_t { char *name; char *type; @@ -70,12 +66,12 @@ extern int verbose; char *version; };*/ -enum flash_mode { +/*enum flash_mode { FLASH_COLD, FLASH_NORMAL, FLASH_MKII, FLASH_DISK, -}; +};*/ /*struct devices { char *name; diff --git a/src/nolo.c b/src/nolo.c new file mode 100644 index 0000000..6be4f86 --- /dev/null +++ b/src/nolo.c @@ -0,0 +1,229 @@ +/* + * 0xFFFF - Open Free Fiasco Firmware Flasher + * Copyright (C) 2007 pancake + * Copyright (C) 2012 Pali Rohár + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include + +#include "nolo.h" +#include "image.h" + +#include "hexdump.h" + +#define CMD_WRITE 64 +#define CMD_QUERY 192 + +extern struct usb_dev_handle *dev; + +/*void check_nolo_order_failed() +{ + fprintf(stderr, "\nERROR: Provide xloader before the secondary. NOLO disagrees anything else.\n"); + fprintf(stderr, "Use: -p xloader.bin -p secondary.bin\n"); + exit(1); +}*/ + +static void query_error_message() +{ + /* query error message */ + int len = 0; + char nolomsg[2048]; + memset(nolomsg, '\0', 2048); + usb_control_msg(dev, 192, 5, 0, 0, nolomsg, 2048, 2000); + nolomsg[2047] = '\0'; + printf("\nNOLO says:\n"); + if (nolomsg[0] == '\0') { + printf(" (.. silence ..)\n"); + } else { + dump_bytes((unsigned char *)nolomsg, 128); + do { + printf(" - %s\n", nolomsg+len); + len+=strlen(nolomsg+len)+1; + } while(nolomsg[len]!='\0'); + } +} + +/*void check_nolo_order() +{ + int i, xlo = 0; + + for(i=0;itype); + const char * version = image->version; + ushort hash = image->hash; + +// 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 (piece != NULL) { + if (!strcmp(piece, "fiasco")) { + fiasco_flash(filename); + return; + } + }*/ + + if (version) + vlen = strlen(version)+1; + +// fd = fopen(filename, "rb"); +// if (fd == NULL) { +// printf("Cannot open file\n"); +// exit(1); +// } + /* cook flash query */ + memset(fquery, '\x00', 27); // reset buffer + memcpy(fquery, "\x2e\x19\x01\x01", 4); // header + //memcpy(fquery+5, "\xbf\x6b", 2); // some magic (modified crc16???) + memcpy(fquery+5, &hash, 2); + tmp = fquery[5]; fquery[5] = fquery[6]; fquery[6] = tmp; + memcpy(fquery+7, piece, strlen(piece)); // XXX ??!?? + + printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]); +// size = get_file_size(filename); + size = image->size; + bsize[0] = (size & 0xff000000) >> 24; + bsize[1] = (size & 0x00ff0000) >> 16; + bsize[2] = (size & 0x0000ff00) >> 8; + bsize[3] = (size & 0x000000ff); + printf("size: %lld (%02x %02x %02x %02x)\n", + size, bsize[0], bsize[1], bsize[2], bsize[3]); + memcpy(fquery+0x13, &bsize, 4); + if (vlen) memcpy(fquery+27, version, vlen); + + if (!strcmp(piece, "rootfs")) + request = 85; + else request = 68; + + //dump_bytes(fquery, 27+vlen); + if (usb_control_msg(dev, CMD_WRITE, request, 0, 0, (char *)fquery, 27+vlen, 2000) <0) { + query_error_message(); + perror("flash_image.header"); + exit(1); + } + + /*/ cook and bulk nollo filler */ + memset(&nolofiller, '\xff', 128); + memcpy(nolofiller+0x00, "NOLO filler", 11); + memcpy(nolofiller+0x40, "NOLO filler", 11); + usb_bulk_write(dev, 2, (char *)nolofiller, 128, 5000); + usb_bulk_write(dev, 2, (char *)nolofiller, 0, 5000); + + /*/ bulk write image here */ + printf("[=] Bulkwriting the %s piece...\n", piece); + fflush(stdout); + + #define BSIZE 0x20000 + + for(off = 0; offBSIZE) bsize = BSIZE; +// bread = fread(buf, bsize, 1, fd); + bread = image_read(image, buf, bsize); + if (bread != 1) + printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize); + bread = usb_bulk_write(dev, 2, buf, bsize, 5000); + if (bread == 64) { + query_error_message(); +// fclose(fd); + return; + } + progressbar(off, size); + if (bread<0) { + printf("\n"); + perror(" -ee- "); +// fclose(fd); + return; + } + fflush(stdout); + } +// fclose(fd); + /*/ EOF */ + usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000); + progressbar(1, 1); + printf("\n"); + + // index = 4???? + if (!strcmp(piece, "rootfs")) { + if (usb_control_msg(dev, CMD_WRITE, 82, 0, 0, (char *)fquery, 0, 30000)<0) { + fprintf(stderr, "Oops. Invalid checksum?\n"); + exit(1); + } + } else { + int t = 0; + if (!strcmp(piece, "secondary")) + t = 1; + else + if (!strcmp(piece, "kernel")) + t = 3; + else + if (!strcmp(piece, "initfs")) + t = 4; + if (!strcmp(piece, "xloader")) + printf("xloader flashed not commiting until secondary arrives...\n"); + else + if (usb_control_msg(dev, CMD_WRITE, 80, 0, t, (char *)fquery, 0, 10000)<0) { + fprintf(stderr, "Oops. Invalid checksum?\n"); + exit(1); + } + } + + // unknown query !! :"" + if (usb_control_msg(dev, CMD_WRITE, 67, 0, 0, (char *)fquery, 0, 2000)<0) { + fprintf(stderr, "Oops, the flash was denied or so :/\n"); + exit(1); + } + printf("Flash done succesfully.\n"); +} diff --git a/src/nolo.h b/src/nolo.h index f0a71a4..9eb38a2 100644 --- a/src/nolo.h +++ b/src/nolo.h @@ -1,3 +1,28 @@ +/* + * 0xFFFF - Open Free Fiasco Firmware Flasher + * Copyright (C) 2007 pancake + * Copyright (C) 2012 Pali Rohár + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NOLO_H +#define NOLO_H + +#include "image.h" + +void nolo_flash_image(struct image * image); #define NOLO_GET_STATUS 1 #define NOLO_GET_BOARD_ID 2 @@ -5,3 +30,5 @@ #define NOLO_GET_HWVERSION 4 #define NOLO_SET_RDFLAGS 16 #define NOLO_GET_RDFLAGS 17 + +#endif -- cgit v1.2.3