kbc1126_ec_dump: fix some errors

- fix the error caused by signed integer extension
- fix fopen mode
- one minor style fix

Change-Id: Iacc4ea50515ea219bc1868dae0446d576e8dce0c
Signed-off-by: Iru Cai <mytbk920423@gmail.com>
Reviewed-on: https://review.coreboot.org/21013
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
This commit is contained in:
Iru Cai 2017-08-12 09:20:55 +08:00 committed by Martin Roth
parent 728d488ab3
commit 457fba6be5
1 changed files with 10 additions and 10 deletions

View File

@ -49,9 +49,9 @@ void dump_fw(FILE *dst, FILE *src, long offset)
fread(&cksum, 2, 1, src); fread(&cksum, 2, 1, src);
fread(buf, len, 1, src); fread(buf, len, 1, src);
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++)
_cksum += buf[i]; _cksum += buf[i];
}
if (_cksum == cksum) { if (_cksum == cksum) {
puts("checksum ok"); puts("checksum ok");
} else { } else {
@ -69,7 +69,7 @@ int main(int argc, char *argv[])
if (argc != 2) if (argc != 2)
usage(argv[0]); usage(argv[0]);
FILE *fp = fopen(argv[1], "rb+"); FILE *fp = fopen(argv[1], "rb");
if (fp == NULL) { if (fp == NULL) {
puts("Error opening file!"); puts("Error opening file!");
@ -89,8 +89,8 @@ int main(int argc, char *argv[])
strcat(fn1, ".fw1"); strcat(fn1, ".fw1");
strcat(fn2, ".fw2"); strcat(fn2, ".fw2");
FILE *fw1 = fopen(fn1, "wb+"); FILE *fw1 = fopen(fn1, "wb");
FILE *fw2 = fopen(fn2, "wb+"); FILE *fw2 = fopen(fn2, "wb");
long romsz; long romsz;
FseekEnd(fp, -1); FseekEnd(fp, -1);
@ -103,14 +103,14 @@ int main(int argc, char *argv[])
} }
/* read offset of fw1 and fw2 */ /* read offset of fw1 and fw2 */
char offs[8]; unsigned char offs[8];
FseekEnd(fp, -0x100); FseekEnd(fp, -0x100);
fread(offs, 8, 1, fp); fread(offs, 8, 1, fp);
assert(offs[0] + offs[2] == '\xff'); assert(offs[0] + offs[2] == 0xff);
assert(offs[1] + offs[3] == '\xff'); assert(offs[1] + offs[3] == 0xff);
assert(offs[4] + offs[6] == '\xff'); assert(offs[4] + offs[6] == 0xff);
assert(offs[5] + offs[7] == '\xff'); assert(offs[5] + offs[7] == 0xff);
long offw1 = (offs[0] << 16) | (offs[1] << 8); long offw1 = (offs[0] << 16) | (offs[1] << 8);
long offw2 = (offs[4] << 16) | (offs[5] << 8); long offw2 = (offs[4] << 16) | (offs[5] << 8);