- added patch for new flash functionality like:

flash verify_image and flash erase_address.
- added patch for new parport_write_on_exit command.
Even this patch will fix some memory leaks.

(thanks too oyvind and Spen for these patches)

git-svn-id: svn://svn.berlios.de/openocd/trunk@240 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
mifi 2007-12-18 21:20:28 +00:00
parent ed1e9d6abd
commit 02f3765351
15 changed files with 267 additions and 63 deletions

View File

@ -320,6 +320,10 @@ This is also the layout used by the HollyGates design
@cindex flashlink @cindex flashlink
ST Parallel cable. ST Parallel cable.
@end itemize @end itemize
@item @b{parport_write_on_exit} <@var{on|off}>
@cindex parport_write_on_exit
This will configure the parallel driver to write a known value to the parallel
interface on exiting openocd
@end itemize @end itemize
@section amt_jtagaccel options @section amt_jtagaccel options

View File

@ -43,13 +43,16 @@ int handle_flash_banks_command(struct command_context_s *cmd_ctx, char *cmd, cha
int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr);
/* flash drivers /* flash drivers
*/ */
@ -103,13 +106,19 @@ int flash_init(struct command_context_s *cmd_ctx)
register_command(cmd_ctx, flash_cmd, "protect_check", handle_flash_protect_check_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "protect_check", handle_flash_protect_check_command, COMMAND_EXEC,
"check protection state of sectors in flash bank <num>"); "check protection state of sectors in flash bank <num>");
register_command(cmd_ctx, flash_cmd, "erase", handle_flash_erase_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "erase", handle_flash_erase_command, COMMAND_EXEC,
"DEPRECATED, use 'erase_sector' instead");
register_command(cmd_ctx, flash_cmd, "erase_sector", handle_flash_erase_command, COMMAND_EXEC,
"erase sectors at <bank> <first> <last>"); "erase sectors at <bank> <first> <last>");
register_command(cmd_ctx, flash_cmd, "erase_address", handle_flash_erase_address_command, COMMAND_EXEC,
"erase address range <address> <length>");
register_command(cmd_ctx, flash_cmd, "write", handle_flash_write_binary_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "write", handle_flash_write_binary_command, COMMAND_EXEC,
"DEPRECATED, use 'write_binary' or 'write_image' instead"); "DEPRECATED, use 'write_binary' instead");
register_command(cmd_ctx, flash_cmd, "write_binary", handle_flash_write_binary_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "write_binary", handle_flash_write_binary_command, COMMAND_EXEC,
"write binary <bank> <file> <offset>"); "write binary <bank> <file> <offset>");
register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC,
"write image <file> [offset] [type]"); "write_image <file> [offset] [type]");
register_command(cmd_ctx, flash_cmd, "verify_image", handle_flash_verify_image_command, COMMAND_EXEC,
"verify_image <file> [offset] [type]");
register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC,
"set protection of sectors at <bank> <first> <last> <on|off>"); "set protection of sectors at <bank> <first> <last> <on|off>");
register_command(cmd_ctx, flash_cmd, "auto_erase", handle_flash_auto_erase_command, COMMAND_EXEC, register_command(cmd_ctx, flash_cmd, "auto_erase", handle_flash_auto_erase_command, COMMAND_EXEC,
@ -355,6 +364,71 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
return ERROR_OK; return ERROR_OK;
} }
static void printError(struct command_context_s *cmd_ctx, flash_bank_t *p, int retval)
{
if (retval==ERROR_OK)
return;
switch (retval)
{
case ERROR_TARGET_NOT_HALTED:
command_print(cmd_ctx, "can't work with this flash while target is running");
break;
case ERROR_INVALID_ARGUMENTS:
command_print(cmd_ctx, "usage: flash write <bank> <file> <offset>");
break;
case ERROR_FLASH_BANK_INVALID:
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
break;
case ERROR_FLASH_OPERATION_FAILED:
command_print(cmd_ctx, "flash program error");
break;
case ERROR_FLASH_DST_BREAKS_ALIGNMENT:
command_print(cmd_ctx, "offset breaks required alignment");
break;
case ERROR_FLASH_DST_OUT_OF_BANK:
command_print(cmd_ctx, "destination is out of flash bank (offset and/or file too large)");
break;
case ERROR_FLASH_SECTOR_NOT_ERASED:
command_print(cmd_ctx, "destination sector(s) not erased");
break;
default:
command_print(cmd_ctx, "unknown error");
}
}
int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
flash_bank_t *p;
target_t *target = get_current_target(cmd_ctx);
if (argc != 2)
{
command_print(cmd_ctx, "usage: flash erase_address <address> <range>");
return ERROR_OK;
}
int address=strtoul(args[0], NULL, 0);
int length=strtoul(args[1], NULL, 0);
if (length<=0)
{
command_print(cmd_ctx, "Length must be >0");
return ERROR_INVALID_ARGUMENTS;
}
p = get_flash_bank_by_addr(target, address);
if (p==NULL)
{
command_print(cmd_ctx, "No flash at that address");
return ERROR_INVALID_ARGUMENTS;
}
int retval=flash_erase(target, address, length);
printError(cmd_ctx, p, retval);
return retval;
}
int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{ {
flash_bank_t *p; flash_bank_t *p;
@ -515,7 +589,7 @@ int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, c
return ERROR_OK; return ERROR_OK;
} }
int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) int handle_flash_write_image_command_core(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, enum flash_image_op op)
{ {
target_t *target = get_current_target(cmd_ctx); target_t *target = get_current_target(cmd_ctx);
@ -531,16 +605,10 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
int retval; int retval;
if (!strcmp(cmd, "write"))
{
command_print(cmd_ctx, "'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
DEBUG("'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
}
if (argc < 1) if (argc < 1)
{ {
command_print(cmd_ctx, "usage: flash write <file> [offset] [type]"); command_print(cmd_ctx, "usage: flash %s <file> [offset] [type]", cmd);
return ERROR_OK; return ERROR_INVALID_ARGUMENTS;
} }
if (!target) if (!target)
@ -574,7 +642,16 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
failed = malloc(sizeof(int) * image.num_sections); failed = malloc(sizeof(int) * image.num_sections);
error_str=NULL; error_str=NULL;
retval = flash_write(target, &image, &written, &error_str, failed, auto_erase);
retval=ERROR_OK;
if ((op==flash_image_op_write)&&auto_erase)
{
retval = flash_image_operation(target, &image, &written, &error_str, failed, flash_image_op_erase);
}
if (retval == ERROR_OK)
{
retval = flash_image_operation(target, &image, &written, &error_str, failed, op);
}
if (retval != ERROR_OK) if (retval != ERROR_OK)
{ {
@ -598,7 +675,8 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
} }
duration_stop_measure(&duration, &duration_text); duration_stop_measure(&duration, &duration_text);
command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)", command_print(cmd_ctx, "%s %u byte from file %s in %s (%f kb/s)",
(op==flash_image_op_write)?"wrote":"verified",
written, args[0], duration_text, written, args[0], duration_text,
(float)written / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0))); (float)written / 1024.0 / ((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)));
@ -610,6 +688,16 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
return ERROR_OK; return ERROR_OK;
} }
int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
return handle_flash_write_image_command_core(cmd_ctx, cmd, args, argc, flash_image_op_write);
}
int handle_flash_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
return handle_flash_write_image_command_core(cmd_ctx, cmd, args, argc, flash_image_op_verify);
}
int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{ {
u32 offset; u32 offset;
@ -626,7 +714,7 @@ int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *c
if (argc < 3) if (argc < 3)
{ {
command_print(cmd_ctx, "usage: flash write <bank> <file> <offset>"); command_print(cmd_ctx, "usage: flash write_binary <bank> <file> <offset>");
return ERROR_OK; return ERROR_OK;
} }
@ -642,14 +730,14 @@ int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *c
if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK) if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
{ {
command_print(cmd_ctx, "flash write error: %s", fileio.error_str); command_print(cmd_ctx, "flash write_binary error: %s", fileio.error_str);
return ERROR_OK; return ERROR_OK;
} }
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)
{ {
command_print(cmd_ctx, "flash write error: %s", fileio.error_str); command_print(cmd_ctx, "flash write_binary error: %s", fileio.error_str);
return ERROR_OK; return ERROR_OK;
} }
@ -657,32 +745,7 @@ int handle_flash_write_binary_command(struct command_context_s *cmd_ctx, char *c
{ {
command_print(cmd_ctx, "failed writing file %s to flash bank %i at offset 0x%8.8x", command_print(cmd_ctx, "failed writing file %s to flash bank %i at offset 0x%8.8x",
args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0)); args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0));
switch (retval) printError(cmd_ctx, p, retval);
{
case ERROR_TARGET_NOT_HALTED:
command_print(cmd_ctx, "can't work with this flash while target is running");
break;
case ERROR_INVALID_ARGUMENTS:
command_print(cmd_ctx, "usage: flash write <bank> <file> <offset>");
break;
case ERROR_FLASH_BANK_INVALID:
command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
break;
case ERROR_FLASH_OPERATION_FAILED:
command_print(cmd_ctx, "flash program error");
break;
case ERROR_FLASH_DST_BREAKS_ALIGNMENT:
command_print(cmd_ctx, "offset breaks required alignment");
break;
case ERROR_FLASH_DST_OUT_OF_BANK:
command_print(cmd_ctx, "destination is out of flash bank (offset and/or file too large)");
break;
case ERROR_FLASH_SECTOR_NOT_ERASED:
command_print(cmd_ctx, "destination sector(s) not erased");
break;
default:
command_print(cmd_ctx, "unknown error");
}
} }
free(buffer); free(buffer);
@ -760,8 +823,8 @@ int flash_erase(target_t *target, u32 addr, u32 length)
return c->driver->erase(c, first, last); return c->driver->erase(c, first, last);
} }
/* write an image to flash memory of the given target */ /* perform an operation on flash using an image: verify, erase or write. */
int flash_write(target_t *target, image_t *image, u32 *written, char **error_str, int *failed, int erase) int flash_image_operation(target_t *target, image_t *image, u32 *written, char **error_str, int *failed, enum flash_image_op op)
{ {
int retval; int retval;
int i; int i;
@ -823,7 +886,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
{ {
if (image->sections[section_last + 1].base_address < (run_address + run_size)) if (image->sections[section_last + 1].base_address < (run_address + run_size))
{ {
WARNING("section %d out of order", section_last + 1); DEBUG("section %d out of order(very slightly surprising, but supported)", section_last + 1);
break; break;
} }
if (image->sections[section_last + 1].base_address != (run_address + run_size)) if (image->sections[section_last + 1].base_address != (run_address + run_size))
@ -880,16 +943,57 @@ int flash_write(target_t *target, image_t *image, u32 *written, char **error_str
retval = ERROR_OK; retval = ERROR_OK;
if (erase) switch (op)
{ {
case flash_image_op_erase:
/* calculate and erase sectors */ /* calculate and erase sectors */
retval = flash_erase( target, run_address, run_size ); retval = flash_erase( target, run_address, run_size );
break;
case flash_image_op_write:
/* write flash sectors */
retval = c->driver->write(c, buffer, run_address - c->base, run_size);
break;
case flash_image_op_verify:
{
// Verify
u8 *data;
data=(u8 *)malloc(run_size);
if (data==NULL)
retval = ERROR_INVALID_ARGUMENTS; // exception handling would be nice...
// Can we use long word accesses?
int size=1;
int count=run_size;
if ((count%4)==0)
{
size*=4;
count/=4;
} }
retval = target->type->read_memory(target, run_address, size, count, data);
if (retval == ERROR_OK) if (retval == ERROR_OK)
{ {
/* write flash sectors */ int i;
retval = c->driver->write(c, buffer, run_address - c->base, run_size); for (i=0; i<run_size; i++)
{
if (data[i]!=buffer[i])
{
ERROR("Verify operation failed address 0x%08x. Was %02x instead of %02x\n", i+run_address, data[i], buffer[i]);
retval=ERROR_FLASH_OPERATION_FAILED;
break;
}
}
}
free(data);
break;
}
default:
// can't happen
exit(-1);
} }
free(buffer); free(buffer);
@ -951,3 +1055,4 @@ int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd
} }

View File

@ -63,11 +63,18 @@ typedef struct flash_bank_s
struct flash_bank_s *next; struct flash_bank_s *next;
} flash_bank_t; } flash_bank_t;
enum flash_image_op
{
flash_image_op_write = 0,
flash_image_op_verify,
flash_image_op_erase
};
extern int flash_register_commands(struct command_context_s *cmd_ctx); extern int flash_register_commands(struct command_context_s *cmd_ctx);
extern int flash_init(struct command_context_s *cmd_ctx); extern int flash_init(struct command_context_s *cmd_ctx);
extern int flash_erase(target_t *target, u32 addr, u32 length); extern int flash_erase(target_t *target, u32 addr, u32 length);
extern int flash_write(target_t *target, image_t *image, u32 *written, char **error, int *failed, int erase); extern int flash_image_operation(target_t *target, image_t *image, u32 *written, char **error_str, int *failed, enum flash_image_op op);
extern flash_bank_t *get_flash_bank_by_num(int num); extern flash_bank_t *get_flash_bank_by_num(int num);
extern flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr); extern flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr);

