本文主要说明[[openocd]]的命令是如何注册与执行的,参考文档为关于 Jim-TCL (OpenOCD 用户指南)
本文以target names
为例,主要讲两部分,一部分为注册,讲命令参数与对应的处理函数做关联,另一部分为调用,讲执行target names
时的具体执行流程。
命令注册是以结构体方式进行,如下部分就注册了target names
命令以及最终调用的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);
}
其中.mode
的参数表明该命令可以在什么阶段下运行:
/**
* 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 */
};
在init
命令后openocd进入运行阶段,target init
命令是只有配置阶段才可运行的,此时运行会报错:
> target init
command - target init
The 'target init' command must be used before 'init'.
参考Server Configuration (OpenOCD User’s Guide)
在最终调用的handle_target_names
函数中加上打印信息,后续作为验证内容:
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;
}
真正执行注册过程是在openocd的启动过程中进行的,以下是openocd的main函数,其中的setup_command_handler
就是做的执行注册的功能:
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;
}
会发现其中target_register_commands
就是在之前的命令注册部分出现过的注册函数,注册过程就是上述函数,注册完成后会打印LOG_INFO("command registration: complete");
具体的注册内容在target_register_commands
函数的底层:
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/[email protected]/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;
}
注册过程会打印LOG_INFO("registering '%s'...", full_name);
具体的注册命令值,与函数指针jim_command_dispatch
进行了关联,后续真正执行的时候就是执行该函数。
以下为注册过程中的相关打印信息:
$ 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 #注册完成
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
在前面注册时有提到将命令关联到jim_command_dispatch
函数上:
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;
}
在script_debug(interp, argc, argv);
中会打印当前命令内容,后面的exec_command
就是真正调用命令关联的函数,也就是最开始的handle_target_names
函数。
初始化过程中也会执行很多配置文件中的命令,以下日志只保留了调用相关部分的日志:
$ 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 : registering 'rk3568.lcore0 arm'...
Info : registering 'rk3568.lcore0 arm semihosting'...
Info : registering 'rk3568.lcore0 arm semihosting_redirect'...
Info : registering 'rk3568.lcore0 arm semihosting_cmdline'...
Info : registering 'rk3568.lcore0 arm semihosting_fileio'...
Info : registering 'rk3568.lcore0 arm semihosting_resexit'...
Info : registering 'rk3568.lcore0 arm semihosting_read_user_param'...
Info : registering 'rk3568.lcore0 arm semihosting_basedir'...
Info : registering 'rk3568.lcore0 catch_exc'...
Info : registering 'rk3568.lcore0 pauth'...
Info : registering 'rk3568.lcore0 aarch64'...
Info : registering 'rk3568.lcore0 aarch64 cache_info'...
Info : registering 'rk3568.lcore0 aarch64 dbginit'...
Info : registering 'rk3568.lcore0 aarch64 disassemble'...
Info : registering 'rk3568.lcore0 aarch64 maskisr'...
Info : registering 'rk3568.lcore0 aarch64 mcr'...
Info : registering 'rk3568.lcore0 aarch64 mrc'...
Info : registering 'rk3568.lcore0 aarch64 smp'...
Info : registering 'rk3568.lcore0 aarch64 smp_gdb'...
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 : registering 'rk3568.lcore1 arm'...
Info : registering 'rk3568.lcore1 arm semihosting'...
Info : registering 'rk3568.lcore1 arm semihosting_redirect'...
Info : registering 'rk3568.lcore1 arm semihosting_cmdline'...
Info : registering 'rk3568.lcore1 arm semihosting_fileio'...
Info : registering 'rk3568.lcore1 arm semihosting_resexit'...
Info : registering 'rk3568.lcore1 arm semihosting_read_user_param'...
Info : registering 'rk3568.lcore1 arm semihosting_basedir'...
Info : registering 'rk3568.lcore1 catch_exc'...
Info : registering 'rk3568.lcore1 pauth'...
Info : registering 'rk3568.lcore1 aarch64'...
Info : registering 'rk3568.lcore1 aarch64 cache_info'...
Info : registering 'rk3568.lcore1 aarch64 dbginit'...
Info : registering 'rk3568.lcore1 aarch64 disassemble'...
Info : registering 'rk3568.lcore1 aarch64 maskisr'...
Info : registering 'rk3568.lcore1 aarch64 mcr'...
Info : registering 'rk3568.lcore1 aarch64 mrc'...
Info : registering 'rk3568.lcore1 aarch64 smp'...
Info : registering 'rk3568.lcore1 aarch64 smp_gdb'...
Info : exec_command finsh
Info : command - rk3568.lcore1 configure -defer-examine
Info : exec_command begin
Info : exec_command finsh
Info : command - cti create cti2 -dap rk3568.dap -baseaddr 0x81016000 -ap-num 0
Info : exec_command begin
Info : registering 'cti2'...
Info : registering 'cti2 dump'...
Info : registering 'cti2 enable'...
Info : registering 'cti2 testmode'...
Info : registering 'cti2 write'...
Info : registering 'cti2 read'...
Info : registering 'cti2 ack'...
Info : registering 'cti2 channel'...
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 : registering 'rk3568.lcore2 arm'...
Info : registering 'rk3568.lcore2 arm semihosting'...
Info : registering 'rk3568.lcore2 arm semihosting_redirect'...
Info : registering 'rk3568.lcore2 arm semihosting_cmdline'...
Info : registering 'rk3568.lcore2 arm semihosting_fileio'...
Info : registering 'rk3568.lcore2 arm semihosting_resexit'...
Info : registering 'rk3568.lcore2 arm semihosting_read_user_param'...
Info : registering 'rk3568.lcore2 arm semihosting_basedir'...
Info : registering 'rk3568.lcore2 catch_exc'...
Info : registering 'rk3568.lcore2 pauth'...
Info : registering 'rk3568.lcore2 aarch64'...
Info : registering 'rk3568.lcore2 aarch64 cache_info'...
Info : registering 'rk3568.lcore2 aarch64 dbginit'...
Info : registering 'rk3568.lcore2 aarch64 disassemble'...
Info : registering 'rk3568.lcore2 aarch64 maskisr'...
Info : registering 'rk3568.lcore2 aarch64 mcr'...
Info : registering 'rk3568.lcore2 aarch64 mrc'...
Info : registering 'rk3568.lcore2 aarch64 smp'...
Info : registering 'rk3568.lcore2 aarch64 smp_gdb'...
Info : exec_command finsh
Info : command - rk3568.lcore2 configure -defer-examine
Info : exec_command begin
Info : exec_command finsh
Info : command - cti create cti3 -dap rk3568.dap -baseaddr 0x81017000 -ap-num 0
Info : exec_command begin
Info : registering 'cti3'...
Info : registering 'cti3 dump'...
Info : registering 'cti3 enable'...
Info : registering 'cti3 testmode'...
Info : registering 'cti3 write'...
Info : registering 'cti3 read'...
Info : registering 'cti3 ack'...
Info : registering 'cti3 channel'...
Info : exec_command finsh
Info : command - target create 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 : registering 'rk3568.lcore3 arm'...
Info : registering 'rk3568.lcore3 arm semihosting'...
Info : registering 'rk3568.lcore3 arm semihosting_redirect'...
Info : registering 'rk3568.lcore3 arm semihosting_cmdline'...
Info : registering 'rk3568.lcore3 arm semihosting_fileio'...
Info : registering 'rk3568.lcore3 arm semihosting_resexit'...
Info : registering 'rk3568.lcore3 arm semihosting_read_user_param'...
Info : registering 'rk3568.lcore3 arm semihosting_basedir'...
Info : registering 'rk3568.lcore3 catch_exc'...
Info : registering 'rk3568.lcore3 pauth'...
Info : registering 'rk3568.lcore3 aarch64'...
Info : registering 'rk3568.lcore3 aarch64 cache_info'...
Info : registering 'rk3568.lcore3 aarch64 dbginit'...
Info : registering 'rk3568.lcore3 aarch64 disassemble'...
Info : registering 'rk3568.lcore3 aarch64 maskisr'...
Info : registering 'rk3568.lcore3 aarch64 mcr'...
Info : registering 'rk3568.lcore3 aarch64 mrc'...
Info : registering 'rk3568.lcore3 aarch64 smp'...
Info : registering 'rk3568.lcore3 aarch64 smp_gdb'...
Info : exec_command finsh
Info : command - rk3568.lcore3 configure -defer-examine
Info : exec_command begin
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
可以看到初始化过程调用的命令有很多,有些命令的调用还进行的命令的注册操作,日志最后可以看到执行了target names
命令,并且的确打印了handle_target_names
函数内的日志信息。
首先是telnet日志:
$ 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
>
然后是openocd后台日志:
Info : accepting 'telnet' connection on tcp/4444
Info : command - target names
Info : exec_command begin
Info : handle_target_names
Info : exec_command finsh
可以看到整个调用过程与初始化调用是完全一致的。