summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/fiasco30
-rw-r--r--src/fiasco.c67
-rw-r--r--src/fpid.c6
-rw-r--r--src/main.c1
-rw-r--r--src/main.h3
5 files changed, 61 insertions, 46 deletions
diff --git a/doc/fiasco b/doc/fiasco
new file mode 100644
index 0000000..ef8cf00
--- /dev/null
+++ b/doc/fiasco
@@ -0,0 +1,30 @@
+SPECS FOR TEH FIASCO FIRMWARE FILE FORMAT ffff!
+-----------------------------------------------
+
+ These notes has not been taken properly and may be wrong. It must
+ be revised to fit the reality. But this is mostly a general idea:
+
+
+FILE HEADER
+
+ 1 byte = 0xb4 -- signature
+ 4 bytes -- firmware name length (big endian)
+ 6 bytes -- versioning info ( byte 4 is format version )
+ N-6 bytes -- firmware name (zero fill)
+
+
+PIECE HEADER
+
+ 1 byte = 0x54 -- piece signature
+ 6 bytes -- unknown
+ 2 bytes -- checksum for the piece contents (xorpair)
+ 12 bytes -- piece name (first byte is FF if is the last)
+ 4 bytes -- piece size (big endian)
+ 4 bytes -- unknown
+ block {
+ 1 byte -- if (value '1'-'9') { ..there's a comment.. }
+ 1 byte -- length of comment
+ N bytes -- comment
+ }
+ N bytes -- piece data
+
diff --git a/src/fiasco.c b/src/fiasco.c
index 4bbb114..f993a11 100644
--- a/src/fiasco.c
+++ b/src/fiasco.c
@@ -25,37 +25,7 @@
#include <sys/stat.h>
#include <arpa/inet.h>
#include "main.h"
-
-#if 0
-
-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)
-
-
-PIECE HEADER
-
- 1 byte = 0x54 -- piece signature
- 6 bytes -- unknown
- 2 bytes -- checksum for the piece contents (xorpair)
- 12 bytes -- piece name (first byte is FF if is the last)
- 4 bytes -- piece size (big endian)
- 4 bytes -- unknown
- block {
- 1 byte -- if (value '1'-'9') { ..there's a comment.. }
- 1 byte -- length of comment
- N bytes -- comment
- }
- N bytes -- piece data
-
-
-#endif
+#include "hash.h"
void (*fiasco_callback)(struct header_t *header) = NULL;
@@ -168,26 +138,38 @@ void fiasco_data_read(struct header_t *header)
int fiasco_new(const char *filename, const char *name)
{
int fd;
- int len = htonl(strlen(name)+1+6);
+ //int len = htonl(strlen(name)+1+6+14);
+
fd = open(filename, O_RDWR|O_CREAT, 0644);
if (fd == -1)
return -1;
+#if 1
+ write(fd, "\xb4\x00\x00\x00\x14\x00\x00\x00\x01\xe8\x0e", 11);
+ write(fd, "OSSO UART+USB", 14);
+#else
+ /* 2nd format doesnt works. atm stay with old one */
write(fd, "\xb4", 1);
write(fd, &len, 4);
/* version header */
write(fd, "\x00\x00\x00\x02\xe8\x0e", 6);
+ /* firmware type */
+ write(fd, "OSSO UART+USB", 14);
/* firmware name */
- write(fd, name, strlen(name)+1);
+ write(fd, name, strlen(name));
+ write(fd, "", 1);
+#endif
return fd;
}
int fiasco_add_eof(int fd)
{
+#if 0
unsigned char buf[120];
if (fd == -1)
return -1;
memset(buf,'\xff', 120);
write(fd, buf, 120);
+#endif
return 0;
}
@@ -198,7 +180,7 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version)
unsigned int sz;
unsigned char len;
unsigned short hash;
- unsigned char *ptr = &hash;
+ unsigned char *ptr = (unsigned char *)&hash;
char buf[4096];
char bname[32];
@@ -213,7 +195,8 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version)
sz = htonl((unsigned int) lseek(gd, 0, SEEK_END));
lseek(gd, 0, SEEK_SET);
// 4 bytes big endian
- write(fd, "T\x02\x2e\x19\x01\x01\x00", 7); // header?
+ //write(fd, "T\x02\x2e\x19\x01\x01\x00", 7); // header?
+ write(fd, "T\x01\x2e\x19\x01\x01\x00", 7); // header (old piece format)
/* checksum */
hash = do_hash_file(file);
ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1];
@@ -222,15 +205,17 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version)
memset(bname, '\0', 13);
if (name == NULL)
- strncpy(bname, file, 12);
- else
- strncpy(bname, name, 12);
+ name = fpid_file(file);
+ /* failback */
+ if (name == NULL)
+ name = file;
+
+ strncpy(bname, name, 12);
write(fd, bname, 12);
write(fd, &sz, 4);
if (version) {
/* append metadata */
- //write(fd, version,
write(fd, "\x00\x00\x00\x00\x31", 5);
len = strlen(version);
write(fd, &len, 1);
@@ -252,7 +237,7 @@ int fiasco_add(int fd, const char *name, const char *file, const char *version)
int fiasco_pack(int optind, char *argv[])
{
- char *file = argv[optind];
+ const char *file = argv[optind];
char *type;
int fd, ret;
@@ -262,7 +247,7 @@ int fiasco_pack(int optind, char *argv[])
printf("Package: %s\n", file);
while((file=argv[++optind])) {
- type = fpid_file(file);
+ type = (char *)fpid_file(file);
printf("Adding %s: %s..\n", type, file);
ret = fiasco_add(fd, type, file, NULL);
if (ret<0) {
diff --git a/src/fpid.c b/src/fpid.c
index cdf3239..9220570 100644
--- a/src/fpid.c
+++ b/src/fpid.c
@@ -20,7 +20,7 @@
#include <stdio.h>
#include <string.h>
-char *fpid_file(char *filename)
+const char *fpid_file(const char *filename)
{
FILE *fd;
char buf[512];
@@ -45,11 +45,9 @@ char *fpid_file(char *filename)
size = ftell(fd);
fclose(fd);
-#if 0
if (!memcmp(b+0x34, "2NDAPE", 6))
- return PIECE_2ND;
+ return pieces[PIECE_2ND];
else
-#endif
if (!memcmp(b+0x04, "NOLOScnd", 8))
return pieces[PIECE_SECONDARY];
else
diff --git a/src/main.c b/src/main.c
index 6ac127e..a029e40 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,6 +42,7 @@ int info = 0;
/* global structs */
char *pieces[] = {
"xloader", // xloader.bin
+ "2nd", // 2nd
"secondary", // secondary.bin
"kernel", // zImage
"initfs", // jffs'd initfs
diff --git a/src/main.h b/src/main.h
index c9535f3..7da0e31 100644
--- a/src/main.h
+++ b/src/main.h
@@ -15,7 +15,7 @@ void check_nolo_order();
extern struct usb_dev_handle *dev;
unsigned long get_file_size(char *file);
void progressbar(unsigned long long part, unsigned long long total);
-char *fpid_file(char *filename);
+const char *fpid_file(const char *filename);
int add_piece(char *piece);
#include <usb.h>
@@ -65,6 +65,7 @@ extern struct piece_t pcs[10];
enum {
PIECE_XLOADER = 0,
+ PIECE_2ND,
PIECE_SECONDARY,
PIECE_KERNEL,
PIECE_INITFS,