summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-06-23 13:07:34 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-06-23 13:07:34 +0200
commit8bc521f3e5e83fddc08a031aa7cf7499514ee732 (patch)
tree386753580f47d05c640e68b50b2120a2af48373e
parentb1cfc3181bc83b43e07f3b801166c8c8181cecf8 (diff)
download0xFFFF-8bc521f3e5e83fddc08a031aa7cf7499514ee732.tar.bz2
do_hash_file - align size for mmc images, append chars \xff (nokia flasher needs mmc images alingned)
-rw-r--r--src/flash.c2
-rw-r--r--src/hash.c16
-rw-r--r--src/hash.h2
-rw-r--r--src/main.c2
4 files changed, 18 insertions, 4 deletions
diff --git a/src/flash.c b/src/flash.c
index d1d7efd..3ad957f 100644
--- a/src/flash.c
+++ b/src/flash.c
@@ -84,7 +84,7 @@ void flash_image(const char *filename, const char *piece, const char *device, co
unsigned long long size, off;
unsigned char bsize[4], tmp;
unsigned char nolofiller[128];
- ushort hash = do_hash_file(filename);
+ ushort hash = do_hash_file(filename, piece);
if (piece == NULL) {
//exit(1);
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 <stdio.h>
+#include <string.h>
#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;
}
diff --git a/src/hash.h b/src/hash.h
index 363d5d4..03825ae 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -5,6 +5,6 @@
#define BSIZE 0x20000
usho do_hash(usho *b, int len);
-usho do_hash_file(const char *filename);
+usho do_hash_file(const char *filename, const char *type);
#endif
diff --git a/src/main.c b/src/main.c
index 6f37334..68f7ffb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -291,7 +291,7 @@ int main(int argc, char **argv)
while((c = getopt(argc, argv, "QC:cp:PvVhRu:ib:U:r:e:ld:I:D:f:F:s:xH:S:n")) != -1) {
switch(c) {
case 'H':
- printf("xorpair: %04x\n", do_hash_file(optarg));
+ printf("xorpair: %04x\n", do_hash_file(optarg, NULL));
return 0;
case 'x':
return dump_config();