Skip to content
Snippets Groups Projects
Commit 7b369df5 authored by oharboe's avatar oharboe
Browse files

better keep_alive() handling

git-svn-id: svn://svn.berlios.de/openocd/trunk@1018 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 333499a9
No related branches found
No related tags found
No related merge requests found
...@@ -998,14 +998,13 @@ int image_close(image_t *image) ...@@ -998,14 +998,13 @@ int image_close(image_t *image)
return ERROR_OK; return ERROR_OK;
} }
static u32 crc32_table[256] = {0, 0};
int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum) int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum)
{ {
u32 crc = 0xffffffff; u32 crc = 0xffffffff;
LOG_DEBUG("Calculating checksum");
u32 crc32_table[256];
if (!crc32_table[1])
{
/* Initialize the CRC table and the decoding table. */ /* Initialize the CRC table and the decoding table. */
int i, j; int i, j;
unsigned int c; unsigned int c;
...@@ -1016,18 +1015,25 @@ int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum) ...@@ -1016,18 +1015,25 @@ int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum)
c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
crc32_table[i] = c; crc32_table[i] = c;
} }
}
while (nbytes--) while (nbytes>0)
{
int run=nbytes;
if (run>32768)
{
run=32768;
}
nbytes-=run;
while (run--)
{ {
/* as per gdb */ /* as per gdb */
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255]; crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255];
if ((nbytes%16384)==0)
{
keep_alive();
} }
keep_alive();
} }
LOG_DEBUG("Calculating checksum done");
*checksum = crc; *checksum = crc;
return ERROR_OK; return ERROR_OK;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment