diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2021-05-02 17:04:27 +0200 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2021-05-02 17:04:27 +0200 |
commit | 1f466936cb4087869e8b1353ebccfd40ca88596f (patch) | |
tree | b066717c2debc553a53159b67ec437f70a3d0552 | |
parent | df8e50a8243ad7003988efca3e4840d15030977c (diff) | |
download | 0xFFFF-1f466936cb4087869e8b1353ebccfd40ca88596f.tar.bz2 |
fiasco: When generating fiasco image append image data part sections
Nokia's fiasco-gen writes data part section even if there is only one part.
So do the same thing in 0xFFFF.
-rw-r--r-- | src/fiasco.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/fiasco.c b/src/fiasco.c index a0caf1a..1c977c5 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -349,6 +349,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) { const char * str; const char * type; struct image_list * image_list; + struct image_part * image_part; struct image * image; unsigned char buf[4096]; @@ -449,7 +450,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) { checksum = 0x00; /* number of subsections */ - length8 = device_count+1; + length8 = device_count+2; if ( image->version ) ++length8; if ( image->layout ) @@ -515,6 +516,39 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) { CHECKSUM(checksum, image->layout, length8); } + if ( image->parts ) { + /* for each image part append subsection */ + for ( image_part = image->parts; image_part; image_part = image_part->next ) { + WRITE_OR_FAIL(file, fd, "4", 1); /* 4 - image data part */ + CHECKSUM(checksum, "4", 1); + length = 16 + (image_part->name ? strlen(image_part->name) : 0); + length8 = length <= UINT8_MAX ? length : UINT8_MAX; + WRITE_OR_FAIL(file, fd, &length8, 1); + CHECKSUM(checksum, &length8, 1); + WRITE_OR_FAIL(file, fd, "\x00\x00\x00\x00", 4); /* unknown */ + CHECKSUM(checksum, "\x00\x00\x00\x00", 4); + size = htonl(image_part->offset); + WRITE_OR_FAIL(file, fd, &size, 4); + CHECKSUM(checksum, &size, 4); + WRITE_OR_FAIL(file, fd, "\x00\x00\x00\x00", 4); /* unknown */ + CHECKSUM(checksum, "\x00\x00\x00\x00", 4); + size = htonl(image_part->size); + WRITE_OR_FAIL(file, fd, &size, 4); + CHECKSUM(checksum, &size, 4); + if ( image_part->name ) { + WRITE_OR_FAIL(file, fd, image_part->name, length-16); + CHECKSUM(checksum, image_part->name, length-16); + } + } + } else { + /* append one image data part subsection */; + WRITE_OR_FAIL(file, fd, "4\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14); + CHECKSUM(checksum, "4\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14); + size = htonl(image->size); + WRITE_OR_FAIL(file, fd, &size, 4); + CHECKSUM(checksum, &size, 4); + } + /* checksum of header */ checksum = 0xFF - checksum; WRITE_OR_FAIL(file, fd, &checksum, 1); |