View File

@ -506,6 +506,7 @@ command_context_t* copy_command_context(command_context_t* context)
int command_done(command_context_t *context) int command_done(command_context_t *context)
{ {
free(context); free(context);
context = NULL;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -44,8 +44,6 @@ int fileio_open_local(fileio_t *fileio)
fileio_local_t *fileio_local = malloc(sizeof(fileio_local_t)); fileio_local_t *fileio_local = malloc(sizeof(fileio_local_t));
char access[4]; char access[4];
fileio->location_private = fileio_local;
if ((fileio->access != FILEIO_WRITE) && (fileio->access != FILEIO_READWRITE)) if ((fileio->access != FILEIO_WRITE) && (fileio->access != FILEIO_READWRITE))
{ {
if (stat(fileio->url, &fileio_local->file_stat) == -1) if (stat(fileio->url, &fileio_local->file_stat) == -1)
@ -113,6 +111,8 @@ int fileio_open_local(fileio_t *fileio)
return ERROR_FILEIO_OPERATION_FAILED; return ERROR_FILEIO_OPERATION_FAILED;
} }
fileio->location_private = fileio_local;
if ((fileio->access != FILEIO_WRITE) || (fileio->access == FILEIO_READWRITE)) if ((fileio->access != FILEIO_WRITE) || (fileio->access == FILEIO_READWRITE))
{ {
fileio->size = fileio_local->file_stat.st_size; fileio->size = fileio_local->file_stat.st_size;
@ -172,6 +172,12 @@ int fileio_close_local(fileio_t *fileio)
int retval; int retval;
fileio_local_t *fileio_local = fileio->location_private; fileio_local_t *fileio_local = fileio->location_private;
if (fileio->location_private == NULL)
{
snprintf(fileio->error_str, FILEIO_MAX_ERROR_STRING, "couldn't close %s: ", fileio->url);
return ERROR_FILEIO_OPERATION_FAILED;
}
if ((retval = fclose(fileio_local->file)) != 0) if ((retval = fclose(fileio_local->file)) != 0)
{ {
if (retval == EBADF) if (retval == EBADF)
@ -187,6 +193,7 @@ int fileio_close_local(fileio_t *fileio)
} }
free(fileio->location_private); free(fileio->location_private);
fileio->location_private = NULL;
return ERROR_OK; return ERROR_OK;
} }
@ -209,6 +216,7 @@ int fileio_close(fileio_t *fileio)
return retval; return retval;
free(fileio->url); free(fileio->url);
fileio->url = NULL;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -2051,6 +2051,7 @@ int ft2232_quit(void)
#endif #endif
free(ft2232_buffer); free(ft2232_buffer);
ft2232_buffer = NULL;
return ERROR_OK; return ERROR_OK;
} }
@ -2137,3 +2138,4 @@ int ft2232_handle_latency_command(struct command_context_s *cmd_ctx, char *cmd,
return ERROR_OK; return ERROR_OK;
} }

