banner
ekko

ekko's blog

时间不在于你拥有多少,而在于你怎样使用
github
xbox
email

openocd Jim-Tcl command registration and invocation

This article mainly explains how the commands of [[openocd]] are registered and executed, with reference to the document About Jim-TCL (OpenOCD User Guide). This article takes target names as an example and mainly discusses two parts: one part is registration, which associates command parameters with corresponding handling functions, and the other part is invocation, which describes the specific execution process when executing target names.

Registration#

Command Registration#

Command registration is done in a struct manner. The following section registers the target names command and the final calling function handle_target_names:

static const struct command_registration target_command_handlers[] = {
    ......
    {
        .name = "target",
        .mode = COMMAND_CONFIG,
        .help = "configure target",
        .chain = target_subcommand_handlers,
        .usage = "",
    },
    COMMAND_REGISTRATION_DONE
};
static const struct command_registration target_subcommand_handlers[] = {
    ......
    {
		.name = "names",
		.mode = COMMAND_ANY,
		.handler = handle_target_names,
		.help = "Returns the names of all targets as a list of strings",
		.usage = "",
	},
    ......
    COMMAND_REGISTRATION_DONE
};
int target_register_commands(struct command_context *cmd_ctx)
{
	return register_commands(cmd_ctx, NULL, target_command_handlers);
}

The .mode parameter indicates the phase in which the command can run:

/**
 * OpenOCD command mode is COMMAND_CONFIG at start, then switches to COMMAND_EXEC
 * during the execution of command 'init'.
 * The field 'mode' in struct command_registration specifies in which command mode
 * the command can be executed:
 * - during COMMAND_CONFIG only,
 * - during COMMAND_EXEC only,
 * - in both modes (COMMAND_ANY).
 */
enum command_mode {
	COMMAND_EXEC,
	COMMAND_CONFIG,
	COMMAND_ANY,
	COMMAND_UNKNOWN = -1, /* error condition */
};

After the init command, openocd enters the running phase. The target init command can only run in the configuration phase, and running it at this time will result in an error:

> target init
command - target init
The 'target init' command must be used before 'init'.

Refer to Server Configuration (OpenOCD User’s Guide).

In the final calling function handle_target_names, print information is added for subsequent verification:

COMMAND_HANDLER(handle_target_names)
{
	if (CMD_ARGC != 0)
		return ERROR_COMMAND_SYNTAX_ERROR;

	LOG_INFO("handle_target_names");
	struct target *target = all_targets;
	while (target) {
		command_print(CMD, "%s", target_name(target));
		target = target->next;
	}

	return ERROR_OK;
}

Execution Registration#

The actual execution of the registration process occurs during the startup of openocd. Below is the main function of openocd, where setup_command_handler performs the execution registration function:

int openocd_main(int argc, char *argv[])
{
	int ret;

	/* initialize commandline interface */
	struct command_context *cmd_ctx;

	cmd_ctx = setup_command_handler(NULL);
	......
}


static struct command_context *setup_command_handler(Jim_Interp *interp)
{
	log_init();
	LOG_INFO("log_init: complete");

	struct command_context *cmd_ctx = command_init(openocd_startup_tcl, interp);

	/* register subsystem commands */
	typedef int (*command_registrant_t)(struct command_context *cmd_ctx_value);
	static const command_registrant_t command_registrants[] = {
		&openocd_register_commands,
		&server_register_commands,
		&gdb_register_commands,
		&log_register_commands,
		&rtt_server_register_commands,
		&transport_register_commands,
		&adapter_register_commands,
		&target_register_commands,
		&flash_register_commands,
		&nand_register_commands,
		&pld_register_commands,
		&cti_register_commands,
		&dap_register_commands,
		&arm_tpiu_swo_register_commands,
		NULL
	};
	for (unsigned i = 0; command_registrants[i]; i++) {
		int retval = (*command_registrants[i])(cmd_ctx);
		if (retval != ERROR_OK) {
			command_done(cmd_ctx);
			return NULL;
		}
	}
	LOG_INFO("command registration: complete");

