diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | config.mk | 6 | ||||
-rw-r--r-- | doc/bug-report | 4 | ||||
-rw-r--r-- | doc/faq2 | 8 | ||||
-rw-r--r-- | doc/fiasco | 49 | ||||
-rw-r--r-- | doc/local-flash | 2 | ||||
-rw-r--r-- | doc/pieces | 2 | ||||
-rw-r--r-- | doc/usage | 2 | ||||
-rw-r--r-- | logotool/uncompress.c | 4 | ||||
-rw-r--r-- | man/0xFFFF.1 | 99 | ||||
-rw-r--r-- | man/goxf.1 | 20 | ||||
-rw-r--r-- | man/logotool.1 | 41 | ||||
-rw-r--r-- | src/Makefile | 5 | ||||
-rw-r--r-- | src/devices.c | 74 | ||||
-rw-r--r-- | src/dump.c | 80 | ||||
-rw-r--r-- | src/fiasco.c | 597 | ||||
-rw-r--r-- | src/flash.c | 4 | ||||
-rw-r--r-- | src/fpid.c | 11 | ||||
-rw-r--r-- | src/gui/Makefile | 12 | ||||
-rw-r--r-- | src/gui/gui.c | 1163 | ||||
-rw-r--r-- | src/gui/gui.gtkaml.orig (renamed from src/gui/gui.gtkaml) | 4 | ||||
-rw-r--r-- | src/gui/gui.gtkon | 321 | ||||
-rw-r--r-- | src/hash.c | 28 | ||||
-rw-r--r-- | src/hash.h | 2 | ||||
-rw-r--r-- | src/main.c | 262 | ||||
-rw-r--r-- | src/main.h | 35 | ||||
-rw-r--r-- | src/pieces.c | 8 | ||||
-rw-r--r-- | src/qmode.c | 2 | ||||
-rw-r--r-- | src/query.c | 22 | ||||
-rw-r--r-- | src/squeue/squeue.c | 2 | ||||
-rw-r--r-- | src/squeue/squeue.vapi | 2 |
31 files changed, 2506 insertions, 368 deletions
@@ -22,6 +22,7 @@ logot: clean: cd src && ${MAKE} clean + cd libusb && ${MAKE} clean cd logotool && ${MAKE} clean install: @@ -31,6 +32,8 @@ install: -cp src/gui/goxf ${DESTDIR}${PREFIX}/bin cp logotool/logotool ${DESTDIR}${PREFIX}/bin cp 0xFFFF.desktop ${DESTDIR}${PREFIX}/share/applications/ + mkdir -p ${DESTDIR}${PREFIX}/share/man/man1 + cp man/*.1 ${DESTDIR}${PREFIX}/share/man/man1 deinstall: rm -f ${DESTDIR}${PREFIX}/bin/0xFFFF @@ -1,8 +1,8 @@ -VERSION=0.4.0 -PREFIX=/usr +VERSION=0.5 +PREFIX=/usr/local # NetBSD stuff -CFLAGS+=-I/usr/pkg/include -O2 +CFLAGS+=-I/usr/pkg/include -g -O2 LDFLAGS+=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib HAVE_USB=1 diff --git a/doc/bug-report b/doc/bug-report index 8a7ad84..6955f69 100644 --- a/doc/bug-report +++ b/doc/bug-report @@ -40,14 +40,14 @@ and sometimes (in the early days often) replacing proprietary software. The non-free bits in the core infrastructure of the IT OS 2007 are a road block for efforts to create free operating systems/distributions besides IT OS on the -N770/N800. +770/N800. The reason for why it is helpful to have other operating system/distribution on the N800 is simple: There are hundreds of GNU/Linux distributions out there. Each one exists because there is a userbase that exactly likes their flavor of GNU/Linux. -For the N770/N800 Internet Tablets there exists only one such distribution: The +For the 770/N800 Internet Tablets there exists only one such distribution: The Internet Tablet OS. With the sheer amount of GNU/Linux distributions for desktops/workstations/servers/routers/PDAs on the one hand and the single OS solution for the Internet Tablets on the other I doubt that it can handle all @@ -50,7 +50,7 @@ This file tries to collect a bunch of common questions/answers about flashing flashed together. On the n800 firmwares, these two pieces are distributed in a single - file, but when flashing a n770, NOLO requires to provide the xloader + file, but when flashing a 770, NOLO requires to provide the xloader (without commiting) and then the secondary piece. This piece of software is closed source and is the responsable of @@ -61,13 +61,13 @@ This file tries to collect a bunch of common questions/answers about flashing <b>*) How can I identify my device?</b> - Theorically n770 and n800 have different USB device ID, but this is not + Theorically 770 and n800 have different USB device ID, but this is not true at all. The first series of the n800 comes with the same usb-id - than n770. That's weird! + than 770. That's weird! So, the only way to identify the device is by asking nolo for the version information of different pieces of the firmware. This can be faked, because - you can flash n770 stuff on n800 and viceversa, but it's not recommended + you can flash 770 stuff on n800 and viceversa, but it's not recommended because it wouldn't work :) @@ -1,3 +1,6 @@ + Copyright (C) 2007-2011 pancake <pancake@youterm.com> + Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com> + SPECS FOR TEH FIASCO FIRMWARE FILE FORMAT ffff! ----------------------------------------------- @@ -8,23 +11,39 @@ SPECS FOR TEH FIASCO FIRMWARE FILE FORMAT ffff! 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) + 4 bytes -- FW header length (big endian) + + +FW HEADER + + 4 bytes -- number of FW header blocks (big endian) + block { + 1 byte -- type of block + 0xE8 - Fiasco name + 0x31 - FW name + 1 byte -- length of block data + N bytes -- block data + } -PIECE HEADER +IMAGE - 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 + 1 byte = 0x54 -- signature + 1 byte -- number of subsection blocks + 1 + 5 bytes -- unknown (always 0x2e 0x19 0x01 0x01 0x00) + 2 bytes -- checksum for the image contents (xorpair) (big endian) + 12 bytes -- image name type (first byte is FF if is the last image) + 4 bytes -- length of image data (big endian) + 4 bytes -- unknown (always 0x00 0x00 0x00 0x00) block { - 1 byte -- if (value '1'-'9') { ..there's a comment.. } - 1 byte -- length of comment - N bytes -- comment + 1 byte -- type of subsection block + '1' - version + '2' - device & hw revisions (separated by char 0x00, max size of device is 16, hw revision 8) + '3' - layout + '4' - unknown + '/' - unknown + 1 byte -- length of subsection block + N bytes -- subsection block data } - N bytes -- piece data - + 1 byte -- unknown (maybe end of subsections?) + N bytes -- image data diff --git a/doc/local-flash b/doc/local-flash index a09d682..a1a44fa 100644 --- a/doc/local-flash +++ b/doc/local-flash @@ -21,4 +21,4 @@ have flashed properly every piece inside the device, but keep in mind that it is dangerous and you can brick your device. But feel free to send feedback to provide a full support for local -flashing on n770 and n800. +flashing on 770 and n800. @@ -37,7 +37,7 @@ Pieces can be automatically identified by using the '-I' flag: You can dump these pieces from the internal memory of the internet tablet by using the mtd-utils over /dev/mtd* or just running: - n770$ 0xFFFF -e /media/mmc1 + 770$ 0xFFFF -e /media/mmc1 There is another way for dumping pieces with extra parameters and options, read doc/dumping for more information. @@ -1,7 +1,7 @@ <b>Usage guide</b> 0xFFFF is a free software implementation of the flasher for the Nokia Internet -Tablets (n770 and n800). +Tablets (770 and n800). <pre> - flash separated pieces of the firmware. - retrieve information about the device diff --git a/logotool/uncompress.c b/logotool/uncompress.c index b3e19dd..72b1fdd 100644 --- a/logotool/uncompress.c +++ b/logotool/uncompress.c @@ -71,7 +71,7 @@ int uncompress_image(char *srcf, char *dstf) src = malloc ( fsize ); dst = malloc ( width*height*2 ); deof = dst+width*height*2; - if ((int)src == -1 || (int)dst == -1 ) { + if (src == (void *)-1 || dst == (void *)-1 ) { printf("Cannot malloc\n"); return 1; } @@ -105,7 +105,7 @@ int uncompress_image(char *srcf, char *dstf) } } } - fprintf(stderr, "Output Size: %d\n",dst2-dst); + fprintf(stderr, "Output Size: %lld\n",(long long int)(dst2-dst)); if ((dst2-dst)!=(width*height*2)) fprintf(stderr, "failed?\n"); diff --git a/man/0xFFFF.1 b/man/0xFFFF.1 new file mode 100644 index 0000000..4897300 --- /dev/null +++ b/man/0xFFFF.1 @@ -0,0 +1,99 @@ +.TH 0xFFFF 1 "November 18, 2010" +.\" Please adjust this date whenever revising the manpage. +.SH NAME +0xFFFF \- Open Free Fiasco Firmware Flasher + +.SH SYNOPSIS +.B 0xFFFF +.RB [OPTION]... +.SH DESCRIPTION +The 'Open Free Fiasco Firmware Flasher' aka 0xFFFF utility implements +a free (GPL3) userspace handler for the NOLO bootloader and related +utilities for the Nokia Internet Tablets like flashing, setting device +options, packing/unpacking FIASCO firmware format and more. + +.SH OPTIONS +.TP +.BI -b [args] +boots the kernel with arguments +.TP +.BI -c +console prompt mode +.TP +.BI -d [vid:pid] +injects a usb device into the supported list +.TP +.BI -D [0|1|2] +sets the root device to flash (0), mmc (1) or usb (2) +.TP +.BI -f <flags> +set the given RD flags (see '-f help') +.TP +.BI -i +show device information (let standby mode) +.TP +.BI -l +list supported usb device ids +.TP +.BI -p [[p%]file] +piece-of-firmware % file-where-this-piece-is +.TP +.BI -r [0|1] +disable/enable R&D mode +.TP +.BI -R +reboot the omap board +.TP +.BI -U [0|1] +disable/enable the usb host mode +.TP +.BI -Q +enter shared queues server mode (for gui or remote) +.TP +.BI -s [serial] +serial port console (minicom like terminal) +.TP +.BI -h +show help message +.TP +.BI -S [subversion] +unpacks/flash pieces matching this sub-version information +.TP +.BI -n +do not flash or write to disk (simulation) +.TP +.BI -C [/dev/mtd] +check bad blocks on mtd +.TP +.BI -e [path] +dump/extract pieces to path +.TP +.BI -F [fiasco] +flash a fiasco firmware image +.TP +.BI -H [file] +calculate hash for file +.TP +.BI -I [piece] +identify a firmware piece +.TP +.BI -P [new-fiasco] +creates a new fiasco package, pieces as arguments +.TP +.BI -u [fiasco] +unpack target fiasco image +.TP +.BI -v +be verbose and noisy +.TP +.BI -V +show version information and exit. +.TP +.BI -x +extract configuration entries from /dev/mtd1 + +.SH AUTHOR +0xFFFF was written by pancake. +.PP +This manual page was written by Sebastian Reichel <elektranox@gmail.com>, +for the Debian project (but may be used by others). diff --git a/man/goxf.1 b/man/goxf.1 new file mode 100644 index 0000000..c07a2f1 --- /dev/null +++ b/man/goxf.1 @@ -0,0 +1,20 @@ +.TH GOXF 1 "November 18, 2010" +.\" Please adjust this date whenever revising the manpage. +.SH NAME +goxf \- 0xFFFF GUI +.SH SYNOPSIS +.B goxf +.RB [FILE] +.SH DESCRIPTION +This utility is a graphical interface to 0xFFFF. It is used to +communicate with the NOLO bootloader of Nokia's internet tablets +(770, N800, N810, N900). +.SH OPTIONS +goxf takes no options. +.SH SEE ALSO +.B 0xFFFF(1) +.SH AUTHOR +goxf was written by pancake. +.PP +This manual page was written by Sebastian Reichel <elektranox@gmail.com>, +for the Debian project (but may be used by others). diff --git a/man/logotool.1 b/man/logotool.1 new file mode 100644 index 0000000..f19d38b --- /dev/null +++ b/man/logotool.1 @@ -0,0 +1,41 @@ +.TH LOGOTOOL 1 "November 18, 2010" +.\" Please adjust this date whenever revising the manpage. +.SH NAME +logotool \- FIASCO logo file tool +.SH SYNOPSIS +.B logotool +.RB [OPTION]... +.SH DESCRIPTION +Tool to compress, uncompress or watch FIASCO logo files. +.SH OPTIONS +.TP +.BI -u img +uncompress image to img.rgb +.TP +.BI -c img +compres a 24 bit rgb raw image to a 16(565) one +.TP +.BI -m img +show image using mplayer (dumps to <img>.yuv) +.TP +.BI -v img +view uncompressed image using the 'display' command from ImageMagick (in monochrome) +.TP +.BI -w +specify width (required for -v and -c) +.TP +.BI -a +force RGBA instead of RGB when compressing (use with -c) +.TP +.BI -h +specify height (required for -v and -c) +.TP +.BI -V +show version information and exit. +.SH SEE ALSO +.B 0xFFFF(1) +.SH AUTHOR +logotool was written by pancake and esteve. +.PP +This manual page was written by Sebastian Reichel <elektranox@gmail.com>, +for the Debian project (but may be used by others). diff --git a/src/Makefile b/src/Makefile index 2e8990d..a04638f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,10 +6,13 @@ BIN=0xFFFF #LIBS=`${HAVE_USB} && echo -- '-lusb'` LIBS=`if [ "${HAVE_USB}" = 1 ]; then echo '-lusb'; fi` CFLAGS+=-DVERSION=\"${VERSION}\" -Wall -I . -CFLAGS+=-pedantic -std=c99 -DHAVE_USB=${HAVE_USB} +CFLAGS+=-pedantic -std=c99 -DHAVE_USB=${HAVE_USB} -Wno-unused-result USBOBJ=../libusb/error.o ../libusb/usb.o ../libusb/descriptors.o USBOBJ+=../libusb/linux.o ## XXX not portable +CFLAGS+=-I../libusb +LDFLAGS+=-L../libusb + all: ${BIN} ${BIN}: ${OBJ} diff --git a/src/devices.c b/src/devices.c index 2691770..cb1e05d 100644 --- a/src/devices.c +++ b/src/devices.c @@ -1,6 +1,7 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2007-2009 pancake <pancake@nopcode.org> + * Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com> * * 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 @@ -29,18 +30,31 @@ * * The following table shows this info: * - * boot os - * n770 0421:0105 0421:0431 - * n800 0421:0431 + * omap-rom nolo flash-mode mass-stor pc-suite + * 770 0421:0105 0421:0431 + * n800 0421:04c3 0421:0431 + * n810 0421:0105 + * n900 0421:0106 0421:0105 0421:01c8 0421:01c7 0421:01c8 + * + * mode images protocol + * omap-rom 2nd, secondary OMAP messages + Nokia X-Loader protocol + * nolo all except mmc NOLO + * flash-mode mmc MK II + * mass-storage sd, first emmc Standard USB Mass Storage + * pc-suite mmc MK II * */ 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 - { "n800", 0x421, 0x04c3, 0x0001 }, // a n800 - { 0 }, - { 0 } + { "FFFF", 0x0000, 0x0000, FLASH_NORMAL }, // dummy + { "unkn", 0x0421, 0x3f00, FLASH_NORMAL }, // probably a development board + { "n800", 0x0421, 0x04c3, FLASH_NORMAL }, // n800 + { "770/n810/n900", 0x0421, 0x0105, FLASH_NORMAL }, // 770, n810, n900 + { "n900", 0x0421, 0x0106, FLASH_COLD }, // n900 cold flashing + { "n900", 0x0421, 0x01c8, FLASH_MKII }, // n900 mmc flashing + { "770/n800", 0x0421, 0x0431, FLASH_DISK }, // 770, n800 usb mass storage + { "n900", 0x0421, 0x01c7, FLASH_DISK }, // n900 usb mass storage + { NULL }, + { NULL } }; /** Returns 0 when no device was found and a positive @@ -73,7 +87,7 @@ void list_valid_devices() int i; struct devices ptr = supported_devices[1]; - for(i=1; ptr.vendor_id; ptr = supported_devices[++i]) + for(i=1; ptr.name; ptr = supported_devices[++i]) printf("%04x:%04x %s\n", ptr.vendor_id, ptr.product_id, ptr.name); } @@ -82,39 +96,31 @@ 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; + printf("%s found!\n", dev->filename); + *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 @@ -37,7 +37,7 @@ int rf_extract(char *dev, off_t from, off_t to, char *file) FILE *fd = fopen(file, "wb+"); if (from>to) { - printf("Bad range %lld - %lld for %s\n", from, to, file); + printf("Bad range %lld - %lld for %s\n", (long long int)from, (long long int)to, file); goto __rf_extract_exit; } if (fs == NULL) { perror(dev); goto __rf_extract_exit; } @@ -56,7 +56,7 @@ int rf_extract(char *dev, off_t from, off_t to, char *file) } printf("\r%s: %lld bytes dumped from %s\n", - file, to-from, dev); + file, (long long int)(to-from), dev); __rf_extract_exit: if (fs) fclose(fs); @@ -138,8 +138,8 @@ int mtd_close(int fd, struct nand_oobinfo *old_oobinfo, int oobinfochanged) // configuration for nanddump // //int noecc = 0; // don't error correct -int omitoob = 1; // omit oob data -int omitbad = 1; +static int omitoob = 1; // omit oob data +static int omitbad = 1; // configuration for nanddump // #define CONFIGURE_FLAGS(x) \ @@ -158,6 +158,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) { @@ -204,8 +204,9 @@ int check_badblocks(char *mtddev) } /* ECC stats available ? */ + memset (&stat1, 0, sizeof (stat1)); if (eccstats) { - if (ioctl(fd, ECCGETSTATS, &stat2)) { + if (ioctl (fd, ECCGETSTATS, &stat2)) { perror("ioctl(ECCGETSTATS)"); goto closeall; } @@ -245,6 +246,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 +455,35 @@ __done: return 1; } -int is_n800() +static int is_n900() +{ + int n900 = 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)) + n900 = 1; + fclose(fd); + return n900; +} + +static int is_n800() { 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; } @@ -539,9 +554,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 (is_n900()) + return reverse_extract_pieces_n900(dir); + + printf("Device detected: 770/n800/n900\n"); chdir(dir); // TODO: get values from /proc/mtd ??? diff --git a/src/fiasco.c b/src/fiasco.c index cb27b10..b0b68cf 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -1,6 +1,7 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2007-2011 pancake <pancake@youterm.com> + * Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com> * * 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 @@ -27,18 +28,24 @@ #include "main.h" #include "hash.h" +char *strdup(const char *s); + int (*fiasco_callback)(struct header_t *header) = NULL; -int openfiasco(char *name, char *piece_grep, int v) +int openfiasco(const char *name, const char *type, const char *device, const char *hwrev, const char *version, int v) { struct header_t header; - unsigned char buf[128]; - unsigned char data[128]; - unsigned char *pdata; - unsigned int namelen; + unsigned char buf[256]; + unsigned char data[256]; + unsigned char *pdata, *pdataend; + unsigned int headerlen; + unsigned int blockcount; off_t off, here; - int i,j; + int subsections; + int match; + int i; + memset(&header, 0, sizeof(header)); header.fd = open(name, O_RDONLY); if (header.fd == -1) { @@ -47,45 +54,73 @@ int openfiasco(char *name, char *piece_grep, int v) } /* read header */ - read(header.fd, buf, 5); + if (read(header.fd, buf, 5) != 5) { + printf("Invalid read of 5 bytes\n"); + return close(header.fd); + } if (buf[0] != 0xb4) { printf("Invalid header\n"); return close(header.fd); } - memcpy(&namelen,buf+1,4); - namelen = ntohl(namelen); - if (namelen>128) { + + memcpy(&headerlen,buf+1,4); + headerlen = ntohl(headerlen); + if (headerlen>128) { printf("Stupid length at header. Is this a joke?\n"); return close(header.fd); } + memset(buf,'\0', 128); - read(header.fd, buf, namelen); + if (read(header.fd, buf, headerlen) != headerlen) { + printf("Invalid read of %d bytes\n", headerlen); + return close(header.fd); + } - if (v) printf("Fiasco version: %2d\n", buf[3]); - strncpy(header.fwname, (char *)buf+6, sizeof(header.fwname) - 1); - if (v) - for(i=6;i<namelen;i+=strlen((char *)(buf+i))+1) - printf("Name: %s\n", buf+i); + memcpy(&blockcount,buf,4); + blockcount = ntohl(blockcount); + if (blockcount==0) { + printf("Error: No block in header\n"); + return close(header.fd); + } + if (v) printf("Number of blocks: %d\n", blockcount); + + pdata = buf+4; + while (pdata < buf+headerlen-4) { + if (pdata[0] == 0xe8) { + if (v) printf("Header: %s\n", pdata+2); + } else if (pdata[0] == 0x31) { + i = pdata[1]; + if (i >= sizeof(header.swver)) i = sizeof(header.swver)-1; + memset(header.swver, 0, sizeof(header.swver)); + strncpy(header.swver, (char *)pdata+2, i); + if (v) printf("SW version: %s\n", header.swver); + } else { + if (v) printf("Unknown header 0x%x, length %d, data %s\n", pdata[0], pdata[1], pdata+2); + } + pdata += (int)pdata[1]+2; + } /* walk the tree */ while(1) { here = lseek(header.fd, 0, SEEK_CUR); - if (read(header.fd, buf, 9)<9) - break; - if (buf[0] != 0x54) { // 'T' - /* skipping some bytes */ - lseek(header.fd, -9, SEEK_CUR); - for(i=0;buf[0]!=0x54;i++) { - j = read(header.fd, buf, 1); - if (j == -1) { - printf("Cannot find next FIASCO header\n"); - return close(header.fd); - } + + i = 0; + while(1) { + if (read(header.fd, buf, 7)<7) { + printf("Next valid header not found\n"); + return close(header.fd); } - if (v) printf("Skipping %d padding bytes\n", i); - lseek(header.fd, -1, SEEK_CUR); - continue; + if (buf[0] == 0x54 && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00) + break; + lseek(header.fd, -6, SEEK_CUR); + ++i; } + if (i && v) printf("Skipping %d padding bytes\n", i); + + subsections = buf[1]-1; + + if (read(header.fd, buf+7, 2)<2) + break; header.hash = buf[7]<<8|buf[8]; /* piece name */ @@ -97,64 +132,192 @@ int openfiasco(char *name, char *piece_grep, int v) printf(" [eof]\n"); break; } else if (v) printf(" %s\n", data); - strcpy(header.name, (char *)data); + memset(header.type, 0, sizeof(header.type)); + strncpy(header.type, (char *)data, sizeof(header.type)-1); + + if (v) { + printf(" header: "); + for (i=0; i<7;++i) printf(" 0x%.2X", (unsigned int)buf[i]); + printf("\n"); + } if (read(header.fd, buf, 9)<9) - break; + return close(header.fd); memcpy(&header.size, buf,4); header.size = ntohl(header.size); if (v) { printf(" offset: 0x%08x\n", (unsigned int)here); printf(" size: %d bytes\n", header.size); printf(" hash: %04x\n", header.hash); + printf(" subsections: %d\n", subsections); } - //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') { + + memset(header.device, 0, sizeof(header.device)); + memset(header.hwrevs, 0, sizeof(header.hwrevs)); + memset(header.version, 0, sizeof(header.version)); + if (header.layout) { + free(header.layout); + header.layout = NULL; + } + + while (subsections > 0) { if (read(header.fd, data, 1)<1) - break; + return close(header.fd); i = data[0]; if (read(header.fd, data, i)<i) - break; - if (data[0]) { + return close(header.fd); + { if (v) { - printf(" version-length: %d\n", i); - printf(" version: %s\n", data); + printf(" subinfo\n"); + printf(" type: "); + if (buf[8] == '1') printf("version string"); + else if (buf[8] == '2') printf("hw revision"); + else if (buf[8] == '3') printf("layout"); + else printf("unknown (%c:0x%x)", buf[8], buf[8]); + printf("\n"); + printf(" length: %d\n", i); } pdata = data; - while(pdata<data+i) { - strcat(header.name,pdata==data?"-":","); - strcat(header.name, (char*)pdata); - if (v) printf(" sub-version: %s\n", pdata); - pdata = pdata+strlen((char*)pdata)+1; - for(;*pdata=='\0'&&pdata<data+i;pdata=pdata+1); + pdataend = data+i; + while(pdata<pdataend) { + char buf2[9]; + if (buf[8] == '2' && pdata != data) { + memset(buf2, 0, 9); + strncpy(buf2, (char *)pdata, 8); + } + if (v) { + printf(" "); + if (buf[8] == '1') printf("version"); + else if (buf[8] == '2' && pdata == data) printf("device"); + else if (buf[8] == '2' && pdata != data) printf("hw revision"); + else if (buf[8] == '3') printf("layout"); + else printf("data"); + if (buf[8] == '2' && pdata != data) + printf(": %s\n", buf2); + else if (buf[8] == '3') + printf(": (not printing)\n"); + else if (buf[8] == '1' || buf[8] == '2') + printf(": %s\n", pdata); + else { + char *buf3 = malloc(i+1); + memcpy(buf3, pdata, i); + buf3[i] = 0; + printf(": (raw) %s\n", buf3); + free(buf3); + } + } + if (buf[8] == '1') { + strncpy(header.version, (char *)pdata, sizeof(header.version)-1); + } else if (buf[8] == '2' && pdata == data) { + strncpy(header.device, (char *)pdata, sizeof(header.device)-1); + } else if (buf[8] == '2' && pdata != data) { + if (header.hwrevs[0] == 0) + strncpy(header.hwrevs, buf2, sizeof(header.hwrevs)-1); + else { + strcat(header.hwrevs, ","); + strcat(header.hwrevs, buf2); + } + } else if (buf[8] == '3') { + if (header.layout) free(header.layout); + header.layout = malloc(strlen((char*)pdata)+1); + if (header.layout) strcpy(header.layout, (char *)pdata); + } + if (buf[8] == '2' && pdata != data && strlen((char *)pdata) > 8) + pdata += 8; + else + pdata += strlen((char*)pdata)+1; + for(;*pdata=='\0' && pdata<pdataend; pdata++); } } - strcpy(header.version, (char *)data); if (read(header.fd, buf+8, 1)<1) - break; + return close(header.fd); + --subsections; } - /* callback */ + + header.name = malloc(strlen(header.type)+strlen(header.device)+strlen(header.hwrevs)+strlen(header.version)+4); + if (!header.name) { + printf("malloc error\n"); + exit(1); + } + strcpy(header.name, header.type); + if (header.device[0]) { + strcat(header.name, "-"); + strcat(header.name, header.device); + } + if (header.hwrevs[0]) { + strcat(header.name, "-"); + strcat(header.name, header.hwrevs); + } + if (header.version[0]) { + strcat(header.name, "-"); + strcat(header.name, header.version); + } + off = lseek(header.fd, 0, SEEK_CUR); if (v) { + printf(" version: %s\n", header.version); + printf(" device: %s\n", header.device); + printf(" hwrevs: %s\n", header.hwrevs); printf(" name: %s\n", header.name); printf(" body-at: 0x%08x\n", (unsigned int)off); } - if (piece_grep==NULL || (strstr(header.name, piece_grep))) { - printf("==> (%s) %s\n", piece_grep, header.name); + + match = 1; + + if (match && type && strcmp(header.type, type) != 0) + match = 0; + + if (match && device && strcmp(header.device, device) != 0) + match = 0; + + if (match && version && strcmp(header.version, version) != 0) + match = 0; + + if (match && hwrev) { + char *tmp1 = malloc(strlen(header.hwrevs)+3); + char *tmp2 = malloc(strlen(hwrev)+3); + + if (!tmp1 || !tmp2) { + printf("malloc error\n"); + return close(header.fd); + } + + sprintf(tmp1, ",%s,", header.hwrevs); + sprintf(tmp2, ",%s,", hwrev); + + if (!strstr(tmp1, tmp2)) + match = 0; + + free(tmp1); + free(tmp2); + } + + /* callback */ + if (match) { + printf("==> %s\n", header.name); if (fiasco_callback != NULL) { fiasco_callback(&header); + if (header.layout) { + free(header.layout); + header.layout = NULL; + } + free(header.name); free(header.data); continue; } else { // ??huh } + } else { + printf("ignored %s\n", header.name); } // XXX dup lseek(header.fd, off, SEEK_SET); lseek(header.fd, header.size, SEEK_CUR); + if (header.layout) { + free(header.layout); + header.layout = NULL; + } + free(header.name); } return close(header.fd); } @@ -166,51 +329,72 @@ void fiasco_data_read(struct header_t *header) printf("Cannot alloc %d bytes\n", header->size); return; } - read(header->fd, header->data, header->size); + if (read (header->fd, header->data, header->size) != header->size) { + printf("Cannot read %d bytes\n", header->size); + return; + } } /* fiasco writer */ -int fiasco_new(const char *filename, const char *name) +int fiasco_new(const char *filename, const char *swver) { int fd; - //int len = htonl(strlen(name)+1+6+14); + unsigned int len; + unsigned char len8; + const char *str = "OSSO UART+USB"; - fd = open(filename, O_RDWR|O_CREAT, 0644); - if (fd == -1) + if (swver && strlen(swver)+1 > UINT8_MAX) { + printf("SW version is too long\n"); 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]; + fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0644); if (fd == -1) return -1; - memset(buf,'\xff', 120); - write(fd, buf, 120); -#endif - return 0; + + printf("Writing header\n"); + + write(fd, "\xb4", 1); //signature + + len = 4; + len += strlen(str) + 3; + if (swver) + len += strlen(swver) + 3; + len = htonl(len); + write(fd, &len, 4); + + if (swver) + len = htonl(2); + else + len = htonl(1); + write(fd, &len, 4); + + // header + len = strlen(str)+1; + len8 = len; + write(fd, "\xe8", 1); + write(fd, &len8, 1); + write(fd, str, len); + + // sw version + if (swver) { + printf("Writing SW version: %s\n", swver); + len = strlen(swver)+1; + len8 = len; + write(fd, "\x31", 1); + write(fd, &len8, 1); + write(fd, swver, len); + }; + + return fd; } -int fiasco_add(int fd, const char *name, const char *file, const char *version) +int fiasco_add(int fd, const char *name, const char *file, const char *layout, const char *device, const char *hwrevs, const char *version) { + int i; int gd,ret; + int size; + int align; unsigned int sz; unsigned char len; unsigned short hash; @@ -226,17 +410,40 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version) if (gd == -1) return -1; - sz = htonl((unsigned int) lseek(gd, 0, SEEK_END)); + sz = lseek(gd, 0, SEEK_END); + if (name) { + if (strcmp(name, "mmc") == 0) // align mmc + sz = ((sz >> 8) + 1) << 8; + else if (strcmp(name, "kernel") == 0) // align kernel + sz = ((sz >> 7) + 1) << 7; + } + + printf(" size: %d\n", sz); + sz = htonl((unsigned int) sz); + 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) + + write(fd, "T", 1); + + /* number of subsections */ + len = 1; + if (version) + ++len; + if (device) + ++len; + if (layout) + ++len; + write(fd, &len, 1); + + write(fd, "\x2e\x19\x01\x01\x00", 5); + /* checksum */ - hash = do_hash_file(file); + hash = do_hash_file(file, name); ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1]; write(fd, &hash, 2); - printf("hash: %04x\n", hash); + printf(" hash: %04x\n", hash); + /* image type name */ memset(bname, '\0', 13); if (name == NULL) name = fpid_file(file); @@ -246,24 +453,104 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version) strncpy(bname, name, 12); write(fd, bname, 12); - write(fd, &sz, 4); + write(fd, "\x00\x00\x00\x00", 4); + + /* append version subsection */ if (version) { - /* append metadata */ - write(fd, "\x00\x00\x00\x00\x31", 5); - len = strlen(version); + write(fd, "1", 1); /* 1 - version */ + len = strlen(version)+1; write(fd, &len, 1); write(fd, version, len); - write(fd, "\x00\x9b", 2); - } else { - write(fd, "\x00\x00\x00\x00\x9b", 5); } + + /* append device & hwrevs subsection */ + if (device) { + const char *ptr = hwrevs; + const char *oldptr = hwrevs; + write(fd, "2", 1); /* 2 - device & hwrevs */ + len = 16; + if (hwrevs) { + i = 1; + while ((ptr = strchr(ptr, ','))) { i++; ptr++; } + if ((int)len + i*8 > 255) { + printf("Device string and HW revisions are too long\n"); + return -1; + } + len += i*8; + } + write(fd, &len, 1); + len = strlen(device); + if (len > 15) len = 15; + write(fd, device, len); + for (i=0; i<16-len; ++i) + write(fd, "\x00", 1); + if (hwrevs) { + ptr = hwrevs; + oldptr = hwrevs; + while ((ptr = strchr(ptr, ','))) { + len = ptr-oldptr; + if (len > 8) len = 8; + write(fd, oldptr, len); + for (i=0; i<8-len; ++i) + write(fd, "\x00", 1); + ++ptr; + oldptr = ptr; + } + len = strlen(oldptr); + if (len > 8) len = 8; + write(fd, oldptr, len); + for (i=0; i<8-len; ++i) + write(fd, "\x00", 1); + } + } + + /* append layout subsection */ + if (layout) { + int lfd = open(layout, O_RDONLY); + if (lfd >= 0) { + len = read(lfd, buf, sizeof(buf)); + if (len > 0) { + write(fd, "3", 1); /* 3 - layout */ + write(fd, &len, 1); + write(fd, buf, len); + } + close(lfd); + } else { + printf("Cannot open layout file %s\n", layout); + return -1; + } + } + + /* dummy byte - end of all subsections */ + write(fd, "\x00", 1); + + size = 0; while(1) { ret = read(gd, buf, 4096); + size += ret; if (ret<1) break; - write(fd, buf, ret); + if (write(fd, buf, ret) != ret) { + fprintf (stderr, "Cannot write %d bytes\n", ret); + return -1; + } + } + + /* align mmc and kernel (fill with 0xff) */ + align = 0; + if (name) { + if (strcmp(name, "mmc") == 0) + align = ((size >> 8) + 1) << 8; + else if (strcmp(name, "kernel") == 0) + align = ((size >> 7) + 1) << 7; + } + if (align) { + while (size < align) { + write(fd, "\xff", 1); + ++size; + } } return 0; @@ -271,57 +558,91 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version) int fiasco_pack(int optind, char *argv[]) { - const char *file = argv[optind]; + char *file = argv[optind]; + int fd, ret, i; + + char *ptr; + char *arg; char *type; - int fd, ret; + char *device; + char *hwrevs; + char *version; + char *layout; - fd = fiasco_new(file, file); // TODO use a format here + char *swver = NULL; + + i = optind; + while((arg=argv[++i])) { + if (strncmp(arg, "version:", strlen("version:"))==0) { + swver = arg+strlen("version:"); + break; + } + } + + printf("Package: %s\n", file); + fd = fiasco_new(file, swver); 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); + while((arg=argv[++optind])) { + + if (strncmp(arg, "version:", strlen("version:"))==0) + continue; + +// format: [[[[dev:[hw:]]ver:]type:]file[%layout] + ptr = strdup(arg); + layout = strchr(ptr, '%'); + if (layout) { + *(layout++) = 0; + } + + type = NULL; + device = NULL; + hwrevs = NULL; + version = NULL; + + file = strrchr(ptr, ':'); + if (file) { + *(file++) = 0; + type = strrchr(ptr, ':'); + if (type) { + *(type++) = 0; + version = strrchr(ptr, ':'); + if (version) { + *(version++) = 0; + hwrevs = strchr(ptr, ':'); + if (hwrevs) + *(hwrevs++) = 0; + device = ptr; + } else { + version = ptr; + } + } else { + type = ptr; + } + } else { + file = ptr; + } + + if (!type) + type = (char *)fpid_file(file); + + printf("Adding file: %s\n", file); + printf(" type: %s\n", type); + if (device) printf(" device: %s\n", device); + if (hwrevs) printf(" hw revisions: %s\n", hwrevs); + if (version) printf(" version: %s\n", version); + if (layout) printf(" layout file: %s\n", layout); + + ret = fiasco_add(fd, type, file, layout, device, hwrevs, version); + free(ptr); if (ret<0) { printf("Error\n"); close(fd); return 1; } } - 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 diff --git a/src/flash.c b/src/flash.c index 43c79bb..3ad957f 100644 --- a/src/flash.c +++ b/src/flash.c @@ -74,7 +74,7 @@ void check_nolo_order() check_nolo_order_failed(); } -void flash_image(const char *filename, const char *piece, const char *version) +void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version) { FILE *fd; int vlen = 0; @@ -84,7 +84,7 @@ void flash_image(const char *filename, const char *piece, const char *version) unsigned long long size, off; unsigned char bsize[4], tmp; unsigned char nolofiller[128]; - ushort hash = do_hash_file(filename); + ushort hash = do_hash_file(filename, piece); if (piece == NULL) { //exit(1); @@ -1,6 +1,7 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com> * * 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 @@ -23,12 +24,16 @@ /* global structs */ char *pieces[] = { "xloader", // xloader.bin - "2nd", // 2nd + "2nd", // 2nd.bin "secondary", // secondary.bin "kernel", // zImage - "initfs", // jffs'd initfs - "rootfs", // 80mB of blob + "initfs", // initfs + "rootfs", // rootfs "omap-nand", // 8kB of food for the nand + "mmc", // raw eMMC image + "cmt-2nd", // cmt-2nd + "cmt-algo", // cmt-algo + "cmt-mcusw", // cmt-mcusw "fiasco", // FIASCO IMAGE NULL }; diff --git a/src/gui/Makefile b/src/gui/Makefile index 61a5efa..3fb5c85 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -1,8 +1,13 @@ include ../../config.mk ifeq (${HAVE_GUI},1) -all: - gtkamlc --save-temps --Xcc=-I../squeue ../squeue/squeue.c ../fpid.c ../squeue/squeue.vapi gui.gtkaml extras.vapi --pkg gtk+-2.0 -o goxf +all: goxf + +goxf: + ${CC} -I../squeue ../squeue/squeue.c ../fpid.c gui.c `pkg-config --cflags --libs gtk+-2.0` -o goxf + +c: + gtkamlc --save-temps --Xcc=-I../squeue ../squeue/squeue.c ../fpid.c ../squeue/squeue.vapi gui.gtkon extras.vapi --pkg gtk+-2.0 -o goxf test: valac --save-temps --Xcc=-I.. squeue.vapi test.vala ../squeue.c -o v @@ -11,3 +16,6 @@ else all: @true endif + +clean: + rm -f goxf *.o *.c diff --git a/src/gui/gui.c b/src/gui/gui.c new file mode 100644 index 0000000..f8a1ffc --- /dev/null +++ b/src/gui/gui.c @@ -0,0 +1,1163 @@ +/* gui.c generated by valac 0.11.2.14-5f971, the Vala compiler + * generated from gui.vala, do not modify */ + + +#include <glib.h> +#include <glib-object.h> +#include <gtk/gtk.h> +#include <squeue.h> +#include <stdlib.h> +#include <string.h> +#include <glib/gstdio.h> +#include <stdio.h> +#include <float.h> +#include <math.h> +#include <gdk/gdk.h> + + +#define TYPE_MAIN_WINDOW (main_window_get_type ()) +#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow)) +#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass)) +#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW)) +#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW)) +#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass)) + +typedef struct _MainWindow MainWindow; +typedef struct _MainWindowClass MainWindowClass; +typedef struct _MainWindowPrivate MainWindowPrivate; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL))) + +struct _MainWindow { + GtkWindow parent_instance; + MainWindowPrivate * priv; +}; + +struct _MainWindowClass { + GtkWindowClass parent_class; +}; + +struct _MainWindowPrivate { + GtkTreeView* tv; + GtkProgressBar* pb; + GtkAboutDialog* aboutdialog1; +}; + + +static gpointer main_window_parent_class = NULL; +static struct squeue_t* main_window_q; +static struct squeue_t* main_window_q = NULL; +static struct squeue_t* main_window_p; +static struct squeue_t* main_window_p = NULL; +static MainWindow* main_window_viewer; +static MainWindow* main_window_viewer = NULL; + +GType main_window_get_type (void) G_GNUC_CONST; +#define MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MAIN_WINDOW, MainWindowPrivate)) +enum { + MAIN_WINDOW_DUMMY_PROPERTY +}; +static void main_window_doCloseApplication (MainWindow* self); +static void main_window_OnReset (MainWindow* self); +static void main_window_OnFileFlashEvent (MainWindow* self); +gboolean main_window_showYesNo (MainWindow* self, const gchar* s); +void main_window_showMessage (MainWindow* self, const gchar* s, GtkMessageType mt); +static void main_window_OnFileOpenEvent (MainWindow* self); +void main_window_add_file (MainWindow* self, const gchar* type, const gchar* size, const gchar* file); +gboolean main_window_loadFile (MainWindow* self, const gchar* filename); +void main_window_showError (MainWindow* self, const gchar* s); +static void main_window_OnMenuHelpAboutActivatedEvent (MainWindow* self); +static void _lambda0_ (gint x, MainWindow* self); +static void __lambda0__gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self); +static void main_window_OnFileNewEvent (MainWindow* self); +void main_window_list_clear (MainWindow* self); +static void main_window_OnQuitEvent (MainWindow* self); +void main_window_list_del (MainWindow* self); +void main_window_setup_treeview (GtkTreeView* view); +gboolean main_window_readFunc (void); +static void main_window_OnGetInformation (MainWindow* self); +void main_window_msg (MainWindow* self, const gchar* str); +static void main_window_OnConnect (MainWindow* self); +static void main_window_OnStop (MainWindow* self); +static gboolean main_window_chk_queues (MainWindow* self); +static gint main_window_main (gchar** args, int args_length1); +MainWindow* main_window_new (void); +MainWindow* main_window_construct (GType object_type); +static gboolean _lambda1_ (GtkWidget* x, GdkEvent* y); +static gboolean __lambda1__gtk_widget_delete_event (GtkWidget* _sender, GdkEvent* event, gpointer self); +static GObject * main_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); +static void _main_window_OnFileNewEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnFileOpenEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnQuitEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnConnect_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnStop_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnGetInformation_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnReset_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnMenuHelpAboutActivatedEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self); +static void _main_window_OnConnect_gtk_button_clicked (GtkButton* _sender, gpointer self); +static void _main_window_OnStop_gtk_button_clicked (GtkButton* _sender, gpointer self); +static void _main_window_OnGetInformation_gtk_button_clicked (GtkButton* _sender, gpointer self); +static void _main_window_OnFileOpenEvent_gtk_button_clicked (GtkButton* _sender, gpointer self); +static void _main_window_list_del_gtk_button_clicked (GtkButton* _sender, gpointer self); +static void _main_window_OnFileFlashEvent_gtk_button_clicked (GtkButton* _sender, gpointer self); +static gboolean _gtk_widget_hide_on_delete_gtk_widget_delete_event (GtkWidget* _sender, GdkEvent* event, gpointer self); +static void main_window_finalize (GObject* obj); +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func); +static gint _vala_array_length (gpointer array); + + +static void main_window_doCloseApplication (MainWindow* self) { + g_return_if_fail (self != NULL); + gtk_main_quit (); +} + + +static void main_window_OnReset (MainWindow* self) { + g_return_if_fail (self != NULL); + squeue_push (main_window_q, "reset:device", 1); +} + + +static gpointer _g_object_ref0 (gpointer self) { + return self ? g_object_ref (self) : NULL; +} + + +static void main_window_OnFileFlashEvent (MainWindow* self) { + GtkTreeModel* _tmp0_ = NULL; + GtkListStore* _tmp1_; + GtkListStore* ls; + const gchar* str; + GtkTreeIter iter = {0}; + gint _tmp2_; + gint n; + g_return_if_fail (self != NULL); + _tmp0_ = gtk_tree_view_get_model (self->priv->tv); + _tmp1_ = _g_object_ref0 (GTK_LIST_STORE (_tmp0_)); + ls = _tmp1_; + str = NULL; + _tmp2_ = gtk_tree_model_iter_n_children ((GtkTreeModel*) ls, NULL); + n = _tmp2_; + if (n > 0) { + gboolean _tmp3_; + _tmp3_ = main_window_showYesNo (self, "Do you want to flash these files?"); + if (_tmp3_) { + GtkTreeIter _tmp4_ = {0}; + gtk_tree_model_get_iter_first ((GtkTreeModel*) ls, &_tmp4_); + iter = _tmp4_; + { + gboolean _tmp5_; + _tmp5_ = TRUE; + while (TRUE) { + if (!_tmp5_) { + gboolean _tmp6_; + _tmp6_ = gtk_tree_model_iter_next ((GtkTreeModel*) ls, &iter); + if (!_tmp6_) { + break; + } + } + _tmp5_ = FALSE; + gtk_tree_model_get ((GtkTreeModel*) ls, &iter, 2, &str, -1, -1); + squeue_push2 (main_window_q, "flash", str, 1); + } + } + } + } else { + main_window_showMessage (self, "No files selected", GTK_MESSAGE_ERROR); + } + _g_object_unref0 (ls); +} + + +static void main_window_OnFileOpenEvent (MainWindow* self) { + GtkFileChooserDialog* _tmp0_ = NULL; + GtkFileChooserDialog* fc; + gint _tmp1_; + gint resp; + g_return_if_fail (self != NULL); + _tmp0_ = (GtkFileChooserDialog*) gtk_file_chooser_dialog_new ("Select file to open", (GtkWindow*) self, GTK_FILE_CHOOSER_ACTION_OPEN, "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-open", GTK_RESPONSE_ACCEPT, NULL); + fc = g_object_ref_sink (_tmp0_); + _tmp1_ = gtk_dialog_run ((GtkDialog*) fc); + resp = _tmp1_; + gtk_widget_hide ((GtkWidget*) fc); + if (resp == GTK_RESPONSE_ACCEPT) { + gchar* _tmp2_ = NULL; + gchar* file; + gchar* _tmp3_ = NULL; + const gchar* type; + glong _tmp4_; + gchar* _tmp5_ = NULL; + gchar* size; + _tmp2_ = gtk_file_chooser_get_filename ((GtkFileChooser*) fc); + file = _tmp2_; + _tmp3_ = fpid_file (file); + type = _tmp3_; + _tmp4_ = fpid_size (file); + _tmp5_ = g_strdup_printf ("%ld", _tmp4_); + size = _tmp5_; + if (type == NULL) { + main_window_showMessage (self, "Invalid file type", GTK_MESSAGE_ERROR); + } else { + main_window_add_file (self, type, size, file); + } + _g_free0 (size); + _g_free0 (file); + } + gtk_object_destroy ((GtkObject*) fc); + _g_object_unref0 (fc); +} + + +gboolean main_window_loadFile (MainWindow* self, const gchar* filename) { + gboolean result = FALSE; + gint err; + gchar* contents; + gsize length = 0UL; + gchar* _tmp0_ = NULL; + gsize _tmp1_; + GError * _inner_error_ = NULL; + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + err = 0; + contents = NULL; + g_file_get_contents (filename, &_tmp0_, &_tmp1_, &_inner_error_); + _g_free0 (contents); + contents = _tmp0_; + length = _tmp1_; + if (_inner_error_ != NULL) { + _g_free0 (contents); + goto __catch0_g_error; + } + _g_free0 (contents); + goto __finally0; + __catch0_g_error: + { + GError * e; + gchar* _tmp2_; + e = _inner_error_; + _inner_error_ = NULL; + _tmp2_ = g_strconcat ("Unexpected error while loading the file, please contact the author wit" \ +"h the following information:\n" \ +"\n", e->message, NULL); + main_window_showError (self, _tmp2_); + _g_free0 (_tmp2_); + err++; + _g_error_free0 (e); + } + __finally0: + if (_inner_error_ != NULL) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); + g_clear_error (&_inner_error_); + return FALSE; + } + result = err == 0; + return result; +} + + +gboolean main_window_showYesNo (MainWindow* self, const gchar* s) { + gboolean result = FALSE; + GtkMessageDialog* _tmp0_ = NULL; + GtkMessageDialog* md; + gint _tmp1_; + gint ret; + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (s != NULL, FALSE); + _tmp0_ = (GtkMessageDialog*) gtk_message_dialog_new ((GtkWindow*) self, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, s); + md = g_object_ref_sink (_tmp0_); + _tmp1_ = gtk_dialog_run ((GtkDialog*) md); + ret = _tmp1_; + gtk_object_destroy ((GtkObject*) md); + result = ret == GTK_RESPONSE_YES; + _g_object_unref0 (md); + return result; +} + + +void main_window_showMessage (MainWindow* self, const gchar* s, GtkMessageType mt) { + GtkMessageDialog* _tmp0_ = NULL; + GtkMessageDialog* md; + g_return_if_fail (self != NULL); + g_return_if_fail (s != NULL); + _tmp0_ = (GtkMessageDialog*) gtk_message_dialog_new ((GtkWindow*) self, GTK_DIALOG_DESTROY_WITH_PARENT, mt, GTK_BUTTONS_CLOSE, s); + md = g_object_ref_sink (_tmp0_); + gtk_dialog_run ((GtkDialog*) md); + gtk_object_destroy ((GtkObject*) md); + _g_object_unref0 (md); +} + + +static void _lambda0_ (gint x, MainWindow* self) { + gtk_widget_hide ((GtkWidget*) self->priv->aboutdialog1); +} + + +static void __lambda0__gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) { + _lambda0_ (response_id, self); +} + + +static void main_window_OnMenuHelpAboutActivatedEvent (MainWindow* self) { + g_return_if_fail (self != NULL); + gtk_window_set_transient_for ((GtkWindow*) self->priv->aboutdialog1, (GtkWindow*) self); + g_signal_connect_object ((GtkDialog*) self->priv->aboutdialog1, "response", (GCallback) __lambda0__gtk_dialog_response, self, 0); + gtk_dialog_run ((GtkDialog*) self->priv->aboutdialog1); +} + + +void main_window_showError (MainWindow* self, const gchar* s) { + GtkMessageDialog* _tmp0_ = NULL; + GtkMessageDialog* md; + g_return_if_fail (self != NULL); + g_return_if_fail (s != NULL); + _tmp0_ = (GtkMessageDialog*) gtk_message_dialog_new ((GtkWindow*) self, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, s); + md = g_object_ref_sink (_tmp0_); + gtk_dialog_run ((GtkDialog*) md); + gtk_object_destroy ((GtkObject*) md); + _g_object_unref0 (md); +} + + +static void main_window_OnFileNewEvent (MainWindow* self) { + g_return_if_fail (self != NULL); + main_window_list_clear (self); +} + + +static void main_window_OnQuitEvent (MainWindow* self) { + g_return_if_fail (self != NULL); + main_window_doCloseApplication (self); +} + + +void main_window_list_clear (MainWindow* self) { + GtkTreeModel* _tmp0_ = NULL; + g_return_if_fail (self != NULL); + _tmp0_ = gtk_tree_view_get_model (self->priv->tv); + gtk_list_store_clear (GTK_LIST_STORE (_tmp0_)); +} + + +void main_window_list_del (MainWindow* self) { + GtkTreeIter iter = {0}; + GtkTreeModel* model; + GtkTreeSelection* _tmp0_ = NULL; + GtkTreeSelection* _tmp1_; + GtkTreeSelection* sel; + gint _tmp2_; + g_return_if_fail (self != NULL); + model = NULL; + _tmp0_ = gtk_tree_view_get_selection (self->priv->tv); + _tmp1_ = _g_object_ref0 (_tmp0_); + sel = _tmp1_; + _tmp2_ = gtk_tree_selection_count_selected_rows (sel); + if (_tmp2_ == 1) { + GtkTreeModel* _tmp3_ = NULL; + GtkTreeIter _tmp4_ = {0}; + GtkTreeModel* _tmp5_; + GtkTreeModel* _tmp6_ = NULL; + gtk_tree_selection_get_selected (sel, &_tmp3_, &_tmp4_); + _g_object_unref0 (model); + _tmp5_ = _g_object_ref0 (_tmp3_); + model = _tmp5_; + iter = _tmp4_; + _tmp6_ = gtk_tree_view_get_model (self->priv->tv); + gtk_list_store_remove (GTK_LIST_STORE (_tmp6_), &iter); + } + _g_object_unref0 (sel); + _g_object_unref0 (model); +} + + +void main_window_add_file (MainWindow* self, const gchar* type, const gchar* size, const gchar* file) { + GtkTreeModel* _tmp0_ = NULL; + GtkListStore* _tmp1_; + GtkListStore* listmodel; + GtkTreeIter iter = {0}; + GtkTreeIter _tmp2_ = {0}; + g_return_if_fail (self != NULL); + g_return_if_fail (type != NULL); + g_return_if_fail (size != NULL); + g_return_if_fail (file != NULL); + _tmp0_ = gtk_tree_view_get_model (self->priv->tv); + _tmp1_ = _g_object_ref0 (GTK_LIST_STORE (_tmp0_)); + listmodel = _tmp1_; + gtk_list_store_append (listmodel, &_tmp2_); + iter = _tmp2_; + gtk_list_store_set (listmodel, &iter, 0, type, 1, size, 2, file, -1, -1); + _g_object_unref0 (listmodel); +} + + +void main_window_setup_treeview (GtkTreeView* view) { + GtkListStore* _tmp0_ = NULL; + GtkListStore* listmodel; + GtkCellRendererText* _tmp1_ = NULL; + GtkCellRendererText* _tmp2_; + GtkCellRendererText* _tmp3_ = NULL; + GtkCellRendererText* _tmp4_; + GtkCellRendererText* _tmp5_ = NULL; + GtkCellRendererText* cell; + g_return_if_fail (view != NULL); + _tmp0_ = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + listmodel = _tmp0_; + gtk_tree_view_set_model (view, (GtkTreeModel*) listmodel); + _tmp1_ = (GtkCellRendererText*) gtk_cell_renderer_text_new (); + _tmp2_ = g_object_ref_sink (_tmp1_); + gtk_tree_view_insert_column_with_attributes (view, -1, "Type", (GtkCellRenderer*) _tmp2_, "text", 0, NULL, NULL); + _g_object_unref0 (_tmp2_); + _tmp3_ = (GtkCellRendererText*) gtk_cell_renderer_text_new (); + _tmp4_ = g_object_ref_sink (_tmp3_); + gtk_tree_view_insert_column_with_attributes (view, -1, "Size", (GtkCellRenderer*) _tmp4_, "text", 1, NULL, NULL); + _g_object_unref0 (_tmp4_); + _tmp5_ = (GtkCellRendererText*) gtk_cell_renderer_text_new (); + cell = g_object_ref_sink (_tmp5_); + g_object_set ((GObject*) cell, "foreground_set", TRUE, NULL, NULL); + gtk_tree_view_insert_column_with_attributes (view, -1, "Name", (GtkCellRenderer*) cell, "text", 2, "foreground", 3, NULL, NULL); + _g_object_unref0 (cell); + _g_object_unref0 (listmodel); +} + + +static gchar string_get (const gchar* self, glong index) { + gchar result = '\0'; + g_return_val_if_fail (self != NULL, '\0'); + result = ((gchar*) self)[index]; + return result; +} + + +gboolean main_window_readFunc (void) { + gboolean result = FALSE; + const gchar* _tmp0_ = NULL; + const gchar* msg; + gboolean _tmp1_ = FALSE; + _tmp0_ = squeue_get (main_window_p, 0); + msg = _tmp0_; + if (msg != NULL) { + gchar _tmp2_; + _tmp2_ = string_get (msg, (glong) 0); + _tmp1_ = _tmp2_ != '\0'; + } else { + _tmp1_ = FALSE; + } + if (_tmp1_) { + gchar** _tmp3_; + gchar** _tmp4_ = NULL; + gint foo_length1; + gint _foo_size_; + gchar** _tmp5_; + gchar** foo; + fprintf (stdout, "[<] msg received: %s\n", msg); + _tmp4_ = _tmp3_ = g_strsplit (msg, ":", 2); + _tmp5_ = _tmp4_; + foo_length1 = _vala_array_length (_tmp3_); + _foo_size_ = foo_length1; + foo = _tmp5_; + if (foo[1] != NULL) { + const gchar* _tmp6_; + GQuark _tmp7_; + static GQuark _tmp7__label0 = 0; + static GQuark _tmp7__label1 = 0; + static GQuark _tmp7__label2 = 0; + _tmp6_ = foo[0]; + _tmp7_ = (NULL == _tmp6_) ? 0 : g_quark_from_string (_tmp6_); + if (_tmp7_ == ((0 != _tmp7__label0) ? _tmp7__label0 : (_tmp7__label0 = g_quark_from_static_string ("bar")))) { + switch (0) { + default: + { + gint _tmp8_; + gchar* _tmp9_; + _tmp8_ = atoi (foo[1]); + gtk_progress_bar_set_fraction (main_window_viewer->priv->pb, (gdouble) (_tmp8_ / 100)); + _tmp9_ = g_strconcat (foo[1], "%", NULL); + gtk_progress_bar_set_text (main_window_viewer->priv->pb, _tmp9_); + _g_free0 (_tmp9_); + break; + } + } + } else if (_tmp7_ == ((0 != _tmp7__label1) ? _tmp7__label1 : (_tmp7__label1 = g_quark_from_static_string ("error")))) { + switch (0) { + default: + { + main_window_showMessage (main_window_viewer, foo[1], GTK_MESSAGE_ERROR); + break; + } + } + } else if (_tmp7_ == ((0 != _tmp7__label2) ? _tmp7__label2 : (_tmp7__label2 = g_quark_from_static_string ("info")))) { + switch (0) { + default: + { + main_window_showMessage (main_window_viewer, foo[1], GTK_MESSAGE_INFO); + break; + } + } + } else { + switch (0) { + default: + { + fprintf (stderr, "[E] Unknown message type\n"); + break; + } + } + } + } + squeue_pop (main_window_p); + foo = (_vala_array_free (foo, foo_length1, (GDestroyNotify) g_free), NULL); + } + result = TRUE; + return result; +} + + +static void main_window_OnGetInformation (MainWindow* self) { + g_return_if_fail (self != NULL); + main_window_msg (self, "info:device"); +} + + +static void main_window_OnConnect (MainWindow* self) { + g_return_if_fail (self != NULL); + main_window_OnStop (self); + system ("sudo 0xFFFF -Q &"); + squeue_close (main_window_p); + squeue_close (main_window_q); + main_window_q = NULL; + main_window_p = main_window_q; +} + + +static void main_window_OnStop (MainWindow* self) { + g_return_if_fail (self != NULL); + system ("sudo pkill 0xFFFF"); +} + + +static gboolean main_window_chk_queues (MainWindow* self) { + gboolean result = FALSE; + gboolean _tmp2_ = FALSE; + g_return_val_if_fail (self != NULL, FALSE); + if (main_window_p == NULL) { + struct squeue_t* _tmp0_ = NULL; + _tmp0_ = squeue_open ("/tmp/0xFFFF.1", (gint) Q_OPEN); + main_window_p = _tmp0_; + } + if (main_window_q == NULL) { + struct squeue_t* _tmp1_ = NULL; + _tmp1_ = squeue_open ("/tmp/0xFFFF.2", (gint) Q_OPEN); + main_window_q = _tmp1_; + } + if (main_window_p == NULL) { + _tmp2_ = TRUE; + } else { + _tmp2_ = main_window_q == NULL; + } + if (_tmp2_) { + main_window_showMessage (self, "Cannot connect to queues", GTK_MESSAGE_ERROR); + result = FALSE; + return result; + } + result = TRUE; + return result; +} + + +void main_window_msg (MainWindow* self, const gchar* str) { + gboolean _tmp0_; + gint _tmp1_; + g_return_if_fail (self != NULL); + g_return_if_fail (str != NULL); + _tmp0_ = main_window_chk_queues (self); + if (!_tmp0_) { + return; + } + _tmp1_ = squeue_push (main_window_q, str, 0); + if (_tmp1_ < 1) { + fprintf (stderr, "Oops on push\n"); + squeue_free (main_window_q); + main_window_q = NULL; + squeue_free (main_window_p); + main_window_p = NULL; + } +} + + +static gboolean _lambda1_ (GtkWidget* x, GdkEvent* y) { + gboolean result = FALSE; + g_return_val_if_fail (x != NULL, FALSE); + g_return_val_if_fail (y != NULL, FALSE); + gtk_main_quit (); + result = FALSE; + return result; +} + + +static gboolean __lambda1__gtk_widget_delete_event (GtkWidget* _sender, GdkEvent* event, gpointer self) { + gboolean result; + result = _lambda1_ (_sender, event); + return result; +} + + +static gint main_window_main (gchar** args, int args_length1) { + gint result = 0; + MainWindow* _tmp0_ = NULL; + MainWindow* _tmp1_; + GSourceFunc _tmp2_; + gtk_init (&args_length1, &args); + _tmp0_ = main_window_new (); + _tmp1_ = g_object_ref_sink (_tmp0_); + _g_object_unref0 (main_window_viewer); + main_window_viewer = _tmp1_; + if (args_length1 > 1) { + main_window_loadFile (main_window_viewer, args[1]); + } + gtk_window_resize ((GtkWindow*) main_window_viewer, 600, 400); + gtk_window_set_position ((GtkWindow*) main_window_viewer, GTK_WIN_POS_CENTER); + g_signal_connect ((GtkWidget*) main_window_viewer, "delete-event", (GCallback) __lambda1__gtk_widget_delete_event, NULL); + main_window_setup_treeview (main_window_viewer->priv->tv); + gtk_widget_show_all ((GtkWidget*) main_window_viewer); + _tmp2_ = (GSourceFunc) main_window_readFunc; + g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 200, _tmp2_, NULL, NULL); + gtk_main (); + result = 0; + return result; +} + + +int main (int argc, char ** argv) { + g_type_init (); + return main_window_main (argv, argc); +} + + +MainWindow* main_window_construct (GType object_type) { + MainWindow * self = NULL; + self = (MainWindow*) g_object_new (object_type, NULL); + return self; +} + + +MainWindow* main_window_new (void) { + return main_window_construct (TYPE_MAIN_WINDOW); +} + + +static void _main_window_OnFileNewEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnFileNewEvent (self); +} + + +static void _main_window_OnFileOpenEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnFileOpenEvent (self); +} + + +static void _main_window_OnQuitEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnQuitEvent (self); +} + + +static void _main_window_OnConnect_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnConnect (self); +} + + +static void _main_window_OnStop_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnStop (self); +} + + +static void _main_window_OnGetInformation_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnGetInformation (self); +} + + +static void _main_window_OnReset_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnReset (self); +} + + +static void _main_window_OnMenuHelpAboutActivatedEvent_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) { + main_window_OnMenuHelpAboutActivatedEvent (self); +} + + +static void _main_window_OnConnect_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_OnConnect (self); +} + + +static void _main_window_OnStop_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_OnStop (self); +} + + +static void _main_window_OnGetInformation_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_OnGetInformation (self); +} + + +static void _main_window_OnFileOpenEvent_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_OnFileOpenEvent (self); +} + + +static void _main_window_list_del_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_list_del (self); +} + + +static void _main_window_OnFileFlashEvent_gtk_button_clicked (GtkButton* _sender, gpointer self) { + main_window_OnFileFlashEvent (self); +} + + +static gboolean _gtk_widget_hide_on_delete_gtk_widget_delete_event (GtkWidget* _sender, GdkEvent* event, gpointer self) { + gboolean result; + result = gtk_widget_hide_on_delete (self); + return result; +} + + +static GObject * main_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) { + GObject * obj; + GObjectClass * parent_class; + MainWindow * self; + GtkVBox* _vbox0; + GtkMenuBar* _menubar0; + GtkMenuItem* _menuitem0; + GtkMenu* _menu0; + GtkImageMenuItem* _imagemenuitem0; + GtkImageMenuItem* _imagemenuitem1; + GtkSeparatorMenuItem* _separatormenuitem0; + GtkImageMenuItem* _imagemenuitem2; + GtkMenuItem* _menuitem1; + GtkMenu* _menu1; + GtkImageMenuItem* _imagemenuitem3; + GtkImageMenuItem* _imagemenuitem4; + GtkImageMenuItem* _imagemenuitem5; + GtkImageMenuItem* _imagemenuitem6; + GtkMenuItem* _menuitem2; + GtkMenu* _menu2; + GtkImageMenuItem* _imagemenuitem7; + GtkHBox* _hbox0; + GtkVBox* _vbox1; + GtkScrolledWindow* _scrolledwindow0; + GtkVBox* _vbox2; + GtkButton* _button0; + GtkButton* _button1; + GtkButton* _button2; + GtkLabel* _label0; + GtkButton* _button3; + GtkButton* _button4; + GtkLabel* _label1; + GtkButton* _button5; + GtkVBox* _tmp0_ = NULL; + GtkVBox* _tmp1_; + GtkMenuBar* _tmp2_ = NULL; + GtkMenuBar* _tmp3_; + GtkMenu* _tmp4_ = NULL; + GtkMenu* _tmp5_; + GtkImageMenuItem* _tmp6_ = NULL; + GtkImageMenuItem* _tmp7_; + GtkImageMenuItem* _tmp8_ = NULL; + GtkImageMenuItem* _tmp9_; + GtkSeparatorMenuItem* _tmp10_ = NULL; + GtkSeparatorMenuItem* _tmp11_; + GtkImageMenuItem* _tmp12_ = NULL; + GtkImageMenuItem* _tmp13_; + GtkMenuItem* _tmp14_ = NULL; + GtkMenuItem* _tmp15_; + GtkMenu* _tmp16_ = NULL; + GtkMenu* _tmp17_; + GtkImageMenuItem* _tmp18_ = NULL; + GtkImageMenuItem* _tmp19_; + GtkImageMenuItem* _tmp20_ = NULL; + GtkImageMenuItem* _tmp21_; + GtkImageMenuItem* _tmp22_ = NULL; + GtkImageMenuItem* _tmp23_; + GtkImageMenuItem* _tmp24_ = NULL; + GtkImageMenuItem* _tmp25_; + GtkMenuItem* _tmp26_ = NULL; + GtkMenuItem* _tmp27_; + GtkMenu* _tmp28_ = NULL; + GtkMenu* _tmp29_; + GtkImageMenuItem* _tmp30_ = NULL; + GtkImageMenuItem* _tmp31_; + GtkMenuItem* _tmp32_ = NULL; + GtkMenuItem* _tmp33_; + GtkHBox* _tmp34_ = NULL; + GtkHBox* _tmp35_; + GtkVBox* _tmp36_ = NULL; + GtkVBox* _tmp37_; + GtkScrolledWindow* _tmp38_ = NULL; + GtkScrolledWindow* _tmp39_; + GtkTreeView* _tmp40_ = NULL; + GtkTreeView* _tmp41_; + GtkVBox* _tmp42_ = NULL; + GtkVBox* _tmp43_; + GtkButton* _tmp44_ = NULL; + GtkButton* _tmp45_; + GtkButton* _tmp46_ = NULL; + GtkButton* _tmp47_; + GtkButton* _tmp48_ = NULL; + GtkButton* _tmp49_; + GtkLabel* _tmp50_ = NULL; + GtkLabel* _tmp51_; + GtkButton* _tmp52_ = NULL; + GtkButton* _tmp53_; + GtkButton* _tmp54_ = NULL; + GtkButton* _tmp55_; + GtkLabel* _tmp56_ = NULL; + GtkLabel* _tmp57_; + GtkButton* _tmp58_ = NULL; + GtkButton* _tmp59_; + GtkProgressBar* _tmp60_ = NULL; + GtkProgressBar* _tmp61_; + GtkAboutDialog* _tmp62_ = NULL; + GtkAboutDialog* _tmp63_; + gchar* _tmp64_; + gchar** _tmp65_ = NULL; + gchar** _tmp66_; + gint _tmp66__length1; + parent_class = G_OBJECT_CLASS (main_window_parent_class); + obj = parent_class->constructor (type, n_construct_properties, construct_properties); + self = MAIN_WINDOW (obj); + _vbox0 = NULL; + _menubar0 = NULL; + _menuitem0 = NULL; + _menu0 = NULL; + _imagemenuitem0 = NULL; + _imagemenuitem1 = NULL; + _separatormenuitem0 = NULL; + _imagemenuitem2 = NULL; + _menuitem1 = NULL; + _menu1 = NULL; + _imagemenuitem3 = NULL; + _imagemenuitem4 = NULL; + _imagemenuitem5 = NULL; + _imagemenuitem6 = NULL; + _menuitem2 = NULL; + _menu2 = NULL; + _imagemenuitem7 = NULL; + _hbox0 = NULL; + _vbox1 = NULL; + _scrolledwindow0 = NULL; + _vbox2 = NULL; + _button0 = NULL; + _button1 = NULL; + _button2 = NULL; + _label0 = NULL; + _button3 = NULL; + _button4 = NULL; + _label1 = NULL; + _button5 = NULL; + _tmp0_ = (GtkVBox*) gtk_vbox_new (FALSE, 0); + _tmp1_ = g_object_ref_sink (_tmp0_); + _g_object_unref0 (_vbox0); + _vbox0 = _tmp1_; + _tmp2_ = (GtkMenuBar*) gtk_menu_bar_new (); + _tmp3_ = g_object_ref_sink (_tmp2_); + _g_object_unref0 (_menubar0); + _menubar0 = _tmp3_; + _tmp4_ = (GtkMenu*) gtk_menu_new (); + _tmp5_ = g_object_ref_sink (_tmp4_); + _g_object_unref0 (_menu0); + _menu0 = _tmp5_; + _tmp6_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-new", NULL); + _tmp7_ = g_object_ref_sink (_tmp6_); + _g_object_unref0 (_imagemenuitem0); + _imagemenuitem0 = _tmp7_; + _tmp8_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-open", NULL); + _tmp9_ = g_object_ref_sink (_tmp8_); + _g_object_unref0 (_imagemenuitem1); + _imagemenuitem1 = _tmp9_; + _tmp10_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new (); + _tmp11_ = g_object_ref_sink (_tmp10_); + _g_object_unref0 (_separatormenuitem0); + _separatormenuitem0 = _tmp11_; + _tmp12_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-quit", NULL); + _tmp13_ = g_object_ref_sink (_tmp12_); + _g_object_unref0 (_imagemenuitem2); + _imagemenuitem2 = _tmp13_; + _tmp14_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic ("_File"); + _tmp15_ = g_object_ref_sink (_tmp14_); + _g_object_unref0 (_menuitem0); + _menuitem0 = _tmp15_; + _tmp16_ = (GtkMenu*) gtk_menu_new (); + _tmp17_ = g_object_ref_sink (_tmp16_); + _g_object_unref0 (_menu1); + _menu1 = _tmp17_; + _tmp18_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-connect", NULL); + _tmp19_ = g_object_ref_sink (_tmp18_); + _g_object_unref0 (_imagemenuitem3); + _imagemenuitem3 = _tmp19_; + _tmp20_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-stop", NULL); + _tmp21_ = g_object_ref_sink (_tmp20_); + _g_object_unref0 (_imagemenuitem4); + _imagemenuitem4 = _tmp21_; + _tmp22_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-info", NULL); + _tmp23_ = g_object_ref_sink (_tmp22_); + _g_object_unref0 (_imagemenuitem5); + _imagemenuitem5 = _tmp23_; + _tmp24_ = (GtkImageMenuItem*) gtk_image_menu_item_new_with_label ("Reset"); + _tmp25_ = g_object_ref_sink (_tmp24_); + _g_object_unref0 (_imagemenuitem6); + _imagemenuitem6 = _tmp25_; + _tmp26_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic ("_Target"); + _tmp27_ = g_object_ref_sink (_tmp26_); + _g_object_unref0 (_menuitem1); + _menuitem1 = _tmp27_; + _tmp28_ = (GtkMenu*) gtk_menu_new (); + _tmp29_ = g_object_ref_sink (_tmp28_); + _g_object_unref0 (_menu2); + _menu2 = _tmp29_; + _tmp30_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-about", NULL); + _tmp31_ = g_object_ref_sink (_tmp30_); + _g_object_unref0 (_imagemenuitem7); + _imagemenuitem7 = _tmp31_; + _tmp32_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic ("_Help"); + _tmp33_ = g_object_ref_sink (_tmp32_); + _g_object_unref0 (_menuitem2); + _menuitem2 = _tmp33_; + _tmp34_ = (GtkHBox*) gtk_hbox_new (FALSE, 0); + _tmp35_ = g_object_ref_sink (_tmp34_); + _g_object_unref0 (_hbox0); + _hbox0 = _tmp35_; + _tmp36_ = (GtkVBox*) gtk_vbox_new (FALSE, 3); + _tmp37_ = g_object_ref_sink (_tmp36_); + _g_object_unref0 (_vbox1); + _vbox1 = _tmp37_; + _tmp38_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL); + _tmp39_ = g_object_ref_sink (_tmp38_); + _g_object_unref0 (_scrolledwindow0); + _scrolledwindow0 = _tmp39_; + _tmp40_ = (GtkTreeView*) gtk_tree_view_new (); + _tmp41_ = g_object_ref_sink (_tmp40_); + _g_object_unref0 (self->priv->tv); + self->priv->tv = _tmp41_; + _tmp42_ = (GtkVBox*) gtk_vbox_new (FALSE, 3); + _tmp43_ = g_object_ref_sink (_tmp42_); + _g_object_unref0 (_vbox2); + _vbox2 = _tmp43_; + _tmp44_ = (GtkButton*) gtk_button_new_with_label ("gtk-connect"); + _tmp45_ = g_object_ref_sink (_tmp44_); + _g_object_unref0 (_button0); + _button0 = _tmp45_; + _tmp46_ = (GtkButton*) gtk_button_new_with_label ("gtk-stop"); + _tmp47_ = g_object_ref_sink (_tmp46_); + _g_object_unref0 (_button1); + _button1 = _tmp47_; + _tmp48_ = (GtkButton*) gtk_button_new_with_label ("gtk-info"); + _tmp49_ = g_object_ref_sink (_tmp48_); + _g_object_unref0 (_button2); + _button2 = _tmp49_; + _tmp50_ = (GtkLabel*) gtk_label_new (""); + _tmp51_ = g_object_ref_sink (_tmp50_); + _g_object_unref0 (_label0); + _label0 = _tmp51_; + _tmp52_ = (GtkButton*) gtk_button_new_with_label ("gtk-add"); + _tmp53_ = g_object_ref_sink (_tmp52_); + _g_object_unref0 (_button3); + _button3 = _tmp53_; + _tmp54_ = (GtkButton*) gtk_button_new_with_label ("gtk-remove"); + _tmp55_ = g_object_ref_sink (_tmp54_); + _g_object_unref0 (_button4); + _button4 = _tmp55_; + _tmp56_ = (GtkLabel*) gtk_label_new (""); + _tmp57_ = g_object_ref_sink (_tmp56_); + _g_object_unref0 (_label1); + _label1 = _tmp57_; + _tmp58_ = (GtkButton*) gtk_button_new_with_label ("gtk-media-record"); + _tmp59_ = g_object_ref_sink (_tmp58_); + _g_object_unref0 (_button5); + _button5 = _tmp59_; + _tmp60_ = (GtkProgressBar*) gtk_progress_bar_new (); + _tmp61_ = g_object_ref_sink (_tmp60_); + _g_object_unref0 (self->priv->pb); + self->priv->pb = _tmp61_; + _tmp62_ = (GtkAboutDialog*) gtk_about_dialog_new (); + _tmp63_ = g_object_ref_sink (_tmp62_); + _g_object_unref0 (self->priv->aboutdialog1); + self->priv->aboutdialog1 = _tmp63_; + g_object_set ((GtkWindow*) self, "type", GTK_WINDOW_TOPLEVEL, NULL); + gtk_window_set_title ((GtkWindow*) self, "0xFFFF GUI"); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem0, "activate", (GCallback) _main_window_OnFileNewEvent_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu0, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem0)); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem1, "activate", (GCallback) _main_window_OnFileOpenEvent_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu0, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem1)); + gtk_menu_shell_append ((GtkMenuShell*) _menu0, (GtkWidget*) ((GtkMenuItem*) _separatormenuitem0)); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem2, "activate", (GCallback) _main_window_OnQuitEvent_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu0, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem2)); + gtk_menu_item_set_submenu (_menuitem0, _menu0); + gtk_menu_shell_append ((GtkMenuShell*) _menubar0, (GtkWidget*) _menuitem0); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem3, "activate", (GCallback) _main_window_OnConnect_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu1, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem3)); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem4, "activate", (GCallback) _main_window_OnStop_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu1, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem4)); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem5, "activate", (GCallback) _main_window_OnGetInformation_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu1, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem5)); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem6, "activate", (GCallback) _main_window_OnReset_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu1, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem6)); + gtk_menu_item_set_submenu (_menuitem1, _menu1); + gtk_menu_shell_append ((GtkMenuShell*) _menubar0, (GtkWidget*) _menuitem1); + g_signal_connect_object ((GtkMenuItem*) _imagemenuitem7, "activate", (GCallback) _main_window_OnMenuHelpAboutActivatedEvent_gtk_menu_item_activate, self, 0); + gtk_menu_shell_append ((GtkMenuShell*) _menu2, (GtkWidget*) ((GtkMenuItem*) _imagemenuitem7)); + gtk_menu_item_set_submenu (_menuitem2, _menu2); + gtk_menu_shell_append ((GtkMenuShell*) _menubar0, (GtkWidget*) _menuitem2); + gtk_box_pack_start ((GtkBox*) _vbox0, (GtkWidget*) _menubar0, FALSE, TRUE, (guint) 0); + gtk_container_set_border_width ((GtkContainer*) _hbox0, (guint) 5); + gtk_container_set_border_width ((GtkContainer*) _vbox1, (guint) 3); + g_object_set ((GtkWidget*) _scrolledwindow0, "can-focus", TRUE, NULL); + g_object_set (_scrolledwindow0, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL); + g_object_set (_scrolledwindow0, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL); + gtk_container_add ((GtkContainer*) _scrolledwindow0, (GtkWidget*) self->priv->tv); + gtk_container_add ((GtkContainer*) _vbox1, (GtkWidget*) _scrolledwindow0); + gtk_container_add ((GtkContainer*) _hbox0, (GtkWidget*) _vbox1); + gtk_container_set_border_width ((GtkContainer*) _vbox2, (guint) 3); + gtk_button_set_use_stock (_button0, TRUE); + g_signal_connect_object (_button0, "clicked", (GCallback) _main_window_OnConnect_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button0, FALSE, TRUE, (guint) 0); + gtk_button_set_use_stock (_button1, TRUE); + g_signal_connect_object (_button1, "clicked", (GCallback) _main_window_OnStop_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button1, FALSE, TRUE, (guint) 0); + gtk_button_set_use_stock (_button2, TRUE); + g_signal_connect_object (_button2, "clicked", (GCallback) _main_window_OnGetInformation_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button2, FALSE, TRUE, (guint) 0); + gtk_container_add ((GtkContainer*) _vbox2, (GtkWidget*) _label0); + gtk_button_set_use_stock (_button3, TRUE); + g_signal_connect_object (_button3, "clicked", (GCallback) _main_window_OnFileOpenEvent_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button3, FALSE, TRUE, (guint) 0); + gtk_button_set_use_stock (_button4, TRUE); + g_signal_connect_object (_button4, "clicked", (GCallback) _main_window_list_del_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button4, FALSE, TRUE, (guint) 0); + gtk_container_add ((GtkContainer*) _vbox2, (GtkWidget*) _label1); + gtk_button_set_use_stock (_button5, TRUE); + g_signal_connect_object (_button5, "clicked", (GCallback) _main_window_OnFileFlashEvent_gtk_button_clicked, self, 0); + gtk_box_pack_start ((GtkBox*) _vbox2, (GtkWidget*) _button5, FALSE, TRUE, (guint) 0); + gtk_box_pack_start ((GtkBox*) _hbox0, (GtkWidget*) _vbox2, FALSE, TRUE, (guint) 0); + gtk_container_add ((GtkContainer*) _vbox0, (GtkWidget*) _hbox0); + gtk_box_pack_start ((GtkBox*) _vbox0, (GtkWidget*) self->priv->pb, FALSE, TRUE, (guint) 0); + gtk_container_add ((GtkContainer*) self, (GtkWidget*) _vbox0); + g_signal_connect_object ((GtkWidget*) self->priv->aboutdialog1, "delete-event", (GCallback) _gtk_widget_hide_on_delete_gtk_widget_delete_event, (GtkWidget*) self->priv->aboutdialog1, 0); + gtk_container_set_border_width ((GtkContainer*) self->priv->aboutdialog1, (guint) 5); + gtk_window_set_title ((GtkWindow*) self->priv->aboutdialog1, "About 0xFFFF gui"); + gtk_window_set_resizable ((GtkWindow*) self->priv->aboutdialog1, FALSE); + gtk_window_set_modal ((GtkWindow*) self->priv->aboutdialog1, TRUE); + g_object_set ((GtkWindow*) self->priv->aboutdialog1, "window-position", GTK_WIN_POS_CENTER_ON_PARENT, NULL); + gtk_dialog_set_has_separator ((GtkDialog*) self->priv->aboutdialog1, FALSE); + gtk_about_dialog_set_program_name (self->priv->aboutdialog1, "0xFFFF"); + gtk_about_dialog_set_version (self->priv->aboutdialog1, "0.5"); + gtk_about_dialog_set_copyright (self->priv->aboutdialog1, "Copyright (c) 2007-2009 pancake"); + gtk_about_dialog_set_comments (self->priv->aboutdialog1, "The Free Nokia Internet Tablet flasher"); + gtk_about_dialog_set_website (self->priv->aboutdialog1, "http://www.nopcode.org/0xFFFF/"); + _tmp64_ = g_strdup ("pancake (pancake@youterm.com)"); + _tmp65_ = g_new0 (gchar*, 2 + 1); + _tmp65_[0] = _tmp64_; + _tmp65_[1] = NULL; + _tmp66_ = _tmp65_; + _tmp66__length1 = 2; + gtk_about_dialog_set_authors (self->priv->aboutdialog1, _tmp66_); + _tmp66_ = (_vala_array_free (_tmp66_, _tmp66__length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_button5); + _g_object_unref0 (_label1); + _g_object_unref0 (_button4); + _g_object_unref0 (_button3); + _g_object_unref0 (_label0); + _g_object_unref0 (_button2); + _g_object_unref0 (_button1); + _g_object_unref0 (_button0); + _g_object_unref0 (_vbox2); + _g_object_unref0 (_scrolledwindow0); + _g_object_unref0 (_vbox1); + _g_object_unref0 (_hbox0); + _g_object_unref0 (_imagemenuitem7); + _g_object_unref0 (_menu2); + _g_object_unref0 (_menuitem2); + _g_object_unref0 (_imagemenuitem6); + _g_object_unref0 (_imagemenuitem5); + _g_object_unref0 (_imagemenuitem4); + _g_object_unref0 (_imagemenuitem3); + _g_object_unref0 (_menu1); + _g_object_unref0 (_menuitem1); + _g_object_unref0 (_imagemenuitem2); + _g_object_unref0 (_separatormenuitem0); + _g_object_unref0 (_imagemenuitem1); + _g_object_unref0 (_imagemenuitem0); + _g_object_unref0 (_menu0); + _g_object_unref0 (_menuitem0); + _g_object_unref0 (_menubar0); + _g_object_unref0 (_vbox0); + return obj; +} + + +static void main_window_class_init (MainWindowClass * klass) { + main_window_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (MainWindowPrivate)); + G_OBJECT_CLASS (klass)->constructor = main_window_constructor; + G_OBJECT_CLASS (klass)->finalize = main_window_finalize; +} + + +static void main_window_instance_init (MainWindow * self) { + self->priv = MAIN_WINDOW_GET_PRIVATE (self); +} + + +static void main_window_finalize (GObject* obj) { + MainWindow * self; + self = MAIN_WINDOW (obj); + _g_object_unref0 (self->priv->tv); + _g_object_unref0 (self->priv->pb); + _g_object_unref0 (self->priv->aboutdialog1); + G_OBJECT_CLASS (main_window_parent_class)->finalize (obj); +} + + +GType main_window_get_type (void) { + static volatile gsize main_window_type_id__volatile = 0; + if (g_once_init_enter (&main_window_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (MainWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MainWindow), 0, (GInstanceInitFunc) main_window_instance_init, NULL }; + GType main_window_type_id; + main_window_type_id = g_type_register_static (GTK_TYPE_WINDOW, "MainWindow", &g_define_type_info, 0); + g_once_init_leave (&main_window_type_id__volatile, main_window_type_id); + } + return main_window_type_id__volatile; +} + + +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) { + if ((array != NULL) && (destroy_func != NULL)) { + int i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + + +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) { + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + + +static gint _vala_array_length (gpointer array) { + int length; + length = 0; + if (array) { + while (((gpointer*) array)[length]) { + length++; + } + } + return length; +} + + + diff --git a/src/gui/gui.gtkaml b/src/gui/gui.gtkaml.orig index e5c9e97..7e73a1a 100644 --- a/src/gui/gui.gtkaml +++ b/src/gui/gui.gtkaml.orig @@ -78,7 +78,7 @@ <AboutDialog class:standalone="true" class:private="aboutdialog1" delete-event="{aboutdialog1.hide_on_delete}" border-width="5" title="About 0xFFFF gui" resizable="false" modal="true" window-position="{WindowPosition.CENTER_ON_PARENT}" has-separator="false" - program-name="0xFFFF" version="0.3.9" copyright="Copyright (c) 2008 pancake" + program-name="0xFFFF" version="0.5" copyright="Copyright (c) 2007-2009 pancake" comments="The Free Nokia Internet Tablet flasher" website="http://www.nopcode.org/0xFFFF/" authors='{new string[] {"pancake (pancake@youterm.com)", null}}'> @@ -143,7 +143,7 @@ public bool loadFile( string filename ) { int err = 0; try { - string contents; int length; + string contents; size_t length; FileUtils.get_contents (filename, out contents, out length); //textview1.buffer.set_text (contents, length); } catch(Error e) { diff --git a/src/gui/gui.gtkon b/src/gui/gui.gtkon new file mode 100644 index 0000000..b684e13 --- /dev/null +++ b/src/gui/gui.gtkon @@ -0,0 +1,321 @@ +/* + | Frontend for the 0xFFFF flasher in gtkaml + | author: pancake <youterm.com> + */ + +Window using="Gtk" gtkon:version=0.4 + using:Extras="Extras" + using:SQueues="SQueues" + name="MainWindow" + title="0xFFFF GUI" +{ + /* delete-event="{OnWindow1DeleteEvent}" */ + VBox { + MenuBar !expand { + MenuItem label="_File" with-mnemonic { + submenu { + Menu { + ImageMenuItem stock-id="gtk-new" activate=OnFileNewEvent; + ImageMenuItem stock-id="gtk-open" activate=OnFileOpenEvent; + SeparatorMenuItem; + ImageMenuItem stock-id="gtk-quit" activate=OnQuitEvent; + } + } + } + MenuItem label="_Target" with-mnemonic { + submenu { + Menu { + ImageMenuItem stock-id="gtk-connect" activate=OnConnect; + ImageMenuItem stock-id="gtk-stop" activate=OnStop; + ImageMenuItem stock-id="gtk-info" activate=OnGetInformation; + ImageMenuItem label="Reset" activate=OnReset; + } + } + } + MenuItem label="_Help" with-mnemonic { + submenu { + Menu { + ImageMenuItem stock-id="gtk-about" activate=OnMenuHelpAboutActivatedEvent; + } + } + } + } + + HBox border-width="5" { + VBox border-width="3" spacing="3" { + ScrolledWindow can-focus="true" hscrollbar-policy="{PolicyType.AUTOMATIC}" vscrollbar-policy="{PolicyType.AUTOMATIC}" { + TreeView $.tv; + } + + } + VBox !expand border-width="3" spacing="3" { + Button label="gtk-connect" use-stock !expand clicked=OnConnect; + Button label="gtk-stop" use-stock !expand clicked=OnStop; + Button label="gtk-info" use-stock !expand clicked=OnGetInformation; + Label label=""; + /* + <!-- <Button label="Options" use-stock="false" expand="false"/> + <Button label="Fiasco!" use-stock="false" expand="false"/> + <Button label="Unpack!" use-stock="false" expand/> --> + */ + Button label="gtk-add" use-stock="true" !expand clicked=OnFileOpenEvent; + Button label="gtk-remove" use-stock="true" expand="false" clicked=list_del; + Label label=""; + Button label="gtk-media-record" use-stock="true" expand="false" clicked=OnFileFlashEvent; + } + } + ProgressBar $.pb !expand; + + //<!-- <Statusbar expand="false"/> --> + } + AboutDialog gtkaml:standalone $.aboutdialog1 delete-event=aboutdialog1.hide_on_delete + border-width="5" title="About 0xFFFF gui" resizable="false" modal="true" + window-position="{WindowPosition.CENTER_ON_PARENT}" has-separator="false" + program-name="0xFFFF" version="0.5" copyright="Copyright (c) 2007-2009 pancake" + comments="The Free Nokia Internet Tablet flasher" + website="http://www.nopcode.org/0xFFFF/" + authors='{new string[] {"pancake (pancake@youterm.com)", null}}'; + + -{ + + + private void doCloseApplication () { + Gtk.main_quit (); + } + + private void OnReset() { + q->push("reset:device", 1); + } + + private void OnFileFlashEvent() { + ListStore ls = (ListStore)tv.get_model(); + weak string str; + TreeIter iter; + + int n = ls.iter_n_children(null); + if (n >0) { + if (showYesNo("Do you want to flash these files?")) { + ls.get_iter_first(out iter); + do { + ls.get(iter, 2, out str, -1); + //stdout.printf("polla:%s\n", str); + q->push2("flash", str, 1); + } while(ls.iter_next(ref iter)); + } + } else showMessage("No files selected", MessageType.ERROR); + } + + private void OnFileOpenEvent () { + FileChooserDialog fc = new FileChooserDialog("Select file to open", + this, FileChooserAction.OPEN, + "gtk-cancel", ResponseType.CANCEL, + "gtk-open", ResponseType.ACCEPT); + int resp = fc.run (); + fc.hide (); + if (resp == ResponseType.ACCEPT) { + string file = fc.get_filename(); + string *type = External.fpid_file(file); + string size = "%ld".printf(External.fpid_size(file)); + if (type == null) + showMessage("Invalid file type", MessageType.ERROR); + else add_file(type, size, file); + } + fc.destroy (); + } + + public bool loadFile( string filename ) { + int err = 0; + try { + string contents; size_t length; + FileUtils.get_contents (filename, out contents, out length); + //textview1.buffer.set_text (contents, length); + } catch(Error e) { + showError ("Unexpected error while loading the file, please contact the author with the following information:\n\n" + e.message); + err++; + } + return err == 0; + } + + public bool showYesNo(string s) { + MessageDialog md = new MessageDialog (this, + DialogFlags.DESTROY_WITH_PARENT, + MessageType.QUESTION, ButtonsType.YES_NO, s); + int ret = md.run (); + md.destroy (); + return ret==ResponseType.YES; + } + + public void showMessage(string s, MessageType mt) { + MessageDialog md = new MessageDialog (this, + DialogFlags.DESTROY_WITH_PARENT, + mt, ButtonsType.CLOSE, s); + md.run (); + md.destroy (); + } + + private void OnMenuHelpAboutActivatedEvent () { + aboutdialog1.transient_for = this; + aboutdialog1.response.connect ((x)=> { aboutdialog1.hide (); }); + aboutdialog1.run (); + } + + public void showError (string s) { + MessageDialog md = new MessageDialog (this, + DialogFlags.DESTROY_WITH_PARENT, + MessageType.ERROR, + ButtonsType.CLOSE, + s); + md.run (); + md.destroy (); + } + + private void OnFileNewEvent () { + list_clear(); + // TODO: clear file list + } + + private void OnQuitEvent () { + doCloseApplication(); + // TODO: send message to gracefully kill 0xFFFF + // TODO: handle ^C when flashing + } + + public void list_clear() { + ((ListStore)tv.model).clear(); + } + + public void list_del() { + TreeIter iter; + TreeModel model; + + TreeSelection sel = tv.get_selection(); + + if (sel.count_selected_rows() == 1) { + sel.get_selected(out model, out iter); + ((ListStore)tv.model).remove(iter); + } + } + + public void add_file(string type, string size, string file) { + ListStore listmodel = (ListStore)tv.get_model(); + Gtk.TreeIter iter; + listmodel.append (out iter); + listmodel.set (iter, 0, type, 1, size, 2, file, -1); + } + + public static void setup_treeview (Gtk.TreeView view) { + /* use liststore to hold accountname, accounttype, balance and color attribute */ + /* for more info how gtkTreeview works take a look in the GTK API */ + + var listmodel = new Gtk.ListStore(4, typeof(string), typeof(string), typeof(string), typeof(string)); + view.set_model(listmodel); + + view.insert_column_with_attributes (-1, "Type", new Gtk.CellRendererText(), "text", 0, null); + view.insert_column_with_attributes (-1, "Size", new Gtk.CellRendererText(), "text", 1, null); + + var cell = new Gtk.CellRendererText (); + cell.set ("foreground_set", true, null); + view.insert_column_with_attributes (-1, "Name", cell, "text", 2, "foreground", 3, null); + + // Gtk.TreeIter iter; + // listmodel.append (out iter); + // listmodel.set (iter, 0, "initfs", 1, "3M", 2, "initfs.jffs", -1); + //listmodel.set (iter, 0, "initfs", 1, "3M", 2, "initfs.jffs", 3, "green", -1); + + // listmodel.append (out iter); + // listmodel.set (iter, 0, "rootfs", 1, "52M", 2, "rootfs.jffs", -1); + } + + public static bool readFunc() { + weak string msg = p->get(0); + + if (msg != null && msg[0]!='\0') { + stdout.printf("[<] msg received: %s\n", msg); + string[] foo = msg.split(":",2); + if (foo[1] != null) { + switch(foo[0]) { + case "bar": + viewer.pb.fraction = foo[1].to_int() / 100; + viewer.pb.text = foo[1]+"%"; + break; + case "error": + viewer.showMessage(foo[1], MessageType.ERROR); + break; + case "info": + viewer.showMessage(foo[1], MessageType.INFO); + break; + default: + stderr.printf("[E] Unknown message type\n"); + break; + } + //viewer.showMessage(msg, MessageType.INFO); + } + p->pop(); + } + return true; + } + + static SQueue *q = null; + static SQueue *p = null; + + private void OnGetInformation() { + msg("info:device"); + } + + private void OnConnect() { + //msg("connect:device"); + OnStop(); + External.system("sudo 0xFFFF -Q &"); + p->close(); + q->close(); + p = q = null; + } + + private void OnStop() { + External.system("sudo pkill 0xFFFF"); + } + + private bool chk_queues() { + if (p == null) + p = SQueue.open("/tmp/0xFFFF.1", SQueueMode.OPEN); + if (q == null) + q = SQueue.open("/tmp/0xFFFF.2", SQueueMode.OPEN); + if (p == null || q == null) { + showMessage("Cannot connect to queues", MessageType.ERROR); + return false; + } + return true; + } + + public void msg(string str) { + if (!chk_queues()) + return; + if (q->push(str, 0)<1) { + stderr.printf("Oops on push\n"); + q->free(); + q = null; + p->free(); + p = null; + } + } + + static MainWindow viewer; + + static int main (string[] args) { + Gtk.init (ref args); + viewer = new MainWindow(); + if (args.length > 1) + viewer.loadFile (args[1]); + viewer.resize(600,400); + viewer.set_position(WindowPosition.CENTER); + viewer.delete_event.connect ((x,y) => { Gtk.main_quit(); return false; }); + setup_treeview(viewer.tv); + viewer.show_all (); + // viewer.showMessage("This software is beta and does not guaranties correct functionality", MessageType.WARNING); + Timeout.add(200, (SourceFunc)(readFunc)); + Gtk.main (); + return 0; + } + + }- +} @@ -1,6 +1,6 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007 pancake <pancake@youterm.com> + * Copyright (C) 2007-2009 pancake <pancake@youterm.com> * * 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 @@ -17,6 +17,7 @@ */ #include <stdio.h> +#include <string.h> #include "hash.h" usho do_hash(usho *b, int len) @@ -27,11 +28,13 @@ usho do_hash(usho *b, int len) return result; } -usho do_hash_file(const char *filename) +usho do_hash_file(const char *filename, const char *type) { unsigned char buf[BSIZE]; FILE *fd = fopen(filename, "r"); usho hash = 0; + int align = 0; + int size; int ret; if (fd == NULL) { @@ -39,7 +42,8 @@ usho do_hash_file(const char *filename) return -1; } - do { ret = fread(&buf, 1, BSIZE, fd); + do { + ret = fread(&buf, 1, BSIZE, fd); if (ret == -1) { fclose(fd); return 0; @@ -47,8 +51,26 @@ usho do_hash_file(const char *filename) hash ^= do_hash((usho *)&buf, ret); } while(ret); + size = ftell(fd); fclose(fd); + /* mmc and kernel image must be aligned */ + if (type) { + if (strcmp(type, "mmc") == 0) + align = ((size >> 8) + 1) << 8; + else if (strcmp(type, "kernel") == 0) + align = ((size >> 7) + 1) << 7; + } + + if (align) { + printf("align from %d to %d\n", size, align); + buf[0] = 0xff; + while (size < align) { + hash ^= do_hash((usho *)&buf, 1); + ++size; + } + } + return hash; } @@ -5,6 +5,6 @@ #define BSIZE 0x20000 usho do_hash(usho *b, int len); -usho do_hash_file(const char *filename); +usho do_hash_file(const char *filename, const char *type); #endif @@ -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); @@ -15,7 +15,7 @@ struct devices; int queue_mode(); int reverse_extract_pieces(char *dir); -void flash_image(const char *filename, const char *piece, const char *version); +void flash_image(const char *filename, const char *piece, const char *device, const char *hwrevs, const char *version); int fiasco_read_image(char *file); void check_nolo_order(); extern struct usb_dev_handle *dev; @@ -56,21 +56,29 @@ extern int verbose; #define CMD_WRITE 64 #define CMD_QUERY 192 - struct piece_t { char *name; char *type; - char *vers; + char *device; + char *hwrevs; + char *version; +}; + +enum flash_mode { + FLASH_COLD, + FLASH_NORMAL, + FLASH_MKII, + FLASH_DISK, }; struct devices { char *name; unsigned short vendor_id; unsigned short product_id; - unsigned short flags; + enum flash_mode mode; }; -#define SUPPORTED_DEVICES 6 +#define SUPPORTED_DEVICES 10 extern struct devices supported_devices[SUPPORTED_DEVICES]; extern int pcs_n; @@ -84,18 +92,26 @@ enum { PIECE_INITFS, PIECE_ROOTFS, PIECE_OMAPNAND, + PIECE_MMC, + PIECE_CMT_2ND, + PIECE_CMT_ALGO, + PIECE_CMT_MCUSW, PIECE_FIASCO, PIECE_LAST }; struct header_t { int fd; - char fwname[128]; - char name[128]; + char swver[128]; + char type[128]; + char device[16]; + char hwrevs[128]; char version[128]; unsigned short hash; unsigned int size; unsigned char *data; + char *name; + char *layout; }; extern char *pieces[]; @@ -103,12 +119,11 @@ extern char *modes[]; extern char *root_devices[]; // fiasco -int openfiasco(char *name, char *grep, int v); +int openfiasco(const char *name, const char *type, const char *device, const char *hwrev, const char *version, 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); extern int (*fiasco_callback)(struct header_t *header); -int fiasco_add(int fd, const char *name, const char *file, const char *version); +int fiasco_add(int fd, const char *name, const char *file, const char *layout, const char *device, const char *hwrevs, const char *version); int fiasco_pack(int optind, char *argv[]); int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char *dumpfile, int isbl, int ioob); diff --git a/src/pieces.c b/src/pieces.c index 16cacce..5f850d2 100644 --- a/src/pieces.c +++ b/src/pieces.c @@ -52,7 +52,9 @@ int add_piece(char *piece) pcs[pcs_n].name = strdup(file); pcs[pcs_n].type = strdup(piece); - pcs[pcs_n].vers = NULL; // TODO version string not yet supported + pcs[pcs_n].device = NULL; + pcs[pcs_n].hwrevs = NULL; + pcs[pcs_n].version = NULL; // TODO version string not yet supported } else { /*/ autodetect piece type */ pcs[pcs_n].type = (char *)fpid_file(piece); @@ -66,7 +68,9 @@ int add_piece(char *piece) } else { pcs[pcs_n].name = strdup(piece); pcs[pcs_n].type = strdup(pcs[pcs_n].type); - pcs[pcs_n].vers = NULL; + pcs[pcs_n].device = NULL; + pcs[pcs_n].hwrevs = NULL; + pcs[pcs_n].version = NULL; } } diff --git a/src/qmode.c b/src/qmode.c index cf52866..e23e457 100644 --- a/src/qmode.c +++ b/src/qmode.c @@ -54,7 +54,7 @@ void process_message(char *msg) const char *type = fpid_file(arg); if (type == NULL) { squeue_push2(p, "error", "Unknown piece format", 1); - } else flash_image(arg, type, NULL); + } else flash_image(arg, type, NULL, NULL, NULL); } else if (!strcmp(str, "reset")) { if (reboot_board() == 0) { diff --git a/src/query.c b/src/query.c index e8a331c..77a8b33 100644 --- a/src/query.c +++ b/src/query.c @@ -1,6 +1,6 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007,2008 pancake <@youterm.com> + * Copyright (C) 2007-2009 pancake <@youterm.com> * * 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 @@ -46,8 +46,7 @@ int get_status() */ int set_usb_mode(unsigned int mode) { - if (mode > 1) - { + if (mode > 1) { printf("Invalid USB mode specified '%d'.\n", mode); return -1; } @@ -79,7 +78,7 @@ int get_usb_mode() } sprintf(strbuf, "Device's USB mode is '%s'\n", (mode) ? "host" : "client"); - printf(strbuf); + printf("%s", strbuf); return 0; } @@ -178,7 +177,6 @@ int get_root_device() { unsigned char opcode; - strbuf[0] = '\0'; if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 1, (char *)&opcode, 1, 2000) < 0) { fprintf(stderr, "Cannot query root device\n"); return -1; @@ -189,8 +187,7 @@ int get_root_device() return -1; } - sprintf(strbuf, "Root device is: %s\n", root_devices[opcode]); - printf(strbuf); + printf("Root device is: %s\n", root_devices[opcode]); return 0; } @@ -292,13 +289,13 @@ int get_rd_flags() { unsigned short flags = 0; - if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 3, (void *) &flags, sizeof(flags), 2000) == -1) { + if (usb_control_msg (dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 3, (void *) &flags,sizeof(flags), 2000) == -1) { fprintf(stderr, "Cannot get rd flags\n"); sprintf(strbuf, "error: Cannot read rd flags\n"); return -1; } - sprintf(strbuf, + sprintf (strbuf, "Current rd flag setting:\n" "disable OMAP watchdog : %s\n" "disable RETU watchdog : %s\n" @@ -310,7 +307,7 @@ int get_rd_flags() , (flags & 0x08) ? "set" : "not set" , (flags & 0x10) ? "set" : "not set" , (flags & 0x20) ? "set" : "not set"); - printf(strbuf); + puts (strbuf); return 0; } @@ -338,7 +335,6 @@ int get_nolo_version() return 0; } - int get_sw_version() { int ret; @@ -359,8 +355,8 @@ int get_sw_version() if (bytes[0]) { sprintf(strbuf, "Software Version: %s\n", bytes); printf("Software Version: %s\n", bytes); //???+strlen(bytes)+1)); - } else - printf("No software version detected\n"); + } else printf("No software version detected\n"); + return 1; } diff --git a/src/squeue/squeue.c b/src/squeue/squeue.c index 89fc7f5..0ed8815 100644 --- a/src/squeue/squeue.c +++ b/src/squeue/squeue.c @@ -94,7 +94,7 @@ _retry: } pool = shmat(shmid, NULL, 0); - if (((int)pool) == -1) { + if (pool == (void *)-1) { perror("shmat"); return NULL; } diff --git a/src/squeue/squeue.vapi b/src/squeue/squeue.vapi index 0f66713..09b10e5 100644 --- a/src/squeue/squeue.vapi +++ b/src/squeue/squeue.vapi @@ -22,7 +22,7 @@ namespace SQueues { [CCode (cname = "squeue_push2")] public int push2(string cmd, string msg, int l); [CCode (cname = "squeue_get")] - public weak string get(int l); + public unowned string get(int l); [CCode (cname = "squeue_pop")] public int pop(); [CCode (cname = "squeue_stats")] |