4 Commits
Author SHA1 Message Date
pancake a215967e38 Import version 0.3 from tarball 0xFFFF-0.3.tar.gz 2007-10-20 02:32:24 +02:00
pancake fbdac811fc * Make the fiasco writing api work (some hardcoded things, but mostly ok)
* Move documentation of fiasco format to doc/
* 0.3 release
2007-10-20 02:32:24 +02:00
pancake d15412a788 * Add documentation for the FIASCO format
* Initial fiasco writer api
* Lot of new checks and code cleanup
* fiasco callback now receives a filedescriptor inside header_t
  - the lseek and data free is autonatically done by the main loop
* Split fiasco_data_read() code, useful for streams (embeddeds low mem footprint)
* Add '-P' flag to create a new fiasco pack
2007-10-11 03:14:11 +02:00
pancake 85fdbfb354 * Finally implement the support for the FIASCO firmware format
* Up version to 0.3
* Alphabetically order the help message flags
* Cleaner short help message
* Pseudo-api for creating firmwares (not yet finished)
* Add '-F' flag to flash from a fiasco image
2007-10-08 00:25:56 +02:00
8 changed files with 382 additions and 138 deletions

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
SPECS FOR TEH FIASCO FIRMWARE FILE FORMAT ffff!
-----------------------------------------------
These notes has not been taken properly and may be wrong. It must
be revised to fit the reality. But this is mostly a general idea:
FILE HEADER
1 byte = 0xb4 -- signature
4 bytes -- firmware name length (big endian)
6 bytes -- versioning info ( byte 4 is format version )
N-6 bytes -- firmware name (zero fill)
PIECE HEADER
1 byte = 0x54 -- piece signature
6 bytes -- unknown
2 bytes -- checksum for the piece contents (xorpair)
12 bytes -- piece name (first byte is FF if is the last)
4 bytes -- piece size (big endian)
4 bytes -- unknown
block {
1 byte -- if (value '1'-'9') { ..there's a comment.. }
1 byte -- length of comment
N bytes -- comment
}
N bytes -- piece data
+17 -14
View File
@@ -8,6 +8,7 @@ Tablets (n770 and n800).
- reboot de mother board
- extract the current firmware pieces from the device (dump)
- set the USB host/slave mode
- pack/unpack fiasco firmwares
- fine grained R&D flags support
- identify firmware pieces
- dump mtd partitions (embedded mtd-utils source code)
@@ -19,27 +20,29 @@ Tablets (n770 and n800).
This is the help message of the tool:
<pre>
<b>~$ 0xFFFF -h</b>
0xFFFF v0.2 // The Free Fiasco Firmware Flasher
0xFFFF v0.3 // The Free Fiasco Firmware Flasher
-b [arg] boots the kernel with arguments
-e [path] dump and extract pieces to path
-r [0|1] disable/enable R&D mode
-f <flags> set the given RD flags (see '-f help')
-p [[p%]file] piece-of-firmware % file-where-this-piece-is
-u [fiasco] unpack target fiasco image
-U [0|1] disable/enable the usb host mode
-s [serial] serial port console (minicom like terminal)
-C [/dev/mtd] check bad blocks on mtd
-c console prompt mode
-h show this help message
-i show device information (let standby mode)
-I [piece] identify a firmware piece
-l list supported usb device ids
-C [/dev/mtd] check bad blocks on mtd
-d [vid:pid] injects a usb device into the supported list
-D [0|1|2] sets the root device to flash (0), mmc (1) or usb (2)
-e [path] dump and extract pieces to path
-f <flags> set the given RD flags (see '-f help')
-F [fiasco] flash a fiasco firmware image
-h show this help message
-H [file] calculate hash for file
-i show device information (let standby mode)
-I [piece] identify a firmware piece
-l, -L list supported usb device ids
-p [[p%]file] piece-of-firmware % file-where-this-piece-is
-r [0|1] disable/enable R&D mode
-R reboot the omap board
-x extract configuration entries from /dev/mtd1
-s [serial] serial port console (minicom like terminal)
-u [fiasco] unpack target fiasco image
-U [0|1] disable/enable the usb host mode
-v be verbose and noisy
-V show 0xFFFF version information
-x extract configuration entries from /dev/mtd1
Pieces are: xloader secondary kernel initfs rootfs omap-nand
</pre>
+2 -2
View File
@@ -1,8 +1,8 @@
OBJ=main.o
BIN=goxf
CFLAGS=`pkg-config gladeui-1.0 libglade-2.0 --cflags`
LDFLAGS=`pkg-config gladeui-1.0 libglade-2.0 --libs`
CFLAGS=`pkg-config libgladeui-1.0 libglade-2.0 --cflags`
LDFLAGS=`pkg-config libgladeui-1.0 libglade-2.0 --libs`
all: ${OBJ}
${CC} ${LDFLAGS} ${OBJ} -o ${BIN}
+1 -1
View File
@@ -1,4 +1,4 @@
VERSION=0.2
VERSION=0.3
OBJ=main.o fiasco.o hexdump.o dump.o flash.o serial.o
OBJ+=hash.o fpid.o query.o pieces.o utils.o devices.o console.o
BIN=0xFFFF
+249 -90
View File
@@ -16,119 +16,278 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include "main.h"
#include "hash.h"
#warning The FIASCO format is not yet fully implemented.
void (*fiasco_callback)(struct header_t *header) = NULL;
off_t piece_header_to_size(unsigned char *header)
int openfiasco(char *name)
{
off_t sz = 0;
sz += header[0x15+3];
sz += header[0x15+2] << 8;
sz += header[0x15+1] << 16;
sz += header[0x15+0] << 24;
return sz;
}
struct header_t header;
unsigned char buf[128];
unsigned char data[128];
unsigned int namelen;
off_t off;
int i;
header.fd = open(name, O_RDONLY);
int piece_header_is_valid(unsigned char *header)
{
if (header[0]=='T' && header[1]=='\x02')
if (header.fd == -1) {
fprintf(stderr, "Cannot open %s\n", name);
return 1;
}
/* read header */
read(header.fd, buf, 5);
if (buf[0] != 0xb4) {
printf("Invalid header\n");
return close(header.fd);
}
memcpy(&namelen,buf+1,4);
namelen = ntohl(namelen);
if (namelen>128) {
printf("Stupid length at header. Is this a joke?\n");
return close(header.fd);
}
memset(buf,'\0', 128);
read(header.fd, buf, namelen);
printf("Fiasco version: %2d\n", buf[3]);
strcpy(header.fwname, buf+6);
for(i=6;i<namelen;i+=strlen(buf+i)+1)
printf("Name: %s\n", buf+i);
/* walk the tree */
while(1) {
if (read(header.fd, buf, 9)<9)
break;
if (buf[0] != 0x54) { // 'T'
printf("unexpected header at 0x%x, found %02x %02x %02x\n",
((int)lseek(header.fd, 0, SEEK_CUR))-9,
buf[0], buf[1], buf[2]);
break;
}
header.hash = buf[7]<<8|buf[8];
/* piece name */
memset(data, '\0', 13);
if (read(header.fd, data, 12)<12)
break;
if (data[0] == 0xff) {
printf(" [eof]\n");
break;
} else printf(" %s\n", data);
strcpy(header.name, data);
if (read(header.fd, buf, 9)<9)
break;
memcpy(&header.size, buf,4);
header.size = ntohl(header.size);
printf(" size: %d bytes\n", header.size);
printf(" hash: %04x\n", header.hash);
//printf("BYTE: %02x %02x %02x %02x %02x\n",
// buf[4], buf[5], buf[6], buf[7], buf[8]);
/* XXX this is not ok */
//printf("BUF8: %02x\n", buf[8]);
while (buf[8] && buf[8]>'0' && buf[8] < '9') {
if (read(header.fd, data, 1)<1)
break;
i = data[0];
if (read(header.fd, data, i)<i)
break;
if (data[0])
printf(" version: %s\n", data);
strcpy(header.version, data);
if (read(header.fd, buf+8, 1)<1)
break;
}
/* callback */
off = lseek(header.fd, 0, SEEK_CUR);
if (fiasco_callback != NULL) {
fiasco_callback(&header);
free(header.data);
continue;
}
// XXX dup
lseek(header.fd, off, SEEK_SET);
lseek(header.fd, header.size, SEEK_CUR);
}
return 0;
}
#define piece_header_to_name(x) x+0x9;
void fiasco_data_read(struct header_t *header)
{
header->data = (char *)malloc(header->size);
if (header->data == NULL) {
printf("Cannot alloc %d bytes\n", header->size);
return;
}
read(header->fd, header->data, header->size);
}
/*
* Teh Fiasco firmware parser lives here!
*/
int fiasco_read_image(char *file)
/* fiasco writer */
int fiasco_new(const char *filename, const char *name)
{
int fd;
unsigned char header[5];
unsigned char version[55];
char *version2;
//int len = htonl(strlen(name)+1+6+14);
fd = open(file, O_RDONLY);
printf("WARNING: Fiasco firmware is not yet fully supported. Don't relay on it ATM.\n");
if (fd == -1) {
printf("Cannot open fiasco image.\n");
fd = open(filename, O_RDWR|O_CREAT, 0644);
if (fd == -1)
return -1;
#if 1
write(fd, "\xb4\x00\x00\x00\x14\x00\x00\x00\x01\xe8\x0e", 11);
write(fd, "OSSO UART+USB", 14);
#else
/* 2nd format doesnt works. atm stay with old one */
write(fd, "\xb4", 1);
write(fd, &len, 4);
/* version header */
write(fd, "\x00\x00\x00\x02\xe8\x0e", 6);
/* firmware type */
write(fd, "OSSO UART+USB", 14);
/* firmware name */
write(fd, name, strlen(name));
write(fd, "", 1);
#endif
return fd;
}
int fiasco_add_eof(int fd)
{
#if 0
unsigned char buf[120];
if (fd == -1)
return -1;
memset(buf,'\xff', 120);
write(fd, buf, 120);
#endif
return 0;
}
int fiasco_add(int fd, const char *name, const char *file, const char *version)
{
int gd,ret;
unsigned int sz;
unsigned char len;
unsigned short hash;
unsigned char *ptr = (unsigned char *)&hash;
char buf[4096];
char bname[32];
if (fd == -1)
return -1;
if (file == NULL)
return -1;
gd = open(file, O_RDONLY);
if (gd == -1)
return -1;
sz = htonl((unsigned int) lseek(gd, 0, SEEK_END));
lseek(gd, 0, SEEK_SET);
// 4 bytes big endian
//write(fd, "T\x02\x2e\x19\x01\x01\x00", 7); // header?
write(fd, "T\x01\x2e\x19\x01\x01\x00", 7); // header (old piece format)
/* checksum */
hash = do_hash_file(file);
ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1];
write(fd, &hash, 2);
printf("hash: %04x\n", hash);
memset(bname, '\0', 13);
if (name == NULL)
name = fpid_file(file);
/* failback */
if (name == NULL)
name = file;
strncpy(bname, name, 12);
write(fd, bname, 12);
write(fd, &sz, 4);
if (version) {
/* append metadata */
write(fd, "\x00\x00\x00\x00\x31", 5);
len = strlen(version);
write(fd, &len, 1);
write(fd, version, len);
write(fd, "\x00\x9b", 2);
} else {
write(fd, "\x00\x00\x00\x00\x9b", 5);
}
// b4 00 00 00 00 36
if (read(fd, header, 5) != 5) {
printf("Error reading fiasco header\n");
goto __fiasco_read_image_end;
}
if (header[0] != 0xb4) {
printf("Invalid fiasco signature.\n");
goto __fiasco_read_image_end;
}
// skip 6 bytes
read(fd, version, 6);
// print version header
if (read(fd, version, 55) != 55) {
printf("Error reading fiasco version.\n");
goto __fiasco_read_image_end;
}
printf("# Fiasco header information:\n");
printf("# ==========================\n");
printf("# firmware type: %s\n", version);
version2 = version+strlen((char *)version)+3;
if (*version2=='.')
printf("firmware version: (null) (old firmware? no version string found?)\n");
else printf("firmware version: %s\n", version2);
// pieces:
// after the version2 string starts the header-body loop love
lseek(fd, 0xf + strlen(version2) + strlen(version), SEEK_SET);
do {
char piece_header[30];
char description[256];
unsigned char desc_len;
char *name;
off_t size;
off_t tmp = lseek(fd, 0, SEEK_CUR);
size = read(fd, piece_header, 30);
if (size != 30) {
fprintf(stderr, "Unexpected end of file\n");
while(1) {
ret = read(gd, buf, 4096);
if (ret<1)
break;
write(fd, buf, ret);
}
return 0;
}
int fiasco_pack(int optind, char *argv[])
{
const char *file = argv[optind];
char *type;
int fd, ret;
fd = fiasco_new(file, file); // TODO use a format here
if (fd == -1)
return 1;
printf("Package: %s\n", file);
while((file=argv[++optind])) {
type = (char *)fpid_file(file);
printf("Adding %s: %s..\n", type, file);
ret = fiasco_add(fd, type, file, NULL);
if (ret<0) {
printf("Error\n");
close(fd);
return 1;
}
dump_bytes(piece_header,30);
if (!piece_header_is_valid(piece_header)) {
fprintf(stderr, "Oops. Invalid piece header.\n");
break;
}
size = piece_header_to_size(piece_header);
name = piece_header_to_name(piece_header);
printf("# %s is %lld bytes\n", name, size);
read(fd, description, 255);
printf("# version: %s\n", description);
/* lseek foreach subimage */
lseek(fd, tmp, SEEK_SET);
lseek(fd, strlen(description) + 0x20, SEEK_CUR);
printf("rsc '%s' %lld '%s.bin' 0 %lld\n", file, lseek(fd,0,SEEK_CUR), name, size);
lseek(fd, size, SEEK_CUR);
} while(1);
//printf("Image '%s', size %d bytes.\n", image, size);
__fiasco_read_image_end:
}
fiasco_add_eof(fd);
printf("Done!\n");
close(fd);
return 0;
}
/* local code */
#if 0
void my_callback(int fd, struct header_t *header)
{
fiasco_data_read(header);
//read(fd, buf, header->size);
printf("Dumping %s\n", header->name);
printf("DATA: %02x\n", header->data[0]);
fiasco_data_free(header);
}
int main(int argc, char **argv)
{
if (argc!=2) {
printf("Usage: unfiasco [file]\n");
return 1;
}
/*
fd = fiasco_new("myfiasco", "pancake-edition");
fiasco_add(fd, "kernel", "zImage", "2.6.22");
close(fd);
*/
// fiasco_callback = &my_callback;
return openfiasco(argv[1]);
}
#endif
+2 -4
View File
@@ -20,7 +20,7 @@
#include <stdio.h>
#include <string.h>
char *fpid_file(char *filename)
const char *fpid_file(const char *filename)
{
FILE *fd;
char buf[512];
@@ -45,11 +45,9 @@ char *fpid_file(char *filename)
size = ftell(fd);
fclose(fd);
#if 0
if (!memcmp(b+0x34, "2NDAPE", 6))
return PIECE_2ND;
return pieces[PIECE_2ND];
else
#endif
if (!memcmp(b+0x04, "NOLOScnd", 8))
return pieces[PIECE_SECONDARY];
else
+60 -26
View File
@@ -42,6 +42,7 @@ int info = 0;
/* global structs */
char *pieces[] = {
"xloader", // xloader.bin
"2nd", // 2nd
"secondary", // secondary.bin
"kernel", // zImage
"initfs", // jffs'd initfs
@@ -73,27 +74,29 @@ void show_usage()
{
int i;
show_title();
printf(" -b [arg] boots the kernel with arguments\n");
printf(" -e [path] dump and extract pieces to path\n");
printf(" -r [0|1] disable/enable R&D mode\n");
printf(" -f <flags> set the given RD flags (see '-f help')\n");
printf(" -b [arg] boots the kernel with arguments\n");
printf(" -c console prompt mode\n");
printf(" -C [/dev/mtd] check bad blocks on mtd\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(" -e [path] dump and extract pieces to path\n");
printf(" -f <flags> set the given RD flags (see '-f help')\n");
printf(" -F [fiasco] flash a fiasco firmware image\n");
printf(" -h show this help message\n");
printf(" -H [file] calculate hash for file\n");
printf(" -i show device information (let standby mode)\n");
printf(" -I [piece] identify a firmware piece\n");
printf(" -l, -L list supported usb device ids\n");
printf(" -p [[p%%]file] piece-of-firmware %% file-where-this-piece-is\n");
printf(" -u [fiasco] unpack target fiasco image\n");
printf(" -U [0|1] disable/enable the usb host mode\n");
printf(" -s [serial] serial port console (minicom like terminal)\n");
printf(" -C [/dev/mtd] check bad blocks on mtd\n");
printf(" -c console prompt mode\n");
printf(" -h show this help message\n");
printf(" -i show device information (let standby mode)\n");
printf(" -I [piece] identify a firmware piece\n");
printf(" -l list supported usb device ids\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(" -R reboot the omap board\n");
printf(" -x extract configuration entries from /dev/mtd1\n");
printf(" -v be verbose and noisy\n");
printf(" -V show 0xFFFF version information\n");
printf(" -P [new-fiasco] creates a new fiasco package, pieces as arguments\n");
printf(" -r [0|1] disable/enable R&D mode\n");
printf(" -R reboot the omap board\n");
printf(" -s [serial] serial port console (minicom like terminal)\n");
printf(" -u [fiasco] unpack target fiasco image\n");
printf(" -U [0|1] disable/enable the usb host mode\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: ");
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)
@@ -102,10 +105,33 @@ void show_usage()
exit(0);
}
void unpack_callback(struct header_t *header)
{
FILE *fd = fopen(header->name, "wb");
if (fd == NULL) {
printf("Cannot open file.\n");
return;
}
fiasco_data_read(header);
fwrite(header->data, header->size, 1, fd);
fclose(fd);
}
void unpack_fiasco_image(char *file)
{
fiasco_read_image(file);
// TODO
printf("Dumping firmware pieces to disk.\n");
fiasco_callback = &unpack_callback;
openfiasco( file );
}
int fiasco_flash(char *file)
{
/* TODO */
fiasco_callback = NULL;
openfiasco( file );
printf("\nTODO: Implement the fiasco flashing here.\n");
}
int connect_via_usb()
@@ -185,12 +211,17 @@ int main(int argc, char **argv)
{
int c;
while((c = getopt(argc, argv, "C:cp:vVhRu:ib:U:r:e:ld:I:D:f:s:x")) != -1) {
while((c = getopt(argc, argv, "C:cp:PvVhRu:ib:U:r:e:Lld:I:D:f:F:s:xH:")) != -1) {
switch(c) {
case 'H':
printf("xorpair: %04x\n", do_hash_file(optarg));
return 0;
case 'x':
return dump_config();
case 'c':
return console_prompt();
case 'F':
return fiasco_flash(optarg);
case 'd':
sscanf(optarg, "%04hx:%04hx",
&supported_devices[SUPPORTED_DEVICES-2].vendor_id,
@@ -232,6 +263,9 @@ int main(int argc, char **argv)
case 'p':
add_piece(optarg);
break;
case 'P':
return fiasco_pack(optind, argv);
case 'L':
case 'l':
list_valid_devices();
return 0;
@@ -274,9 +308,9 @@ int main(int argc, char **argv)
&& (usb_mode == -1)
&& (root_device == -1))
{
printf("Usage: 0xFFFF [-hvVRi] [-e path] [-U 0|1] [-p [piece%%]file [-p ...]]\n");
printf(" [-b boot-args] [-I piece [-I ...]] [-u fiasco-image] [-x]\n");
printf(" [-D 0|1|2] [-F rd flags] [-s serial-dev] [-c] [-C mtd-dev]\n");
printf("0xFFFF [-chiLRvVx] [-C mtd-dev] [-d vid:pid] [-D 0|1|2] [-e path] [-f flags]\n");
printf(" [-F fiasco] [-H hash-file] [-I piece] [-p [piece%%]file]] [-r 0|1]\n");
printf(" [-s serial-dev] [-u fiasco-image] [-U 0|1] | [-P new-fiasco] [piece1] [2] ..\n");
return 1;
}
+21 -1
View File
@@ -15,7 +15,7 @@ void check_nolo_order();
extern struct usb_dev_handle *dev;
unsigned long get_file_size(char *file);
void progressbar(unsigned long long part, unsigned long long total);
char *fpid_file(char *filename);
const char *fpid_file(const char *filename);
int add_piece(char *piece);
#include <usb.h>
@@ -65,6 +65,7 @@ extern struct piece_t pcs[10];
enum {
PIECE_XLOADER = 0,
PIECE_2ND,
PIECE_SECONDARY,
PIECE_KERNEL,
PIECE_INITFS,
@@ -77,4 +78,23 @@ extern char *pieces[];
extern char *modes[];
extern char *root_devices[];
// fiasco
int openfiasco(char *name);
int fiasco_new(const char *filename, const char *name);
void fiasco_data_read(struct header_t *header);
int fiasco_add_eof(int fd);
extern void (*fiasco_callback)(struct header_t *header);
int fiasco_add(int fd, const char *name, const char *file, const char *version);
int fiasco_pack(int optind, char *argv[]);
struct header_t {
int fd;
char fwname[128];
char name[128];
char version[128];
unsigned short hash;
unsigned int size;
unsigned char *data;
};
#endif