	LOG_OUTPUT(OPENOCD_VERSION "\n"
		"Licensed under GNU GPL v2\n");

	global_cmd_ctx = cmd_ctx;

	return cmd_ctx;
}

You will find that target_register_commands is the registration function that appeared in the previous command registration section. The registration process is the function mentioned above, and after registration is complete, it will print LOG_INFO("command registration: complete");.

The specific registration content is in the underlying target_register_commands function:

static struct command *register_command(struct command_context *context,
	const char *cmd_prefix, const struct command_registration *cr)
{
	char *full_name;

	if (!context || !cr->name)
		return NULL;

	if (cmd_prefix)
		full_name = alloc_printf("%s %s", cmd_prefix, cr->name);
	else
		full_name = strdup(cr->name);
	if (!full_name)
		return NULL;

	struct command *c = command_find_from_name(context->interp, full_name);
	if (c) {
		/* TODO: originally we treated attempting to register a cmd twice as an error
		 * Sometimes we need this behaviour, such as with flash banks.
		 * http://www.mail-archive.com/openocd-development@lists.berlios.de/msg11152.html */
		LOG_DEBUG("command '%s' is already registered", full_name);
		free(full_name);
		return c;
	}

	c = command_new(context, full_name, cr);
	if (!c) {
		free(full_name);
		return NULL;
	}

	// if (false) /* too noisy with debug_level 3 */
		LOG_INFO("registering '%s'...", full_name);
	int retval = Jim_CreateCommand(context->interp, full_name,
				jim_command_dispatch, c, command_free);
	if (retval != JIM_OK) {
		command_run_linef(context, "del_help_text {%s}", full_name);
		command_run_linef(context, "del_usage_text {%s}", full_name);
		free(c);
		free(full_name);
		return NULL;
	}

	free(full_name);
	return c;
}

The registration process will print LOG_INFO("registering '%s'...", full_name); with the specific registered command value, and associates it with the function pointer jim_command_dispatch, which will be executed when the command is actually invoked.

Initialization Registration Log#

The following are the relevant print information during the registration process:

$ openocd -f interface/jlink.cfg -f target/rk3568.cfg                                             [16:04:06]
Info : log_init: complete
Info : registering 'ocd_find'...
Info : registering 'capture'...
Info : registering 'echo'...
Info : registering 'add_help_text'...
Info : registering 'add_usage_text'...
Info : registering 'sleep'...
Info : registering 'help'...
Info : registering 'usage'...
Info : registering 'command'...
Info : registering 'command mode'...
Info : registering 'version'...
Info : registering 'noinit'...
Info : registering 'init'...
Info : registering 'add_script_search_dir'...
Info : registering 'exit'...
Info : registering 'telnet_port'...
Info : registering 'tcl_port'...
Info : registering 'tcl_notifications'...
Info : registering 'tcl_trace'...
Info : registering 'jsp_port'...
Info : registering 'shutdown'...
Info : registering 'poll_period'...
Info : registering 'bindto'...
Info : registering 'gdb_sync'...
Info : registering 'gdb_port'...
Info : registering 'gdb_memory_map'...
Info : registering 'gdb_flash_program'...
Info : registering 'gdb_report_data_abort'...
Info : registering 'gdb_report_register_access_error'...
Info : registering 'gdb_breakpoint_override'...
Info : registering 'gdb_target_description'...
Info : registering 'gdb_save_tdesc'...
Info : registering 'log_output'...
Info : registering 'debug_level'...
Info : registering 'rtt'...
Info : registering 'rtt server'...
Info : registering 'rtt server start'...
Info : registering 'rtt server stop'...
Info : registering 'transport'...
Info : registering 'transport init'...
Info : registering 'transport list'...
Info : registering 'transport select'...
Info : registering 'adapter'...
Info : registering 'adapter driver'...
Info : registering 'adapter speed'...
Info : registering 'adapter serial'...
Info : registering 'adapter list'...
Info : registering 'adapter name'...
Info : registering 'adapter srst'...
Info : registering 'adapter srst delay'...
Info : registering 'adapter srst pulse_width'...
Info : registering 'adapter transports'...
Info : registering 'adapter usb'...
Info : registering 'adapter usb location'...
Info : registering 'adapter assert'...
Info : registering 'adapter deassert'...
Info : registering 'adapter gpio'...
Info : registering 'reset_config'...
Info : target_register_commands
Info : registering 'targets'...
Info : registering 'target'...
Info : registering 'target init'...
Info : registering 'target create'...
Info : registering 'target current'...
Info : registering 'target types'...
Info : registering 'target names'...
Info : registering 'target smp'...
Info : registering 'flash'...
Info : registering 'flash bank'...
Info : registering 'flash init'...
Info : registering 'flash banks'...
Info : registering 'flash list'...
Info : registering 'nand'...
Info : registering 'nand device'...
Info : registering 'nand drivers'...
Info : registering 'nand init'...
Info : registering 'pld'...
Info : registering 'pld create'...
Info : registering 'pld init'...
Info : registering 'cti'...
Info : registering 'cti create'...
Info : registering 'cti names'...
Info : registering 'dap'...
Info : registering 'dap create'...
Info : registering 'dap names'...
Info : registering 'dap init'...
Info : registering 'dap info'...
Info : registering 'tpiu'...
Info : registering 'tpiu create'...
Info : registering 'tpiu names'...
Info : registering 'tpiu init'...
Info : registering 'swo'...
Info : registering 'swo create'...
Info : registering 'swo names'...
Info : registering 'swo init'...
Info : command registration: complete  # Registration complete
Open On-Chip Debugger 0.12.0+dev-01573-gbc9ca5f4a-dirty (2024-05-09-16:04)
Licensed under GNU GPL v2
Info : registering 'ms'...
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html

