summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-07 20:41:43 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-07 20:41:43 +0200
commitef4a506905c11708c0183f46178b9fc40e8850db (patch)
tree37e6ef5f167f7d4490d506b3b6cc3a2587a490fd /src
parent1a7d30cebf76ff9ed057d05c03afabbaf36ebff6 (diff)
download0xFFFF-ef4a506905c11708c0183f46178b9fc40e8850db.tar.bz2
fiasco: fix creating fiasco image
Diffstat (limited to 'src')
-rw-r--r--src/fiasco2.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/fiasco2.c b/src/fiasco2.c
index 8888176..b155ec4 100644
--- a/src/fiasco2.c
+++ b/src/fiasco2.c
@@ -250,6 +250,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
int fd = -1;
uint32_t size;
uint32_t length;
+ uint16_t hash;
uint8_t length8;
const char * str;
const char * type;
@@ -282,18 +283,18 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
printf("Writing FW header\n");
- if ( fiasco->name )
+ if ( fiasco->name[0] )
str = fiasco->name;
else
str = "OSSO UART+USB";
length = 4 + strlen(str) + 3;
- if ( fiasco->swver )
+ if ( fiasco->swver[0] )
length += strlen(fiasco->swver) + 3;
length = htonl(length);
WRITE_OR_FAIL(fd, &length, 4); /* FW header length */
- if ( fiasco->swver )
+ if ( fiasco->swver[0] )
length = htonl(2);
else
length = htonl(1);
@@ -306,7 +307,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
WRITE_OR_FAIL(fd, str, length8);
/* SW version */
- if ( fiasco->swver ) {
+ if ( fiasco->swver[0] ) {
printf("Writing SW version: %s\n", fiasco->swver);
length8 = strlen(fiasco->swver)+1;
WRITE_OR_FAIL(fd, "\x31", 1);
@@ -371,10 +372,13 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
WRITE_OR_FAIL(fd, "\x2e\x19\x01\x01\x00", 5);
/* checksum */
- WRITE_OR_FAIL(fd, &image->hash, 2);
+ hash = htons(image->hash);
+ WRITE_OR_FAIL(fd, &hash, 2);
/* image type name */
- WRITE_OR_FAIL(fd, type, 12);
+ memset(buf, 0, 12);
+ strncpy((char *)buf, type, 12);
+ WRITE_OR_FAIL(fd, buf, 12);
/* image size */
size = htonl(image->size);
@@ -387,8 +391,8 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
if ( image->version ) {
WRITE_OR_FAIL(fd, "1", 1); /* 1 - version */
length8 = strlen(image->version)+1;
- WRITE_OR_FAIL(fd, &length, 1);
- WRITE_OR_FAIL(fd, image->version, length);
+ WRITE_OR_FAIL(fd, &length8, 1);
+ WRITE_OR_FAIL(fd, image->version, length8);
}
/* append device & hwrevs subsection */