View File

@ -1345,6 +1345,7 @@ int jtag_validate_chain()
char *cbuf = buf_to_str(ir_test, total_ir_length, 16); char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf); ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
free(cbuf); free(cbuf);
free(ir_test);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
chain_pos += device->ir_length; chain_pos += device->ir_length;
@ -1356,6 +1357,7 @@ int jtag_validate_chain()
char *cbuf = buf_to_str(ir_test, total_ir_length, 16); char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf); ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
free(cbuf); free(cbuf);
free(ir_test);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }

View File

@ -120,8 +120,9 @@ cable_t cables[] =
}; };
/* configuration */ /* configuration */
char* parport_cable; char* parport_cable = NULL;
unsigned long parport_port; unsigned long parport_port;
static int parport_exit = 0;
/* interface variables /* interface variables
*/ */
@ -150,6 +151,7 @@ int parport_quit(void);
/* interface commands */ /* interface commands */
int parport_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int parport_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int parport_handle_parport_cable_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int parport_handle_parport_cable_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
int parport_handle_write_on_exit_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
jtag_interface_t parport_interface = jtag_interface_t parport_interface =
{ {
@ -249,7 +251,6 @@ void parport_reset(int trst, int srst)
/* turn LED on parport adapter on (1) or off (0) */ /* turn LED on parport adapter on (1) or off (0) */
void parport_led(int on) void parport_led(int on)
{ {
u8 output;
if (on) if (on)
dataport_value |= cable->LED_MASK; dataport_value |= cable->LED_MASK;
else else
@ -271,6 +272,8 @@ int parport_register_commands(struct command_context_s *cmd_ctx)
COMMAND_CONFIG, NULL); COMMAND_CONFIG, NULL);
register_command(cmd_ctx, NULL, "parport_cable", parport_handle_parport_cable_command, register_command(cmd_ctx, NULL, "parport_cable", parport_handle_parport_cable_command,
COMMAND_CONFIG, NULL); COMMAND_CONFIG, NULL);
register_command(cmd_ctx, NULL, "parport_write_on_exit", parport_handle_write_on_exit_command,
COMMAND_CONFIG, NULL);
return ERROR_OK; return ERROR_OK;
} }
@ -429,11 +432,20 @@ int parport_init(void)
int parport_quit(void) int parport_quit(void)
{ {
u8 output;
parport_led(0); parport_led(0);
if (parport_exit)
{
dataport_value = cable->PORT_EXIT; dataport_value = cable->PORT_EXIT;
parport_write_data(); parport_write_data();
}
if (parport_cable)
{
free(parport_cable);
parport_cable = NULL;
}
return ERROR_OK; return ERROR_OK;
} }
@ -463,3 +475,19 @@ int parport_handle_parport_cable_command(struct command_context_s *cmd_ctx, char
return ERROR_OK; return ERROR_OK;
} }
int parport_handle_write_on_exit_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
if (argc != 1)
{
command_print(cmd_ctx, "usage: parport_write_on_exit <on|off>");
return ERROR_OK;
}
if (strcmp(args[0], "on") == 0)
parport_exit = 1;
else if (strcmp(args[0], "off") == 0)
parport_exit = 0;
return ERROR_OK;
}

