summaryrefslogtreecommitdiff
path: root/src/target/image.c
diff options
context:
space:
mode:
authorntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-10-22 08:44:34 +0000
committerntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-10-22 08:44:34 +0000
commite27696f6b04459e935a0a5f65f7f668cb02970dd (patch)
tree24ec25797d6cc0f97336553b44b0eee920634859 /src/target/image.c
parentce8768f46345e3f88ca6f8f0b88603d79e22d89a (diff)
downloadopenocd_libswd-e27696f6b04459e935a0a5f65f7f668cb02970dd.tar.gz
openocd_libswd-e27696f6b04459e935a0a5f65f7f668cb02970dd.tar.bz2
openocd_libswd-e27696f6b04459e935a0a5f65f7f668cb02970dd.tar.xz
openocd_libswd-e27696f6b04459e935a0a5f65f7f668cb02970dd.zip
- add verify_image command
- add support for gdb qCRC packet (compare-sections command) git-svn-id: svn://svn.berlios.de/openocd/trunk@210 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target/image.c')
-rw-r--r--src/target/image.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/target/image.c b/src/target/image.c
index dbb1c2ab..d20f9df2 100644
--- a/src/target/image.c
+++ b/src/target/image.c
@@ -949,3 +949,34 @@ int image_close(image_t *image)
return ERROR_OK;
}
+
+static u32 crc32_table[256] = {0, 0};
+
+int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum)
+{
+ u32 crc = 0xffffffff;
+
+ if (!crc32_table[1])
+ {
+ /* Initialize the CRC table and the decoding table. */
+ int i, j;
+ unsigned int c;
+ for (i = 0; i < 256; i++)
+ {
+ /* as per gdb */
+ for (c = i << 24, j = 8; j > 0; --j)
+ c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
+ crc32_table[i] = c;
+ }
+ }
+
+ while (nbytes--)
+ {
+ /* as per gdb */
+ crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255];
+ }
+
+ *checksum = crc;
+ return ERROR_OK;
+}
+