diff options
author | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-11-21 23:45:36 +0100 |
---|---|---|
committer | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-11-22 13:38:42 +0100 |
commit | 31da0003dc6d307faa8fd66eb23319bd5e9ab7dd (patch) | |
tree | d8e659570f4097ffb5d3f4da59ea65bb0932f9f5 /src | |
parent | 808e53368c2c1daee3f6a5eb59038b990534f1ac (diff) | |
download | openocd_libswd-31da0003dc6d307faa8fd66eb23319bd5e9ab7dd.tar.gz openocd_libswd-31da0003dc6d307faa8fd66eb23319bd5e9ab7dd.tar.bz2 openocd_libswd-31da0003dc6d307faa8fd66eb23319bd5e9ab7dd.tar.xz openocd_libswd-31da0003dc6d307faa8fd66eb23319bd5e9ab7dd.zip |
embedded: save stack
and also do not recaluate the crc32_table upon
every invocation.
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/target/image.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/target/image.c b/src/target/image.c index 8774c251..76c8cc90 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -1023,17 +1023,23 @@ int image_calculate_checksum(uint8_t* buffer, uint32_t nbytes, uint32_t* checksu uint32_t crc = 0xffffffff; LOG_DEBUG("Calculating checksum"); - uint32_t crc32_table[256]; + static uint32_t crc32_table[256]; - /* Initialize the CRC table and the decoding table. */ - int i, j; - unsigned int c; - for (i = 0; i < 256; i++) + static bool first_init = false; + if (!first_init) { - /* as per gdb */ - for (c = i << 24, j = 8; j > 0; --j) - c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); - crc32_table[i] = c; + /* 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; + } + + first_init = true; } while (nbytes > 0) |