diff options
author | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-10-06 11:16:10 +0000 |
---|---|---|
committer | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-10-06 11:16:10 +0000 |
commit | 7b369df52cb71fab738fc852c9358059f6cff57c (patch) | |
tree | 32e5e529e69b9fde207cd13254a997f4c1c532c8 /src/target/image.c | |
parent | 333499a962c56b9b5b121d469d0b048b891c0fa1 (diff) | |
download | riscv-openocd-7b369df52cb71fab738fc852c9358059f6cff57c.zip riscv-openocd-7b369df52cb71fab738fc852c9358059f6cff57c.tar.gz riscv-openocd-7b369df52cb71fab738fc852c9358059f6cff57c.tar.bz2 |
better keep_alive() handling
git-svn-id: svn://svn.berlios.de/openocd/trunk@1018 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target/image.c')
-rw-r--r-- | src/target/image.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/target/image.c b/src/target/image.c index 793a811..48c6a6c 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -998,36 +998,42 @@ 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; + LOG_DEBUG("Calculating checksum"); + + u32 crc32_table[256]; - if (!crc32_table[1]) + /* Initialize the CRC table and the decoding table. */ + int i, j; + unsigned int c; + for (i = 0; i < 256; i++) { - /* 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; - } + /* 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--) + while (nbytes>0) { - /* as per gdb */ - crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255]; - if ((nbytes%16384)==0) + int run=nbytes; + if (run>32768) { - keep_alive(); + run=32768; } + nbytes-=run; + while (run--) + { + /* as per gdb */ + crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255]; + } + keep_alive(); } + LOG_DEBUG("Calculating checksum done"); + *checksum = crc; return ERROR_OK; } |