target.c 128 KB
Newer Older
5001
			{
zwelch's avatar
zwelch committed
5002
				length -= (image.sections[i].base_address + buf_cnt)-max_address;
5003
5004
			}

zwelch's avatar
zwelch committed
5005
			fastload[i].address = image.sections[i].base_address + offset;
zwelch's avatar
zwelch committed
5006
			fastload[i].data = malloc(length);
zwelch's avatar
zwelch committed
5007
			if (fastload[i].data == NULL)
5008
5009
5010
5011
			{
				free(buffer);
				break;
			}
zwelch's avatar
zwelch committed
5012
			memcpy(fastload[i].data, buffer + offset, length);
zwelch's avatar
zwelch committed
5013
			fastload[i].length = length;
5014
5015

			image_size += length;
5016
			command_print(CMD_CTX, "%u bytes written at address 0x%8.8x",
5017
						  (unsigned int)length,
zwelch's avatar
zwelch committed
5018
						  ((unsigned int)(image.sections[i].base_address + offset)));
5019
5020
5021
5022
5023
		}

		free(buffer);
	}

Zachary T Welch's avatar
Zachary T Welch committed
5024
	if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
5025
	{
5026
		command_print(CMD_CTX, "Loaded %" PRIu32 " bytes "
5027
				"in %fs (%0.3f KiB/s)", image_size,
Zachary T Welch's avatar
Zachary T Welch committed
5028
5029
				duration_elapsed(&bench), duration_kbps(&bench, image_size));

5030
		command_print(CMD_CTX,
Zachary T Welch's avatar
Zachary T Welch committed
5031
5032
				"WARNING: image has not been loaded to target!"
				"You can issue a 'fast_load' to finish loading.");
5033
5034
5035
5036
	}

	image_close(&image);

zwelch's avatar
zwelch committed
5037
	if (retval != ERROR_OK)
5038
5039
5040
5041
5042
5043
5044
	{
		free_fastload();
	}

	return retval;
}

5045
COMMAND_HANDLER(handle_fast_load_command)
5046
{
5047
	if (CMD_ARGC > 0)
5048
		return ERROR_COMMAND_SYNTAX_ERROR;
zwelch's avatar
zwelch committed
5049
	if (fastload == NULL)
5050
5051
5052
5053
5054
	{
		LOG_ERROR("No image in memory");
		return ERROR_FAIL;
	}
	int i;
zwelch's avatar
zwelch committed
5055
5056
5057
	int ms = timeval_ms();
	int size = 0;
	int retval = ERROR_OK;
zwelch's avatar
zwelch committed
5058
	for (i = 0; i < fastload_num;i++)
5059
	{
5060
5061
		struct target *target = get_current_target(CMD_CTX);
		command_print(CMD_CTX, "Write to 0x%08x, length 0x%08x",
5062
					  (unsigned int)(fastload[i].address),
duane's avatar
duane committed
5063
					  (unsigned int)(fastload[i].length));
zwelch's avatar
zwelch committed
5064
		if (retval == ERROR_OK)
5065
		{
oharboe's avatar
oharboe committed
5066
			retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data);
5067
		}
zwelch's avatar
zwelch committed
5068
		size += fastload[i].length;
5069
	}
zwelch's avatar
zwelch committed
5070
	int after = timeval_ms();
5071
	command_print(CMD_CTX, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0));
oharboe's avatar
oharboe committed
5072
	return retval;
5073
}
duane's avatar
duane committed
5074

5075
5076
5077
static const struct command_registration target_command_handlers[] = {
	{
		.name = "targets",
5078
		.handler = handle_targets_command,
5079
		.mode = COMMAND_ANY,
5080
5081
5082
		.help = "change current default target (one parameter) "
			"or prints table of all targets (no parameters)",
		.usage = "[target]",
5083
	},
5084
5085
5086
5087
	{
		.name = "target",
		.mode = COMMAND_CONFIG,
		.help = "configure target",
5088
5089

		.chain = target_subcommand_handlers,
5090
	},
5091
5092
5093
	COMMAND_REGISTRATION_DONE
};

5094
int target_register_commands(struct command_context *cmd_ctx)
5095
{
5096
	return register_commands(cmd_ctx, NULL, target_command_handlers);
5097
5098
}

Øyvind Harboe's avatar
Øyvind Harboe committed
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
static bool target_reset_nag = true;