Invocation#

Invocation Process#

As mentioned earlier during registration, the command is associated with the jim_command_dispatch function:

static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
	/* check subcommands */
	if (argc > 1) {
		char *s = alloc_printf("%s %s", Jim_GetString(argv[0], NULL), Jim_GetString(argv[1], NULL));
		Jim_Obj *js = Jim_NewStringObj(interp, s, -1);
		Jim_IncrRefCount(js);
		free(s);
		Jim_Cmd *cmd = Jim_GetCommand(interp, js, JIM_NONE);
		if (cmd) {
			int retval = Jim_EvalObjPrefix(interp, js, argc - 2, argv + 2);
			Jim_DecrRefCount(interp, js);
			return retval;
		}
		Jim_DecrRefCount(interp, js);
	}

	script_debug(interp, argc, argv);

	struct command *c = jim_to_command(interp);
	if (!c->jim_handler && !c->handler) {
		Jim_EvalObjPrefix(interp, Jim_NewStringObj(interp, "usage", -1), 1, argv);
		return JIM_ERR;
	}

	struct command_context *cmd_ctx = current_command_context(interp);

	if (!command_can_run(cmd_ctx, c, Jim_GetString(argv[0], NULL)))
		return JIM_ERR;

	target_call_timer_callbacks();

	/*
	 * Black magic of overridden current target:
	 * If the command we are going to handle has a target prefix,
	 * override the current target temporarily for the time
	 * of processing the command.
	 * current_target_override is used also for event handlers
	 * therefore we prevent touching it if command has no prefix.
	 * Previous override is saved and restored back to ensure
	 * correct work when jim_command_dispatch() is re-entered.
	 */
	struct target *saved_target_override = cmd_ctx->current_target_override;
	if (c->jim_override_target)
		cmd_ctx->current_target_override = c->jim_override_target;

	LOG_INFO("exec_command begin");
	int retval = exec_command(interp, cmd_ctx, c, argc, argv);
	LOG_INFO("exec_command finsh");

	if (c->jim_override_target)
		cmd_ctx->current_target_override = saved_target_override;

	return retval;
}

In script_debug(interp, argc, argv);, the current command content will be printed, and the subsequent exec_command is the actual invocation of the function associated with the command, which is the initial handle_target_names function.

Initialization Invocation Log#