View File

@ -447,9 +447,14 @@ int gdb_connection_closed(connection_t *connection)
delete_debug_msg_receiver(connection->cmd_ctx, gdb_service->target); delete_debug_msg_receiver(connection->cmd_ctx, gdb_service->target);
if (connection->priv) if (connection->priv)
{
free(connection->priv); free(connection->priv);
connection->priv = NULL;
}
else else
{
ERROR("BUG: connection->priv == NULL"); ERROR("BUG: connection->priv == NULL");
}
target_unregister_event_callback(gdb_target_callback_event_handler, connection); target_unregister_event_callback(gdb_target_callback_event_handler, connection);
@ -1325,7 +1330,7 @@ int gdb_v_packet(connection_t *connection, target_t *target, char *packet, int p
char *error_str; char *error_str;
/* process the flashing buffer */ /* process the flashing buffer */
if ((result = flash_write(gdb_service->target, gdb_connection->vflash_image, &written, &error_str, NULL, 0)) != ERROR_OK) if ((result = flash_image_operation(gdb_service->target, gdb_connection->vflash_image, &written, &error_str, NULL, flash_image_op_write)) != ERROR_OK)
{ {
if (result == ERROR_FLASH_DST_OUT_OF_BANK) if (result == ERROR_FLASH_DST_OUT_OF_BANK)
gdb_put_packet(connection, "E.memtype", 9); gdb_put_packet(connection, "E.memtype", 9);

View File

@ -230,6 +230,8 @@ int remove_services()
c = next; c = next;
} }
services = NULL;
return ERROR_OK; return ERROR_OK;
} }
@ -454,3 +456,4 @@ int handle_shutdown_command(struct command_context_s *cmd_ctx, char *cmd, char *
return ERROR_COMMAND_CLOSE_CONNECTION; return ERROR_COMMAND_CLOSE_CONNECTION;
} }