bool get_target_reset_nag(void)
{
	return target_reset_nag;
}

COMMAND_HANDLER(handle_target_reset_nag)
{
	return CALL_COMMAND_HANDLER(handle_command_parse_bool,
			&target_reset_nag, "Nag after each reset about options to improve "
			"performance");
}

5113
5114
5115
static const struct command_registration target_exec_command_handlers[] = {
	{
		.name = "fast_load_image",
5116
		.handler = handle_fast_load_image_command,
5117
		.mode = COMMAND_ANY,
5118
5119
5120
5121
		.help = "Load image into server memory for later use by "
			"fast_load; primarily for profiling",
		.usage = "filename address ['bin'|'ihex'|'elf'|'s19'] "
			"[min_address [max_length]]",
5122
5123
5124
	},
	{
		.name = "fast_load",
5125
		.handler = handle_fast_load_command,
5126
		.mode = COMMAND_EXEC,
5127
5128
5129
5130
5131
		.help = "loads active fast load image to current target "
			"- mainly for profiling purposes",
	},
	{
		.name = "profile",
5132
		.handler = handle_profile_command,
5133
5134
5135
5136
5137
5138
		.mode = COMMAND_EXEC,
		.help = "profiling samples the CPU PC",
	},
	/** @todo don't register virt2phys() unless target supports it */
	{
		.name = "virt2phys",
5139
		.handler = handle_virt2phys_command,
5140
5141
		.mode = COMMAND_ANY,
		.help = "translate a virtual address into a physical address",
David Brownell's avatar
David Brownell committed
5142
		.usage = "virtual_address",
5143
5144
5145
	},
	{
		.name = "reg",
5146
		.handler = handle_reg_command,
5147
		.mode = COMMAND_EXEC,
5148
5149
5150
		.help = "display or set a register; with no arguments, "
			"displays all registers and their values",
		.usage = "[(register_name|register_number) [value]]",
5151
5152
5153
	},
	{
		.name = "poll",
5154
		.handler = handle_poll_command,
5155
		.mode = COMMAND_EXEC,
5156
5157
		.help = "poll target state; or reconfigure background polling",
		.usage = "['on'|'off']",
5158
5159
5160
	},
	{
		.name = "wait_halt",
5161
		.handler = handle_wait_halt_command,
5162
		.mode = COMMAND_EXEC,
5163
5164
5165
		.help = "wait up to the specified number of milliseconds "
			"(default 5) for a previously requested halt",
		.usage = "[milliseconds]",
5166
5167
5168
	},
	{
		.name = "halt",
5169
		.handler = handle_halt_command,
5170
		.mode = COMMAND_EXEC,
5171
5172
5173
		.help = "request target to halt, then wait up to the specified"
			"number of milliseconds (default 5) for it to complete",
		.usage = "[milliseconds]",
5174
5175
5176
	},
	{
		.name = "resume",
5177
		.handler = handle_resume_command,
5178
		.mode = COMMAND_EXEC,
5179
5180
		.help =	"resume target execution from current PC or address",
		.usage = "[address]",
5181
5182
5183
	},
	{
		.name = "reset",
5184
		.handler = handle_reset_command,
5185
5186
5187
5188
5189
5190
5191
		.mode = COMMAND_EXEC,
		.usage = "[run|halt|init]",
		.help = "Reset all targets into the specified mode."
			"Default reset mode is run, if not given.",
	},
	{
		.name = "soft_reset_halt",
5192
		.handler = handle_soft_reset_halt_command,
5193
5194
5195
5196
5197
		.mode = COMMAND_EXEC,
		.help = "halt the target and do a soft reset",
	},
	{
		.name = "step",
5198
		.handler = handle_step_command,
5199
		.mode = COMMAND_EXEC,
5200
5201
		.help =	"step one instruction from current PC or address",
		.usage = "[address]",
5202
5203
5204
	},
	{
		.name = "mdw",
5205
		.handler = handle_md_command,
5206
5207
		.mode = COMMAND_EXEC,
		.help = "display memory words",
5208
		.usage = "['phys'] address [count]",
5209
5210
5211
	},
	{
		.name = "mdh",
5212
		.handler = handle_md_command,
5213
5214
		.mode = COMMAND_EXEC,
		.help = "display memory half-words",
5215
		.usage = "['phys'] address [count]",
5216
5217
5218
	},
	{
		.name = "mdb",
5219
		.handler = handle_md_command,
5220
5221
		.mode = COMMAND_EXEC,
		.help = "display memory bytes",
5222
		.usage = "['phys'] address [count]",
5223
5224
5225
	},
	{
		.name = "mww",
5226
		.handler = handle_mw_command,
5227
5228
		.mode = COMMAND_EXEC,
		.help = "write memory word",
5229
		.usage = "['phys'] address value [count]",
5230
5231
5232
	},
	{
		.name = "mwh",
5233
		.handler = handle_mw_command,
5234
5235
		.mode = COMMAND_EXEC,
		.help = "write memory half-word",
5236
		.usage = "['phys'] address value [count]",
5237
5238
5239
	},
	{
		.name = "mwb",
5240
		.handler = handle_mw_command,
5241
5242
		.mode = COMMAND_EXEC,
		.help = "write memory byte",
5243
		.usage = "['phys'] address value [count]",
5244
5245
5246
	},
	{
		.name = "bp",
5247
		.handler = handle_bp_command,
5248
		.mode = COMMAND_EXEC,
5249
5250
		.help = "list or set hardware or software breakpoint",
		.usage = "[address length ['hw']]",
5251
5252
5253
	},
	{
		.name = "rbp",
5254
		.handler = handle_rbp_command,
5255
5256
		.mode = COMMAND_EXEC,
		.help = "remove breakpoint",
5257
		.usage = "address",
5258
5259
5260
	},
	{
		.name = "wp",
5261
		.handler = handle_wp_command,
5262
		.mode = COMMAND_EXEC,
5263
5264
		.help = "list (no params) or create watchpoints",
		.usage = "[address length [('r'|'w'|'a') value [mask]]]",
5265
5266
5267
	},
	{
		.name = "rwp",
5268
		.handler = handle_rwp_command,
5269
5270
		.mode = COMMAND_EXEC,
		.help = "remove watchpoint",
5271
		.usage = "address",
5272
5273
5274
	},
	{
		.name = "load_image",
5275
		.handler = handle_load_image_command,
5276
		.mode = COMMAND_EXEC,
5277
		.usage = "filename address ['bin'|'ihex'|'elf'|'s19'] "
5278
5279
5280
5281
			"[min_address] [max_length]",
	},
	{
		.name = "dump_image",
5282
		.handler = handle_dump_image_command,
5283
		.mode = COMMAND_EXEC,
5284
		.usage = "filename address size",
5285
5286
5287
	},
	{
		.name = "verify_image",
5288
		.handler = handle_verify_image_command,
5289
		.mode = COMMAND_EXEC,
5290
		.usage = "filename [offset [type]]",
5291
5292
5293
	},
	{
		.name = "test_image",
5294
		.handler = handle_test_image_command,
5295
		.mode = COMMAND_EXEC,
5296
		.usage = "filename [offset [type]]",
5297
	},
5298
	{
5299
		.name = "mem2array",
5300
		.mode = COMMAND_EXEC,
5301
5302
		.jim_handler = jim_mem2array,
		.help = "read 8/16/32 bit memory and return as a TCL array "
5303
			"for script processing",
5304
		.usage = "arrayname bitwidth address count",
5305
5306
	},
	{
5307
		.name = "array2mem",
5308
		.mode = COMMAND_EXEC,
5309
		.jim_handler = jim_array2mem,
5310
		.help = "convert a TCL array to memory locations "
5311
5312
			"and write the 8/16/32 bit values",
		.usage = "arrayname bitwidth address count",
5313
	},
Øyvind Harboe's avatar
Øyvind Harboe committed
5314
5315
5316
5317
5318
5319
5320
5321
	{
		.name = "reset_nag",
		.handler = handle_target_reset_nag,
		.mode = COMMAND_ANY,
		.help = "Nag after each reset about options that could have been "
				"enabled to improve performance. ",
		.usage = "['enable'|'disable']",
	},
5322
5323
	COMMAND_REGISTRATION_DONE
};
5324
static int target_register_user_commands(struct command_context *cmd_ctx)
5325
5326
5327
5328
5329
5330
5331
5332
5333
{
	int retval = ERROR_OK;
	if ((retval = target_request_register_commands(cmd_ctx)) != ERROR_OK)
		return retval;

	if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
		return retval;


5334
	return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
5335
}
For faster browsing, not all history is shown. View entire blame