summaryrefslogtreecommitdiffstats
path: root/tools/telechips.c
diff options
context:
space:
mode:
authorTomer Shalev <shalev.tomer@gmail.com>2009-11-01 18:26:00 +0000
committerTomer Shalev <shalev.tomer@gmail.com>2009-11-01 18:26:00 +0000
commitbcadf96066c20953ae6be7447f1ee2cd8742ab4f (patch)
tree422ba0e39a5275103eee185b2fd63e4120a87058 /tools/telechips.c
parent50edc5819ea22c9635bfdc7459a1cd7bcd6d82fa (diff)
downloadrockbox-bcadf96066c20953ae6be7447f1ee2cd8742ab4f.tar.gz
rockbox-bcadf96066c20953ae6be7447f1ee2cd8742ab4f.tar.bz2
rockbox-bcadf96066c20953ae6be7447f1ee2cd8742ab4f.zip
FS#10740 - rbutil: Test Cowon D2 OF file for CRC consistency before patching
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23470 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/telechips.c')
-rw-r--r--tools/telechips.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/tools/telechips.c b/tools/telechips.c
index 8eefffcb98..acb15b8b14 100644
--- a/tools/telechips.c
+++ b/tools/telechips.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
static uint32_t crctable[256];
@@ -57,11 +58,11 @@ static void gentable(uint32_t poly)
{
int i;
uint32_t r;
- uint32_t index;
+ uint32_t idx;
- for (index = 0; index < 256; index++)
+ for (idx = 0; idx < 256; idx++)
{
- r = bitreverse(index,8) << 24;
+ r = bitreverse(idx,8) << 24;
for (i=0; i<8; i++)
{
if (r & (1 << 31))
@@ -69,7 +70,7 @@ static void gentable(uint32_t poly)
else
r<<=1;
}
- crctable[index] = bitreverse(r,32);
+ crctable[idx] = bitreverse(r,32);
}
}
@@ -156,3 +157,26 @@ void telechips_encode_crc(unsigned char* buf, int length)
put_uint32le(buf+0x10, crc1);
}
}
+
+int telechips_test_crc(unsigned char* buf, int length)
+{
+ uint32_t crc1, crc2, test_crc1, test_crc2;
+ unsigned char *test_buf;
+
+ crc1 = get_uint32le(buf + 0x10);
+ crc2 = get_uint32le(buf + 0x18);
+
+ test_buf = malloc(length);
+ if (!test_buf)
+ return 1;
+
+ memcpy(test_buf, buf, length);
+ telechips_encode_crc(test_buf, length);
+
+ test_crc1 = get_uint32le(test_buf + 0x10);
+ test_crc2 = get_uint32le(test_buf + 0x18);
+
+ free(test_buf);
+
+ return (crc1 == test_crc1 && crc2 == test_crc2) ? 0 : 2;
+}