Fixed creating fiasco images, added param version: for specifing sw-ver. Now generated fiasco images are valid for nokia flasher.
This commit is contained in:
1 parent
4f92794cdf
commit
9195f3c7da
2 files changed
+112
-54
No files matched your search
+107
-50
@@ -302,37 +302,56 @@ void fiasco_data_read(struct header_t *header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* fiasco writer */
|
/* fiasco writer */
|
||||||
int fiasco_new(const char *filename, const char *name)
|
int fiasco_new(const char *filename, const char *swver)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
//int len = htonl(strlen(name)+1+6+14);
|
unsigned int len;
|
||||||
|
uint8_t len8;
|
||||||
|
const char *str = "OSSO UART+USB";
|
||||||
|
|
||||||
fd = open(filename, O_RDWR|O_CREAT, 0644);
|
if (swver && strlen(swver)+1 > UINT8_MAX) {
|
||||||
|
printf("SW version is too long\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -1;
|
return -1;
|
||||||
#if 1
|
|
||||||
if (write(fd, "\xb4\x00\x00\x00\x14\x00\x00\x00\x01\xe8\x0e", 11) != 11) {
|
printf("Writing header\n");
|
||||||
fprintf (stderr, "Cannot write 11 bytes to target file\n");
|
|
||||||
close (fd);
|
write(fd, "\xb4", 1); //signature
|
||||||
return -1;
|
|
||||||
}
|
len = 4;
|
||||||
if (write(fd, "OSSO UART+USB", 14) != 14) {
|
len += strlen(str) + 3;
|
||||||
fprintf (stderr, "Cannot write 14 bytes to target file\n");
|
if (swver)
|
||||||
close (fd);
|
len += strlen(swver) + 3;
|
||||||
return -1;
|
len = htonl(len);
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* 2nd format doesnt works. atm stay with old one */
|
|
||||||
write(fd, "\xb4", 1);
|
|
||||||
write(fd, &len, 4);
|
write(fd, &len, 4);
|
||||||
/* version header */
|
|
||||||
write(fd, "\x00\x00\x00\x02\xe8\x0e", 6);
|
if (swver)
|
||||||
/* firmware type */
|
len = htonl(2);
|
||||||
write(fd, "OSSO UART+USB", 14);
|
else
|
||||||
/* firmware name */
|
len = htonl(1);
|
||||||
write(fd, name, strlen(name));
|
write(fd, &len, 4);
|
||||||
write(fd, "", 1);
|
|
||||||
#endif
|
// 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;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,6 +369,7 @@ int fiasco_add_eof(int fd)
|
|||||||
|
|
||||||
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_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 gd,ret;
|
||||||
int size;
|
int size;
|
||||||
unsigned int sz;
|
unsigned int sz;
|
||||||
@@ -370,16 +390,23 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
sz = lseek(gd, 0, SEEK_END);
|
sz = lseek(gd, 0, SEEK_END);
|
||||||
if (name && strcmp(name, "mmc") == 0) // align mmc
|
if (name && strcmp(name, "mmc") == 0) // align mmc
|
||||||
sz = ((sz >> 8) + 1) << 8;
|
sz = ((sz >> 8) + 1) << 8;
|
||||||
|
|
||||||
|
printf(" size: %d\n", sz);
|
||||||
sz = htonl((unsigned int) sz);
|
sz = htonl((unsigned int) sz);
|
||||||
|
|
||||||
lseek(gd, 0, SEEK_SET);
|
lseek(gd, 0, SEEK_SET);
|
||||||
|
|
||||||
write(fd, "T", 1);
|
write(fd, "T", 1);
|
||||||
|
|
||||||
// FIXME: What is this char? If incorrect nokia flasher refuse fiasco image
|
/* number of subsections */
|
||||||
// \x03 - mmc?
|
len = 1;
|
||||||
// \x04 - normal?
|
if (version)
|
||||||
write(fd, "\x04", 1);
|
++len;
|
||||||
|
if (device)
|
||||||
|
++len;
|
||||||
|
if (layout)
|
||||||
|
++len;
|
||||||
|
write(fd, &len, 1);
|
||||||
|
|
||||||
write(fd, "\x2e\x19\x01\x01\x00", 5);
|
write(fd, "\x2e\x19\x01\x01\x00", 5);
|
||||||
|
|
||||||
@@ -387,8 +414,9 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
hash = do_hash_file(file, name);
|
hash = do_hash_file(file, name);
|
||||||
ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1];
|
ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1];
|
||||||
write(fd, &hash, 2);
|
write(fd, &hash, 2);
|
||||||
printf("hash: %04x\n", hash);
|
printf(" hash: %04x\n", hash);
|
||||||
|
|
||||||
|
/* image type name */
|
||||||
memset(bname, '\0', 13);
|
memset(bname, '\0', 13);
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
name = fpid_file(file);
|
name = fpid_file(file);
|
||||||
@@ -400,47 +428,57 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
write(fd, bname, 12);
|
write(fd, bname, 12);
|
||||||
write(fd, &sz, 4);
|
write(fd, &sz, 4);
|
||||||
write(fd, "\x00\x00\x00\x00", 4);
|
write(fd, "\x00\x00\x00\x00", 4);
|
||||||
|
|
||||||
|
/* append version subsection */
|
||||||
if (version) {
|
if (version) {
|
||||||
/* append version */
|
|
||||||
write(fd, "1", 1); /* 1 - version */
|
write(fd, "1", 1); /* 1 - version */
|
||||||
len = strlen(version)+1;
|
len = strlen(version)+1;
|
||||||
write(fd, &len, 1);
|
write(fd, &len, 1);
|
||||||
write(fd, version, len);
|
write(fd, version, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* append device & hwrevs subsection */
|
||||||
if (device) {
|
if (device) {
|
||||||
/* append device & hwrevs */
|
|
||||||
const char *ptr = hwrevs;
|
const char *ptr = hwrevs;
|
||||||
const char *oldptr = hwrevs;
|
const char *oldptr = hwrevs;
|
||||||
int i;
|
|
||||||
write(fd, "2", 1); /* 2 - device & hwrevs */
|
write(fd, "2", 1); /* 2 - device & hwrevs */
|
||||||
len = 16;
|
len = 16;
|
||||||
if (hwrevs) {
|
if (hwrevs) {
|
||||||
i = 1;
|
i = 1;
|
||||||
while ((ptr = strchr(ptr, ','))) { i++; ptr++; }
|
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;
|
len += i*8;
|
||||||
}
|
}
|
||||||
write(fd, &len, 1);
|
write(fd, &len, 1);
|
||||||
len = strlen(device);
|
len = strlen(device);
|
||||||
if (len > 15) len = 15;
|
if (len > 15) len = 15;
|
||||||
write(fd, device, len);
|
write(fd, device, len);
|
||||||
lseek(fd, 16-len, SEEK_CUR);
|
for (i=0; i<16-len; ++i)
|
||||||
|
write(fd, "\x00", 1);
|
||||||
ptr = hwrevs;
|
ptr = hwrevs;
|
||||||
oldptr = hwrevs;
|
oldptr = hwrevs;
|
||||||
while ((ptr = strchr(ptr, ','))) {
|
while ((ptr = strchr(ptr, ','))) {
|
||||||
len = ptr-oldptr;
|
len = ptr-oldptr;
|
||||||
if (len > 8) len = 8;
|
if (len > 8) len = 8;
|
||||||
write(fd, oldptr, len);
|
write(fd, oldptr, len);
|
||||||
lseek(fd, 8-len, SEEK_CUR);
|
for (i=0; i<8-len; ++i)
|
||||||
|
write(fd, "\x00", 1);
|
||||||
++ptr;
|
++ptr;
|
||||||
oldptr = ptr;
|
oldptr = ptr;
|
||||||
}
|
}
|
||||||
len = strlen(oldptr);
|
len = strlen(oldptr);
|
||||||
if (len > 8) len = 8;
|
if (len > 8) len = 8;
|
||||||
write(fd, oldptr, len);
|
write(fd, oldptr, len);
|
||||||
lseek(fd, 8-len, SEEK_CUR);
|
for (i=0; i<8-len; ++i)
|
||||||
|
write(fd, "\x00", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* append layout subsection */
|
||||||
if (layout) {
|
if (layout) {
|
||||||
/* append layout */
|
|
||||||
int lfd = open(layout, O_RDONLY);
|
int lfd = open(layout, O_RDONLY);
|
||||||
if (lfd >= 0) {
|
if (lfd >= 0) {
|
||||||
len = read(lfd, buf, sizeof(buf));
|
len = read(lfd, buf, sizeof(buf));
|
||||||
@@ -450,15 +488,14 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
write(fd, buf, len);
|
write(fd, buf, len);
|
||||||
}
|
}
|
||||||
close(lfd);
|
close(lfd);
|
||||||
|
} else {
|
||||||
|
printf("Cannot open layout file %s\n", layout);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write(fd, "4", 1); /* 4 - piece size */
|
|
||||||
len = 16;
|
|
||||||
write(fd, &len, 1);
|
|
||||||
lseek(fd, len-4, SEEK_CUR);
|
|
||||||
write(fd, &sz, 4);
|
|
||||||
|
|
||||||
write(fd, "\x00", 1); /* FIXME: last char is unknown, maybe nokia flasher ignore it? */
|
/* dummy byte - end of all subsections */
|
||||||
|
write(fd, "\x00", 1);
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
@@ -472,7 +509,7 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* align mmc (add \xff) */
|
/* align mmc (fill with 0xff) */
|
||||||
if (name && strcmp(name, "mmc") == 0) {
|
if (name && strcmp(name, "mmc") == 0) {
|
||||||
int align = ((size >> 8) + 1) << 8;
|
int align = ((size >> 8) + 1) << 8;
|
||||||
while (size < align) {
|
while (size < align) {
|
||||||
@@ -487,7 +524,7 @@ int fiasco_add(int fd, const char *name, const char *file, const char *layout, c
|
|||||||
int fiasco_pack(int optind, char *argv[])
|
int fiasco_pack(int optind, char *argv[])
|
||||||
{
|
{
|
||||||
char *file = argv[optind];
|
char *file = argv[optind];
|
||||||
int fd, ret;
|
int fd, ret, i;
|
||||||
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *arg;
|
char *arg;
|
||||||
@@ -497,15 +534,28 @@ int fiasco_pack(int optind, char *argv[])
|
|||||||
char *version;
|
char *version;
|
||||||
char *layout;
|
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)
|
if (fd == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("Package: %s\n", file);
|
|
||||||
while((arg=argv[++optind])) {
|
while((arg=argv[++optind])) {
|
||||||
// [[[[dev:hw:]ver:]type:]file[%%layout]
|
|
||||||
ptr = strdup(arg);
|
|
||||||
|
|
||||||
|
if (strncmp(arg, "version:", strlen("version:"))==0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// format: [[[[dev:hw:]ver:]type:]file[%layout]
|
||||||
|
ptr = strdup(arg);
|
||||||
layout = strchr(ptr, '%');
|
layout = strchr(ptr, '%');
|
||||||
if (layout) {
|
if (layout) {
|
||||||
*(layout++) = 0;
|
*(layout++) = 0;
|
||||||
@@ -543,8 +593,15 @@ int fiasco_pack(int optind, char *argv[])
|
|||||||
if (!type)
|
if (!type)
|
||||||
type = (char *)fpid_file(file);
|
type = (char *)fpid_file(file);
|
||||||
|
|
||||||
printf("Adding %s (%s:%s %s): %s..\n", type, device, hwrevs, version, 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);
|
ret = fiasco_add(fd, type, file, layout, device, hwrevs, version);
|
||||||
|
free(ptr);
|
||||||
if (ret<0) {
|
if (ret<0) {
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
+5
-4
@@ -106,7 +106,7 @@ void show_usage()
|
|||||||
|
|
||||||
printf ("Fiasco options:\n"
|
printf ("Fiasco options:\n"
|
||||||
" -u [dir] unpack fiasco image to directory\n"
|
" -u [dir] unpack fiasco image to directory\n"
|
||||||
" -g generate fiasco image\n"
|
" -g [ver] generate fiasco image for SW version\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -120,7 +120,6 @@ void show_usage()
|
|||||||
" file is image file name\n"
|
" file is image file name\n"
|
||||||
" layout is file name for layout file\n"
|
" layout is file name for layout file\n"
|
||||||
" -F [file] specify Fiasco image\n"
|
" -F [file] specify Fiasco image\n"
|
||||||
" (see '-p help' for supported types)\n"
|
|
||||||
" -t [type] specify image type\n"
|
" -t [type] specify image type\n"
|
||||||
" -s [ver] specify image with version\n"
|
" -s [ver] specify image with version\n"
|
||||||
" -d [dev] specify image for device\n"
|
" -d [dev] specify image for device\n"
|
||||||
@@ -140,7 +139,7 @@ void show_usage()
|
|||||||
);
|
);
|
||||||
|
|
||||||
#if HAVE_SQUEUE
|
#if HAVE_SQUEUE
|
||||||
printf( " -Q enter shared queues server mode (for gui or remote)\n");
|
printf( " -Q enter shared queues server mode (for gui or remote)\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf( "R&D flags:\n"
|
printf( "R&D flags:\n"
|
||||||
@@ -195,6 +194,7 @@ void show_usage()
|
|||||||
" -H [file] calculate hash for file\n"
|
" -H [file] calculate hash for file\n"
|
||||||
" -I [piece] identify a firmware piece\n"
|
" -I [piece] identify a firmware piece\n"
|
||||||
" -P [new-fiasco] creates a new fiasco package, pieces as arguments\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"
|
" -u [fiasco] unpack target fiasco image\n"
|
||||||
" -v be verbose and noisy\n"
|
" -v be verbose and noisy\n"
|
||||||
" -V show 0xFFFF version information\n"
|
" -V show 0xFFFF version information\n"
|
||||||
@@ -229,7 +229,8 @@ int unpack_callback(struct header_t *header)
|
|||||||
printf("Cannot open file.\n");
|
printf("Cannot open file.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fwrite(header->data, header->size, 1, fd);
|
if (fwrite(header->data, header->size, 1, fd) != 1)
|
||||||
|
printf("Writing failed\n");
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user