Add static keywords to core target source file data and functions.
[openocd.git] / src / target / image.c
index 793a811f6724ba901a63aa6618b4663c5c960c2e..2b6d0d11def83ebd35cac5bca16f6ebeaddaf19d 100644 (file)
@@ -83,15 +83,15 @@ static int autodetect_image_type(image_t *image, char *url)
                LOG_DEBUG("ELF image detected.");
                image->type = IMAGE_ELF;
        }
-       else if  ((buffer[0]==':') /* record start byte */
-               &&(isxdigit(buffer[1]))
-               &&(isxdigit(buffer[2]))
-               &&(isxdigit(buffer[3]))
-               &&(isxdigit(buffer[4]))
-               &&(isxdigit(buffer[5]))
-               &&(isxdigit(buffer[6]))
-               &&(buffer[7]=='0') /* record type : 00 -> 05 */
-               &&(buffer[8]>='0')&&(buffer[8]<'6'))
+       else if ((buffer[0]==':') /* record start byte */
+               &&(isxdigit(buffer[1]))
+               &&(isxdigit(buffer[2]))
+               &&(isxdigit(buffer[3]))
+               &&(isxdigit(buffer[4]))
+               &&(isxdigit(buffer[5]))
+               &&(isxdigit(buffer[6]))
+               &&(buffer[7]=='0') /* record type : 00 -> 05 */
+               &&(buffer[8]>='0')&&(buffer[8]<'6'))
        {
                LOG_DEBUG("IHEX image detected.");
                image->type = IMAGE_IHEX;
@@ -113,7 +113,7 @@ static int autodetect_image_type(image_t *image, char *url)
        return ERROR_OK;
 }
 
-int identify_image_type(image_t *image, char *type_string, char *url)
+static int identify_image_type(image_t *image, char *type_string, char *url)
 {
        if (type_string)
        {
@@ -154,7 +154,7 @@ int identify_image_type(image_t *image, char *type_string, char *url)
        return ERROR_OK;
 }
 
-int image_ihex_buffer_complete(image_t *image)
+static int image_ihex_buffer_complete(image_t *image)
 {
        image_ihex_t *ihex = image->type_private;
        fileio_t *fileio = &ihex->fileio;
@@ -344,7 +344,7 @@ int image_ihex_buffer_complete(image_t *image)
        return ERROR_IMAGE_FORMAT_ERROR;
 }
 
-int image_elf_read_headers(image_t *image)
+static int image_elf_read_headers(image_t *image)
 {
        image_elf_t *elf = image->type_private;
        u32 read_bytes;
@@ -381,7 +381,6 @@ int image_elf_read_headers(image_t *image)
                return ERROR_IMAGE_FORMAT_ERROR;
        }
 
-
        elf->endianness = elf->header->e_ident[EI_DATA];
        if ((elf->endianness!=ELFDATA2LSB)
                 &&(elf->endianness!=ELFDATA2MSB))
@@ -446,7 +445,7 @@ int image_elf_read_headers(image_t *image)
        return ERROR_OK;
 }
 
-int image_elf_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read)
+static int image_elf_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read)
 {
        image_elf_t *elf = image->type_private;
        Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
@@ -487,7 +486,7 @@ int image_elf_read_section(image_t *image, int section, u32 offset, u32 size, u8
        return ERROR_OK;
 }
 
-int image_mot_buffer_complete(image_t *image)
+static int image_mot_buffer_complete(image_t *image)
 {
        image_mot_t *mot = image->type_private;
        fileio_t *fileio = &mot->fileio;
@@ -718,6 +717,13 @@ int image_open(image_t *image, char *url, char *type_string)
        }
        else if (image->type == IMAGE_MEMORY)
        {
+               target_t *target = get_target_by_num(strtoul(url, NULL, 0));
+               if (target==NULL)
+               {
+                       LOG_ERROR("Target '%s' does not exist", url);
+                       return ERROR_FAIL;
+               }
+
                image_memory_t *image_memory;
 
                image->num_sections = 1;
@@ -728,7 +734,7 @@ int image_open(image_t *image, char *url, char *type_string)
 
                image_memory = image->type_private = malloc(sizeof(image_memory_t));
 
-               image_memory->target = get_target_by_num(strtoul(url, NULL, 0));;
+               image_memory->target = target;
                image_memory->cache = NULL;
                image_memory->cache_address = 0x0;
        }
@@ -912,7 +918,7 @@ int image_add_section(image_t *image, u32 base, u32 size, int flags, u8 *data)
        return ERROR_OK;
 }
 
-int image_close(image_t *image)
+void image_close(image_t *image)
 {
        if (image->type == IMAGE_BINARY)
        {
@@ -994,42 +1000,44 @@ int image_close(image_t *image)
                free(image->sections);
                image->sections = NULL;
        }
-
-       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;
 }
-
-

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)