#include "config.h"
#endif
-#include "replacements.h"
#include "target.h"
#include "target_request.h"
-
-#include "log.h"
-#include "configuration.h"
-#include "binarybuffer.h"
+#include "time_support.h"
+#include "register.h"
+#include "trace.h"
+#include "image.h"
#include "jtag.h"
-#include <string.h>
-#include <stdlib.h>
#include <inttypes.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/time.h>
-#include <time.h>
-
-#include <time_support.h>
-
-#include <fileio.h>
-#include <image.h>
static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
static int target_continous_poll = 1;
/* read a u32 from a buffer in target memory endianness */
-u32 target_buffer_get_u32(target_t *target, u8 *buffer)
+u32 target_buffer_get_u32(target_t *target, const u8 *buffer)
{
if (target->endianness == TARGET_LITTLE_ENDIAN)
return le_to_h_u32(buffer);
}
/* read a u16 from a buffer in target memory endianness */
-u16 target_buffer_get_u16(target_t *target, u8 *buffer)
+u16 target_buffer_get_u16(target_t *target, const u8 *buffer)
{
if (target->endianness == TARGET_LITTLE_ENDIAN)
return le_to_h_u16(buffer);
}
/* read a u8 from a buffer in target memory endianness */
-u8 target_buffer_get_u8(target_t *target, u8 *buffer)
+u8 target_buffer_get_u8(target_t *target, const u8 *buffer)
{
return *buffer & 0x0ff;
}
*buffer = value;
}
+/* return a pointer to a configured target; id is name or number */
+target_t *get_target(const char *id)
+{
+ target_t *target;
+ char *endptr;
+ int num;
+
+ /* try as tcltarget name */
+ for (target = all_targets; target; target = target->next) {
+ if (target->cmd_name == NULL)
+ continue;
+ if (strcmp(id, target->cmd_name) == 0)
+ return target;
+ }
+
+ /* no match, try as number */
+ num = strtoul(id, &endptr, 0);
+ if (*endptr != 0)
+ return NULL;
+
+ for (target = all_targets; target; target = target->next) {
+ if (target->target_number == num)
+ return target;
+ }
+
+ return NULL;
+}
+
/* returns a pointer to the n-th configured target */
-target_t* get_target_by_num(int num)
+static target_t *get_target_by_num(int num)
{
target_t *target = all_targets;
return ERROR_FAIL;
}
+ if (size == 0) {
+ return ERROR_OK;
+ }
+
if ((address + size - 1) < address)
{
/* GDB can request this when e.g. PC is 0xfffffffc*/
return ERROR_FAIL;
}
+ if (size == 0) {
+ return ERROR_OK;
+ }
+
if ((address + size - 1) < address)
{
/* GDB can request this when e.g. PC is 0xfffffffc*/
/* script procedures */
register_command(cmd_ctx, NULL, "profile", handle_profile_command, COMMAND_EXEC, "profiling samples the CPU PC");
- register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing");
- register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values");
+ register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
+ register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
register_command(cmd_ctx, NULL, "fast_load_image", handle_fast_load_image_command, COMMAND_ANY,
"same args as load_image, image stored in memory - mainly for profiling purposes");
static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- char *cp;
target_t *target = all_targets;
if (argc == 1)
{
- /* try as tcltarget name */
- for( target = all_targets ; target ; target = target->next ){
- if( target->cmd_name ){
- if( 0 == strcmp( args[0], target->cmd_name ) ){
- /* MATCH */
- goto Match;
- }
- }
- }
- /* no match, try as number */
-
- int num = strtoul(args[0], &cp, 0 );
- if( *cp != 0 ){
- /* then it was not a number */
- command_print( cmd_ctx, "Target: %s unknown, try one of:\n", args[0] );
- goto DumpTargets;
- }
-
- target = get_target_by_num( num );
- if( target == NULL ){
+ target = get_target(args[0]);
+ if (target == NULL) {
command_print(cmd_ctx,"Target: %s is unknown, try one of:\n", args[0] );
goto DumpTargets;
}
- Match:
+
cmd_ctx->current_target = target->target_number;
return ERROR_OK;
}
if ((i%line_modulo == line_modulo-1) || (i == count - 1))
{
- command_print(cmd_ctx, output);
+ command_print(cmd_ctx, "%s", output);
output_len = 0;
}
}
}
for (i=0; i<count; i++)
{
- int retval;
- switch (wordsize)
- {
- case 4:
- retval = target->type->write_memory(target, address + i*wordsize, 4, 1, value_buf);
- break;
- case 2:
- retval = target->type->write_memory(target, address + i*wordsize, 2, 1, value_buf);
- break;
- case 1:
- retval = target->type->write_memory(target, address + i*wordsize, 1, 1, value_buf);
- break;
- default:
- return ERROR_OK;
- }
- keep_alive();
-
- if (retval!=ERROR_OK)
- {
+ int retval = target->type->write_memory(target,
+ address + i * wordsize, wordsize, 1, value_buf);
+ if (ERROR_OK != retval)
return retval;
- }
+ keep_alive();
}
return ERROR_OK;
address = strtoul(args[1], NULL, 0);
size = strtoul(args[2], NULL, 0);
- if ((address & 3) || (size & 3))
- {
- command_print(cmd_ctx, "only 32-bit aligned address and size are supported");
- return ERROR_OK;
- }
-
if (fileio_open(&fileio, args[0], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK)
{
return ERROR_OK;
u32 size_written;
u32 this_run_size = (size > 560) ? 560 : size;
- retval = target->type->read_memory(target, address, 4, this_run_size / 4, buffer);
+ retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
{
break;
if (retval==ERROR_OK)
{
- command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
+ command_print(cmd_ctx, "dumped %lld byte in %s",
+ fileio.size, duration_text);
+ free(duration_text);
}
- free(duration_text);
- return ERROR_OK;
+ return retval;
}
static int handle_verify_image_command_internal(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, int verify)
}
else
{
- command_print(cmd_ctx, "breakpoint added at address 0x%8.8x", strtoul(args[0], NULL, 0));
+ command_print(cmd_ctx, "breakpoint added at address 0x%8.8lx",
+ strtoul(args[0], NULL, 0));
}
}
else
return JIM_ERR;
}
- return target_mem2array(interp, target, argc,argv);
+ return target_mem2array(interp, target, argc-1, argv+1);
}
static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
* argv[3] = memory address
* argv[4] = count of times to read
*/
- if (argc != 5) {
+ if (argc != 4) {
Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems");
return JIM_ERR;
}
- varname = Jim_GetString(argv[1], &len);
+ varname = Jim_GetString(argv[0], &len);
/* given "foo" get space for worse case "foo(%d)" .. add 20 */
- e = Jim_GetLong(interp, argv[2], &l);
+ e = Jim_GetLong(interp, argv[1], &l);
width = l;
if (e != JIM_OK) {
return e;
}
- e = Jim_GetLong(interp, argv[3], &l);
+ e = Jim_GetLong(interp, argv[2], &l);
addr = l;
if (e != JIM_OK) {
return e;
}
- e = Jim_GetLong(interp, argv[4], &l);
+ e = Jim_GetLong(interp, argv[3], &l);
len = l;
if (e != JIM_OK) {
return e;
return JIM_ERR;
}
- return target_array2mem( interp,target, argc, argv );
+ return target_array2mem( interp,target, argc-1, argv+1 );
}
static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
* argv[3] = memory address
* argv[4] = count to write
*/
- if (argc != 5) {
+ if (argc != 4) {
Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems");
return JIM_ERR;
}
- varname = Jim_GetString(argv[1], &len);
+ varname = Jim_GetString(argv[0], &len);
/* given "foo" get space for worse case "foo(%d)" .. add 20 */
- e = Jim_GetLong(interp, argv[2], &l);
+ e = Jim_GetLong(interp, argv[1], &l);
width = l;
if (e != JIM_OK) {
return e;
}
- e = Jim_GetLong(interp, argv[3], &l);
+ e = Jim_GetLong(interp, argv[2], &l);
addr = l;
if (e != JIM_OK) {
return e;
}
- e = Jim_GetLong(interp, argv[4], &l);
+ e = Jim_GetLong(interp, argv[3], &l);
len = l;
if (e != JIM_OK) {
return e;