for (i = 0; i < image->num_sections; i++)
{
image->sections[i].private = section[i].private;
- image->sections[i].base_address = section[i].base_address +
- ((image->base_address_set) ? image->base_address : 0);
+ image->sections[i].base_address = section[i].base_address;
image->sections[i].size = section[i].size;
image->sections[i].flags = section[i].flags;
}
full_address = (full_address & 0xffff) | (upper_address << 4);
}
}
+ else if (record_type == 3) /* Start Segment Address Record */
+ {
+ u32 dummy;
+
+ /* "Start Segment Address Record" will not be supported */
+ /* but we must consume it, and do not create an error. */
+ while (count-- > 0)
+ {
+ sscanf(&lpszLine[bytes_read], "%2x", &dummy);
+ cal_checksum += (u8)dummy;
+ bytes_read += 2;
+ }
+ }
else if (record_type == 4) /* Extended Linear Address Record */
{
u16 upper_address;
full_address++;
}
}
+ else if (record_type == 5)
+ {
+ /* S5 is the data count record, we ignore it */
+ u32 dummy;
+
+ while (count-- > 0)
+ {
+ sscanf(&lpszLine[bytes_read], "%2x", &dummy);
+ cal_checksum += (u8)dummy;
+ bytes_read += 2;
+ }
+ }
else if (record_type >= 7 && record_type <= 9)
{
/* S7, S8, S9 - ending records for 32, 24 and 16bit */
for (i = 0; i < image->num_sections; i++)
{
image->sections[i].private = section[i].private;
- image->sections[i].base_address = section[i].base_address +
- ((image->base_address_set) ? image->base_address : 0);
+ image->sections[i].base_address = section[i].base_address;
image->sections[i].size = section[i].size;
image->sections[i].flags = section[i].flags;
}
image->sections[0].base_address = 0x0;
image->sections[0].size = image_binary->fileio.size;
image->sections[0].flags = 0;
-
- if (image->base_address_set == 1)
- image->sections[0].base_address = image->base_address;
-
- return ERROR_OK;
}
else if (image->type == IMAGE_IHEX)
{
image->sections = NULL;
image->type_private = NULL;
}
+
+ if (image->base_address_set)
+ {
+ // relocate
+ int section;
+ for (section=0; section < image->num_sections; section++)
+ {
+ image->sections[section].base_address+=image->base_address;
+ }
+ // we're done relocating. The two statements below are mainly
+ // for documenation purposes: stop anyone from empirically
+ // thinking they should use these values henceforth.
+ image->base_address=0;
+ image->base_address_set=0;
+ }
return retval;
};
IMAGE_MEMORY_CACHE_SIZE, image_memory->cache) != ERROR_OK)
{
free(image_memory->cache);
+ image_memory->cache = NULL;
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
}
image_memory->cache_address = address & ~(IMAGE_MEMORY_CACHE_SIZE - 1);
fileio_close(&image_ihex->fileio);
if (image_ihex->buffer)
+ {
free(image_ihex->buffer);
+ image_ihex->buffer = NULL;
+ }
}
else if (image->type == IMAGE_ELF)
{
fileio_close(&image_elf->fileio);
if (image_elf->header)
+ {
free(image_elf->header);
+ image_elf->header = NULL;
+ }
if (image_elf->segments)
+ {
free(image_elf->segments);
+ image_elf->segments = NULL;
+ }
}
else if (image->type == IMAGE_MEMORY)
{
image_memory_t *image_memory = image->type_private;
if (image_memory->cache)
+ {
free(image_memory->cache);
+ image_memory->cache = NULL;
+ }
}
else if (image->type == IMAGE_SRECORD)
{
fileio_close(&image_mot->fileio);
if (image_mot->buffer)
+ {
free(image_mot->buffer);
+ image_mot->buffer = NULL;
+ }
}
else if (image->type == IMAGE_BUILDER)
{
for (i = 0; i < image->num_sections; i++)
{
free(image->sections[i].private);
+ image->sections[i].private = NULL;
}
}
if (image->type_private)
+ {
free(image->type_private);
+ image->type_private = NULL;
+ }
if (image->sections)
+ {
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;
+
+ if (!crc32_table[1])
+ {
+ /* 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;
+ }
+ }
+
+ while (nbytes--)
+ {
+ /* as per gdb */
+ crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255];
+ }
+
+ *checksum = crc;
+ return ERROR_OK;
+}
+
+