embedded: save stack
authorØyvind Harboe <oyvind.harboe@zylin.com>
Sat, 21 Nov 2009 22:45:36 +0000 (23:45 +0100)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Sun, 22 Nov 2009 12:38:42 +0000 (13:38 +0100)
and also do not recaluate the crc32_table upon
every invocation.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/target/image.c

index 8774c2517ba6e1f500e1f353466d348503e1595a..76c8cc90bb4f132b5cfae678be25035b7a210719 100644 (file)
@@ -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)