do_hash_file - align size for mmc images, append chars \xff (nokia flasher needs mmc images alingned)
This commit is contained in:
1 parent
b1cfc3181b
commit
8bc521f3e5
4 files changed
+18
-4
No files matched your search
+1
-1
@@ -84,7 +84,7 @@ void flash_image(const char *filename, const char *piece, const char *device, co
|
|||||||
unsigned long long size, off;
|
unsigned long long size, off;
|
||||||
unsigned char bsize[4], tmp;
|
unsigned char bsize[4], tmp;
|
||||||
unsigned char nolofiller[128];
|
unsigned char nolofiller[128];
|
||||||
ushort hash = do_hash_file(filename);
|
ushort hash = do_hash_file(filename, piece);
|
||||||
|
|
||||||
if (piece == NULL) {
|
if (piece == NULL) {
|
||||||
//exit(1);
|
//exit(1);
|
||||||
|
|||||||
+15
-1
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
usho do_hash(usho *b, int len)
|
usho do_hash(usho *b, int len)
|
||||||
@@ -27,11 +28,12 @@ usho do_hash(usho *b, int len)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
usho do_hash_file(const char *filename)
|
usho do_hash_file(const char *filename, const char *type)
|
||||||
{
|
{
|
||||||
unsigned char buf[BSIZE];
|
unsigned char buf[BSIZE];
|
||||||
FILE *fd = fopen(filename, "r");
|
FILE *fd = fopen(filename, "r");
|
||||||
usho hash = 0;
|
usho hash = 0;
|
||||||
|
int size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
@@ -46,8 +48,20 @@ usho do_hash_file(const char *filename)
|
|||||||
hash ^= do_hash((usho *)&buf, ret);
|
hash ^= do_hash((usho *)&buf, ret);
|
||||||
} while(ret);
|
} while(ret);
|
||||||
|
|
||||||
|
size = ftell(fd);
|
||||||
fclose(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;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,6 +5,6 @@
|
|||||||
#define BSIZE 0x20000
|
#define BSIZE 0x20000
|
||||||
|
|
||||||
usho do_hash(usho *b, int len);
|
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
|
#endif
|
||||||
+1
-1
@@ -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) {
|
while((c = getopt(argc, argv, "QC:cp:PvVhRu:ib:U:r:e:ld:I:D:f:F:s:xH:S:n")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'H':
|
case 'H':
|
||||||
printf("xorpair: %04x\n", do_hash_file(optarg));
|
printf("xorpair: %04x\n", do_hash_file(optarg, NULL));
|
||||||
return 0;
|
return 0;
|
||||||
case 'x':
|
case 'x':
|
||||||
return dump_config();
|
return dump_config();
|
||||||
|
|||||||
Reference in new issue
Block a user