View File

@ -506,21 +506,32 @@ int telnet_connection_closed(connection_t *connection)
int i; int i;
if (t_con->prompt) if (t_con->prompt)
{
free(t_con->prompt); free(t_con->prompt);
t_con->prompt = NULL;
}
for (i = 0; i < TELNET_LINE_HISTORY_SIZE; i++) for (i = 0; i < TELNET_LINE_HISTORY_SIZE; i++)
{ {
if (t_con->history[i]) if (t_con->history[i])
{
free(t_con->history[i]); free(t_con->history[i]);
t_con->history[i] = NULL;
}
} }
/* if this connection registered a debug-message receiver delete it */ /* if this connection registered a debug-message receiver delete it */
delete_debug_msg_receiver(connection->cmd_ctx, NULL); delete_debug_msg_receiver(connection->cmd_ctx, NULL);
if (connection->priv) if (connection->priv)
{
free(connection->priv); free(connection->priv);
connection->priv = NULL;
}
else else
{
ERROR("BUG: connection->priv == NULL"); ERROR("BUG: connection->priv == NULL");
}
target_unregister_event_callback(telnet_target_callback_event_handler, connection->cmd_ctx); target_unregister_event_callback(telnet_target_callback_event_handler, connection->cmd_ctx);

View File

@ -41,6 +41,7 @@ void init_mem_param(mem_param_t *param, u32 address, u32 size, enum param_direct
void destroy_mem_param(mem_param_t *param) void destroy_mem_param(mem_param_t *param)
{ {
free(param->value); free(param->value);
param->value = NULL;
} }
void init_reg_param(reg_param_t *param, char *reg_name, u32 size, enum param_direction direction) void init_reg_param(reg_param_t *param, char *reg_name, u32 size, enum param_direction direction)
@ -54,4 +55,5 @@ void init_reg_param(reg_param_t *param, char *reg_name, u32 size, enum param_dir
void destroy_reg_param(reg_param_t *param) void destroy_reg_param(reg_param_t *param)
{ {
free(param->value); free(param->value);
param->value = NULL;
} }

View File

@ -1200,6 +1200,7 @@ int handle_etm_tracemode_command(struct command_context_s *cmd_ctx, char *cmd, c
if (arm7_9->etm_ctx->trace_depth > 0) if (arm7_9->etm_ctx->trace_depth > 0)
{ {
free(arm7_9->etm_ctx->trace_data); free(arm7_9->etm_ctx->trace_data);
arm7_9->etm_ctx->trace_data = NULL;
} }
arm7_9->etm_ctx->trace_depth = 0; arm7_9->etm_ctx->trace_depth = 0;
} }
@ -1725,6 +1726,7 @@ int handle_etm_start_command(struct command_context_s *cmd_ctx, char *cmd, char
if (arm7_9->etm_ctx->trace_depth > 0) if (arm7_9->etm_ctx->trace_depth > 0)
{ {
free(arm7_9->etm_ctx->trace_data); free(arm7_9->etm_ctx->trace_data);
arm7_9->etm_ctx->trace_data = NULL;
} }
arm7_9->etm_ctx->trace_depth = 0; arm7_9->etm_ctx->trace_depth = 0;

View File

@ -821,6 +821,7 @@ int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *bu
IMAGE_MEMORY_CACHE_SIZE, image_memory->cache) != ERROR_OK) IMAGE_MEMORY_CACHE_SIZE, image_memory->cache) != ERROR_OK)
{ {
free(image_memory->cache); free(image_memory->cache);
image_memory->cache = NULL;
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE; return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
} }
image_memory->cache_address = address & ~(IMAGE_MEMORY_CACHE_SIZE - 1); image_memory->cache_address = address & ~(IMAGE_MEMORY_CACHE_SIZE - 1);
@ -909,7 +910,10 @@ int image_close(image_t *image)
fileio_close(&image_ihex->fileio); fileio_close(&image_ihex->fileio);
if (image_ihex->buffer) if (image_ihex->buffer)
{
free(image_ihex->buffer); free(image_ihex->buffer);
image_ihex->buffer = NULL;
}
} }
else if (image->type == IMAGE_ELF) else if (image->type == IMAGE_ELF)
{ {
@ -918,17 +922,26 @@ int image_close(image_t *image)
fileio_close(&image_elf->fileio); fileio_close(&image_elf->fileio);
if (image_elf->header) if (image_elf->header)
{
free(image_elf->header); free(image_elf->header);
image_elf->header = NULL;
}
if (image_elf->segments) if (image_elf->segments)
{
free(image_elf->segments); free(image_elf->segments);
image_elf->segments = NULL;
}
} }
else if (image->type == IMAGE_MEMORY) else if (image->type == IMAGE_MEMORY)
{ {
image_memory_t *image_memory = image->type_private; image_memory_t *image_memory = image->type_private;
if (image_memory->cache) if (image_memory->cache)
{
free(image_memory->cache); free(image_memory->cache);
image_memory->cache = NULL;
}
} }
else if (image->type == IMAGE_SRECORD) else if (image->type == IMAGE_SRECORD)
{ {
@ -937,7 +950,10 @@ int image_close(image_t *image)
fileio_close(&image_mot->fileio); fileio_close(&image_mot->fileio);
if (image_mot->buffer) if (image_mot->buffer)
{
free(image_mot->buffer); free(image_mot->buffer);
image_mot->buffer = NULL;
}
} }
else if (image->type == IMAGE_BUILDER) else if (image->type == IMAGE_BUILDER)
{ {
@ -946,14 +962,21 @@ int image_close(image_t *image)
for (i = 0; i < image->num_sections; i++) for (i = 0; i < image->num_sections; i++)
{ {
free(image->sections[i].private); free(image->sections[i].private);
image->sections[i].private = NULL;
} }
} }
if (image->type_private) if (image->type_private)
{
free(image->type_private); free(image->type_private);
image->type_private = NULL;
}
if (image->sections) if (image->sections)
{
free(image->sections); free(image->sections);
image->sections = NULL;
}
return ERROR_OK; return ERROR_OK;
} }
@ -988,3 +1011,4 @@ int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum)
return ERROR_OK; return ERROR_OK;
} }

View File

@ -76,7 +76,7 @@ int handle_trace_point_command(struct command_context_s *cmd_ctx, char *cmd, cha
{ {
if (trace->trace_points) if (trace->trace_points)
free(trace->trace_points); free(trace->trace_points);
trace->num_trace_points = 0; trace->num_trace_points = NULL;
trace->trace_points_size = 0; trace->trace_points_size = 0;
return ERROR_OK; return ERROR_OK;