]> git.sur5r.net Git - openocd/blobdiff - src/target/image.c
- fixed ETM configuration register decoding
[openocd] / src / target / image.c
index dbb1c2ab3a41791de683a42bdf760bb209888b05..d20f9df270fd96dc4e7ac4ce6c8f573802e46f85 100644 (file)
@@ -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;
+}
+