* Added -n flag to do not write to disk or flash (simulation)

* Added -S flag to specify subversion id manually while flashing or dumping
* Fixed support for the last fiasco image
  - Skip paddings
  - More verbose output while parsing FIASCO headers
* Initial implementation of the full direct FIASCO flasher
  - No need to dump manually before flashing
* Some warnings and code cleanup
* Fix building issue
* Add HAVE_GUI directive in config.mk
* Up to version 0.4
This commit is contained in:
pancake committed 2008-12-08 00:21:05 +01:00
1 parent edac98d26e
commit 3d427bfd77
11 files changed
+133 -40

No files matched your search

+3 -1
View File
@@ -1,8 +1,10 @@
VERSION=0.3.9
VERSION=0.4.0
PREFIX=/usr
# NetBSD stuff
CFLAGS+=-I/usr/pkg/include
LDFLAGS+=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib
HAVE_USB=1
HAVE_GUI=0
+4 -1
View File
@@ -1,7 +1,10 @@
OBJ=logotool.o compress.o uncompress.o rgb2yuv.o
CFLAGS=-Wall -g
BIN=logotool
all: ${OBJ}
all: ${BIN}
${BIN}: ${OBJ}
${CC} ${OBJ} -o logotool
clean:
+3 -1
View File
@@ -10,7 +10,9 @@ CFLAGS+=-pedantic -std=c99 -DHAVE_USB=${HAVE_USB}
USBOBJ=../libusb/error.o ../libusb/usb.o ../libusb/descriptors.o
USBOBJ+=../libusb/linux.o ## XXX not portable
all: ${OBJ}
all: ${BIN}
${BIN}: ${OBJ}
${CC} ${LDFLAGS} -o ${BIN} ${OBJ} ${LIBS}
allusb: ${OBJ}
+32 -9
View File
@@ -27,16 +27,17 @@
#include "main.h"
#include "hash.h"
void (*fiasco_callback)(struct header_t *header) = NULL;
int (*fiasco_callback)(struct header_t *header) = NULL;
int openfiasco(char *name)
{
struct header_t header;
unsigned char buf[128];
unsigned char data[128];
unsigned char *pdata;
unsigned int namelen;
off_t off;
int i;
off_t off, here;
int i,j;
header.fd = open(name, O_RDONLY);
if (header.fd == -1) {
@@ -66,14 +67,22 @@ int openfiasco(char *name)
/* 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'
printf("unexpected header at 0x%x, found %02x %02x %02x\n",
((int)lseek(header.fd, 0, SEEK_CUR))-9,
buf[0], buf[1], buf[2]);
break;
/* 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);
}
}
printf("Skipping %d padding bytes\n", i);
lseek(header.fd, -1, SEEK_CUR);
continue;
}
header.hash = buf[7]<<8|buf[8];
@@ -92,6 +101,7 @@ int openfiasco(char *name)
break;
memcpy(&header.size, buf,4);
header.size = ntohl(header.size);
printf(" offset: 0x%08x\n", (unsigned int)here);
printf(" size: %d bytes\n", header.size);
printf(" hash: %04x\n", header.hash);
//printf("BYTE: %02x %02x %02x %02x %02x\n",
@@ -104,18 +114,31 @@ int openfiasco(char *name)
i = data[0];
if (read(header.fd, data, i)<i)
break;
if (data[0])
if (data[0]) {
printf(" version-length: %d\n", i);
printf(" version: %s\n", data);
pdata = data;
while(pdata<data+i) {
strcat(header.name,pdata==data?"-":",");
strcat(header.name, (char*)pdata);
printf(" sub-version: %s\n", pdata);
pdata=pdata+strlen((char*)pdata)+1;
for(;*pdata=='\0'&&pdata<data+i;pdata=pdata+1);
}
}
strcpy(header.version, (char *)data);
if (read(header.fd, buf+8, 1)<1)
break;
}
printf(" name: %s\n", header.name);
/* callback */
off = lseek(header.fd, 0, SEEK_CUR);
printf(" body-at: 0x%08x\n", (unsigned int)off);
if (fiasco_callback != NULL) {
fiasco_callback(&header);
free(header.data);
continue;
} else {
}
// XXX dup
lseek(header.fd, off, SEEK_SET);
+1 -1
View File
@@ -74,7 +74,7 @@ void check_nolo_order()
check_nolo_order_failed();
}
void flash_image(char *filename, char *piece, char *version)
void flash_image(const char *filename, const char *piece, const char *version)
{
FILE *fd;
int vlen = 0;
+7
View File
@@ -1,6 +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
test:
valac --save-temps --Xcc=-I.. squeue.vapi test.vala ../squeue.c -o v
valac --save-temps --Xcc=-I.. squeue.vapi client.vala ../squeue.c -o c
else
all:
@true
endif
+58 -12
View File
@@ -32,6 +32,7 @@ struct usb_dev_handle *dev = NULL;
char *fiasco_image = NULL;
char *boot_cmdline = NULL;
char *reverseto = NULL;
char *subverstr = NULL;
int rd_mode = -1;
int rd_flags = -1;
int usb_mode = -1;
@@ -42,6 +43,7 @@ int moboreboot = 0;
int unpack = 0;
int qmode = 0;
int info = 0;
int nomode = 0;
char *modes[]={
"host",
@@ -86,6 +88,8 @@ void show_usage()
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");
@@ -105,16 +109,50 @@ void show_usage()
}
void unpack_callback(struct header_t *header)
int unpack_callback(struct header_t *header)
{
FILE *fd = fopen(header->name, "wb");
FILE *fd;
fiasco_data_read(header);
if (subverstr) {
if (strchr(header->name, ',') != NULL) {
if (!strstr(header->name, subverstr)) {
printf("Skipping '%s' does not matches -S subversion\n",
header->name);
return 1;
}
}
}
if (nomode)
return 1;
fd = fopen(header->name, "wb");
if (fd == NULL) {
printf("Cannot open file.\n");
return;
return 1;
}
fiasco_data_read(header);
fwrite(header->data, header->size, 1, fd);
fclose(fd);
return 0;
}
int flash_callback(struct header_t *header)
{
int ret;
char *type;
ret = unpack_callback(header);
if (ret) {
printf("ignored\n");
return 1;
}
type = (char *)fpid_file(header->name);
printf("Flashing %s (%s)\n", header->name, type);
flash_image(header->name, type, NULL);
return 0;
}
void unpack_fiasco_image(char *file)
@@ -126,21 +164,23 @@ void unpack_fiasco_image(char *file)
int fiasco_flash(char *file)
{
/* TODO */
fiasco_callback = NULL;
check_nolo_order();
get_sw_version();
get_nolo_version();
fiasco_callback = &flash_callback;
openfiasco( file );
printf("\nTODO: Implement the fiasco flashing here.\n");
return -1;
return 0;
}
#if HAVE_USB
int connect_via_usb()
{
static char pbc[]={'/','-','\\', '|'};
struct usb_device_descriptor udd;
struct devices it_device;
int c = 0;
static char pbc[]={'/','-','\\', '|'};
// usb_set_debug(5);
usb_init();
@@ -214,7 +254,7 @@ int main(int argc, char **argv)
{
int c;
while((c = getopt(argc, argv, "QC:cp:PvVhRu:ib:U:r:e:ld:I:D:f:F:s:xH:")) != -1) {
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));
@@ -227,6 +267,12 @@ int main(int argc, char **argv)
case 'b':
boot_cmdline = optarg;
break;
case 'S':
subverstr = optarg;
break;
case 'n':
nomode = 1;
break;
case 'U':
usb_mode = atoi(optarg);
break;
@@ -321,8 +367,8 @@ int main(int argc, char **argv)
{
printf("# The Free Fiasco Firmware Flasher v"VERSION"\n"
"0xFFFF [-chilQRvVx] [-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]\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;
}
+8 -4
View File
@@ -5,7 +5,6 @@
#include "hash.h"
#include "nolo.h"
#include "os.h"
extern char strbuf[1024];
#define _FILE_OFFSET_BITS 64
@@ -16,11 +15,11 @@ struct devices;
int queue_mode();
int reverse_extract_pieces(char *dir);
void flash_image(char *filename, char *piece, char *version);
void flash_image(const char *filename, const char *piece, const char *version);
int fiasco_read_image(char *file);
void check_nolo_order();
extern struct usb_dev_handle *dev;
unsigned long get_file_size(char *file);
unsigned long get_file_size(const char *file);
void progressbar(unsigned long long part, unsigned long long total);
const char *fpid_file(const char *filename);
int add_piece(char *piece);
@@ -107,10 +106,15 @@ int openfiasco(char *name);
int fiasco_new(const char *filename, const char *name);
void fiasco_data_read(struct header_t *header);
int fiasco_add_eof(int fd);
extern void (*fiasco_callback)(struct header_t *header);
extern int (*fiasco_callback)(struct header_t *header);
int fiasco_add(int fd, const char *name, const char *file, const char *version);
int fiasco_pack(int optind, char *argv[]);
int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char *dumpfile, int isbl, int ioob);
//
int reboot_board();
int get_rd_flags();
int get_usb_mode();
int get_nolo_version();
#endif
+11 -9
View File
@@ -19,7 +19,13 @@
#include "main.h"
#include "os.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#if HAVE_SQUEUE
struct squeue_t *q;
@@ -43,23 +49,19 @@ void process_message(char *msg)
printf("[x] (%s)\n", msg);
str = strdup(msg);
arg = strchr(str, ':');
if (c!=NULL) {
if (c!=0) {
arg[0]='\0';
arg = arg +1;
if (!strcmp(str, "flash")) {
char buf[1024];
char *type = fpid_file(arg);
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);
} else
if (!strcmp(str, "reset")) {
if (reboot_board() == 0) {
squeue_push2(p,"info", "Device reboots", 1);
} else
squeue_push2(p,"error", "Cannot reboot device", 1);
} else squeue_push2(p,"error", "Cannot reboot device", 1);
} else
if (!strcmp(str, "info")) {
get_rd_flags();
@@ -95,7 +97,7 @@ int queue_mode()
pid = dofork();
if (pid) {
wait(pid);
wait(&pid);
return 0;
} else {
p = squeue_open("/tmp/0xFFFF.1", Q_CREAT);
+4
View File
@@ -1,13 +1,17 @@
#include "squeue.h"
#define _XOPEN_SOURCE 500 /* Or: #define _BSD_SOURCE */
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <signal.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define POOL_SIZE ITEM_MAX*ITEM_SIZE
+2 -2
View File
@@ -22,7 +22,7 @@
#include <stdarg.h>
#include <stdlib.h>
unsigned long get_file_size(char *file)
unsigned long get_file_size(const char *file)
{
FILE *fd = fopen(file, "r");
unsigned long len = 0;
@@ -53,7 +53,7 @@ void progressbar(unsigned long long part, unsigned long long total)
squeue_push2(p, "bar", msg, 0);
} else {
#endif
printf("\e[K %3d%% [", pc);
printf("\x1b[K %3d%% [", pc);
if (columns)
cols = atoi(columns);
cols-=15;