Edgar Grimberg fixes some memory handling issues and
a problem with arm7_9_debug_entry not executing a code path upon crashes. git-svn-id: svn://svn.berlios.de/openocd/trunk@669 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
0989c374e9
commit
0485363c45
|
@ -829,12 +829,15 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
|
||||||
buffer = malloc(fileio.size);
|
buffer = malloc(fileio.size);
|
||||||
if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
|
if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
|
||||||
{
|
{
|
||||||
|
free(buffer);
|
||||||
|
fileio_close(&fileio);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = flash_driver_write(p, buffer, offset, buf_cnt);
|
retval = flash_driver_write(p, buffer, offset, buf_cnt);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
buffer = NULL;
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
duration_stop_measure(&duration, &duration_text);
|
||||||
if (retval!=ERROR_OK)
|
if (retval!=ERROR_OK)
|
||||||
|
|
|
@ -1292,6 +1292,9 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
if (offset % p->page_size)
|
if (offset % p->page_size)
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "only page size aligned offsets and sizes are supported");
|
command_print(cmd_ctx, "only page size aligned offsets and sizes are supported");
|
||||||
|
fileio_close(&fileio);
|
||||||
|
free(oob);
|
||||||
|
free(page);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1299,7 +1302,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
{
|
{
|
||||||
u32 size_read;
|
u32 size_read;
|
||||||
|
|
||||||
if (page)
|
if (NULL != page)
|
||||||
{
|
{
|
||||||
fileio_read(&fileio, page_size, page, &size_read);
|
fileio_read(&fileio, page_size, page, &size_read);
|
||||||
buf_cnt -= size_read;
|
buf_cnt -= size_read;
|
||||||
|
@ -1309,7 +1312,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oob)
|
if (NULL != oob)
|
||||||
{
|
{
|
||||||
fileio_read(&fileio, oob_size, oob, &size_read);
|
fileio_read(&fileio, oob_size, oob, &size_read);
|
||||||
buf_cnt -= size_read;
|
buf_cnt -= size_read;
|
||||||
|
@ -1323,17 +1326,26 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "failed writing file %s to NAND flash %s at offset 0x%8.8x",
|
command_print(cmd_ctx, "failed writing file %s to NAND flash %s at offset 0x%8.8x",
|
||||||
args[1], args[0], offset);
|
args[1], args[0], offset);
|
||||||
|
|
||||||
|
fileio_close(&fileio);
|
||||||
|
free(oob);
|
||||||
|
free(page);
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
offset += page_size;
|
offset += page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
free(oob);
|
||||||
|
free(page);
|
||||||
|
oob = NULL;
|
||||||
|
page = NULL;
|
||||||
duration_stop_measure(&duration, &duration_text);
|
duration_stop_measure(&duration, &duration_text);
|
||||||
command_print(cmd_ctx, "wrote file %s to NAND flash %s at offset 0x%8.8x in %s",
|
command_print(cmd_ctx, "wrote file %s to NAND flash %s at offset 0x%8.8x in %s",
|
||||||
args[1], args[0], offset, duration_text);
|
args[1], args[0], offset, duration_text);
|
||||||
free(duration_text);
|
free(duration_text);
|
||||||
|
duration_text = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1419,16 +1431,19 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
if ((retval = nand_read_page(p, address / p->page_size, page, page_size, oob, oob_size)) != ERROR_OK)
|
if ((retval = nand_read_page(p, address / p->page_size, page, page_size, oob, oob_size)) != ERROR_OK)
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "reading NAND flash page failed");
|
command_print(cmd_ctx, "reading NAND flash page failed");
|
||||||
|
free(page);
|
||||||
|
free(oob);
|
||||||
|
fileio_close(&fileio);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page)
|
if (NULL != page)
|
||||||
{
|
{
|
||||||
fileio_write(&fileio, page_size, page, &size_written);
|
fileio_write(&fileio, page_size, page, &size_written);
|
||||||
bytes_done += page_size;
|
bytes_done += page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oob)
|
if (NULL != oob)
|
||||||
{
|
{
|
||||||
fileio_write(&fileio, oob_size, oob, &size_written);
|
fileio_write(&fileio, oob_size, oob, &size_written);
|
||||||
bytes_done += oob_size;
|
bytes_done += oob_size;
|
||||||
|
@ -1438,17 +1453,16 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
|
||||||
address += p->page_size;
|
address += p->page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page)
|
free(page);
|
||||||
free(page);
|
page = NULL;
|
||||||
|
free(oob);
|
||||||
if (oob)
|
oob = NULL;
|
||||||
free(oob);
|
|
||||||
|
|
||||||
fileio_close(&fileio);
|
fileio_close(&fileio);
|
||||||
|
|
||||||
duration_stop_measure(&duration, &duration_text);
|
duration_stop_measure(&duration, &duration_text);
|
||||||
command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
|
command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
|
||||||
free(duration_text);
|
free(duration_text);
|
||||||
|
duration_text = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1111,7 +1111,7 @@ int arm7_9_debug_entry(target_t *target)
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
|
|
||||||
/* exceptions other than USR & SYS have a saved program status register */
|
/* exceptions other than USR & SYS have a saved program status register */
|
||||||
if ((armv4_5_mode_to_number(armv4_5->core_mode) != ARMV4_5_MODE_USR) && (armv4_5_mode_to_number(armv4_5->core_mode) != ARMV4_5_MODE_SYS))
|
if ((armv4_5->core_mode != ARMV4_5_MODE_USR) && (armv4_5->core_mode != ARMV4_5_MODE_SYS))
|
||||||
{
|
{
|
||||||
u32 spsr;
|
u32 spsr;
|
||||||
arm7_9->read_xpsr(target, &spsr, 1);
|
arm7_9->read_xpsr(target, &spsr, 1);
|
||||||
|
|
|
@ -1645,12 +1645,14 @@ int handle_etm_load_command(struct command_context_s *cmd_ctx, char *cmd, char *
|
||||||
if (file.size % 4)
|
if (file.size % 4)
|
||||||
{
|
{
|
||||||
command_print(cmd_ctx, "size isn't a multiple of 4, no valid trace data");
|
command_print(cmd_ctx, "size isn't a multiple of 4, no valid trace data");
|
||||||
|
fileio_close(&file);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (etm_ctx->trace_depth > 0)
|
if (etm_ctx->trace_depth > 0)
|
||||||
{
|
{
|
||||||
free(etm_ctx->trace_data);
|
free(etm_ctx->trace_data);
|
||||||
|
etm_ctx->trace_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileio_read_u32(&file, &etm_ctx->capture_status);
|
fileio_read_u32(&file, &etm_ctx->capture_status);
|
||||||
|
@ -1659,6 +1661,12 @@ int handle_etm_load_command(struct command_context_s *cmd_ctx, char *cmd, char *
|
||||||
fileio_read_u32(&file, &etm_ctx->trace_depth);
|
fileio_read_u32(&file, &etm_ctx->trace_depth);
|
||||||
|
|
||||||
etm_ctx->trace_data = malloc(sizeof(etmv1_trace_data_t) * etm_ctx->trace_depth);
|
etm_ctx->trace_data = malloc(sizeof(etmv1_trace_data_t) * etm_ctx->trace_depth);
|
||||||
|
if(etm_ctx->trace_data == NULL)
|
||||||
|
{
|
||||||
|
command_print(cmd_ctx, "not enough memory to perform operation");
|
||||||
|
fileio_close(&file);
|
||||||
|
return ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < etm_ctx->trace_depth; i++)
|
for (i = 0; i < etm_ctx->trace_depth; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -347,6 +347,12 @@ int image_elf_read_headers(image_t *image)
|
||||||
|
|
||||||
elf->header = malloc(sizeof(Elf32_Ehdr));
|
elf->header = malloc(sizeof(Elf32_Ehdr));
|
||||||
|
|
||||||
|
if(elf->header == NULL)
|
||||||
|
{
|
||||||
|
LOG_ERROR("insufficient memory to perform operation ");
|
||||||
|
return ERROR_FILEIO_OPERATION_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
if ((retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (u8*)elf->header, &read_bytes)) != ERROR_OK)
|
if ((retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (u8*)elf->header, &read_bytes)) != ERROR_OK)
|
||||||
{
|
{
|
||||||
LOG_ERROR("cannot read ELF file header, read failed");
|
LOG_ERROR("cannot read ELF file header, read failed");
|
||||||
|
@ -392,6 +398,11 @@ int image_elf_read_headers(image_t *image)
|
||||||
}
|
}
|
||||||
|
|
||||||
elf->segments = malloc(elf->segment_count*sizeof(Elf32_Phdr));
|
elf->segments = malloc(elf->segment_count*sizeof(Elf32_Phdr));
|
||||||
|
if(elf->segments == NULL)
|
||||||
|
{
|
||||||
|
LOG_ERROR("insufficient memory to perform operation ");
|
||||||
|
return ERROR_FILEIO_OPERATION_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
if ((retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (u8*)elf->segments, &read_bytes)) != ERROR_OK)
|
if ((retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (u8*)elf->segments, &read_bytes)) != ERROR_OK)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue