From 8bc521f3e5e83fddc08a031aa7cf7499514ee732 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Sat, 23 Jun 2012 13:07:34 +0200 Subject: do_hash_file - align size for mmc images, append chars \xff (nokia flasher needs mmc images alingned) --- src/hash.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/hash.c') diff --git a/src/hash.c b/src/hash.c index db79a06..4ee070c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -17,6 +17,7 @@ */ #include +#include #include "hash.h" usho do_hash(usho *b, int len) @@ -27,11 +28,12 @@ usho do_hash(usho *b, int len) return result; } -usho do_hash_file(const char *filename) +usho do_hash_file(const char *filename, const char *type) { unsigned char buf[BSIZE]; FILE *fd = fopen(filename, "r"); usho hash = 0; + int size; int ret; if (fd == NULL) { @@ -46,8 +48,20 @@ usho do_hash_file(const char *filename) hash ^= do_hash((usho *)&buf, ret); } while(ret); + size = ftell(fd); fclose(fd); + /* mmc image must be aligned */ + if (type && strcmp(type, "mmc") == 0) { + int align = ((size >> 8) + 1) << 8; + printf("align from %d to %d\n", size, align); + buf[0] = 0xff; + while (size < align) { + hash ^= do_hash((usho *)&buf, 1); + ++size; + } + } + return hash; } -- cgit v1.2.3