diff options
author | pancake@localhost.localdomain <pancake@localhost.localdomain> | 2009-10-17 15:43:39 +0200 |
---|---|---|
committer | pancake@localhost.localdomain <pancake@localhost.localdomain> | 2009-10-17 15:43:39 +0200 |
commit | 034b17cef42f293e2048b44c074d70b3a8695339 (patch) | |
tree | 06db2c1574121ff389fe159bccae6123676cd3bb | |
parent | 3a1053b29e5fb8109463259ee9dff3d8f4e4be5b (diff) | |
download | 0xFFFF-034b17cef42f293e2048b44c074d70b3a8695339.tar.bz2 |
* Added support for local n900 nand dump * Do some code cleanup, update headers from 2007 to 2009 :) - Fix warning messages
-rw-r--r-- | src/devices.c | 44 | ||||
-rw-r--r-- | src/dump.c | 67 | ||||
-rw-r--r-- | src/fiasco.c | 2 | ||||
-rw-r--r-- | src/main.h | 3 |
4 files changed, 82 insertions, 34 deletions
diff --git a/src/devices.c b/src/devices.c index 2691770..2ffdfde 100644 --- a/src/devices.c +++ b/src/devices.c @@ -1,6 +1,6 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2007-2009 pancake <pancake@nopcode.org> * * 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 @@ -32,13 +32,16 @@ * boot os * n770 0421:0105 0421:0431 * n800 0421:0431 + * n900 0421:0105 0421:01c7 * */ struct devices supported_devices[SUPPORTED_DEVICES] = { { "FFFF", 0x000, 0x0000, 0x0000 }, // dummy { "unkn", 0x421, 0x3f00, 0x0000 }, // probably a development board - { "n770/n810", 0x421, 0x0105, 0x0001 }, // my n770 + { "n770/n810/n900", 0x421, 0x0105, 0x0001 }, { "n800", 0x421, 0x04c3, 0x0001 }, // a n800 +// { "n900", 0x421, 0x01c7, 0x0001 }, // a pre-production n900 +// { "n900", 0x421, 0x0105, 0x0001 }, // a pre-production n900 { 0 }, { 0 } }; @@ -82,39 +85,30 @@ void list_valid_devices() * structures for the specified device. * Otherwise returns false (0) */ - int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device) { + int dev_index = 0; struct usb_bus *bus; - int dev_index = 0; - - if (usb_find_busses() < 0) { - fprintf(stderr, "\nerror: no usb busses found.\n"); + if ((usb_find_busses()<0) || (usb_find_devices()==-1)) { + fprintf(stderr, "\nerror: no usb bus or device found.\n"); exit(1); } else { - switch(usb_find_devices()) { - case -1: - fprintf(stderr, "\nerror: no devices found.\n"); - exit(1); - default: - for (bus = usb_busses; bus; bus = bus->next) { - struct usb_device *dev = bus->devices; - D printf("bus: \n"); - for (; dev; dev = dev->next) { - *udd = dev->descriptor; - D printf(" dev (%s) - ", dev->filename); - D printf("vendor: %04x product: %04x\n", udd->idVendor, udd->idProduct); + for (bus = usb_busses; bus; bus = bus->next) { + struct usb_device *dev = bus->devices; + D printf("bus: \n"); + for (; dev; dev = dev->next) { + *udd = dev->descriptor; + D printf(" dev (%s) - ", dev->filename); + D printf("vendor: %04x product: %04x\n", udd->idVendor, udd->idProduct); - if ((dev_index = is_valid_device(udd))) { - device = dev; - *it_device = supported_devices[dev_index]; - return 1; - } + if ((dev_index = is_valid_device(udd))) { + device = dev; + *it_device = supported_devices[dev_index]; + return 1; } } } } - return 0; } #endif @@ -1,6 +1,6 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2007-2009 pancake <pancake@nopcode.org> * * 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 @@ -161,6 +161,7 @@ int check_badblocks(char *mtddev) unsigned char oobbuf[64]; struct nand_oobinfo old_oobinfo; struct mtd_oob_buf oob = {0, 16, oobbuf}; + /* XXX stat1 is never initialized !!! */ struct mtd_ecc_stats stat1, stat2; mtd_info_t meminfo; @@ -176,7 +177,6 @@ int check_badblocks(char *mtddev) fprintf(stderr, "Size %u, flags %u, type 0x%x\n", meminfo.size, meminfo.flags, (int)meminfo.type); - oob.length = meminfo.oobsize; for(i = 0; i < meminfo.size; i+= meminfo.writesize) { @@ -245,6 +245,7 @@ closeall: } // XXX warning ioob is not used +// isbl is used to skip bad blocks ? int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char *dumpfile, int isbl, int ioob) { unsigned char readbuf[2048]; @@ -453,22 +454,35 @@ __done: return 1; } -int is_n800() +static int is_n900() { int n800 = 0; unsigned char buf[4]; FILE *fd = fopen("/dev/mtd0", "rb"); - if (!fd) { fprintf(stderr, "Cannot open /dev/mtd0.\n"); exit(1); } - fread(buf, 4, 1,fd); + fread(buf, 4, 1, fd); if (!memcmp("\xff\xff\xff\xff", buf, 4)) n800 = 1; - fclose(fd); + return n800; +} +static int is_n800() +{ + int n800 = 0; + unsigned char buf[4]; + FILE *fd = fopen("/dev/mtd2", "rb"); + if (!fd) { + fprintf(stderr, "Cannot open /dev/mtd2.\n"); + exit(1); + } + fread(buf, 4, 1, fd); + if (!memcmp("\xff\xff\xff\xff", buf, 4)) + n800 = 1; + fclose(fd); return n800; } @@ -539,9 +553,50 @@ int dump_config() return 0; } +int reverse_extract_pieces_n900(char *dir) +{ + char reply; + chdir(dir); + printf("Device detected: n900\n"); + // Some of the values here are probably not correct + // I need a firmware to identify if the sizes of the pieces are ok + + nanddump("/dev/mtd0", 0, 0, "xloader.bin", 1, 0); // fix size? + nanddump("/dev/mtd1", 0, 0, "config.bin", 1, 0); + nanddump("/dev/mtd3", 0, 0, "nolo.bin", 0, 0); + + printf("\n\nExtract rootfs? (y/N): "); fflush(stdout); + read(0, &reply, 1); + if (reply=='y'||reply=='Y') { + //rf_extract("/dev/mtd4", 0x000000, 0x6000000, "rootfs.jffs2"); + nanddump("/dev/mtd5", 0x000000, 0, "rootfs.jffs2", 0,0); + } else printf("*** Ignoring rootfs\n"); + + printf("\n\nStrip dumped files? (y/N): "); fflush(stdout); + read(0, &reply, 1); + if (reply=='y'||reply=='Y') { + rf_strip("xloader.bin"); + rf_strip("config.bin"); + rf_strip("nolo.bin"); + } else printf("*** Ignoring strip\n"); + + printf("\nIdentifying extracted files...\n"); + printf("%s: xloader\n", fpid_file("xloader.bin")); + printf("%s: config.bin\n", fpid_file("config.bin")); + printf("%s: nolo.bin\n", fpid_file("nolo.bin")); + printf("%s: rootfs.jffs2\n", fpid_file("rootfs.jffs2")); + + return 1; +} + int reverse_extract_pieces(char *dir) { char reply; + + if (n900) + return reverse_extract_pieces_n900(dir); + + printf("Device detected: n770/n800/n900\n"); chdir(dir); // TODO: get values from /proc/mtd ??? diff --git a/src/fiasco.c b/src/fiasco.c index 3e9da9f..9d805a2 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, char *piece_grep, int v) +int openfiasco(char *name, const char *piece_grep, int v) { struct header_t header; unsigned char buf[128]; @@ -56,7 +56,6 @@ extern int verbose; #define CMD_WRITE 64 #define CMD_QUERY 192 - struct piece_t { char *name; char *type; @@ -103,7 +102,7 @@ extern char *modes[]; extern char *root_devices[]; // fiasco -int openfiasco(char *name, char *grep, int v); +int openfiasco(char *name, const char *grep, int v); int fiasco_new(const char *filename, const char *name); void fiasco_data_read(struct header_t *header); int fiasco_add_eof(int fd); |