summaryrefslogtreecommitdiffstats
path: root/src/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/hash.c b/src/hash.c
index d4ad607..cc17492 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -1,6 +1,6 @@
/*
* 0xFFFF - Open Free Fiasco Firmware Flasher
- * Copyright (C) 2007 pancake <pancake@youterm.com>
+ * Copyright (C) 2007-2009 pancake <pancake@youterm.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "hash.h"
usho do_hash(usho *b, int len)
@@ -27,11 +28,13 @@ 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 align = 0;
+ int size;
int ret;
if (fd == NULL) {
@@ -39,7 +42,8 @@ usho do_hash_file(const char *filename)
return -1;
}
- do { ret = fread(&buf, 1, BSIZE, fd);
+ do {
+ ret = fread(&buf, 1, BSIZE, fd);
if (ret == -1) {
fclose(fd);
return 0;
@@ -47,8 +51,26 @@ usho do_hash_file(const char *filename)
hash ^= do_hash((usho *)&buf, ret);
} while(ret);
+ size = ftell(fd);
fclose(fd);
+ /* mmc and kernel image must be aligned */
+ if (type) {
+ if (strcmp(type, "mmc") == 0)
+ align = ((size >> 8) + 1) << 8;
+ else if (strcmp(type, "kernel") == 0)
+ align = ((size >> 7) + 1) << 7;
+ }
+
+ if (align) {
+ printf("align from %d to %d\n", size, align);
+ buf[0] = 0xff;
+ while (size < align) {
+ hash ^= do_hash((usho *)&buf, 1);
+ ++size;
+ }
+ }
+
return hash;
}