During the initialization process, many commands from configuration files are also executed. The following logs only retain the parts related to invocation:

$ openocd -f interface/jlink.cfg -f target/rk3568.cfg                                             [16:04:06]
Info : command - add_usage_text find <file>
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text find print full path to file according to OpenOCD search rules
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text script filename of OpenOCD script (tcl) to run
Info : exec_command begin
Info : exec_command finsh
Info : command - add_usage_text script <file>
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text power_restore Overridable procedure run when power restore is detected. Runs 'reset init' by default.
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text srst_deasserted Overridable procedure run when srst deassert is detected. Runs 'reset init' by default.
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text measure_clk Runs a test to measure the JTAG clk. Useful with RCLK / RTCK.
Info : exec_command begin
Info : exec_command finsh
Info : command - add_help_text program write an image to flash, address is only required for binary images. verify, reset, exit are optional
Info : exec_command begin
Info : exec_command finsh
Info : command - add_usage_text program <filename> [address] [pre-verify] [verify] [reset] [exit]
Info : exec_command begin
Info : exec_command finsh
Open On-Chip Debugger 0.12.0+dev-01573-gbc9ca5f4a-dirty (2024-05-09-16:04)
Licensed under GNU GPL v2
Info : registering 'ms'...
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : command - ocd_find interface/jlink.cfg
Info : exec_command begin
Info : exec_command finsh
Info : command - adapter driver jlink
Info : exec_command begin
Info : registering 'jlink'...
Info : registering 'jlink jtag'...
Info : registering 'jlink targetpower'...
Info : registering 'jlink freemem'...
Info : registering 'jlink hwstatus'...
Info : registering 'jlink usb'...
Info : registering 'jlink config'...
Info : registering 'jlink config usb'...
Info : registering 'jlink config targetpower'...
Info : registering 'jlink config mac'...
Info : registering 'jlink config ip'...
Info : registering 'jlink config reset'...
Info : registering 'jlink config write'...
Info : registering 'jlink emucom'...
Info : registering 'jlink emucom write'...
Info : registering 'jlink emucom read'...
Info : exec_command finsh
Info : command - ocd_find target/rk3568.cfg
Info : exec_command begin
Info : exec_command finsh
Info : command - reset_config trst_and_srst separate
Info : exec_command begin
Info : exec_command finsh
Info : command - adapter driver jlink
Info : exec_command begin
Warn : Interface already configured, ignoring
Info : exec_command finsh
Info : command - adapter speed 12000
Info : exec_command begin
Info : exec_command finsh
Info : command - transport select swd
Info : exec_command begin
Info : registering 'swd'...
Info : registering 'swd newdap'...
Info : exec_command finsh
Info : command - swd newdap rk3568 cpu -expected-id 0x2ba01477 -ignore-version
Info : exec_command begin
Info : exec_command finsh
Info : command - dap create rk3568.dap -chain-position rk3568.cpu
Info : exec_command begin
Info : registering 'rk3568.dap'...
Info : registering 'rk3568.dap info'...
Info : registering 'rk3568.dap apsel'...
Info : registering 'rk3568.dap apcsw'...
Info : registering 'rk3568.dap apid'...
Info : registering 'rk3568.dap apreg'...
Info : registering 'rk3568.dap dpreg'...
Info : registering 'rk3568.dap baseaddr'...
Info : registering 'rk3568.dap memaccess'...
Info : registering 'rk3568.dap ti_be_32_quirks'...
Info : registering 'rk3568.dap nu_npcx_quirks'...
Info : exec_command finsh
Info : command - target create rk3568.ahb mem_ap -dap rk3568.dap -ap-num 0
Info : exec_command begin
Info : registering 'rk3568.ahb'...
Info : registering 'rk3568.ahb configure'...
Info : registering 'rk3568.ahb cget'...
Info : registering 'rk3568.ahb mwd'...
Info : registering 'rk3568.ahb mww'...
Info : registering 'rk3568.ahb mwh'...
Info : registering 'rk3568.ahb mwb'...
Info : registering 'rk3568.ahb mdd'...
Info : registering 'rk3568.ahb mdw'...
Info : registering 'rk3568.ahb mdh'...
Info : registering 'rk3568.ahb mdb'...
Info : registering 'rk3568.ahb get_reg'...
Info : registering 'rk3568.ahb set_reg'...
Info : registering 'rk3568.ahb read_memory'...
Info : registering 'rk3568.ahb write_memory'...
Info : registering 'rk3568.ahb eventlist'...
Info : registering 'rk3568.ahb curstate'...
Info : registering 'rk3568.ahb debug_reason'...
Info : registering 'rk3568.ahb arp_examine'...
Info : registering 'rk3568.ahb was_examined'...
Info : registering 'rk3568.ahb examine_deferred'...
Info : registering 'rk3568.ahb arp_halt_gdb'...
Info : registering 'rk3568.ahb arp_poll'...
Info : registering 'rk3568.ahb arp_reset'...
Info : registering 'rk3568.ahb arp_halt'...
Info : registering 'rk3568.ahb arp_waitstate'...
Info : registering 'rk3568.ahb invoke-event'...
Info : exec_command finsh
Info : command - cti create cti0 -dap rk3568.dap -baseaddr 0x81014000 -ap-num 0
Info : exec_command begin
Info : registering 'cti0'...
Info : registering 'cti0 dump'...
Info : registering 'cti0 enable'...
Info : registering 'cti0 testmode'...
Info : registering 'cti0 write'...
Info : registering 'cti0 read'...
Info : registering 'cti0 ack'...
Info : registering 'cti0 channel'...
Info : exec_command finsh
Info : command - target create rk3568.lcore0 aarch64 -dap rk3568.dap -coreid 0 -cti cti0 -dbgbase 0x81004000
Info : exec_command begin
Info : registering 'arm'...
Info : registering 'arm semihosting'...
Info : registering 'arm semihosting_redirect'...
Info : registering 'arm semihosting_cmdline'...
Info : registering 'arm semihosting_fileio'...
Info : registering 'arm semihosting_resexit'...
Info : registering 'arm semihosting_read_user_param'...
Info : registering 'arm semihosting_basedir'...
Info : registering 'catch_exc'...
Info : registering 'pauth'...
Info : registering 'aarch64'...
Info : registering 'aarch64 cache_info'...
Info : registering 'aarch64 dbginit'...
Info : registering 'aarch64 disassemble'...
Info : registering 'aarch64 maskisr'...
Info : registering 'aarch64 mcr'...
Info : registering 'aarch64 mrc'...
Info : registering 'aarch64 smp'...
Info : registering 'aarch64 smp_gdb'...
Info : registering 'rk3568.lcore0'...
Info : registering 'rk3568.lcore0 configure'...
Info : registering 'rk3568.lcore0 cget'...
Info : registering 'rk3568.lcore0 mwd'...
Info : registering 'rk3568.lcore0 mww'...
Info : registering 'rk3568.lcore0 mwh'...
Info : registering 'rk3568.lcore0 mwb'...
Info : registering 'rk3568.lcore0 mdd'...
Info : registering 'rk3568.lcore0 mdw'...
Info : registering 'rk3568.lcore0 mdh'...
Info : registering 'rk3568.lcore0 mdb'...
Info : registering 'rk3568.lcore0 get_reg'...
Info : registering 'rk3568.lcore0 set_reg'...
Info : registering 'rk3568.lcore0 read_memory'...
Info : registering 'rk3568.lcore0 write_memory'...
Info : registering 'rk3568.lcore0 eventlist'...
Info : registering 'rk3568.lcore0 curstate'...
Info : registering 'rk3568.lcore0 debug_reason'...
Info : registering 'rk3568.lcore0 arp_examine'...
Info : registering 'rk3568.lcore0 was_examined'...
Info : registering 'rk3568.lcore0 examine_deferred'...
Info : registering 'rk3568.lcore0 arp_halt_gdb'...
Info : registering 'rk3568.lcore0 arp_poll'...
Info : registering 'rk3568.lcore0 arp_reset'...
Info : registering 'rk3568.lcore0 arp_halt'...
Info : registering 'rk3568.lcore0 arp_waitstate'...
Info : registering 'rk3568.lcore0 invoke-event'...
Info : exec_command finsh
Info : command - rk3568.lcore0 configure -work-area-size 0x30000 -work-area-phys 0xff8c0000 -work-area-backup 0
Info : exec_command begin
Info : exec_command finsh
Info : command - cti create cti1 -dap rk3568.dap -baseaddr 0x81015000 -ap-num 0
Info : exec_command begin
Info : registering 'cti1'...
Info : registering 'cti1 dump'...
Info : registering 'cti1 enable'...
Info : registering 'cti1 testmode'...
Info : registering 'cti1 write'...
Info : registering 'cti1 read'...
Info : registering 'cti1 ack'...
Info : registering 'cti1 channel'...
Info : exec_command finsh
Info : command - target create rk3568.lcore1 aarch64 -dap rk3568.dap -coreid 1 -cti cti1 -dbgbase 0x81005000
Info : exec_command begin
Info : registering 'rk3568.lcore1'...
Info : registering 'rk3568.lcore1 configure'...
Info : registering 'rk3568.lcore1 cget'...
Info : registering 'rk3568.lcore1 mwd'...
Info : registering 'rk3568.lcore1 mww'...
Info : registering 'rk3568.lcore1 mwh'...
Info : registering 'rk3568.lcore1 mwb'...
Info : registering 'rk3568.lcore1 mdd'...
Info : registering 'rk3568.lcore1 mdw'...
Info : registering 'rk3568.lcore1 mdh'...
Info : registering 'rk3568.lcore1 mdb'...
Info : registering 'rk3568.lcore1 get_reg'...
Info : registering 'rk3568.lcore1 set_reg'...
Info : registering 'rk3568.lcore1 read_memory'...
Info : registering 'rk3568.lcore1 write_memory'...
Info : registering 'rk3568.lcore1 eventlist'...
Info : registering 'rk3568.lcore1 curstate'...
Info : registering 'rk3568.lcore1 debug_reason'...
Info : registering 'rk3568.lcore1 arp_examine'...
Info : registering 'rk3568.lcore1 was_examined'...
Info : registering 'rk3568.lcore1 examine_deferred'...
Info : registering 'rk3568.lcore1 arp_halt_gdb'...
Info : registering 'rk3568.lcore1 arp_poll'...
Info : registering 'rk3568.lcore1 arp_reset'...
Info : registering 'rk3568.lcore1 arp_halt'...
Info : registering 'rk3568.lcore1 arp_waitstate'...
Info : registering 'rk3568.lcore1 invoke-event'...
Info : exec_command finsh
Info : command - target create rk3568.lcore2 aarch64 -dap rk3568.dap -coreid 2 -cti cti2 -dbgbase 0x81006000
Info : exec_command begin
Info : registering 'rk3568.lcore2'...
Info : registering 'rk3568.lcore2 configure'...
Info : registering 'rk3568.lcore2 cget'...
Info : registering 'rk3568.lcore2 mwd'...
Info : registering 'rk3568.lcore2 mww'...
Info : registering 'rk3568.lcore2 mwh'...
Info : registering 'rk3568.lcore2 mwb'...
Info : registering 'rk3568.lcore2 mdd'...
Info : registering 'rk3568.lcore2 mdw'...
Info : registering 'rk3568.lcore2 mdh'...
Info : registering 'rk3568.lcore2 mdb'...
Info : registering 'rk3568.lcore2 get_reg'...
Info : registering 'rk3568.lcore2 set_reg'...
Info : registering 'rk3568.lcore2 read_memory'...
Info : registering 'rk3568.lcore2 write_memory'...
Info : registering 'rk3568.lcore2 eventlist'...
Info : registering 'rk3568.lcore2 curstate'...
Info : registering 'rk3568.lcore2 debug_reason'...
Info : registering 'rk3568.lcore2 arp_examine'...
Info : registering 'rk3568.lcore2 was_examined'...
Info : registering 'rk3568.lcore2 examine_deferred'...
Info : registering 'rk3568.lcore2 arp_halt_gdb'...
Info : registering 'rk3568.lcore2 arp_poll'...
Info : registering 'rk3568.lcore2 arp_reset'...
Info : registering 'rk3568.lcore2 arp_halt'...
Info : registering 'rk3568.lcore2 arp_waitstate'...
Info : registering 'rk3568.lcore2 invoke-event'...
Info : exec_command finsh
Info : command - rk3568.lcore3 aarch64 -dap rk3568.dap -coreid 3 -cti cti3 -dbgbase 0x81007000
Info : exec_command begin
Info : registering 'rk3568.lcore3'...
Info : registering 'rk3568.lcore3 configure'...
Info : registering 'rk3568.lcore3 cget'...
Info : registering 'rk3568.lcore3 mwd'...
Info : registering 'rk3568.lcore3 mww'...
Info : registering 'rk3568.lcore3 mwh'...
Info : registering 'rk3568.lcore3 mwb'...
Info : registering 'rk3568.lcore3 mdd'...
Info : registering 'rk3568.lcore3 mdw'...
Info : registering 'rk3568.lcore3 mdh'...
Info : registering 'rk3568.lcore3 mdb'...
Info : registering 'rk3568.lcore3 get_reg'...
Info : registering 'rk3568.lcore3 set_reg'...
Info : registering 'rk3568.lcore3 read_memory'...
Info : registering 'rk3568.lcore3 write_memory'...
Info : registering 'rk3568.lcore3 eventlist'...
Info : registering 'rk3568.lcore3 curstate'...
Info : registering 'rk3568.lcore3 debug_reason'...
Info : registering 'rk3568.lcore3 arp_examine'...
Info : registering 'rk3568.lcore3 was_examined'...
Info : registering 'rk3568.lcore3 examine_deferred'...
Info : registering 'rk3568.lcore3 arp_halt_gdb'...
Info : registering 'rk3568.lcore3 arp_poll'...
Info : registering 'rk3568.lcore3 arp_reset'...
Info : registering 'rk3568.lcore3 arp_halt'...
Info : registering 'rk3568.lcore3 arp_waitstate'...
Info : registering 'rk3568.lcore3 invoke-event'...
Info : exec_command finsh
Info : command - target smp  rk3568.lcore0 rk3568.lcore1 rk3568.lcore2 rk3568.lcore3
Info : exec_command begin
Error: Invalid command argument
Info : exec_command finsh
Info : command - targets rk3568.lcore0
Info : exec_command begin
Info : exec_command finsh
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : command - init
Info : exec_command begin
Info : command - target init
Info : exec_command begin
Info : command - target names
Info : exec_command begin
Info : handle_target_names
Info : exec_command finsh
Info : command - rk3568.ahb cget -event gdb-flash-erase-start
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.ahb configure -event gdb-flash-erase-start reset init
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.ahb cget -event gdb-flash-write-end
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.ahb configure -event gdb-flash-write-end reset halt
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.ahb cget -event gdb-attach
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.ahb configure -event gdb-attach halt 1000
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 cget -event gdb-flash-erase-start
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 configure -event gdb-flash-erase-start reset init
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 cget -event gdb-flash-write-end
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 configure -event gdb-flash-write-end reset halt
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 cget -event gdb-attach
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore0 configure -event gdb-attach halt 1000
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 cget -event gdb-flash-erase-start
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 configure -event gdb-flash-erase-start reset init
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 cget -event gdb-flash-write-end
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 configure -event gdb-flash-write-end reset halt
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 cget -event gdb-attach
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore1 configure -event gdb-attach halt 1000
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 cget -event gdb-flash-erase-start
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 configure -event gdb-flash-erase-start reset init
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 cget -event gdb-flash-write-end
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 configure -event gdb-flash-write-end reset halt
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 cget -event gdb-attach
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore2 configure -event gdb-attach halt 1000
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 cget -event gdb-flash-erase-start
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 configure -event gdb-flash-erase-start reset init
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 cget -event gdb-flash-write-end
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 configure -event gdb-flash-write-end reset halt
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 cget -event gdb-attach
Info : exec_command begin
Info : exec_command finsh
Info : command - rk3568.lcore3 configure -event gdb-attach halt 1000
Info : exec_command begin
Info : exec_command finsh
Info : registering 'target_request'...
Info : registering 'target_request debugmsgs'...
Info : registering 'trace'...
Info : registering 'trace history'...
Info : registering 'trace point'...
Info : registering 'fast_load_image'...
Info : registering 'fast_load'...
Info : registering 'profile'...
Info : registering 'virt2phys'...
Info : registering 'reg'...
Info : registering 'poll'...
Info : registering 'wait_halt'...
Info : registering 'halt'...
Info : registering 'resume'...
Info : registering 'reset'...
Info : registering 'soft_reset_halt'...
Info : registering 'step'...
Info : registering 'mdd'...
Info : registering 'mdw'...
Info : registering 'mdh'...
Info : registering 'mdb'...
Info : registering 'mwd'...
Info : registering 'mww'...
Info : registering 'mwh'...
Info : registering 'mwb'...
Info : registering 'bp'...
Info : registering 'rbp'...
Info : registering 'wp'...
Info : registering 'rwp'...
Info : registering 'load_image'...
Info : registering 'dump_image'...
Info : registering 'verify_image_checksum'...
Info : registering 'verify_image'...
Info : registering 'test_image'...
Info : registering 'get_reg'...
Info : registering 'set_reg'...
Info : registering 'read_memory'...
Info : registering 'write_memory'...
Info : registering 'debug_reason'...
Info : registering 'reset_nag'...
Info : registering 'ps'...
Info : registering 'test_mem_access'...
Info : exec_command finsh
Info : J-Link V11 compiled Jun 20 2023 17:59:57
Info : Hardware version: 11.00
Info : VTarget = 3.184 V
Info : clock speed 12000 kHz
Info : command - transport init
Info : exec_command begin
Info : exec_command finsh
Info : command - dap init
Info : exec_command begin
Info : SWD DPIDR 0x2ba01477
Info : exec_command finsh
Info : [rk3568.ahb] Examination succeed
Info : rk3568.lcore0: hardware has 6 breakpoints, 4 watchpoints
Info : rk3568.lcore0 cluster 0 core 0 multi core
Info : [rk3568.lcore0] Examination succeed
Info : command - flash init
Info : exec_command begin
Info : exec_command finsh
Info : command - nand init
Info : exec_command begin
Info : exec_command finsh
Info : command - pld init
Info : exec_command begin
Info : exec_command finsh
Info : command - tpiu init
Info : exec_command begin
Info : exec_command finsh
Info : gdb port disabled
Info : starting gdb server for rk3568.lcore0 on 3333
Info : Listening on port 3333 for gdb connections
Info : starting gdb server for rk3568.lcore1 on 3334
Info : Listening on port 3334 for gdb connections
Info : starting gdb server for rk3568.lcore2 on 3335
Info : Listening on port 3335 for gdb connections
Info : starting gdb server for rk3568.lcore3 on 3336
Info : Listening on port 3336 for gdb connections
Info : command - target names
Info : exec_command begin
Info : handle_target_names
Info : exec_command finsh
Info : exec_command finsh

It can be seen that many commands are called during the initialization process, and some command calls also perform command registration operations. At the end of the log, it can be seen that the target names command was executed, and indeed the log information from within the handle_target_names function was printed.

Command Line Invocation Log#

First, the telnet log:

$ telnet localhost 4444                                                                                   [15:40:43]
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> target names
command - target names
exec_command begin
handle_target_names
exec_command finsh
rk3568.ahb
rk3568.lcore0
rk3568.lcore1
rk3568.lcore2
rk3568.lcore3
>

Then the openocd background log:

Info : accepting 'telnet' connection on tcp/4444
Info : command - target names
Info : exec_command begin
Info : handle_target_names
Info : exec_command finsh

It can be seen that the entire invocation process is completely consistent with the initialization invocation.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.