From 076802606a46dc2fe03946ab686467593e35a3d8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 4 Mar 2019 17:27:32 +0100 Subject: [PATCH 001/176] helper/startup.tcl: remove proc exit The TCL command exit is already replaced by the OpenOCD command exit in server/telnet_server.c, no need to redefine it in the script. Moreover, the implementation is broken because the proc ocd_throw has been removed in mid 2008 with pre-git-era commit dfbb9f3e89ae in svn rev 849. Remove completely the unused proc exit. Change-Id: I0365d740eccc47631eb459aab77b865b0877c1f7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4986 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/startup.tcl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 2578de930..cda3a8fa3 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -3,13 +3,6 @@ # Embedded into OpenOCD executable # - -# We need to explicitly redirect this to the OpenOCD command -# as Tcl defines the exit proc -proc exit {} { - ocd_throw exit -} - # All commands are registered with an 'ocd_' prefix, while the "real" # command is a wrapper that calls this function. Its primary purpose is # to discard 'handler' command output. From 07da3b3913dcb6b65564f4fe67c2f26032f180c0 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Fri, 16 Nov 2018 00:23:10 +0100 Subject: [PATCH 002/176] flash/nor/core.h: clarify comment flash_sector::is_erased Setting of flash_sector::is_erased in flash erase and mass erase is popular folklore. Make clear it is useless. Change-Id: Ide397eb6d24fc8fa38931e6c8a0693d39668a5d2 Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/4768 Tested-by: jenkins Reviewed-by: Christopher Head --- src/flash/nor/core.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index f6bd0cf1a..a8edb2dc9 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -45,9 +45,12 @@ struct flash_sector { uint32_t size; /** * Indication of erasure status: 0 = not erased, 1 = erased, - * other = unknown. Set by @c flash_driver_s::erase_check. + * other = unknown. Set by @c flash_driver_s::erase_check only. * - * Flag is not used in protection block + * This information must be considered stale immediately. + * Don't set it in flash_driver_s::erase or a device mass_erase + * Don't clear it in flash_driver_s::write + * The flag is not used in a protection block */ int is_erased; /** From 0627e4686aa18159327751361940595e19b0c525 Mon Sep 17 00:00:00 2001 From: Mete Balci Date: Thu, 28 Mar 2019 10:35:30 +0100 Subject: [PATCH 003/176] target/arm_adi_v5: fix typo Fixed the small typo. Change-Id: Ia8834b23302d25e92cb2fa0802bebb2a9416595b Signed-off-by: Mete Balci Reviewed-on: http://openocd.zylin.com/5001 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/arm_adi_v5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 021d02a44..9a641fce2 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1412,7 +1412,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, } break; case 6: - major = "Perfomance Monitor"; + major = "Performance Monitor"; switch (minor) { case 0: subtype = "other"; From 5202d82a954627c6706529a82447aad4c63aefcc Mon Sep 17 00:00:00 2001 From: Peter Lawrence Date: Sun, 20 Jan 2019 15:12:22 -0600 Subject: [PATCH 004/176] tcl_server: fix minor typo in comment ctrl-z usage is incorrectly commented as ctrl-d Change-Id: I54fe1775760ee984154bbae380baa38bcaffa04e Signed-off-by: Peter Lawrence Reviewed-on: http://openocd.zylin.com/4863 Tested-by: jenkins Reviewed-by: Christopher Head Reviewed-by: Tomas Vanek --- src/server/tcl_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 0676c883b..1ec45ffbb 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -246,7 +246,7 @@ static int tcl_input(struct connection *connection) retval = tcl_output(connection, result, reslen); if (retval != ERROR_OK) return retval; - /* Always output ctrl-d as end of line to allow multiline results */ + /* Always output ctrl-z as end of line to allow multiline results */ tcl_output(connection, "\x1a", 1); } From 92c50fda2bbe0061d26a420332ba625bc780cdc4 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 9 Apr 2018 23:00:10 +0300 Subject: [PATCH 005/176] contrib: rpc_examples: python: fix memory retrieval mem2array returns a Tcl (associative) array and so the order of elements is not guaranteed. Treat it as such. Change-Id: Ie4d1219faac1e60247ca13bc2eedf22041a9a9e9 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/4487 Tested-by: jenkins Reviewed-by: Christopher Head --- contrib/rpc_examples/ocd_rpc_example.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 6c8529cdc..b585aaa42 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -92,9 +92,10 @@ class OpenOcd: self.send("array unset output") # better to clear the array before self.send("mem2array output %d 0x%x %d" % (wordLen, address, n)) - output = self.send("ocd_echo $output").split(" ") + output = [*map(int, self.send("ocd_echo $output").split(" "))] + d = dict([tuple(output[i:i + 2]) for i in range(0, len(output), 2)]) - return [int(output[2*i+1]) for i in range(len(output)//2)] + return [d[k] for k in sorted(d.keys())] def writeVariable(self, address, value): assert value is not None From 6949b5393d9fb6511ddef13ce0bef1a147e7f962 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 10:53:49 +0100 Subject: [PATCH 006/176] log: add const qualifier to commands struct The struct log_command_handlers[] is never modified. Add const qualifier to it. Change-Id: I5785aeb09ae9c23eaf7c34a05b88d0c7285f2d78 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5009 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/helper/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/log.c b/src/helper/log.c index f9807747b..90653c41d 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -236,7 +236,7 @@ COMMAND_HANDLER(handle_log_output_command) return ERROR_OK; } -static struct command_registration log_command_handlers[] = { +static const struct command_registration log_command_handlers[] = { { .name = "log_output", .handler = handle_log_output_command, From d303a2864df74117f6d0b2fae3f461fb0ee72226 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:25:53 +0100 Subject: [PATCH 007/176] target/arm7_9_common: use coherent syntax in struct initialization While initializing struct command_registration, the field's name "name" is not specified, thus relying on the fact that it is the first field declared in the struct and it's initialization value can be listed as the first one. Be coherent in the struct initialization and always use the field's name. Change-Id: I743457acf7757df4646c9bc4e5ea1a6f9c841516 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5010 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/target/arm7_9_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index c6a8a26d8..4fedc0d8f 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2864,7 +2864,7 @@ int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9) static const struct command_registration arm7_9_any_command_handlers[] = { { - "dbgrq", + .name = "dbgrq", .handler = handle_arm7_9_dbgrq_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", @@ -2872,7 +2872,7 @@ static const struct command_registration arm7_9_any_command_handlers[] = { "for target halt requests", }, { - "fast_memory_access", + .name = "fast_memory_access", .handler = handle_arm7_9_fast_memory_access_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", @@ -2880,7 +2880,7 @@ static const struct command_registration arm7_9_any_command_handlers[] = { "but potentially safer accesses", }, { - "dcc_downloads", + .name = "dcc_downloads", .handler = handle_arm7_9_dcc_downloads_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", From a5fe9d6e24fc98ef2c97a97fe4c2e1c9b5e1a181 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:35:46 +0100 Subject: [PATCH 008/176] target/armv4_5: use coherent syntax in struct initialization While initializing struct command_registration, the field's name "name" is not specified, thus relying on the fact that it is the first field declared in the struct and it's initialization value can be listed as the first one. Be coherent in the struct initialization and always use the field's name. Change-Id: I9ef7ac08e7cd5b82a6a7896c47017943d668925f Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5011 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/target/armv4_5.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index e16a9ecea..d04b17973 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -1140,28 +1140,28 @@ static const struct command_registration arm_exec_command_handlers[] = { .usage = "cpnum op1 CRn CRm op2", }, { - "semihosting", + .name = "semihosting", .handler = handle_common_semihosting_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting operations", }, { - "semihosting_cmdline", + .name = "semihosting_cmdline", .handler = handle_common_semihosting_cmdline, .mode = COMMAND_EXEC, .usage = "arguments", .help = "command line arguments to be passed to program", }, { - "semihosting_fileio", + .name = "semihosting_fileio", .handler = handle_common_semihosting_fileio_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting fileio operations", }, { - "semihosting_resexit", + .name = "semihosting_resexit", .handler = handle_common_semihosting_resumable_exit_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", From a18c1f289dc4d32d636791462880ae4a94a338b7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:36:39 +0100 Subject: [PATCH 009/176] target/openrisc: use coherent syntax in struct initialization While initializing struct command_registration, the field's name "name" is not specified, thus relying on the fact that it is the first field declared in the struct and it's initialization value can be listed as the first one. Be coherent in the struct initialization and always use the field's name. Change-Id: I65d32870bf4d3df845db69682fe445c71642f976 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5012 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/target/openrisc/or1k.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c index 34b1b0748..1cecebd30 100644 --- a/src/target/openrisc/or1k.c +++ b/src/target/openrisc/or1k.c @@ -1374,28 +1374,28 @@ COMMAND_HANDLER(or1k_addreg_command_handler) static const struct command_registration or1k_hw_ip_command_handlers[] = { { - "tap_select", + .name = "tap_select", .handler = or1k_tap_select_command_handler, .mode = COMMAND_ANY, .usage = "tap_select name", .help = "Select the TAP core to use", }, { - "tap_list", + .name = "tap_list", .handler = or1k_tap_list_command_handler, .mode = COMMAND_ANY, .usage = "tap_list", .help = "Display available TAP core", }, { - "du_select", + .name = "du_select", .handler = or1k_du_select_command_handler, .mode = COMMAND_ANY, .usage = "du_select name", .help = "Select the Debug Unit core to use", }, { - "du_list", + .name = "du_list", .handler = or1k_du_list_command_handler, .mode = COMMAND_ANY, .usage = "select_tap name", @@ -1406,7 +1406,7 @@ static const struct command_registration or1k_hw_ip_command_handlers[] = { static const struct command_registration or1k_reg_command_handlers[] = { { - "addreg", + .name = "addreg", .handler = or1k_addreg_command_handler, .mode = COMMAND_ANY, .usage = "addreg name addr feature group", From 69ba2a677bf57e28fae2318e64c392ad162b09ac Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:37:21 +0100 Subject: [PATCH 010/176] target/riscv: use coherent syntax in struct initialization While initializing struct command_registration, the field's name "name" is not specified, thus relying on the fact that it is the first field declared in the struct and it's initialization value can be listed as the first one. Be coherent in the struct initialization and always use the field's name. Change-Id: Iefaeb15cc051db9f1e0f0140fe2f231b45f5bb12 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5013 Reviewed-by: Tomas Vanek Tested-by: jenkins Reviewed-by: Tim Newsome --- src/target/riscv/riscv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 7bae39034..3b88e3313 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1900,28 +1900,28 @@ extern __COMMAND_HANDLER(handle_common_semihosting_cmdline); */ static const struct command_registration arm_exec_command_handlers[] = { { - "semihosting", + .name = "semihosting", .handler = handle_common_semihosting_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting operations", }, { - "semihosting_cmdline", + .name = "semihosting_cmdline", .handler = handle_common_semihosting_cmdline, .mode = COMMAND_EXEC, .usage = "arguments", .help = "command line arguments to be passed to program", }, { - "semihosting_fileio", + .name = "semihosting_fileio", .handler = handle_common_semihosting_fileio_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting fileio operations", }, { - "semihosting_resexit", + .name = "semihosting_resexit", .handler = handle_common_semihosting_resumable_exit_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", From 04354fbc59b0dcf83c8d1ecd9659252dfc66cbb4 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:48:37 +0100 Subject: [PATCH 011/176] flash/kinetis: use coherent indentation in struct initialization Keep using the same indentation rules while initializing struct command_registration. Change-Id: Ie69d9d6a786e1ef0abbcfd3eef89a61206238ebe Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5014 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/flash/nor/kinetis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 22c5d5c2d..9b2c014ca 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -3074,7 +3074,8 @@ static const struct command_registration kinetis_security_command_handlers[] = { .usage = "", .handler = kinetis_mdm_mass_erase, }, - { .name = "reset", + { + .name = "reset", .mode = COMMAND_EXEC, .help = "Issue a reset via the MDM-AP", .usage = "", From c239ee020bf0ce8a25b7558193b73f1939b901e2 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 11:50:53 +0100 Subject: [PATCH 012/176] flash/xmc4xxx: use coherent indentation in struct initialization Keep using the same indentation rules while initializing struct command_registration. Change-Id: I900924600753ee7a72ca45da13db4112ab4b1522 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5015 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/flash/nor/xmc4xxx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flash/nor/xmc4xxx.c b/src/flash/nor/xmc4xxx.c index c56adb500..d85be6214 100644 --- a/src/flash/nor/xmc4xxx.c +++ b/src/flash/nor/xmc4xxx.c @@ -1329,7 +1329,8 @@ static const struct command_registration xmc4xxx_exec_command_handlers[] = { .usage = "bank_id user_level[0-1]", .help = "Permanently Removes flash protection (read and write) " "for the specified user level", - }, COMMAND_REGISTRATION_DONE + }, + COMMAND_REGISTRATION_DONE }; static const struct command_registration xmc4xxx_command_handlers[] = { From a5a882c5c808baa9da543a20d50aa134423e45cc Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 10:48:30 +0100 Subject: [PATCH 013/176] target/armv7a: simplify help description of command "l2x" There is no need to split the string in two lines. Change-Id: Ifc574904acd06c31fab589643334e86f4dd0a122 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5016 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/armv7a.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/target/armv7a.c b/src/target/armv7a.c index f9594c9c3..437a2f266 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -584,8 +584,7 @@ static const struct command_registration l2_cache_commands[] = { .name = "l2x", .handler = handle_cache_l2x, .mode = COMMAND_EXEC, - .help = "configure l2x cache " - "", + .help = "configure l2x cache", .usage = "[base_addr] [number_of_way]", }, COMMAND_REGISTRATION_DONE From 57962f4d1c2db12dffa03c7357f5d7e0d8f71fb8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 15:13:53 +0100 Subject: [PATCH 014/176] command_registration: add empty usage field to chained commands Chained command require a subcommand as first argument. The usage field for chained commands is not really important because the "help" command will list all the subcommands with their respective usage. Add a empty usage field on all chained command. The command "jlink config" can be either followed by a subcommand or used alone, so use a dedicated usage string. Change-Id: I43c3f8a766f96a9bdab4e709e3c90713be41fcef Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5017 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nand/mxc.c | 3 ++- src/flash/nor/faux.c | 1 + src/flash/nor/max32xxx.c | 1 + src/flash/nor/tcl.c | 1 + src/hello.c | 2 +- src/helper/command.c | 1 + src/jtag/drivers/dummy.c | 2 +- src/jtag/drivers/jlink.c | 5 ++++- src/target/arm_cti.c | 1 + src/target/arm_dap.c | 1 + src/target/etb.c | 1 + src/target/etm_dummy.c | 1 + src/target/target.c | 2 +- src/target/testee.c | 2 +- 14 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/flash/nand/mxc.c b/src/flash/nand/mxc.c index 6be416057..6069c6268 100644 --- a/src/flash/nand/mxc.c +++ b/src/flash/nand/mxc.c @@ -193,7 +193,8 @@ static const struct command_registration mxc_nand_command_handler[] = { .name = "mxc", .mode = COMMAND_ANY, .help = "MXC NAND flash controller commands", - .chain = mxc_sub_command_handlers + .chain = mxc_sub_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/faux.c b/src/flash/nor/faux.c index 49b6dccd0..a894d0398 100644 --- a/src/flash/nor/faux.c +++ b/src/flash/nor/faux.c @@ -109,6 +109,7 @@ static const struct command_registration faux_command_handlers[] = { .mode = COMMAND_ANY, .help = "faux flash command group", .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index 12e3db940..f51f6e2a9 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -977,6 +977,7 @@ static const struct command_registration max32xxx_command_handlers[] = { .mode = COMMAND_EXEC, .help = "max32xxx flash command group", .chain = max32xxx_exec_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 6e216e68e..6d2d2b816 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -1260,6 +1260,7 @@ static const struct command_registration flash_command_handlers[] = { .mode = COMMAND_ANY, .help = "NOR flash command group", .chain = flash_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/hello.c b/src/hello.c index 25938bcf8..2afbba3a3 100644 --- a/src/hello.c +++ b/src/hello.c @@ -105,8 +105,8 @@ const struct command_registration hello_command_handlers[] = { .name = "foo", .mode = COMMAND_ANY, .help = "example command handler skeleton", - .chain = foo_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/helper/command.c b/src/helper/command.c index 7a3c2d4fe..869eff559 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1294,6 +1294,7 @@ static const struct command_registration command_builtin_handlers[] = { .mode = COMMAND_ANY, .help = "core command group (introspection)", .chain = command_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/jtag/drivers/dummy.c b/src/jtag/drivers/dummy.c index db1ba13a4..4e5b6152c 100644 --- a/src/jtag/drivers/dummy.c +++ b/src/jtag/drivers/dummy.c @@ -136,8 +136,8 @@ static const struct command_registration dummy_command_handlers[] = { .name = "dummy", .mode = COMMAND_ANY, .help = "dummy interface driver commands", - .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE, }; diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 1eae82734..c81579ab2 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -1849,12 +1849,14 @@ static const struct command_registration jlink_subcommand_handlers[] = { .help = "access the device configuration. If no argument is given " "this will show the device configuration", .chain = jlink_config_subcommand_handlers, + .usage = "[]", }, { .name = "emucom", .mode = COMMAND_EXEC, .help = "access EMUCOM channel", - .chain = jlink_emucom_subcommand_handlers + .chain = jlink_emucom_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1865,6 +1867,7 @@ static const struct command_registration jlink_command_handlers[] = { .mode = COMMAND_ANY, .help = "perform jlink management", .chain = jlink_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/arm_cti.c b/src/target/arm_cti.c index f33379240..3fa54d69c 100644 --- a/src/target/arm_cti.c +++ b/src/target/arm_cti.c @@ -576,6 +576,7 @@ static const struct command_registration cti_command_handlers[] = { .mode = COMMAND_CONFIG, .help = "CTI commands", .chain = cti_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 119e5117d..dd7ec9b58 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -373,6 +373,7 @@ static const struct command_registration dap_commands[] = { .mode = COMMAND_CONFIG, .help = "DAP commands", .chain = dap_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/etb.c b/src/target/etb.c index 98a90a556..7cd8b6cd5 100644 --- a/src/target/etb.c +++ b/src/target/etb.c @@ -441,6 +441,7 @@ static const struct command_registration etb_command_handlers[] = { .mode = COMMAND_ANY, .help = "Embedded Trace Buffer command group", .chain = etb_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c index b18ce1744..9f18d84a1 100644 --- a/src/target/etm_dummy.c +++ b/src/target/etm_dummy.c @@ -66,6 +66,7 @@ static const struct command_registration etm_dummy_command_handlers[] = { .mode = COMMAND_ANY, .help = "Dummy ETM capture driver command group", .chain = etm_dummy_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/target.c b/src/target/target.c index 5295dd626..084a2cffc 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -6096,8 +6096,8 @@ static const struct command_registration target_command_handlers[] = { .name = "target", .mode = COMMAND_CONFIG, .help = "configure target", - .chain = target_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/testee.c b/src/target/testee.c index 5b6ccedd8..236ac9aba 100644 --- a/src/target/testee.c +++ b/src/target/testee.c @@ -30,8 +30,8 @@ static const struct command_registration testee_command_handlers[] = { .name = "testee", .mode = COMMAND_ANY, .help = "testee target commands", - .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; From f9056d222c401f782481d323206595eed17671cb Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 21:07:36 +0100 Subject: [PATCH 015/176] drivers/imx_gpio: fix usage messages The notation "(tck tms tdi tdo)* " is incorrect, because it means the quadruple of gpio can be repeated on the command-line. The correct syntax of the command requires instead to provide either all the four gpio numbers (in order to set the values) or to pass an empty command-line (to dump the values previously set). Change the .usage field to "[tck tms tdi tdo]". Change similarly the corresponding .usage field for SWD command. Add the .usage field for the commands that individually set each gpio or gpio property. Dump the previously set values when commands imx_gpio_speed_coeffs or imx_gpio_peripheral_base are executed with empty command-line. Change-Id: Id56a68622817101bd0a46fed1fead6d2cd2b6ec6 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5018 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/imx_gpio.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/imx_gpio.c b/src/jtag/drivers/imx_gpio.c index f42692c38..8f172c26c 100644 --- a/src/jtag/drivers/imx_gpio.c +++ b/src/jtag/drivers/imx_gpio.c @@ -322,6 +322,9 @@ COMMAND_HANDLER(imx_gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], speed_coeff); COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } + + command_print(CMD_CTX, "imx_gpio: speed_coeffs = %d, speed_offset = %d", + speed_coeff, speed_offset); return ERROR_OK; } @@ -329,6 +332,9 @@ COMMAND_HANDLER(imx_gpio_handle_peripheral_base) { if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], imx_gpio_peri_base); + + command_print(CMD_CTX, "imx_gpio: peripheral_base = 0x%08x", + imx_gpio_peri_base); return ERROR_OK; } @@ -338,74 +344,84 @@ static const struct command_registration imx_gpio_command_handlers[] = { .handler = &imx_gpio_handle_jtag_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for tck, tms, tdi, tdo. (in that order)", - .usage = "(tck tms tdi tdo)* ", + .usage = "[tck tms tdi tdo]", }, { .name = "imx_gpio_tck_num", .handler = &imx_gpio_handle_jtag_gpionum_tck, .mode = COMMAND_CONFIG, .help = "gpio number for tck.", + .usage = "[tck]", }, { .name = "imx_gpio_tms_num", .handler = &imx_gpio_handle_jtag_gpionum_tms, .mode = COMMAND_CONFIG, .help = "gpio number for tms.", + .usage = "[tms]", }, { .name = "imx_gpio_tdo_num", .handler = &imx_gpio_handle_jtag_gpionum_tdo, .mode = COMMAND_CONFIG, .help = "gpio number for tdo.", + .usage = "[tdo]", }, { .name = "imx_gpio_tdi_num", .handler = &imx_gpio_handle_jtag_gpionum_tdi, .mode = COMMAND_CONFIG, .help = "gpio number for tdi.", + .usage = "[tdi]", }, { .name = "imx_gpio_swd_nums", .handler = &imx_gpio_handle_swd_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for swclk, swdio. (in that order)", - .usage = "(swclk swdio)* ", + .usage = "[swclk swdio]", }, { .name = "imx_gpio_swclk_num", .handler = &imx_gpio_handle_swd_gpionum_swclk, .mode = COMMAND_CONFIG, .help = "gpio number for swclk.", + .usage = "[swclk]", }, { .name = "imx_gpio_swdio_num", .handler = &imx_gpio_handle_swd_gpionum_swdio, .mode = COMMAND_CONFIG, .help = "gpio number for swdio.", + .usage = "[swdio]", }, { .name = "imx_gpio_srst_num", .handler = &imx_gpio_handle_jtag_gpionum_srst, .mode = COMMAND_CONFIG, .help = "gpio number for srst.", + .usage = "[srst]", }, { .name = "imx_gpio_trst_num", .handler = &imx_gpio_handle_jtag_gpionum_trst, .mode = COMMAND_CONFIG, .help = "gpio number for trst.", + .usage = "[trst]", }, { .name = "imx_gpio_speed_coeffs", .handler = &imx_gpio_handle_speed_coeffs, .mode = COMMAND_CONFIG, .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.", + .usage = "[SPEED_COEFF SPEED_OFFSET]", }, { .name = "imx_gpio_peripheral_base", .handler = &imx_gpio_handle_peripheral_base, .mode = COMMAND_CONFIG, .help = "peripheral base to access GPIOs (0x0209c000 for most IMX).", + .usage = "[base]", }, COMMAND_REGISTRATION_DONE From 84ca4995adfa6d15120e76f99a7b9dd73727d2d8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 21:18:37 +0100 Subject: [PATCH 016/176] drivers/bcm2835gpio: fix usage messages The notation "(tck tms tdi tdo)* " is incorrect, because it means the quadruple of gpio can be repeated on the command-line. The correct syntax of the command requires instead to provide either all the four gpio numbers (in order to set the values) or to pass an empty command-line (to dump the values previously set). Change the .usage field to "[tck tms tdi tdo]". Change similarly the corresponding .usage field for SWD command. Add the .usage field for the commands that individually set each gpio or gpio property. Dump the previously set values when commands bcm2835gpio_speed_coeffs or bcm2835gpio_peripheral_base are executed with empty command-line. Change-Id: Ie45d8268c1de331aded0bb52d5e6b8f0e8766a5b Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5019 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/jtag/drivers/bcm2835gpio.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index 38ef163fa..926bd89d3 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -300,6 +300,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], speed_coeff); COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } + + command_print(CMD_CTX, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d", + speed_coeff, speed_offset); return ERROR_OK; } @@ -307,6 +310,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_peripheral_base) { if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bcm2835_peri_base); + + command_print(CMD_CTX, "BCM2835 GPIO: peripheral_base = 0x%08x", + bcm2835_peri_base); return ERROR_OK; } @@ -316,74 +322,84 @@ static const struct command_registration bcm2835gpio_command_handlers[] = { .handler = &bcm2835gpio_handle_jtag_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for tck, tms, tdi, tdo. (in that order)", - .usage = "(tck tms tdi tdo)* ", + .usage = "[tck tms tdi tdo]", }, { .name = "bcm2835gpio_tck_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tck, .mode = COMMAND_CONFIG, .help = "gpio number for tck.", + .usage = "[tck]", }, { .name = "bcm2835gpio_tms_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tms, .mode = COMMAND_CONFIG, .help = "gpio number for tms.", + .usage = "[tms]", }, { .name = "bcm2835gpio_tdo_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tdo, .mode = COMMAND_CONFIG, .help = "gpio number for tdo.", + .usage = "[tdo]", }, { .name = "bcm2835gpio_tdi_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tdi, .mode = COMMAND_CONFIG, .help = "gpio number for tdi.", + .usage = "[tdi]", }, { .name = "bcm2835gpio_swd_nums", .handler = &bcm2835gpio_handle_swd_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for swclk, swdio. (in that order)", - .usage = "(swclk swdio)* ", + .usage = "[swclk swdio]", }, { .name = "bcm2835gpio_swclk_num", .handler = &bcm2835gpio_handle_swd_gpionum_swclk, .mode = COMMAND_CONFIG, .help = "gpio number for swclk.", + .usage = "[swclk]", }, { .name = "bcm2835gpio_swdio_num", .handler = &bcm2835gpio_handle_swd_gpionum_swdio, .mode = COMMAND_CONFIG, .help = "gpio number for swdio.", + .usage = "[swdio]", }, { .name = "bcm2835gpio_srst_num", .handler = &bcm2835gpio_handle_jtag_gpionum_srst, .mode = COMMAND_CONFIG, .help = "gpio number for srst.", + .usage = "[srst]", }, { .name = "bcm2835gpio_trst_num", .handler = &bcm2835gpio_handle_jtag_gpionum_trst, .mode = COMMAND_CONFIG, .help = "gpio number for trst.", + .usage = "[trst]", }, { .name = "bcm2835gpio_speed_coeffs", .handler = &bcm2835gpio_handle_speed_coeffs, .mode = COMMAND_CONFIG, .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.", + .usage = "[SPEED_COEFF SPEED_OFFSET]", }, { .name = "bcm2835gpio_peripheral_base", .handler = &bcm2835gpio_handle_peripheral_base, .mode = COMMAND_CONFIG, .help = "peripheral base to access GPIOs (RPi1 0x20000000, RPi2 0x3F000000).", + .usage = "[base]", }, COMMAND_REGISTRATION_DONE From 3d59e0f61257ef4dd19a49bd793e24a8e6eaa675 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 08:42:36 +0100 Subject: [PATCH 017/176] drivers/vsllink: add help and usage to commands Change-Id: I4a8a68147011525191ca79e65fc3d7e760371ae1 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5020 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/vsllink.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 6f7e9cadf..ea9152c09 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -919,31 +919,43 @@ static const struct command_registration vsllink_command_handlers[] = { .name = "vsllink_usb_vid", .handler = &vsllink_handle_usb_vid_command, .mode = COMMAND_CONFIG, + .help = "Set USB VID", + .usage = "", }, { .name = "vsllink_usb_pid", .handler = &vsllink_handle_usb_pid_command, .mode = COMMAND_CONFIG, + .help = "Set USB PID", + .usage = "", }, { .name = "vsllink_usb_serial", .handler = &vsllink_handle_usb_serial_command, .mode = COMMAND_CONFIG, + .help = "Set or disable check for USB serial", + .usage = "[]", }, { .name = "vsllink_usb_bulkin", .handler = &vsllink_handle_usb_bulkin_command, .mode = COMMAND_CONFIG, + .help = "Set USB input endpoint", + .usage = "", }, { .name = "vsllink_usb_bulkout", .handler = &vsllink_handle_usb_bulkout_command, .mode = COMMAND_CONFIG, + .help = "Set USB output endpoint", + .usage = "", }, { .name = "vsllink_usb_interface", .handler = &vsllink_handle_usb_interface_command, .mode = COMMAND_CONFIG, + .help = "Set USB output interface", + .usage = "", }, COMMAND_REGISTRATION_DONE }; From 80ca927ebc2bb1ca18aff70215222d55c1f196f8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 08:36:38 +0100 Subject: [PATCH 018/176] flash/nor/at91samd: set usage for command "set-security" The only allowed parameter is the string "enable" Change-Id: Iefdad38f1b4177e4194e58caf2be654357299ded Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5021 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/at91samd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index ad0da5d7e..a0d603a2c 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -1241,6 +1241,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { "This makes it impossible to read the Flash contents. " "The only way to undo this is to issue the chip-erase " "command.", + .usage = "'enable'", }, { .name = "eeprom", From 6e9571164b4461dde96201a0676783c60151642f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 08:39:26 +0100 Subject: [PATCH 019/176] flash/nor/str9xpec: fix help and usage for command "part_id" Remove the numeric parameter from help and add it to usage Change-Id: I630ca5450955210299f54e16fe5c9e8e51b3b266 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5022 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/flash/nor/str9xpec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flash/nor/str9xpec.c b/src/flash/nor/str9xpec.c index b618706b9..37d805344 100644 --- a/src/flash/nor/str9xpec.c +++ b/src/flash/nor/str9xpec.c @@ -1177,9 +1177,10 @@ static const struct command_registration str9xpec_config_command_handlers[] = { }, { .name = "part_id", + .usage = "", .handler = str9xpec_handle_part_id_command, .mode = COMMAND_EXEC, - .help = "print part id of str9xpec flash bank ", + .help = "print part id of str9xpec flash bank", }, COMMAND_REGISTRATION_DONE }; From fcfbb1792c985dcf1c9b5ae9300c7f24fac53d3a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 08:43:19 +0100 Subject: [PATCH 020/176] drivers/at91rm9200: fix help and usage to command "at91rm9200_device" Add usage and fix the help text of the command Change-Id: I0e157d76f5d87bcda80f82a110912994908c8e03 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5023 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/jtag/drivers/at91rm9200.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jtag/drivers/at91rm9200.c b/src/jtag/drivers/at91rm9200.c index 0015da06b..0360ec5de 100644 --- a/src/jtag/drivers/at91rm9200.c +++ b/src/jtag/drivers/at91rm9200.c @@ -183,7 +183,8 @@ static const struct command_registration at91rm9200_command_handlers[] = { .name = "at91rm9200_device", .handler = &at91rm9200_handle_device_command, .mode = COMMAND_CONFIG, - .help = "query armjtagew info", + .help = "Set at91rm9200 device [default \"rea_ecr\"]", + .usage = "", }, COMMAND_REGISTRATION_DONE }; From b6ea92247de948579715379abb591e61e887e7a5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 4 Dec 2018 23:50:02 +0100 Subject: [PATCH 021/176] target/adi_v5_swd: add "usage" field to command "swd" The missing field causes runtime debug message BUG: command 'swd' does not have the '.usage' field filled out Change-Id: I5a36c0fc822c4d5d74ef2d1c75e369648c6f7d4d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4830 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/adi_v5_swd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c index d92e2961e..594b5081f 100644 --- a/src/target/adi_v5_swd.c +++ b/src/target/adi_v5_swd.c @@ -352,6 +352,7 @@ static const struct command_registration swd_handlers[] = { .mode = COMMAND_ANY, .help = "SWD command group", .chain = swd_commands, + .usage = "", }, COMMAND_REGISTRATION_DONE }; From b61e454869c988e7fafc1c16982ccfec04415b51 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 4 Jan 2019 18:16:00 +0100 Subject: [PATCH 022/176] Set empty usage field for commands that do not need parameters The missing field causes runtime debug message BUG: command '%s' does not have the '.usage' field filled out While there, fix some minor typo in the help messages: s/deasert/deassert/ s/Deasert/Deassert/ Change-Id: If3dd18265cda103ca0d05609f67f4ca58e7cbb27 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5024 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/mflash.c | 1 + src/flash/nand/tcl.c | 1 + src/flash/nor/at91sam3.c | 1 + src/flash/nor/at91sam4.c | 1 + src/flash/nor/at91sam4l.c | 3 ++- src/flash/nor/at91samd.c | 5 ++++- src/flash/nor/atsame5.c | 2 ++ src/flash/nor/kinetis.c | 1 + src/flash/nor/nrf5.c | 1 + src/flash/nor/numicro.c | 1 + src/flash/nor/tcl.c | 2 ++ src/helper/ioutil.c | 1 + src/jtag/adapter.c | 1 + src/jtag/drivers/arm-jtag-ew.c | 1 + src/jtag/drivers/buspirate.c | 1 + src/jtag/drivers/jlink.c | 12 ++++++++---- src/jtag/drivers/opendous.c | 1 + src/pld/pld.c | 1 + src/server/gdb_server.c | 1 + src/target/target.c | 1 + src/target/xscale.c | 1 + 21 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 4c95d216c..1ad7290fa 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -1327,6 +1327,7 @@ static const struct command_registration mflash_exec_command_handlers[] = { .handler = mg_probe_cmd, .mode = COMMAND_EXEC, .help = "Detect bank configuration information", + .usage = "", }, { .name = "write", diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c index d9738c55b..dee4f6da8 100644 --- a/src/flash/nand/tcl.c +++ b/src/flash/nand/tcl.c @@ -411,6 +411,7 @@ static const struct command_registration nand_exec_command_handlers[] = { .handler = handle_nand_list_command, .mode = COMMAND_EXEC, .help = "list configured NAND flash devices", + .usage = "", }, { .name = "info", diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index 2d61a8780..a220279cf 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -3731,6 +3731,7 @@ static const struct command_registration at91sam3_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91sam3 chip" "and its flash configuration.", + .usage = "", }, { .name = "slowclk", diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 446f7983b..c89c50239 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -3212,6 +3212,7 @@ static const struct command_registration at91sam4_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91sam4 chip" "and its flash configuration.", + .usage = "", }, { .name = "slowclk", diff --git a/src/flash/nor/at91sam4l.c b/src/flash/nor/at91sam4l.c index 1c2402ff0..d356398dc 100644 --- a/src/flash/nor/at91sam4l.c +++ b/src/flash/nor/at91sam4l.c @@ -668,7 +668,8 @@ static const struct command_registration at91sam4l_exec_command_handlers[] = { .name = "smap_reset_deassert", .handler = sam4l_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "deasert internal reset held by SMAP" + .help = "deassert internal reset held by SMAP", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index a0d603a2c..c325194ed 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -1217,7 +1217,8 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .name = "dsu_reset_deassert", .handler = samd_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "Deasert internal reset held by DSU." + .help = "Deassert internal reset held by DSU.", + .usage = "", }, { .name = "info", @@ -1225,6 +1226,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91samd chip " "and its flash configuration.", + .usage = "", }, { .name = "chip-erase", @@ -1232,6 +1234,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Erase the entire Flash by using the Chip-" "Erase feature in the Device Service Unit (DSU).", + .usage = "", }, { .name = "set-security", diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 833177e1a..df4234917 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -893,12 +893,14 @@ COMMAND_HANDLER(samd_handle_reset_deassert) static const struct command_registration same5_exec_command_handlers[] = { { .name = "dsu_reset_deassert", + .usage = "", .handler = samd_handle_reset_deassert, .mode = COMMAND_EXEC, .help = "Deasert internal reset held by DSU." }, { .name = "chip-erase", + .usage = "", .handler = same5_handle_chip_erase_command, .mode = COMMAND_EXEC, .help = "Erase the entire Flash by using the Chip-" diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 9b2c014ca..847513502 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -3127,6 +3127,7 @@ static const struct command_registration kinetis_exec_command_handlers[] = { .mode = COMMAND_CONFIG, .help = "Driver creates additional banks if device with two/four flash blocks is probed", .handler = kinetis_create_banks_handler, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/nrf5.c b/src/flash/nor/nrf5.c index aab80f9bc..4041bfbe4 100644 --- a/src/flash/nor/nrf5.c +++ b/src/flash/nor/nrf5.c @@ -1118,6 +1118,7 @@ static const struct command_registration nrf5_exec_command_handlers[] = { .handler = nrf5_handle_mass_erase_command, .mode = COMMAND_EXEC, .help = "Erase all flash contents of the chip.", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/numicro.c b/src/flash/nor/numicro.c index 8d8abd5ed..47f9a8826 100644 --- a/src/flash/nor/numicro.c +++ b/src/flash/nor/numicro.c @@ -1856,6 +1856,7 @@ static const struct command_registration numicro_exec_command_handlers[] = { .handler = numicro_handle_chip_erase_command, .mode = COMMAND_EXEC, .help = "chip erase through ISP.", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 6d2d2b816..87d599a59 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -1239,12 +1239,14 @@ static const struct command_registration flash_config_command_handlers[] = { .mode = COMMAND_CONFIG, .handler = handle_flash_init_command, .help = "Initialize flash devices.", + .usage = "", }, { .name = "banks", .mode = COMMAND_ANY, .handler = handle_flash_banks_command, .help = "Display table with information about flash banks.", + .usage = "", }, { .name = "list", diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index f1123cd82..a48879905 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -472,6 +472,7 @@ static const struct command_registration ioutil_command_handlers[] = { .handler = handle_meminfo_command, .mode = COMMAND_ANY, .help = "display free heap space", + .usage = "", }, #endif { diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 3fb52a71e..24706f562 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -555,6 +555,7 @@ static const struct command_registration interface_command_handlers[] = { .handler = handle_interface_list_command, .mode = COMMAND_ANY, .help = "List all built-in debug adapter interfaces (drivers)", + .usage = "", }, { .name = "reset_config", diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index d9ea367ce..665dd4d18 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -490,6 +490,7 @@ static const struct command_registration armjtagew_command_handlers[] = { .handler = &armjtagew_handle_armjtagew_info_command, .mode = COMMAND_EXEC, .help = "query armjtagew info", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 35649c280..14c719d4c 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -491,6 +491,7 @@ static const struct command_registration buspirate_command_handlers[] = { .handler = &buspirate_handle_adc_command, .mode = COMMAND_EXEC, .help = "reads voltages on adc pins", + .usage = "", }, { .name = "buspirate_vreg", diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index c81579ab2..5a17dfd43 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -1772,13 +1772,15 @@ static const struct command_registration jlink_config_subcommand_handlers[] = { .name = "reset", .handler = &jlink_handle_config_reset_command, .mode = COMMAND_EXEC, - .help = "undo configuration changes" + .help = "undo configuration changes", + .usage = "", }, { .name = "write", .handler = &jlink_handle_config_write_command, .mode = COMMAND_EXEC, - .help = "write configuration to the device" + .help = "write configuration to the device", + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1820,13 +1822,15 @@ static const struct command_registration jlink_subcommand_handlers[] = { .name = "freemem", .handler = &jlink_handle_free_memory_command, .mode = COMMAND_EXEC, - .help = "show free device memory" + .help = "show free device memory", + .usage = "", }, { .name = "hwstatus", .handler = &jlink_handle_hwstatus_command, .mode = COMMAND_EXEC, - .help = "show the hardware status" + .help = "show the hardware status", + .usage = "", }, { .name = "usb", diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index 458df34a7..cec453dd9 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -215,6 +215,7 @@ static const struct command_registration opendous_command_handlers[] = { .handler = &opendous_handle_opendous_info_command, .mode = COMMAND_EXEC, .help = "show opendous info", + .usage = "", }, { .name = "opendous_hw_jtag", diff --git a/src/pld/pld.c b/src/pld/pld.c index 5210b97b7..3f23f6a00 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -170,6 +170,7 @@ static const struct command_registration pld_exec_command_handlers[] = { .handler = handle_pld_devices_command, .mode = COMMAND_EXEC, .help = "list configured pld devices", + .usage = "", }, { .name = "load", diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 3ade195cb..95e6c0491 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3699,6 +3699,7 @@ static const struct command_registration gdb_command_handlers[] = { .handler = handle_gdb_save_tdesc_command, .mode = COMMAND_EXEC, .help = "Save the target description file", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/target.c b/src/target/target.c index 084a2cffc..380a9fcdd 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5890,6 +5890,7 @@ static const struct command_registration target_subcommand_handlers[] = { .mode = COMMAND_CONFIG, .handler = handle_target_init_command, .help = "initialize targets", + .usage = "", }, { .name = "create", diff --git a/src/target/xscale.c b/src/target/xscale.c index 09abd9ef0..34c5f0001 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3577,6 +3577,7 @@ static const struct command_registration xscale_exec_command_handlers[] = { .handler = xscale_handle_cache_info_command, .mode = COMMAND_EXEC, .help = "display information about CPU caches", + .usage = "", }, { .name = "mmu", From c19de41a0f49ee11eb474c51dc243383047bd663 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 11:19:47 +0100 Subject: [PATCH 023/176] helper/command: handle empty "usage" with add_help_text/add_usage_text By using the command "add_help_text" to add a help text to a TCL procedure it implicitly creates a new command_registration struct that has field .usage set to NULL. This triggers a debug message BUG: command '%s' does not have the '.usage' field filled out Use an empty string if usage field is NULL. Plus, do not annoy the user with a LOG_INFO when the command "add_usage_text" replaces an empty usage. Change-Id: I4a72646e0fb704ba354f938d774055540cde3967 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5025 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 869eff559..ec66c2d29 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1119,7 +1119,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, .name = cmd_name, .mode = COMMAND_ANY, .help = help_text, - .usage = usage, + .usage = usage ? : "", }; nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) { @@ -1144,8 +1144,9 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (usage) { bool replaced = false; if (nc->usage) { + if (*nc->usage) + replaced = true; free(nc->usage); - replaced = true; } nc->usage = strdup(usage); if (replaced) From a3dc54d2d32919588cd7b8d22552f016cf603a49 Mon Sep 17 00:00:00 2001 From: Rocco Marco Guglielmi Date: Sun, 7 Apr 2019 16:18:36 +0200 Subject: [PATCH 024/176] topic: Remapped Flash over ITCM region in STM32F7x script This patch remaps the Flash over ITCM region as virtual to ensure that any breakpoint placed in this area will be automatically set as an hardware breakpoint. This patch is a fix to a regression introduced with changes #4429. Change-Id: I03d46d8537ef06b33a3d4a2328274667c6481969 Signed-off-by: Rocco Marco Guglielmi Reviewed-on: http://openocd.zylin.com/5097 Reviewed-by: Freddie Chopin Tested-by: jenkins --- tcl/target/stm32f7x.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tcl/target/stm32f7x.cfg b/tcl/target/stm32f7x.cfg index b777c6112..927a3e8d0 100755 --- a/tcl/target/stm32f7x.cfg +++ b/tcl/target/stm32f7x.cfg @@ -51,6 +51,10 @@ set _FLASHNAME $_CHIPNAME.flash flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME flash bank $_CHIPNAME.otp stm32f2x 0x1ff0f000 0 0 0 $_TARGETNAME +# Configuring the Flash via ITCM alias as virtual +set _FLASH_ITCM_VMA itcm-flash.alias +flash bank $_FLASH_ITCM_VMA virtual 0x00200000 0 0 0 $_TARGETNAME $_FLASHNAME + # adapter speed should be <= F_CPU/6. F_CPU after reset is 16MHz, so use F_JTAG = 2MHz adapter_khz 2000 From 1f4596cc46c96471f32d81613a612a4adefe36ab Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 3 Apr 2019 07:41:54 +0200 Subject: [PATCH 025/176] target: fix copy&paste error in cget -coreid Command should return target->coreid, not target->working_area_size Solution appeared as an off topic fix in http://openocd.zylin.com/4935 Change-Id: Ic9701ce2001c75060dbaa75fbd013ed475a352e5 Suggested-by: Graham Sanderson Reported-by: Tim Newsome Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5035 Tested-by: jenkins Reviewed-by: Tim Newsome Reviewed-by: Matthias Welwarsky --- src/target/target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 380a9fcdd..bcc2c5e2e 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4831,7 +4831,7 @@ no_params: if (goi->argc != 0) goto no_params; } - Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, target->working_area_size)); + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, target->coreid)); /* loop for more */ break; From 487710da6d65e1704f68849a152fec76752d4f4e Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Mon, 1 Apr 2019 16:06:30 -0700 Subject: [PATCH 026/176] Document the mem_ap target type Change-Id: I56e971b38f20db8c4ad0cdee5cc42b42a25319ea Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5029 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- doc/openocd.texi | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/openocd.texi b/doc/openocd.texi index 027e6d2ed..f5852cc09 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4367,6 +4367,7 @@ compact Thumb2 instruction set. The current implementation supports eSi-32xx cores. @item @code{fa526} -- resembles arm920 (w/o Thumb) @item @code{feroceon} -- resembles arm926 +@item @code{mem_ap} -- this is an ARM debug infrastructure Access Port without a CPU, through which bus read and write cycles can be generated; it may be useful for working with non-CPU hardware behind an AP or during development of support for new CPUs. @item @code{mips_m4k} -- a MIPS core @item @code{xscale} -- this is actually an architecture, not a CPU type. It is based on the ARMv5 architecture. From ca7ba6b58d2246547f156944be5326cf51c476ac Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Mon, 1 Apr 2019 16:02:09 -0700 Subject: [PATCH 027/176] Fix incorrect commas in URLs In Texinfo, a comma inside an @url separates parameters to the @url function rather than being included as part of a parameter. Use @comma{} instead to resolve this. Change-Id: I8b38939462cf4452e5bc2582ee484220aaf83ae0 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5028 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- doc/openocd.texi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index f5852cc09..feb433459 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4376,14 +4376,14 @@ The current implementation supports three JTAG TAP cores: @item @code{ls1_sap} -- this is the SAP on NXP LS102x CPUs, allowing access to physical memory addresses independently of CPU cores. @itemize @minus -@item @code{OpenCores TAP} (See: @url{http://opencores.org/project,jtag}) +@item @code{OpenCores TAP} (See: @url{http://opencores.org/project@comma{}jtag}) @item @code{Altera Virtual JTAG TAP} (See: @url{http://www.altera.com/literature/ug/ug_virtualjtag.pdf}) @item @code{Xilinx BSCAN_* virtual JTAG interface} (See: @url{http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_2/spartan6_hdl.pdf}) @end itemize And two debug interfaces cores: @itemize @minus -@item @code{Advanced debug interface} (See: @url{http://opencores.org/project,adv_debug_sys}) -@item @code{SoC Debug Interface} (See: @url{http://opencores.org/project,dbg_interface}) +@item @code{Advanced debug interface} (See: @url{http://opencores.org/project@comma{}adv_debug_sys}) +@item @code{SoC Debug Interface} (See: @url{http://opencores.org/project@comma{}dbg_interface}) @end itemize @end itemize @end deffn From 84e3f63a8ce170c3889a8cfe3ef885d8d7353844 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Fri, 10 Aug 2018 17:09:41 +0300 Subject: [PATCH 028/176] jtag: tcl: Add cget -idcode This can be used to dynamically distinguish between similar chips in tcl code. Change-Id: Ic4dfb61693e78616355173142dc7f9b9683a9f73 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5033 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- doc/openocd.texi | 6 +++++- src/jtag/tcl.c | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index feb433459..81a913541 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3895,10 +3895,14 @@ devices do not set the ack bit until sometime later. @section Other TAP commands +@deffn Command {jtag cget} dotted.name @option{-idcode} +Get the value of the IDCODE found in hardware. +@end deffn + @deffn Command {jtag cget} dotted.name @option{-event} event_name @deffnx Command {jtag configure} dotted.name @option{-event} event_name handler At this writing this TAP attribute -mechanism is used only for event handling. +mechanism is limited and used mostly for event handling. (It is not a direct analogue of the @code{cget}/@code{configure} mechanism for debugger targets.) See the next section for information about the available events. diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 768301470..71d220b82 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -307,11 +307,13 @@ static const struct command_registration jtag_command_handlers_to_move[] = { enum jtag_tap_cfg_param { - JCFG_EVENT + JCFG_EVENT, + JCFG_IDCODE, }; static Jim_Nvp nvp_config_opts[] = { { .name = "-event", .value = JCFG_EVENT }, + { .name = "-idcode", .value = JCFG_IDCODE }, { .name = NULL, .value = -1 } }; @@ -404,8 +406,23 @@ static int jtag_tap_configure_cmd(Jim_GetOptInfo *goi, struct jtag_tap *tap) if (e != JIM_OK) return e; break; + case JCFG_IDCODE: + if (goi->isconfigure) { + Jim_SetResultFormatted(goi->interp, + "not settable: %s", n->name); + return JIM_ERR; + } else { + if (goi->argc != 0) { + Jim_WrongNumArgs(goi->interp, + goi->argc, goi->argv, + "NO PARAMS"); + return JIM_ERR; + } + } + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, tap->idcode)); + break; default: - Jim_SetResultFormatted(goi->interp, "unknown event: %s", n->name); + Jim_SetResultFormatted(goi->interp, "unknown value: %s", n->name); return JIM_ERR; } } From 2fc82eae3c1c48485c1fb789dce4c7261fa81af7 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Fri, 10 Aug 2018 16:05:16 +0300 Subject: [PATCH 029/176] target/imx7: Add ahb mem_ap This allows bus access even when CPU is off. Change-Id: I2d5c5581cd0169aecb92ac7b610810988a8dcef4 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5032 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx7.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tcl/target/imx7.cfg b/tcl/target/imx7.cfg index f47dd7d0f..ea23deb0f 100644 --- a/tcl/target/imx7.cfg +++ b/tcl/target/imx7.cfg @@ -37,4 +37,9 @@ set _TARGETNAME_2 $_CHIPNAME.cpu_m4 target create $_TARGETNAME_2 cortex_m -dap $_CHIPNAME.dap -ap-num 4 \ -defer-examine +# +# AHB mem-ap target +# +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + targets $_TARGETNAME.0 From 55d53fb64c900f1d196870cb39998b40e1e4ce0e Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Fri, 10 Aug 2018 16:06:43 +0300 Subject: [PATCH 030/176] target/imx6: Add -ignore-version Looking through imx6 manuals all of them claim that "In follow-on silicon revisions the ID value is subject to change by incrementing the first nibble". Handle this by passing -ignore-version to jtag newtap command. Change-Id: I7fc4779f9757d527ea20a5174a8c90f919580013 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5031 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx6.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/tcl/target/imx6.cfg b/tcl/target/imx6.cfg index 8a32517f3..58dc418e6 100644 --- a/tcl/target/imx6.cfg +++ b/tcl/target/imx6.cfg @@ -30,6 +30,7 @@ set _SJC_TAPID3 0x2191e01d set _SJC_TAPID4 0x1191c01d jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ + -ignore-version \ -expected-id $_SJC_TAPID -expected-id $_SJC_TAPID2 \ -expected-id $_SJC_TAPID3 -expected-id $_SJC_TAPID4 From 3b291a369c4e0804619be7c9bf0a68b5f9d8e7d6 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Thu, 4 Apr 2019 16:17:49 +0300 Subject: [PATCH 031/176] target/imx6: Fix indentation in DAP_TAPID handling OpenOCD scripts are usually indented with 4 spaces but here there are 8. Change-Id: Iaad53e3b377d246d99119bb7bb5fd75d4422f564 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5039 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx6.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tcl/target/imx6.cfg b/tcl/target/imx6.cfg index 58dc418e6..e2ef7ae4e 100644 --- a/tcl/target/imx6.cfg +++ b/tcl/target/imx6.cfg @@ -8,9 +8,9 @@ if { [info exists CHIPNAME] } { # CoreSight Debug Access Port if { [info exists DAP_TAPID] } { - set _DAP_TAPID $DAP_TAPID + set _DAP_TAPID $DAP_TAPID } else { - set _DAP_TAPID 0x4ba00477 + set _DAP_TAPID 0x4ba00477 } jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ From 38d053d11b507cc762dc99ec7882d15d755f6c41 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Fri, 10 Aug 2018 19:54:43 +0300 Subject: [PATCH 032/176] target/imx6: Update list of supported TAPIDs Copy all SJC TAPIPs from imx6 reference manuals. Some imx6 chips are based on Cortex-A7 or have an additional Cortex-M4 and need separate scripts. Change-Id: I3b07d94058c2c5e6313cfc8bb43134a90682a62e Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5034 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx6.cfg | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/tcl/target/imx6.cfg b/tcl/target/imx6.cfg index e2ef7ae4e..f359346d7 100644 --- a/tcl/target/imx6.cfg +++ b/tcl/target/imx6.cfg @@ -1,4 +1,10 @@ -# Freescale i.MX6 series single/dual/quad core processor +# +# Freescale i.MX6 series +# +# Supports 6Q 6D 6QP 6DP 6DL 6S 6SL 6SLL +# +# Some imx6 chips have Cortex-A7 or an Cortex-M and need special handling +# if { [info exists CHIPNAME] } { set _CHIPNAME $CHIPNAME @@ -20,19 +26,34 @@ jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f # System JTAG Controller + +# List supported SJC TAPIDs from imx reference manuals: +set _SJC_TAPID_6Q 0x0191c01d +set _SJC_TAPID_6D 0x0191e01d +set _SJC_TAPID_6QP 0x3191c01d +set _SJC_TAPID_6DP 0x3191d01d +set _SJC_TAPID_6DL 0x0891a01d +set _SJC_TAPID_6S 0x0891b01d +set _SJC_TAPID_6SL 0x0891f01d +set _SJC_TAPID_6SLL 0x088c201d + +# Allow external override of the first SJC TAPID if { [info exists SJC_TAPID] } { - set _SJC_TAPID $SJC_TAPID + set _SJC_TAPID $SJC_TAPID } else { - set _SJC_TAPID 0x0191c01d + set _SJC_TAPID $_SJC_TAPID_6Q } -set _SJC_TAPID2 0x2191c01d -set _SJC_TAPID3 0x2191e01d -set _SJC_TAPID4 0x1191c01d jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ -ignore-version \ - -expected-id $_SJC_TAPID -expected-id $_SJC_TAPID2 \ - -expected-id $_SJC_TAPID3 -expected-id $_SJC_TAPID4 + -expected-id $_SJC_TAPID \ + -expected-id $_SJC_TAPID_6QP \ + -expected-id $_SJC_TAPID_6DP \ + -expected-id $_SJC_TAPID_6D \ + -expected-id $_SJC_TAPID_6DL \ + -expected-id $_SJC_TAPID_6S \ + -expected-id $_SJC_TAPID_6SL \ + -expected-id $_SJC_TAPID_6SLL # GDB target: Cortex-A9, using DAP, configuring only one core # Base addresses of cores: From 6f04bc1568445052b7135b801366c327786a3efe Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 30 Mar 2019 08:47:38 +0100 Subject: [PATCH 033/176] helper/command: log an error for commands without usage Every command has been fixed with proper usage field. Change LOG_DEBUG with LOG_ERROR so a developer will get a visible alert for missing usage field when adds a new command. Change-Id: I077c3745fd6265aded8e54b3f9d202d4d6516966 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5026 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/command.c b/src/helper/command.c index ec66c2d29..aadc072fa 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -316,7 +316,7 @@ static struct command *command_new(struct command_context *cmd_ctx, * arguments. */ if ((cr->jim_handler == NULL) && (cr->usage == NULL)) { - LOG_DEBUG("BUG: command '%s%s%s' does not have the " + LOG_ERROR("BUG: command '%s%s%s' does not have the " "'.usage' field filled out", parent && parent->name ? parent->name : "", parent && parent->name ? " " : "", From 6aae614cc2072e0d45bc32213595286ccbd32248 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Tue, 30 Oct 2018 14:45:11 -0700 Subject: [PATCH 034/176] flash/stm32h7x: include IO_HSLV in user3_options Bit 29 of OPTSR is IO_HSLV. It ought to be read in stm32x_read_options and written in stm32x_write_options. Adjust the bitmasks to do this. Change-Id: I785a5291c991c98b774177f960dc58f2b5e045e2 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/4745 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- src/flash/nor/stm32h7x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index ce89bb446..8bcc29cb1 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -321,7 +321,7 @@ static int stm32x_read_options(struct flash_bank *bank) stm32x_info->option_bytes.user_options = optiondata & 0xfc; stm32x_info->option_bytes.RDP = (optiondata >> 8) & 0xff; stm32x_info->option_bytes.user2_options = (optiondata >> 16) & 0xff; - stm32x_info->option_bytes.user3_options = (optiondata >> 24) & 0x83; + stm32x_info->option_bytes.user3_options = (optiondata >> 24) & 0xa3; if (stm32x_info->option_bytes.RDP != 0xAA) LOG_INFO("Device Security Bit Set"); @@ -357,7 +357,7 @@ static int stm32x_write_options(struct flash_bank *bank) optiondata = stm32x_info->option_bytes.user_options; optiondata |= (stm32x_info->option_bytes.RDP << 8); optiondata |= (stm32x_info->option_bytes.user2_options & 0xff) << 16; - optiondata |= (stm32x_info->option_bytes.user3_options & 0x83) << 24; + optiondata |= (stm32x_info->option_bytes.user3_options & 0xa3) << 24; /* program options */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTPRG, optiondata); From d5936dc688bedf54848a29b7c171ef47deb2bf91 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 1 Apr 2019 13:47:17 +0200 Subject: [PATCH 035/176] target/riscv: Free registers to avoid memory leak Tested with SiFive HiFive1 development board. Change-Id: I96a9a528057fcf9fc54d3da46a672d2cd54c3d5f Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/4885 Tested-by: jenkins Reviewed-by: Tim Newsome Reviewed-by: Tomas Vanek --- src/target/riscv/riscv.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 3b88e3313..44da5a9e6 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -271,16 +271,8 @@ static int riscv_init_target(struct command_context *cmd_ctx, return ERROR_OK; } -static void riscv_deinit_target(struct target *target) +static void riscv_free_registers(struct target *target) { - LOG_DEBUG("riscv_deinit_target()"); - struct target_type *tt = get_target_type(target); - if (tt) { - tt->deinit_target(target); - riscv_info_t *info = (riscv_info_t *) target->arch_info; - free(info->reg_names); - free(info); - } /* Free the shared structure use for most registers. */ if (target->reg_cache) { if (target->reg_cache->reg_list) { @@ -293,6 +285,21 @@ static void riscv_deinit_target(struct target *target) } free(target->reg_cache); } +} + +static void riscv_deinit_target(struct target *target) +{ + LOG_DEBUG("riscv_deinit_target()"); + struct target_type *tt = get_target_type(target); + if (tt) { + tt->deinit_target(target); + riscv_info_t *info = (riscv_info_t *) target->arch_info; + free(info->reg_names); + free(info); + } + + riscv_free_registers(target); + target->arch_info = NULL; } @@ -2503,11 +2510,7 @@ int riscv_init_registers(struct target *target) { RISCV_INFO(info); - if (target->reg_cache) { - if (target->reg_cache->reg_list) - free(target->reg_cache->reg_list); - free(target->reg_cache); - } + riscv_free_registers(target); target->reg_cache = calloc(1, sizeof(*target->reg_cache)); target->reg_cache->name = "RISC-V Registers"; From 5b263d7b0c71d2560af5dabbeec051b807d9e6a3 Mon Sep 17 00:00:00 2001 From: Mete Balci Date: Sat, 30 Mar 2019 12:51:03 +0100 Subject: [PATCH 036/176] fix for sanitizer errors in left shifts The modified lines cause "runtime error: left shift of by places cannot be represented in type 'int'", because integer literal is cast to int by default. Change-Id: Ie38119b5eb46ee470e0d149959e523b48ac4d66d Signed-off-by: Mete Balci Reviewed-on: http://openocd.zylin.com/5005 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/binarybuffer.h | 2 +- src/jtag/core.c | 2 +- src/target/armv8.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h index f1da8c4aa..7ac221e47 100644 --- a/src/helper/binarybuffer.h +++ b/src/helper/binarybuffer.h @@ -118,7 +118,7 @@ static inline uint32_t buf_get_u32(const uint8_t *_buffer, uint32_t result = 0; for (unsigned i = first; i < first + num; i++) { if (((buffer[i / 8] >> (i % 8)) & 1) == 1) - result |= 1 << (i - first); + result |= 1U << (i - first); } return result; } diff --git a/src/jtag/core.c b/src/jtag/core.c index f90ae99ba..e57f62db7 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1007,7 +1007,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap) return true; /* optionally ignore the JTAG version field - bits 28-31 of IDCODE */ - uint32_t mask = tap->ignore_version ? ~(0xf << 28) : ~0; + uint32_t mask = tap->ignore_version ? ~(0xfU << 28) : ~0U; uint32_t idcode = tap->idcode & mask; /* Loop over the expected identification codes and test for a match */ diff --git a/src/target/armv8.c b/src/target/armv8.c index c8cfcae20..e271c1a92 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -646,7 +646,7 @@ int armv8_read_mpidr(struct armv8_common *armv8) retval = dpm->instr_read_data_r0(dpm, armv8_opcode(armv8, READ_REG_MPIDR), &mpidr); if (retval != ERROR_OK) goto done; - if (mpidr & 1<<31) { + if (mpidr & 1U<<31) { armv8->multi_processor_system = (mpidr >> 30) & 1; armv8->cluster_id = (mpidr >> 8) & 0xf; armv8->cpu_id = mpidr & 0x3; From a4ac56152d9fc13c3fa479397407d9b86ffb13d8 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Wed, 1 Aug 2018 10:21:15 -0700 Subject: [PATCH 037/176] target/cortex_m: Implement maskisr steponly option `maskisr steponly` disables interrupts during single-stepping but enables them during normal execution. This can be used as a partial workaround for 702596 erratum in Cortex-M7 r0p1. See "Cortex-M7 (AT610) and Cortex-M7 with FPU (AT611) Software Developer Errata Notice" from ARM for further details. Change-Id: I797a14e4d43f6dcb3706528ee4ab452846ebf133 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/4673 Tested-by: jenkins Reviewed-by: Freddie Chopin --- doc/openocd.texi | 7 ++- src/target/cortex_m.c | 141 ++++++++++++++++++++++++++++++++++-------- src/target/cortex_m.h | 5 ++ 3 files changed, 127 insertions(+), 26 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 81a913541..a5037b254 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9078,7 +9078,7 @@ Enable or disable trace output for all ITM stimulus ports. @subsection Cortex-M specific commands @cindex Cortex-M -@deffn Command {cortex_m maskisr} (@option{auto}|@option{on}|@option{off}) +@deffn Command {cortex_m maskisr} (@option{auto}|@option{on}|@option{off}|@option{steponly}) Control masking (disabling) interrupts during target step/resume. The @option{auto} option handles interrupts during stepping in a way that they @@ -9088,6 +9088,11 @@ the next instruction where the core was halted. After the step interrupts are enabled again. If the interrupt handlers don't complete within 500ms, the step command leaves with the core running. +The @option{steponly} option disables interrupts during single-stepping but +enables them during normal execution. This can be used as a partial workaround +for 702596 erratum in Cortex-M7 r0p1. See "Cortex-M7 (AT610) and Cortex-M7 with +FPU (AT611) Software Developer Errata Notice" from ARM for further details. + Note that a free hardware (FPB) breakpoint is required for the @option{auto} option. If no breakpoint is available at the time of the step, then the step is taken with interrupts enabled, i.e. the same way the @option{off} option diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index d341d4572..e88392504 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -136,6 +136,83 @@ static int cortex_m_write_debug_halt_mask(struct target *target, return mem_ap_write_atomic_u32(armv7m->debug_ap, DCB_DHCSR, cortex_m->dcb_dhcsr); } +static int cortex_m_set_maskints(struct target *target, bool mask) +{ + struct cortex_m_common *cortex_m = target_to_cm(target); + if (!!(cortex_m->dcb_dhcsr & C_MASKINTS) != mask) + return cortex_m_write_debug_halt_mask(target, mask ? C_MASKINTS : 0, mask ? 0 : C_MASKINTS); + else + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_halt(struct target *target) +{ + struct cortex_m_common *cortex_m = target_to_cm(target); + switch (cortex_m->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* interrupts taken at resume, whether for step or run -> no mask */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> mask now if MASKINTS + * erratum, otherwise only mask before stepping */ + return cortex_m_set_maskints(target, cortex_m->maskints_erratum); + } + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_run(struct target *target) +{ + switch (target_to_cm(target)->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* interrupts taken at resume, whether for step or run -> no mask */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> no mask */ + return cortex_m_set_maskints(target, false); + } + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_step(struct target *target) +{ + switch (target_to_cm(target)->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* the auto-interrupt should already be done -> mask */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> mask */ + return cortex_m_set_maskints(target, true); + } + return ERROR_OK; +} + static int cortex_m_clear_halt(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); @@ -237,11 +314,8 @@ static int cortex_m_endreset_event(struct target *target) return retval; } - /* Restore proper interrupt masking setting. */ - if (cortex_m->isrmasking_mode == CORTEX_M_ISRMASK_ON) - cortex_m_write_debug_halt_mask(target, C_MASKINTS, 0); - else - cortex_m_write_debug_halt_mask(target, 0, C_MASKINTS); + /* Restore proper interrupt masking setting for running CPU. */ + cortex_m_set_maskints_for_run(target); /* Enable features controlled by ITM and DWT blocks, and catch only * the vectors we were told to pay attention to. @@ -405,6 +479,10 @@ static int cortex_m_debug_entry(struct target *target) LOG_DEBUG(" "); + /* Do this really early to minimize the window where the MASKINTS erratum + * can pile up pending interrupts. */ + cortex_m_set_maskints_for_halt(target); + cortex_m_clear_halt(target); retval = mem_ap_read_atomic_u32(armv7m->debug_ap, DCB_DHCSR, &cortex_m->dcb_dhcsr); if (retval != ERROR_OK) @@ -614,6 +692,10 @@ static int cortex_m_halt(struct target *target) /* Write to Debug Halting Control and Status Register */ cortex_m_write_debug_halt_mask(target, C_HALT, 0); + /* Do this really early to minimize the window where the MASKINTS erratum + * can pile up pending interrupts. */ + cortex_m_set_maskints_for_halt(target); + target->debug_reason = DBG_REASON_DBGRQ; return ERROR_OK; @@ -767,6 +849,7 @@ static int cortex_m_resume(struct target *target, int current, } /* Restart core */ + cortex_m_set_maskints_for_run(target); cortex_m_write_debug_halt_mask(target, 0, C_HALT); target->debug_reason = DBG_REASON_NOTHALTED; @@ -829,10 +912,12 @@ static int cortex_m_step(struct target *target, int current, * a normal step, otherwise we have to manually step over the bkpt * instruction - as such simulate a step */ if (bkpt_inst_found == false) { - /* Automatic ISR masking mode off: Just step over the next instruction */ - if ((cortex_m->isrmasking_mode != CORTEX_M_ISRMASK_AUTO)) + if ((cortex_m->isrmasking_mode != CORTEX_M_ISRMASK_AUTO)) { + /* Automatic ISR masking mode off: Just step over the next + * instruction, with interrupts on or off as appropriate. */ + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - else { + } else { /* Process interrupts during stepping in a way they don't interfere * debugging. * @@ -871,8 +956,9 @@ static int cortex_m_step(struct target *target, int current, LOG_DEBUG("Stepping over next instruction with interrupts disabled"); cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - /* Re-enable interrupts */ - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); } else { @@ -891,12 +977,17 @@ static int cortex_m_step(struct target *target, int current, bool tmp_bp_set = (retval == ERROR_OK); /* No more breakpoints left, just do a step */ - if (!tmp_bp_set) + if (!tmp_bp_set) { + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - else { + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); + } else { /* Start the core */ LOG_DEBUG("Starting core to serve pending interrupts"); int64_t t_start = timeval_ms(); + cortex_m_set_maskints_for_run(target); cortex_m_write_debug_halt_mask(target, 0, C_HALT | C_STEP); /* Wait for pending handlers to complete or timeout */ @@ -924,12 +1015,14 @@ static int cortex_m_step(struct target *target, int current, "leaving target running"); } else { /* Step over next instruction with interrupts disabled */ + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - /* Re-enable interrupts */ - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); } } } @@ -1031,8 +1124,7 @@ static int cortex_m_assert_reset(struct target *target) if (!target->reset_halt) { /* Set/Clear C_MASKINTS in a separate operation */ - if (cortex_m->dcb_dhcsr & C_MASKINTS) - cortex_m_write_debug_halt_mask(target, 0, C_MASKINTS); + cortex_m_set_maskints_for_run(target); /* clear any debug flags before resuming */ cortex_m_clear_halt(target); @@ -2020,12 +2112,15 @@ int cortex_m_examine(struct target *target) LOG_DEBUG("Cortex-M%d r%" PRId8 "p%" PRId8 " processor detected", i, (uint8_t)((cpuid >> 20) & 0xf), (uint8_t)((cpuid >> 0) & 0xf)); + cortex_m->maskints_erratum = false; if (i == 7) { uint8_t rev, patch; rev = (cpuid >> 20) & 0xf; patch = (cpuid >> 0) & 0xf; - if ((rev == 0) && (patch < 2)) - LOG_WARNING("Silicon bug: single stepping will enter pending exception handler!"); + if ((rev == 0) && (patch < 2)) { + LOG_WARNING("Silicon bug: single stepping may enter pending exception handler!"); + cortex_m->maskints_erratum = true; + } } LOG_DEBUG("cpuid: 0x%8.8" PRIx32 "", cpuid); @@ -2381,6 +2476,7 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) { .name = "auto", .value = CORTEX_M_ISRMASK_AUTO }, { .name = "off", .value = CORTEX_M_ISRMASK_OFF }, { .name = "on", .value = CORTEX_M_ISRMASK_ON }, + { .name = "steponly", .value = CORTEX_M_ISRMASK_STEPONLY }, { .name = NULL, .value = -1 }, }; const Jim_Nvp *n; @@ -2400,12 +2496,7 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) if (n->name == NULL) return ERROR_COMMAND_SYNTAX_ERROR; cortex_m->isrmasking_mode = n->value; - - - if (cortex_m->isrmasking_mode == CORTEX_M_ISRMASK_ON) - cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); - else - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + cortex_m_set_maskints_for_halt(target); } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_m->isrmasking_mode); @@ -2465,7 +2556,7 @@ static const struct command_registration cortex_m_exec_command_handlers[] = { .handler = handle_cortex_m_mask_interrupts_command, .mode = COMMAND_EXEC, .help = "mask cortex_m interrupts", - .usage = "['auto'|'on'|'off']", + .usage = "['auto'|'on'|'off'|'steponly']", }, { .name = "vector_catch", diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index 4b207467e..c33486273 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -159,6 +159,7 @@ enum cortex_m_isrmasking_mode { CORTEX_M_ISRMASK_AUTO, CORTEX_M_ISRMASK_OFF, CORTEX_M_ISRMASK_ON, + CORTEX_M_ISRMASK_STEPONLY, }; struct cortex_m_common { @@ -190,6 +191,10 @@ struct cortex_m_common { struct armv7m_common armv7m; int apsel; + + /* Whether this target has the erratum that makes C_MASKINTS not apply to + * already pending interrupts */ + bool maskints_erratum; }; static inline struct cortex_m_common * From d3a9e535d52bebf9973babe564c09797c71a2fc2 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 15 Apr 2019 23:47:50 +0200 Subject: [PATCH 038/176] target/cortex_a: fix waiting for target halted after step Depending on adapter speed, the function cortex_a_poll() can take time to execute and can complete successfully when the timeout is already expired. Checking the timeout at function return causes a timeout error while that could be avoided. Check the target status at cortex_a_poll() return, before checking for the timeout. Change-Id: I4c1581f6e718298c566df7b1359255e16e3955d5 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5111 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/cortex_a.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 6eb6aa933..8ed81b78f 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -1206,6 +1206,8 @@ static int cortex_a_step(struct target *target, int current, target_addr_t addre retval = cortex_a_poll(target); if (retval != ERROR_OK) return retval; + if (target->state == TARGET_HALTED) + break; if (timeval_ms() > then + 1000) { LOG_ERROR("timeout waiting for target halt"); return ERROR_FAIL; From d870ecf5ff4a71e119418fabe8a250a2bab61357 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 15 Apr 2019 22:32:32 +0200 Subject: [PATCH 039/176] target/cortex_a: check dscr before timeout In function cortex_a_wait_dscr_bits() the last read on dscr gets ignored in case of timeout, even if it finally provides the value that would trigger a successful return. Check the returned value before testing the timeout. Also, print a message on failure reading dscr. Change-Id: I261ac1545113db39374833a55be911a4da71d893 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5112 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/cortex_a.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 8ed81b78f..587cbba0e 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -1765,14 +1765,22 @@ static int cortex_a_wait_dscr_bits(struct target *target, uint32_t mask, { /* Waits until the specified bit(s) of DSCR take on a specified value. */ struct armv7a_common *armv7a = target_to_armv7a(target); - int64_t then = timeval_ms(); + int64_t then; int retval; - while ((*dscr & mask) != value) { + if ((*dscr & mask) == value) + return ERROR_OK; + + then = timeval_ms(); + while (1) { retval = mem_ap_read_atomic_u32(armv7a->debug_ap, armv7a->debug_base + CPUDBG_DSCR, dscr); - if (retval != ERROR_OK) + if (retval != ERROR_OK) { + LOG_ERROR("Could not read DSCR register"); return retval; + } + if ((*dscr & mask) == value) + break; if (timeval_ms() > then + 1000) { LOG_ERROR("timeout waiting for DSCR bit change"); return ERROR_FAIL; From f9986394dc98cf27708022487a5e5b1b8cc9f5b5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 15 Apr 2019 23:46:29 +0200 Subject: [PATCH 040/176] target/cortex_a: use extensively cortex_a_wait_dscr_bits() We have the function to wait for bits in dscr. Use it whenever possible. When the bit to test is DSCR_INSTR_COMP, use instead the wrapper function cortex_a_wait_instrcmpl(). Change-Id: I5c54c239a00f489712af448eb97752210b4b38b8 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5113 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/cortex_a.c | 110 +++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 71 deletions(-) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 587cbba0e..8d0e10013 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -70,6 +70,8 @@ static int cortex_a_set_hybrid_breakpoint(struct target *target, struct breakpoint *breakpoint); static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *breakpoint); +static int cortex_a_wait_dscr_bits(struct target *target, uint32_t mask, + uint32_t value, uint32_t *dscr); static int cortex_a_mmu(struct target *target, int *enabled); static int cortex_a_mmu_modify(struct target *target, int enable); static int cortex_a_virt2phys(struct target *target, @@ -250,21 +252,21 @@ static int cortex_a_wait_instrcmpl(struct target *target, uint32_t *dscr, bool f * Writes final value of DSCR into *dscr. Pass force to force always * reading DSCR at least once. */ struct armv7a_common *armv7a = target_to_armv7a(target); - int64_t then = timeval_ms(); - while ((*dscr & DSCR_INSTR_COMP) == 0 || force) { - force = false; - int retval = mem_ap_read_atomic_u32(armv7a->debug_ap, + int retval; + + if (force) { + retval = mem_ap_read_atomic_u32(armv7a->debug_ap, armv7a->debug_base + CPUDBG_DSCR, dscr); if (retval != ERROR_OK) { LOG_ERROR("Could not read DSCR register"); return retval; } - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for InstrCompl=1"); - return ERROR_FAIL; - } } - return ERROR_OK; + + retval = cortex_a_wait_dscr_bits(target, DSCR_INSTR_COMP, DSCR_INSTR_COMP, dscr); + if (retval != ERROR_OK) + LOG_ERROR("Error waiting for InstrCompl=1"); + return retval; } /* To reduce needless round-trips, pass in a pointer to the current @@ -293,19 +295,12 @@ static int cortex_a_exec_opcode(struct target *target, if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - do { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) { - LOG_ERROR("Could not read DSCR register"); - return retval; - } - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for cortex_a_exec_opcode"); - return ERROR_FAIL; - } - } while ((dscr & DSCR_INSTR_COMP) == 0); /* Wait for InstrCompl bit to be set */ + /* Wait for InstrCompl bit to be set */ + retval = cortex_a_wait_instrcmpl(target, &dscr, true); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for cortex_a_exec_opcode"); + return retval; + } if (dscr_p) *dscr_p = dscr; @@ -359,17 +354,11 @@ static int cortex_a_read_dcc(struct cortex_a_common *a, uint32_t *data, dscr = *dscr_p; /* Wait for DTRRXfull */ - int64_t then = timeval_ms(); - while ((dscr & DSCR_DTR_TX_FULL) == 0) { - retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, - a->armv7a_common.debug_base + CPUDBG_DSCR, - &dscr); - if (retval != ERROR_OK) - return retval; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for read dcc"); - return ERROR_FAIL; - } + retval = cortex_a_wait_dscr_bits(a->armv7a_common.arm.target, + DSCR_DTR_TX_FULL, DSCR_DTR_TX_FULL, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for read dcc"); + return retval; } retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, @@ -391,19 +380,10 @@ static int cortex_a_dpm_prepare(struct arm_dpm *dpm) int retval; /* set up invariant: INSTR_COMP is set after ever DPM operation */ - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, - a->armv7a_common.debug_base + CPUDBG_DSCR, - &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_INSTR_COMP) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for dpm prepare"); - return ERROR_FAIL; - } + retval = cortex_a_wait_instrcmpl(dpm->arm->target, &dscr, true); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for dpm prepare"); + return retval; } /* this "should never happen" ... */ @@ -752,7 +732,7 @@ static int cortex_a_poll(struct target *target) static int cortex_a_halt(struct target *target) { - int retval = ERROR_OK; + int retval; uint32_t dscr; struct armv7a_common *armv7a = target_to_armv7a(target); @@ -765,18 +745,12 @@ static int cortex_a_halt(struct target *target) if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_CORE_HALTED) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for halt"); - return ERROR_FAIL; - } + dscr = 0; /* force read of dscr */ + retval = cortex_a_wait_dscr_bits(target, DSCR_CORE_HALTED, + DSCR_CORE_HALTED, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for halt"); + return retval; } target->debug_reason = DBG_REASON_DBGRQ; @@ -915,18 +889,12 @@ static int cortex_a_internal_restart(struct target *target) if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_CORE_RESTARTED) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for resume"); - return ERROR_FAIL; - } + dscr = 0; /* force read of dscr */ + retval = cortex_a_wait_dscr_bits(target, DSCR_CORE_RESTARTED, + DSCR_CORE_RESTARTED, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for resume"); + return retval; } target->debug_reason = DBG_REASON_NOTHALTED; From 33281a87b66576057c14200e034e8e7e0a7e2d85 Mon Sep 17 00:00:00 2001 From: Alexander Kurz Date: Tue, 24 Jan 2017 13:34:38 +0100 Subject: [PATCH 041/176] tcl/board: Add config for the Amazon Kindle 2 and DX Add a config to access the Amazon Kindle Model No. D00701 and D00801. Both ebook readers are based on a Freescale i.MX31. A JTAG interface is included in a 40 pin FFC connector marked "J9" on both variants. Change-Id: I58bb1ded3d6706bc3798af488ca8bafb7dc45225 Signed-off-by: Alexander Kurz Reviewed-on: http://openocd.zylin.com/3956 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/board/kindle2.cfg | 181 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tcl/board/kindle2.cfg diff --git a/tcl/board/kindle2.cfg b/tcl/board/kindle2.cfg new file mode 100644 index 000000000..f32b2a321 --- /dev/null +++ b/tcl/board/kindle2.cfg @@ -0,0 +1,181 @@ +# Board configuration file for Amazon Kindle Model No. D00701 and D00801 +# AKA Kindle 2nd generation and Kindle DX +# using a Freescale MCIMX31LDVKN5D i.MX31 processor +# +# Pins at J9 40-Pin FFC-A: +# 1 - GND +# 16 - TRSTB +# 17 - TDI +# 18 - TMS +# 19 - TCK +# 20 - RTCK +# 21 - TDO +# 22 - DE +# 25 - BOOT_MODE4 +# 27 - BOOT_MODE2 + +source [find target/imx31.cfg] +source [find target/imx.cfg] + +$_TARGETNAME configure -event reset-init { kindle2_init } +$_TARGETNAME configure -event reset-start { adapter_khz 1000 } + +# 8MiB NOR Flash +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME cfi 0xa0000000 0x800000 2 2 $_TARGETNAME + +# 16kiB internal SRAM +$_TARGETNAME configure -work-area-phys 0x1fffc000 \ + -work-area-size 0x4000 -work-area-backup 0 + +# FIXME: currently SRST is not wired to the system +reset_config trst_only +jtag_ntrst_assert_width 10 +jtag_ntrst_delay 30 + +# this is broken but enabled by default +arm11 memwrite burst disable + +adapter_khz 1000 +ftdi_tdo_sample_edge falling + +proc kindle2_init {} { + imx3x_reset + kindle2_clock_setup + disable_mmu_and_cache + kindle2_misc_init + kindle2_sdram_init + arm core_state arm +} + +proc kindle2_clock_setup {} { + # CCMR: clock from FPM/CKIL + mww 0x53f80000 0x074b0b7b + # IPU_CONF + mww 0x53fc0000 0x040 + # 398MHz + mww 0x53f80004 0xff871650 + mww 0x53f80010 0x00331c23 +} + +proc kindle2_misc_init { } { + # AIPS1 + mww 0x43f00040 0x0 + mww 0x43f00044 0x0 + mww 0x43f00048 0x0 + mww 0x43f0004c 0x0 + mww 0x43f00050 0x0 + mww 0x43f00000 0x77777777 + mww 0x43f00004 0x77777777 + + # AIPS2 + mww 0x53f00040 0x0 + mww 0x53f00044 0x0 + mww 0x53f00048 0x0 + mww 0x53f0004c 0x0 + mww 0x53f00050 0x0 + mww 0x53f00000 0x77777777 + mww 0x53f00004 0x77777777 + + # Start 16 bit NorFlash Initialization on CS0 + mww 0xb8002000 0x0000cc03 + mww 0xb8002004 0xa0330d01 + mww 0xb8002008 0x00220800 +} + +proc disable_mmu_and_cache {} { + # Mode Supervisor, disable FIQ, IRQ and imprecise data aborts + reg cpsr 0x1d3 + + # flush entire BTAC + arm mcr 15 0 7 5 6 0 + # invalidate instruction and data cache + # MCR CP15, 0, R1, C7, C7, 0 + arm mcr 15 0 7 7 0 + + # clean and invalidate cache + arm mcr 15 0 7 15 0 + + # disable MMU and caches + arm mcr 15 0 1 0 0 0 + + arm mcr 15 0 15 2 4 0 + + # invalidate TLBs + arm mcr 15 0 8 7 0 0 + + # Drain the write buffer + arm mcr 15 0 7 10 4 0 + + # start from AIPS 2GB region + arm mcr 15 0 15 2 4 0x40000015 +} + +proc kindle2_sdram_init {} { + #-------------------------------------------- + # Samsung K4X1G323PC-8GC3 32Mx32 Mobile DDR SDRAM + #-------------------------------------------- + # SDCLK + mww 0x43fac26c 0 + + # CAS + mww 0x43fac270 0 + + # RAS + mww 0x43fac274 0 + + # CS2 (CSD0) + mww 0x43fac27c 0x1000 + + # DQM3 + mww 0x43fac284 0 + + # DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2dc) + mww 0x43fac288 0 + mww 0x43fac28c 0 + mww 0x43fac290 0 + mww 0x43fac294 0 + mww 0x43fac298 0 + mww 0x43fac29c 0 + mww 0x43fac2a0 0 + mww 0x43fac2a4 0 + mww 0x43fac2a8 0 + mww 0x43fac2ac 0 + mww 0x43fac2b0 0 + mww 0x43fac2b4 0 + mww 0x43fac2b8 0 + mww 0x43fac2bc 0 + mww 0x43fac2c0 0 + mww 0x43fac2c4 0 + mww 0x43fac2c8 0 + mww 0x43fac2cc 0 + mww 0x43fac2d0 0 + mww 0x43fac2d4 0 + mww 0x43fac2d8 0 + mww 0x43fac2dc 0 + + # ? + mww 0xb8002000 0x00006602 + mww 0xb8002004 0x00000501 + mww 0xb8002008 0x00000000 + + # LPDDR1 Initialization script + mww 0xb8001010 0x00000002 + mww 0xb8001010 0x00000004 + # ESDCFG0: set timing paramters + mww 0xb8001004 0x007fff7f + # ESDCTL0: select Prechare-All mode + mww 0xb8001000 0x92100000 + mww 0x80000f00 0x12344321 + # ESDCTL0: Auto Refresh + mww 0xb8001000 0xa2100000 + mww 0x80000000 0x12344321 + mww 0x80000000 0x12344321 + # ESDCTL0: Load Mode Register + mww 0xb8001000 0xb2100000 + mwb 0x80000033 0xda + mwb 0x81000000 0xff + # ESDCTL0: enable Auto-Refresh + mww 0xb8001000 0x82226080 + mww 0x80000000 0xdeadbeef +} From 83515b60c9a506c458e614732165a791fa1a833a Mon Sep 17 00:00:00 2001 From: Tommy Vestermark Date: Thu, 11 Apr 2019 20:40:36 +1000 Subject: [PATCH 042/176] armv7a: Improve parsing of MPIDR register to avoid error message for Cortex R5 References: - ARM DDI0406C ARMv7 Architecture Reference Manual, section B4.1.106 - ARM DDI0460D Cortex-R5 Technical Reference Manual section 4.3.6 - ARM 100048_0002_0 Cortex-A73 Technical Reference Manual section 4.5.2 Tested on: TMS570LC4357 Change-Id: Ie0d45fb697697f78cc4ad4e7a0116be9772590ba Signed-off-by: Tommy Vestermark Reviewed-on: http://openocd.zylin.com/5108 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/armv7a.c | 24 +++++++++++------------- src/target/armv7a.h | 5 +++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 437a2f266..97ce473e5 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -307,23 +307,21 @@ static int armv7a_read_mpidr(struct target *target) if (retval != ERROR_OK) goto done; - /* ARMv7R uses a different format for MPIDR. - * When configured uniprocessor (most R cores) it reads as 0. - * This will need to be implemented for multiprocessor ARMv7R cores. */ - if (armv7a->is_armv7r) { - if (mpidr) - LOG_ERROR("MPIDR nonzero in ARMv7-R target"); - goto done; - } - - if (mpidr & 1<<31) { + /* Is register in Multiprocessing Extensions register format? */ + if (mpidr & MPIDR_MP_EXT) { + LOG_DEBUG("%s: MPIDR 0x%" PRIx32, target_name(target), mpidr); armv7a->multi_processor_system = (mpidr >> 30) & 1; + armv7a->multi_threading_processor = (mpidr >> 24) & 1; + armv7a->level2_id = (mpidr >> 16) & 0xf; armv7a->cluster_id = (mpidr >> 8) & 0xf; - armv7a->cpu_id = mpidr & 0x3; - LOG_INFO("%s cluster %x core %x %s", target_name(target), + armv7a->cpu_id = mpidr & 0xf; + LOG_INFO("%s: MPIDR level2 %x, cluster %x, core %x, %s, %s", + target_name(target), + armv7a->level2_id, armv7a->cluster_id, armv7a->cpu_id, - armv7a->multi_processor_system == 0 ? "multi core" : "mono core"); + armv7a->multi_processor_system == 0 ? "multi core" : "mono core", + armv7a->multi_threading_processor == 1 ? "SMT" : "no SMT"); } else LOG_ERROR("MPIDR not in multiprocessor format"); diff --git a/src/target/armv7a.h b/src/target/armv7a.h index 1e88c98cf..9b1436c72 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -108,6 +108,8 @@ struct armv7a_common { struct adiv5_ap *debug_ap; /* mdir */ uint8_t multi_processor_system; + uint8_t multi_threading_processor; + uint8_t level2_id; uint8_t cluster_id; uint8_t cpu_id; bool is_armv7r; @@ -183,6 +185,9 @@ static inline bool is_armv7a(struct armv7a_common *armv7a) #define DBG_VCR_PREF_ABORT_MASK ((1 << 27) | (1 << 3)) #define DBG_VCR_SVC_MASK ((1 << 26) | (1 << 2)) +/* Masks for Multiprocessor Affinity Register */ +#define MPIDR_MP_EXT (1UL << 31) + int armv7a_arch_state(struct target *target); int armv7a_identify_cache(struct target *target); int armv7a_init_arch_info(struct target *target, struct armv7a_common *armv7a); From ae4b2720a49d666a065869f55e35130a5c689c3f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 6 Apr 2019 09:40:18 +0200 Subject: [PATCH 043/176] doc/openocd.texi: fix cross referencing Commit b04c7c2ca587feebd6506716cd84297212350608 adds the cross reference target "adapter_usb_location", but references it with the command @xref inside a text, where command @ref should be used. This triggers a compile warning: doc/openocd.texi:2517: warning: `.' or `,' must follow @xref, not c Replace @xref with @ref and adapt both the text and the command syntax. Change-Id: I1520ffecb7d1d375f924492b1884d5b47f399007 Fixes: b04c7c2ca587 ("ftdi: use "adapter usb location" instead of ftdi_location command") Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5045 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- doc/openocd.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index a5037b254..479bf34ec 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2514,7 +2514,7 @@ and are not restricted to containing only decimal digits.) @deffn {Config Command} {ftdi_location} -[.]... @emph{DEPRECATED -- avoid using this. -Use the @xref{adapter_usb_location, adapter usb location} command instead.} +Use the command @ref{adapter_usb_location,,adapter usb location} instead.} Specifies the physical USB port of the adapter to use. The path roots at @var{bus} and walks down the physical ports, with each From 537bbefcbd693d3c544c7d12e015d615193d0c82 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Thu, 4 Apr 2019 22:40:21 +0300 Subject: [PATCH 044/176] target/imx7ulp: Initial support Unlike imx7d/solo supported by imx7.cfg the M4 core is on a different AP and is always running by default so no -defer-examine is required. There is also only one Cortex-A7 Tested on imx7ulp-evk Change-Id: Ifa923d1b9a372c788e6654bc2233fd4d9073a32d Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5043 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx7ulp.cfg | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tcl/target/imx7ulp.cfg diff --git a/tcl/target/imx7ulp.cfg b/tcl/target/imx7ulp.cfg new file mode 100644 index 000000000..879fcf8cc --- /dev/null +++ b/tcl/target/imx7ulp.cfg @@ -0,0 +1,36 @@ +# +# NXP i.MX7ULP: Cortex-A7 + Cortex-M4 +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx7ulp +} + +# CoreSight Debug Access Port +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + # TAPID is from FreeScale! + set _DAP_TAPID 0x188e101d +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID + +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# Cortex-A7 +target create $_CHIPNAME.cpu_a7 cortex_a -dap $_CHIPNAME.dap \ + -coreid 0 -dbgbase 0x80030000 + +# Cortex-M4 +# Boots by default so don't defer examination +target create $_CHIPNAME.cpu_m4 cortex_m -dap $_CHIPNAME.dap -ap-num 3 + +# AHB main soc bus +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# Default is Cortex-A7 +targets $_CHIPNAME.cpu_a7 From b13055069c12fe0f8d60777b37f0df39d883e359 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Thu, 4 Apr 2019 22:25:49 +0300 Subject: [PATCH 045/176] target/imx6sx: Initial support Unlike the rest of imx6 a Cortex-M4 was added with a second CoreSight DAP so a separate script is required. Tested on imx6sx-sdb running linux Change-Id: I1561910b233015f42508f341175822c0827655ec Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5041 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx6sx.cfg | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tcl/target/imx6sx.cfg diff --git a/tcl/target/imx6sx.cfg b/tcl/target/imx6sx.cfg new file mode 100644 index 000000000..d3fae8a9b --- /dev/null +++ b/tcl/target/imx6sx.cfg @@ -0,0 +1,50 @@ +# +# Freescale i.MX6SoloX +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx6sx +} + +# 2x CoreSight Debug Access Port for Cortex-M4 and Cortex-A9 +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu_m4 -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID +dap create $_CHIPNAME.dap_m4 -chain-position $_CHIPNAME.cpu_m4 + +jtag newtap $_CHIPNAME cpu_a9 -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID +dap create $_CHIPNAME.dap_a9 -chain-position $_CHIPNAME.cpu_a9 + +# SDMA / no IDCODE +jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f + +# System JTAG Controller +if { [info exists SJC_TAPID] } { + set _SJC_TAPID $SJC_TAPID +} else { + set _SJC_TAPID 0x0891c01d +} +jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ + -expected-id $_SJC_TAPID -ignore-version + +# Cortex-A9 (boot core) +target create $_CHIPNAME.cpu_a9 cortex_a -dap $_CHIPNAME.dap_a9 \ + -coreid 0 -dbgbase 0x82150000 + +# Cortex-M4 (default off) +target create $_CHIPNAME.cpu_m4 cortex_m -dap $_CHIPNAME.dap_m4 \ + -ap-num 0 -defer-examine + +# AHB mem-ap target +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap_a9 -ap-num 0 + +# Default target is Cortex-A9 +targets $_CHIPNAME.cpu_a9 From 23836fc5be5cc57f04267bee10c451e667c95143 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Thu, 4 Apr 2019 16:19:55 +0300 Subject: [PATCH 046/176] target/imx6ul: Initial support Unlike the rest of imx6 the 6UL 6ULL 6ULZ chips are based on Cortex-A7 which is at a different address so a custom script is required. Tested on imx6ull-14x14-evk Change-Id: I72822d2241045c318389fadbc66d7aaabaaf4cb5 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5040 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx6ul.cfg | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tcl/target/imx6ul.cfg diff --git a/tcl/target/imx6ul.cfg b/tcl/target/imx6ul.cfg new file mode 100644 index 000000000..f42aa636e --- /dev/null +++ b/tcl/target/imx6ul.cfg @@ -0,0 +1,50 @@ +# +# Freescale i.MX6UltraLite series: 6UL 6ULL 6ULZ +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx6ul +} + +# CoreSight Debug Access Port +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID + +# SDMA / no IDCODE +jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f + +# System JTAG Controller +set _SJC_TAPID_6UL 0x0891d01d +set _SJC_TAPID_6ULL 0x0891e01d +set _SJC_TAPID_6ULZ 0x1891e01d + +# Allow external override of the first SJC TAPID +if { [info exists SJC_TAPID] } { + set _SJC_TAPID $SJC_TAPID +} else { + set _SJC_TAPID $_SJC_TAPID_6UL +} + +jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ + -ignore-version \ + -expected-id $_SJC_TAPID \ + -expected-id $_SJC_TAPID_6ULL \ + -expected-id $_SJC_TAPID_6ULZ \ + +# Create DAP +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# Main AHB bus +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# Cortex-A7 single core +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_a -dap $_CHIPNAME.dap -dbgbase 0x82130000 From c63c73c743f8948905c1ae1a25404e598153eaf2 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Wed, 3 Apr 2019 19:07:56 +0300 Subject: [PATCH 047/176] target/imx8m: Cleanup defaults * Add mem_ap for direct access to axi bus (without halting cpu) * Mark m4 core with -defer-examine because it's not used by default * Make a53.0 default target since it's the boot core Change-Id: Id031533c5d4af346eb08a9ac2532fa1bca602913 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5036 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/imx8m.cfg | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tcl/target/imx8m.cfg b/tcl/target/imx8m.cfg index 5d7acbed1..e3b7d24e1 100644 --- a/tcl/target/imx8m.cfg +++ b/tcl/target/imx8m.cfg @@ -52,7 +52,13 @@ for { set _core 0 } { $_core < $_cores } { incr _core } { } eval $_smp_command -targets $_TARGETNAME.0 # declare the auxiliary Cortex-M4 core on AP #4 -target create ${_CHIPNAME}.m4 cortex_m -dap ${_CHIPNAME}.dap -ap-num 4 +target create ${_CHIPNAME}.m4 cortex_m -dap ${_CHIPNAME}.dap -ap-num 4 \ + -defer-examine + +# AHB-AP for direct access to soc bus +target create ${_CHIPNAME}.ahb mem_ap -dap ${_CHIPNAME}.dap -ap-num 0 + +# default target is A53 core 0 +targets $_TARGETNAME.0 From bbdb820c82d65cd11abdc329eaa91d410690436e Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 8 Apr 2019 14:06:04 -0700 Subject: [PATCH 048/176] flash/fespi: Use COMMAND_PARSE_ADDRESS Signed-off-by: Tim Newsome Change-Id: If4d22fe1440f926271274820f96428718a127ac2 Reviewed-on: http://openocd.zylin.com/5100 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/fespi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c index 1c343a84c..5d8f810ad 100644 --- a/src/flash/nor/fespi.c +++ b/src/flash/nor/fespi.c @@ -159,9 +159,7 @@ FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command) fespi_info->probed = 0; fespi_info->ctrl_base = 0; if (CMD_ARGC >= 7) { - int temp; - COMMAND_PARSE_NUMBER(int, CMD_ARGV[6], temp); - fespi_info->ctrl_base = (uint32_t) temp; + COMMAND_PARSE_ADDRESS(CMD_ARGV[6], fespi_info->ctrl_base); LOG_DEBUG("ASSUMING FESPI device at ctrl_base = " TARGET_ADDR_FMT, fespi_info->ctrl_base); } From f78a7046a9c19696a660c4cbf8233cb145441ea5 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 7 Apr 2019 09:26:44 +0200 Subject: [PATCH 049/176] flash/nor/atsame5: fix typo in dsu_reset_deassert help text Change-Id: Iebed1a160376717d19c5f56b2553f7d4d1eed3a7 Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5095 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/flash/nor/atsame5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index df4234917..4a114a35f 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -896,7 +896,7 @@ static const struct command_registration same5_exec_command_handlers[] = { .usage = "", .handler = samd_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "Deasert internal reset held by DSU." + .help = "Deassert internal reset held by DSU." }, { .name = "chip-erase", From 7ee618692f56b0efea864890da45d73d28e393d9 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 7 Feb 2019 18:30:10 +0100 Subject: [PATCH 050/176] flash/nor/stm32h7x: use of wait queue flag instead of the busy flag Based on RM0433.rev5 > Section 3.3.9 : Flash program operations: QW1/2: this bit indicates that a write, erase or option byte change operation is pending in the write queue or command queue buffer. It remains high until the write operation is complete. It supersedes the BSY1/2 status bit. On this basis, stm32x_wait_status_busy is renamed accordingly to be 'stm32x_wait_flash_op_queue' Note : In this commit there is a fix of SR_ERROR_MASK value in flash loader algo Note : This modification is mandatory for revision X, and backward compatible with old revisions Change-Id: I59d2973317d76b01fbb0fb5e4a472a47d0a7a5b5 Signed-off-by: Laurent LEMELE Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/4883 Tested-by: jenkins Reviewed-by: Christopher Head Reviewed-by: Tomas Vanek --- contrib/loaders/flash/stm32/stm32h7x.S | 7 +++-- contrib/loaders/flash/stm32/stm32h7x.inc | 12 ++++---- src/flash/nor/stm32h7x.c | 37 ++++++++++++------------ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/contrib/loaders/flash/stm32/stm32h7x.S b/contrib/loaders/flash/stm32/stm32h7x.S index f910bfbb1..f0d32956f 100644 --- a/contrib/loaders/flash/stm32/stm32h7x.S +++ b/contrib/loaders/flash/stm32/stm32h7x.S @@ -48,8 +48,8 @@ #define STM32_FLASH_CR_OFFSET 0x0C /* offset of CR register in FLASH struct */ #define STM32_FLASH_SR_OFFSET 0x10 /* offset of SR register in FLASH struct */ #define STM32_CR_PROG 0x00000032 /* PSIZE64 | PG */ -#define STM32_SR_BUSY_MASK 0x00000001 /* BSY */ -#define STM32_SR_ERROR_MASK 0x03ee0000 /* DBECCERR | SNECCERR | RDSERR | RDPERR | OPERR +#define STM32_SR_QW_MASK 0x00000004 /* QW */ +#define STM32_SR_ERROR_MASK 0x07ee0000 /* DBECCERR | SNECCERR | RDSERR | RDPERR | OPERR | INCERR | STRBERR | PGSERR | WRPERR */ .thumb_func @@ -73,6 +73,7 @@ wait_fifo: mov r7, #8 /* program by 8 words = 32 bytes */ write_flash: + dsb ldr r6, [r5], #0x04 /* read one word from src, increment ptr */ str r6, [r2], #0x04 /* write one word to dst, increment ptr */ dsb @@ -84,7 +85,7 @@ write_flash: busy: ldr r6, [r4, #STM32_FLASH_SR_OFFSET] - tst r6, #STM32_SR_BUSY_MASK + tst r6, #STM32_SR_QW_MASK bne busy /* operation in progress, wait ... */ ldr r7, =STM32_SR_ERROR_MASK diff --git a/contrib/loaders/flash/stm32/stm32h7x.inc b/contrib/loaders/flash/stm32/stm32h7x.inc index 174354c76..ec14de0ef 100644 --- a/contrib/loaders/flash/stm32/stm32h7x.inc +++ b/contrib/loaders/flash/stm32/stm32h7x.inc @@ -1,7 +1,7 @@ /* Autogenerated with ../../../../src/helper/bin2char.sh */ -0x45,0x68,0x06,0x68,0x26,0xb3,0x76,0x1b,0x42,0xbf,0x76,0x18,0x36,0x1a,0x08,0x3e, -0x20,0x2e,0xf6,0xd3,0x4f,0xf0,0x32,0x06,0xe6,0x60,0x4f,0xf0,0x08,0x07,0x55,0xf8, -0x04,0x6b,0x42,0xf8,0x04,0x6b,0xbf,0xf3,0x4f,0x8f,0x8d,0x42,0x28,0xbf,0x00,0xf1, -0x08,0x05,0x01,0x3f,0xf3,0xd1,0x26,0x69,0x16,0xf0,0x01,0x0f,0xfb,0xd1,0x05,0x4f, -0x3e,0x42,0x03,0xd1,0x45,0x60,0x01,0x3b,0xdb,0xd1,0x01,0xe0,0x00,0x27,0x47,0x60, -0x30,0x46,0x00,0xbe,0x00,0x00,0xee,0x03, +0x45,0x68,0x06,0x68,0x36,0xb3,0x76,0x1b,0x42,0xbf,0x76,0x18,0x36,0x1a,0x08,0x3e, +0x20,0x2e,0xf6,0xd3,0x4f,0xf0,0x32,0x06,0xe6,0x60,0x4f,0xf0,0x08,0x07,0xbf,0xf3, +0x4f,0x8f,0x55,0xf8,0x04,0x6b,0x42,0xf8,0x04,0x6b,0xbf,0xf3,0x4f,0x8f,0x8d,0x42, +0x28,0xbf,0x00,0xf1,0x08,0x05,0x01,0x3f,0xf1,0xd1,0x26,0x69,0x16,0xf0,0x04,0x0f, +0xfb,0xd1,0x05,0x4f,0x3e,0x42,0x03,0xd1,0x45,0x60,0x01,0x3b,0xd9,0xd1,0x01,0xe0, +0x00,0x27,0x47,0x60,0x30,0x46,0x00,0xbe,0x00,0x00,0xee,0x07, diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 8bcc29cb1..2ee7ca2f1 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -61,6 +61,7 @@ /* FLASH_SR register bits */ #define FLASH_BSY (1 << 0) /* Operation in progress */ +#define FLASH_QW (1 << 2) /* Operation queue in progress */ #define FLASH_WRPERR (1 << 17) /* Write protection error */ #define FLASH_PGSERR (1 << 18) /* Programming sequence error */ #define FLASH_STRBERR (1 << 19) /* Strobe error */ @@ -132,7 +133,7 @@ struct stm32h7x_flash_bank { }; static const struct stm32h7x_rev stm32_450_revs[] = { - { 0x1000, "A" }, { 0x1001, "Z" }, { 0x1003, "Y" }, + { 0x1000, "A" }, { 0x1001, "Z" }, { 0x1003, "Y" }, { 0x2001, "X" }, }; static const struct stm32h7x_part_info stm32h7x_parts[] = { @@ -184,33 +185,33 @@ static inline int stm32x_get_flash_status(struct flash_bank *bank, uint32_t *sta return target_read_u32(target, stm32x_get_flash_reg(bank, FLASH_SR), status); } -static int stm32x_wait_status_busy(struct flash_bank *bank, int timeout) +static int stm32x_wait_flash_op_queue(struct flash_bank *bank, int timeout) { struct target *target = bank->target; struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv; uint32_t status; int retval; - /* wait for busy to clear */ + /* wait for flash operations completion */ for (;;) { retval = stm32x_get_flash_status(bank, &status); if (retval != ERROR_OK) { - LOG_INFO("wait_status_busy, target_read_u32 : error : remote address 0x%x", stm32x_info->flash_base); + LOG_INFO("wait_flash_op_queue, target_read_u32 : error : remote address 0x%x", stm32x_info->flash_base); return retval; } - if ((status & FLASH_BSY) == 0) + if ((status & FLASH_QW) == 0) break; if (timeout-- <= 0) { - LOG_INFO("wait_status_busy, time out expired, status: 0x%" PRIx32 "", status); + LOG_INFO("wait_flash_op_queue, time out expired, status: 0x%" PRIx32 "", status); return ERROR_FAIL; } alive_sleep(1); } if (status & FLASH_WRPERR) { - LOG_INFO("wait_status_busy, WRPERR : error : remote address 0x%x", stm32x_info->flash_base); + LOG_INFO("wait_flash_op_queue, WRPERR : error : remote address 0x%x", stm32x_info->flash_base); retval = ERROR_FAIL; } @@ -393,14 +394,14 @@ static int stm32x_write_options(struct flash_bank *bank) uint32_t status; retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_SR, &status); if (retval != ERROR_OK) { - LOG_INFO("stm32x_write_options: wait_status_busy : error"); + LOG_INFO("stm32x_write_options: wait_flash_op_queue : error"); return retval; } - if ((status & FLASH_BSY) == 0) + if ((status & FLASH_QW) == 0) break; if (timeout-- <= 0) { - LOG_INFO("wait_status_busy, time out expired, status: 0x%" PRIx32 "", status); + LOG_INFO("wait_flash_op_queue, time out expired, status: 0x%" PRIx32 "", status); return ERROR_FAIL; } alive_sleep(1); @@ -459,12 +460,12 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last) /* Sector Erase To erase a sector, follow the procedure below: - 1. Check that no Flash memory operation is ongoing by checking the BSY bit in the + 1. Check that no Flash memory operation is ongoing by checking the QW bit in the FLASH_SR register 2. Set the SER bit and select the sector you wish to erase (SNB) in the FLASH_CR register 3. Set the STRT bit in the FLASH_CR register - 4. Wait for the BSY bit to be cleared + 4. Wait for flash operations completion */ for (int i = first; i <= last; i++) { LOG_DEBUG("erase sector %d", i); @@ -480,7 +481,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last) LOG_ERROR("Error erase sector %d", i); return retval; } - retval = stm32x_wait_status_busy(bank, FLASH_ERASE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_ERASE_TIMEOUT); if (retval != ERROR_OK) { LOG_ERROR("erase time-out or operation error sector %d", i); @@ -687,11 +688,11 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, /* Standard programming The Flash memory programming sequence is as follows: - 1. Check that no main Flash memory operation is ongoing by checking the BSY bit in the + 1. Check that no main Flash memory operation is ongoing by checking the QW bit in the FLASH_SR register. 2. Set the PG bit in the FLASH_CR register 3. 8 x Word access (or Force Write FW) - 4. Wait for the BSY bit to be cleared + 4. Wait for flash operations completion */ while (blocks_remaining > 0) { retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_PG | FLASH_PSIZE_64); @@ -702,7 +703,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, if (retval != ERROR_OK) goto flash_lock; - retval = stm32x_wait_status_busy(bank, FLASH_WRITE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT); if (retval != ERROR_OK) goto flash_lock; @@ -725,7 +726,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, if (retval != ERROR_OK) goto flash_lock; - retval = stm32x_wait_status_busy(bank, FLASH_WRITE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT); if (retval != ERROR_OK) goto flash_lock; } @@ -1038,7 +1039,7 @@ static int stm32x_mass_erase(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - retval = stm32x_wait_status_busy(bank, 30000); + retval = stm32x_wait_flash_op_queue(bank, 30000); if (retval != ERROR_OK) return retval; From 250185c096bab341f99fb984aebda671d55e1ab0 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Wed, 24 Apr 2019 17:26:40 -0700 Subject: [PATCH 051/176] stm32h7x: fix incorrect indentation Change-Id: I5dc16031c38576d853774b6123c93be1e1b4aa96 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5133 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/stm32h7x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 2ee7ca2f1..90bc8f393 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -362,26 +362,26 @@ static int stm32x_write_options(struct flash_bank *bank) /* program options */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTPRG, optiondata); - if (retval != ERROR_OK) - return retval; + if (retval != ERROR_OK) + return retval; optiondata = stm32x_info->option_bytes.protection & 0xff; /* Program protection WPSNPRG */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSNPRG, optiondata); - if (retval != ERROR_OK) - return retval; + if (retval != ERROR_OK) + return retval; optiondata = stm32x_info->option_bytes.protection2 & 0xff; /* Program protection WPSNPRG2 */ retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSNPRG, optiondata); - if (retval != ERROR_OK) - return retval; + if (retval != ERROR_OK) + return retval; optiondata = 0x40000000; /* Remove OPT error flag before programming */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCCR, optiondata); - if (retval != ERROR_OK) - return retval; + if (retval != ERROR_OK) + return retval; /* start programming cycle */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCR, OPT_START); From 1ce51507a146e7089e1c78a564dd246a2f245433 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 13 Mar 2019 21:31:57 +0100 Subject: [PATCH 052/176] target: rewrite jim_target_event_list to handle_target_event_list jim_target_event_list handler used command_print() in jim handler. Rewriting the jim handler to the OpenOCD command is easy as get_current_target() returns proper target for prefixed commands since bb9d9c60264a905926e0d15f84842858d0de80b7 Change-Id: I3e937249386ca5dbd7a5dd6ebb0ccde0911325d8 Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4993 Tested-by: jenkins --- src/target/target.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index bcc2c5e2e..439545416 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5364,27 +5364,25 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a /* List for human, Events defined for this target. * scripts/programs should use 'name cget -event NAME' */ -static int jim_target_event_list(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +COMMAND_HANDLER(handle_target_event_list) { - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx != NULL); - - struct target *target = Jim_CmdPrivData(interp); + struct target *target = get_current_target(CMD_CTX); struct target_event_action *teap = target->event_action; - command_print(cmd_ctx, "Event actions for target (%d) %s\n", + + command_print(CMD_CTX, "Event actions for target (%d) %s\n", target->target_number, target_name(target)); - command_print(cmd_ctx, "%-25s | Body", "Event"); - command_print(cmd_ctx, "------------------------- | " + command_print(CMD_CTX, "%-25s | Body", "Event"); + command_print(CMD_CTX, "------------------------- | " "----------------------------------------"); while (teap) { Jim_Nvp *opt = Jim_Nvp_value2name_simple(nvp_target_event, teap->event); - command_print(cmd_ctx, "%-25s | %s", + command_print(CMD_CTX, "%-25s | %s", opt->name, Jim_GetString(teap->body, NULL)); teap = teap->next; } - command_print(cmd_ctx, "***END***"); - return JIM_OK; + command_print(CMD_CTX, "***END***"); + return ERROR_OK; } static int jim_target_current_state(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { @@ -5491,9 +5489,10 @@ static const struct command_registration target_instance_command_handlers[] = { }, { .name = "eventlist", + .handler = handle_target_event_list, .mode = COMMAND_EXEC, - .jim_handler = jim_target_event_list, .help = "displays a table of events defined for this target", + .usage = "", }, { .name = "curstate", From 5e027407e35e898fc4f87abeaef4b8177a51854b Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Tue, 26 Mar 2019 11:55:37 +0100 Subject: [PATCH 053/176] target/arm946e: rewrite jim_arm946e_cp15 to arm945e_handle_cp15 jim_arm946e_cp15() used command_print() in the jim handler. Change-Id: I0a258aad5a60f45672b9b6fa6819691507d4f0f6 Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5000 Tested-by: jenkins --- src/target/arm946e.c | 70 +++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 5e25d71ec..073381431 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -549,70 +549,54 @@ int arm946e_read_memory(struct target *target, target_addr_t address, return ERROR_OK; } -static int jim_arm946e_cp15(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +COMMAND_HANDLER(arm946e_handle_cp15) { /* one or two arguments, access a single register (write if second argument is given) */ - if (argc < 2 || argc > 3) { - Jim_WrongNumArgs(interp, 1, argv, "addr [value]"); - return JIM_ERR; - } + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx != NULL); - - struct target *target = get_current_target(cmd_ctx); - if (target == NULL) { - LOG_ERROR("arm946e: no current target"); - return JIM_ERR; - } + struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - int retval = arm946e_verify_pointer(cmd_ctx, arm946e); + int retval = arm946e_verify_pointer(CMD_CTX, arm946e); if (retval != ERROR_OK) - return JIM_ERR; - - if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target %s must be stopped for \"cp15\" command", target_name(target)); - return JIM_ERR; - } - - long l; - uint32_t address; - retval = Jim_GetLong(interp, argv[1], &l); - address = l; - if (JIM_OK != retval) return retval; - if (argc == 2) { + if (target->state != TARGET_HALTED) { + command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + return ERROR_TARGET_NOT_HALTED; + } + + uint32_t address; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); + + if (CMD_ARGC == 1) { uint32_t value; retval = arm946e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } retval = jtag_execute_queue(); if (retval != ERROR_OK) - return JIM_ERR; - char buf[20]; - sprintf(buf, "0x%08" PRIx32, value); - /* Return value in hex format */ - Jim_SetResultString(interp, buf, -1); - } else if (argc == 3) { - uint32_t value; - retval = Jim_GetLong(interp, argv[2], &l); - value = l; - if (JIM_OK != retval) return retval; + + /* Return value in hex format */ + command_print(CMD_CTX, "0x%08" PRIx32, value); + } else if (CMD_ARGC == 2) { + uint32_t value; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); + retval = arm946e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } if (address == CP15_CTL) arm946e_update_cp15_caches(target, value); } - return JIM_OK; + return ERROR_OK; } COMMAND_HANDLER(arm946e_handle_idcache) @@ -703,7 +687,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) static const struct command_registration arm946e_exec_command_handlers[] = { { .name = "cp15", - .jim_handler = jim_arm946e_cp15, + .handler = arm946e_handle_cp15, .mode = COMMAND_EXEC, .usage = "regnum [value]", .help = "read/modify cp15 register", From 84cfb727dfce2725d91af9f506bca49c8bb15de2 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 31 Mar 2019 17:55:43 +0200 Subject: [PATCH 054/176] helper/command: add macro CMD Accessing the variable "cmd" in a COMMAND_HANDLER is confusing because the variable definition is not visible in the prototype, thus "cmd" can be identified by the reader as a global variable defined somewhere else. Add the new macro CMD to make more evident it is a part of the COMMAND_HANDLER. Change-Id: I8f63da593a931045cc404323f143b88c5c80ab5e Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5047 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/helper/command.h b/src/helper/command.h index f9c02e573..9aed2827c 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -121,6 +121,11 @@ struct command_invocation { */ #define COMMAND_HELPER(name, extra ...) __COMMAND_HANDLER(name, extra) +/** + * Use this macro to access the command being handled, + * rather than accessing the variable directly. It may be moved. + */ +#define CMD (cmd) /** * Use this macro to access the context of the command being handled, * rather than accessing the variable directly. It may be moved. From 74cd25a4d39d85caeb275f178c1c93b4ff334810 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 1 Apr 2019 08:44:26 +0200 Subject: [PATCH 055/176] target: change prototype of target_process_reset() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of target_process_reset() to pass CMD instead of CMD_CTX. Replace NULL parameter of command_print(). Remove extra newline, already added by command_print(). Change-Id: Ieb820c2586e1ff74a0c2b63a9c8693ca7710dfb7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5048 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 439545416..28e67bf75 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -640,7 +640,7 @@ int target_resume(struct target *target, int current, target_addr_t address, return retval; } -static int target_process_reset(struct command_context *cmd_ctx, enum target_reset_mode reset_mode) +static int target_process_reset(struct command_invocation *cmd, enum target_reset_mode reset_mode) { char buf[100]; int retval; @@ -664,13 +664,13 @@ static int target_process_reset(struct command_context *cmd_ctx, enum target_res jtag_poll_set_enabled(false); sprintf(buf, "ocd_process_reset %s", n->name); - retval = Jim_Eval(cmd_ctx->interp, buf); + retval = Jim_Eval(cmd->ctx->interp, buf); jtag_poll_set_enabled(save_poll); if (retval != JIM_OK) { - Jim_MakeErrorMessage(cmd_ctx->interp); - command_print(NULL, "%s\n", Jim_GetString(Jim_GetResult(cmd_ctx->interp), NULL)); + Jim_MakeErrorMessage(cmd->ctx->interp); + command_print(cmd->ctx, "%s", Jim_GetString(Jim_GetResult(cmd->ctx->interp), NULL)); return ERROR_FAIL; } @@ -3079,7 +3079,7 @@ COMMAND_HANDLER(handle_reset_command) } /* reset *all* targets */ - return target_process_reset(CMD_CTX, reset_mode); + return target_process_reset(CMD, reset_mode); } From b3ce5a0ae5453a879a36856b5d8453722ba0f9b5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 1 Apr 2019 10:34:25 +0200 Subject: [PATCH 056/176] target: use LOG_USER to print errors in events Events are supposed to be executed asynchronously and not linked with any command, so it's incorrect printing out an eventual error using command_print(). Even in the case of events triggered by the command invoke-event the eventual error in the event handler is not propagated to the command, so the command_print() is still not appropriate. Replace command_print() with LOG_USER() in target_handle_event(). Add further info in the log to identify which event has generated the error and its associated target. Before return, clean-up the error message and the stacktrace from the error already displayed, to avoid propagate them. Change-Id: I5966aa25e7c81348f4ad4d6e7ce5d4dee44ea4c8 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5049 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 28e67bf75..14b6b0b99 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4553,7 +4553,12 @@ void target_handle_event(struct target *target, enum target_event e) if (Jim_EvalObj(teap->interp, teap->body) != JIM_OK) { Jim_MakeErrorMessage(teap->interp); - command_print(NULL, "%s\n", Jim_GetString(Jim_GetResult(teap->interp), NULL)); + LOG_USER("Error executing event %s on target %s:\n%s", + Jim_Nvp_value2name_simple(nvp_target_event, e)->name, + target_name(target), + Jim_GetString(Jim_GetResult(teap->interp), NULL)); + /* clean both error code and stacktrace before return */ + Jim_Eval(teap->interp, "error \"\" \"\""); } cmd_ctx->current_target_override = saved_target_override; From 79a92d467dae86eefee57ab7170f61cc51d9b0be Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 2 Apr 2019 16:25:52 +0200 Subject: [PATCH 057/176] target: unify memory read/write commands Current code provides two independent implementations for the memory read/write commands: a) jim_target_md()/jim_target_mw() for the target specific commands " m[dw][bhw]" b) handle_md_command()/handle_mw_command() for the current target commands "m[dw][bhwd]" The case a) misses the handling of doubleword and calls functions command_print_sameline() with first parameter NULL because defined as jim handler. Remove the code in jim_target_md()/jim_target_mw() and use the same code in b) for the target specific memory read/write. This approach also provides support for 64-bit data size, not present in the implementation in a). The only drawback is that the implementation of memory read in b) prints the data also as human readable ASCII characters, feature missing in the implementation in a). This could introduced later if it's really needed. Update the documentation to: - add 64-bit support - add phys parameter - add the count parameter Add attribute "unused" to target_buffer_get_u8(), now not used anymore. Change-Id: Ib11ff924c409ad87e77fe708d628b2cc82b74d6a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5050 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/openocd.texi | 42 +++++--- src/target/target.c | 258 +++++--------------------------------------- 2 files changed, 54 insertions(+), 246 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 479bf34ec..069208b36 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4688,23 +4688,35 @@ Invokes the handler for the event named @var{event_name}. code, for example by the reset code in @file{startup.tcl}.) @end deffn -@deffn Command {$target_name mdw} addr [count] -@deffnx Command {$target_name mdh} addr [count] -@deffnx Command {$target_name mdb} addr [count] +@deffn Command {$target_name mdd} [phys] addr [count] +@deffnx Command {$target_name mdw} [phys] addr [count] +@deffnx Command {$target_name mdh} [phys] addr [count] +@deffnx Command {$target_name mdb} [phys] addr [count] Display contents of address @var{addr}, as +64-bit doublewords (@command{mdd}), 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}), or 8-bit bytes (@command{mdb}). +When the current target has an MMU which is present and active, +@var{addr} is interpreted as a virtual address. +Otherwise, or if the optional @var{phys} flag is specified, +@var{addr} is interpreted as a physical address. If @var{count} is specified, displays that many units. (If you want to manipulate the data instead of displaying it, see the @code{mem2array} primitives.) @end deffn -@deffn Command {$target_name mww} addr word -@deffnx Command {$target_name mwh} addr halfword -@deffnx Command {$target_name mwb} addr byte -Writes the specified @var{word} (32 bits), -@var{halfword} (16 bits), or @var{byte} (8-bit) pattern, +@deffn Command {$target_name mwd} [phys] addr doubleword [count] +@deffnx Command {$target_name mww} [phys] addr word [count] +@deffnx Command {$target_name mwh} [phys] addr halfword [count] +@deffnx Command {$target_name mwb} [phys] addr byte [count] +Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits), +@var{halfword} (16 bits), or @var{byte} (8-bit) value, at the specified address @var{addr}. +When the current target has an MMU which is present and active, +@var{addr} is interpreted as a virtual address. +Otherwise, or if the optional @var{phys} flag is specified, +@var{addr} is interpreted as a physical address. +If @var{count} is specified, fills that many units of consecutive address. @end deffn @anchor{targetevents} @@ -7945,10 +7957,12 @@ Please use their TARGET object siblings to avoid making assumptions about what TAP is the current target, or about MMU configuration. @end enumerate -@deffn Command mdw [phys] addr [count] +@deffn Command mdd [phys] addr [count] +@deffnx Command mdw [phys] addr [count] @deffnx Command mdh [phys] addr [count] @deffnx Command mdb [phys] addr [count] Display contents of address @var{addr}, as +64-bit doublewords (@command{mdd}), 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}), or 8-bit bytes (@command{mdb}). When the current target has an MMU which is present and active, @@ -7960,16 +7974,18 @@ If @var{count} is specified, displays that many units. see the @code{mem2array} primitives.) @end deffn -@deffn Command mww [phys] addr word -@deffnx Command mwh [phys] addr halfword -@deffnx Command mwb [phys] addr byte -Writes the specified @var{word} (32 bits), +@deffn Command mwd [phys] addr doubleword [count] +@deffnx Command mww [phys] addr word [count] +@deffnx Command mwh [phys] addr halfword [count] +@deffnx Command mwb [phys] addr byte [count] +Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits), @var{halfword} (16 bits), or @var{byte} (8-bit) value, at the specified address @var{addr}. When the current target has an MMU which is present and active, @var{addr} is interpreted as a virtual address. Otherwise, or if the optional @var{phys} flag is specified, @var{addr} is interpreted as a physical address. +If @var{count} is specified, fills that many units of consecutive address. @end deffn @anchor{imageaccess} diff --git a/src/target/target.c b/src/target/target.c index 14b6b0b99..7946f76fa 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -376,7 +376,7 @@ uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer) } /* read a uint8_t from a buffer in target memory endianness */ -static uint8_t target_buffer_get_u8(struct target *target, const uint8_t *buffer) +static __attribute__((unused)) uint8_t target_buffer_get_u8(struct target *target, const uint8_t *buffer) { return *buffer & 0x0ff; } @@ -4934,228 +4934,6 @@ static int jim_target_configure(Jim_Interp *interp, int argc, Jim_Obj * const *a return target_configure(&goi, target); } -static int jim_target_mw(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - const char *cmd_name = Jim_GetString(argv[0], NULL); - - Jim_GetOptInfo goi; - Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); - - if (goi.argc < 2 || goi.argc > 4) { - Jim_SetResultFormatted(goi.interp, - "usage: %s [phys]
[]", cmd_name); - return JIM_ERR; - } - - target_write_fn fn; - fn = target_write_memory; - - int e; - if (strcmp(Jim_GetString(argv[1], NULL), "phys") == 0) { - /* consume it */ - struct Jim_Obj *obj; - e = Jim_GetOpt_Obj(&goi, &obj); - if (e != JIM_OK) - return e; - - fn = target_write_phys_memory; - } - - jim_wide a; - e = Jim_GetOpt_Wide(&goi, &a); - if (e != JIM_OK) - return e; - - jim_wide b; - e = Jim_GetOpt_Wide(&goi, &b); - if (e != JIM_OK) - return e; - - jim_wide c = 1; - if (goi.argc == 1) { - e = Jim_GetOpt_Wide(&goi, &c); - if (e != JIM_OK) - return e; - } - - /* all args must be consumed */ - if (goi.argc != 0) - return JIM_ERR; - - struct target *target = Jim_CmdPrivData(goi.interp); - unsigned data_size; - if (strcasecmp(cmd_name, "mww") == 0) - data_size = 4; - else if (strcasecmp(cmd_name, "mwh") == 0) - data_size = 2; - else if (strcasecmp(cmd_name, "mwb") == 0) - data_size = 1; - else { - LOG_ERROR("command '%s' unknown: ", cmd_name); - return JIM_ERR; - } - - return (target_fill_mem(target, a, fn, data_size, b, c) == ERROR_OK) ? JIM_OK : JIM_ERR; -} - -/** -* @brief Reads an array of words/halfwords/bytes from target memory starting at specified address. -* -* Usage: mdw [phys]
[] - for 32 bit reads -* mdh [phys]
[] - for 16 bit reads -* mdb [phys]
[] - for 8 bit reads -* -* Count defaults to 1. -* -* Calls target_read_memory or target_read_phys_memory depending on -* the presence of the "phys" argument -* Reads the target memory in blocks of max. 32 bytes, and returns an array of ints formatted -* to int representation in base16. -* Also outputs read data in a human readable form using command_print -* -* @param phys if present target_read_phys_memory will be used instead of target_read_memory -* @param address address where to start the read. May be specified in decimal or hex using the standard "0x" prefix -* @param count optional count parameter to read an array of values. If not specified, defaults to 1. -* @returns: JIM_ERR on error or JIM_OK on success and sets the result string to an array of ascii formatted numbers -* on success, with [] number of elements. -* -* In case of little endian target: -* Example1: "mdw 0x00000000" returns "10123456" -* Exmaple2: "mdh 0x00000000 1" returns "3456" -* Example3: "mdb 0x00000000" returns "56" -* Example4: "mdh 0x00000000 2" returns "3456 1012" -* Example5: "mdb 0x00000000 3" returns "56 34 12" -**/ -static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - const char *cmd_name = Jim_GetString(argv[0], NULL); - - Jim_GetOptInfo goi; - Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); - - if ((goi.argc < 1) || (goi.argc > 3)) { - Jim_SetResultFormatted(goi.interp, - "usage: %s [phys]
[]", cmd_name); - return JIM_ERR; - } - - int (*fn)(struct target *target, - target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer); - fn = target_read_memory; - - int e; - if (strcmp(Jim_GetString(argv[1], NULL), "phys") == 0) { - /* consume it */ - struct Jim_Obj *obj; - e = Jim_GetOpt_Obj(&goi, &obj); - if (e != JIM_OK) - return e; - - fn = target_read_phys_memory; - } - - /* Read address parameter */ - jim_wide addr; - e = Jim_GetOpt_Wide(&goi, &addr); - if (e != JIM_OK) - return JIM_ERR; - - /* If next parameter exists, read it out as the count parameter, if not, set it to 1 (default) */ - jim_wide count; - if (goi.argc == 1) { - e = Jim_GetOpt_Wide(&goi, &count); - if (e != JIM_OK) - return JIM_ERR; - } else - count = 1; - - /* all args must be consumed */ - if (goi.argc != 0) - return JIM_ERR; - - jim_wide dwidth = 1; /* shut up gcc */ - if (strcasecmp(cmd_name, "mdw") == 0) - dwidth = 4; - else if (strcasecmp(cmd_name, "mdh") == 0) - dwidth = 2; - else if (strcasecmp(cmd_name, "mdb") == 0) - dwidth = 1; - else { - LOG_ERROR("command '%s' unknown: ", cmd_name); - return JIM_ERR; - } - - /* convert count to "bytes" */ - int bytes = count * dwidth; - - struct target *target = Jim_CmdPrivData(goi.interp); - uint8_t target_buf[32]; - jim_wide x, y, z; - while (bytes > 0) { - y = (bytes < 16) ? bytes : 16; /* y = min(bytes, 16); */ - - /* Try to read out next block */ - e = fn(target, addr, dwidth, y / dwidth, target_buf); - - if (e != ERROR_OK) { - Jim_SetResultFormatted(interp, "error reading target @ 0x%08lx", (long)addr); - return JIM_ERR; - } - - command_print_sameline(NULL, "0x%08x ", (int)(addr)); - switch (dwidth) { - case 4: - for (x = 0; x < 16 && x < y; x += 4) { - z = target_buffer_get_u32(target, &(target_buf[x])); - command_print_sameline(NULL, "%08x ", (int)(z)); - } - for (; (x < 16) ; x += 4) - command_print_sameline(NULL, " "); - break; - case 2: - for (x = 0; x < 16 && x < y; x += 2) { - z = target_buffer_get_u16(target, &(target_buf[x])); - command_print_sameline(NULL, "%04x ", (int)(z)); - } - for (; (x < 16) ; x += 2) - command_print_sameline(NULL, " "); - break; - case 1: - default: - for (x = 0 ; (x < 16) && (x < y) ; x += 1) { - z = target_buffer_get_u8(target, &(target_buf[x])); - command_print_sameline(NULL, "%02x ", (int)(z)); - } - for (; (x < 16) ; x += 1) - command_print_sameline(NULL, " "); - break; - } - /* ascii-ify the bytes */ - for (x = 0 ; x < y ; x++) { - if ((target_buf[x] >= 0x20) && - (target_buf[x] <= 0x7e)) { - /* good */ - } else { - /* smack it */ - target_buf[x] = '.'; - } - } - /* space pad */ - while (x < 16) { - target_buf[x] = ' '; - x++; - } - /* terminate */ - target_buf[16] = 0; - /* print - with a newline */ - command_print_sameline(NULL, "%s\n", target_buf); - /* NEXT... */ - bytes -= 16; - addr += 16; - } - return JIM_OK; -} - static int jim_target_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { @@ -5435,44 +5213,58 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "target_attribute", }, { - .name = "mww", + .name = "mwd", + .handler = handle_mw_command, + .mode = COMMAND_EXEC, + .help = "Write 64-bit word(s) to target memory", + .usage = "address data [count]", + }, + { + .name = "mww", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write 32-bit word(s) to target memory", .usage = "address data [count]", }, { .name = "mwh", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write 16-bit half-word(s) to target memory", .usage = "address data [count]", }, { .name = "mwb", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write byte(s) to target memory", .usage = "address data [count]", }, { - .name = "mdw", + .name = "mdd", + .handler = handle_md_command, + .mode = COMMAND_EXEC, + .help = "Display target memory as 64-bit words", + .usage = "address [count]", + }, + { + .name = "mdw", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 32-bit words", .usage = "address [count]", }, { .name = "mdh", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 16-bit half-words", .usage = "address [count]", }, { .name = "mdb", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 8-bit bytes", .usage = "address [count]", }, @@ -6436,7 +6228,7 @@ static const struct command_registration target_exec_command_handlers[] = { .name = "mdd", .handler = handle_md_command, .mode = COMMAND_EXEC, - .help = "display memory words", + .help = "display memory double-words", .usage = "['phys'] address [count]", }, { @@ -6464,7 +6256,7 @@ static const struct command_registration target_exec_command_handlers[] = { .name = "mwd", .handler = handle_mw_command, .mode = COMMAND_EXEC, - .help = "write memory word", + .help = "write memory double-word", .usage = "['phys'] address value [count]", }, { From ce6340d8ce76af4fdb0ce1011863f5312ae1d8ee Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 3 Apr 2019 10:14:29 +0200 Subject: [PATCH 058/176] target_request: replace command_print() with command_output_text() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. When dumping traces or semihosting text, the command that enabled it is already completed, so CMD is not a valid value. Plus, we want the dump to be printed in the command context where the enable command was executed. Replace command_print() with command_output_text(). Change-Id: I297a2b799a914233499641062407cf6e8b9fe012 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5051 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target_request.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/target_request.c b/src/target/target_request.c index 6ca204b50..2df29587f 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -56,7 +56,7 @@ static int target_asciimsg(struct target *target, uint32_t length) LOG_DEBUG("%s", msg); while (c) { - command_print(c->cmd_ctx, "%s", msg); + command_output_text(c->cmd_ctx, msg); c = c->next; } @@ -100,7 +100,7 @@ static int target_hexmsg(struct target *target, int size, uint32_t length) LOG_DEBUG("%s", line); while (c) { - command_print(c->cmd_ctx, "%s", line); + command_output_text(c->cmd_ctx, line); c = c->next; } c = target->dbgmsg; From dae5a32c05f66e86202fef827454469853d2be8e Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 31 Mar 2019 18:18:01 +0200 Subject: [PATCH 059/176] nand/fileio: change prototype of nand_fileio_start() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of nand_fileio_start() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I7993f6aba997a2d2917949563651c8d0c213730d Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5052 Tested-by: jenkins --- src/flash/nand/fileio.c | 8 ++++---- src/flash/nand/fileio.h | 2 +- src/flash/nand/tcl.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/flash/nand/fileio.c b/src/flash/nand/fileio.c index 64c32c0a8..76f6e104a 100644 --- a/src/flash/nand/fileio.c +++ b/src/flash/nand/fileio.c @@ -54,12 +54,12 @@ void nand_fileio_init(struct nand_fileio_state *state) state->oob_format = NAND_OOB_NONE; } -int nand_fileio_start(struct command_context *cmd_ctx, +int nand_fileio_start(struct command_invocation *cmd, struct nand_device *nand, const char *filename, int filemode, struct nand_fileio_state *state) { if (state->address % nand->page_size) { - command_print(cmd_ctx, "only page-aligned addresses are supported"); + command_print(cmd->ctx, "only page-aligned addresses are supported"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -69,7 +69,7 @@ int nand_fileio_start(struct command_context *cmd_ctx, int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY); if (ERROR_OK != retval) { const char *msg = (FILEIO_READ == filemode) ? "read" : "write"; - command_print(cmd_ctx, "failed to open '%s' for %s access", + command_print(cmd->ctx, "failed to open '%s' for %s access", filename, msg); return retval; } @@ -161,7 +161,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, } } - retval = nand_fileio_start(CMD_CTX, nand, CMD_ARGV[1], filemode, state); + retval = nand_fileio_start(CMD, nand, CMD_ARGV[1], filemode, state); if (ERROR_OK != retval) return retval; diff --git a/src/flash/nand/fileio.h b/src/flash/nand/fileio.h index af6c7666e..6a094c2f2 100644 --- a/src/flash/nand/fileio.h +++ b/src/flash/nand/fileio.h @@ -41,7 +41,7 @@ struct nand_fileio_state { }; void nand_fileio_init(struct nand_fileio_state *state); -int nand_fileio_start(struct command_context *cmd_ctx, +int nand_fileio_start(struct command_invocation *cmd, struct nand_device *nand, const char *filename, int filemode, struct nand_fileio_state *state); int nand_fileio_cleanup(struct nand_fileio_state *state); diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c index dee4f6da8..5e8b46e81 100644 --- a/src/flash/nand/tcl.c +++ b/src/flash/nand/tcl.c @@ -294,7 +294,7 @@ COMMAND_HANDLER(handle_nand_verify_command) dev.address = file.address; dev.size = file.size; dev.oob_format = file.oob_format; - retval = nand_fileio_start(CMD_CTX, nand, NULL, FILEIO_NONE, &dev); + retval = nand_fileio_start(CMD, nand, NULL, FILEIO_NONE, &dev); if (ERROR_OK != retval) return retval; From 962267ba1a3b71cf50407bb6a9b3b2d1cb8cdf85 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 31 Mar 2019 18:34:25 +0200 Subject: [PATCH 060/176] nand/tcl: pass CMD to nand_list_walker() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Pass CMD instead of CMD_CTX as parameter to nand_list_walker(). This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ia11887dfc6dc58d5458a88ba84780cd895b8c253 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5053 Tested-by: jenkins --- src/flash/nand/tcl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c index 5e8b46e81..8a7022aeb 100644 --- a/src/flash/nand/tcl.c +++ b/src/flash/nand/tcl.c @@ -501,15 +501,15 @@ COMMAND_HANDLER(handle_nand_init_command) static int nand_list_walker(struct nand_flash_controller *c, void *x) { - struct command_context *cmd_ctx = x; - command_print(cmd_ctx, " %s", c->name); + struct command_invocation *cmd = x; + command_print(cmd->ctx, " %s", c->name); return ERROR_OK; } COMMAND_HANDLER(handle_nand_list_drivers) { command_print(CMD_CTX, "Available NAND flash controller drivers:"); - return nand_driver_walk(&nand_list_walker, CMD_CTX); + return nand_driver_walk(&nand_list_walker, CMD); } static COMMAND_HELPER(create_nand_device, const char *bank_name, From 30de1bfda4ea0fd4cd01a2055df463767b979ed4 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 03:45:54 +0200 Subject: [PATCH 061/176] nor/at91sam3: change prototype of get_current_sam3() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of get_current_sam3() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ia1e7af79d0fc89d229b4e10df37317a374bbab62 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5054 Tested-by: jenkins --- src/flash/nor/at91sam3.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index a220279cf..616c3fe9d 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -249,14 +249,14 @@ struct sam3_reg_list { static struct sam3_chip *all_sam3_chips; -static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) +static struct sam3_chip *get_current_sam3(struct command_invocation *cmd) { struct target *t; static struct sam3_chip *p; - t = get_current_target(cmd_ctx); + t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd_ctx, "No current target?"); + command_print(cmd->ctx, "No current target?"); return NULL; } @@ -264,7 +264,7 @@ static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd_ctx, "No SAM3 chips exist?"); + command_print(cmd->ctx, "No SAM3 chips exist?"); return NULL; } @@ -273,7 +273,7 @@ static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) return p; p = p->next; } - command_print(cmd_ctx, "Cannot find SAM3 chip?"); + command_print(cmd->ctx, "Cannot find SAM3 chip?"); return NULL; } @@ -3538,7 +3538,7 @@ done: COMMAND_HANDLER(sam3_handle_info_command) { struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; @@ -3598,7 +3598,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) int r, who; struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; @@ -3682,7 +3682,7 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) { struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; From d06b952376d04a11fd1d53a899424e18b47564b5 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 03:50:38 +0200 Subject: [PATCH 062/176] nor/at91sam4: change prototype of get_current_sam4() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of get_current_sam4() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I8dfa66f3f6be318d6ba89649279b1b4502f375d9 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5055 Tested-by: jenkins --- src/flash/nor/at91sam4.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index c89c50239..719da2bb2 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -228,14 +228,14 @@ struct sam4_reg_list { static struct sam4_chip *all_sam4_chips; -static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) +static struct sam4_chip *get_current_sam4(struct command_invocation *cmd) { struct target *t; static struct sam4_chip *p; - t = get_current_target(cmd_ctx); + t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd_ctx, "No current target?"); + command_print(cmd->ctx, "No current target?"); return NULL; } @@ -243,7 +243,7 @@ static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd_ctx, "No SAM4 chips exist?"); + command_print(cmd->ctx, "No SAM4 chips exist?"); return NULL; } @@ -252,7 +252,7 @@ static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) return p; p = p->next; } - command_print(cmd_ctx, "Cannot find SAM4 chip?"); + command_print(cmd->ctx, "Cannot find SAM4 chip?"); return NULL; } @@ -3018,7 +3018,7 @@ done: COMMAND_HANDLER(sam4_handle_info_command) { struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; @@ -3078,7 +3078,7 @@ COMMAND_HANDLER(sam4_handle_gpnvm_command) int r, who; struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; @@ -3163,7 +3163,7 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) { struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; From fce3b698fb3785dbec23d6cc4496120b69ae7613 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:32:12 +0200 Subject: [PATCH 063/176] target/arm920t: change prototype of arm920t_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm920t_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I9a603d7c032df91b3913aadb242de89dbed0358e Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5056 Tested-by: jenkins --- src/target/arm920t.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/target/arm920t.c b/src/target/arm920t.c index ed9d388a5..7052a72a8 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -507,11 +507,11 @@ void arm920t_pre_restore_context(struct target *target) static const char arm920_not[] = "target is not an ARM920"; -static int arm920t_verify_pointer(struct command_context *cmd_ctx, +static int arm920t_verify_pointer(struct command_invocation *cmd, struct arm920t_common *arm920t) { if (arm920t->common_magic != ARM920T_COMMON_MAGIC) { - command_print(cmd_ctx, arm920_not); + command_print(cmd->ctx, arm920_not); return ERROR_TARGET_INVALID; } @@ -869,7 +869,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) int segment, index_t; struct reg *r; - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1151,7 +1151,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) int victim; struct reg *r; - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1451,7 +1451,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1507,7 +1507,7 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1581,7 +1581,7 @@ COMMAND_HANDLER(arm920t_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; From c104617584cfe14c0c859227f6aad51d48d74d63 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:35:04 +0200 Subject: [PATCH 064/176] target/arm926ejs: change prototype of arm926ejs_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm926ejs_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ibbb03429a7fe8b9979f9bb9e513f9eb86aee3b5b Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5057 Tested-by: jenkins --- src/target/arm926ejs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 3f22a8a46..429db44f9 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -501,11 +501,11 @@ static void arm926ejs_pre_restore_context(struct target *target) static const char arm926_not[] = "target is not an ARM926"; -static int arm926ejs_verify_pointer(struct command_context *cmd_ctx, +static int arm926ejs_verify_pointer(struct command_invocation *cmd, struct arm926ejs_common *arm926) { if (arm926->common_magic != ARM926EJS_COMMON_MAGIC) { - command_print(cmd_ctx, arm926_not); + command_print(cmd->ctx, arm926_not); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -729,7 +729,7 @@ COMMAND_HANDLER(arm926ejs_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct arm926ejs_common *arm926ejs = target_to_arm926(target); - retval = arm926ejs_verify_pointer(CMD_CTX, arm926ejs); + retval = arm926ejs_verify_pointer(CMD, arm926ejs); if (retval != ERROR_OK) return retval; From 6a453e5cf0adc4d19378e953122ca69efcf32b6d Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:37:05 +0200 Subject: [PATCH 065/176] target/arm966e: change prototype of arm966e_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm966e_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I92745591256ad56a588b6386842028e0b18dec96 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5058 Tested-by: jenkins --- src/target/arm966e.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/arm966e.c b/src/target/arm966e.c index c9d7f01aa..98c62745f 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -56,11 +56,11 @@ static int arm966e_target_create(struct target *target, Jim_Interp *interp) return arm966e_init_arch_info(target, arm966e, target->tap); } -static int arm966e_verify_pointer(struct command_context *cmd_ctx, +static int arm966e_verify_pointer(struct command_invocation *cmd, struct arm966e_common *arm966e) { if (arm966e->common_magic != ARM966E_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM966"); + command_print(cmd->ctx, "target is not an ARM966"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -170,7 +170,7 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm966e_common *arm966e = target_to_arm966(target); - retval = arm966e_verify_pointer(CMD_CTX, arm966e); + retval = arm966e_verify_pointer(CMD, arm966e); if (retval != ERROR_OK) return retval; From 2f3ab89a78d217f20233fab0f514b241908c9ce8 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:44:43 +0200 Subject: [PATCH 066/176] target/arm720t: change prototype of arm720t_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm720t_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I7fa0628fabacd9ceb62ce921192f88edca659c15 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5059 Tested-by: jenkins --- src/target/arm720t.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/arm720t.c b/src/target/arm720t.c index b592ffc47..e8ad852c9 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -233,11 +233,11 @@ static void arm720t_pre_restore_context(struct target *target) arm720t_write_cp15(target, 0xee060f10, arm720t->far_reg); } -static int arm720t_verify_pointer(struct command_context *cmd_ctx, +static int arm720t_verify_pointer(struct command_invocation *cmd, struct arm720t_common *arm720t) { if (arm720t->common_magic != ARM720T_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM720"); + command_print(cmd->ctx, "target is not an ARM720"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -442,7 +442,7 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm720t_common *arm720t = target_to_arm720(target); - retval = arm720t_verify_pointer(CMD_CTX, arm720t); + retval = arm720t_verify_pointer(CMD, arm720t); if (retval != ERROR_OK) return retval; From c734202dc89bb3ee05a204140b3c890451e79686 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:46:29 +0200 Subject: [PATCH 067/176] target/arm946e: change prototype of arm946e_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm946e_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ib7119e2b009d05eec47b50c3b9d32feaebc97538 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5060 Tested-by: jenkins --- src/target/arm946e.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 073381431..278a70ca2 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -99,11 +99,11 @@ static int arm946e_target_create(struct target *target, Jim_Interp *interp) return ERROR_OK; } -static int arm946e_verify_pointer(struct command_context *cmd_ctx, +static int arm946e_verify_pointer(struct command_invocation *cmd, struct arm946e_common *arm946e) { if (arm946e->common_magic != ARM946E_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM946"); + command_print(cmd->ctx, "target is not an ARM946"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -558,7 +558,7 @@ COMMAND_HANDLER(arm946e_handle_cp15) struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - int retval = arm946e_verify_pointer(CMD_CTX, arm946e); + int retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) return retval; @@ -608,7 +608,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - retval = arm946e_verify_pointer(CMD_CTX, arm946e); + retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) return retval; From 07632ab94c57943b786c9f274c74f344797d8301 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:55:27 +0200 Subject: [PATCH 068/176] target/cortex_m: change prototype of cortex_m_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of cortex_m_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Icf6d1e5f8b4a3ce115c4253e49769df19a5211ae Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5061 Tested-by: jenkins --- src/target/cortex_m.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index e88392504..639e09f7e 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2366,11 +2366,11 @@ static int cortex_m_target_create(struct target *target, Jim_Interp *interp) /*--------------------------------------------------------------------------*/ -static int cortex_m_verify_pointer(struct command_context *cmd_ctx, +static int cortex_m_verify_pointer(struct command_invocation *cmd, struct cortex_m_common *cm) { if (cm->common_magic != CORTEX_M_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not a Cortex-M"); + command_print(cmd->ctx, "target is not a Cortex-M"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -2404,7 +2404,7 @@ COMMAND_HANDLER(handle_cortex_m_vector_catch_command) { "reset", VC_CORERESET, }, }; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; @@ -2482,7 +2482,7 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) const Jim_Nvp *n; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; @@ -2512,7 +2512,7 @@ COMMAND_HANDLER(handle_cortex_m_reset_config_command) int retval; char *reset_config; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; From 42bc2051aa5528a26a2c24f0d76cbb63d399c7c0 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:57:01 +0200 Subject: [PATCH 069/176] target/mips32: change prototype of mips32_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of mips32_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ic4a4de10518ee009d6df420e7278fd028e1f22ca Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5062 Tested-by: jenkins --- src/target/mips32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/mips32.c b/src/target/mips32.c index d9d8ba975..9cb24a447 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -905,11 +905,11 @@ cleanup: return 1; /* only one block has been checked */ } -static int mips32_verify_pointer(struct command_context *cmd_ctx, +static int mips32_verify_pointer(struct command_invocation *cmd, struct mips32_common *mips32) { if (mips32->common_magic != MIPS32_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an MIPS32"); + command_print(cmd->ctx, "target is not an MIPS32"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -927,7 +927,7 @@ COMMAND_HANDLER(mips32_handle_cp0_command) struct mips_ejtag *ejtag_info = &mips32->ejtag_info; - retval = mips32_verify_pointer(CMD_CTX, mips32); + retval = mips32_verify_pointer(CMD, mips32); if (retval != ERROR_OK) return retval; From 7b164d21baa97f01ff14168b3289f28671caf58a Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:58:56 +0200 Subject: [PATCH 070/176] target/mips_m4k: change prototype of mips_m4k_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of mips_m4k_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I9fa3e883d2ca9cc858caaefd33586f78638702f5 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5063 Tested-by: jenkins --- src/target/mips_m4k.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 653d732f1..755ed72e6 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -1270,11 +1270,11 @@ static int mips_m4k_bulk_write_memory(struct target *target, target_addr_t addre return retval; } -static int mips_m4k_verify_pointer(struct command_context *cmd_ctx, +static int mips_m4k_verify_pointer(struct command_invocation *cmd, struct mips_m4k_common *mips_m4k) { if (mips_m4k->common_magic != MIPSM4K_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an MIPS_M4K"); + command_print(cmd->ctx, "target is not an MIPS_M4K"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -1287,7 +1287,7 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) struct mips_m4k_common *mips_m4k = target_to_m4k(target); struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info; - retval = mips_m4k_verify_pointer(CMD_CTX, mips_m4k); + retval = mips_m4k_verify_pointer(CMD, mips_m4k); if (retval != ERROR_OK) return retval; From 32470a973ffc4d0e69fb419448c6b4470cb328fc Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 03:56:26 +0200 Subject: [PATCH 071/176] target/xscale: change prototype of xscale_verify_pointer() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of xscale_verify_pointer() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Id047fab41ec4f673a46756b0ab901e659e088544 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5064 Tested-by: jenkins --- src/target/xscale.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/target/xscale.c b/src/target/xscale.c index 34c5f0001..fa4aa4e96 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -138,11 +138,11 @@ static int xscale_set_reg_u32(struct reg *reg, uint32_t value) static const char xscale_not[] = "target is not an XScale"; -static int xscale_verify_pointer(struct command_context *cmd_ctx, +static int xscale_verify_pointer(struct command_invocation *cmd, struct xscale_common *xscale) { if (xscale->common_magic != XSCALE_COMMON_MAGIC) { - command_print(cmd_ctx, xscale_not); + command_print(cmd->ctx, xscale_not); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -3032,7 +3032,7 @@ COMMAND_HANDLER(xscale_handle_debug_handler_command) } xscale = target_to_xscale(target); - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3066,7 +3066,7 @@ COMMAND_HANDLER(xscale_handle_cache_clean_address_command) return ERROR_FAIL; } xscale = target_to_xscale(target); - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3086,7 +3086,7 @@ COMMAND_HANDLER(xscale_handle_cache_info_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3131,7 +3131,7 @@ COMMAND_HANDLER(xscale_handle_mmu_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3161,7 +3161,7 @@ COMMAND_HANDLER(xscale_handle_idcache_command) struct target *target = get_current_target(CMD_CTX); struct xscale_common *xscale = target_to_xscale(target); - int retval = xscale_verify_pointer(CMD_CTX, xscale); + int retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3222,7 +3222,7 @@ COMMAND_HANDLER(xscale_handle_vector_catch_command) uint32_t catch = 0; struct reg *dcsr_reg = &xscale->reg_cache->reg_list[XSCALE_DCSR]; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3272,7 +3272,7 @@ COMMAND_HANDLER(xscale_handle_vector_table_command) int err = 0; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3330,7 +3330,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) uint32_t dcsr_value; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3395,7 +3395,7 @@ COMMAND_HANDLER(xscale_handle_trace_image_command) if (CMD_ARGC < 1) return ERROR_COMMAND_SYNTAX_ERROR; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3434,7 +3434,7 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) struct fileio *file; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3482,7 +3482,7 @@ COMMAND_HANDLER(xscale_handle_analyze_trace_buffer_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3497,7 +3497,7 @@ COMMAND_HANDLER(xscale_handle_cp15) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; From c779387279e96f37c8049d81284cd07bf7238ac9 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:06:58 +0200 Subject: [PATCH 072/176] target/xscale: change prototype of xscale_display_instruction() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of xscale_display_instruction() and of xscale_analyze_trace() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I8420f19c1b2ff0d2a2f2a8d3627767f7acda437c Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5065 Tested-by: jenkins --- src/target/xscale.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/target/xscale.c b/src/target/xscale.c index fa4aa4e96..bc79c7f74 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -2654,16 +2654,16 @@ static inline void xscale_branch_address(struct xscale_trace_data *trace_data, static inline void xscale_display_instruction(struct target *target, uint32_t pc, struct arm_instruction *instruction, - struct command_context *cmd_ctx) + struct command_invocation *cmd) { int retval = xscale_read_instruction(target, pc, instruction); if (retval == ERROR_OK) - command_print(cmd_ctx, "%s", instruction->text); + command_print(cmd->ctx, "%s", instruction->text); else - command_print(cmd_ctx, "0x%8.8" PRIx32 "\t", pc); + command_print(cmd->ctx, "0x%8.8" PRIx32 "\t", pc); } -static int xscale_analyze_trace(struct target *target, struct command_context *cmd_ctx) +static int xscale_analyze_trace(struct target *target, struct command_invocation *cmd) { struct xscale_common *xscale = target_to_xscale(target); struct xscale_trace_data *trace_data = xscale->trace.data; @@ -2771,7 +2771,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c count = trace_data->entries[i].data & 0x0f; for (j = 0; j < count; j++) { xscale_display_instruction(target, current_pc, &instruction, - cmd_ctx); + cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -2779,7 +2779,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c * rollover and some exceptions: undef, swi, prefetch abort. */ if ((trace_msg_type == 15) || (exception > 0 && exception < 4)) { xscale_display_instruction(target, current_pc, &instruction, - cmd_ctx); + cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -2787,13 +2787,13 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c continue; if (exception) { - command_print(cmd_ctx, "--- exception %i ---", exception); + command_print(cmd->ctx, "--- exception %i ---", exception); continue; } /* not exception or rollover; next instruction is a branch and is * not included in the count */ - xscale_display_instruction(target, current_pc, &instruction, cmd_ctx); + xscale_display_instruction(target, current_pc, &instruction, cmd); /* for direct branches, extract branch destination from instruction */ if ((trace_msg_type == 8) || (trace_msg_type == 12)) { @@ -2813,7 +2813,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c } if (current_pc == 0) - command_print(cmd_ctx, "address unknown"); + command_print(cmd->ctx, "address unknown"); continue; } @@ -2855,7 +2855,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c /* display remaining instructions */ for (i = 0; i < gap_count; i++) { - xscale_display_instruction(target, current_pc, &instruction, cmd_ctx); + xscale_display_instruction(target, current_pc, &instruction, cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -3486,7 +3486,7 @@ COMMAND_HANDLER(xscale_handle_analyze_trace_buffer_command) if (retval != ERROR_OK) return retval; - xscale_analyze_trace(target, CMD_CTX); + xscale_analyze_trace(target, CMD); return ERROR_OK; } From c867806f0d3bd8e8b175093b9024bf781758cd07 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:16:34 +0200 Subject: [PATCH 073/176] target/armv8: change prototype of display_cache_info() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of display_cache_info(), armv8_handle_inner_cache_info_command() and armv8_handle_cache_info_command() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I13519c79af82cdba57d5205ba84a5a27fce65a36 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5066 Tested-by: jenkins --- src/target/aarch64.c | 2 +- src/target/armv8.c | 6 +++--- src/target/armv8.h | 4 ++-- src/target/armv8_cache.c | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/target/aarch64.c b/src/target/aarch64.c index ff68e3adb..68ae9f1bf 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -2533,7 +2533,7 @@ COMMAND_HANDLER(aarch64_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct armv8_common *armv8 = target_to_armv8(target); - return armv8_handle_cache_info_command(CMD_CTX, + return armv8_handle_cache_info_command(CMD, &armv8->armv8_mmu.armv8_cache); } diff --git a/src/target/armv8.c b/src/target/armv8.c index e271c1a92..4054c954f 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -1079,16 +1079,16 @@ COMMAND_HANDLER(armv8_handle_exception_catch_command) return ERROR_OK; } -int armv8_handle_cache_info_command(struct command_context *cmd_ctx, +int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache) { if (armv8_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd->ctx, "cache not yet identified"); return ERROR_OK; } if (armv8_cache->display_cache_info) - armv8_cache->display_cache_info(cmd_ctx, armv8_cache); + armv8_cache->display_cache_info(cmd, armv8_cache); return ERROR_OK; } diff --git a/src/target/armv8.h b/src/target/armv8.h index af00e52d6..1a611455d 100644 --- a/src/target/armv8.h +++ b/src/target/armv8.h @@ -170,7 +170,7 @@ struct armv8_cache_common { /* l2 external unified cache if some */ void *l2_cache; int (*flush_all_data_cache)(struct target *target); - int (*display_cache_info)(struct command_context *cmd_ctx, + int (*display_cache_info)(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache); }; @@ -301,7 +301,7 @@ int armv8_mmu_translate_va_pa(struct target *target, target_addr_t va, target_addr_t *val, int meminfo); int armv8_mmu_translate_va(struct target *target, target_addr_t va, target_addr_t *val); -int armv8_handle_cache_info_command(struct command_context *cmd_ctx, +int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache); void armv8_set_cpsr(struct arm *arm, uint32_t cpsr); diff --git a/src/target/armv8_cache.c b/src/target/armv8_cache.c index 40965ebd8..a641d04ab 100644 --- a/src/target/armv8_cache.c +++ b/src/target/armv8_cache.c @@ -188,13 +188,13 @@ done: return retval; } -static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx, +static int armv8_handle_inner_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache) { int cl; if (armv8_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd->ctx, "cache not yet identified"); return ERROR_OK; } @@ -202,7 +202,7 @@ static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx struct armv8_arch_cache *arch = &(armv8_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd_ctx, + command_print(cmd->ctx, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -215,7 +215,7 @@ static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx } if (arch->ctype >= 2) { - command_print(cmd_ctx, + command_print(cmd->ctx, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 From cff570b22f15494948313e4f0c4c28fae74887ad Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:24:33 +0200 Subject: [PATCH 074/176] target/dsp563xx: change prototype of handle_md_output() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of handle_md_output() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ib0b84c933689ac8c940c9bbe62d9c95fd015c4f5 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5067 Tested-by: jenkins --- src/target/dsp563xx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index 5f1338474..28fb8594d 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -1875,7 +1875,7 @@ static int dsp563xx_remove_watchpoint(struct target *target, struct watchpoint * return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } -static void handle_md_output(struct command_context *cmd_ctx, +static void handle_md_output(struct command_invocation *cmd, struct target *target, uint32_t address, unsigned size, @@ -1930,7 +1930,7 @@ static void handle_md_output(struct command_context *cmd_ctx, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); + command_print(cmd->ctx, "%s", output); output_len = 0; } } @@ -2208,7 +2208,7 @@ COMMAND_HANDLER(dsp563xx_mem_command) err = dsp563xx_read_memory(target, mem_type, address, sizeof(uint32_t), count, buffer); if (err == ERROR_OK) - handle_md_output(CMD_CTX, target, address, sizeof(uint32_t), count, buffer); + handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); } else { b = buffer; From 54ecec2e85d7ffd8aeaa9cd1f76a5a983ff20391 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:42:23 +0200 Subject: [PATCH 075/176] target/armv4_5_cache: change prototype of armv4_5_handle_cache_info_command() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of armv4_5_handle_cache_info_command() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ib6ab3ec2fc6504c2a0635b654697a4b6e12a3750 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5068 Tested-by: jenkins --- src/target/arm920t.c | 2 +- src/target/arm926ejs.c | 2 +- src/target/armv4_5_cache.c | 10 +++++----- src/target/armv4_5_cache.h | 4 ++-- src/target/xscale.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 7052a72a8..88a03952d 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -1585,7 +1585,7 @@ COMMAND_HANDLER(arm920t_handle_cache_info_command) if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, + return armv4_5_handle_cache_info_command(CMD, &arm920t->armv4_5_mmu.armv4_5_cache); } diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 429db44f9..01ce17663 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -733,7 +733,7 @@ COMMAND_HANDLER(arm926ejs_handle_cache_info_command) if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, &arm926ejs->armv4_5_mmu.armv4_5_cache); + return armv4_5_handle_cache_info_command(CMD, &arm926ejs->armv4_5_mmu.armv4_5_cache); } static int arm926ejs_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical) diff --git a/src/target/armv4_5_cache.c b/src/target/armv4_5_cache.c index bd0091d80..6a169253e 100644 --- a/src/target/armv4_5_cache.c +++ b/src/target/armv4_5_cache.c @@ -76,23 +76,23 @@ int armv4_5_identify_cache(uint32_t cache_type_reg, struct armv4_5_cache_common return ERROR_OK; } -int armv4_5_handle_cache_info_command(struct command_context *cmd_ctx, struct armv4_5_cache_common *armv4_5_cache) +int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache) { if (armv4_5_cache->ctype == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd->ctx, "cache not yet identified"); return ERROR_OK; } - command_print(cmd_ctx, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, + command_print(cmd->ctx, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, (armv4_5_cache->separate) ? "separate caches" : "unified cache"); - command_print(cmd_ctx, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd->ctx, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->d_u_size.linelen, armv4_5_cache->d_u_size.associativity, armv4_5_cache->d_u_size.nsets, armv4_5_cache->d_u_size.cachesize); - command_print(cmd_ctx, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd->ctx, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->i_size.linelen, armv4_5_cache->i_size.associativity, armv4_5_cache->i_size.nsets, diff --git a/src/target/armv4_5_cache.h b/src/target/armv4_5_cache.h index 2fd1ca387..768938fd1 100644 --- a/src/target/armv4_5_cache.h +++ b/src/target/armv4_5_cache.h @@ -19,7 +19,7 @@ #ifndef OPENOCD_TARGET_ARMV4_5_CACHE_H #define OPENOCD_TARGET_ARMV4_5_CACHE_H -struct command_context; +struct command_invocation; struct armv4_5_cachesize { int linelen; @@ -42,7 +42,7 @@ int armv4_5_identify_cache(uint32_t cache_type_reg, int armv4_5_cache_state(uint32_t cp15_control_reg, struct armv4_5_cache_common *cache); -int armv4_5_handle_cache_info_command(struct command_context *cmd_ctx, +int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache); enum { diff --git a/src/target/xscale.c b/src/target/xscale.c index bc79c7f74..a090c4b39 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3090,7 +3090,7 @@ COMMAND_HANDLER(xscale_handle_cache_info_command) if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, &xscale->armv4_5_mmu.armv4_5_cache); + return armv4_5_handle_cache_info_command(CMD, &xscale->armv4_5_mmu.armv4_5_cache); } static int xscale_virt2phys(struct target *target, From 95caf7714d0f408a934029ae73f9f13f0c55e812 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:50:47 +0200 Subject: [PATCH 076/176] target/armv7a: change prototype of armv7a_handle_cache_info_command() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of armv7a_handle_cache_info_command() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I27f507869cb41c74722a759e69dfd45658fcd4be Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5069 Tested-by: jenkins --- src/target/armv7a.c | 10 +++++----- src/target/armv7a.h | 2 +- src/target/armv7a_cache.c | 2 +- src/target/cortex_a.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 97ce473e5..7f51990af 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -239,7 +239,7 @@ COMMAND_HANDLER(handle_cache_l2x) return ERROR_OK; } -int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, +int armv7a_handle_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache) { struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *) @@ -248,7 +248,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, int cl; if (armv7a_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd->ctx, "cache not yet identified"); return ERROR_OK; } @@ -256,7 +256,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, struct armv7a_arch_cache *arch = &(armv7a_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd_ctx, + command_print(cmd->ctx, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -269,7 +269,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, } if (arch->ctype >= 2) { - command_print(cmd_ctx, + command_print(cmd->ctx, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -283,7 +283,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, } if (l2x_cache != NULL) - command_print(cmd_ctx, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", + command_print(cmd->ctx, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); return ERROR_OK; diff --git a/src/target/armv7a.h b/src/target/armv7a.h index 9b1436c72..0ef04c162 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -192,7 +192,7 @@ int armv7a_arch_state(struct target *target); int armv7a_identify_cache(struct target *target); int armv7a_init_arch_info(struct target *target, struct armv7a_common *armv7a); -int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, +int armv7a_handle_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache); int armv7a_read_ttbcr(struct target *target); diff --git a/src/target/armv7a_cache.c b/src/target/armv7a_cache.c index 7435aab95..fca195c29 100644 --- a/src/target/armv7a_cache.c +++ b/src/target/armv7a_cache.c @@ -431,7 +431,7 @@ COMMAND_HANDLER(arm7a_l1_cache_info_cmd) struct target *target = get_current_target(CMD_CTX); struct armv7a_common *armv7a = target_to_armv7a(target); - return armv7a_handle_cache_info_command(CMD_CTX, + return armv7a_handle_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 8d0e10013..5d1d42af9 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -2930,7 +2930,7 @@ COMMAND_HANDLER(cortex_a_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct armv7a_common *armv7a = target_to_armv7a(target); - return armv7a_handle_cache_info_command(CMD_CTX, + return armv7a_handle_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } From 105cfac5525b5274ace311a5a33a4bafc39085f1 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:27:58 +0200 Subject: [PATCH 077/176] target/armv7a_cache_l2x: change prototype of arm7a_handle_l2x_cache_info_command() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of arm7a_handle_l2x_cache_info_command() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ib926cd7380ac8b6fb89f64e0a85d81d124633315 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5070 Tested-by: jenkins --- src/target/armv7a_cache_l2x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/armv7a_cache_l2x.c b/src/target/armv7a_cache_l2x.c index e181f268d..0aa695382 100644 --- a/src/target/armv7a_cache_l2x.c +++ b/src/target/armv7a_cache_l2x.c @@ -173,18 +173,18 @@ done: return retval; } -static int arm7a_handle_l2x_cache_info_command(struct command_context *cmd_ctx, +static int arm7a_handle_l2x_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache) { struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *) (armv7a_cache->outer_cache); if (armv7a_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd->ctx, "cache not yet identified"); return ERROR_OK; } - command_print(cmd_ctx, + command_print(cmd->ctx, "L2 unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); @@ -235,7 +235,7 @@ COMMAND_HANDLER(arm7a_l2x_cache_info_command) if (retval) return retval; - return arm7a_handle_l2x_cache_info_command(CMD_CTX, + return arm7a_handle_l2x_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } From 0f488acbbaceb9107e27d052fb8a4aeb7b41d6ee Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 04:53:19 +0200 Subject: [PATCH 078/176] target/x86_32_common: change prototype of handle_iod_output() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of handle_iod_output() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I67f594c80d6bbbbf6c9567069a545f16877b1e94 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5071 Tested-by: jenkins --- src/target/x86_32_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/x86_32_common.c b/src/target/x86_32_common.c index 011e7d843..a641ca94f 100644 --- a/src/target/x86_32_common.c +++ b/src/target/x86_32_common.c @@ -1340,7 +1340,7 @@ static int write_hw_reg_from_cache(struct target *t, int num) } /* x86 32 commands */ -static void handle_iod_output(struct command_context *cmd_ctx, +static void handle_iod_output(struct command_invocation *cmd, struct target *target, uint32_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -1392,7 +1392,7 @@ static void handle_iod_output(struct command_context *cmd_ctx, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); + command_print(cmd->ctx, "%s", output); output_len = 0; } } @@ -1429,7 +1429,7 @@ COMMAND_HANDLER(handle_iod_command) struct target *target = get_current_target(CMD_CTX); int retval = x86_32_common_read_io(target, address, size, buffer); if (ERROR_OK == retval) - handle_iod_output(CMD_CTX, target, address, size, count, buffer); + handle_iod_output(CMD, target, address, size, count, buffer); free(buffer); return retval; } From 5a330d1d743bfbc26bc6fdd542e63f814f0d61b3 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:03:21 +0200 Subject: [PATCH 079/176] target/etm: change prototype of etmv1_analyze_trace() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of etmv1_analyze_trace() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ic923af5480a54c7272d2ff1abbe235ba941cf1a0 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5072 Tested-by: jenkins --- src/target/etm.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/target/etm.c b/src/target/etm.c index 6a00c23a8..4c95626f9 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -859,7 +859,7 @@ static int etmv1_data(struct etm_context *ctx, int size, uint32_t *data) return 0; } -static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *cmd_ctx) +static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocation *cmd) { int retval; struct arm_instruction instruction; @@ -869,7 +869,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * ctx->capture_driver->read_trace(ctx); if (ctx->trace_depth == 0) { - command_print(cmd_ctx, "Trace is empty."); + command_print(cmd->ctx, "Trace is empty."); return ERROR_OK; } @@ -893,7 +893,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * int current_pc_ok = ctx->pc_ok; if (ctx->trace_data[ctx->pipe_index].flags & ETMV1_TRIGGER_CYCLE) - command_print(cmd_ctx, "--- trigger ---"); + command_print(cmd->ctx, "--- trigger ---"); /* instructions execute in IE/D or BE/D cycles */ if ((pipestat == STAT_IE) || (pipestat == STAT_ID)) @@ -942,7 +942,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * next_pc = ctx->last_branch; break; case 0x1: /* tracing enabled */ - command_print(cmd_ctx, + command_print(cmd->ctx, "--- tracing enabled at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -950,7 +950,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * continue; break; case 0x2: /* trace restarted after FIFO overflow */ - command_print(cmd_ctx, + command_print(cmd->ctx, "--- trace restarted after FIFO overflow at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -958,7 +958,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * continue; break; case 0x3: /* exit from debug state */ - command_print(cmd_ctx, + command_print(cmd->ctx, "--- exit from debug state at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -971,7 +971,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * * we have to move on with the next trace cycle */ if (!current_pc_ok) { - command_print(cmd_ctx, + command_print(cmd->ctx, "--- periodic synchronization point at 0x%8.8" PRIx32 " ---", next_pc); ctx->current_pc = next_pc; @@ -998,9 +998,9 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * || ((ctx->last_branch >= 0xffff0000) && (ctx->last_branch <= 0xffff0020))) { if ((ctx->last_branch & 0xff) == 0x10) - command_print(cmd_ctx, "data abort"); + command_print(cmd->ctx, "data abort"); else { - command_print(cmd_ctx, + command_print(cmd->ctx, "exception vector 0x%2.2" PRIx32 "", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -1058,7 +1058,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * ctx->ptr_ok = 1; if (ctx->ptr_ok) - command_print(cmd_ctx, + command_print(cmd->ctx, "address: 0x%8.8" PRIx32 "", ctx->last_ptr); } @@ -1073,7 +1073,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * uint32_t data; if (etmv1_data(ctx, 4, &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd_ctx, + command_print(cmd->ctx, "data: 0x%8.8" PRIx32 "", data); } @@ -1084,7 +1084,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * if (etmv1_data(ctx, arm_access_size(&instruction), &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd_ctx, "data: 0x%8.8" PRIx32 "", data); + command_print(cmd->ctx, "data: 0x%8.8" PRIx32 "", data); } } @@ -1119,7 +1119,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * (cycles == 1) ? "cycle" : "cycles"); } - command_print(cmd_ctx, "%s%s%s", + command_print(cmd->ctx, "%s%s%s", instruction.text, (pipestat == STAT_IN) ? " (not executed)" : "", cycles_text); @@ -1982,7 +1982,7 @@ COMMAND_HANDLER(handle_etm_analyze_command) return ERROR_FAIL; } - retval = etmv1_analyze_trace(etm_ctx, CMD_CTX); + retval = etmv1_analyze_trace(etm_ctx, CMD); if (retval != ERROR_OK) { /* FIX! error should be reported inside etmv1_analyze_trace() */ switch (retval) { From d50e92e7f7e44ef315e5bf005a78f9184db051c4 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:10:56 +0200 Subject: [PATCH 080/176] target/arm_adi_v5: change prototype of dap_rom_display() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of dap_rom_display() and dap_info_command() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Idb97b20759c03fcecbac1184c354966f469caa5f Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5073 Tested-by: jenkins --- src/target/arm_adi_v5.c | 64 ++++++++++++++++++++--------------------- src/target/arm_adi_v5.h | 2 +- src/target/arm_dap.c | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 9a641fce2..f9eb8f4cb 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1190,7 +1190,7 @@ static const struct { { ANY_ID, 0x343, "TI DAPCTL", "", }, /* from OMAP3 memmap */ }; -static int dap_rom_display(struct command_context *cmd_ctx, +static int dap_rom_display(struct command_invocation *cmd, struct adiv5_ap *ap, uint32_t dbgbase, int depth) { int retval; @@ -1199,7 +1199,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, char tabs[16] = ""; if (depth > 16) { - command_print(cmd_ctx, "\tTables too deep"); + command_print(cmd->ctx, "\tTables too deep"); return ERROR_FAIL; } @@ -1207,25 +1207,25 @@ static int dap_rom_display(struct command_context *cmd_ctx, snprintf(tabs, sizeof(tabs), "[L%02d] ", depth); uint32_t base_addr = dbgbase & 0xFFFFF000; - command_print(cmd_ctx, "\t\tComponent base address 0x%08" PRIx32, base_addr); + command_print(cmd->ctx, "\t\tComponent base address 0x%08" PRIx32, base_addr); retval = dap_read_part_id(ap, base_addr, &cid, &pid); if (retval != ERROR_OK) { - command_print(cmd_ctx, "\t\tCan't read component, the corresponding core might be turned off"); + command_print(cmd->ctx, "\t\tCan't read component, the corresponding core might be turned off"); return ERROR_OK; /* Don't abort recursion */ } if (!is_dap_cid_ok(cid)) { - command_print(cmd_ctx, "\t\tInvalid CID 0x%08" PRIx32, cid); + command_print(cmd->ctx, "\t\tInvalid CID 0x%08" PRIx32, cid); return ERROR_OK; /* Don't abort recursion */ } /* component may take multiple 4K pages */ uint32_t size = (pid >> 36) & 0xf; if (size > 0) - command_print(cmd_ctx, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); + command_print(cmd->ctx, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); - command_print(cmd_ctx, "\t\tPeripheral ID 0x%010" PRIx64, pid); + command_print(cmd->ctx, "\t\tPeripheral ID 0x%010" PRIx64, pid); uint8_t class = (cid >> 12) & 0xf; uint16_t part_num = pid & 0xfff; @@ -1233,12 +1233,12 @@ static int dap_rom_display(struct command_context *cmd_ctx, if (designer_id & 0x80) { /* JEP106 code */ - command_print(cmd_ctx, "\t\tDesigner is 0x%03" PRIx16 ", %s", + command_print(cmd->ctx, "\t\tDesigner is 0x%03" PRIx16 ", %s", designer_id, jep106_manufacturer(designer_id >> 8, designer_id & 0x7f)); } else { /* Legacy ASCII ID, clear invalid bits */ designer_id &= 0x7f; - command_print(cmd_ctx, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", + command_print(cmd->ctx, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", designer_id, designer_id == 0x41 ? "ARM" : ""); } @@ -1260,8 +1260,8 @@ static int dap_rom_display(struct command_context *cmd_ctx, break; } - command_print(cmd_ctx, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); - command_print(cmd_ctx, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); + command_print(cmd->ctx, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); + command_print(cmd->ctx, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); if (class == 1) { /* ROM Table */ uint32_t memtype; @@ -1270,9 +1270,9 @@ static int dap_rom_display(struct command_context *cmd_ctx, return retval; if (memtype & 0x01) - command_print(cmd_ctx, "\t\tMEMTYPE system memory present on bus"); + command_print(cmd->ctx, "\t\tMEMTYPE system memory present on bus"); else - command_print(cmd_ctx, "\t\tMEMTYPE system memory not present: dedicated debug bus"); + command_print(cmd->ctx, "\t\tMEMTYPE system memory not present: dedicated debug bus"); /* Read ROM table entries from base address until we get 0x00000000 or reach the reserved area */ for (uint16_t entry_offset = 0; entry_offset < 0xF00; entry_offset += 4) { @@ -1280,17 +1280,17 @@ static int dap_rom_display(struct command_context *cmd_ctx, retval = mem_ap_read_atomic_u32(ap, base_addr | entry_offset, &romentry); if (retval != ERROR_OK) return retval; - command_print(cmd_ctx, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", + command_print(cmd->ctx, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", tabs, entry_offset, romentry); if (romentry & 0x01) { /* Recurse */ - retval = dap_rom_display(cmd_ctx, ap, base_addr + (romentry & 0xFFFFF000), depth + 1); + retval = dap_rom_display(cmd, ap, base_addr + (romentry & 0xFFFFF000), depth + 1); if (retval != ERROR_OK) return retval; } else if (romentry != 0) { - command_print(cmd_ctx, "\t\tComponent not present"); + command_print(cmd->ctx, "\t\tComponent not present"); } else { - command_print(cmd_ctx, "\t%s\tEnd of ROM table", tabs); + command_print(cmd->ctx, "\t%s\tEnd of ROM table", tabs); break; } } @@ -1435,7 +1435,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, } break; } - command_print(cmd_ctx, "\t\tType is 0x%02" PRIx8 ", %s, %s", + command_print(cmd->ctx, "\t\tType is 0x%02" PRIx8 ", %s, %s", (uint8_t)(devtype & 0xff), major, subtype); /* REVISIT also show 0xfc8 DevId */ @@ -1444,7 +1444,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, return ERROR_OK; } -int dap_info_command(struct command_context *cmd_ctx, +int dap_info_command(struct command_invocation *cmd, struct adiv5_ap *ap) { int retval; @@ -1456,27 +1456,27 @@ int dap_info_command(struct command_context *cmd_ctx, if (retval != ERROR_OK) return retval; - command_print(cmd_ctx, "AP ID register 0x%8.8" PRIx32, apid); + command_print(cmd->ctx, "AP ID register 0x%8.8" PRIx32, apid); if (apid == 0) { - command_print(cmd_ctx, "No AP found at this ap 0x%x", ap->ap_num); + command_print(cmd->ctx, "No AP found at this ap 0x%x", ap->ap_num); return ERROR_FAIL; } switch (apid & (IDR_JEP106 | IDR_TYPE)) { case IDR_JEP106_ARM | AP_TYPE_JTAG_AP: - command_print(cmd_ctx, "\tType is JTAG-AP"); + command_print(cmd->ctx, "\tType is JTAG-AP"); break; case IDR_JEP106_ARM | AP_TYPE_AHB_AP: - command_print(cmd_ctx, "\tType is MEM-AP AHB"); + command_print(cmd->ctx, "\tType is MEM-AP AHB"); break; case IDR_JEP106_ARM | AP_TYPE_APB_AP: - command_print(cmd_ctx, "\tType is MEM-AP APB"); + command_print(cmd->ctx, "\tType is MEM-AP APB"); break; case IDR_JEP106_ARM | AP_TYPE_AXI_AP: - command_print(cmd_ctx, "\tType is MEM-AP AXI"); + command_print(cmd->ctx, "\tType is MEM-AP AXI"); break; default: - command_print(cmd_ctx, "\tUnknown AP type"); + command_print(cmd->ctx, "\tUnknown AP type"); break; } @@ -1485,17 +1485,17 @@ int dap_info_command(struct command_context *cmd_ctx, */ mem_ap = (apid & IDR_CLASS) == AP_CLASS_MEM_AP; if (mem_ap) { - command_print(cmd_ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); + command_print(cmd->ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); if (dbgbase == 0xFFFFFFFF || (dbgbase & 0x3) == 0x2) { - command_print(cmd_ctx, "\tNo ROM table present"); + command_print(cmd->ctx, "\tNo ROM table present"); } else { if (dbgbase & 0x01) - command_print(cmd_ctx, "\tValid ROM table present"); + command_print(cmd->ctx, "\tValid ROM table present"); else - command_print(cmd_ctx, "\tROM table in legacy format"); + command_print(cmd->ctx, "\tROM table in legacy format"); - dap_rom_display(cmd_ctx, ap, dbgbase & 0xFFFFF000, 0); + dap_rom_display(cmd, ap, dbgbase & 0xFFFFF000, 0); } } @@ -1646,7 +1646,7 @@ COMMAND_HANDLER(handle_dap_info_command) return ERROR_COMMAND_SYNTAX_ERROR; } - return dap_info_command(CMD_CTX, &dap->ap[apsel]); + return dap_info_command(CMD, &dap->ap[apsel]); } COMMAND_HANDLER(dap_baseaddr_command) diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 96291a7af..0b61b757a 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -526,7 +526,7 @@ extern const struct command_registration dap_instance_commands[]; struct arm_dap_object; extern struct adiv5_dap *dap_instance_by_jim_obj(Jim_Interp *interp, Jim_Obj *o); extern struct adiv5_dap *adiv5_get_dap(struct arm_dap_object *obj); -extern int dap_info_command(struct command_context *cmd_ctx, +extern int dap_info_command(struct command_invocation *cmd, struct adiv5_ap *ap); extern int dap_register_commands(struct command_context *cmd_ctx); extern const char *adiv5_dap_name(struct adiv5_dap *self); diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index dd7ec9b58..5c15f2c10 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -331,7 +331,7 @@ COMMAND_HANDLER(handle_dap_info_command) return ERROR_COMMAND_SYNTAX_ERROR; } - return dap_info_command(CMD_CTX, &dap->ap[apsel]); + return dap_info_command(CMD, &dap->ap[apsel]); } static const struct command_registration dap_subcommand_handlers[] = { From eaa70635dc3886a3795d5ddb542b008adb45467a Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:14:26 +0200 Subject: [PATCH 081/176] target: change prototype of handle_md_output() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of handle_md_output() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I2150201fad3fd3bc0be89249dcbd314b38a6f860 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5074 Tested-by: jenkins --- src/target/target.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 7946f76fa..e25cb3726 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3125,7 +3125,7 @@ COMMAND_HANDLER(handle_step_command) return target->type->step(target, current_pc, addr, 1); } -static void handle_md_output(struct command_context *cmd_ctx, +static void handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -3183,7 +3183,7 @@ static void handle_md_output(struct command_context *cmd_ctx, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); + command_print(cmd->ctx, "%s", output); output_len = 0; } } @@ -3240,7 +3240,7 @@ COMMAND_HANDLER(handle_md_command) struct target *target = get_current_target(CMD_CTX); int retval = fn(target, address, size, count, buffer); if (ERROR_OK == retval) - handle_md_output(CMD_CTX, target, address, size, count, buffer); + handle_md_output(CMD, target, address, size, count, buffer); free(buffer); From fa765f137460181fd84529df82309a12c376e71a Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:17:07 +0200 Subject: [PATCH 082/176] target: change prototype of handle_bp_command_list() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of handle_bp_command_list() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ibff636d476bcd59784ce3da5409d930225cfe637 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5075 Tested-by: jenkins --- src/target/target.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index e25cb3726..e12ed7fd1 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3694,32 +3694,32 @@ COMMAND_HANDLER(handle_test_image_command) return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, IMAGE_TEST); } -static int handle_bp_command_list(struct command_context *cmd_ctx) +static int handle_bp_command_list(struct command_invocation *cmd) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct breakpoint *breakpoint = target->breakpoints; while (breakpoint) { if (breakpoint->type == BKPT_SOFT) { char *buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd_ctx, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", + command_print(cmd->ctx, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", breakpoint->address, breakpoint->length, breakpoint->set, buf); free(buf); } else { if ((breakpoint->address == 0) && (breakpoint->asid != 0)) - command_print(cmd_ctx, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd->ctx, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", breakpoint->asid, breakpoint->length, breakpoint->set); else if ((breakpoint->address != 0) && (breakpoint->asid != 0)) { - command_print(cmd_ctx, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd->ctx, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); - command_print(cmd_ctx, "\t|--->linked with ContextID: 0x%8.8" PRIx32, + command_print(cmd->ctx, "\t|--->linked with ContextID: 0x%8.8" PRIx32, breakpoint->asid); } else - command_print(cmd_ctx, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd->ctx, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); } @@ -3773,7 +3773,7 @@ COMMAND_HANDLER(handle_bp_command) switch (CMD_ARGC) { case 0: - return handle_bp_command_list(CMD_CTX); + return handle_bp_command_list(CMD); case 2: asid = 0; From 20184ea86170a297ac77a4b7f6844935571f6c18 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:19:21 +0200 Subject: [PATCH 083/176] target: change prototype of handle_bp_command_set() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of handle_bp_command_set() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: If00f9cfb784b53bb3df92d4469178e2f930a146a Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5076 Tested-by: jenkins --- src/target/target.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index e12ed7fd1..bffb55410 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3729,17 +3729,17 @@ static int handle_bp_command_list(struct command_invocation *cmd) return ERROR_OK; } -static int handle_bp_command_set(struct command_context *cmd_ctx, +static int handle_bp_command_set(struct command_invocation *cmd, target_addr_t addr, uint32_t asid, uint32_t length, int hw) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); int retval; if (asid == 0) { retval = breakpoint_add(target, addr, length, hw); /* error is always logged in breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "breakpoint set at " TARGET_ADDR_FMT "", addr); + command_print(cmd->ctx, "breakpoint set at " TARGET_ADDR_FMT "", addr); } else if (addr == 0) { if (target->type->add_context_breakpoint == NULL) { @@ -3749,7 +3749,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, retval = context_breakpoint_add(target, asid, length, hw); /* error is always logged in context_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd->ctx, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); } else { if (target->type->add_hybrid_breakpoint == NULL) { @@ -3759,7 +3759,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, retval = hybrid_breakpoint_add(target, addr, asid, length, hw); /* error is always logged in hybrid_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd->ctx, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); } return retval; } @@ -3779,7 +3779,7 @@ COMMAND_HANDLER(handle_bp_command) asid = 0; COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); case 3: if (strcmp(CMD_ARGV[2], "hw") == 0) { @@ -3787,13 +3787,13 @@ COMMAND_HANDLER(handle_bp_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); asid = 0; - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); } else if (strcmp(CMD_ARGV[2], "hw_ctx") == 0) { hw = BKPT_HARD; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], asid); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); addr = 0; - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); } /* fallthrough */ case 4: @@ -3801,7 +3801,7 @@ COMMAND_HANDLER(handle_bp_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], asid); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], length); - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); default: return ERROR_COMMAND_SYNTAX_ERROR; From fd66dfb61de9699501ef1e7187fcc8d91cb642c3 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:22:35 +0200 Subject: [PATCH 084/176] target: change prototype of binprint() To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of binprint() to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I5ebdc50417d97c791c98ac0cfe2218319809eb7f Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5077 Tested-by: jenkins --- src/target/target.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index bffb55410..58864ce2c 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5939,13 +5939,13 @@ COMMAND_HANDLER(handle_ps_command) } } -static void binprint(struct command_context *cmd_ctx, const char *text, const uint8_t *buf, int size) +static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size) { if (text != NULL) - command_print_sameline(cmd_ctx, "%s", text); + command_print_sameline(cmd->ctx, "%s", text); for (int i = 0; i < size; i++) - command_print_sameline(cmd_ctx, " %02x", buf[i]); - command_print(cmd_ctx, " "); + command_print_sameline(cmd->ctx, " %02x", buf[i]); + command_print(cmd->ctx, " "); } COMMAND_HANDLER(handle_test_mem_access_command) @@ -6028,8 +6028,8 @@ COMMAND_HANDLER(handle_test_mem_access_command) duration_kbps(&bench, count * size)); } else { command_print(CMD_CTX, "Compare failed"); - binprint(CMD_CTX, "ref:", read_ref, host_bufsiz); - binprint(CMD_CTX, "buf:", read_buf, host_bufsiz); + binprint(CMD, "ref:", read_ref, host_bufsiz); + binprint(CMD, "buf:", read_buf, host_bufsiz); } next: free(read_ref); @@ -6114,8 +6114,8 @@ out: duration_kbps(&bench, count * size)); } else { command_print(CMD_CTX, "Compare failed"); - binprint(CMD_CTX, "ref:", read_ref, num_bytes); - binprint(CMD_CTX, "buf:", read_buf, num_bytes); + binprint(CMD, "ref:", read_ref, num_bytes); + binprint(CMD, "buf:", read_buf, num_bytes); } nextw: free(read_ref); From 3f8f7352d2f64411df6eee48a63c71e7bded6056 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:37:24 +0200 Subject: [PATCH 085/176] target/esirisc_trace: change prototype of trace analyse functions To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of esirisc_trace_analyze*() functions to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ie7cfd323fe591a987ea648a20be2bb9c7273dde8 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5078 Tested-by: jenkins Reviewed-by: Steven Stallion --- src/target/esirisc_trace.c | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/target/esirisc_trace.c b/src/target/esirisc_trace.c index 4e0a15529..8df555a16 100644 --- a/src/target/esirisc_trace.c +++ b/src/target/esirisc_trace.c @@ -385,9 +385,9 @@ static int esirisc_trace_read_buffer(struct target *target, uint8_t *buffer) buffer_cur - trace_info->buffer_start, buffer); } -static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); const uint32_t num_bits = size * 8; int retval; @@ -403,7 +403,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * case ESIRISC_TRACE_ID_EXECUTE: case ESIRISC_TRACE_ID_STALL: case ESIRISC_TRACE_ID_BRANCH: - command_print(cmd_ctx, "%s", esirisc_trace_id_strings[id]); + command_print(cmd->ctx, "%s", esirisc_trace_id_strings[id]); break; case ESIRISC_TRACE_ID_EXTENDED: { @@ -417,7 +417,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * case ESIRISC_TRACE_EXT_ID_STOP: case ESIRISC_TRACE_EXT_ID_WAIT: case ESIRISC_TRACE_EXT_ID_MULTICYCLE: - command_print(cmd_ctx, "%s", esirisc_trace_ext_id_strings[ext_id]); + command_print(cmd->ctx, "%s", esirisc_trace_ext_id_strings[ext_id]); break; case ESIRISC_TRACE_EXT_ID_ERET: @@ -430,11 +430,11 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "%s PC: 0x%" PRIx32, + command_print(cmd->ctx, "%s PC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], pc); if (ext_id == ESIRISC_TRACE_EXT_ID_END_PC) { - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd->ctx, "--- end of trace ---"); return ERROR_OK; } break; @@ -450,7 +450,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, + command_print(cmd->ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], eid, epc); break; } @@ -461,34 +461,34 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "repeats %" PRId32 " %s", count, + command_print(cmd->ctx, "repeats %" PRId32 " %s", count, (count == 1) ? "time" : "times"); break; } case ESIRISC_TRACE_EXT_ID_END: - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd->ctx, "--- end of trace ---"); return ERROR_OK; default: - command_print(cmd_ctx, "invalid extended trace ID: %" PRId32, ext_id); + command_print(cmd->ctx, "invalid extended trace ID: %" PRId32, ext_id); return ERROR_FAIL; } break; } default: - command_print(cmd_ctx, "invalid trace ID: %" PRId32, id); + command_print(cmd->ctx, "invalid trace ID: %" PRId32, id); return ERROR_FAIL; } } fail: - command_print(cmd_ctx, "trace buffer too small"); + command_print(cmd->ctx, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } -static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze_simple(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; const uint32_t end_of_trace = BIT_MASK(trace_info->pc_bits) << 1; @@ -504,45 +504,45 @@ static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t break; if (pc == end_of_trace) { - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd->ctx, "--- end of trace ---"); return ERROR_OK; } - command_print(cmd_ctx, "PC: 0x%" PRIx32, pc); + command_print(cmd->ctx, "PC: 0x%" PRIx32, pc); } - command_print(cmd_ctx, "trace buffer too small"); + command_print(cmd->ctx, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } -static int esirisc_trace_analyze(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; switch (trace_info->format) { case ESIRISC_TRACE_FORMAT_FULL: - command_print(cmd_ctx, "--- full pipeline ---"); - return esirisc_trace_analyze_full(cmd_ctx, buffer, size); + command_print(cmd->ctx, "--- full pipeline ---"); + return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_BRANCH: - command_print(cmd_ctx, "--- branches taken ---"); - return esirisc_trace_analyze_full(cmd_ctx, buffer, size); + command_print(cmd->ctx, "--- branches taken ---"); + return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_ICACHE: - command_print(cmd_ctx, "--- icache misses ---"); - return esirisc_trace_analyze_simple(cmd_ctx, buffer, size); + command_print(cmd->ctx, "--- icache misses ---"); + return esirisc_trace_analyze_simple(cmd, buffer, size); default: - command_print(cmd_ctx, "invalid trace format: %i", trace_info->format); + command_print(cmd->ctx, "invalid trace format: %i", trace_info->format); return ERROR_FAIL; } } -static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) +static int esirisc_trace_analyze_buffer(struct command_invocation *cmd) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; uint8_t *buffer; @@ -552,7 +552,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd->ctx, "out of memory"); return ERROR_FAIL; } @@ -560,7 +560,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) if (retval != ERROR_OK) goto done; - retval = esirisc_trace_analyze(cmd_ctx, buffer, size); + retval = esirisc_trace_analyze(cmd, buffer, size); done: free(buffer); @@ -568,16 +568,16 @@ done: return retval; } -static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx, +static int esirisc_trace_analyze_memory(struct command_invocation *cmd, target_addr_t address, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); uint8_t *buffer; int retval; buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd->ctx, "out of memory"); return ERROR_FAIL; } @@ -585,7 +585,7 @@ static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx, if (retval != ERROR_OK) goto done; - retval = esirisc_trace_analyze(cmd_ctx, buffer, size); + retval = esirisc_trace_analyze(cmd, buffer, size); done: free(buffer); @@ -821,12 +821,12 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command) return ERROR_FAIL; } - return esirisc_trace_analyze_buffer(CMD_CTX); + return esirisc_trace_analyze_buffer(CMD); } else { COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size); - return esirisc_trace_analyze_memory(CMD_CTX, address, size); + return esirisc_trace_analyze_memory(CMD, address, size); } } From 7060286175166bb78c803c79121d20dd6eddd693 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:42:24 +0200 Subject: [PATCH 086/176] target/esirisc_trace: change prototype of trace dump functions To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of esirisc_trace_dump*() functions to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Ia43bff112372cbb76e1aea9f59f4a9b6df05c15d Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5079 Tested-by: jenkins Reviewed-by: Steven Stallion --- src/target/esirisc_trace.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/target/esirisc_trace.c b/src/target/esirisc_trace.c index 8df555a16..d07a0da9c 100644 --- a/src/target/esirisc_trace.c +++ b/src/target/esirisc_trace.c @@ -593,7 +593,7 @@ done: return retval; } -static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filename, +static int esirisc_trace_dump(struct command_invocation *cmd, const char *filename, uint8_t *buffer, uint32_t size) { struct fileio *fileio; @@ -602,24 +602,24 @@ static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filen retval = fileio_open(&fileio, filename, FILEIO_WRITE, FILEIO_BINARY); if (retval != ERROR_OK) { - command_print(cmd_ctx, "could not open dump file: %s", filename); + command_print(cmd->ctx, "could not open dump file: %s", filename); return retval; } retval = fileio_write(fileio, size, buffer, &size_written); if (retval == ERROR_OK) - command_print(cmd_ctx, "trace data dumped to: %s", filename); + command_print(cmd->ctx, "trace data dumped to: %s", filename); else - command_print(cmd_ctx, "could not write dump file: %s", filename); + command_print(cmd->ctx, "could not write dump file: %s", filename); fileio_close(fileio); return retval; } -static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char *filename) +static int esirisc_trace_dump_buffer(struct command_invocation *cmd, const char *filename) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; uint8_t *buffer; @@ -629,7 +629,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd->ctx, "out of memory"); return ERROR_FAIL; } @@ -637,7 +637,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char if (retval != ERROR_OK) goto done; - retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size); + retval = esirisc_trace_dump(cmd, filename, buffer, size); done: free(buffer); @@ -645,16 +645,16 @@ done: return retval; } -static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char *filename, +static int esirisc_trace_dump_memory(struct command_invocation *cmd, const char *filename, target_addr_t address, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); uint8_t *buffer; int retval; buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd->ctx, "out of memory"); return ERROR_FAIL; } @@ -662,7 +662,7 @@ static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char if (retval != ERROR_OK) goto done; - retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size); + retval = esirisc_trace_dump(cmd, filename, buffer, size); done: free(buffer); @@ -853,12 +853,12 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command) return ERROR_FAIL; } - return esirisc_trace_dump_buffer(CMD_CTX, CMD_ARGV[0]); + return esirisc_trace_dump_buffer(CMD, CMD_ARGV[0]); } else { COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size); - return esirisc_trace_dump_memory(CMD_CTX, CMD_ARGV[2], address, size); + return esirisc_trace_dump_memory(CMD, CMD_ARGV[2], address, size); } } From 69165509386efffc2848ac3b345be750f1ddbe56 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 1 Apr 2019 05:54:15 +0200 Subject: [PATCH 087/176] jlink: change prototype of show_config*() functions To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should be ready to switch to CMD as first parameter. Change prototype of show_config*() functions to pass CMD instead of CMD_CTX. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I131a904774bf60ad1bf9d90dbc65927c246ac23a Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5080 Tested-by: jenkins --- src/jtag/drivers/jlink.c | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 5a17dfd43..090eeaa64 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -1101,49 +1101,49 @@ COMMAND_HANDLER(jlink_handle_target_power_command) return ERROR_OK; } -static void show_config_usb_address(struct command_context *ctx) +static void show_config_usb_address(struct command_invocation *cmd) { if (config.usb_address != tmp_config.usb_address) - command_print(ctx, "USB address: %u [%u]", config.usb_address, + command_print(cmd->ctx, "USB address: %u [%u]", config.usb_address, tmp_config.usb_address); else - command_print(ctx, "USB address: %u", config.usb_address); + command_print(cmd->ctx, "USB address: %u", config.usb_address); } -static void show_config_ip_address(struct command_context *ctx) +static void show_config_ip_address(struct command_invocation *cmd) { if (!memcmp(config.ip_address, tmp_config.ip_address, 4)) - command_print(ctx, "IP address: %d.%d.%d.%d", + command_print(cmd->ctx, "IP address: %d.%d.%d.%d", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0]); else - command_print(ctx, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd->ctx, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0], tmp_config.ip_address[3], tmp_config.ip_address[2], tmp_config.ip_address[1], tmp_config.ip_address[0]); if (!memcmp(config.subnet_mask, tmp_config.subnet_mask, 4)) - command_print(ctx, "Subnet mask: %d.%d.%d.%d", + command_print(cmd->ctx, "Subnet mask: %d.%d.%d.%d", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0]); else - command_print(ctx, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd->ctx, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0], tmp_config.subnet_mask[3], tmp_config.subnet_mask[2], tmp_config.subnet_mask[1], tmp_config.subnet_mask[0]); } -static void show_config_mac_address(struct command_context *ctx) +static void show_config_mac_address(struct command_invocation *cmd) { if (!memcmp(config.mac_address, tmp_config.mac_address, 6)) - command_print(ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", + command_print(cmd->ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], config.mac_address[1], config.mac_address[0]); else - command_print(ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " + command_print(cmd->ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], @@ -1153,7 +1153,7 @@ static void show_config_mac_address(struct command_context *ctx) tmp_config.mac_address[1], tmp_config.mac_address[0]); } -static void show_config_target_power(struct command_context *ctx) +static void show_config_target_power(struct command_invocation *cmd) { const char *target_power; const char *current_target_power; @@ -1169,24 +1169,24 @@ static void show_config_target_power(struct command_context *ctx) current_target_power = "on"; if (config.target_power != tmp_config.target_power) - command_print(ctx, "Target power supply: %s [%s]", target_power, + command_print(cmd->ctx, "Target power supply: %s [%s]", target_power, current_target_power); else - command_print(ctx, "Target power supply: %s", target_power); + command_print(cmd->ctx, "Target power supply: %s", target_power); } -static void show_config(struct command_context *ctx) +static void show_config(struct command_invocation *cmd) { - command_print(ctx, "J-Link device configuration:"); + command_print(cmd->ctx, "J-Link device configuration:"); - show_config_usb_address(ctx); + show_config_usb_address(cmd); if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) - show_config_target_power(ctx); + show_config_target_power(cmd); if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - show_config_ip_address(ctx); - show_config_mac_address(ctx); + show_config_ip_address(cmd); + show_config_mac_address(cmd); } } @@ -1352,7 +1352,7 @@ COMMAND_HANDLER(jlink_handle_config_usb_address_command) } if (!CMD_ARGC) { - show_config_usb_address(CMD_CTX); + show_config_usb_address(CMD); } else if (CMD_ARGC == 1) { if (sscanf(CMD_ARGV[0], "%" SCNd8, &tmp) != 1) { command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); @@ -1391,7 +1391,7 @@ COMMAND_HANDLER(jlink_handle_config_target_power_command) } if (!CMD_ARGC) { - show_config_target_power(CMD_CTX); + show_config_target_power(CMD); } else if (CMD_ARGC == 1) { if (!strcmp(CMD_ARGV[0], "on")) { enable = true; @@ -1432,7 +1432,7 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) } if (!CMD_ARGC) { - show_config_mac_address(CMD_CTX); + show_config_mac_address(CMD); } else if (CMD_ARGC == 1) { str = CMD_ARGV[0]; @@ -1520,7 +1520,7 @@ COMMAND_HANDLER(jlink_handle_config_ip_address_command) } if (!CMD_ARGC) { - show_config_ip_address(CMD_CTX); + show_config_ip_address(CMD); } else { if (!string_to_ip(CMD_ARGV[0], ip_address, &i)) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1616,7 +1616,7 @@ COMMAND_HANDLER(jlink_handle_config_command) } if (CMD_ARGC == 0) - show_config(CMD_CTX); + show_config(CMD); return ERROR_OK; } From 6cb5ba6f1136df2986850f5c176cb38e34ca1795 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 3 Apr 2019 10:37:24 +0200 Subject: [PATCH 088/176] helper/command: change prototype of command_print/command_print_sameline To prepare for handling TCL return values consistently, all calls to command_print/command_print_sameline should switch to CMD as first parameter. Change prototype of command_print() and command_print_sameline() to pass CMD instead of CMD_CTX. Since the first parameter is currently not used, the change can be done though scripts without manual coding. This patch is created using the command: sed -i PATTERN $(find src/ doc/ -type f) with all the following patters: 's/\(command_print(cmd\)->ctx,/\1,/' 's/\(command_print(CMD\)_CTX,/\1,/' 's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/' 's/\(command_print_sameline(cmd\)->ctx,/\1,/' 's/\(command_print_sameline(CMD\)_CTX,/\1,/' 's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/' This change is inspired by http://openocd.zylin.com/1815 from Paul Fertser but is now done through scripting. Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385 Signed-off-by: Antonio Borneo Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/5081 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/manual/primer/commands.txt | 2 +- src/flash/mflash.c | 6 +- src/flash/nand/at91sam9.c | 10 +- src/flash/nand/core.c | 2 +- src/flash/nand/fileio.c | 10 +- src/flash/nand/lpc3180.c | 6 +- src/flash/nand/lpc32xx.c | 4 +- src/flash/nand/mxc.c | 6 +- src/flash/nand/tcl.c | 44 ++++---- src/flash/nor/ambiqmicro.c | 10 +- src/flash/nor/at91sam3.c | 26 ++--- src/flash/nor/at91sam4.c | 26 ++--- src/flash/nor/at91sam7.c | 4 +- src/flash/nor/at91samd.c | 30 +++--- src/flash/nor/atsame5.c | 12 +-- src/flash/nor/atsamv.c | 10 +- src/flash/nor/avrf.c | 4 +- src/flash/nor/efm32.c | 2 +- src/flash/nor/em357.c | 16 +-- src/flash/nor/esirisc_flash.c | 4 +- src/flash/nor/fm3.c | 4 +- src/flash/nor/kinetis.c | 26 ++--- src/flash/nor/lpc2000.c | 6 +- src/flash/nor/lpc2900.c | 16 +-- src/flash/nor/max32xxx.c | 28 ++--- src/flash/nor/niietcm4.c | 46 ++++---- src/flash/nor/numicro.c | 4 +- src/flash/nor/pic32mx.c | 12 +-- src/flash/nor/psoc4.c | 4 +- src/flash/nor/psoc5lp.c | 4 +- src/flash/nor/stellaris.c | 4 +- src/flash/nor/stm32f1x.c | 40 +++---- src/flash/nor/stm32f2x.c | 56 +++++----- src/flash/nor/stm32h7x.c | 18 ++-- src/flash/nor/stm32l4x.c | 20 ++-- src/flash/nor/stm32lx.c | 12 +-- src/flash/nor/str9xpec.c | 32 +++--- src/flash/nor/tcl.c | 56 +++++----- src/flash/nor/tms470.c | 14 +-- src/flash/nor/xmc4xxx.c | 6 +- src/hello.c | 2 +- src/helper/command.c | 4 +- src/helper/command.h | 10 +- src/helper/ioutil.c | 14 +-- src/helper/log.c | 2 +- src/jtag/adapter.c | 16 +-- src/jtag/aice/aice_interface.c | 6 +- src/jtag/aice/aice_transport.c | 8 +- src/jtag/drivers/amt_jtagaccel.c | 4 +- src/jtag/drivers/bcm2835gpio.c | 20 ++-- src/jtag/drivers/ft232r.c | 16 +-- src/jtag/drivers/ftdi.c | 2 +- src/jtag/drivers/gw16012.c | 2 +- src/jtag/drivers/imx_gpio.c | 20 ++-- src/jtag/drivers/jlink.c | 108 +++++++++---------- src/jtag/drivers/opendous.c | 2 +- src/jtag/drivers/parport.c | 4 +- src/jtag/drivers/sysfsgpio.c | 20 ++-- src/jtag/tcl.c | 24 ++--- src/pld/pld.c | 10 +- src/pld/virtex2.c | 6 +- src/server/gdb_server.c | 2 +- src/server/server.c | 6 +- src/svf/svf.c | 10 +- src/target/aarch64.c | 2 +- src/target/arm720t.c | 12 +-- src/target/arm7_9_common.c | 12 +-- src/target/arm920t.c | 30 +++--- src/target/arm926ejs.c | 2 +- src/target/arm946e.c | 18 ++-- src/target/arm966e.c | 12 +-- src/target/arm9tdmi.c | 6 +- src/target/arm_adi_v5.c | 70 ++++++------ src/target/arm_cti.c | 4 +- src/target/armv4_5.c | 24 ++--- src/target/armv4_5_cache.c | 8 +- src/target/armv7a.c | 10 +- src/target/armv7a_cache.c | 2 +- src/target/armv7a_cache_l2x.c | 6 +- src/target/armv8.c | 4 +- src/target/armv8_cache.c | 6 +- src/target/cortex_a.c | 4 +- src/target/cortex_m.c | 10 +- src/target/dsp563xx.c | 2 +- src/target/esirisc.c | 6 +- src/target/esirisc_trace.c | 106 +++++++++--------- src/target/etb.c | 14 +-- src/target/etm.c | 178 +++++++++++++++---------------- src/target/etm_dummy.c | 2 +- src/target/mips32.c | 18 ++-- src/target/mips_m4k.c | 18 ++-- src/target/nds32_cmd.c | 120 ++++++++++----------- src/target/oocd_trace.c | 20 ++-- src/target/openrisc/or1k.c | 4 +- src/target/riscv/riscv.c | 4 +- src/target/semihosting_common.c | 20 ++-- src/target/smp.c | 4 +- src/target/stm8.c | 4 +- src/target/target.c | 128 +++++++++++----------- src/target/target_request.c | 2 +- src/target/trace.c | 10 +- src/target/x86_32_common.c | 2 +- src/target/xscale.c | 46 ++++---- src/transport/transport.c | 4 +- src/xsvf/xsvf.c | 12 +-- 105 files changed, 963 insertions(+), 963 deletions(-) diff --git a/doc/manual/primer/commands.txt b/doc/manual/primer/commands.txt index a626f56b5..8ea228205 100644 --- a/doc/manual/primer/commands.txt +++ b/doc/manual/primer/commands.txt @@ -16,7 +16,7 @@ COMMAND_HANDLER(handle_hello_command) const char *sep, *name; int retval = CALL_COMMAND_HANDLER(handle_hello_args); if (ERROR_OK == retval) - command_print(CMD_CTX, "Greetings%s%s!", sep, name); + command_print(CMD, "Greetings%s%s!", sep, name); return retval; } @endcode diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 1ad7290fa..acf1441b7 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -423,7 +423,7 @@ COMMAND_HANDLER(mg_probe_cmd) ret = mg_mflash_probe(); if (ret == ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "mflash (total %" PRIu32 " sectors) found at 0x%8.8" PRIx32 "", mflash_bank->drv_info->tot_sects, mflash_bank->base); @@ -799,7 +799,7 @@ COMMAND_HANDLER(mg_write_cmd) } if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD_CTX, "wrote %zu bytes from file %s " + command_print(CMD, "wrote %zu bytes from file %s " "in %fs (%0.3f kB/s)", filesize, CMD_ARGV[1], duration_elapsed(&bench), duration_kbps(&bench, filesize)); } @@ -866,7 +866,7 @@ COMMAND_HANDLER(mg_dump_cmd) } if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD_CTX, "dump image (address 0x%8.8" PRIx32 " " + command_print(CMD, "dump image (address 0x%8.8" PRIx32 " " "size %" PRIu32 ") to file %s in %fs (%0.3f kB/s)", address, size, CMD_ARGV[1], duration_elapsed(&bench), duration_kbps(&bench, size)); diff --git a/src/flash/nand/at91sam9.c b/src/flash/nand/at91sam9.c index 0af12b20c..47c050563 100644 --- a/src/flash/nand/at91sam9.c +++ b/src/flash/nand/at91sam9.c @@ -547,14 +547,14 @@ COMMAND_HANDLER(handle_at91sam9_cle_command) unsigned num, address_line; if (CMD_ARGC != 2) { - command_print(CMD_CTX, "incorrect number of arguments for 'at91sam9 cle' command"); + command_print(CMD, "incorrect number of arguments for 'at91sam9 cle' command"); return ERROR_OK; } COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_OK; } @@ -582,7 +582,7 @@ COMMAND_HANDLER(handle_at91sam9_ale_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -610,7 +610,7 @@ COMMAND_HANDLER(handle_at91sam9_rdy_busy_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -641,7 +641,7 @@ COMMAND_HANDLER(handle_at91sam9_ce_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } diff --git a/src/flash/nand/core.c b/src/flash/nand/core.c index 7428d2253..b9ac793f2 100644 --- a/src/flash/nand/core.c +++ b/src/flash/nand/core.c @@ -217,7 +217,7 @@ COMMAND_HELPER(nand_command_get_device, unsigned name_index, COMMAND_PARSE_NUMBER(uint, str, num); *nand = get_nand_device_by_num(num); if (!*nand) { - command_print(CMD_CTX, "NAND flash device '%s' not found", str); + command_print(CMD, "NAND flash device '%s' not found", str); return ERROR_COMMAND_SYNTAX_ERROR; } return ERROR_OK; diff --git a/src/flash/nand/fileio.c b/src/flash/nand/fileio.c index 76f6e104a..f65f957bf 100644 --- a/src/flash/nand/fileio.c +++ b/src/flash/nand/fileio.c @@ -59,7 +59,7 @@ int nand_fileio_start(struct command_invocation *cmd, struct nand_fileio_state *state) { if (state->address % nand->page_size) { - command_print(cmd->ctx, "only page-aligned addresses are supported"); + command_print(cmd, "only page-aligned addresses are supported"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -69,7 +69,7 @@ int nand_fileio_start(struct command_invocation *cmd, int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY); if (ERROR_OK != retval) { const char *msg = (FILEIO_READ == filemode) ? "read" : "write"; - command_print(cmd->ctx, "failed to open '%s' for %s access", + command_print(cmd, "failed to open '%s' for %s access", filename, msg); return retval; } @@ -131,7 +131,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, return retval; if (NULL == nand->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_NAND_DEVICE_NOT_PROBED; } @@ -139,7 +139,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, if (need_size) { COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], state->size); if (state->size % nand->page_size) { - command_print(CMD_CTX, "only page-aligned sizes are supported"); + command_print(CMD, "only page-aligned sizes are supported"); return ERROR_COMMAND_SYNTAX_ERROR; } } @@ -155,7 +155,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, else if (sw_ecc && !strcmp(CMD_ARGV[i], "oob_softecc_kw")) state->oob_format |= NAND_OOB_SW_ECC_KW; else { - command_print(CMD_CTX, "unknown option: %s", CMD_ARGV[i]); + command_print(CMD, "unknown option: %s", CMD_ARGV[i]); return ERROR_COMMAND_SYNTAX_ERROR; } } diff --git a/src/flash/nand/lpc3180.c b/src/flash/nand/lpc3180.c index d15fdce38..436580e37 100644 --- a/src/flash/nand/lpc3180.c +++ b/src/flash/nand/lpc3180.c @@ -1290,7 +1290,7 @@ COMMAND_HANDLER(handle_lpc3180_select_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); struct nand_device *nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "nand device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "nand device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -1310,10 +1310,10 @@ COMMAND_HANDLER(handle_lpc3180_select_command) } if (lpc3180_info->selected_controller == LPC3180_MLC_CONTROLLER) - command_print(CMD_CTX, "%s controller selected", + command_print(CMD, "%s controller selected", selected[lpc3180_info->selected_controller]); else - command_print(CMD_CTX, + command_print(CMD, lpc3180_info->is_bulk ? "%s controller selected bulk mode is available" : "%s controller selected bulk mode is not available", selected[lpc3180_info->selected_controller]); diff --git a/src/flash/nand/lpc32xx.c b/src/flash/nand/lpc32xx.c index 1ed16dfd0..6febe16a1 100644 --- a/src/flash/nand/lpc32xx.c +++ b/src/flash/nand/lpc32xx.c @@ -1760,7 +1760,7 @@ COMMAND_HANDLER(handle_lpc32xx_select_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); struct nand_device *nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "nand device '#%s' is out of bounds", + command_print(CMD, "nand device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -1778,7 +1778,7 @@ COMMAND_HANDLER(handle_lpc32xx_select_command) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "%s controller selected", + command_print(CMD, "%s controller selected", selected[lpc32xx_info->selected_controller]); return ERROR_OK; diff --git a/src/flash/nand/mxc.c b/src/flash/nand/mxc.c index 6069c6268..b54115731 100644 --- a/src/flash/nand/mxc.c +++ b/src/flash/nand/mxc.c @@ -157,7 +157,7 @@ COMMAND_HANDLER(handle_mxc_biswap_command) int retval = CALL_COMMAND_HANDLER(nand_command_get_device, 0, &nand); if (retval != ERROR_OK) { - command_print(CMD_CTX, "invalid nand device number or name: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number or name: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -169,9 +169,9 @@ COMMAND_HANDLER(handle_mxc_biswap_command) mxc_nf_info->flags.biswap_enabled = false; } if (mxc_nf_info->flags.biswap_enabled) - command_print(CMD_CTX, "BI-swapping enabled on %s", nand->name); + command_print(CMD, "BI-swapping enabled on %s", nand->name); else - command_print(CMD_CTX, "BI-swapping disabled on %s", nand->name); + command_print(CMD, "BI-swapping disabled on %s", nand->name); return ERROR_OK; } diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c index 8a7022aeb..5480e0d61 100644 --- a/src/flash/nand/tcl.c +++ b/src/flash/nand/tcl.c @@ -37,20 +37,20 @@ COMMAND_HANDLER(handle_nand_list_command) int i; if (!nand_devices) { - command_print(CMD_CTX, "no NAND flash devices configured"); + command_print(CMD, "no NAND flash devices configured"); return ERROR_OK; } for (p = nand_devices, i = 0; p; p = p->next, i++) { if (p->device) - command_print(CMD_CTX, "#%i: %s (%s) " + command_print(CMD, "#%i: %s (%s) " "pagesize: %i, buswidth: %i,\n\t" "blocksize: %i, blocks: %i", i, p->device->name, p->manufacturer->name, p->page_size, p->bus_width, p->erase_size, p->num_blocks); else - command_print(CMD_CTX, "#%i: not probed", i); + command_print(CMD, "#%i: not probed", i); } return ERROR_OK; @@ -87,7 +87,7 @@ COMMAND_HANDLER(handle_nand_info_command) return retval; if (NULL == p->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_OK; } @@ -97,7 +97,7 @@ COMMAND_HANDLER(handle_nand_info_command) if (last >= p->num_blocks) last = p->num_blocks - 1; - command_print(CMD_CTX, + command_print(CMD, "#%i: %s (%s) pagesize: %i, buswidth: %i, erasesize: %i", i++, p->device->name, @@ -123,7 +123,7 @@ COMMAND_HANDLER(handle_nand_info_command) else bad_state = " (block condition unknown)"; - command_print(CMD_CTX, + command_print(CMD, "\t#%i: 0x%8.8" PRIx32 " (%" PRId32 "kB) %s%s", j, p->blocks[j].offset, @@ -147,7 +147,7 @@ COMMAND_HANDLER(handle_nand_probe_command) retval = nand_probe(p); if (retval == ERROR_OK) { - command_print(CMD_CTX, "NAND flash device '%s (%s)' found", + command_print(CMD, "NAND flash device '%s (%s)' found", p->device->name, p->manufacturer->name); } @@ -189,7 +189,7 @@ COMMAND_HANDLER(handle_nand_erase_command) retval = nand_erase(p, offset, offset + length - 1); if (retval == ERROR_OK) { - command_print(CMD_CTX, "erased blocks %lu to %lu " + command_print(CMD, "erased blocks %lu to %lu " "on NAND flash device #%s '%s'", offset, offset + length - 1, CMD_ARGV[0], p->device->name); @@ -233,7 +233,7 @@ COMMAND_HANDLER(handle_nand_check_bad_blocks_command) retval = nand_build_bbt(p, first, last); if (retval == ERROR_OK) { - command_print(CMD_CTX, "checked NAND flash device for bad blocks, " + command_print(CMD, "checked NAND flash device for bad blocks, " "use \"nand info\" command to list blocks"); } @@ -253,7 +253,7 @@ COMMAND_HANDLER(handle_nand_write_command) while (s.size > 0) { int bytes_read = nand_fileio_read(nand, &s); if (bytes_read <= 0) { - command_print(CMD_CTX, "error while reading file"); + command_print(CMD, "error while reading file"); nand_fileio_cleanup(&s); return ERROR_FAIL; } @@ -262,7 +262,7 @@ COMMAND_HANDLER(handle_nand_write_command) retval = nand_write_page(nand, s.address / nand->page_size, s.page, s.page_size, s.oob, s.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "failed writing file %s " + command_print(CMD, "failed writing file %s " "to NAND flash %s at offset 0x%8.8" PRIx32, CMD_ARGV[1], CMD_ARGV[0], s.address); nand_fileio_cleanup(&s); @@ -272,7 +272,7 @@ COMMAND_HANDLER(handle_nand_write_command) } if (nand_fileio_finish(&s) == ERROR_OK) { - command_print(CMD_CTX, "wrote file %s to NAND flash %s up to " + command_print(CMD, "wrote file %s to NAND flash %s up to " "offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", CMD_ARGV[1], CMD_ARGV[0], s.address, duration_elapsed(&s.bench), duration_kbps(&s.bench, total_bytes)); @@ -302,7 +302,7 @@ COMMAND_HANDLER(handle_nand_verify_command) retval = nand_read_page(nand, dev.address / dev.page_size, dev.page, dev.page_size, dev.oob, dev.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "reading NAND flash page failed"); + command_print(CMD, "reading NAND flash page failed"); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); return retval; @@ -310,7 +310,7 @@ COMMAND_HANDLER(handle_nand_verify_command) int bytes_read = nand_fileio_read(nand, &file); if (bytes_read <= 0) { - command_print(CMD_CTX, "error while reading file"); + command_print(CMD, "error while reading file"); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); return ERROR_FAIL; @@ -318,7 +318,7 @@ COMMAND_HANDLER(handle_nand_verify_command) if ((dev.page && memcmp(dev.page, file.page, dev.page_size)) || (dev.oob && memcmp(dev.oob, file.oob, dev.oob_size))) { - command_print(CMD_CTX, "NAND flash contents differ " + command_print(CMD, "NAND flash contents differ " "at 0x%8.8" PRIx32, dev.address); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); @@ -330,7 +330,7 @@ COMMAND_HANDLER(handle_nand_verify_command) } if (nand_fileio_finish(&file) == ERROR_OK) { - command_print(CMD_CTX, "verified file %s in NAND flash %s " + command_print(CMD, "verified file %s in NAND flash %s " "up to offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", CMD_ARGV[1], CMD_ARGV[0], dev.address, duration_elapsed(&file.bench), duration_kbps(&file.bench, dev.size)); @@ -354,7 +354,7 @@ COMMAND_HANDLER(handle_nand_dump_command) retval = nand_read_page(nand, s.address / nand->page_size, s.page, s.page_size, s.oob, s.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "reading NAND flash page failed"); + command_print(CMD, "reading NAND flash page failed"); nand_fileio_cleanup(&s); return retval; } @@ -374,7 +374,7 @@ COMMAND_HANDLER(handle_nand_dump_command) return retval; if (nand_fileio_finish(&s) == ERROR_OK) { - command_print(CMD_CTX, "dumped %zu bytes in %fs (%0.3f KiB/s)", + command_print(CMD, "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize, duration_elapsed(&s.bench), duration_kbps(&s.bench, filesize)); } @@ -392,7 +392,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command) return retval; if (NULL == p->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_OK; } @@ -400,7 +400,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command) COMMAND_PARSE_ENABLE(CMD_ARGV[1], p->use_raw); const char *msg = p->use_raw ? "enabled" : "disabled"; - command_print(CMD_CTX, "raw access is %s", msg); + command_print(CMD, "raw access is %s", msg); return ERROR_OK; } @@ -502,13 +502,13 @@ COMMAND_HANDLER(handle_nand_init_command) static int nand_list_walker(struct nand_flash_controller *c, void *x) { struct command_invocation *cmd = x; - command_print(cmd->ctx, " %s", c->name); + command_print(cmd, " %s", c->name); return ERROR_OK; } COMMAND_HANDLER(handle_nand_list_drivers) { - command_print(CMD_CTX, "Available NAND flash controller drivers:"); + command_print(CMD, "Available NAND flash controller drivers:"); return nand_driver_walk(&nand_list_walker, CMD); } diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c index a536d5456..b1e3e72a9 100644 --- a/src/flash/nor/ambiqmicro.c +++ b/src/flash/nor/ambiqmicro.c @@ -791,9 +791,9 @@ COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "ambiqmicro mass erase complete"); + command_print(CMD, "ambiqmicro mass erase complete"); } else - command_print(CMD_CTX, "ambiqmicro mass erase failed"); + command_print(CMD, "ambiqmicro mass erase failed"); return ERROR_OK; } @@ -815,9 +815,9 @@ COMMAND_HANDLER(ambiqmicro_handle_page_erase_command) return retval; if (ambiqmicro_erase(bank, first, last) == ERROR_OK) - command_print(CMD_CTX, "ambiqmicro page erase complete"); + command_print(CMD, "ambiqmicro page erase complete"); else - command_print(CMD_CTX, "ambiqmicro page erase failed"); + command_print(CMD, "ambiqmicro page erase failed"); return ERROR_OK; } @@ -838,7 +838,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], offset); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count); - command_print(CMD_CTX, "offset=0x%08x count=%d", offset, count); + command_print(CMD, "offset=0x%08x count=%d", offset, count); CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index 616c3fe9d..2457c15f3 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -256,7 +256,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd) t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd->ctx, "No current target?"); + command_print(cmd, "No current target?"); return NULL; } @@ -264,7 +264,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd->ctx, "No SAM3 chips exist?"); + command_print(cmd, "No SAM3 chips exist?"); return NULL; } @@ -273,7 +273,7 @@ static struct sam3_chip *get_current_sam3(struct command_invocation *cmd) return p; p = p->next; } - command_print(cmd->ctx, "Cannot find SAM3 chip?"); + command_print(cmd, "Cannot find SAM3 chip?"); return NULL; } @@ -3549,7 +3549,7 @@ COMMAND_HANDLER(sam3_handle_info_command) if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(CMD_CTX, + command_print(CMD, "Please define bank %d via command: flash bank %s ... ", x, at91sam3_flash.name); @@ -3608,7 +3608,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) } if (pChip->details.bank[0].pBank == NULL) { - command_print(CMD_CTX, "Bank0 must be defined first via: flash bank %s ...", + command_print(CMD, "Bank0 must be defined first via: flash bank %s ...", at91sam3_flash.name); return ERROR_FAIL; } @@ -3647,22 +3647,22 @@ showall: r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "sam3-gpnvm%u: %u", x, v); + command_print(CMD, "sam3-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); - command_print(CMD_CTX, "sam3-gpnvm%u: %u", who, v); + command_print(CMD, "sam3-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "sam3-gpnvm invalid GPNVM: %u", who); + command_print(CMD, "sam3-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "Missing GPNVM number"); + command_print(CMD, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3672,7 +3672,7 @@ showall: (0 == strcmp("clear", CMD_ARGV[0]))) /* quietly accept both */ r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); else { - command_print(CMD_CTX, "Unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "Unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -3697,7 +3697,7 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v); if (v > 200000) { /* absurd slow clock of 200Khz? */ - command_print(CMD_CTX, "Absurd/illegal slow clock freq: %d\n", (int)(v)); + command_print(CMD, "Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; } pChip->cfg.slow_freq = v; @@ -3705,11 +3705,11 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) } default: /* error */ - command_print(CMD_CTX, "Too many parameters"); + command_print(CMD, "Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(CMD_CTX, "Slowclk freq: %d.%03dkhz", + command_print(CMD, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq / 1000), (int)(pChip->cfg.slow_freq % 1000)); return ERROR_OK; diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 719da2bb2..621754c90 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -235,7 +235,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd) t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd->ctx, "No current target?"); + command_print(cmd, "No current target?"); return NULL; } @@ -243,7 +243,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd->ctx, "No SAM4 chips exist?"); + command_print(cmd, "No SAM4 chips exist?"); return NULL; } @@ -252,7 +252,7 @@ static struct sam4_chip *get_current_sam4(struct command_invocation *cmd) return p; p = p->next; } - command_print(cmd->ctx, "Cannot find SAM4 chip?"); + command_print(cmd, "Cannot find SAM4 chip?"); return NULL; } @@ -3029,7 +3029,7 @@ COMMAND_HANDLER(sam4_handle_info_command) if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(CMD_CTX, + command_print(CMD, "Please define bank %d via command: flash bank %s ... ", x, at91sam4_flash.name); @@ -3088,7 +3088,7 @@ COMMAND_HANDLER(sam4_handle_gpnvm_command) } if (pChip->details.bank[0].pBank == NULL) { - command_print(CMD_CTX, "Bank0 must be defined first via: flash bank %s ...", + command_print(CMD, "Bank0 must be defined first via: flash bank %s ...", at91sam4_flash.name); return ERROR_FAIL; } @@ -3127,23 +3127,23 @@ showall: r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "sam4-gpnvm%u: %u", x, v); + command_print(CMD, "sam4-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); if (r == ERROR_OK) - command_print(CMD_CTX, "sam4-gpnvm%u: %u", who, v); + command_print(CMD, "sam4-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "sam4-gpnvm invalid GPNVM: %u", who); + command_print(CMD, "sam4-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "Missing GPNVM number"); + command_print(CMD, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3153,7 +3153,7 @@ showall: (0 == strcmp("clear", CMD_ARGV[0]))) /* quietly accept both */ r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); else { - command_print(CMD_CTX, "Unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "Unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -3178,7 +3178,7 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v); if (v > 200000) { /* absurd slow clock of 200Khz? */ - command_print(CMD_CTX, "Absurd/illegal slow clock freq: %d\n", (int)(v)); + command_print(CMD, "Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; } pChip->cfg.slow_freq = v; @@ -3186,11 +3186,11 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) } default: /* error */ - command_print(CMD_CTX, "Too many parameters"); + command_print(CMD, "Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(CMD_CTX, "Slowclk freq: %d.%03dkhz", + command_print(CMD, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq / 1000), (int)(pChip->cfg.slow_freq % 1000)); return ERROR_OK; diff --git a/src/flash/nor/at91sam7.c b/src/flash/nor/at91sam7.c index 15b93a29f..232260b93 100644 --- a/src/flash/nor/at91sam7.c +++ b/src/flash/nor/at91sam7.c @@ -1067,7 +1067,7 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) if (bank == NULL) return ERROR_FLASH_BANK_INVALID; if (strcmp(bank->driver->name, "at91sam7")) { - command_print(CMD_CTX, "not an at91sam7 flash bank '%s'", CMD_ARGV[0]); + command_print(CMD, "not an at91sam7 flash bank '%s'", CMD_ARGV[0]); return ERROR_FLASH_BANK_INVALID; } if (bank->target->state != TARGET_HALTED) { @@ -1091,7 +1091,7 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], bit); if ((bit < 0) || (bit >= at91sam7_info->num_nvmbits)) { - command_print(CMD_CTX, + command_print(CMD, "gpnvm bit '#%s' is out of bounds for target %s", CMD_ARGV[0], at91sam7_info->target_name); diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index c325194ed..b6cff9a67 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -947,9 +947,9 @@ COMMAND_HANDLER(samd_handle_chip_erase_command) * perform the erase. */ res = target_write_u8(target, SAMD_DSU + SAMD_DSU_CTRL_EXT, (1<<4)); if (res == ERROR_OK) - command_print(CMD_CTX, "chip erase started"); + command_print(CMD, "chip erase started"); else - command_print(CMD_CTX, "write to DSU CTRL failed"); + command_print(CMD, "write to DSU CTRL failed"); } return res; @@ -961,7 +961,7 @@ COMMAND_HANDLER(samd_handle_set_security_command) struct target *target = get_current_target(CMD_CTX); if (CMD_ARGC < 1 || (CMD_ARGC >= 1 && (strcmp(CMD_ARGV[0], "enable")))) { - command_print(CMD_CTX, "supply the \"enable\" argument to proceed."); + command_print(CMD, "supply the \"enable\" argument to proceed."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -975,9 +975,9 @@ COMMAND_HANDLER(samd_handle_set_security_command) /* Check (and clear) error conditions */ if (res == ERROR_OK) - command_print(CMD_CTX, "chip secured on next power-cycle"); + command_print(CMD, "chip secured on next power-cycle"); else - command_print(CMD_CTX, "failed to secure chip"); + command_print(CMD, "failed to secure chip"); } return res; @@ -1008,7 +1008,7 @@ COMMAND_HANDLER(samd_handle_eeprom_command) } if (code > 6) { - command_print(CMD_CTX, "Invalid EEPROM size. Please see " + command_print(CMD, "Invalid EEPROM size. Please see " "datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1022,10 +1022,10 @@ COMMAND_HANDLER(samd_handle_eeprom_command) uint32_t size = ((val >> 4) & 0x7); /* grab size code */ if (size == 0x7) - command_print(CMD_CTX, "EEPROM is disabled"); + command_print(CMD, "EEPROM is disabled"); else { /* Otherwise, 6 is 256B, 0 is 16KB */ - command_print(CMD_CTX, "EEPROM size is %u bytes", + command_print(CMD, "EEPROM size is %u bytes", (2 << (13 - size))); } } @@ -1038,7 +1038,7 @@ COMMAND_HANDLER(samd_handle_eeprom_command) static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value) { if (num >= CMD_ARGC) { - command_print(CMD_CTX, "Too few Arguments."); + command_print(CMD, "Too few Arguments."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1049,12 +1049,12 @@ static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value) *value = strtoull(&(CMD_ARGV[num][2]), &check, 16); if ((value == 0 && errno == ERANGE) || check == NULL || *check != 0) { - command_print(CMD_CTX, "Invalid 64-bit hex value in argument %d.", + command_print(CMD, "Invalid 64-bit hex value in argument %d.", num + 1); return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Argument %d needs to be a hex value.", num + 1); + command_print(CMD, "Argument %d needs to be a hex value.", num + 1); return ERROR_COMMAND_SYNTAX_ERROR; } return ERROR_OK; @@ -1067,7 +1067,7 @@ COMMAND_HANDLER(samd_handle_nvmuserrow_command) if (target) { if (CMD_ARGC > 2) { - command_print(CMD_CTX, "Too much Arguments given."); + command_print(CMD, "Too much Arguments given."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1105,7 +1105,7 @@ COMMAND_HANDLER(samd_handle_nvmuserrow_command) uint64_t value; res = read_userrow(target, &value); if (res == ERROR_OK) - command_print(CMD_CTX, "NVMUSERROW: 0x%016"PRIX64, value); + command_print(CMD, "NVMUSERROW: 0x%016"PRIX64, value); else LOG_ERROR("NVMUSERROW could not be read."); } @@ -1145,7 +1145,7 @@ COMMAND_HANDLER(samd_handle_bootloader_command) } if (code > 6) { - command_print(CMD_CTX, "Invalid bootloader size. Please " + command_print(CMD, "Invalid bootloader size. Please " "see datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1166,7 +1166,7 @@ COMMAND_HANDLER(samd_handle_bootloader_command) nb = (2 << (8 - size)) * page_size; /* There are 4 pages per row */ - command_print(CMD_CTX, "Bootloader size is %" PRIu32 " bytes (%" PRIu32 " rows)", + command_print(CMD, "Bootloader size is %" PRIu32 " bytes (%" PRIu32 " rows)", nb, (uint32_t)(nb / (page_size * 4))); } } diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 4a114a35f..eac7847dc 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -765,9 +765,9 @@ COMMAND_HANDLER(same5_handle_chip_erase_command) * perform the erase. */ int res = target_write_u8(target, SAMD_DSU + SAMD_DSU_CTRL_EXT, (1<<4)); if (res == ERROR_OK) - command_print(CMD_CTX, "chip erase started"); + command_print(CMD, "chip erase started"); else - command_print(CMD_CTX, "write to DSU CTRL failed"); + command_print(CMD, "write to DSU CTRL failed"); return res; } @@ -781,7 +781,7 @@ COMMAND_HANDLER(same5_handle_userpage_command) return ERROR_FAIL; if (CMD_ARGC > 2) { - command_print(CMD_CTX, "Too much Arguments given."); + command_print(CMD, "Too much Arguments given."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -806,7 +806,7 @@ COMMAND_HANDLER(same5_handle_userpage_command) int res2 = target_read_memory(target, SAMD_USER_ROW, 4, 2, buffer); if (res2 == ERROR_OK) { uint64_t value = target_buffer_get_u64(target, buffer); - command_print(CMD_CTX, "USER PAGE: 0x%016"PRIX64, value); + command_print(CMD, "USER PAGE: 0x%016"PRIX64, value); } else { LOG_ERROR("USER PAGE could not be read."); } @@ -829,7 +829,7 @@ COMMAND_HANDLER(same5_handle_bootloader_command) unsigned long size = strtoul(CMD_ARGV[0], NULL, 0); uint32_t code = (size + 8191) / 8192; if (code > 15) { - command_print(CMD_CTX, "Invalid bootloader size. Please " + command_print(CMD, "Invalid bootloader size. Please " "see datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -842,7 +842,7 @@ COMMAND_HANDLER(same5_handle_bootloader_command) if (res2 == ERROR_OK) { uint32_t code = (val >> 26) & 0xf; /* grab size code */ uint32_t size = (15 - code) * 8192; - command_print(CMD_CTX, "Bootloader protected in the first %" + command_print(CMD, "Bootloader protected in the first %" PRIu32 " bytes", size); } diff --git a/src/flash/nor/atsamv.c b/src/flash/nor/atsamv.c index 5beeefc5a..d6f1a0a48 100644 --- a/src/flash/nor/atsamv.c +++ b/src/flash/nor/atsamv.c @@ -672,22 +672,22 @@ showall: r = samv_get_gpnvm(target, x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "samv-gpnvm%u: %u", x, v); + command_print(CMD, "samv-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)who) < SAMV_NUM_GPNVM_BITS)) { r = samv_get_gpnvm(target, who, &v); - command_print(CMD_CTX, "samv-gpnvm%u: %u", who, v); + command_print(CMD, "samv-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "invalid gpnvm: %u", who); + command_print(CMD, "invalid gpnvm: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "missing gpnvm number"); + command_print(CMD, "missing gpnvm number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -696,7 +696,7 @@ showall: else if (!strcmp("clr", CMD_ARGV[0]) || !strcmp("clear", CMD_ARGV[0])) r = samv_clear_gpnvm(target, who); else { - command_print(CMD_CTX, "unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 6969f7741..178567e6b 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -433,9 +433,9 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "avr mass erase complete"); + command_print(CMD, "avr mass erase complete"); } else - command_print(CMD_CTX, "avr mass erase failed"); + command_print(CMD, "avr mass erase failed"); LOG_DEBUG("%s", __func__); return ERROR_OK; diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index d2ac3a8fb..83d133ff6 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -1093,7 +1093,7 @@ COMMAND_HANDLER(efm32x_handle_debuglock_command) return retval; } - command_print(CMD_CTX, "efm32x debug interface locked, reset the device to apply"); + command_print(CMD, "efm32x debug interface locked, reset the device to apply"); return ERROR_OK; } diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c index e6b27283b..38fb73189 100644 --- a/src/flash/nor/em357.c +++ b/src/flash/nor/em357.c @@ -776,7 +776,7 @@ COMMAND_HANDLER(em357_handle_lock_command) } if (em357_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to erase options"); + command_print(CMD, "em357 failed to erase options"); return ERROR_OK; } @@ -784,11 +784,11 @@ COMMAND_HANDLER(em357_handle_lock_command) em357_info->option_bytes.RDP = 0; if (em357_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to lock device"); + command_print(CMD, "em357 failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "em357 locked"); + command_print(CMD, "em357 locked"); return ERROR_OK; } @@ -813,16 +813,16 @@ COMMAND_HANDLER(em357_handle_unlock_command) } if (em357_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to unlock device"); + command_print(CMD, "em357 failed to unlock device"); return ERROR_OK; } if (em357_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to lock device"); + command_print(CMD, "em357 failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "em357 unlocked.\n" + command_print(CMD, "em357 unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -886,9 +886,9 @@ COMMAND_HANDLER(em357_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "em357 mass erase complete"); + command_print(CMD, "em357 mass erase complete"); } else - command_print(CMD_CTX, "em357 mass erase failed"); + command_print(CMD, "em357 mass erase failed"); return retval; } diff --git a/src/flash/nor/esirisc_flash.c b/src/flash/nor/esirisc_flash.c index 948d001a0..4e33b9429 100644 --- a/src/flash/nor/esirisc_flash.c +++ b/src/flash/nor/esirisc_flash.c @@ -516,7 +516,7 @@ COMMAND_HANDLER(handle_esirisc_flash_mass_erase_command) retval = esirisc_flash_mass_erase(bank); - command_print(CMD_CTX, "mass erase %s", + command_print(CMD, "mass erase %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; @@ -536,7 +536,7 @@ COMMAND_HANDLER(handle_esirisc_flash_ref_erase_command) retval = esirisc_flash_ref_erase(bank); - command_print(CMD_CTX, "erase reference cell %s", + command_print(CMD, "erase reference cell %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; diff --git a/src/flash/nor/fm3.c b/src/flash/nor/fm3.c index f2da2af8a..eeefa3f43 100644 --- a/src/flash/nor/fm3.c +++ b/src/flash/nor/fm3.c @@ -958,9 +958,9 @@ COMMAND_HANDLER(fm3_handle_chip_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "fm3 chip erase complete"); + command_print(CMD, "fm3 chip erase complete"); } else { - command_print(CMD_CTX, "fm3 chip erase failed"); + command_print(CMD, "fm3 chip erase failed"); } return ERROR_OK; diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 847513502..687a3370b 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -2895,7 +2895,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) flex_nvm_partition_code = (uint8_t)((sim_fcfg1 >> 8) & 0x0f); switch (flex_nvm_partition_code) { case 0: - command_print(CMD_CTX, "No EEPROM backup, data flash only"); + command_print(CMD, "No EEPROM backup, data flash only"); break; case 1: case 2: @@ -2903,10 +2903,10 @@ COMMAND_HANDLER(kinetis_nvm_partition) case 4: case 5: case 6: - command_print(CMD_CTX, "EEPROM backup %d KB", 4 << flex_nvm_partition_code); + command_print(CMD, "EEPROM backup %d KB", 4 << flex_nvm_partition_code); break; case 8: - command_print(CMD_CTX, "No data flash, EEPROM backup only"); + command_print(CMD, "No data flash, EEPROM backup only"); break; case 0x9: case 0xA: @@ -2914,13 +2914,13 @@ COMMAND_HANDLER(kinetis_nvm_partition) case 0xC: case 0xD: case 0xE: - command_print(CMD_CTX, "data flash %d KB", 4 << (flex_nvm_partition_code & 7)); + command_print(CMD, "data flash %d KB", 4 << (flex_nvm_partition_code & 7)); break; case 0xf: - command_print(CMD_CTX, "No EEPROM backup, data flash only (DEPART not set)"); + command_print(CMD, "No EEPROM backup, data flash only (DEPART not set)"); break; default: - command_print(CMD_CTX, "Unsupported EEPROM backup size code 0x%02" PRIx8, flex_nvm_partition_code); + command_print(CMD, "Unsupported EEPROM backup size code 0x%02" PRIx8, flex_nvm_partition_code); } return ERROR_OK; @@ -2986,7 +2986,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) if (result != ERROR_OK) return result; - command_print(CMD_CTX, "FlexNVM partition set. Please reset MCU."); + command_print(CMD, "FlexNVM partition set. Please reset MCU."); if (k_chip) { first_nvm_bank = k_chip->num_pflash_blocks; @@ -2996,7 +2996,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) k_chip->probed = false; } - command_print(CMD_CTX, "FlexNVM banks will be re-probed to set new data flash size."); + command_print(CMD, "FlexNVM banks will be re-probed to set new data flash size."); return ERROR_OK; } @@ -3015,12 +3015,12 @@ COMMAND_HANDLER(kinetis_fcf_source_handler) } if (allow_fcf_writes) { - command_print(CMD_CTX, "Arbitrary Flash Configuration Field writes enabled."); - command_print(CMD_CTX, "Protection info writes to FCF disabled."); + command_print(CMD, "Arbitrary Flash Configuration Field writes enabled."); + command_print(CMD, "Protection info writes to FCF disabled."); LOG_WARNING("BEWARE: incorrect flash configuration may permanently lock the device."); } else { - command_print(CMD_CTX, "Protection info writes to Flash Configuration Field enabled."); - command_print(CMD_CTX, "Arbitrary FCF writes disabled. Mode safe from unwanted locking of the device."); + command_print(CMD, "Protection info writes to Flash Configuration Field enabled."); + command_print(CMD, "Arbitrary FCF writes disabled. Mode safe from unwanted locking of the device."); } return ERROR_OK; @@ -3035,7 +3035,7 @@ COMMAND_HANDLER(kinetis_fopt_handler) fcf_fopt = (uint8_t)strtoul(CMD_ARGV[0], NULL, 0); fcf_fopt_configured = true; } else { - command_print(CMD_CTX, "FCF_FOPT 0x%02" PRIx8, fcf_fopt); + command_print(CMD, "FCF_FOPT 0x%02" PRIx8, fcf_fopt); } return ERROR_OK; diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c index cb3f58e87..2a69af692 100644 --- a/src/flash/nor/lpc2000.c +++ b/src/flash/nor/lpc2000.c @@ -1579,11 +1579,11 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command) int status_code = get_lpc2000_part_id(bank, &part_id); if (status_code != 0x0) { if (status_code == ERROR_FLASH_OPERATION_FAILED) { - command_print(CMD_CTX, "no sufficient working area specified, can't access LPC2000 IAP interface"); + command_print(CMD, "no sufficient working area specified, can't access LPC2000 IAP interface"); } else - command_print(CMD_CTX, "lpc2000 IAP returned status code %i", status_code); + command_print(CMD, "lpc2000 IAP returned status code %i", status_code); } else - command_print(CMD_CTX, "lpc2000 part id: 0x%8.8" PRIx32, part_id); + command_print(CMD, "lpc2000 part id: 0x%8.8" PRIx32, part_id); return retval; } diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c index c798e4455..5412c93de 100644 --- a/src/flash/nor/lpc2900.c +++ b/src/flash/nor/lpc2900.c @@ -501,7 +501,7 @@ COMMAND_HANDLER(lpc2900_handle_signature_command) if (status != ERROR_OK) return status; - command_print(CMD_CTX, "signature: 0x%8.8" PRIx32 + command_print(CMD, "signature: 0x%8.8" PRIx32 ":0x%8.8" PRIx32 ":0x%8.8" PRIx32 ":0x%8.8" PRIx32, @@ -595,11 +595,11 @@ COMMAND_HANDLER(lpc2900_handle_password_command) lpc2900_info->risky = !strcmp(CMD_ARGV[1], ISS_PASSWORD); if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Wrong password (use '%s')", ISS_PASSWORD); + command_print(CMD, "Wrong password (use '%s')", ISS_PASSWORD); return ERROR_COMMAND_ARGUMENT_INVALID; } - command_print(CMD_CTX, + command_print(CMD, "Potentially dangerous operation allowed in next command!"); return ERROR_OK; @@ -622,7 +622,7 @@ COMMAND_HANDLER(lpc2900_handle_write_custom_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed!"); + command_print(CMD, "Command execution not allowed!"); return ERROR_COMMAND_ARGUMENT_INVALID; } lpc2900_info->risky = 0; @@ -721,7 +721,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed! " + command_print(CMD, "Command execution not allowed! " "(use 'password' command first)"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -734,7 +734,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) if ((first >= bank->num_sectors) || (last >= bank->num_sectors) || (first > last)) { - command_print(CMD_CTX, "Illegal sector range"); + command_print(CMD, "Illegal sector range"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -773,7 +773,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) } } - command_print(CMD_CTX, + command_print(CMD, "Sectors security will become effective after next power cycle"); /* Update the sector security status */ @@ -803,7 +803,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed! " + command_print(CMD, "Command execution not allowed! " "(use 'password' command first)"); return ERROR_COMMAND_ARGUMENT_INVALID; } diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index f51f6e2a9..3bf4b22ff 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -772,7 +772,7 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command) int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); if (CMD_ARGC < 1) { - command_print(CMD_CTX, "max32xxx mass_erase "); + command_print(CMD, "max32xxx mass_erase "); return ERROR_OK; } @@ -784,9 +784,9 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "max32xxx mass erase complete"); + command_print(CMD, "max32xxx mass erase complete"); } else - command_print(CMD_CTX, "max32xxx mass erase failed"); + command_print(CMD, "max32xxx mass erase failed"); return ERROR_OK; } @@ -799,7 +799,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) uint32_t addr, len; if (CMD_ARGC != 3) { - command_print(CMD_CTX, "max32xxx protection_set "); + command_print(CMD, "max32xxx protection_set "); return ERROR_OK; } @@ -811,7 +811,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) /* Convert the range to the page numbers */ if (1 != sscanf(CMD_ARGV[1], "0x%"SCNx32, &addr)) { LOG_WARNING("Error parsing address"); - command_print(CMD_CTX, "max32xxx protection_set "); + command_print(CMD, "max32xxx protection_set "); return ERROR_FAIL; } /* Mask off the top portion on the address */ @@ -819,7 +819,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) if (1 != sscanf(CMD_ARGV[2], "0x%"SCNx32, &len)) { LOG_WARNING("Error parsing length"); - command_print(CMD_CTX, "max32xxx protection_set "); + command_print(CMD, "max32xxx protection_set "); return ERROR_FAIL; } @@ -840,9 +840,9 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) len = addr + (len / info->sector_size) - 1; if (max32xxx_protect(bank, 1, addr, len) == ERROR_OK) - command_print(CMD_CTX, "max32xxx protection set complete"); + command_print(CMD, "max32xxx protection set complete"); else - command_print(CMD_CTX, "max32xxx protection set failed"); + command_print(CMD, "max32xxx protection set failed"); return ERROR_OK; } @@ -855,7 +855,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) uint32_t addr, len; if (CMD_ARGC != 3) { - command_print(CMD_CTX, "max32xxx protection_clr "); + command_print(CMD, "max32xxx protection_clr "); return ERROR_OK; } @@ -867,7 +867,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) /* Convert the range to the page numbers */ if (1 != sscanf(CMD_ARGV[1], "0x%"SCNx32, &addr)) { LOG_WARNING("Error parsing address"); - command_print(CMD_CTX, "max32xxx protection_clr "); + command_print(CMD, "max32xxx protection_clr "); return ERROR_FAIL; } /* Mask off the top portion on the address */ @@ -875,7 +875,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) if (1 != sscanf(CMD_ARGV[2], "0x%"SCNx32, &len)) { LOG_WARNING("Error parsing length"); - command_print(CMD_CTX, "max32xxx protection_clr "); + command_print(CMD, "max32xxx protection_clr "); return ERROR_FAIL; } @@ -896,9 +896,9 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) len = addr + (len / info->sector_size) - 1; if (max32xxx_protect(bank, 0, addr, len) == ERROR_OK) - command_print(CMD_CTX, "max32xxx protection clear complete"); + command_print(CMD, "max32xxx protection clear complete"); else - command_print(CMD_CTX, "max32xxx protection clear failed"); + command_print(CMD, "max32xxx protection clear failed"); return ERROR_OK; } @@ -911,7 +911,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "max32xxx protection_check "); + command_print(CMD, "max32xxx protection_check "); return ERROR_OK; } diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c index b034ee127..62549f206 100644 --- a/src/flash/nor/niietcm4.c +++ b/src/flash/nor/niietcm4.c @@ -425,7 +425,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command) retval = target_read_u32(target, UFMD, &uflash_data); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "Read userflash %s region:\n" + command_print(CMD, "Read userflash %s region:\n" "address = 0x%04x,\n" "value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); return retval; @@ -467,7 +467,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command) int page_num = uflash_addr/USERFLASH_PAGE_SIZE; - command_print(CMD_CTX, "Write userflash %s region:\n" + command_print(CMD, "Write userflash %s region:\n" "address = 0x%04x,\n" "value = 0x%02x.\n" "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); @@ -483,7 +483,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, page_num, mem_type); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -520,7 +520,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_full_erase_command) retval = niietcm4_uopstatus_check(bank); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "Userflash full erase done!"); + command_print(CMD, "Userflash full erase done!"); return retval; } @@ -563,7 +563,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command) return retval; } - command_print(CMD_CTX, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last); + command_print(CMD, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last); return retval; } @@ -621,9 +621,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command) return retval; if (uflash_data & INFOWORD3_LOCK_IFB_UF) - command_print(CMD_CTX, "All sectors of info userflash are not protected!"); + command_print(CMD, "All sectors of info userflash are not protected!"); else - command_print(CMD_CTX, "All sectors of info userflash are protected!"); + command_print(CMD, "All sectors of info userflash are protected!"); } else { uflash_addr = UF_LOCK_ADDR; uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB; @@ -645,10 +645,10 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command) for (j = 0; j < 8; j++) { if (uflash_data & 0x1) - command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is not protected!", + command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is not protected!", i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE); else - command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is protected!", + command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is protected!", i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE); uflash_data = uflash_data >> 1; } @@ -693,11 +693,11 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command) int set; if (strcmp("on", CMD_ARGV[3]) == 0) { - command_print(CMD_CTX, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ", + command_print(CMD, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ", CMD_ARGV[0], first, last); set = 1; } else if (strcmp("off", CMD_ARGV[3]) == 0) { - command_print(CMD_CTX, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ", + command_print(CMD, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ", CMD_ARGV[0], first, last); set = 0; } else @@ -707,7 +707,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -733,10 +733,10 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command) int set; if (strcmp("on", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to enable bootflash info region remap. Please wait ..."); + command_print(CMD, "Try to enable bootflash info region remap. Please wait ..."); set = 1; } else if (strcmp("off", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to disable bootflash info region remap. Please wait ..."); + command_print(CMD, "Try to disable bootflash info region remap. Please wait ..."); set = 0; } else return ERROR_COMMAND_SYNTAX_ERROR; @@ -756,7 +756,7 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -814,7 +814,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command) else return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "Try to configure external memory boot interface:\n" + command_print(CMD, "Try to configure external memory boot interface:\n" "port = %s\n" "pin = %s\n" "func = %s\n" @@ -833,7 +833,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -861,10 +861,10 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command) int set; if (strcmp("on", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to enable boot from external memory. Please wait ..."); + command_print(CMD, "Try to enable boot from external memory. Please wait ..."); set = 1; } else if (strcmp("off", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to disable boot from external memory. Please wait ..."); + command_print(CMD, "Try to disable boot from external memory. Please wait ..."); set = 0; } else return ERROR_COMMAND_SYNTAX_ERROR; @@ -884,7 +884,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -900,7 +900,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command) return retval; struct target *target = bank->target; - command_print(CMD_CTX, "Try to perform service mode erase. Please wait ..."); + command_print(CMD, "Try to perform service mode erase. Please wait ..."); retval = target_write_u32(target, SERVICE_MODE_ERASE_ADDR, 1); if (retval != ERROR_OK) @@ -923,7 +923,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command) } busy_sleep(1); /* can use busy sleep for short times. */ } - command_print(CMD_CTX, "done! All data erased."); + command_print(CMD, "done! All data erased."); return retval; } @@ -938,7 +938,7 @@ COMMAND_HANDLER(niietcm4_handle_driver_info_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "niietcm4 flash driver\n" + command_print(CMD, "niietcm4 flash driver\n" "version: %d.%d\n" "author: Bogdan Kolbov\n" "mail: kolbov@niiet.ru", diff --git a/src/flash/nor/numicro.c b/src/flash/nor/numicro.c index 47f9a8826..c62af04bf 100644 --- a/src/flash/nor/numicro.c +++ b/src/flash/nor/numicro.c @@ -1827,11 +1827,11 @@ COMMAND_HANDLER(numicro_handle_chip_erase_command) retval = numicro_fmc_cmd(target, ISPCMD_CHIPERASE, 0, 0, &rdat); if (retval != ERROR_OK) { - command_print(CMD_CTX, "numicro chip_erase failed"); + command_print(CMD, "numicro chip_erase failed"); return retval; } - command_print(CMD_CTX, "numicro chip_erase complete"); + command_print(CMD, "numicro chip_erase complete"); return ERROR_OK; } diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index 5ad4cb7e5..81ffdc400 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -858,7 +858,7 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) return retval; if (address < bank->base || address >= (bank->base + bank->size)) { - command_print(CMD_CTX, "flash address '%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "flash address '%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -870,9 +870,9 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) res = ERROR_FLASH_OPERATION_FAILED; if (res == ERROR_OK) - command_print(CMD_CTX, "pic32mx pgm word complete"); + command_print(CMD, "pic32mx pgm word complete"); else - command_print(CMD_CTX, "pic32mx pgm word failed (status = 0x%x)", status); + command_print(CMD, "pic32mx pgm word failed (status = 0x%x)", status); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) int timeout = 10; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "pic32mx unlock "); + command_print(CMD, "pic32mx unlock "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -907,7 +907,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) mips_ejtag_drscan_8(ejtag_info, &mchip_cmd); if (mchip_cmd & (1 << 7)) { /* device is not locked */ - command_print(CMD_CTX, "pic32mx is already unlocked, erasing anyway"); + command_print(CMD, "pic32mx is already unlocked, erasing anyway"); } /* unlock/erase device */ @@ -931,7 +931,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) /* select ejtag tap */ mips_ejtag_set_instr(ejtag_info, MTAP_SW_ETAP); - command_print(CMD_CTX, "pic32mx unlocked.\n" + command_print(CMD, "pic32mx unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c index 0058f2dad..1eb6a26ed 100644 --- a/src/flash/nor/psoc4.c +++ b/src/flash/nor/psoc4.c @@ -913,9 +913,9 @@ COMMAND_HANDLER(psoc4_handle_mass_erase_command) retval = psoc4_mass_erase(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "psoc mass erase complete"); + command_print(CMD, "psoc mass erase complete"); else - command_print(CMD_CTX, "psoc mass erase failed"); + command_print(CMD, "psoc mass erase failed"); return retval; } diff --git a/src/flash/nor/psoc5lp.c b/src/flash/nor/psoc5lp.c index 66e2b071e..7f801f294 100644 --- a/src/flash/nor/psoc5lp.c +++ b/src/flash/nor/psoc5lp.c @@ -1501,9 +1501,9 @@ COMMAND_HANDLER(psoc5lp_handle_mass_erase_command) retval = psoc5lp_spc_erase_all(bank->target); if (retval == ERROR_OK) - command_print(CMD_CTX, "PSoC 5LP erase succeeded"); + command_print(CMD, "PSoC 5LP erase succeeded"); else - command_print(CMD_CTX, "PSoC 5LP erase failed"); + command_print(CMD, "PSoC 5LP erase failed"); return retval; } diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 6b6f6e802..9c4c4bc89 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -1336,9 +1336,9 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stellaris mass erase complete"); + command_print(CMD, "stellaris mass erase complete"); } else - command_print(CMD_CTX, "stellaris mass erase failed"); + command_print(CMD, "stellaris mass erase failed"); return ERROR_OK; } diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c index d5d59c611..cf10e3747 100644 --- a/src/flash/nor/stm32f1x.c +++ b/src/flash/nor/stm32f1x.c @@ -1186,7 +1186,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) return retval; if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } @@ -1194,11 +1194,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.rdp = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to lock device"); + command_print(CMD, "stm32x failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x locked"); + command_print(CMD, "stm32x locked"); return ERROR_OK; } @@ -1227,16 +1227,16 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) return retval; if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to unlock device"); + command_print(CMD, "stm32x failed to unlock device"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x unlocked.\n" + command_print(CMD, "stm32x unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1281,30 +1281,30 @@ COMMAND_HANDLER(stm32x_handle_options_read_command) return retval; if (optionbyte & (1 << OPT_ERROR)) - command_print(CMD_CTX, "option byte complement error"); + command_print(CMD, "option byte complement error"); - command_print(CMD_CTX, "option byte register = 0x%" PRIx32 "", optionbyte); - command_print(CMD_CTX, "write protection register = 0x%" PRIx32 "", protection); + command_print(CMD, "option byte register = 0x%" PRIx32 "", optionbyte); + command_print(CMD, "write protection register = 0x%" PRIx32 "", protection); - command_print(CMD_CTX, "read protection: %s", + command_print(CMD, "read protection: %s", (optionbyte & (1 << OPT_READOUT)) ? "on" : "off"); /* user option bytes are offset depending on variant */ optionbyte >>= stm32x_info->option_offset; - command_print(CMD_CTX, "watchdog: %sware", + command_print(CMD, "watchdog: %sware", (optionbyte & (1 << OPT_RDWDGSW)) ? "soft" : "hard"); - command_print(CMD_CTX, "stop mode: %sreset generated upon entry", + command_print(CMD, "stop mode: %sreset generated upon entry", (optionbyte & (1 << OPT_RDRSTSTOP)) ? "no " : ""); - command_print(CMD_CTX, "standby mode: %sreset generated upon entry", + command_print(CMD, "standby mode: %sreset generated upon entry", (optionbyte & (1 << OPT_RDRSTSTDBY)) ? "no " : ""); if (stm32x_info->has_dual_banks) - command_print(CMD_CTX, "boot: bank %d", (optionbyte & (1 << OPT_BFB2)) ? 0 : 1); + command_print(CMD, "boot: bank %d", (optionbyte & (1 << OPT_BFB2)) ? 0 : 1); - command_print(CMD_CTX, "user data = 0x%02" PRIx16 "", user_data); + command_print(CMD, "user data = 0x%02" PRIx16 "", user_data); return ERROR_OK; } @@ -1383,7 +1383,7 @@ COMMAND_HANDLER(stm32x_handle_options_write_command) } if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } @@ -1391,11 +1391,11 @@ COMMAND_HANDLER(stm32x_handle_options_write_command) stm32x_info->option_bytes.data = useropt; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to write options"); + command_print(CMD, "stm32x failed to write options"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x write options complete.\n" + command_print(CMD, "stm32x write options complete.\n" "INFO: %spower cycle is required " "for the new settings to take effect.", stm32x_info->can_load_options @@ -1504,9 +1504,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32x mass erase complete"); + command_print(CMD, "stm32x mass erase complete"); } else - command_print(CMD_CTX, "stm32x mass erase failed"); + command_print(CMD, "stm32x mass erase failed"); return retval; } diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c index 23f003085..b49e76e32 100644 --- a/src/flash/nor/stm32f2x.c +++ b/src/flash/nor/stm32f2x.c @@ -1415,7 +1415,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1423,11 +1423,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.RDP = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", bank->driver->name); + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s locked", bank->driver->name); + command_print(CMD, "%s locked", bank->driver->name); return ERROR_OK; } @@ -1454,7 +1454,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1466,11 +1466,11 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s unlocked.\n" + command_print(CMD, "%s unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect.", bank->driver->name); @@ -1525,7 +1525,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32x mass_erase "); + command_print(CMD, "stm32x mass_erase "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1540,9 +1540,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32x mass erase complete"); + command_print(CMD, "stm32x mass erase complete"); } else { - command_print(CMD_CTX, "stm32x mass erase failed"); + command_print(CMD, "stm32x mass erase failed"); } return retval; @@ -1555,7 +1555,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_read_command) struct stm32x_flash_bank *stm32x_info = NULL; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "stm32f2x options_read "); + command_print(CMD, "stm32f2x options_read "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1572,20 +1572,20 @@ COMMAND_HANDLER(stm32f2x_handle_options_read_command) if (stm32x_info->has_boot_addr) { uint32_t boot_addr = stm32x_info->option_bytes.boot_addr; - command_print(CMD_CTX, "stm32f2x user_options 0x%03X," + command_print(CMD, "stm32f2x user_options 0x%03X," " boot_add0 0x%04X, boot_add1 0x%04X", stm32x_info->option_bytes.user_options, boot_addr & 0xffff, (boot_addr & 0xffff0000) >> 16); if (stm32x_info->has_optcr2_pcrop) { - command_print(CMD_CTX, "stm32f2x optcr2_pcrop 0x%08X", + command_print(CMD, "stm32f2x optcr2_pcrop 0x%08X", stm32x_info->option_bytes.optcr2_pcrop); } } else { - command_print(CMD_CTX, "stm32f2x user_options 0x%03X", + command_print(CMD, "stm32f2x user_options 0x%03X", stm32x_info->option_bytes.user_options); } } else { - command_print(CMD_CTX, "stm32f2x user_options 0x%02X", + command_print(CMD, "stm32f2x user_options 0x%02X", stm32x_info->option_bytes.user_options); } @@ -1601,7 +1601,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) uint16_t user_options, boot_addr0, boot_addr1, options_mask; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32f2x options_write ..."); + command_print(CMD, "stm32f2x options_write ..."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1616,7 +1616,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) stm32x_info = bank->driver_priv; if (stm32x_info->has_boot_addr) { if (CMD_ARGC != 4) { - command_print(CMD_CTX, "stm32f2x options_write " + command_print(CMD, "stm32f2x options_write " " "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1625,7 +1625,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) stm32x_info->option_bytes.boot_addr = boot_addr0 | (((uint32_t) boot_addr1) << 16); } else { if (CMD_ARGC != 2) { - command_print(CMD_CTX, "stm32f2x options_write "); + command_print(CMD, "stm32f2x options_write "); return ERROR_COMMAND_SYNTAX_ERROR; } } @@ -1634,14 +1634,14 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) options_mask = !stm32x_info->has_extra_options ? ~0xfc : ~(((0xf00 << (stm32x_info->protection_bits - 12)) | 0xff) & 0xffc); if (user_options & options_mask) { - command_print(CMD_CTX, "stm32f2x invalid user_options"); + command_print(CMD, "stm32f2x invalid user_options"); return ERROR_COMMAND_ARGUMENT_INVALID; } stm32x_info->option_bytes.user_options = user_options; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32f2x failed to write options"); + command_print(CMD, "stm32f2x failed to write options"); return ERROR_OK; } @@ -1649,7 +1649,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) /* ... and reprogramming of whole flash */ stm32x_info->probed = false; - command_print(CMD_CTX, "stm32f2x write options complete.\n" + command_print(CMD, "stm32f2x write options complete.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); return retval; @@ -1663,7 +1663,7 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) uint32_t optcr2_pcrop; if (CMD_ARGC != 2) { - command_print(CMD_CTX, "stm32f2x optcr2_write "); + command_print(CMD, "stm32f2x optcr2_write "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1673,11 +1673,11 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) stm32x_info = bank->driver_priv; if (!stm32x_info->has_optcr2_pcrop) { - command_print(CMD_CTX, "no optcr2 register"); + command_print(CMD, "no optcr2 register"); return ERROR_COMMAND_ARGUMENT_INVALID; } - command_print(CMD_CTX, "INFO: To disable PCROP, set PCROP_RDP" + command_print(CMD, "INFO: To disable PCROP, set PCROP_RDP" " with PCROPi bits STILL SET, then\nlock device and" " finally unlock it. Clears PCROP and mass erases flash."); @@ -1689,18 +1689,18 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) stm32x_info->option_bytes.optcr2_pcrop = optcr2_pcrop; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32f2x failed to write options"); + command_print(CMD, "stm32f2x failed to write options"); return ERROR_OK; } - command_print(CMD_CTX, "stm32f2x optcr2_write complete."); + command_print(CMD, "stm32f2x optcr2_write complete."); return retval; } COMMAND_HANDLER(stm32x_handle_otp_command) { if (CMD_ARGC < 2) { - command_print(CMD_CTX, "stm32x otp (enable|disable|show)"); + command_print(CMD, "stm32x otp (enable|disable|show)"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1714,7 +1714,7 @@ COMMAND_HANDLER(stm32x_handle_otp_command) } else if (strcmp(CMD_ARGV[1], "disable") == 0) { stm32x_otp_disable(bank); } else if (strcmp(CMD_ARGV[1], "show") == 0) { - command_print(CMD_CTX, + command_print(CMD, "OTP memory bank #%d is %s for write commands.", bank->bank_number, stm32x_is_otp_unlocked(bank) ? "enabled" : "disabled"); @@ -1722,7 +1722,7 @@ COMMAND_HANDLER(stm32x_handle_otp_command) return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Failed: not an OTP bank."); + command_print(CMD, "Failed: not an OTP bank."); } return retval; diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 90bc8f393..cb96cf265 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -952,7 +952,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -960,11 +960,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.RDP = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s locked", bank->driver->name); + command_print(CMD, "%s locked", bank->driver->name); return ERROR_OK; } @@ -998,7 +998,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1007,10 +1007,10 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) stm32x_info->option_bytes.RDP = 0xAA; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s unlocked.\n", bank->driver->name); + command_print(CMD, "%s unlocked.\n", bank->driver->name); return ERROR_OK; } @@ -1056,7 +1056,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32h7x mass_erase "); + command_print(CMD, "stm32h7x mass_erase "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1071,9 +1071,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32h7x mass erase complete"); + command_print(CMD, "stm32h7x mass erase complete"); } else { - command_print(CMD_CTX, "stm32h7x mass erase failed"); + command_print(CMD, "stm32h7x mass erase failed"); } return retval; diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 3d4303bee..f680542c7 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -835,7 +835,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) uint32_t action; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32l4x mass_erase "); + command_print(CMD, "stm32l4x mass_erase "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -851,9 +851,9 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32l4x mass erase complete"); + command_print(CMD, "stm32l4x mass erase complete"); } else { - command_print(CMD_CTX, "stm32l4x mass erase failed"); + command_print(CMD, "stm32l4x mass erase failed"); } return retval; @@ -862,7 +862,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) COMMAND_HANDLER(stm32l4_handle_option_read_command) { if (CMD_ARGC < 2) { - command_print(CMD_CTX, "stm32l4x option_read "); + command_print(CMD, "stm32l4x option_read "); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -880,7 +880,7 @@ COMMAND_HANDLER(stm32l4_handle_option_read_command) if (ERROR_OK != retval) return retval; - command_print(CMD_CTX, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32 "", reg_addr, value); + command_print(CMD, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32 "", reg_addr, value); return retval; } @@ -888,7 +888,7 @@ COMMAND_HANDLER(stm32l4_handle_option_read_command) COMMAND_HANDLER(stm32l4_handle_option_write_command) { if (CMD_ARGC < 3) { - command_print(CMD_CTX, "stm32l4x option_write [mask]"); + command_print(CMD, "stm32l4x option_write [mask]"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -906,7 +906,7 @@ COMMAND_HANDLER(stm32l4_handle_option_write_command) if (CMD_ARGC > 3) mask = strtoul(CMD_ARGV[3], NULL, 16); - command_print(CMD_CTX, "%s Option written.\n" + command_print(CMD, "%s Option written.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect.", bank->driver->name); @@ -937,7 +937,7 @@ COMMAND_HANDLER(stm32l4_handle_option_load_command) /* Write the OBLLAUNCH bit in CR -> Cause device "POR" and option bytes reload */ retval = target_write_u32(target, stm32l4_get_flash_reg(bank, STM32_FLASH_CR), FLASH_OBLLAUNCH); - command_print(CMD_CTX, "stm32l4x option load (POR) completed."); + command_print(CMD, "stm32l4x option load (POR) completed."); return retval; } @@ -962,7 +962,7 @@ COMMAND_HANDLER(stm32l4_handle_lock_command) /* set readout protection level 1 by erasing the RDP option byte */ if (stm32l4_write_option(bank, STM32_FLASH_OPTR, 0, 0x000000FF) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", bank->driver->name); + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } @@ -989,7 +989,7 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) } if (stm32l4_write_option(bank, STM32_FLASH_OPTR, RDP_LEVEL_0, 0x000000FF) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index 27780103e..e6473f8c2 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -324,9 +324,9 @@ COMMAND_HANDLER(stm32lx_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32lx mass erase complete"); + command_print(CMD, "stm32lx mass erase complete"); } else { - command_print(CMD_CTX, "stm32lx mass erase failed"); + command_print(CMD, "stm32lx mass erase failed"); } return retval; @@ -345,9 +345,9 @@ COMMAND_HANDLER(stm32lx_handle_lock_command) retval = stm32lx_lock(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "STM32Lx locked, takes effect after power cycle."); + command_print(CMD, "STM32Lx locked, takes effect after power cycle."); else - command_print(CMD_CTX, "STM32Lx lock failed"); + command_print(CMD, "STM32Lx lock failed"); return retval; } @@ -365,9 +365,9 @@ COMMAND_HANDLER(stm32lx_handle_unlock_command) retval = stm32lx_unlock(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "STM32Lx unlocked, takes effect after power cycle."); + command_print(CMD, "STM32Lx unlocked, takes effect after power cycle."); else - command_print(CMD_CTX, "STM32Lx unlock failed"); + command_print(CMD, "STM32Lx unlock failed"); return retval; } diff --git a/src/flash/nor/str9xpec.c b/src/flash/nor/str9xpec.c index 37d805344..6e1ecf347 100644 --- a/src/flash/nor/str9xpec.c +++ b/src/flash/nor/str9xpec.c @@ -746,7 +746,7 @@ COMMAND_HANDLER(str9xpec_handle_part_id_command) idcode = buf_get_u32(buffer, 0, 32); - command_print(CMD_CTX, "str9xpec part id: 0x%8.8" PRIx32 "", idcode); + command_print(CMD, "str9xpec part id: 0x%8.8" PRIx32 "", idcode); free(buffer); @@ -780,33 +780,33 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_read_command) /* boot bank */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1)) - command_print(CMD_CTX, "CS Map: bank1"); + command_print(CMD, "CS Map: bank1"); else - command_print(CMD_CTX, "CS Map: bank0"); + command_print(CMD, "CS Map: bank0"); /* OTP lock */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_OTPBIT, 1)) - command_print(CMD_CTX, "OTP Lock: OTP Locked"); + command_print(CMD, "OTP Lock: OTP Locked"); else - command_print(CMD_CTX, "OTP Lock: OTP Unlocked"); + command_print(CMD, "OTP Lock: OTP Unlocked"); /* LVD Threshold */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1)) - command_print(CMD_CTX, "LVD Threshold: 2.7v"); + command_print(CMD, "LVD Threshold: 2.7v"); else - command_print(CMD_CTX, "LVD Threshold: 2.4v"); + command_print(CMD, "LVD Threshold: 2.4v"); /* LVD reset warning */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1)) - command_print(CMD_CTX, "LVD Reset Warning: VDD or VDDQ Inputs"); + command_print(CMD, "LVD Reset Warning: VDD or VDDQ Inputs"); else - command_print(CMD_CTX, "LVD Reset Warning: VDD Input Only"); + command_print(CMD, "LVD Reset Warning: VDD Input Only"); /* LVD reset select */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1)) - command_print(CMD_CTX, "LVD Reset Selection: VDD or VDDQ Inputs"); + command_print(CMD, "LVD Reset Selection: VDD or VDDQ Inputs"); else - command_print(CMD_CTX, "LVD Reset Selection: VDD Input Only"); + command_print(CMD, "LVD Reset Selection: VDD Input Only"); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_write_command) if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS) return ERROR_FLASH_OPERATION_FAILED; - command_print(CMD_CTX, "str9xpec write options complete.\n" + command_print(CMD, "str9xpec write options complete.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1017,7 +1017,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_unlock_command) if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS) return ERROR_FLASH_OPERATION_FAILED; - command_print(CMD_CTX, "str9xpec unlocked.\n" + command_print(CMD, "str9xpec unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1045,19 +1045,19 @@ COMMAND_HANDLER(str9xpec_handle_flash_enable_turbo_command) tap0 = str9xpec_info->tap; if (tap0 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap0) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap0) invalid chain?"); return ERROR_FAIL; } tap1 = tap0->next_tap; if (tap1 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap1) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap1) invalid chain?"); return ERROR_FAIL; } tap2 = tap1->next_tap; if (tap2 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap2) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap2) invalid chain?"); return ERROR_FAIL; } diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 87d599a59..0daa531b8 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -111,7 +111,7 @@ COMMAND_HANDLER(handle_flash_info_command) if (retval == ERROR_FLASH_OPER_UNSUPPORTED) LOG_WARNING("Flash protection check is not implemented."); - command_print(CMD_CTX, + command_print(CMD, "#%d : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", buswidth %i, chipwidth %i", p->bank_number, @@ -140,7 +140,7 @@ COMMAND_HANDLER(handle_flash_info_command) else if (!show_sectors || !prot_block_available) protect_state = "protection state unknown"; - command_print(CMD_CTX, + command_print(CMD, "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", j, block_array[j].offset, @@ -152,7 +152,7 @@ COMMAND_HANDLER(handle_flash_info_command) if (p->driver->info != NULL) { retval = p->driver->info(p, buf, sizeof(buf)); if (retval == ERROR_OK) - command_print(CMD_CTX, "%s", buf); + command_print(CMD, "%s", buf); else LOG_ERROR("error retrieving flash info"); } @@ -176,12 +176,12 @@ COMMAND_HANDLER(handle_flash_probe_command) if (p) { retval = p->driver->probe(p); if (retval == ERROR_OK) - command_print(CMD_CTX, + command_print(CMD, "flash '%s' found at " TARGET_ADDR_FMT, p->driver->name, p->base); } else { - command_print(CMD_CTX, "flash bank '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "flash bank '#%s' is out of bounds", CMD_ARGV[0]); retval = ERROR_FAIL; } @@ -202,9 +202,9 @@ COMMAND_HANDLER(handle_flash_erase_check_command) int j; retval = p->driver->erase_check(p); if (retval == ERROR_OK) - command_print(CMD_CTX, "successfully checked erase state"); + command_print(CMD, "successfully checked erase state"); else { - command_print(CMD_CTX, + command_print(CMD, "unknown error when checking erase state of flash bank #%s at " TARGET_ADDR_FMT, CMD_ARGV[0], @@ -222,7 +222,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command) erase_state = "erase state unknown"; blank = false; - command_print(CMD_CTX, + command_print(CMD, "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", j, p->sectors[j].offset, @@ -232,7 +232,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command) } if (blank) - command_print(CMD_CTX, "\tBank is erased"); + command_print(CMD, "\tBank is erased"); return retval; } @@ -267,7 +267,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); if (length <= 0) { - command_print(CMD_CTX, "Length must be >0"); + command_print(CMD, "Length must be >0"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -289,7 +289,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command) retval = flash_erase_address_range(target, do_pad, address, length); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "erased address " TARGET_ADDR_FMT " (length %" + command_print(CMD, "erased address " TARGET_ADDR_FMT " (length %" PRIi32 ")" " in %fs (%0.3f KiB/s)", address, length, duration_elapsed(&bench), duration_kbps(&bench, length)); @@ -320,13 +320,13 @@ COMMAND_HANDLER(handle_flash_erase_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], last); if (!(first <= last)) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "first sector must be <= last"); return ERROR_FAIL; } if (!(last <= (uint32_t)(p->num_sectors - 1))) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "last sector must be <= %" PRIu32, p->num_sectors - 1); return ERROR_FAIL; @@ -338,7 +338,7 @@ COMMAND_HANDLER(handle_flash_erase_command) retval = flash_driver_erase(p, first, last); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "erased sectors %" PRIu32 " " + command_print(CMD, "erased sectors %" PRIu32 " " "through %" PRIu32 " on flash bank %d " "in %fs", first, last, p->bank_number, duration_elapsed(&bench)); } @@ -377,14 +377,14 @@ COMMAND_HANDLER(handle_flash_protect_command) COMMAND_PARSE_ON_OFF(CMD_ARGV[3], set); if (!(first <= last)) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "first %s must be <= last", (p->num_prot_blocks) ? "block" : "sector"); return ERROR_FAIL; } if (!(last <= (uint32_t)(num_blocks - 1))) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "last %s must be <= %" PRIu32, (p->num_prot_blocks) ? "block" : "sector", num_blocks - 1); @@ -393,7 +393,7 @@ COMMAND_HANDLER(handle_flash_protect_command) retval = flash_driver_protect(p, set, first, last); if (retval == ERROR_OK) { - command_print(CMD_CTX, "%s protection for %s %" PRIu32 + command_print(CMD, "%s protection for %s %" PRIu32 " through %" PRIu32 " on flash bank %d", (set) ? "set" : "cleared", (p->num_prot_blocks) ? "blocks" : "sectors", @@ -421,12 +421,12 @@ COMMAND_HANDLER(handle_flash_write_image_command) auto_erase = 1; CMD_ARGV++; CMD_ARGC--; - command_print(CMD_CTX, "auto erase enabled"); + command_print(CMD, "auto erase enabled"); } else if (strcmp(CMD_ARGV[0], "unlock") == 0) { auto_unlock = true; CMD_ARGV++; CMD_ARGC--; - command_print(CMD_CTX, "auto unlock enabled"); + command_print(CMD, "auto unlock enabled"); } else break; } @@ -463,7 +463,7 @@ COMMAND_HANDLER(handle_flash_write_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %" PRIu32 " bytes from file %s " + command_print(CMD, "wrote %" PRIu32 " bytes from file %s " "in %fs (%0.3f KiB/s)", written, CMD_ARGV[0], duration_elapsed(&bench), duration_kbps(&bench, written)); } @@ -602,7 +602,7 @@ COMMAND_HANDLER(handle_flash_fill_command) } if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %" PRIu32 " bytes to " TARGET_ADDR_FMT + command_print(CMD, "wrote %" PRIu32 " bytes to " TARGET_ADDR_FMT " in %fs (%0.3f KiB/s)", size_bytes, address, duration_elapsed(&bench), duration_kbps(&bench, size_bytes)); } @@ -716,7 +716,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command) free(buffer); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %zu bytes from file %s to flash bank %u" + command_print(CMD, "wrote %zu bytes from file %s to flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", length, CMD_ARGV[1], bank->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, length)); @@ -798,7 +798,7 @@ COMMAND_HANDLER(handle_flash_read_bank_command) } if (duration_measure(&bench) == ERROR_OK) - command_print(CMD_CTX, "wrote %zd bytes to file %s from flash bank %u" + command_print(CMD, "wrote %zd bytes to file %s from flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", written, CMD_ARGV[1], p->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, written)); @@ -900,23 +900,23 @@ COMMAND_HANDLER(handle_flash_verify_bank_command) } if (duration_measure(&bench) == ERROR_OK) - command_print(CMD_CTX, "read %zd bytes from file %s and flash bank %u" + command_print(CMD, "read %zd bytes from file %s and flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", length, CMD_ARGV[1], p->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, length)); differ = memcmp(buffer_file, buffer_flash, length); - command_print(CMD_CTX, "contents %s", differ ? "differ" : "match"); + command_print(CMD, "contents %s", differ ? "differ" : "match"); if (differ) { uint32_t t; int diffs = 0; for (t = 0; t < length; t++) { if (buffer_flash[t] == buffer_file[t]) continue; - command_print(CMD_CTX, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", + command_print(CMD, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", diffs, t + offset, buffer_flash[t], buffer_file[t]); if (diffs++ >= 127) { - command_print(CMD_CTX, "More than 128 errors, the rest are not printed."); + command_print(CMD, "More than 128 errors, the rest are not printed."); break; } keep_alive(); @@ -952,7 +952,7 @@ COMMAND_HANDLER(handle_flash_padded_value_command) COMMAND_PARSE_NUMBER(u8, CMD_ARGV[1], p->default_padded_value); - command_print(CMD_CTX, "Default padded value set to 0x%" PRIx8 " for flash bank %u", \ + command_print(CMD, "Default padded value set to 0x%" PRIx8 " for flash bank %u", \ p->default_padded_value, p->bank_number); return retval; diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 195d1ae1f..90557b8f1 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -301,7 +301,7 @@ COMMAND_HANDLER(tms470_handle_flash_keyset_command) int start = (0 == strncmp(CMD_ARGV[i], "0x", 2)) ? 2 : 0; if (1 != sscanf(&CMD_ARGV[i][start], "%" SCNx32 "", &flashKeys[i])) { - command_print(CMD_CTX, "could not process flash key %s", + command_print(CMD, "could not process flash key %s", CMD_ARGV[i]); LOG_ERROR("could not process flash key %s", CMD_ARGV[i]); return ERROR_COMMAND_SYNTAX_ERROR; @@ -310,19 +310,19 @@ COMMAND_HANDLER(tms470_handle_flash_keyset_command) keysSet = 1; } else if (CMD_ARGC != 0) { - command_print(CMD_CTX, "tms470 flash_keyset "); + command_print(CMD, "tms470 flash_keyset "); return ERROR_COMMAND_SYNTAX_ERROR; } if (keysSet) { - command_print(CMD_CTX, + command_print(CMD, "using flash keys 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 "", flashKeys[0], flashKeys[1], flashKeys[2], flashKeys[3]); } else - command_print(CMD_CTX, "flash keys not set"); + command_print(CMD, "flash keys not set"); return ERROR_OK; } @@ -352,12 +352,12 @@ COMMAND_HANDLER(tms470_handle_osc_megahertz_command) if (oscMHz <= 0) { LOG_ERROR("osc_megahertz must be positive and non-zero!"); - command_print(CMD_CTX, "osc_megahertz must be positive and non-zero!"); + command_print(CMD, "osc_megahertz must be positive and non-zero!"); oscMHz = 12; return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "osc_megahertz=%d", oscMHz); + command_print(CMD, "osc_megahertz=%d", oscMHz); return ERROR_OK; } @@ -375,7 +375,7 @@ COMMAND_HANDLER(tms470_handle_plldis_command) plldis = plldis ? 1 : 0; } - command_print(CMD_CTX, "plldis=%d", plldis); + command_print(CMD, "plldis=%d", plldis); return ERROR_OK; } diff --git a/src/flash/nor/xmc4xxx.c b/src/flash/nor/xmc4xxx.c index d85be6214..d6a1ad453 100644 --- a/src/flash/nor/xmc4xxx.c +++ b/src/flash/nor/xmc4xxx.c @@ -1284,9 +1284,9 @@ COMMAND_HANDLER(xmc4xxx_handle_flash_password_command) fb->pw_set = true; - command_print(CMD_CTX, "XMC4xxx flash passwords set to:\n"); - command_print(CMD_CTX, "-0x%08"PRIx32"\n", fb->pw1); - command_print(CMD_CTX, "-0x%08"PRIx32"\n", fb->pw2); + command_print(CMD, "XMC4xxx flash passwords set to:\n"); + command_print(CMD, "-0x%08"PRIx32"\n", fb->pw1); + command_print(CMD, "-0x%08"PRIx32"\n", fb->pw2); return ERROR_OK; } diff --git a/src/hello.c b/src/hello.c index 2afbba3a3..a1c00c0dd 100644 --- a/src/hello.c +++ b/src/hello.c @@ -89,7 +89,7 @@ COMMAND_HANDLER(handle_hello_command) const char *sep, *name; int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name); if (ERROR_OK == retval) - command_print(CMD_CTX, "Greetings%s%s!", sep, name); + command_print(CMD, "Greetings%s%s!", sep, name); return retval; } diff --git a/src/helper/command.c b/src/helper/command.c index aadc072fa..be131bb3b 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -502,7 +502,7 @@ void command_output_text(struct command_context *context, const char *data) context->output_handler(context, data); } -void command_print_sameline(struct command_context *context, const char *format, ...) +void command_print_sameline(struct command_invocation *cmd, const char *format, ...) { char *string; @@ -525,7 +525,7 @@ void command_print_sameline(struct command_context *context, const char *format, va_end(ap); } -void command_print(struct command_context *context, const char *format, ...) +void command_print(struct command_invocation *cmd, const char *format, ...) { char *string; diff --git a/src/helper/command.h b/src/helper/command.h index 9aed2827c..41cdc0b9d 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -353,9 +353,9 @@ struct command_context *copy_command_context(struct command_context *cmd_ctx); */ void command_done(struct command_context *context); -void command_print(struct command_context *context, const char *format, ...) +void command_print(struct command_invocation *cmd, const char *format, ...) __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 2, 3))); -void command_print_sameline(struct command_context *context, const char *format, ...) +void command_print_sameline(struct command_invocation *cmd, const char *format, ...) __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 2, 3))); int command_run_line(struct command_context *context, char *line); int command_run_linef(struct command_context *context, const char *format, ...) @@ -409,7 +409,7 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); do { \ int retval_macro_tmp = parse_ ## type(in, &(out)); \ if (ERROR_OK != retval_macro_tmp) { \ - command_print(CMD_CTX, stringify(out) \ + command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ return retval_macro_tmp; \ } \ @@ -429,9 +429,9 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); bool value; \ int retval_macro_tmp = command_parse_bool_arg(in, &value); \ if (ERROR_OK != retval_macro_tmp) { \ - command_print(CMD_CTX, stringify(out) \ + command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ - command_print(CMD_CTX, " choices are '%s' or '%s'", \ + command_print(CMD, " choices are '%s' or '%s'", \ on, off); \ return retval_macro_tmp; \ } \ diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index a48879905..d4f39e242 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -113,10 +113,10 @@ COMMAND_HANDLER(handle_cat_command) int retval = load_file(CMD_ARGV[0], &data, &len); if (retval == ERROR_OK) { - command_print(CMD_CTX, "%s", data); + command_print(CMD, "%s", data); free(data); } else - command_print(CMD_CTX, "%s not found", CMD_ARGV[0]); + command_print(CMD, "%s not found", CMD_ARGV[0]); return ERROR_OK; } @@ -146,10 +146,10 @@ COMMAND_HANDLER(handle_meminfo_command) info = mallinfo(); if (prev > 0) - command_print(CMD_CTX, "Diff: %d", prev - info.fordblks); + command_print(CMD, "Diff: %d", prev - info.fordblks); prev = info.fordblks; - command_print(CMD_CTX, "Available ram: %d", info.fordblks); + command_print(CMD, "Available ram: %d", info.fordblks); return ERROR_OK; } @@ -217,7 +217,7 @@ COMMAND_HANDLER(handle_cp_command) if (retval != ERROR_OK) break; - command_print(CMD_CTX, "%zu", len - pos); + command_print(CMD, "%zu", len - pos); pos += chunk; @@ -226,9 +226,9 @@ COMMAND_HANDLER(handle_cp_command) } if (retval == ERROR_OK) - command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]); + command_print(CMD, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]); else - command_print(CMD_CTX, "copy failed"); + command_print(CMD, "copy failed"); if (data != NULL) free(data); diff --git a/src/helper/log.c b/src/helper/log.c index 90653c41d..d65430c50 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -213,7 +213,7 @@ COMMAND_HANDLER(handle_debug_level_command) } else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "debug_level: %i", debug_level); + command_print(CMD, "debug_level: %i", debug_level); return ERROR_OK; } diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 24706f562..0a887ef20 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -114,10 +114,10 @@ COMMAND_HANDLER(handle_interface_list_command) if (strcmp(CMD_NAME, "interface_list") == 0 && CMD_ARGC > 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "The following debug interfaces are available:"); + command_print(CMD, "The following debug interfaces are available:"); for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) { const char *name = jtag_interfaces[i]->name; - command_print(CMD_CTX, "%u: %s", i + 1, name); + command_print(CMD, "%u: %s", i + 1, name); } return ERROR_OK; @@ -394,7 +394,7 @@ next: modes[5] = ""; } - command_print(CMD_CTX, "%s %s%s%s%s%s", + command_print(CMD, "%s %s%s%s%s%s", modes[0], modes[1], modes[2], modes[3], modes[4], modes[5]); @@ -411,7 +411,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_delay_command) jtag_set_nsrst_delay(delay); } - command_print(CMD_CTX, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay()); + command_print(CMD, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay()); return ERROR_OK; } @@ -425,7 +425,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command) jtag_set_nsrst_assert_width(width); } - command_print(CMD_CTX, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); + command_print(CMD, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); return ERROR_OK; } @@ -450,9 +450,9 @@ COMMAND_HANDLER(handle_adapter_khz_command) return retval; if (cur_speed) - command_print(CMD_CTX, "adapter speed: %d kHz", cur_speed); + command_print(CMD, "adapter speed: %d kHz", cur_speed); else - command_print(CMD_CTX, "adapter speed: RCLK - adaptive"); + command_print(CMD, "adapter speed: RCLK - adaptive"); return retval; } @@ -464,7 +464,7 @@ COMMAND_HANDLER(handle_usb_location_command) if (CMD_ARGC == 1) jtag_usb_set_location(CMD_ARGV[0]); - command_print(CMD_CTX, "adapter usb location: %s", jtag_usb_get_location()); + command_print(CMD, "adapter usb location: %s", jtag_usb_get_location()); return ERROR_OK; } diff --git a/src/jtag/aice/aice_interface.c b/src/jtag/aice/aice_interface.c index c758bb43b..2aac5e93a 100644 --- a/src/jtag/aice/aice_interface.c +++ b/src/jtag/aice/aice_interface.c @@ -269,10 +269,10 @@ COMMAND_HANDLER(aice_handle_aice_info_command) { LOG_DEBUG("aice_handle_aice_info_command"); - command_print(CMD_CTX, "Description: %s", param.device_desc); - command_print(CMD_CTX, "Serial number: %s", param.serial); + command_print(CMD, "Description: %s", param.device_desc); + command_print(CMD, "Serial number: %s", param.serial); if (strncmp(aice_port->name, "aice_pipe", 9) == 0) - command_print(CMD_CTX, "Adapter: %s", param.adapter_name); + command_print(CMD, "Adapter: %s", param.adapter_name); return ERROR_OK; } diff --git a/src/jtag/aice/aice_transport.c b/src/jtag/aice/aice_transport.c index 06583183d..15ebcac97 100644 --- a/src/jtag/aice/aice_transport.c +++ b/src/jtag/aice/aice_transport.c @@ -165,9 +165,9 @@ COMMAND_HANDLER(handle_scan_chain_command) aice_scan_jtag_chain(); tap = jtag_all_taps(); - command_print(CMD_CTX, + command_print(CMD, " TapName Enabled IdCode Expected IrLen IrCap IrMask"); - command_print(CMD_CTX, + command_print(CMD, "-- ------------------- -------- ---------- ---------- ----- ----- ------"); while (tap) { @@ -183,7 +183,7 @@ COMMAND_HANDLER(handle_scan_chain_command) expected = buf_get_u32(tap->expected, 0, tap->ir_length); expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length); - command_print(CMD_CTX, + command_print(CMD, "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x", tap->abs_chain_position, tap->dotted_name, @@ -200,7 +200,7 @@ COMMAND_HANDLER(handle_scan_chain_command) if (tap->ignore_version) expected_id[2] = '*'; - command_print(CMD_CTX, + command_print(CMD, " %s", expected_id); } diff --git a/src/jtag/drivers/amt_jtagaccel.c b/src/jtag/drivers/amt_jtagaccel.c index 57c0ce600..9808e34b7 100644 --- a/src/jtag/drivers/amt_jtagaccel.c +++ b/src/jtag/drivers/amt_jtagaccel.c @@ -548,7 +548,7 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = %u", amt_jtagaccel_port); + command_print(CMD, "parport port = %u", amt_jtagaccel_port); return ERROR_OK; } @@ -556,7 +556,7 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command) COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command) { if (CMD_ARGC == 0) { - command_print(CMD_CTX, + command_print(CMD, "amt_jtagaccel RTCK feature %s", (rtck_enabled) ? "enabled" : "disabled"); return ERROR_OK; diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index 926bd89d3..edec4beff 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -199,7 +199,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "BCM2835 GPIO config: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -211,7 +211,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tck = %d", tck_gpio); + command_print(CMD, "BCM2835 GPIO config: tck = %d", tck_gpio); return ERROR_OK; } @@ -220,7 +220,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tms = %d", tms_gpio); + command_print(CMD, "BCM2835 GPIO config: tms = %d", tms_gpio); return ERROR_OK; } @@ -229,7 +229,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tdo = %d", tdo_gpio); + command_print(CMD, "BCM2835 GPIO config: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -238,7 +238,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tdi = %d", tdi_gpio); + command_print(CMD, "BCM2835 GPIO config: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -247,7 +247,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: srst = %d", srst_gpio); + command_print(CMD, "BCM2835 GPIO config: srst = %d", srst_gpio); return ERROR_OK; } @@ -256,7 +256,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: trst = %d", trst_gpio); + command_print(CMD, "BCM2835 GPIO config: trst = %d", trst_gpio); return ERROR_OK; } @@ -269,7 +269,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "BCM2835 GPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -281,7 +281,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "BCM2835 num: swclk = %d", swclk_gpio); + command_print(CMD, "BCM2835 num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -290,7 +290,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "BCM2835 num: swdio = %d", swdio_gpio); + command_print(CMD, "BCM2835 num: swdio = %d", swdio_gpio); return ERROR_OK; } diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c index e16bcdcbf..0389427d8 100644 --- a/src/jtag/drivers/ft232r.c +++ b/src/jtag/drivers/ft232r.c @@ -442,7 +442,7 @@ COMMAND_HANDLER(ft232r_handle_jtag_nums_command) if (tdo_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R nums: TCK = %d %s, TMS = %d %s, TDI = %d %s, TDO = %d %s", tck_gpio, ft232r_bit_number_to_name(tck_gpio), tms_gpio, ft232r_bit_number_to_name(tms_gpio), @@ -462,7 +462,7 @@ COMMAND_HANDLER(ft232r_handle_tck_num_command) if (tck_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TCK = %d %s", tck_gpio, ft232r_bit_number_to_name(tck_gpio)); return ERROR_OK; @@ -478,7 +478,7 @@ COMMAND_HANDLER(ft232r_handle_tms_num_command) if (tms_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TMS = %d %s", tms_gpio, ft232r_bit_number_to_name(tms_gpio)); return ERROR_OK; @@ -494,7 +494,7 @@ COMMAND_HANDLER(ft232r_handle_tdo_num_command) if (tdo_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TDO = %d %s", tdo_gpio, ft232r_bit_number_to_name(tdo_gpio)); return ERROR_OK; @@ -510,7 +510,7 @@ COMMAND_HANDLER(ft232r_handle_tdi_num_command) if (tdi_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TDI = %d %s", tdi_gpio, ft232r_bit_number_to_name(tdi_gpio)); return ERROR_OK; @@ -526,7 +526,7 @@ COMMAND_HANDLER(ft232r_handle_trst_num_command) if (ntrst_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TRST = %d %s", ntrst_gpio, ft232r_bit_number_to_name(ntrst_gpio)); return ERROR_OK; @@ -542,7 +542,7 @@ COMMAND_HANDLER(ft232r_handle_srst_num_command) if (nsysrst_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: SRST = %d %s", nsysrst_gpio, ft232r_bit_number_to_name(nsysrst_gpio)); return ERROR_OK; @@ -555,7 +555,7 @@ COMMAND_HANDLER(ft232r_handle_restore_serial_command) else if (CMD_ARGC != 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R restore serial: 0x%04X (%s)", ft232r_restore_bitmode, ft232r_restore_bitmode == 0xFFFF ? "disabled" : "enabled"); diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index e7f3c3dce..00ae8d0e0 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -930,7 +930,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command) } n = Jim_Nvp_value2name_simple(nvp_ftdi_jtag_modes, ftdi_jtag_mode); - command_print(CMD_CTX, "ftdi samples TDO on %s edge of TCK", n->name); + command_print(CMD, "ftdi samples TDO on %s edge of TCK", n->name); return ERROR_OK; } diff --git a/src/jtag/drivers/gw16012.c b/src/jtag/drivers/gw16012.c index f6689969a..f91f7ac11 100644 --- a/src/jtag/drivers/gw16012.c +++ b/src/jtag/drivers/gw16012.c @@ -515,7 +515,7 @@ COMMAND_HANDLER(gw16012_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = %u", gw16012_port); + command_print(CMD, "parport port = %u", gw16012_port); return ERROR_OK; } diff --git a/src/jtag/drivers/imx_gpio.c b/src/jtag/drivers/imx_gpio.c index 8f172c26c..196d0e4a1 100644 --- a/src/jtag/drivers/imx_gpio.c +++ b/src/jtag/drivers/imx_gpio.c @@ -221,7 +221,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "imx_gpio GPIO config: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -233,7 +233,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tck = %d", tck_gpio); + command_print(CMD, "imx_gpio GPIO config: tck = %d", tck_gpio); return ERROR_OK; } @@ -242,7 +242,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tms = %d", tms_gpio); + command_print(CMD, "imx_gpio GPIO config: tms = %d", tms_gpio); return ERROR_OK; } @@ -251,7 +251,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tdo = %d", tdo_gpio); + command_print(CMD, "imx_gpio GPIO config: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -260,7 +260,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tdi = %d", tdi_gpio); + command_print(CMD, "imx_gpio GPIO config: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -269,7 +269,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: srst = %d", srst_gpio); + command_print(CMD, "imx_gpio GPIO config: srst = %d", srst_gpio); return ERROR_OK; } @@ -278,7 +278,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: trst = %d", trst_gpio); + command_print(CMD, "imx_gpio GPIO config: trst = %d", trst_gpio); return ERROR_OK; } @@ -291,7 +291,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "imx_gpio GPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -303,7 +303,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "imx_gpio num: swclk = %d", swclk_gpio); + command_print(CMD, "imx_gpio num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -312,7 +312,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "imx_gpio num: swdio = %d", swdio_gpio); + command_print(CMD, "imx_gpio num: swdio = %d", swdio_gpio); return ERROR_OK; } diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 090eeaa64..cc04953cd 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -923,17 +923,17 @@ COMMAND_HANDLER(jlink_usb_command) int tmp; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink usb."); + command_print(CMD, "Need exactly one argument for jlink usb."); return ERROR_COMMAND_SYNTAX_ERROR; } if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } if (tmp < JAYLINK_USB_ADDRESS_0 || tmp > JAYLINK_USB_ADDRESS_3) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } @@ -950,17 +950,17 @@ COMMAND_HANDLER(jlink_serial_command) int ret; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink serial."); + command_print(CMD, "Need exactly one argument for jlink serial."); return ERROR_COMMAND_SYNTAX_ERROR; } ret = jaylink_parse_serial_number(CMD_ARGV[0], &serial_number); if (ret == JAYLINK_ERR) { - command_print(CMD_CTX, "Invalid serial number: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid serial number: %s.", CMD_ARGV[0]); return ERROR_FAIL; } else if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_parse_serial_number() failed: %s.", + command_print(CMD, "jaylink_parse_serial_number() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } @@ -979,20 +979,20 @@ COMMAND_HANDLER(jlink_handle_hwstatus_command) ret = jaylink_get_hardware_status(devh, &status); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_get_hardware_status() failed: %s.", + command_print(CMD, "jaylink_get_hardware_status() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } - command_print(CMD_CTX, "VTarget = %u.%03u V", + command_print(CMD, "VTarget = %u.%03u V", status.target_voltage / 1000, status.target_voltage % 1000); - command_print(CMD_CTX, "TCK = %u TDI = %u TDO = %u TMS = %u SRST = %u " + command_print(CMD, "TCK = %u TDI = %u TDO = %u TMS = %u SRST = %u " "TRST = %u", status.tck, status.tdi, status.tdo, status.tms, status.tres, status.trst); if (status.target_voltage < 1500) - command_print(CMD_CTX, "Target voltage too low. Check target power."); + command_print(CMD, "Target voltage too low. Check target power."); return ERROR_OK; } @@ -1003,7 +1003,7 @@ COMMAND_HANDLER(jlink_handle_free_memory_command) uint32_t tmp; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) { - command_print(CMD_CTX, "Retrieval of free memory is not supported by " + command_print(CMD, "Retrieval of free memory is not supported by " "the device."); return ERROR_OK; } @@ -1011,12 +1011,12 @@ COMMAND_HANDLER(jlink_handle_free_memory_command) ret = jaylink_get_free_memory(devh, &tmp); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_get_free_memory() failed: %s.", + command_print(CMD, "jaylink_get_free_memory() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } - command_print(CMD_CTX, "Device has %u bytes of free memory.", tmp); + command_print(CMD, "Device has %u bytes of free memory.", tmp); return ERROR_OK; } @@ -1038,10 +1038,10 @@ COMMAND_HANDLER(jlink_handle_jlink_jtag_command) return ERROR_FAIL; } - command_print(CMD_CTX, "JTAG command version: %i", version); + command_print(CMD, "JTAG command version: %i", version); } else if (CMD_ARGC == 1) { if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1053,11 +1053,11 @@ COMMAND_HANDLER(jlink_handle_jlink_jtag_command) jtag_command_version = JAYLINK_JTAG_VERSION_3; break; default: - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Need exactly one argument for jlink jtag."); + command_print(CMD, "Need exactly one argument for jlink jtag."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1070,13 +1070,13 @@ COMMAND_HANDLER(jlink_handle_target_power_command) int enable; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink " + command_print(CMD, "Need exactly one argument for jlink " "targetpower."); return ERROR_COMMAND_SYNTAX_ERROR; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) { - command_print(CMD_CTX, "Target power supply is not supported by the " + command_print(CMD, "Target power supply is not supported by the " "device."); return ERROR_OK; } @@ -1086,14 +1086,14 @@ COMMAND_HANDLER(jlink_handle_target_power_command) } else if (!strcmp(CMD_ARGV[0], "off")) { enable = false; } else { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_FAIL; } ret = jaylink_set_target_power(devh, enable); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_set_target_power() failed: %s.", + command_print(CMD, "jaylink_set_target_power() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } @@ -1104,31 +1104,31 @@ COMMAND_HANDLER(jlink_handle_target_power_command) static void show_config_usb_address(struct command_invocation *cmd) { if (config.usb_address != tmp_config.usb_address) - command_print(cmd->ctx, "USB address: %u [%u]", config.usb_address, + command_print(cmd, "USB address: %u [%u]", config.usb_address, tmp_config.usb_address); else - command_print(cmd->ctx, "USB address: %u", config.usb_address); + command_print(cmd, "USB address: %u", config.usb_address); } static void show_config_ip_address(struct command_invocation *cmd) { if (!memcmp(config.ip_address, tmp_config.ip_address, 4)) - command_print(cmd->ctx, "IP address: %d.%d.%d.%d", + command_print(cmd, "IP address: %d.%d.%d.%d", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0]); else - command_print(cmd->ctx, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0], tmp_config.ip_address[3], tmp_config.ip_address[2], tmp_config.ip_address[1], tmp_config.ip_address[0]); if (!memcmp(config.subnet_mask, tmp_config.subnet_mask, 4)) - command_print(cmd->ctx, "Subnet mask: %d.%d.%d.%d", + command_print(cmd, "Subnet mask: %d.%d.%d.%d", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0]); else - command_print(cmd->ctx, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0], tmp_config.subnet_mask[3], tmp_config.subnet_mask[2], @@ -1138,12 +1138,12 @@ static void show_config_ip_address(struct command_invocation *cmd) static void show_config_mac_address(struct command_invocation *cmd) { if (!memcmp(config.mac_address, tmp_config.mac_address, 6)) - command_print(cmd->ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", + command_print(cmd, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], config.mac_address[1], config.mac_address[0]); else - command_print(cmd->ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " + command_print(cmd, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], @@ -1169,15 +1169,15 @@ static void show_config_target_power(struct command_invocation *cmd) current_target_power = "on"; if (config.target_power != tmp_config.target_power) - command_print(cmd->ctx, "Target power supply: %s [%s]", target_power, + command_print(cmd, "Target power supply: %s [%s]", target_power, current_target_power); else - command_print(cmd->ctx, "Target power supply: %s", target_power); + command_print(cmd, "Target power supply: %s", target_power); } static void show_config(struct command_invocation *cmd) { - command_print(cmd->ctx, "J-Link device configuration:"); + command_print(cmd, "J-Link device configuration:"); show_config_usb_address(cmd); @@ -1346,7 +1346,7 @@ COMMAND_HANDLER(jlink_handle_config_usb_address_command) uint8_t tmp; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } @@ -1355,18 +1355,18 @@ COMMAND_HANDLER(jlink_handle_config_usb_address_command) show_config_usb_address(CMD); } else if (CMD_ARGC == 1) { if (sscanf(CMD_ARGV[0], "%" SCNd8, &tmp) != 1) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } if (tmp > JAYLINK_USB_ADDRESS_3) { - command_print(CMD_CTX, "Invalid USB address: %u.", tmp); + command_print(CMD, "Invalid USB address: %u.", tmp); return ERROR_FAIL; } tmp_config.usb_address = tmp; } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " "usb."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1379,13 +1379,13 @@ COMMAND_HANDLER(jlink_handle_config_target_power_command) int enable; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) { - command_print(CMD_CTX, "Target power supply is not supported by the " + command_print(CMD, "Target power supply is not supported by the " "device."); return ERROR_OK; } @@ -1398,13 +1398,13 @@ COMMAND_HANDLER(jlink_handle_config_target_power_command) } else if (!strcmp(CMD_ARGV[0], "off")) { enable = false; } else { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_FAIL; } tmp_config.target_power = enable; } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " "targetpower."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1420,13 +1420,13 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) const char *str; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - command_print(CMD_CTX, "Ethernet connectivity is not supported by the " + command_print(CMD, "Ethernet connectivity is not supported by the " "device."); return ERROR_OK; } @@ -1438,7 +1438,7 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) if ((strlen(str) != 17) || (str[2] != ':' || str[5] != ':' || \ str[8] != ':' || str[11] != ':' || str[14] != ':')) { - command_print(CMD_CTX, "Invalid MAC address format."); + command_print(CMD, "Invalid MAC address format."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1448,18 +1448,18 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) } if (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5])) { - command_print(CMD_CTX, "Invalid MAC address: zero address."); + command_print(CMD, "Invalid MAC address: zero address."); return ERROR_COMMAND_SYNTAX_ERROR; } if (!(0x01 & addr[0])) { - command_print(CMD_CTX, "Invalid MAC address: multicast address."); + command_print(CMD, "Invalid MAC address: multicast address."); return ERROR_COMMAND_SYNTAX_ERROR; } memcpy(tmp_config.mac_address, addr, sizeof(addr)); } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " " mac."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1508,13 +1508,13 @@ COMMAND_HANDLER(jlink_handle_config_ip_address_command) uint8_t subnet_bits = 24; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - command_print(CMD_CTX, "Ethernet connectivity is not supported by the " + command_print(CMD, "Ethernet connectivity is not supported by the " "device."); return ERROR_OK; } @@ -1565,19 +1565,19 @@ COMMAND_HANDLER(jlink_handle_config_write_command) int ret; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) { - command_print(CMD_CTX, "Writing configuration is not supported by the " + command_print(CMD, "Writing configuration is not supported by the " "device."); return ERROR_OK; } if (!memcmp(&config, &tmp_config, sizeof(struct device_config))) { - command_print(CMD_CTX, "Operation not performed due to no changes in " + command_print(CMD, "Operation not performed due to no changes in " "the configuration."); return ERROR_OK; } @@ -1602,7 +1602,7 @@ COMMAND_HANDLER(jlink_handle_config_write_command) } memcpy(&tmp_config, &config, sizeof(struct device_config)); - command_print(CMD_CTX, "The new device configuration applies after power " + command_print(CMD, "The new device configuration applies after power " "cycling the J-Link device."); return ERROR_OK; @@ -1611,7 +1611,7 @@ COMMAND_HANDLER(jlink_handle_config_write_command) COMMAND_HANDLER(jlink_handle_config_command) { if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Device doesn't support reading configuration."); + command_print(CMD, "Device doesn't support reading configuration."); return ERROR_OK; } @@ -1732,7 +1732,7 @@ COMMAND_HANDLER(jlink_handle_emucom_read_command) return ERROR_FAIL; } - command_print(CMD_CTX, "%s", buf + length); + command_print(CMD, "%s", buf + length); free(buf); return ERROR_OK; diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index cec453dd9..2f8b524f7 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -185,7 +185,7 @@ COMMAND_HANDLER(opendous_handle_opendous_hw_jtag_command) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "opendous hw jtag %i", opendous_hw_jtag_version); + command_print(CMD, "opendous hw jtag %i", opendous_hw_jtag_version); break; case 1: { diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c index 14fa9df9f..0e7992fe9 100644 --- a/src/jtag/drivers/parport.c +++ b/src/jtag/drivers/parport.c @@ -413,7 +413,7 @@ COMMAND_HANDLER(parport_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = 0x%" PRIx16 "", parport_port); + command_print(CMD, "parport port = 0x%" PRIx16 "", parport_port); return ERROR_OK; } @@ -470,7 +470,7 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command) } } - command_print(CMD_CTX, "parport toggling time = %" PRIu32 " ns", + command_print(CMD, "parport toggling time = %" PRIu32 " ns", parport_toggling_time_ns); return ERROR_OK; diff --git a/src/jtag/drivers/sysfsgpio.c b/src/jtag/drivers/sysfsgpio.c index 90e93f5a6..eb4941e6b 100644 --- a/src/jtag/drivers/sysfsgpio.c +++ b/src/jtag/drivers/sysfsgpio.c @@ -356,7 +356,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "SysfsGPIO nums: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -368,7 +368,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tck = %d", tck_gpio); + command_print(CMD, "SysfsGPIO num: tck = %d", tck_gpio); return ERROR_OK; } @@ -377,7 +377,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tms = %d", tms_gpio); + command_print(CMD, "SysfsGPIO num: tms = %d", tms_gpio); return ERROR_OK; } @@ -386,7 +386,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tdo = %d", tdo_gpio); + command_print(CMD, "SysfsGPIO num: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -395,7 +395,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tdi = %d", tdi_gpio); + command_print(CMD, "SysfsGPIO num: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -404,7 +404,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "SysfsGPIO num: srst = %d", srst_gpio); + command_print(CMD, "SysfsGPIO num: srst = %d", srst_gpio); return ERROR_OK; } @@ -413,7 +413,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "SysfsGPIO num: trst = %d", trst_gpio); + command_print(CMD, "SysfsGPIO num: trst = %d", trst_gpio); return ERROR_OK; } @@ -426,7 +426,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "SysfsGPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -438,7 +438,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "SysfsGPIO num: swclk = %d", swclk_gpio); + command_print(CMD, "SysfsGPIO num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -447,7 +447,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "SysfsGPIO num: swdio = %d", swdio_gpio); + command_print(CMD, "SysfsGPIO num: swdio = %d", swdio_gpio); return ERROR_OK; } diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 71d220b82..0161b2807 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -952,9 +952,9 @@ COMMAND_HANDLER(handle_scan_chain_command) char expected_id[12]; tap = jtag_all_taps(); - command_print(CMD_CTX, + command_print(CMD, " TapName Enabled IdCode Expected IrLen IrCap IrMask"); - command_print(CMD_CTX, + command_print(CMD, "-- ------------------- -------- ---------- ---------- ----- ----- ------"); while (tap) { @@ -970,7 +970,7 @@ COMMAND_HANDLER(handle_scan_chain_command) expected = buf_get_u32(tap->expected, 0, tap->ir_length); expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length); - command_print(CMD_CTX, + command_print(CMD, "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x", tap->abs_chain_position, tap->dotted_name, @@ -987,7 +987,7 @@ COMMAND_HANDLER(handle_scan_chain_command) if (tap->ignore_version) expected_id[2] = '*'; - command_print(CMD_CTX, + command_print(CMD, " %s", expected_id); } @@ -1008,7 +1008,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_delay_command) jtag_set_ntrst_delay(delay); } - command_print(CMD_CTX, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); + command_print(CMD, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); return ERROR_OK; } @@ -1022,7 +1022,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command) jtag_set_ntrst_assert_width(delay); } - command_print(CMD_CTX, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); + command_print(CMD, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); return ERROR_OK; } @@ -1047,9 +1047,9 @@ COMMAND_HANDLER(handle_jtag_rclk_command) return retval; if (cur_khz) - command_print(CMD_CTX, "RCLK not supported - fallback to %d kHz", cur_khz); + command_print(CMD, "RCLK not supported - fallback to %d kHz", cur_khz); else - command_print(CMD_CTX, "RCLK - adaptive"); + command_print(CMD, "RCLK - adaptive"); return retval; } @@ -1148,7 +1148,7 @@ COMMAND_HANDLER(handle_irscan_command) tap = jtag_tap_by_string(CMD_ARGV[i*2]); if (tap == NULL) { free(fields); - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[i*2]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]); return ERROR_FAIL; } @@ -1193,7 +1193,7 @@ COMMAND_HANDLER(handle_verify_ircapture_command) } const char *status = jtag_will_verify_capture_ir() ? "enabled" : "disabled"; - command_print(CMD_CTX, "verify Capture-IR is %s", status); + command_print(CMD, "verify Capture-IR is %s", status); return ERROR_OK; } @@ -1210,7 +1210,7 @@ COMMAND_HANDLER(handle_verify_jtag_command) } const char *status = jtag_will_verify() ? "enabled" : "disabled"; - command_print(CMD_CTX, "verify jtag capture is %s", status); + command_print(CMD, "verify jtag capture is %s", status); return ERROR_OK; } @@ -1232,7 +1232,7 @@ COMMAND_HANDLER(handle_tms_sequence_command) tap_use_new_tms_table(use_new_table); } - command_print(CMD_CTX, "tms sequence is %s", + command_print(CMD, "tms sequence is %s", tap_uses_new_tms_table() ? "short" : "long"); return ERROR_OK; diff --git a/src/pld/pld.c b/src/pld/pld.c index 3f23f6a00..ef7993c5d 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -116,12 +116,12 @@ COMMAND_HANDLER(handle_pld_devices_command) int i = 0; if (!pld_devices) { - command_print(CMD_CTX, "no pld devices configured"); + command_print(CMD, "no pld devices configured"); return ERROR_OK; } for (p = pld_devices; p; p = p->next) - command_print(CMD_CTX, "#%i: %s", i++, p->driver->name); + command_print(CMD, "#%i: %s", i++, p->driver->name); return ERROR_OK; } @@ -141,13 +141,13 @@ COMMAND_HANDLER(handle_pld_load_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id); p = get_pld_device_by_num(dev_id); if (!p) { - command_print(CMD_CTX, "pld device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } retval = p->driver->load(p, CMD_ARGV[1]); if (retval != ERROR_OK) { - command_print(CMD_CTX, "failed loading file %s to pld device %u", + command_print(CMD, "failed loading file %s to pld device %u", CMD_ARGV[1], dev_id); switch (retval) { } @@ -156,7 +156,7 @@ COMMAND_HANDLER(handle_pld_load_command) gettimeofday(&end, NULL); timeval_subtract(&duration, &end, &start); - command_print(CMD_CTX, "loaded file %s to pld device %u in %jis %jius", + command_print(CMD, "loaded file %s to pld device %u in %jis %jius", CMD_ARGV[1], dev_id, (intmax_t)duration.tv_sec, (intmax_t)duration.tv_usec); } diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index 4e385e97b..934a6807c 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -183,13 +183,13 @@ COMMAND_HANDLER(virtex2_handle_read_stat_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id); device = get_pld_device_by_num(dev_id); if (!device) { - command_print(CMD_CTX, "pld device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } virtex2_read_stat(device, &status); - command_print(CMD_CTX, "virtex2 status register: 0x%8.8" PRIx32 "", status); + command_print(CMD, "virtex2 status register: 0x%8.8" PRIx32 "", status); return ERROR_OK; } @@ -205,7 +205,7 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command) tap = jtag_tap_by_string(CMD_ARGV[1]); if (tap == NULL) { - command_print(CMD_CTX, "Tap: %s does not exist", CMD_ARGV[1]); + command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]); return ERROR_OK; } diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 95e6c0491..c6cf7d350 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3494,7 +3494,7 @@ COMMAND_HANDLER(handle_gdb_sync_command) return ERROR_COMMAND_SYNTAX_ERROR; if (current_gdb_connection == NULL) { - command_print(CMD_CTX, + command_print(CMD, "gdb_sync command can only be run from within gdb using \"monitor gdb_sync\""); return ERROR_FAIL; } diff --git a/src/server/server.c b/src/server/server.c index 539bdaf82..9e63f74f4 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -769,7 +769,7 @@ COMMAND_HANDLER(handle_bindto_command) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "bindto name: %s", bindto_name); + command_print(CMD, "bindto name: %s", bindto_name); break; case 1: free(bindto_name); @@ -828,7 +828,7 @@ COMMAND_HELPER(server_port_command, unsigned short *out) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%d", *out); + command_print(CMD, "%d", *out); break; case 1: { @@ -847,7 +847,7 @@ COMMAND_HELPER(server_pipe_command, char **out) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%s", *out); + command_print(CMD, "%s", *out); break; case 1: { diff --git a/src/svf/svf.c b/src/svf/svf.c index 223af7e18..759ba5263 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -382,7 +382,7 @@ COMMAND_HANDLER(handle_svf_command) if (strcmp(CMD_ARGV[i], "-tap") == 0) { tap = jtag_tap_by_string(CMD_ARGV[i+1]); if (!tap) { - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[i+1]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[i+1]); return ERROR_FAIL; } i++; @@ -401,7 +401,7 @@ COMMAND_HANDLER(handle_svf_command) svf_fd = fopen(CMD_ARGV[i], "r"); if (svf_fd == NULL) { int err = errno; - command_print(CMD_CTX, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err)); + command_print(CMD, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err)); /* no need to free anything now */ return ERROR_COMMAND_SYNTAX_ERROR; } else @@ -534,7 +534,7 @@ COMMAND_HANDLER(handle_svf_command) time_measure_m = time_measure_s / 60; time_measure_s %= 60; if (time_measure_ms < 1000) - command_print(CMD_CTX, + command_print(CMD, "\r\nTime used: %dm%ds%" PRId64 "ms ", time_measure_m, time_measure_s, @@ -579,13 +579,13 @@ free_all: svf_free_xxd_para(&svf_para.sir_para); if (ERROR_OK == ret) - command_print(CMD_CTX, + command_print(CMD, "svf file programmed %s for %d commands with %d errors", (svf_ignore_error > 1) ? "unsuccessfully" : "successfully", command_num, (svf_ignore_error > 1) ? (svf_ignore_error - 1) : 0); else - command_print(CMD_CTX, "svf file programmed failed"); + command_print(CMD, "svf file programmed failed"); svf_ignore_error = 0; return ret; diff --git a/src/target/aarch64.c b/src/target/aarch64.c index 68ae9f1bf..9e8983f3f 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -2572,7 +2572,7 @@ COMMAND_HANDLER(aarch64_mask_interrupts_command) } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, aarch64->isrmasking_mode); - command_print(CMD_CTX, "aarch64 interrupt mask %s", n->name); + command_print(CMD, "aarch64 interrupt mask %s", n->name); return ERROR_OK; } diff --git a/src/target/arm720t.c b/src/target/arm720t.c index e8ad852c9..abe5f1cea 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -237,7 +237,7 @@ static int arm720t_verify_pointer(struct command_invocation *cmd, struct arm720t_common *arm720t) { if (arm720t->common_magic != ARM720T_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not an ARM720"); + command_print(cmd, "target is not an ARM720"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -447,7 +447,7 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -460,7 +460,7 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) uint32_t value; retval = arm720t_read_cp15(target, opcode, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); + command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); return ERROR_OK; } @@ -468,17 +468,17 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); + command_print(CMD, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); } else if (CMD_ARGC == 2) { uint32_t value; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); retval = arm720t_write_cp15(target, opcode, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); + command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); return ERROR_OK; } - command_print(CMD_CTX, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); + command_print(CMD, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); } } diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 4fedc0d8f..b2962d1c4 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2747,14 +2747,14 @@ COMMAND_HANDLER(handle_arm7_9_dbgrq_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->use_dbgrq); - command_print(CMD_CTX, + command_print(CMD, "use of EmbeddedICE dbgrq instead of breakpoint for target halt %s", (arm7_9->use_dbgrq) ? "enabled" : "disabled"); @@ -2767,14 +2767,14 @@ COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->fast_memory_access); - command_print(CMD_CTX, + command_print(CMD, "fast memory access is %s", (arm7_9->fast_memory_access) ? "enabled" : "disabled"); @@ -2787,14 +2787,14 @@ COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->dcc_downloads); - command_print(CMD_CTX, + command_print(CMD, "dcc downloads are %s", (arm7_9->dcc_downloads) ? "enabled" : "disabled"); diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 88a03952d..2ecf218fd 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -511,7 +511,7 @@ static int arm920t_verify_pointer(struct command_invocation *cmd, struct arm920t_common *arm920t) { if (arm920t->common_magic != ARM920T_COMMON_MAGIC) { - command_print(cmd->ctx, arm920_not); + command_print(cmd, arm920_not); return ERROR_TARGET_INVALID; } @@ -1103,7 +1103,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) /* restore CP15 MMU and Cache settings */ arm920t_write_cp15_physical(target, CP15PHYS_CTRL, cp15_ctrl_saved); - command_print(CMD_CTX, "cache content successfully output to %s", + command_print(CMD, "cache content successfully output to %s", CMD_ARGV[0]); fclose(output); @@ -1415,7 +1415,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) (i_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)"); } - command_print(CMD_CTX, "mmu content successfully output to %s", + command_print(CMD, "mmu content successfully output to %s", CMD_ARGV[0]); fclose(output); @@ -1456,7 +1456,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for " + command_print(CMD, "target must be stopped for " "\"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1472,7 +1472,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) uint32_t value; retval = arm920t_read_cp15_physical(target, address, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %i", address); return ERROR_OK; } @@ -1480,7 +1480,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "%i: %8.8" PRIx32, + command_print(CMD, "%i: %8.8" PRIx32, address, value); } else if (CMD_ARGC == 2) { uint32_t value; @@ -1488,12 +1488,12 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) retval = arm920t_write_cp15_physical(target, address, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %i", address); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%i: %8.8" PRIx32, + command_print(CMD, "%i: %8.8" PRIx32, address, value); } } @@ -1513,7 +1513,7 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for " + command_print(CMD, "target must be stopped for " "\"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1530,14 +1530,14 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_read_cp15_interpreted(target, opcode, 0x0, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32, + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, opcode, value); } else if (CMD_ARGC == 2) { uint32_t value; @@ -1545,13 +1545,13 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_write_cp15_interpreted(target, opcode, value, 0); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32, + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, opcode, value); } else if (CMD_ARGC == 3) { uint32_t value; @@ -1561,12 +1561,12 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_write_cp15_interpreted(target, opcode, value, address); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32 + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32 " %8.8" PRIx32, opcode, value, address); } } else diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 01ce17663..ac30485b8 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -505,7 +505,7 @@ static int arm926ejs_verify_pointer(struct command_invocation *cmd, struct arm926ejs_common *arm926) { if (arm926->common_magic != ARM926EJS_COMMON_MAGIC) { - command_print(cmd->ctx, arm926_not); + command_print(cmd, arm926_not); return ERROR_TARGET_INVALID; } return ERROR_OK; diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 278a70ca2..112631a7c 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -103,7 +103,7 @@ static int arm946e_verify_pointer(struct command_invocation *cmd, struct arm946e_common *arm946e) { if (arm946e->common_magic != ARM946E_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not an ARM946"); + command_print(cmd, "target is not an ARM946"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -563,7 +563,7 @@ COMMAND_HANDLER(arm946e_handle_cp15) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_TARGET_NOT_HALTED; } @@ -574,7 +574,7 @@ COMMAND_HANDLER(arm946e_handle_cp15) uint32_t value; retval = arm946e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); return retval; } retval = jtag_execute_queue(); @@ -582,14 +582,14 @@ COMMAND_HANDLER(arm946e_handle_cp15) return retval; /* Return value in hex format */ - command_print(CMD_CTX, "0x%08" PRIx32, value); + command_print(CMD, "0x%08" PRIx32, value); } else if (CMD_ARGC == 2) { uint32_t value; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); retval = arm946e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); return retval; } if (address == CP15_CTL) @@ -613,7 +613,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_TARGET_NOT_HALTED; } @@ -623,9 +623,9 @@ COMMAND_HANDLER(arm946e_handle_idcache) bool bena = ((arm946e->cp15_control_reg & (icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE)) != 0) && (arm946e->cp15_control_reg & 0x1); if (csize == 0) - command_print(CMD_CTX, "%s-cache absent", icache ? "I" : "D"); + command_print(CMD, "%s-cache absent", icache ? "I" : "D"); else - command_print(CMD_CTX, "%s-cache size: %" PRIu32 "K, %s", + command_print(CMD, "%s-cache size: %" PRIu32 "K, %s", icache ? "I" : "D", csize, bena ? "enabled" : "disabled"); return ERROR_OK; } @@ -643,7 +643,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) /* Do not invalidate or change state, if cache is absent */ if (csize == 0) { - command_print(CMD_CTX, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); + command_print(CMD, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } diff --git a/src/target/arm966e.c b/src/target/arm966e.c index 98c62745f..8462f546e 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -60,7 +60,7 @@ static int arm966e_verify_pointer(struct command_invocation *cmd, struct arm966e_common *arm966e) { if (arm966e->common_magic != ARM966E_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not an ARM966"); + command_print(cmd, "target is not an ARM966"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -175,7 +175,7 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -188,7 +188,7 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) uint32_t value; retval = arm966e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, address); return ERROR_OK; @@ -197,19 +197,19 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "%" PRIi32 ": %8.8" PRIx32, address, value); } else if (CMD_ARGC == 2) { uint32_t value; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); retval = arm966e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, address); return ERROR_OK; } - command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "%" PRIi32 ": %8.8" PRIx32, address, value); } } diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 6425027f4..6ab06edf9 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -801,7 +801,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* it's uncommon, but some ARM7 chips can support this */ if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC || !arm7_9->has_vector_catch) { - command_print(CMD_CTX, "target doesn't have EmbeddedICE " + command_print(CMD, "target doesn't have EmbeddedICE " "with vector_catch"); return ERROR_TARGET_INVALID; } @@ -834,7 +834,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* complain if vector wasn't found */ if (!arm9tdmi_vectors[j].name) { - command_print(CMD_CTX, "vector '%s' not found, leaving current setting unchanged", CMD_ARGV[i]); + command_print(CMD, "vector '%s' not found, leaving current setting unchanged", CMD_ARGV[i]); /* reread current setting */ vector_catch_value = buf_get_u32( @@ -852,7 +852,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* output current settings */ for (unsigned i = 0; arm9tdmi_vectors[i].name; i++) { - command_print(CMD_CTX, "%s: %s", arm9tdmi_vectors[i].name, + command_print(CMD, "%s: %s", arm9tdmi_vectors[i].name, (vector_catch_value & arm9tdmi_vectors[i].value) ? "catch" : "don't catch"); } diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index f9eb8f4cb..8ff5efd7a 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1199,7 +1199,7 @@ static int dap_rom_display(struct command_invocation *cmd, char tabs[16] = ""; if (depth > 16) { - command_print(cmd->ctx, "\tTables too deep"); + command_print(cmd, "\tTables too deep"); return ERROR_FAIL; } @@ -1207,25 +1207,25 @@ static int dap_rom_display(struct command_invocation *cmd, snprintf(tabs, sizeof(tabs), "[L%02d] ", depth); uint32_t base_addr = dbgbase & 0xFFFFF000; - command_print(cmd->ctx, "\t\tComponent base address 0x%08" PRIx32, base_addr); + command_print(cmd, "\t\tComponent base address 0x%08" PRIx32, base_addr); retval = dap_read_part_id(ap, base_addr, &cid, &pid); if (retval != ERROR_OK) { - command_print(cmd->ctx, "\t\tCan't read component, the corresponding core might be turned off"); + command_print(cmd, "\t\tCan't read component, the corresponding core might be turned off"); return ERROR_OK; /* Don't abort recursion */ } if (!is_dap_cid_ok(cid)) { - command_print(cmd->ctx, "\t\tInvalid CID 0x%08" PRIx32, cid); + command_print(cmd, "\t\tInvalid CID 0x%08" PRIx32, cid); return ERROR_OK; /* Don't abort recursion */ } /* component may take multiple 4K pages */ uint32_t size = (pid >> 36) & 0xf; if (size > 0) - command_print(cmd->ctx, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); + command_print(cmd, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); - command_print(cmd->ctx, "\t\tPeripheral ID 0x%010" PRIx64, pid); + command_print(cmd, "\t\tPeripheral ID 0x%010" PRIx64, pid); uint8_t class = (cid >> 12) & 0xf; uint16_t part_num = pid & 0xfff; @@ -1233,12 +1233,12 @@ static int dap_rom_display(struct command_invocation *cmd, if (designer_id & 0x80) { /* JEP106 code */ - command_print(cmd->ctx, "\t\tDesigner is 0x%03" PRIx16 ", %s", + command_print(cmd, "\t\tDesigner is 0x%03" PRIx16 ", %s", designer_id, jep106_manufacturer(designer_id >> 8, designer_id & 0x7f)); } else { /* Legacy ASCII ID, clear invalid bits */ designer_id &= 0x7f; - command_print(cmd->ctx, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", + command_print(cmd, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", designer_id, designer_id == 0x41 ? "ARM" : ""); } @@ -1260,8 +1260,8 @@ static int dap_rom_display(struct command_invocation *cmd, break; } - command_print(cmd->ctx, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); - command_print(cmd->ctx, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); + command_print(cmd, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); + command_print(cmd, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); if (class == 1) { /* ROM Table */ uint32_t memtype; @@ -1270,9 +1270,9 @@ static int dap_rom_display(struct command_invocation *cmd, return retval; if (memtype & 0x01) - command_print(cmd->ctx, "\t\tMEMTYPE system memory present on bus"); + command_print(cmd, "\t\tMEMTYPE system memory present on bus"); else - command_print(cmd->ctx, "\t\tMEMTYPE system memory not present: dedicated debug bus"); + command_print(cmd, "\t\tMEMTYPE system memory not present: dedicated debug bus"); /* Read ROM table entries from base address until we get 0x00000000 or reach the reserved area */ for (uint16_t entry_offset = 0; entry_offset < 0xF00; entry_offset += 4) { @@ -1280,7 +1280,7 @@ static int dap_rom_display(struct command_invocation *cmd, retval = mem_ap_read_atomic_u32(ap, base_addr | entry_offset, &romentry); if (retval != ERROR_OK) return retval; - command_print(cmd->ctx, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", + command_print(cmd, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", tabs, entry_offset, romentry); if (romentry & 0x01) { /* Recurse */ @@ -1288,9 +1288,9 @@ static int dap_rom_display(struct command_invocation *cmd, if (retval != ERROR_OK) return retval; } else if (romentry != 0) { - command_print(cmd->ctx, "\t\tComponent not present"); + command_print(cmd, "\t\tComponent not present"); } else { - command_print(cmd->ctx, "\t%s\tEnd of ROM table", tabs); + command_print(cmd, "\t%s\tEnd of ROM table", tabs); break; } } @@ -1435,7 +1435,7 @@ static int dap_rom_display(struct command_invocation *cmd, } break; } - command_print(cmd->ctx, "\t\tType is 0x%02" PRIx8 ", %s, %s", + command_print(cmd, "\t\tType is 0x%02" PRIx8 ", %s, %s", (uint8_t)(devtype & 0xff), major, subtype); /* REVISIT also show 0xfc8 DevId */ @@ -1456,27 +1456,27 @@ int dap_info_command(struct command_invocation *cmd, if (retval != ERROR_OK) return retval; - command_print(cmd->ctx, "AP ID register 0x%8.8" PRIx32, apid); + command_print(cmd, "AP ID register 0x%8.8" PRIx32, apid); if (apid == 0) { - command_print(cmd->ctx, "No AP found at this ap 0x%x", ap->ap_num); + command_print(cmd, "No AP found at this ap 0x%x", ap->ap_num); return ERROR_FAIL; } switch (apid & (IDR_JEP106 | IDR_TYPE)) { case IDR_JEP106_ARM | AP_TYPE_JTAG_AP: - command_print(cmd->ctx, "\tType is JTAG-AP"); + command_print(cmd, "\tType is JTAG-AP"); break; case IDR_JEP106_ARM | AP_TYPE_AHB_AP: - command_print(cmd->ctx, "\tType is MEM-AP AHB"); + command_print(cmd, "\tType is MEM-AP AHB"); break; case IDR_JEP106_ARM | AP_TYPE_APB_AP: - command_print(cmd->ctx, "\tType is MEM-AP APB"); + command_print(cmd, "\tType is MEM-AP APB"); break; case IDR_JEP106_ARM | AP_TYPE_AXI_AP: - command_print(cmd->ctx, "\tType is MEM-AP AXI"); + command_print(cmd, "\tType is MEM-AP AXI"); break; default: - command_print(cmd->ctx, "\tUnknown AP type"); + command_print(cmd, "\tUnknown AP type"); break; } @@ -1485,15 +1485,15 @@ int dap_info_command(struct command_invocation *cmd, */ mem_ap = (apid & IDR_CLASS) == AP_CLASS_MEM_AP; if (mem_ap) { - command_print(cmd->ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); + command_print(cmd, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); if (dbgbase == 0xFFFFFFFF || (dbgbase & 0x3) == 0x2) { - command_print(cmd->ctx, "\tNo ROM table present"); + command_print(cmd, "\tNo ROM table present"); } else { if (dbgbase & 0x01) - command_print(cmd->ctx, "\tValid ROM table present"); + command_print(cmd, "\tValid ROM table present"); else - command_print(cmd->ctx, "\tROM table in legacy format"); + command_print(cmd, "\tROM table in legacy format"); dap_rom_display(cmd, ap, dbgbase & 0xFFFFF000, 0); } @@ -1681,7 +1681,7 @@ COMMAND_HANDLER(dap_baseaddr_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32, baseaddr); + command_print(CMD, "0x%8.8" PRIx32, baseaddr); return retval; } @@ -1703,7 +1703,7 @@ COMMAND_HANDLER(dap_memaccess_command) } dap->ap[dap->apsel].memaccess_tck = memaccess_tck; - command_print(CMD_CTX, "memory bus access delay set to %" PRIi32 " tck", + command_print(CMD, "memory bus access delay set to %" PRIi32 " tck", dap->ap[dap->apsel].memaccess_tck); return ERROR_OK; @@ -1716,7 +1716,7 @@ COMMAND_HANDLER(dap_apsel_command) switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%" PRIi32, dap->apsel); + command_print(CMD, "%" PRIi32, dap->apsel); return ERROR_OK; case 1: COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel); @@ -1740,7 +1740,7 @@ COMMAND_HANDLER(dap_apcsw_command) switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "ap %" PRIi32 " selected, csw 0x%8.8" PRIx32, + command_print(CMD, "ap %" PRIi32 " selected, csw 0x%8.8" PRIx32, dap->apsel, apcsw); return ERROR_OK; case 1: @@ -1801,7 +1801,7 @@ COMMAND_HANDLER(dap_apid_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32, apid); + command_print(CMD, "0x%8.8" PRIx32, apid); return retval; } @@ -1853,7 +1853,7 @@ COMMAND_HANDLER(dap_apreg_command) return retval; if (CMD_ARGC == 2) - command_print(CMD_CTX, "0x%08" PRIx32, value); + command_print(CMD, "0x%08" PRIx32, value); return retval; } @@ -1884,7 +1884,7 @@ COMMAND_HANDLER(dap_dpreg_command) return retval; if (CMD_ARGC == 1) - command_print(CMD_CTX, "0x%08" PRIx32, value); + command_print(CMD, "0x%08" PRIx32, value); return retval; } @@ -1906,7 +1906,7 @@ COMMAND_HANDLER(dap_ti_be_32_quirks_command) return ERROR_COMMAND_SYNTAX_ERROR; } dap->ti_be_32_quirks = enable; - command_print(CMD_CTX, "TI BE-32 quirks mode %s", + command_print(CMD, "TI BE-32 quirks mode %s", enable ? "enabled" : "disabled"); return 0; diff --git a/src/target/arm_cti.c b/src/target/arm_cti.c index 3fa54d69c..3f063b894 100644 --- a/src/target/arm_cti.c +++ b/src/target/arm_cti.c @@ -252,7 +252,7 @@ COMMAND_HANDLER(handle_cti_dump) return JIM_ERR; for (int i = 0; i < (int)ARRAY_SIZE(cti_names); i++) - command_print(CMD_CTX, "%8.8s (0x%04"PRIx32") 0x%08"PRIx32, + command_print(CMD, "%8.8s (0x%04"PRIx32") 0x%08"PRIx32, cti_names[i].label, cti_names[i].offset, *cti_names[i].p_val); return JIM_OK; @@ -336,7 +336,7 @@ COMMAND_HANDLER(handle_cti_read) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%08"PRIx32, value); + command_print(CMD, "0x%08"PRIx32, value); return ERROR_OK; } diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index d04b17973..53a6b2229 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -778,17 +778,17 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) struct reg *regs; if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "error: target must be halted for register accesses"); + command_print(CMD, "error: target must be halted for register accesses"); return ERROR_FAIL; } if (arm->core_type != ARM_MODE_ANY) { - command_print(CMD_CTX, + command_print(CMD, "Microcontroller Profile not supported - use standard reg cmd"); return ERROR_OK; } @@ -799,7 +799,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) } if (!arm->full_context) { - command_print(CMD_CTX, "error: target doesn't support %s", + command_print(CMD, "error: target doesn't support %s", CMD_NAME); return ERROR_FAIL; } @@ -828,7 +828,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) shadow = "shadow "; break; } - command_print(CMD_CTX, "%s%s mode %sregisters", + command_print(CMD, "%s%s mode %sregisters", sep, name, shadow); /* display N rows of up to 4 registers each */ @@ -855,7 +855,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) "%8s: %8.8" PRIx32 " ", reg->name, value); } - command_print(CMD_CTX, "%s", output); + command_print(CMD, "%s", output); } } @@ -868,13 +868,13 @@ COMMAND_HANDLER(handle_armv4_5_core_state_command) struct arm *arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (arm->core_type == ARM_MODE_THREAD) { /* armv7m not supported */ - command_print(CMD_CTX, "Unsupported Command"); + command_print(CMD, "Unsupported Command"); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(handle_armv4_5_core_state_command) arm->core_state = ARM_STATE_THUMB; } - command_print(CMD_CTX, "core state: %s", arm_state_strings[arm->core_state]); + command_print(CMD, "core state: %s", arm_state_strings[arm->core_state]); return ERROR_OK; } @@ -906,7 +906,7 @@ COMMAND_HANDLER(handle_arm_disassemble_command) int thumb = 0; if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } @@ -928,7 +928,7 @@ COMMAND_HANDLER(handle_arm_disassemble_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); if (address & 0x01) { if (!thumb) { - command_print(CMD_CTX, "Disassemble as Thumb"); + command_print(CMD, "Disassemble as Thumb"); thumb = 1; } address &= ~1; @@ -963,7 +963,7 @@ usage: if (retval != ERROR_OK) break; } - command_print(CMD_CTX, "%s", cur_instruction.text); + command_print(CMD, "%s", cur_instruction.text); address += cur_instruction.instruction_size; } diff --git a/src/target/armv4_5_cache.c b/src/target/armv4_5_cache.c index 6a169253e..eda8cb7c6 100644 --- a/src/target/armv4_5_cache.c +++ b/src/target/armv4_5_cache.c @@ -79,20 +79,20 @@ int armv4_5_identify_cache(uint32_t cache_type_reg, struct armv4_5_cache_common int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache) { if (armv4_5_cache->ctype == -1) { - command_print(cmd->ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } - command_print(cmd->ctx, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, + command_print(cmd, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, (armv4_5_cache->separate) ? "separate caches" : "unified cache"); - command_print(cmd->ctx, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->d_u_size.linelen, armv4_5_cache->d_u_size.associativity, armv4_5_cache->d_u_size.nsets, armv4_5_cache->d_u_size.cachesize); - command_print(cmd->ctx, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->i_size.linelen, armv4_5_cache->i_size.associativity, armv4_5_cache->i_size.nsets, diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 7f51990af..2be70b78b 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -229,7 +229,7 @@ COMMAND_HANDLER(handle_cache_l2x) if (CMD_ARGC != 2) return ERROR_COMMAND_SYNTAX_ERROR; - /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ + /* command_print(CMD, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way); @@ -248,7 +248,7 @@ int armv7a_handle_cache_info_command(struct command_invocation *cmd, int cl; if (armv7a_cache->info == -1) { - command_print(cmd->ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } @@ -256,7 +256,7 @@ int armv7a_handle_cache_info_command(struct command_invocation *cmd, struct armv7a_arch_cache *arch = &(armv7a_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd->ctx, + command_print(cmd, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -269,7 +269,7 @@ int armv7a_handle_cache_info_command(struct command_invocation *cmd, } if (arch->ctype >= 2) { - command_print(cmd->ctx, + command_print(cmd, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -283,7 +283,7 @@ int armv7a_handle_cache_info_command(struct command_invocation *cmd, } if (l2x_cache != NULL) - command_print(cmd->ctx, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", + command_print(cmd, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); return ERROR_OK; diff --git a/src/target/armv7a_cache.c b/src/target/armv7a_cache.c index fca195c29..921ba9be9 100644 --- a/src/target/armv7a_cache.c +++ b/src/target/armv7a_cache.c @@ -513,7 +513,7 @@ COMMAND_HANDLER(arm7a_cache_disable_auto_cmd) struct armv7a_common *armv7a = target_to_armv7a(target); if (CMD_ARGC == 0) { - command_print(CMD_CTX, "auto cache is %s", + command_print(CMD, "auto cache is %s", armv7a->armv7a_mmu.armv7a_cache.auto_cache_enabled ? "enabled" : "disabled"); return ERROR_OK; } diff --git a/src/target/armv7a_cache_l2x.c b/src/target/armv7a_cache_l2x.c index 0aa695382..72e12b42b 100644 --- a/src/target/armv7a_cache_l2x.c +++ b/src/target/armv7a_cache_l2x.c @@ -180,11 +180,11 @@ static int arm7a_handle_l2x_cache_info_command(struct command_invocation *cmd, (armv7a_cache->outer_cache); if (armv7a_cache->info == -1) { - command_print(cmd->ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } - command_print(cmd->ctx, + command_print(cmd, "L2 unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); @@ -312,7 +312,7 @@ COMMAND_HANDLER(armv7a_l2x_cache_conf_cmd) if (CMD_ARGC != 2) return ERROR_COMMAND_SYNTAX_ERROR; - /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ + /* command_print(CMD, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way); diff --git a/src/target/armv8.c b/src/target/armv8.c index 4054c954f..e7369372a 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -1054,7 +1054,7 @@ COMMAND_HANDLER(armv8_handle_exception_catch_command) return ERROR_FAIL; } - command_print(CMD_CTX, "Exception Catch: Secure: %s, Non-Secure: %s", sec, nsec); + command_print(CMD, "Exception Catch: Secure: %s, Non-Secure: %s", sec, nsec); return ERROR_OK; } @@ -1083,7 +1083,7 @@ int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache) { if (armv8_cache->info == -1) { - command_print(cmd->ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } diff --git a/src/target/armv8_cache.c b/src/target/armv8_cache.c index a641d04ab..41c85c9ab 100644 --- a/src/target/armv8_cache.c +++ b/src/target/armv8_cache.c @@ -194,7 +194,7 @@ static int armv8_handle_inner_cache_info_command(struct command_invocation *cmd, int cl; if (armv8_cache->info == -1) { - command_print(cmd->ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } @@ -202,7 +202,7 @@ static int armv8_handle_inner_cache_info_command(struct command_invocation *cmd, struct armv8_arch_cache *arch = &(armv8_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd->ctx, + command_print(cmd, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -215,7 +215,7 @@ static int armv8_handle_inner_cache_info_command(struct command_invocation *cmd, } if (arch->ctype >= 2) { - command_print(cmd->ctx, + command_print(cmd, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 5d1d42af9..9fc265288 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -2969,7 +2969,7 @@ COMMAND_HANDLER(handle_cortex_a_mask_interrupts_command) } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_a->isrmasking_mode); - command_print(CMD_CTX, "cortex_a interrupt mask %s", n->name); + command_print(CMD, "cortex_a interrupt mask %s", n->name); return ERROR_OK; } @@ -2995,7 +2995,7 @@ COMMAND_HANDLER(handle_cortex_a_dacrfixup_command) } n = Jim_Nvp_value2name_simple(nvp_dacrfixup_modes, cortex_a->dacrfixup_mode); - command_print(CMD_CTX, "cortex_a domain access control fixup %s", n->name); + command_print(CMD, "cortex_a domain access control fixup %s", n->name); return ERROR_OK; } diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 639e09f7e..fba832c78 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2370,7 +2370,7 @@ static int cortex_m_verify_pointer(struct command_invocation *cmd, struct cortex_m_common *cm) { if (cm->common_magic != CORTEX_M_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not a Cortex-M"); + command_print(cmd, "target is not a Cortex-M"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -2459,7 +2459,7 @@ write: } for (unsigned i = 0; i < ARRAY_SIZE(vec_ids); i++) { - command_print(CMD_CTX, "%9s: %s", vec_ids[i].name, + command_print(CMD, "%9s: %s", vec_ids[i].name, (demcr & vec_ids[i].mask) ? "catch" : "ignore"); } @@ -2487,7 +2487,7 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -2500,7 +2500,7 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_m->isrmasking_mode); - command_print(CMD_CTX, "cortex_m interrupt mask %s", n->name); + command_print(CMD, "cortex_m interrupt mask %s", n->name); return ERROR_OK; } @@ -2545,7 +2545,7 @@ COMMAND_HANDLER(handle_cortex_m_reset_config_command) break; } - command_print(CMD_CTX, "cortex_m reset_config %s", reset_config); + command_print(CMD, "cortex_m reset_config %s", reset_config); return ERROR_OK; } diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index 28fb8594d..d8285e49c 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -1930,7 +1930,7 @@ static void handle_md_output(struct command_invocation *cmd, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd->ctx, "%s", output); + command_print(cmd, "%s", output); output_len = 0; } } diff --git a/src/target/esirisc.c b/src/target/esirisc.c index 3d2954fac..c928445cc 100644 --- a/src/target/esirisc.c +++ b/src/target/esirisc.c @@ -1680,7 +1680,7 @@ COMMAND_HANDLER(handle_esirisc_cache_arch_command) } } - command_print(CMD_CTX, "esirisc cache_arch %s", esirisc_cache_arch_name(esirisc)); + command_print(CMD, "esirisc cache_arch %s", esirisc_cache_arch_name(esirisc)); return ERROR_OK; } @@ -1698,7 +1698,7 @@ COMMAND_HANDLER(handle_esirisc_flush_caches_command) retval = esirisc_flush_caches(target); - command_print(CMD_CTX, "cache flush %s", + command_print(CMD, "cache flush %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; @@ -1748,7 +1748,7 @@ COMMAND_HANDLER(handle_esirisc_hwdc_command) } for (size_t i = 0; i < ARRAY_SIZE(esirisc_hwdc_masks); ++i) - command_print(CMD_CTX, "%9s: %s", esirisc_hwdc_masks[i].name, + command_print(CMD, "%9s: %s", esirisc_hwdc_masks[i].name, (esirisc->hwdc_save & esirisc_hwdc_masks[i].mask) ? "enabled" : "disabled"); return ERROR_OK; diff --git a/src/target/esirisc_trace.c b/src/target/esirisc_trace.c index d07a0da9c..6a7d5a29d 100644 --- a/src/target/esirisc_trace.c +++ b/src/target/esirisc_trace.c @@ -403,7 +403,7 @@ static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *b case ESIRISC_TRACE_ID_EXECUTE: case ESIRISC_TRACE_ID_STALL: case ESIRISC_TRACE_ID_BRANCH: - command_print(cmd->ctx, "%s", esirisc_trace_id_strings[id]); + command_print(cmd, "%s", esirisc_trace_id_strings[id]); break; case ESIRISC_TRACE_ID_EXTENDED: { @@ -417,7 +417,7 @@ static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *b case ESIRISC_TRACE_EXT_ID_STOP: case ESIRISC_TRACE_EXT_ID_WAIT: case ESIRISC_TRACE_EXT_ID_MULTICYCLE: - command_print(cmd->ctx, "%s", esirisc_trace_ext_id_strings[ext_id]); + command_print(cmd, "%s", esirisc_trace_ext_id_strings[ext_id]); break; case ESIRISC_TRACE_EXT_ID_ERET: @@ -430,11 +430,11 @@ static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *b if (retval != ERROR_OK) goto fail; - command_print(cmd->ctx, "%s PC: 0x%" PRIx32, + command_print(cmd, "%s PC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], pc); if (ext_id == ESIRISC_TRACE_EXT_ID_END_PC) { - command_print(cmd->ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; } break; @@ -450,7 +450,7 @@ static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *b if (retval != ERROR_OK) goto fail; - command_print(cmd->ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, + command_print(cmd, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], eid, epc); break; } @@ -461,28 +461,28 @@ static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *b if (retval != ERROR_OK) goto fail; - command_print(cmd->ctx, "repeats %" PRId32 " %s", count, + command_print(cmd, "repeats %" PRId32 " %s", count, (count == 1) ? "time" : "times"); break; } case ESIRISC_TRACE_EXT_ID_END: - command_print(cmd->ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; default: - command_print(cmd->ctx, "invalid extended trace ID: %" PRId32, ext_id); + command_print(cmd, "invalid extended trace ID: %" PRId32, ext_id); return ERROR_FAIL; } break; } default: - command_print(cmd->ctx, "invalid trace ID: %" PRId32, id); + command_print(cmd, "invalid trace ID: %" PRId32, id); return ERROR_FAIL; } } fail: - command_print(cmd->ctx, "trace buffer too small"); + command_print(cmd, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } @@ -504,14 +504,14 @@ static int esirisc_trace_analyze_simple(struct command_invocation *cmd, uint8_t break; if (pc == end_of_trace) { - command_print(cmd->ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; } - command_print(cmd->ctx, "PC: 0x%" PRIx32, pc); + command_print(cmd, "PC: 0x%" PRIx32, pc); } - command_print(cmd->ctx, "trace buffer too small"); + command_print(cmd, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } @@ -523,19 +523,19 @@ static int esirisc_trace_analyze(struct command_invocation *cmd, uint8_t *buffer switch (trace_info->format) { case ESIRISC_TRACE_FORMAT_FULL: - command_print(cmd->ctx, "--- full pipeline ---"); + command_print(cmd, "--- full pipeline ---"); return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_BRANCH: - command_print(cmd->ctx, "--- branches taken ---"); + command_print(cmd, "--- branches taken ---"); return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_ICACHE: - command_print(cmd->ctx, "--- icache misses ---"); + command_print(cmd, "--- icache misses ---"); return esirisc_trace_analyze_simple(cmd, buffer, size); default: - command_print(cmd->ctx, "invalid trace format: %i", trace_info->format); + command_print(cmd, "invalid trace format: %i", trace_info->format); return ERROR_FAIL; } } @@ -552,7 +552,7 @@ static int esirisc_trace_analyze_buffer(struct command_invocation *cmd) size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd->ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -577,7 +577,7 @@ static int esirisc_trace_analyze_memory(struct command_invocation *cmd, buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd->ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -602,15 +602,15 @@ static int esirisc_trace_dump(struct command_invocation *cmd, const char *filena retval = fileio_open(&fileio, filename, FILEIO_WRITE, FILEIO_BINARY); if (retval != ERROR_OK) { - command_print(cmd->ctx, "could not open dump file: %s", filename); + command_print(cmd, "could not open dump file: %s", filename); return retval; } retval = fileio_write(fileio, size, buffer, &size_written); if (retval == ERROR_OK) - command_print(cmd->ctx, "trace data dumped to: %s", filename); + command_print(cmd, "trace data dumped to: %s", filename); else - command_print(cmd->ctx, "could not write dump file: %s", filename); + command_print(cmd, "could not write dump file: %s", filename); fileio_close(fileio); @@ -629,7 +629,7 @@ static int esirisc_trace_dump_buffer(struct command_invocation *cmd, const char size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd->ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -654,7 +654,7 @@ static int esirisc_trace_dump_memory(struct command_invocation *cmd, const char buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd->ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -676,13 +676,13 @@ COMMAND_HANDLER(handle_esirisc_trace_init_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_init(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace initialized"); + command_print(CMD, "trace initialized"); return retval; } @@ -694,42 +694,42 @@ COMMAND_HANDLER(handle_esirisc_trace_info_command) struct esirisc_trace *trace_info = &esirisc->trace_info; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } if (esirisc_trace_is_fifo(trace_info)) - command_print(CMD_CTX, "trace FIFO address: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace FIFO address: 0x%" TARGET_PRIxADDR, trace_info->buffer_start); else { - command_print(CMD_CTX, "trace buffer start: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace buffer start: 0x%" TARGET_PRIxADDR, trace_info->buffer_start); - command_print(CMD_CTX, "trace buffer end: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace buffer end: 0x%" TARGET_PRIxADDR, trace_info->buffer_end); - command_print(CMD_CTX, "trace buffer will %swrap", + command_print(CMD, "trace buffer will %swrap", trace_info->buffer_wrap ? "" : "not "); } - command_print(CMD_CTX, "flow control: %s", + command_print(CMD, "flow control: %s", trace_info->flow_control ? "enabled" : "disabled"); - command_print(CMD_CTX, "trace format: %s", + command_print(CMD, "trace format: %s", esirisc_trace_format_strings[trace_info->format]); - command_print(CMD_CTX, "number of PC bits: %i", trace_info->pc_bits); + command_print(CMD, "number of PC bits: %i", trace_info->pc_bits); - command_print(CMD_CTX, "start trigger: %s", + command_print(CMD, "start trigger: %s", esirisc_trace_trigger_strings[trace_info->start_trigger]); - command_print(CMD_CTX, "start data: 0x%" PRIx32, trace_info->start_data); - command_print(CMD_CTX, "start mask: 0x%" PRIx32, trace_info->start_mask); + command_print(CMD, "start data: 0x%" PRIx32, trace_info->start_data); + command_print(CMD, "start mask: 0x%" PRIx32, trace_info->start_mask); - command_print(CMD_CTX, "stop trigger: %s", + command_print(CMD, "stop trigger: %s", esirisc_trace_trigger_strings[trace_info->stop_trigger]); - command_print(CMD_CTX, "stop data: 0x%" PRIx32, trace_info->stop_data); - command_print(CMD_CTX, "stop mask: 0x%" PRIx32, trace_info->stop_mask); + command_print(CMD, "stop data: 0x%" PRIx32, trace_info->stop_data); + command_print(CMD, "stop mask: 0x%" PRIx32, trace_info->stop_mask); - command_print(CMD_CTX, "trigger delay: %s", + command_print(CMD, "trigger delay: %s", esirisc_trace_delay_strings[trace_info->delay]); - command_print(CMD_CTX, "trigger delay cycles: %i", trace_info->delay_cycles); + command_print(CMD, "trigger delay cycles: %i", trace_info->delay_cycles); return ERROR_OK; } @@ -741,7 +741,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command) uint32_t status; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -749,7 +749,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "trace is %s%s%s%s", + command_print(CMD, "trace is %s%s%s%s", (status & STATUS_T) ? "started" : "stopped", (status & STATUS_TD) ? ", disabled" : "", (status & STATUS_W) ? ", wrapped" : "", @@ -764,13 +764,13 @@ COMMAND_HANDLER(handle_esirisc_trace_start_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_start(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace started"); + command_print(CMD, "trace started"); return retval; } @@ -781,13 +781,13 @@ COMMAND_HANDLER(handle_esirisc_trace_stop_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_stop(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace stopped"); + command_print(CMD, "trace stopped"); return retval; } @@ -801,7 +801,7 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command) uint32_t size; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -817,7 +817,7 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command) * as arguments as a workaround. */ if (esirisc_trace_is_fifo(trace_info)) { - command_print(CMD_CTX, "analyze from FIFO not supported"); + command_print(CMD, "analyze from FIFO not supported"); return ERROR_FAIL; } @@ -839,7 +839,7 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command) uint32_t size; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -849,7 +849,7 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command) if (CMD_ARGC == 1) { /* also see: handle_esirisc_trace_analyze_command() */ if (esirisc_trace_is_fifo(trace_info)) { - command_print(CMD_CTX, "dump from FIFO not supported"); + command_print(CMD, "dump from FIFO not supported"); return ERROR_FAIL; } @@ -946,7 +946,7 @@ COMMAND_HANDLER(handle_esirisc_trace_format_command) COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], pc_bits); if (pc_bits < 1 || pc_bits > 31) { - command_print(CMD_CTX, "invalid pc_bits: %i; must be 1..31", pc_bits); + command_print(CMD, "invalid pc_bits: %i; must be 1..31", pc_bits); return ERROR_COMMAND_SYNTAX_ERROR; } diff --git a/src/target/etb.c b/src/target/etb.c index 7cd8b6cd5..392c6ad7f 100644 --- a/src/target/etb.c +++ b/src/target/etb.c @@ -344,13 +344,13 @@ COMMAND_HANDLER(handle_etb_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETB: '%s' isn't an ARM", CMD_ARGV[0]); + command_print(CMD, "ETB: '%s' isn't an ARM", CMD_ARGV[0]); return ERROR_FAIL; } tap = jtag_tap_by_string(CMD_ARGV[1]); if (tap == NULL) { - command_print(CMD_CTX, "ETB: TAP %s does not exist", CMD_ARGV[1]); + command_print(CMD, "ETB: TAP %s does not exist", CMD_ARGV[1]); return ERROR_FAIL; } @@ -382,17 +382,17 @@ COMMAND_HANDLER(handle_etb_trigger_percent_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETB: current target isn't an ARM"); + command_print(CMD, "ETB: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "ETB: target has no ETM configured"); + command_print(CMD, "ETB: target has no ETM configured"); return ERROR_FAIL; } if (etm->capture_driver != &etb_capture_driver) { - command_print(CMD_CTX, "ETB: target not using ETB"); + command_print(CMD, "ETB: target not using ETB"); return ERROR_FAIL; } etb = arm->etm->capture_driver_priv; @@ -402,13 +402,13 @@ COMMAND_HANDLER(handle_etb_trigger_percent_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], new_value); if ((new_value < 2) || (new_value > 100)) - command_print(CMD_CTX, + command_print(CMD, "valid percentages are 2%% to 100%%"); else etb->trigger_percent = (unsigned) new_value; } - command_print(CMD_CTX, "%d percent of tracebuffer fills after trigger", + command_print(CMD, "%d percent of tracebuffer fills after trigger", etb->trigger_percent); return ERROR_OK; diff --git a/src/target/etm.c b/src/target/etm.c index 4c95626f9..5751348e7 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -869,7 +869,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio ctx->capture_driver->read_trace(ctx); if (ctx->trace_depth == 0) { - command_print(cmd->ctx, "Trace is empty."); + command_print(cmd, "Trace is empty."); return ERROR_OK; } @@ -893,7 +893,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio int current_pc_ok = ctx->pc_ok; if (ctx->trace_data[ctx->pipe_index].flags & ETMV1_TRIGGER_CYCLE) - command_print(cmd->ctx, "--- trigger ---"); + command_print(cmd, "--- trigger ---"); /* instructions execute in IE/D or BE/D cycles */ if ((pipestat == STAT_IE) || (pipestat == STAT_ID)) @@ -942,7 +942,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio next_pc = ctx->last_branch; break; case 0x1: /* tracing enabled */ - command_print(cmd->ctx, + command_print(cmd, "--- tracing enabled at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -950,7 +950,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio continue; break; case 0x2: /* trace restarted after FIFO overflow */ - command_print(cmd->ctx, + command_print(cmd, "--- trace restarted after FIFO overflow at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -958,7 +958,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio continue; break; case 0x3: /* exit from debug state */ - command_print(cmd->ctx, + command_print(cmd, "--- exit from debug state at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -971,7 +971,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio * we have to move on with the next trace cycle */ if (!current_pc_ok) { - command_print(cmd->ctx, + command_print(cmd, "--- periodic synchronization point at 0x%8.8" PRIx32 " ---", next_pc); ctx->current_pc = next_pc; @@ -998,9 +998,9 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio || ((ctx->last_branch >= 0xffff0000) && (ctx->last_branch <= 0xffff0020))) { if ((ctx->last_branch & 0xff) == 0x10) - command_print(cmd->ctx, "data abort"); + command_print(cmd, "data abort"); else { - command_print(cmd->ctx, + command_print(cmd, "exception vector 0x%2.2" PRIx32 "", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -1058,7 +1058,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio ctx->ptr_ok = 1; if (ctx->ptr_ok) - command_print(cmd->ctx, + command_print(cmd, "address: 0x%8.8" PRIx32 "", ctx->last_ptr); } @@ -1073,7 +1073,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio uint32_t data; if (etmv1_data(ctx, 4, &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd->ctx, + command_print(cmd, "data: 0x%8.8" PRIx32 "", data); } @@ -1084,7 +1084,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio if (etmv1_data(ctx, arm_access_size(&instruction), &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd->ctx, "data: 0x%8.8" PRIx32 "", data); + command_print(cmd, "data: 0x%8.8" PRIx32 "", data); } } @@ -1119,7 +1119,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio (cycles == 1) ? "cycle" : "cycles"); } - command_print(cmd->ctx, "%s%s%s", + command_print(cmd, "%s%s%s", instruction.text, (pipestat == STAT_IN) ? " (not executed)" : "", cycles_text); @@ -1156,7 +1156,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update, else if (strcmp(CMD_ARGV[0], "all") == 0) tracemode = ETM_CTRL_TRACE_DATA | ETM_CTRL_TRACE_ADDR; else { - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[0]); + command_print(CMD, "invalid option '%s'", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1176,7 +1176,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update, tracemode |= ETM_CTRL_CONTEXTID_32; break; default: - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[1]); + command_print(CMD, "invalid option '%s'", CMD_ARGV[1]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1207,13 +1207,13 @@ COMMAND_HANDLER(handle_etm_tracemode_command) struct etm_context *etm; if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1235,47 +1235,47 @@ COMMAND_HANDLER(handle_etm_tracemode_command) * or couldn't be written; display actual hardware state... */ - command_print(CMD_CTX, "current tracemode configuration:"); + command_print(CMD, "current tracemode configuration:"); switch (tracemode & ETM_CTRL_TRACE_MASK) { default: - command_print(CMD_CTX, "data tracing: none"); + command_print(CMD, "data tracing: none"); break; case ETM_CTRL_TRACE_DATA: - command_print(CMD_CTX, "data tracing: data only"); + command_print(CMD, "data tracing: data only"); break; case ETM_CTRL_TRACE_ADDR: - command_print(CMD_CTX, "data tracing: address only"); + command_print(CMD, "data tracing: address only"); break; case ETM_CTRL_TRACE_DATA | ETM_CTRL_TRACE_ADDR: - command_print(CMD_CTX, "data tracing: address and data"); + command_print(CMD, "data tracing: address and data"); break; } switch (tracemode & ETM_CTRL_CONTEXTID_MASK) { case ETM_CTRL_CONTEXTID_NONE: - command_print(CMD_CTX, "contextid tracing: none"); + command_print(CMD, "contextid tracing: none"); break; case ETM_CTRL_CONTEXTID_8: - command_print(CMD_CTX, "contextid tracing: 8 bit"); + command_print(CMD, "contextid tracing: 8 bit"); break; case ETM_CTRL_CONTEXTID_16: - command_print(CMD_CTX, "contextid tracing: 16 bit"); + command_print(CMD, "contextid tracing: 16 bit"); break; case ETM_CTRL_CONTEXTID_32: - command_print(CMD_CTX, "contextid tracing: 32 bit"); + command_print(CMD, "contextid tracing: 32 bit"); break; } if (tracemode & ETM_CTRL_CYCLE_ACCURATE) - command_print(CMD_CTX, "cycle-accurate tracing enabled"); + command_print(CMD, "cycle-accurate tracing enabled"); else - command_print(CMD_CTX, "cycle-accurate tracing disabled"); + command_print(CMD, "cycle-accurate tracing disabled"); if (tracemode & ETM_CTRL_BRANCH_OUTPUT) - command_print(CMD_CTX, "full branch address output enabled"); + command_print(CMD, "full branch address output enabled"); else - command_print(CMD_CTX, "full branch address output disabled"); + command_print(CMD, "full branch address output disabled"); #define TRACEMODE_MASK ( \ ETM_CTRL_CONTEXTID_MASK \ @@ -1331,7 +1331,7 @@ COMMAND_HANDLER(handle_etm_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "target '%s' is '%s'; not an ARM", + command_print(CMD, "target '%s' is '%s'; not an ARM", target_name(target), target_type_name(target)); return ERROR_FAIL; @@ -1382,7 +1382,7 @@ COMMAND_HANDLER(handle_etm_config_command) portmode |= ETM_PORT_2BIT; break; default: - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port width '%s'", CMD_ARGV[1]); return ERROR_FAIL; } @@ -1394,7 +1394,7 @@ COMMAND_HANDLER(handle_etm_config_command) else if (strcmp("demultiplexed", CMD_ARGV[2]) == 0) portmode |= ETM_PORT_DEMUXED; else { - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port mode '%s', must be 'normal', 'multiplexed' or 'demultiplexed'", CMD_ARGV[2]); return ERROR_FAIL; @@ -1405,7 +1405,7 @@ COMMAND_HANDLER(handle_etm_config_command) else if (strcmp("full", CMD_ARGV[3]) == 0) portmode |= ETM_PORT_FULL_CLOCK; else { - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port clocking '%s', must be 'full' or 'half'", CMD_ARGV[3]); return ERROR_FAIL; @@ -1461,44 +1461,44 @@ COMMAND_HANDLER(handle_etm_info_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } - command_print(CMD_CTX, "ETM v%d.%d", + command_print(CMD, "ETM v%d.%d", etm->bcd_vers >> 4, etm->bcd_vers & 0xf); - command_print(CMD_CTX, "pairs of address comparators: %i", + command_print(CMD, "pairs of address comparators: %i", (int) (etm->config >> 0) & 0x0f); - command_print(CMD_CTX, "data comparators: %i", + command_print(CMD, "data comparators: %i", (int) (etm->config >> 4) & 0x0f); - command_print(CMD_CTX, "memory map decoders: %i", + command_print(CMD, "memory map decoders: %i", (int) (etm->config >> 8) & 0x1f); - command_print(CMD_CTX, "number of counters: %i", + command_print(CMD, "number of counters: %i", (int) (etm->config >> 13) & 0x07); - command_print(CMD_CTX, "sequencer %spresent", + command_print(CMD, "sequencer %spresent", (int) (etm->config & (1 << 16)) ? "" : "not "); - command_print(CMD_CTX, "number of ext. inputs: %i", + command_print(CMD, "number of ext. inputs: %i", (int) (etm->config >> 17) & 0x07); - command_print(CMD_CTX, "number of ext. outputs: %i", + command_print(CMD, "number of ext. outputs: %i", (int) (etm->config >> 20) & 0x07); - command_print(CMD_CTX, "FIFO full %spresent", + command_print(CMD, "FIFO full %spresent", (int) (etm->config & (1 << 23)) ? "" : "not "); if (etm->bcd_vers < 0x20) - command_print(CMD_CTX, "protocol version: %i", + command_print(CMD, "protocol version: %i", (int) (etm->config >> 28) & 0x07); else { - command_print(CMD_CTX, + command_print(CMD, "coprocessor and memory access %ssupported", (etm->config & (1 << 26)) ? "" : "not "); - command_print(CMD_CTX, "trace start/stop %spresent", + command_print(CMD, "trace start/stop %spresent", (etm->config & (1 << 26)) ? "" : "not "); - command_print(CMD_CTX, "number of context comparators: %i", + command_print(CMD, "number of context comparators: %i", (int) (etm->config >> 24) & 0x03); } @@ -1549,30 +1549,30 @@ COMMAND_HANDLER(handle_etm_info_command) LOG_ERROR("Illegal max_port_size"); return ERROR_FAIL; } - command_print(CMD_CTX, "max. port size: %i", max_port_size); + command_print(CMD, "max. port size: %i", max_port_size); if (etm->bcd_vers < 0x30) { - command_print(CMD_CTX, "half-rate clocking %ssupported", + command_print(CMD, "half-rate clocking %ssupported", (config & (1 << 3)) ? "" : "not "); - command_print(CMD_CTX, "full-rate clocking %ssupported", + command_print(CMD, "full-rate clocking %ssupported", (config & (1 << 4)) ? "" : "not "); - command_print(CMD_CTX, "normal trace format %ssupported", + command_print(CMD, "normal trace format %ssupported", (config & (1 << 5)) ? "" : "not "); - command_print(CMD_CTX, "multiplex trace format %ssupported", + command_print(CMD, "multiplex trace format %ssupported", (config & (1 << 6)) ? "" : "not "); - command_print(CMD_CTX, "demultiplex trace format %ssupported", + command_print(CMD, "demultiplex trace format %ssupported", (config & (1 << 7)) ? "" : "not "); } else { /* REVISIT show which size and format are selected ... */ - command_print(CMD_CTX, "current port size %ssupported", + command_print(CMD, "current port size %ssupported", (config & (1 << 10)) ? "" : "not "); - command_print(CMD_CTX, "current trace format %ssupported", + command_print(CMD, "current trace format %ssupported", (config & (1 << 11)) ? "" : "not "); } if (etm->bcd_vers >= 0x21) - command_print(CMD_CTX, "fetch comparisons %ssupported", + command_print(CMD, "fetch comparisons %ssupported", (config & (1 << 17)) ? "not " : ""); - command_print(CMD_CTX, "FIFO full %ssupported", + command_print(CMD, "FIFO full %ssupported", (config & (1 << 8)) ? "" : "not "); return ERROR_OK; @@ -1588,13 +1588,13 @@ COMMAND_HANDLER(handle_etm_status_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1608,7 +1608,7 @@ COMMAND_HANDLER(handle_etm_status_command) if (etm_get_reg(reg) == ERROR_OK) { unsigned s = buf_get_u32(reg->value, 0, reg->size); - command_print(CMD_CTX, "etm: %s%s%s%s", + command_print(CMD, "etm: %s%s%s%s", /* bit(1) == progbit */ (etm->bcd_vers >= 0x12) ? ((s & (1 << 1)) @@ -1626,21 +1626,21 @@ COMMAND_HANDLER(handle_etm_status_command) /* Trace Port Driver status */ trace_status = etm->capture_driver->status(etm); if (trace_status == TRACE_IDLE) - command_print(CMD_CTX, "%s: idle", etm->capture_driver->name); + command_print(CMD, "%s: idle", etm->capture_driver->name); else { static char *completed = " completed"; static char *running = " is running"; static char *overflowed = ", overflowed"; static char *triggered = ", triggered"; - command_print(CMD_CTX, "%s: trace collection%s%s%s", + command_print(CMD, "%s: trace collection%s%s%s", etm->capture_driver->name, (trace_status & TRACE_RUNNING) ? running : completed, (trace_status & TRACE_OVERFLOWED) ? overflowed : "", (trace_status & TRACE_TRIGGERED) ? triggered : ""); if (etm->trace_depth > 0) { - command_print(CMD_CTX, "%i frames of trace data read", + command_print(CMD, "%i frames of trace data read", (int)(etm->trace_depth)); } } @@ -1660,20 +1660,20 @@ COMMAND_HANDLER(handle_etm_image_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->image) { image_close(etm_ctx->image); free(etm_ctx->image); - command_print(CMD_CTX, "previously loaded image found and closed"); + command_print(CMD, "previously loaded image found and closed"); } etm_ctx->image = malloc(sizeof(struct image)); @@ -1711,24 +1711,24 @@ COMMAND_HANDLER(handle_etm_dump_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->capture_driver->status == TRACE_IDLE) { - command_print(CMD_CTX, "trace capture wasn't enabled, no trace data captured"); + command_print(CMD, "trace capture wasn't enabled, no trace data captured"); return ERROR_OK; } if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING) { /* TODO: if on-the-fly capture is to be supported, this needs to be changed */ - command_print(CMD_CTX, "trace capture not completed"); + command_print(CMD, "trace capture not completed"); return ERROR_FAIL; } @@ -1768,18 +1768,18 @@ COMMAND_HANDLER(handle_etm_load_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING) { - command_print(CMD_CTX, "trace capture running, stop first"); + command_print(CMD, "trace capture running, stop first"); return ERROR_FAIL; } @@ -1794,7 +1794,7 @@ COMMAND_HANDLER(handle_etm_load_command) } if (filesize % 4) { - command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data"); + command_print(CMD, "size isn't a multiple of 4, no valid trace data"); fileio_close(file); return ERROR_FAIL; } @@ -1812,7 +1812,7 @@ COMMAND_HANDLER(handle_etm_load_command) } etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth); if (etm_ctx->trace_data == NULL) { - command_print(CMD_CTX, "not enough memory to perform operation"); + command_print(CMD, "not enough memory to perform operation"); fileio_close(file); return ERROR_FAIL; } @@ -1842,13 +1842,13 @@ COMMAND_HANDLER(handle_etm_start_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1887,13 +1887,13 @@ COMMAND_HANDLER(handle_etm_stop_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1923,14 +1923,14 @@ COMMAND_HANDLER(handle_etm_trigger_debug_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: %s isn't an ARM", + command_print(CMD, "ETM: %s isn't an ARM", target_name(target)); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "ETM: no ETM configured for %s", + command_print(CMD, "ETM: no ETM configured for %s", target_name(target)); return ERROR_FAIL; } @@ -1955,7 +1955,7 @@ COMMAND_HANDLER(handle_etm_trigger_debug_command) buf_set_u32(etm_ctrl_reg->value, 0, 32, etm->control); } - command_print(CMD_CTX, "ETM: %s debug halt", + command_print(CMD, "ETM: %s debug halt", (etm->control & ETM_CTRL_DBGRQ) ? "triggers" : "does not trigger"); @@ -1972,13 +1972,13 @@ COMMAND_HANDLER(handle_etm_analyze_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1987,18 +1987,18 @@ COMMAND_HANDLER(handle_etm_analyze_command) /* FIX! error should be reported inside etmv1_analyze_trace() */ switch (retval) { case ERROR_ETM_ANALYSIS_FAILED: - command_print(CMD_CTX, + command_print(CMD, "further analysis failed (corrupted trace data or just end of data"); break; case ERROR_TRACE_INSTRUCTION_UNAVAILABLE: - command_print(CMD_CTX, + command_print(CMD, "no instruction for current address available, analysis aborted"); break; case ERROR_TRACE_IMAGE_UNAVAILABLE: - command_print(CMD_CTX, "no image available for trace analysis"); + command_print(CMD, "no image available for trace analysis"); break; default: - command_print(CMD_CTX, "unknown error"); + command_print(CMD, "unknown error"); } } diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c index 9f18d84a1..ba53c7a82 100644 --- a/src/target/etm_dummy.c +++ b/src/target/etm_dummy.c @@ -37,7 +37,7 @@ COMMAND_HANDLER(handle_etm_dummy_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "target '%s' isn't an ARM", CMD_ARGV[0]); + command_print(CMD, "target '%s' isn't an ARM", CMD_ARGV[0]); return ERROR_FAIL; } diff --git a/src/target/mips32.c b/src/target/mips32.c index 9cb24a447..526003216 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -909,7 +909,7 @@ static int mips32_verify_pointer(struct command_invocation *cmd, struct mips32_common *mips32) { if (mips32->common_magic != MIPS32_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not an MIPS32"); + command_print(cmd, "target is not an MIPS32"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -932,7 +932,7 @@ COMMAND_HANDLER(mips32_handle_cp0_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -949,12 +949,12 @@ COMMAND_HANDLER(mips32_handle_cp0_command) retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, cp0_reg); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } else if (CMD_ARGC == 3) { @@ -962,12 +962,12 @@ COMMAND_HANDLER(mips32_handle_cp0_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value); retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access cp0 reg %" PRIi32 ", select %" PRIi32, cp0_reg, cp0_sel); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } } @@ -986,13 +986,13 @@ COMMAND_HANDLER(mips32_handle_scan_delay_command) else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "scan delay: %d nsec", ejtag_info->scan_delay); + command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay); if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) { ejtag_info->mode = 0; - command_print(CMD_CTX, "running in legacy mode"); + command_print(CMD, "running in legacy mode"); } else { ejtag_info->mode = 1; - command_print(CMD_CTX, "running in fast queued mode"); + command_print(CMD, "running in fast queued mode"); } return ERROR_OK; diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 755ed72e6..ad27520c8 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -1274,7 +1274,7 @@ static int mips_m4k_verify_pointer(struct command_invocation *cmd, struct mips_m4k_common *mips_m4k) { if (mips_m4k->common_magic != MIPSM4K_COMMON_MAGIC) { - command_print(cmd->ctx, "target is not an MIPS_M4K"); + command_print(cmd, "target is not an MIPS_M4K"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -1292,7 +1292,7 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1308,12 +1308,12 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) uint32_t value; retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, cp0_reg); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } else if (CMD_ARGC == 3) { @@ -1321,12 +1321,12 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value); retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access cp0 reg %" PRIi32 ", select %" PRIi32, cp0_reg, cp0_sel); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } } @@ -1345,13 +1345,13 @@ COMMAND_HANDLER(mips_m4k_handle_scan_delay_command) else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "scan delay: %d nsec", ejtag_info->scan_delay); + command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay); if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) { ejtag_info->mode = 0; - command_print(CMD_CTX, "running in legacy mode"); + command_print(CMD, "running in legacy mode"); } else { ejtag_info->mode = 1; - command_print(CMD_CTX, "running in fast queued mode"); + command_print(CMD, "running in fast queued mode"); } return ERROR_OK; diff --git a/src/target/nds32_cmd.c b/src/target/nds32_cmd.c index 500651dbc..1accf6f83 100644 --- a/src/target/nds32_cmd.c +++ b/src/target/nds32_cmd.c @@ -46,7 +46,7 @@ COMMAND_HANDLER(handle_nds32_dssim_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -57,7 +57,7 @@ COMMAND_HANDLER(handle_nds32_dssim_command) nds32->step_isr_enable = false; } - command_print(CMD_CTX, "%s: $INT_MASK.DSSIM: %d", target_name(target), + command_print(CMD, "%s: $INT_MASK.DSSIM: %d", target_name(target), nds32->step_isr_enable); return ERROR_OK; @@ -71,7 +71,7 @@ COMMAND_HANDLER(handle_nds32_memory_access_command) struct nds32_memory *memory = &(nds32->memory); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -88,7 +88,7 @@ COMMAND_HANDLER(handle_nds32_memory_access_command) aice_memory_access(aice, memory->access_channel); } else { - command_print(CMD_CTX, "%s: memory access channel: %s", + command_print(CMD, "%s: memory access channel: %s", target_name(target), NDS_MEMORY_ACCESS_NAME[memory->access_channel]); } @@ -103,18 +103,18 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) struct aice_port_s *aice = target_to_aice(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (nds32->edm.access_control == false) { - command_print(CMD_CTX, "%s does not support ACC_CTL. " + command_print(CMD, "%s does not support ACC_CTL. " "Set memory mode to MEMORY", target_name(target)); nds32->memory.mode = NDS_MEMORY_SELECT_MEM; } else if (nds32->edm.direct_access_local_memory == false) { - command_print(CMD_CTX, "%s does not support direct access " + command_print(CMD, "%s does not support direct access " "local memory. Set memory mode to MEMORY", target_name(target)); nds32->memory.mode = NDS_MEMORY_SELECT_MEM; @@ -128,13 +128,13 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) nds32->memory.mode = NDS_MEMORY_SELECT_MEM; } else if (strcmp(CMD_ARGV[0], "ilm") == 0) { if (nds32->memory.ilm_base == 0) - command_print(CMD_CTX, "%s does not support ILM", + command_print(CMD, "%s does not support ILM", target_name(target)); else nds32->memory.mode = NDS_MEMORY_SELECT_ILM; } else if (strcmp(CMD_ARGV[0], "dlm") == 0) { if (nds32->memory.dlm_base == 0) - command_print(CMD_CTX, "%s does not support DLM", + command_print(CMD, "%s does not support DLM", target_name(target)); else nds32->memory.mode = NDS_MEMORY_SELECT_DLM; @@ -145,7 +145,7 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) } } - command_print(CMD_CTX, "%s: memory mode: %s", + command_print(CMD, "%s: memory mode: %s", target_name(target), NDS_MEMORY_SELECT_NAME[nds32->memory.mode]); @@ -162,7 +162,7 @@ COMMAND_HANDLER(handle_nds32_cache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -173,30 +173,30 @@ COMMAND_HANDLER(handle_nds32_cache_command) /* D$ write back */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Write back data cache...failed", + command_print(CMD, "%s: Write back data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Write back data cache...done", + command_print(CMD, "%s: Write back data cache...done", target_name(target)); /* D$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate data cache...failed", + command_print(CMD, "%s: Invalidate data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate data cache...done", + command_print(CMD, "%s: Invalidate data cache...done", target_name(target)); } else { if (dcache->line_size == 0) - command_print(CMD_CTX, "%s: No data cache", + command_print(CMD, "%s: No data cache", target_name(target)); else - command_print(CMD_CTX, "%s: Data cache disabled", + command_print(CMD, "%s: Data cache disabled", target_name(target)); } @@ -204,23 +204,23 @@ COMMAND_HANDLER(handle_nds32_cache_command) /* I$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate instruction cache...failed", + command_print(CMD, "%s: Invalidate instruction cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate instruction cache...done", + command_print(CMD, "%s: Invalidate instruction cache...done", target_name(target)); } else { if (icache->line_size == 0) - command_print(CMD_CTX, "%s: No instruction cache", + command_print(CMD, "%s: No instruction cache", target_name(target)); else - command_print(CMD_CTX, "%s: Instruction cache disabled", + command_print(CMD, "%s: Instruction cache disabled", target_name(target)); } } else - command_print(CMD_CTX, "No valid parameter"); + command_print(CMD, "No valid parameter"); } return ERROR_OK; @@ -235,14 +235,14 @@ COMMAND_HANDLER(handle_nds32_icache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (icache->line_size == 0) { - command_print(CMD_CTX, "%s: No instruction cache", + command_print(CMD, "%s: No instruction cache", target_name(target)); return ERROR_OK; } @@ -252,15 +252,15 @@ COMMAND_HANDLER(handle_nds32_icache_command) /* I$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate instruction cache...failed", + command_print(CMD, "%s: Invalidate instruction cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate instruction cache...done", + command_print(CMD, "%s: Invalidate instruction cache...done", target_name(target)); } else { - command_print(CMD_CTX, "%s: Instruction cache disabled", + command_print(CMD, "%s: Instruction cache disabled", target_name(target)); } } else if (strcmp(CMD_ARGV[0], "enable") == 0) { @@ -274,7 +274,7 @@ COMMAND_HANDLER(handle_nds32_icache_command) } else if (strcmp(CMD_ARGV[0], "dump") == 0) { /* TODO: dump cache content */ } else { - command_print(CMD_CTX, "%s: No valid parameter", target_name(target)); + command_print(CMD, "%s: No valid parameter", target_name(target)); } } @@ -290,14 +290,14 @@ COMMAND_HANDLER(handle_nds32_dcache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (dcache->line_size == 0) { - command_print(CMD_CTX, "%s: No data cache", target_name(target)); + command_print(CMD, "%s: No data cache", target_name(target)); return ERROR_OK; } @@ -306,26 +306,26 @@ COMMAND_HANDLER(handle_nds32_dcache_command) /* D$ write back */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Write back data cache...failed", + command_print(CMD, "%s: Write back data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Write back data cache...done", + command_print(CMD, "%s: Write back data cache...done", target_name(target)); /* D$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate data cache...failed", + command_print(CMD, "%s: Invalidate data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate data cache...done", + command_print(CMD, "%s: Invalidate data cache...done", target_name(target)); } else { - command_print(CMD_CTX, "%s: Data cache disabled", + command_print(CMD, "%s: Data cache disabled", target_name(target)); } } else if (strcmp(CMD_ARGV[0], "enable") == 0) { @@ -339,7 +339,7 @@ COMMAND_HANDLER(handle_nds32_dcache_command) } else if (strcmp(CMD_ARGV[0], "dump") == 0) { /* TODO: dump cache content */ } else { - command_print(CMD_CTX, "%s: No valid parameter", target_name(target)); + command_print(CMD, "%s: No valid parameter", target_name(target)); } } @@ -352,7 +352,7 @@ COMMAND_HANDLER(handle_nds32_auto_break_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -364,10 +364,10 @@ COMMAND_HANDLER(handle_nds32_auto_break_command) } if (nds32->auto_convert_hw_bp) - command_print(CMD_CTX, "%s: convert sw break to hw break on ROM: on", + command_print(CMD, "%s: convert sw break to hw break on ROM: on", target_name(target)); else - command_print(CMD_CTX, "%s: convert sw break to hw break on ROM: off", + command_print(CMD, "%s: convert sw break to hw break on ROM: off", target_name(target)); return ERROR_OK; @@ -379,7 +379,7 @@ COMMAND_HANDLER(handle_nds32_virtual_hosting_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -391,9 +391,9 @@ COMMAND_HANDLER(handle_nds32_virtual_hosting_command) } if (nds32->virtual_hosting) - command_print(CMD_CTX, "%s: virtual hosting: on", target_name(target)); + command_print(CMD, "%s: virtual hosting: on", target_name(target)); else - command_print(CMD_CTX, "%s: virtual hosting: off", target_name(target)); + command_print(CMD, "%s: virtual hosting: off", target_name(target)); return ERROR_OK; } @@ -404,7 +404,7 @@ COMMAND_HANDLER(handle_nds32_global_stop_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -429,7 +429,7 @@ COMMAND_HANDLER(handle_nds32_soft_reset_halt_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -454,7 +454,7 @@ COMMAND_HANDLER(handle_nds32_boot_time_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -470,7 +470,7 @@ COMMAND_HANDLER(handle_nds32_login_edm_passcode_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -485,7 +485,7 @@ COMMAND_HANDLER(handle_nds32_login_edm_operation_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -516,7 +516,7 @@ COMMAND_HANDLER(handle_nds32_reset_halt_as_init_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -536,7 +536,7 @@ COMMAND_HANDLER(handle_nds32_keep_target_edm_ctl_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -556,7 +556,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -581,7 +581,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) read_addr, &instruction)) return ERROR_FAIL; - command_print(CMD_CTX, "%s", instruction.text); + command_print(CMD, "%s", instruction.text); read_addr += instruction.instruction_size; i++; @@ -599,7 +599,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode, addr, &instruction)) return ERROR_FAIL; - command_print(CMD_CTX, "%s", instruction.text); + command_print(CMD, "%s", instruction.text); } else return ERROR_FAIL; @@ -612,7 +612,7 @@ COMMAND_HANDLER(handle_nds32_word_access_mem_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -632,11 +632,11 @@ COMMAND_HANDLER(handle_nds32_query_target_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } - command_print(CMD_CTX, "OCD"); + command_print(CMD, "OCD"); return ERROR_OK; } @@ -647,7 +647,7 @@ COMMAND_HANDLER(handle_nds32_query_endian_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -655,9 +655,9 @@ COMMAND_HANDLER(handle_nds32_query_endian_command) nds32_get_mapped_reg(nds32, IR0, &value_psw); if (value_psw & 0x20) - command_print(CMD_CTX, "%s: BE", target_name(target)); + command_print(CMD, "%s: BE", target_name(target)); else - command_print(CMD_CTX, "%s: LE", target_name(target)); + command_print(CMD, "%s: LE", target_name(target)); return ERROR_OK; } @@ -668,11 +668,11 @@ COMMAND_HANDLER(handle_nds32_query_cpuid_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } - command_print(CMD_CTX, "CPUID: %s", target_name(target)); + command_print(CMD, "CPUID: %s", target_name(target)); return ERROR_OK; } diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c index 627366d5d..f38916a0b 100644 --- a/src/target/oocd_trace.c +++ b/src/target/oocd_trace.c @@ -277,7 +277,7 @@ COMMAND_HANDLER(handle_oocd_trace_config_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } @@ -306,17 +306,17 @@ COMMAND_HANDLER(handle_oocd_trace_status_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (!arm->etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (strcmp(arm->etm->capture_driver->name, "oocd_trace") != 0) { - command_print(CMD_CTX, "current target's ETM capture driver isn't 'oocd_trace'"); + command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); return ERROR_FAIL; } @@ -325,9 +325,9 @@ COMMAND_HANDLER(handle_oocd_trace_status_command) oocd_trace_read_reg(oocd_trace, OOCD_TRACE_STATUS, &status); if (status & 0x8) - command_print(CMD_CTX, "trace clock locked"); + command_print(CMD, "trace clock locked"); else - command_print(CMD_CTX, "no trace clock"); + command_print(CMD, "no trace clock"); return ERROR_OK; } @@ -344,17 +344,17 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (!arm->etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (strcmp(arm->etm->capture_driver->name, "oocd_trace") != 0) { - command_print(CMD_CTX, "current target's ETM capture driver isn't 'oocd_trace'"); + command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); return ERROR_FAIL; } @@ -366,7 +366,7 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command) if (bytes_written < 1) return ERROR_FAIL; - command_print(CMD_CTX, "requesting traceclock resync"); + command_print(CMD, "requesting traceclock resync"); LOG_DEBUG("resyncing traceclk pll"); return ERROR_OK; diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c index 1cecebd30..1e5db8c61 100644 --- a/src/target/openrisc/or1k.c +++ b/src/target/openrisc/or1k.c @@ -1291,7 +1291,7 @@ COMMAND_HANDLER(or1k_tap_list_command_handler) list_for_each_entry(or1k_tap, &tap_list, list) { if (or1k_tap->name) - command_print(CMD_CTX, "%s", or1k_tap->name); + command_print(CMD, "%s", or1k_tap->name); } return ERROR_OK; @@ -1339,7 +1339,7 @@ COMMAND_HANDLER(or1k_du_list_command_handler) list_for_each_entry(or1k_du, &du_list, list) { if (or1k_du->name) - command_print(CMD_CTX, "%s", or1k_du->name); + command_print(CMD, "%s", or1k_du->name); } return ERROR_OK; diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 44da5a9e6..8b5a361bb 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1623,7 +1623,7 @@ COMMAND_HANDLER(riscv_authdata_read) uint32_t value; if (r->authdata_read(target, &value) != ERROR_OK) return ERROR_FAIL; - command_print(CMD_CTX, "0x%" PRIx32, value); + command_print(CMD, "0x%" PRIx32, value); return ERROR_OK; } else { LOG_ERROR("authdata_read is not implemented for this target."); @@ -1676,7 +1676,7 @@ COMMAND_HANDLER(riscv_dmi_read) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); if (r->dmi_read(target, &value, address) != ERROR_OK) return ERROR_FAIL; - command_print(CMD_CTX, "0x%" PRIx32, value); + command_print(CMD, "0x%" PRIx32, value); return ERROR_OK; } else { LOG_ERROR("dmi_read is not implemented for this target."); diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index 59207897a..ce6a79171 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -1470,7 +1470,7 @@ __COMMAND_HANDLER(handle_common_semihosting_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } @@ -1493,7 +1493,7 @@ __COMMAND_HANDLER(handle_common_semihosting_command) semihosting->is_active = is_active; } - command_print(CMD_CTX, "semihosting is %s", + command_print(CMD, "semihosting is %s", semihosting->is_active ? "enabled" : "disabled"); @@ -1512,19 +1512,19 @@ __COMMAND_HANDLER(handle_common_semihosting_fileio_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } if (!semihosting->is_active) { - command_print(CMD_CTX, "semihosting not yet enabled for current target"); + command_print(CMD, "semihosting not yet enabled for current target"); return ERROR_FAIL; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], semihosting->is_fileio); - command_print(CMD_CTX, "semihosting fileio is %s", + command_print(CMD, "semihosting fileio is %s", semihosting->is_fileio ? "enabled" : "disabled"); @@ -1543,7 +1543,7 @@ __COMMAND_HANDLER(handle_common_semihosting_cmdline) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } @@ -1558,7 +1558,7 @@ __COMMAND_HANDLER(handle_common_semihosting_cmdline) semihosting->cmdline = cmdline; } - command_print(CMD_CTX, "semihosting command line is [%s]", + command_print(CMD, "semihosting command line is [%s]", semihosting->cmdline); return ERROR_OK; @@ -1575,19 +1575,19 @@ __COMMAND_HANDLER(handle_common_semihosting_resumable_exit_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } if (!semihosting->is_active) { - command_print(CMD_CTX, "semihosting not yet enabled for current target"); + command_print(CMD, "semihosting not yet enabled for current target"); return ERROR_FAIL; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], semihosting->has_resumable_exit); - command_print(CMD_CTX, "semihosting resumable exit is %s", + command_print(CMD, "semihosting resumable exit is %s", semihosting->has_resumable_exit ? "enabled" : "disabled"); diff --git a/src/target/smp.c b/src/target/smp.c index f42d8abed..acd4628e2 100644 --- a/src/target/smp.c +++ b/src/target/smp.c @@ -106,7 +106,7 @@ COMMAND_HANDLER(default_handle_smp_command) return ERROR_COMMAND_SYNTAX_ERROR; if (!CMD_ARGC) { - command_print(CMD_CTX, "%s", target->smp ? "on" : "off"); + command_print(CMD, "%s", target->smp ? "on" : "off"); return ERROR_OK; } @@ -166,7 +166,7 @@ COMMAND_HANDLER(handle_smp_gdb_command) target->gdb_service->core[1] = coreid; } - command_print(CMD_CTX, "gdb coreid %" PRId32 " -> %" PRId32, target->gdb_service->core[0] + command_print(CMD, "gdb coreid %" PRId32 " -> %" PRId32, target->gdb_service->core[0] , target->gdb_service->core[1]); } return ERROR_OK; diff --git a/src/target/stm8.c b/src/target/stm8.c index b62ff131d..fcfc1707e 100644 --- a/src/target/stm8.c +++ b/src/target/stm8.c @@ -2147,7 +2147,7 @@ COMMAND_HANDLER(stm8_handle_enable_step_irq_command) stm8->enable_step_irq = enable; } msg = stm8->enable_step_irq ? "enabled" : "disabled"; - command_print(CMD_CTX, "enable_step_irq = %s", msg); + command_print(CMD, "enable_step_irq = %s", msg); return ERROR_OK; } @@ -2163,7 +2163,7 @@ COMMAND_HANDLER(stm8_handle_enable_stm8l_command) stm8->enable_stm8l = enable; } msg = stm8->enable_stm8l ? "enabled" : "disabled"; - command_print(CMD_CTX, "enable_stm8l = %s", msg); + command_print(CMD, "enable_stm8l = %s", msg); stm8_init_flash_regs(stm8->enable_stm8l, stm8); return ERROR_OK; } diff --git a/src/target/target.c b/src/target/target.c index 58864ce2c..20bf26b5d 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -670,7 +670,7 @@ static int target_process_reset(struct command_invocation *cmd, enum target_rese if (retval != JIM_OK) { Jim_MakeErrorMessage(cmd->ctx->interp); - command_print(cmd->ctx, "%s", Jim_GetString(Jim_GetResult(cmd->ctx->interp), NULL)); + command_print(cmd, "%s", Jim_GetString(Jim_GetResult(cmd->ctx->interp), NULL)); return ERROR_FAIL; } @@ -2612,8 +2612,8 @@ COMMAND_HANDLER(handle_targets_command) } struct target *target = all_targets; - command_print(CMD_CTX, " TargetName Type Endian TapName State "); - command_print(CMD_CTX, "-- ------------------ ---------- ------ ------------------ ------------"); + command_print(CMD, " TargetName Type Endian TapName State "); + command_print(CMD, "-- ------------------ ---------- ------ ------------------ ------------"); while (target) { const char *state; char marker = ' '; @@ -2627,7 +2627,7 @@ COMMAND_HANDLER(handle_targets_command) marker = '*'; /* keep columns lined up to match the headers above */ - command_print(CMD_CTX, + command_print(CMD, "%2d%c %-18s %-10s %-6s %-18s %s", target->target_number, marker, @@ -2837,7 +2837,7 @@ COMMAND_HANDLER(handle_reg_command) while (cache) { unsigned i; - command_print(CMD_CTX, "===== %s", cache->name); + command_print(CMD, "===== %s", cache->name); for (i = 0, reg = cache->reg_list; i < cache->num_regs; @@ -2848,7 +2848,7 @@ COMMAND_HANDLER(handle_reg_command) if (reg->valid) { value = buf_to_str(reg->value, reg->size, 16); - command_print(CMD_CTX, + command_print(CMD, "(%i) %s (/%" PRIu32 "): 0x%s%s", count, reg->name, reg->size, value, @@ -2857,7 +2857,7 @@ COMMAND_HANDLER(handle_reg_command) : ""); free(value); } else { - command_print(CMD_CTX, "(%i) %s (/%" PRIu32 ")", + command_print(CMD, "(%i) %s (/%" PRIu32 ")", count, reg->name, reg->size) ; } @@ -2889,7 +2889,7 @@ COMMAND_HANDLER(handle_reg_command) } if (!reg) { - command_print(CMD_CTX, "%i is out of bounds, the current target " + command_print(CMD, "%i is out of bounds, the current target " "has only %i registers (0 - %i)", num, count, count - 1); return ERROR_OK; } @@ -2915,7 +2915,7 @@ COMMAND_HANDLER(handle_reg_command) if (reg->valid == 0) reg->type->get(reg); value = buf_to_str(reg->value, reg->size, 16); - command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); + command_print(CMD, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); return ERROR_OK; } @@ -2930,7 +2930,7 @@ COMMAND_HANDLER(handle_reg_command) reg->type->set(reg, buf); value = buf_to_str(reg->value, reg->size, 16); - command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); + command_print(CMD, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); free(buf); @@ -2941,7 +2941,7 @@ COMMAND_HANDLER(handle_reg_command) return ERROR_COMMAND_SYNTAX_ERROR; not_found: - command_print(CMD_CTX, "register %s not found in current target", CMD_ARGV[0]); + command_print(CMD, "register %s not found in current target", CMD_ARGV[0]); return ERROR_OK; } @@ -2951,9 +2951,9 @@ COMMAND_HANDLER(handle_poll_command) struct target *target = get_current_target(CMD_CTX); if (CMD_ARGC == 0) { - command_print(CMD_CTX, "background polling: %s", + command_print(CMD, "background polling: %s", jtag_poll_get_enabled() ? "on" : "off"); - command_print(CMD_CTX, "TAP: %s (%s)", + command_print(CMD, "TAP: %s (%s)", target->tap->dotted_name, target->tap->enabled ? "enabled" : "disabled"); if (!target->tap->enabled) @@ -3183,7 +3183,7 @@ static void handle_md_output(struct command_invocation *cmd, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd->ctx, "%s", output); + command_print(cmd, "%s", output); output_len = 0; } } @@ -3413,7 +3413,7 @@ COMMAND_HANDLER(handle_load_image_command) for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); retval = ERROR_FAIL; @@ -3450,7 +3450,7 @@ COMMAND_HANDLER(handle_load_image_command) break; } image_size += length; - command_print(CMD_CTX, "%u bytes written at address " TARGET_ADDR_FMT "", + command_print(CMD, "%u bytes written at address " TARGET_ADDR_FMT "", (unsigned int)length, image.sections[i].base_address + offset); } @@ -3459,7 +3459,7 @@ COMMAND_HANDLER(handle_load_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "downloaded %" PRIu32 " bytes " + command_print(CMD, "downloaded %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); } @@ -3520,7 +3520,7 @@ COMMAND_HANDLER(handle_dump_image_command) retval = fileio_size(fileio, &filesize); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, + command_print(CMD, "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize, duration_elapsed(&bench), duration_kbps(&bench, filesize)); } @@ -3585,7 +3585,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); break; @@ -3636,14 +3636,14 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver uint32_t t; for (t = 0; t < buf_cnt; t++) { if (data[t] != buffer[t]) { - command_print(CMD_CTX, + command_print(CMD, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", diffs, (unsigned)(t + image.sections[i].base_address), data[t], buffer[t]); if (diffs++ >= 127) { - command_print(CMD_CTX, "More than 128 errors, the rest are not printed."); + command_print(CMD, "More than 128 errors, the rest are not printed."); free(data); free(buffer); goto done; @@ -3655,7 +3655,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver free(data); } } else { - command_print(CMD_CTX, "address " TARGET_ADDR_FMT " length 0x%08zx", + command_print(CMD, "address " TARGET_ADDR_FMT " length 0x%08zx", image.sections[i].base_address, buf_cnt); } @@ -3664,12 +3664,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver image_size += buf_cnt; } if (diffs > 0) - command_print(CMD_CTX, "No more differences found."); + command_print(CMD, "No more differences found."); done: if (diffs > 0) retval = ERROR_FAIL; if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "verified %" PRIu32 " bytes " + command_print(CMD, "verified %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); } @@ -3702,24 +3702,24 @@ static int handle_bp_command_list(struct command_invocation *cmd) if (breakpoint->type == BKPT_SOFT) { char *buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd->ctx, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", + command_print(cmd, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", breakpoint->address, breakpoint->length, breakpoint->set, buf); free(buf); } else { if ((breakpoint->address == 0) && (breakpoint->asid != 0)) - command_print(cmd->ctx, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", breakpoint->asid, breakpoint->length, breakpoint->set); else if ((breakpoint->address != 0) && (breakpoint->asid != 0)) { - command_print(cmd->ctx, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); - command_print(cmd->ctx, "\t|--->linked with ContextID: 0x%8.8" PRIx32, + command_print(cmd, "\t|--->linked with ContextID: 0x%8.8" PRIx32, breakpoint->asid); } else - command_print(cmd->ctx, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); } @@ -3739,7 +3739,7 @@ static int handle_bp_command_set(struct command_invocation *cmd, retval = breakpoint_add(target, addr, length, hw); /* error is always logged in breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd->ctx, "breakpoint set at " TARGET_ADDR_FMT "", addr); + command_print(cmd, "breakpoint set at " TARGET_ADDR_FMT "", addr); } else if (addr == 0) { if (target->type->add_context_breakpoint == NULL) { @@ -3749,7 +3749,7 @@ static int handle_bp_command_set(struct command_invocation *cmd, retval = context_breakpoint_add(target, asid, length, hw); /* error is always logged in context_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd->ctx, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); } else { if (target->type->add_hybrid_breakpoint == NULL) { @@ -3759,7 +3759,7 @@ static int handle_bp_command_set(struct command_invocation *cmd, retval = hybrid_breakpoint_add(target, addr, asid, length, hw); /* error is always logged in hybrid_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd->ctx, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); } return retval; } @@ -3830,7 +3830,7 @@ COMMAND_HANDLER(handle_wp_command) struct watchpoint *watchpoint = target->watchpoints; while (watchpoint) { - command_print(CMD_CTX, "address: " TARGET_ADDR_FMT + command_print(CMD, "address: " TARGET_ADDR_FMT ", len: 0x%8.8" PRIx32 ", r/w/a: %i, value: 0x%8.8" PRIx32 ", mask: 0x%8.8" PRIx32, @@ -3922,7 +3922,7 @@ COMMAND_HANDLER(handle_virt2phys_command) struct target *target = get_current_target(CMD_CTX); int retval = target->type->virt2phys(target, va, &pa); if (retval == ERROR_OK) - command_print(CMD_CTX, "Physical address " TARGET_ADDR_FMT "", pa); + command_print(CMD, "Physical address " TARGET_ADDR_FMT "", pa); return retval; } @@ -4115,7 +4115,7 @@ COMMAND_HANDLER(handle_profile_command) write_gmon(samples, num_of_samples, CMD_ARGV[1], with_range, start_address, end_address, target, duration_ms); - command_print(CMD_CTX, "Wrote %s", CMD_ARGV[1]); + command_print(CMD, "Wrote %s", CMD_ARGV[1]); free(samples); return retval; @@ -5152,19 +5152,19 @@ COMMAND_HANDLER(handle_target_event_list) struct target *target = get_current_target(CMD_CTX); struct target_event_action *teap = target->event_action; - command_print(CMD_CTX, "Event actions for target (%d) %s\n", + command_print(CMD, "Event actions for target (%d) %s\n", target->target_number, target_name(target)); - command_print(CMD_CTX, "%-25s | Body", "Event"); - command_print(CMD_CTX, "------------------------- | " + command_print(CMD, "%-25s | Body", "Event"); + command_print(CMD, "------------------------- | " "----------------------------------------"); while (teap) { Jim_Nvp *opt = Jim_Nvp_value2name_simple(nvp_target_event, teap->event); - command_print(CMD_CTX, "%-25s | %s", + command_print(CMD, "%-25s | %s", opt->name, Jim_GetString(teap->body, NULL)); teap = teap->next; } - command_print(CMD_CTX, "***END***"); + command_print(CMD, "***END***"); return ERROR_OK; } static int jim_target_current_state(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -5776,7 +5776,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload_num = image.num_sections; fastload = malloc(sizeof(struct FastLoad)*image.num_sections); if (fastload == NULL) { - command_print(CMD_CTX, "out of memory"); + command_print(CMD, "out of memory"); image_close(&image); return ERROR_FAIL; } @@ -5784,7 +5784,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, "error allocating buffer for section (%d bytes)", + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); retval = ERROR_FAIL; break; @@ -5816,7 +5816,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload[i].data = malloc(length); if (fastload[i].data == NULL) { free(buffer); - command_print(CMD_CTX, "error allocating buffer for section (%" PRIu32 " bytes)", + command_print(CMD, "error allocating buffer for section (%" PRIu32 " bytes)", length); retval = ERROR_FAIL; break; @@ -5825,7 +5825,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload[i].length = length; image_size += length; - command_print(CMD_CTX, "%u bytes written at address 0x%8.8x", + command_print(CMD, "%u bytes written at address 0x%8.8x", (unsigned int)length, ((unsigned int)(image.sections[i].base_address + offset))); } @@ -5834,11 +5834,11 @@ COMMAND_HANDLER(handle_fast_load_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "Loaded %" PRIu32 " bytes " + command_print(CMD, "Loaded %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); - command_print(CMD_CTX, + command_print(CMD, "WARNING: image has not been loaded to target!" "You can issue a 'fast_load' to finish loading."); } @@ -5865,7 +5865,7 @@ COMMAND_HANDLER(handle_fast_load_command) int retval = ERROR_OK; for (i = 0; i < fastload_num; i++) { struct target *target = get_current_target(CMD_CTX); - command_print(CMD_CTX, "Write to 0x%08x, length 0x%08x", + command_print(CMD, "Write to 0x%08x, length 0x%08x", (unsigned int)(fastload[i].address), (unsigned int)(fastload[i].length)); retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data); @@ -5875,7 +5875,7 @@ COMMAND_HANDLER(handle_fast_load_command) } if (retval == ERROR_OK) { int64_t after = timeval_ms(); - command_print(CMD_CTX, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0)); + command_print(CMD, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0)); } return retval; } @@ -5930,7 +5930,7 @@ COMMAND_HANDLER(handle_ps_command) if ((target->rtos) && (target->rtos->type) && (target->rtos->type->ps_command)) { display = target->rtos->type->ps_command(target); - command_print(CMD_CTX, "%s", display); + command_print(CMD, "%s", display); free(display); return ERROR_OK; } else { @@ -5942,10 +5942,10 @@ COMMAND_HANDLER(handle_ps_command) static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size) { if (text != NULL) - command_print_sameline(cmd->ctx, "%s", text); + command_print_sameline(cmd, "%s", text); for (int i = 0; i < size; i++) - command_print_sameline(cmd->ctx, " %02x", buf[i]); - command_print(cmd->ctx, " "); + command_print_sameline(cmd, " %02x", buf[i]); + command_print(cmd, " "); } COMMAND_HANDLER(handle_test_mem_access_command) @@ -5997,7 +5997,7 @@ COMMAND_HANDLER(handle_test_mem_access_command) read_ref[i] = rand(); read_buf[i] = read_ref[i]; } - command_print_sameline(CMD_CTX, + command_print_sameline(CMD, "Test read %" PRIu32 " x %d @ %d to %saligned buffer: ", count, size, offset, host_offset ? "un" : ""); @@ -6010,10 +6010,10 @@ COMMAND_HANDLER(handle_test_mem_access_command) duration_measure(&bench); if (retval == ERROR_TARGET_UNALIGNED_ACCESS) { - command_print(CMD_CTX, "Unsupported alignment"); + command_print(CMD, "Unsupported alignment"); goto next; } else if (retval != ERROR_OK) { - command_print(CMD_CTX, "Memory read failed"); + command_print(CMD, "Memory read failed"); goto next; } @@ -6023,11 +6023,11 @@ COMMAND_HANDLER(handle_test_mem_access_command) /* check result */ int result = memcmp(read_ref, read_buf, host_bufsiz); if (result == 0) { - command_print(CMD_CTX, "Pass in %fs (%0.3f KiB/s)", + command_print(CMD, "Pass in %fs (%0.3f KiB/s)", duration_elapsed(&bench), duration_kbps(&bench, count * size)); } else { - command_print(CMD_CTX, "Compare failed"); + command_print(CMD, "Compare failed"); binprint(CMD, "ref:", read_ref, host_bufsiz); binprint(CMD, "buf:", read_buf, host_bufsiz); } @@ -6069,13 +6069,13 @@ out: for (size_t i = 0; i < host_bufsiz; i++) write_buf[i] = rand(); - command_print_sameline(CMD_CTX, + command_print_sameline(CMD, "Test write %" PRIu32 " x %d @ %d from %saligned buffer: ", count, size, offset, host_offset ? "un" : ""); retval = target_write_memory(target, wa->address, 1, num_bytes, test_pattern); if (retval != ERROR_OK) { - command_print(CMD_CTX, "Test pattern write failed"); + command_print(CMD, "Test pattern write failed"); goto nextw; } @@ -6092,28 +6092,28 @@ out: duration_measure(&bench); if (retval == ERROR_TARGET_UNALIGNED_ACCESS) { - command_print(CMD_CTX, "Unsupported alignment"); + command_print(CMD, "Unsupported alignment"); goto nextw; } else if (retval != ERROR_OK) { - command_print(CMD_CTX, "Memory write failed"); + command_print(CMD, "Memory write failed"); goto nextw; } /* read back */ retval = target_read_memory(target, wa->address, 1, num_bytes, read_buf); if (retval != ERROR_OK) { - command_print(CMD_CTX, "Test pattern write failed"); + command_print(CMD, "Test pattern write failed"); goto nextw; } /* check result */ int result = memcmp(read_ref, read_buf, num_bytes); if (result == 0) { - command_print(CMD_CTX, "Pass in %fs (%0.3f KiB/s)", + command_print(CMD, "Pass in %fs (%0.3f KiB/s)", duration_elapsed(&bench), duration_kbps(&bench, count * size)); } else { - command_print(CMD_CTX, "Compare failed"); + command_print(CMD, "Compare failed"); binprint(CMD, "ref:", read_ref, num_bytes); binprint(CMD, "buf:", read_buf, num_bytes); } diff --git a/src/target/target_request.c b/src/target/target_request.c index 2df29587f..c1da1a20e 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -283,7 +283,7 @@ COMMAND_HANDLER(handle_target_request_debugmsgs_command) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "receiving debug messages from current target %s", + command_print(CMD, "receiving debug messages from current target %s", (receiving) ? (charmsg_mode ? "charmsg" : "enabled") : "disabled"); return ERROR_OK; } diff --git a/src/target/trace.c b/src/target/trace.c index 63c477fbf..943bf1f4f 100644 --- a/src/target/trace.c +++ b/src/target/trace.c @@ -53,7 +53,7 @@ COMMAND_HANDLER(handle_trace_point_command) uint32_t i; for (i = 0; i < trace->num_trace_points; i++) { - command_print(CMD_CTX, "trace point 0x%8.8" PRIx32 " (%lld times hit)", + command_print(CMD, "trace point 0x%8.8" PRIx32 " (%lld times hit)", trace->trace_points[i].address, (long long)trace->trace_points[i].hit_counter); } @@ -108,14 +108,14 @@ COMMAND_HANDLER(handle_trace_history_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], trace->trace_history_size); trace->trace_history = malloc(sizeof(uint32_t) * trace->trace_history_size); - command_print(CMD_CTX, "new trace history size: %i", (int)(trace->trace_history_size)); + command_print(CMD, "new trace history size: %i", (int)(trace->trace_history_size)); } else { uint32_t i; uint32_t first = 0; uint32_t last = trace->trace_history_pos; if (!trace->trace_history_size) { - command_print(CMD_CTX, "trace history buffer is not allocated"); + command_print(CMD, "trace history buffer is not allocated"); return ERROR_OK; } @@ -128,11 +128,11 @@ COMMAND_HANDLER(handle_trace_history_command) if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points) { uint32_t address; address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address; - command_print(CMD_CTX, "trace point %i: 0x%8.8" PRIx32 "", + command_print(CMD, "trace point %i: 0x%8.8" PRIx32 "", (int)(trace->trace_history[i % trace->trace_history_size]), address); } else - command_print(CMD_CTX, "trace point %i: -not defined-", + command_print(CMD, "trace point %i: -not defined-", (int)(trace->trace_history[i % trace->trace_history_size])); } } diff --git a/src/target/x86_32_common.c b/src/target/x86_32_common.c index a641ca94f..b85e45119 100644 --- a/src/target/x86_32_common.c +++ b/src/target/x86_32_common.c @@ -1392,7 +1392,7 @@ static void handle_iod_output(struct command_invocation *cmd, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd->ctx, "%s", output); + command_print(cmd, "%s", output); output_len = 0; } } diff --git a/src/target/xscale.c b/src/target/xscale.c index a090c4b39..093925b62 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -142,7 +142,7 @@ static int xscale_verify_pointer(struct command_invocation *cmd, struct xscale_common *xscale) { if (xscale->common_magic != XSCALE_COMMON_MAGIC) { - command_print(cmd->ctx, xscale_not); + command_print(cmd, xscale_not); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -2658,9 +2658,9 @@ static inline void xscale_display_instruction(struct target *target, uint32_t pc { int retval = xscale_read_instruction(target, pc, instruction); if (retval == ERROR_OK) - command_print(cmd->ctx, "%s", instruction->text); + command_print(cmd, "%s", instruction->text); else - command_print(cmd->ctx, "0x%8.8" PRIx32 "\t", pc); + command_print(cmd, "0x%8.8" PRIx32 "\t", pc); } static int xscale_analyze_trace(struct target *target, struct command_invocation *cmd) @@ -2787,7 +2787,7 @@ static int xscale_analyze_trace(struct target *target, struct command_invocation continue; if (exception) { - command_print(cmd->ctx, "--- exception %i ---", exception); + command_print(cmd, "--- exception %i ---", exception); continue; } @@ -2813,7 +2813,7 @@ static int xscale_analyze_trace(struct target *target, struct command_invocation } if (current_pc == 0) - command_print(cmd->ctx, "address unknown"); + command_print(cmd, "address unknown"); continue; } @@ -3136,7 +3136,7 @@ COMMAND_HANDLER(xscale_handle_mmu_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3150,7 +3150,7 @@ COMMAND_HANDLER(xscale_handle_mmu_command) xscale->armv4_5_mmu.mmu_enabled = enable; } - command_print(CMD_CTX, "mmu %s", + command_print(CMD, "mmu %s", (xscale->armv4_5_mmu.mmu_enabled) ? "enabled" : "disabled"); return ERROR_OK; @@ -3166,7 +3166,7 @@ COMMAND_HANDLER(xscale_handle_idcache_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3195,7 +3195,7 @@ COMMAND_HANDLER(xscale_handle_idcache_command) xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled : xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled; const char *msg = enabled ? "enabled" : "disabled"; - command_print(CMD_CTX, "%s %s", CMD_NAME, msg); + command_print(CMD, "%s %s", CMD_NAME, msg); return ERROR_OK; } @@ -3257,7 +3257,7 @@ COMMAND_HANDLER(xscale_handle_vector_catch_command) dcsr_value = buf_get_u32(dcsr_reg->value, 0, 32); for (unsigned i = 0; i < ARRAY_SIZE(vec_ids); i++) { - command_print(CMD_CTX, "%15s: %s", vec_ids[i].name, + command_print(CMD, "%15s: %s", vec_ids[i].name, (dcsr_value & vec_ids[i].mask) ? "catch" : "ignore"); } @@ -3279,16 +3279,16 @@ COMMAND_HANDLER(xscale_handle_vector_table_command) if (CMD_ARGC == 0) { /* print current settings */ int idx; - command_print(CMD_CTX, "active user-set static vectors:"); + command_print(CMD, "active user-set static vectors:"); for (idx = 1; idx < 8; idx++) if (xscale->static_low_vectors_set & (1 << idx)) - command_print(CMD_CTX, + command_print(CMD, "low %d: 0x%" PRIx32, idx, xscale->static_low_vectors[idx]); for (idx = 1; idx < 8; idx++) if (xscale->static_high_vectors_set & (1 << idx)) - command_print(CMD_CTX, + command_print(CMD, "high %d: 0x%" PRIx32, idx, xscale->static_high_vectors[idx]); @@ -3335,7 +3335,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3354,7 +3354,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) if (CMD_ARGC >= 3) COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], buffcount); if (buffcount < 1) { /* invalid */ - command_print(CMD_CTX, "fill buffer count must be > 0"); + command_print(CMD, "fill buffer count must be > 0"); xscale->trace.mode = XSCALE_TRACE_DISABLED; return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3371,11 +3371,11 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) if (xscale->trace.mode != XSCALE_TRACE_DISABLED) { char fill_string[12]; sprintf(fill_string, "fill %d", xscale->trace.buffer_fill); - command_print(CMD_CTX, "trace buffer enabled (%s)", + command_print(CMD, "trace buffer enabled (%s)", (xscale->trace.mode == XSCALE_TRACE_FILL) ? fill_string : "wrap"); } else - command_print(CMD_CTX, "trace buffer disabled"); + command_print(CMD, "trace buffer disabled"); dcsr_value = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32); if (xscale->trace.mode == XSCALE_TRACE_FILL) @@ -3402,7 +3402,7 @@ COMMAND_HANDLER(xscale_handle_trace_image_command) if (xscale->trace.image) { image_close(xscale->trace.image); free(xscale->trace.image); - command_print(CMD_CTX, "previously loaded image found and closed"); + command_print(CMD, "previously loaded image found and closed"); } xscale->trace.image = malloc(sizeof(struct image)); @@ -3439,7 +3439,7 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3449,7 +3449,7 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) trace_data = xscale->trace.data; if (!trace_data) { - command_print(CMD_CTX, "no trace data collected"); + command_print(CMD, "no trace data collected"); return ERROR_OK; } @@ -3502,7 +3502,7 @@ COMMAND_HANDLER(xscale_handle_cp15) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } uint32_t reg_no = 0; @@ -3536,7 +3536,7 @@ COMMAND_HANDLER(xscale_handle_cp15) reg_no = XSCALE_CPACCESS; break; default: - command_print(CMD_CTX, "invalid register number"); + command_print(CMD, "invalid register number"); return ERROR_COMMAND_SYNTAX_ERROR; } reg = &xscale->reg_cache->reg_list[reg_no]; @@ -3548,7 +3548,7 @@ COMMAND_HANDLER(xscale_handle_cp15) /* read cp15 control register */ xscale_get_reg(reg); value = buf_get_u32(reg->value, 0, 32); - command_print(CMD_CTX, "%s (/%i): 0x%" PRIx32 "", reg->name, (int)(reg->size), + command_print(CMD, "%s (/%i): 0x%" PRIx32 "", reg->name, (int)(reg->size), value); } else if (CMD_ARGC == 2) { uint32_t value; diff --git a/src/transport/transport.c b/src/transport/transport.c index 708594712..77db9e210 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -258,10 +258,10 @@ COMMAND_HANDLER(handle_transport_list) if (CMD_ARGC != 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "The following transports are available:"); + command_print(CMD, "The following transports are available:"); for (struct transport *t = transport_list; t; t = t->next) - command_print(CMD_CTX, "\t%s", t->name); + command_print(CMD, "\t%s", t->name); return ERROR_OK; } diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 63c891511..e574c6f0e 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -249,14 +249,14 @@ COMMAND_HANDLER(handle_xsvf_command) if (strcmp(CMD_ARGV[0], "plain") != 0) { tap = jtag_tap_by_string(CMD_ARGV[0]); if (!tap) { - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[0]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[0]); return ERROR_FAIL; } } xsvf_fd = open(filename, O_RDONLY); if (xsvf_fd < 0) { - command_print(CMD_CTX, "file \"%s\" not found", filename); + command_print(CMD, "file \"%s\" not found", filename); return ERROR_FAIL; } @@ -1005,7 +1005,7 @@ COMMAND_HANDLER(handle_xsvf_command) } if (tdo_mismatch) { - command_print(CMD_CTX, + command_print(CMD, "TDO mismatch, somewhere near offset %lu in xsvf file, aborting", file_offset); @@ -1014,14 +1014,14 @@ COMMAND_HANDLER(handle_xsvf_command) if (unsupported) { off_t offset = lseek(xsvf_fd, 0, SEEK_CUR) - 1; - command_print(CMD_CTX, + command_print(CMD, "unsupported xsvf command (0x%02X) at offset %jd, aborting", uc, (intmax_t)offset); return ERROR_FAIL; } if (do_abort) { - command_print(CMD_CTX, "premature end of xsvf file detected, aborting"); + command_print(CMD, "premature end of xsvf file detected, aborting"); return ERROR_FAIL; } @@ -1036,7 +1036,7 @@ COMMAND_HANDLER(handle_xsvf_command) close(xsvf_fd); - command_print(CMD_CTX, "XSVF file programmed successfully"); + command_print(CMD, "XSVF file programmed successfully"); return ERROR_OK; } From 585fcea14aeaed41a6e7593dcff4e44101364243 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 3 Apr 2019 17:29:21 +0200 Subject: [PATCH 089/176] nor/niietcm4: fix indentation After replace CMD_CTX with CMD, the indentation is incorrect. Fix it. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I5d7c40227ceda2e9db8dab88088d74012d2254c4 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5082 Tested-by: jenkins --- src/flash/nor/niietcm4.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c index 62549f206..7b67bb8ad 100644 --- a/src/flash/nor/niietcm4.c +++ b/src/flash/nor/niietcm4.c @@ -426,8 +426,8 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command) if (retval != ERROR_OK) return retval; command_print(CMD, "Read userflash %s region:\n" - "address = 0x%04x,\n" - "value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); + "address = 0x%04x,\n" + "value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); return retval; } @@ -468,9 +468,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command) int page_num = uflash_addr/USERFLASH_PAGE_SIZE; command_print(CMD, "Write userflash %s region:\n" - "address = 0x%04x,\n" - "value = 0x%02x.\n" - "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); + "address = 0x%04x,\n" + "value = 0x%02x.\n" + "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); /* dump */ uint32_t uflash_dump[USERFLASH_PAGE_SIZE]; niietcm4_dump_uflash_page(bank, uflash_dump, page_num, mem_type); @@ -815,10 +815,10 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command) return ERROR_COMMAND_SYNTAX_ERROR; command_print(CMD, "Try to configure external memory boot interface:\n" - "port = %s\n" - "pin = %s\n" - "func = %s\n" - "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]); + "port = %s\n" + "pin = %s\n" + "func = %s\n" + "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]); /* dump */ uint32_t uflash_dump[USERFLASH_PAGE_SIZE]; niietcm4_dump_uflash_page(bank, uflash_dump, 0, 1); From 2caa3455ada686baea01a50d092e4244c461e101 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 3 Apr 2019 17:31:57 +0200 Subject: [PATCH 090/176] flash/nor: use command_print() in command "flash banks" The command uses LOG_USER() instead of command_print(). Fix it. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I92e5e5954a75b96093b3ed6af73a7536c063b639 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5083 Tested-by: jenkins --- src/flash/nor/tcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 0daa531b8..b336cffda 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -1167,7 +1167,7 @@ COMMAND_HANDLER(handle_flash_banks_command) unsigned n = 0; for (struct flash_bank *p = flash_bank_list(); p; p = p->next, n++) { - LOG_USER("#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", " + command_print(CMD, "#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", " "buswidth %u, chipwidth %u", p->bank_number, p->name, p->driver->name, p->base, p->size, p->bus_width, p->chip_width); From 7f260f5009a774f2d66b5f3037f8f595c6881d4d Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Thu, 4 Apr 2019 09:54:09 +0200 Subject: [PATCH 091/176] helper/command: Handle Tcl return values consistently Rationale: 1. There's logging output and there're return values; 2. If a function should return something, it should do it explicitly, same for logging; 3. Interactive interfaces (telnet, Gdb and Tcl RPC) must always return the result of the evaluation for the given expression. You can suppress this output by adding ``; after 0'' to the end of your expression. 4. Some commands "throw an exception" and if you want to be able to collect both the return value (when it succeeds) and the log output (when something goes wrong) you can use do like this: set log_output [capture "catch {reset_config} return_value"] So what I'm proposing is following: 1. Every jim_handler command should set the return value the standard JimTcl way, without any tricks. If it needs to print some logging output, it should use LOG_* functions. 2. The usual commands (COMMANDS) can easily construct their return value by appending strings with command_print() and command_print_sameline(). This required changing "struct command_invocation" and passing a pointer to it to command_print* functions. The code is already functional, please test and comment. TODO items: 1. Modify all jim_handler commands to properly return or log values (some of them are commented out for now in this patch). 2. Properly document "capture" command and provide a convenience function to automate log_output + return_value gathering. 3. Add appropriate Doxygen comments. 4. Add Tcl RPC interface description to the manual, all the example clients in different languages (from the mailing list) to contrib/. This change is the core part of http://openocd.zylin.com/1815 from Paul Fertser. It has been extracted and rebased to simplify the review and provided again as 1815. Change-Id: I675c91aa9da1e4e7c6f0a8fe6112a00550b9e4db Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/1815 Tested-by: jenkins --- src/helper/command.c | 15 +++++++++++---- src/helper/command.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index be131bb3b..11c9e5f52 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -510,13 +510,13 @@ void command_print_sameline(struct command_invocation *cmd, const char *format, va_start(ap, format); string = alloc_vprintf(format, ap); - if (string != NULL) { + if (string != NULL && cmd) { /* we want this collected in the log + we also want to pick it up as a tcl return * value. * * The latter bit isn't precisely neat, but will do for now. */ - LOG_USER_N("%s", string); + Jim_AppendString(cmd->ctx->interp, cmd->output, string, -1); /* We already printed it above * command_output_text(context, string); */ free(string); @@ -533,7 +533,7 @@ void command_print(struct command_invocation *cmd, const char *format, ...) va_start(ap, format); string = alloc_vprintf(format, ap); - if (string != NULL) { + if (string != NULL && cmd) { strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one *char longer */ /* we want this collected in the log + we also want to pick it up as a tcl return @@ -541,7 +541,7 @@ void command_print(struct command_invocation *cmd, const char *format, ...) * * The latter bit isn't precisely neat, but will do for now. */ - LOG_USER_N("%s", string); + Jim_AppendString(cmd->ctx->interp, cmd->output, string, -1); /* We already printed it above * command_output_text(context, string); */ free(string); @@ -628,6 +628,9 @@ static int run_command(struct command_context *context, if (c->jim_handler_data) context->current_target_override = c->jim_handler_data; + cmd.output = Jim_NewEmptyStringObj(context->interp); + Jim_IncrRefCount(cmd.output); + int retval = c->handler(&cmd); if (c->jim_handler_data) @@ -650,7 +653,11 @@ static int run_command(struct command_context *context, LOG_DEBUG("Command '%s' failed with error code %d", full_name ? full_name : c->name, retval); free(full_name); + } else { + /* Use the command output as the Tcl result */ + Jim_SetResult(context->interp, cmd.output); } + Jim_DecrRefCount(context->interp, cmd.output); return retval; } diff --git a/src/helper/command.h b/src/helper/command.h index 41cdc0b9d..733ba42dd 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -79,6 +79,7 @@ struct command_invocation { const char *name; unsigned argc; const char **argv; + Jim_Obj *output; }; /** From a72561ba9103e9dd63be6874df90ebf0d74874dc Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Thu, 4 Apr 2019 09:35:15 +0200 Subject: [PATCH 092/176] helper/command: do not capture log in script_command_run() Command's output should be put in JimTcl result. We should not anymore capture the log output and pack it as a JimTcl result. Remove the log capture feature in script_command_run(). This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: Id326c8719e1cee9156d7fc15ae8355ec79a74951 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5085 Tested-by: jenkins --- src/helper/command.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 11c9e5f52..bab98dfee 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -190,7 +190,7 @@ struct command_context *current_command_context(Jim_Interp *interp) } static int script_command_run(Jim_Interp *interp, - int argc, Jim_Obj * const *argv, struct command *c, bool capture) + int argc, Jim_Obj * const *argv, struct command *c) { target_call_timer_callbacks_now(); LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ @@ -200,15 +200,9 @@ static int script_command_run(Jim_Interp *interp, if (NULL == words) return JIM_ERR; - struct log_capture_state *state = NULL; - if (capture) - state = command_log_capture_start(interp); - struct command_context *cmd_ctx = current_command_context(interp); int retval = run_command(cmd_ctx, c, (const char **)words, nwords); - command_log_capture_finish(state); - script_command_args_free(words, nwords); return command_retval_set(interp, retval); } @@ -220,7 +214,7 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command *c = interp->cmdPrivData; assert(c); script_debug(interp, c->name, argc, argv); - return script_command_run(interp, argc, argv, c, true); + return script_command_run(interp, argc, argv, c); } static struct command *command_root(struct command *c) @@ -1024,7 +1018,6 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } - bool found = true; Jim_Obj *const *start; unsigned count; if (c->handler || c->jim_handler) { @@ -1039,7 +1032,6 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } count = argc - remaining; start = argv; - found = false; } /* pass the command through to the intended handler */ if (c->jim_handler) { @@ -1050,7 +1042,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return (*c->jim_handler)(interp, count, start); } - return script_command_run(interp, count, start, c, found); + return script_command_run(interp, count, start, c); } static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) From 0840414f0e57cb9b64867ac3e57d266502ea2ee4 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Thu, 4 Apr 2019 09:40:27 +0200 Subject: [PATCH 093/176] helper/command: do not replace new commands with ocd_ prefix The TCL return values are now consistent, no need anymore for the hack of registering the commands with "ocd_" prefix and override them with proc ocd_bouncer. Clean-up the command registration and remove the proc ocd_bouncer. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I2a467e73ecb068686ea3fda91bf961aba6db6427 Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5086 Tested-by: jenkins --- src/helper/command.c | 20 ++------------------ src/helper/startup.tcl | 30 ------------------------------ 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index bab98dfee..4883984f1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -351,27 +351,11 @@ static int register_command_handler(struct command_context *cmd_ctx, struct command *c) { Jim_Interp *interp = cmd_ctx->interp; - char *ocd_name = alloc_printf("ocd_%s", c->name); - if (NULL == ocd_name) - return JIM_ERR; - LOG_DEBUG("registering '%s'...", ocd_name); + LOG_DEBUG("registering '%s'...", c->name); Jim_CmdProc *func = c->handler ? &script_command : &command_unknown; - int retval = Jim_CreateCommand(interp, ocd_name, func, c, NULL); - free(ocd_name); - if (JIM_OK != retval) - return retval; - - /* we now need to add an overrideable proc */ - char *override_name = alloc_printf( - "proc %s {args} {eval ocd_bouncer %s $args}", - c->name, c->name); - if (NULL == override_name) - return JIM_ERR; - - retval = Jim_Eval_Named(interp, override_name, 0, 0); - free(override_name); + int retval = Jim_CreateCommand(interp, c->name, func, c, NULL); return retval; } diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index cda3a8fa3..691e3824f 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -3,36 +3,6 @@ # Embedded into OpenOCD executable # -# All commands are registered with an 'ocd_' prefix, while the "real" -# command is a wrapper that calls this function. Its primary purpose is -# to discard 'handler' command output. -# Due to the two nested proc calls, this wrapper has to explicitly run -# the wrapped command in the stack frame two levels above. -proc ocd_bouncer {name args} { - set cmd [format "ocd_%s" $name] - set type [eval ocd_command type $cmd $args] - set errcode error - set skiplevel [expr [eval info level] > 1 ? 2 : 1] - if {$type == "native"} { - return [uplevel $skiplevel $cmd $args] - } else {if {$type == "simple"} { - set errcode [catch {uplevel $skiplevel $cmd $args}] - if {$errcode == 0} { - return "" - } else { - # 'classic' commands output error message as part of progress output - set errmsg "" - } - } else {if {$type == "group"} { - catch {eval ocd_usage $name $args} - set errmsg [format "%s: command requires more arguments" \ - [concat $name " " $args]] - } else { - set errmsg [format "invalid subcommand \"%s\"" $args] - }}} - return -code $errcode $errmsg -} - # Try flipping / and \ to find file if the filename does not # match the precise spelling proc find {filename} { From 6da0512092d03bb9ea08df0cafd5d3fbaef432d2 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 3 Apr 2019 18:50:41 +0200 Subject: [PATCH 094/176] helper/command: remove command "command type" Once the wrapper "ocd_bouncer" is removed (which was the only user of this command), there is no reason to keep the command any longer. Remove it. This change was part of http://openocd.zylin.com/1815 from Paul Fertser and has been extracted and rebased to simplify the review. Change-Id: I979ce1c147babedb44dd77418751133f589f827c Signed-off-by: Paul Fertser Signed-off-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5084 Tested-by: jenkins --- src/helper/command.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 4883984f1..98c62cf8c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1065,32 +1065,6 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } -static int jim_command_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - if (1 == argc) - return JIM_ERR; - - struct command_context *cmd_ctx = current_command_context(interp); - struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc - 1, argv + 1, c, &c, true); - /* if nothing could be consumed, then it's an unknown command */ - if (remaining == argc - 1) { - Jim_SetResultString(interp, "unknown", -1); - return JIM_OK; - } - - if (c->jim_handler) - Jim_SetResultString(interp, "native", -1); - else if (c->handler) - Jim_SetResultString(interp, "simple", -1); - else if (remaining == 0) - Jim_SetResultString(interp, "group", -1); - else - Jim_SetResultString(interp, "unknown", -1); - - return JIM_OK; -} - int help_add_command(struct command_context *cmd_ctx, struct command *parent, const char *cmd_name, const char *help_text, const char *usage) { @@ -1211,15 +1185,6 @@ static const struct command_registration command_subcommand_handlers[] = { "Returns 'unknown' if an unknown command is given. " "Command can be multiple tokens.", }, - { - .name = "type", - .mode = COMMAND_ANY, - .jim_handler = jim_command_type, - .usage = "command_name [...]", - .help = "Returns the type of built-in command:" - "'native', 'simple', 'group', or 'unknown'. " - "Command can be multiple tokens.", - }, COMMAND_REGISTRATION_DONE }; From 9eea9cce3f0931d9ecf3977211bd0f189be57c52 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 28 Mar 2019 11:58:10 +0100 Subject: [PATCH 095/176] helper/command: remove search for "ocd_" prefix We do not register commands with special "ocd_" prefix anymore. Change-Id: I588816eb22c2435a97be5fbfa87ee5584274b02f Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5087 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 98c62cf8c..0f35f8565 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -812,8 +812,6 @@ static COMMAND_HELPER(command_help_find, struct command *head, if (0 == CMD_ARGC) return ERROR_COMMAND_SYNTAX_ERROR; *out = command_find(head, CMD_ARGV[0]); - if (NULL == *out && strncmp(CMD_ARGV[0], "ocd_", 4) == 0) - *out = command_find(head, CMD_ARGV[0] + 4); if (NULL == *out) return ERROR_COMMAND_SYNTAX_ERROR; if (--CMD_ARGC == 0) @@ -967,18 +965,16 @@ COMMAND_HANDLER(handle_help_command) } static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, - struct command *head, struct command **out, bool top_level) + struct command *head, struct command **out) { if (0 == argc) return argc; const char *cmd_name = Jim_GetString(argv[0], NULL); struct command *c = command_find(head, cmd_name); - if (NULL == c && top_level && strncmp(cmd_name, "ocd_", 4) == 0) - c = command_find(head, cmd_name + 4); if (NULL == c) return argc; *out = c; - return command_unknown_find(--argc, ++argv, (*out)->children, out, false); + return command_unknown_find(--argc, ++argv, (*out)->children, out); } static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -994,7 +990,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command_context *cmd_ctx = current_command_context(interp); struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc, argv, c, &c, true); + int remaining = command_unknown_find(argc, argv, c, &c); /* if nothing could be consumed, then it's really an unknown command */ if (remaining == argc) { const char *cmd = Jim_GetString(argv[0], NULL); @@ -1036,7 +1032,7 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (argc > 1) { struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc - 1, argv + 1, c, &c, true); + int remaining = command_unknown_find(argc - 1, argv + 1, c, &c); /* if nothing could be consumed, then it's an unknown command */ if (remaining == argc - 1) { Jim_SetResultString(interp, "unknown", -1); From 24bfdf53fdb3f79dd6ef4c435feee5d94ab85a19 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 28 Mar 2019 12:14:56 +0100 Subject: [PATCH 096/176] doc: remove references to "ocd_" prefixed commands The commands prefixed with "ocd_" are removed. Remove any reference in the documentation. Change-Id: I27cebaa4752752ec8700757bf1c98b267c24f15b Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5088 Reviewed-by: Tomas Vanek Tested-by: jenkins --- doc/openocd.texi | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 069208b36..4fb7b00b1 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4926,7 +4926,6 @@ Use it in board specific configuration files, not interactively. @end quotation @end deffn -@comment the REAL name for this command is "ocd_flash_banks" @comment less confusing would be: "flash list" (like "nand list") @deffn Command {flash banks} Prints a one-line summary of each device that was @@ -9534,13 +9533,12 @@ The following commands can be used to authenticate to a RISC-V system. Eg. a trivial challenge-response protocol could be implemented as follows in a configuration file, immediately following @command{init}: @example -set challenge [ocd_riscv authdata_read] +set challenge [riscv authdata_read] riscv authdata_write [expr $challenge + 1] @end example @deffn Command {riscv authdata_read} -Return the 32-bit value read from authdata. Note that to get read value back in -a TCL script, it needs to be invoked as @command{ocd_riscv authdata_read}. +Return the 32-bit value read from authdata. @end deffn @deffn Command {riscv authdata_write} value @@ -9553,9 +9551,7 @@ The following commands allow direct access to the Debug Module Interface, which can be used to interact with custom debug features. @deffn Command {riscv dmi_read} -Perform a 32-bit DMI read at address, returning the value. Note that to get -read value back in a TCL script, it needs to be invoked as @command{ocd_riscv -dmi_read}. +Perform a 32-bit DMI read at address, returning the value. @end deffn @deffn Command {riscv dmi_write} address value @@ -10439,10 +10435,6 @@ should be passed in to the proc in question. By "low-level," we mean commands that a human would typically not invoke directly. -Some low-level commands need to be prefixed with "ocd_"; e.g. -@command{ocd_flash_banks} -is the low-level API upon which @command{flash banks} is implemented. - @itemize @bullet @item @b{mem2array} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}> @@ -10450,7 +10442,7 @@ Read memory and return as a Tcl array for script processing @item @b{array2mem} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}> Convert a Tcl array to memory locations and write the values -@item @b{ocd_flash_banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...] +@item @b{flash banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...] Return information about the flash banks @@ -10509,8 +10501,8 @@ interpreter terminating it with @code{0x1a} and wait for the return value (it will be terminated with @code{0x1a} as well). This can be repeated as many times as desired without reopening the connection. -Remember that most of the OpenOCD commands need to be prefixed with -@code{ocd_} to get the results back. Sometimes you might also need the +It is not needed anymore to prefix the OpenOCD commands with +@code{ocd_} to get the results back. But sometimes you might need the @command{capture} command. See @file{contrib/rpc_examples/} for specific client implementations. From 83af3d992e45ccf011f80b7e786886784b0cf469 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 28 Mar 2019 12:15:47 +0100 Subject: [PATCH 097/176] TODO: remove references to "ocd_" prefix in documentation The commands prefixed with "ocd_" are removed. No need to review the documentation. Change-Id: Idad95e62f6c8574ff8b61930aeef04e9727fae8a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5089 Reviewed-by: Tomas Vanek Tested-by: jenkins --- TODO | 1 - 1 file changed, 1 deletion(-) diff --git a/TODO b/TODO index aa43fdddf..350aaa274 100644 --- a/TODO +++ b/TODO @@ -365,7 +365,6 @@ to complete: - committing to git - Review Users' Guide for documentation errors or omissions - "capture" and "ocd_find" commands - - "ocd_" prefix on various stuff - Update Developer's Manual (doxygen output) - Add documentation describing the architecture of each module - Provide more Technical Primers to bootstrap contributor knowledge From 3605cb96252efb4644924f1c1357a1ea122c6390 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 28 Mar 2019 12:22:25 +0100 Subject: [PATCH 098/176] tcl/psoc4: remove "ocd_" prefixed commands The commands prefixed with "ocd_" are removed. Remove them from configuration files. Change-Id: Ib44627ee17a39f3d06b479507ab5a025073bf9a8 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5090 Reviewed-by: Tomas Vanek Tested-by: jenkins --- tcl/target/psoc4.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcl/target/psoc4.cfg b/tcl/target/psoc4.cfg index eb51847ce..544e10987 100644 --- a/tcl/target/psoc4.cfg +++ b/tcl/target/psoc4.cfg @@ -179,7 +179,7 @@ proc ocd_process_reset_inner { MODE } { } # Check if PSoC CPU is stopped in system ROM - set pc [ocd_reg pc] + set pc [reg pc] regsub {pc[^:]*: } $pc "" pc if { $pc < 0x10000000 || $pc > 0x1000ffff } { set hint "" From 31c67cc83083ccc2db49d136a9b0d7227e336dba Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 6 Apr 2019 16:26:31 +0200 Subject: [PATCH 099/176] target: fix output of command "targets" Part of the output is generated with log functions. Change prototype of find_target() and use command_print() for all the output of the command. Change-Id: Ia9fdb653fd5b27be427381053a037545faa34414 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5092 Reviewed-by: Tomas Vanek Tested-by: jenkins --- src/target/target.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 20bf26b5d..4b4aec83c 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2578,23 +2578,23 @@ int target_write_phys_u8(struct target *target, target_addr_t address, uint8_t v return retval; } -static int find_target(struct command_context *cmd_ctx, const char *name) +static int find_target(struct command_invocation *cmd, const char *name) { struct target *target = get_target(name); if (target == NULL) { - LOG_ERROR("Target: %s is unknown, try one of:\n", name); + command_print(cmd, "Target: %s is unknown, try one of:\n", name); return ERROR_FAIL; } if (!target->tap->enabled) { - LOG_USER("Target: TAP %s is disabled, " + command_print(cmd, "Target: TAP %s is disabled, " "can't be the current target\n", target->tap->dotted_name); return ERROR_FAIL; } - cmd_ctx->current_target = target; - if (cmd_ctx->current_target_override) - cmd_ctx->current_target_override = target; + cmd->ctx->current_target = target; + if (cmd->ctx->current_target_override) + cmd->ctx->current_target_override = target; return ERROR_OK; } @@ -2604,7 +2604,7 @@ COMMAND_HANDLER(handle_targets_command) { int retval = ERROR_OK; if (CMD_ARGC == 1) { - retval = find_target(CMD_CTX, CMD_ARGV[0]); + retval = find_target(CMD, CMD_ARGV[0]); if (retval == ERROR_OK) { /* we're done! */ return retval; From c826746068d46099eb787c403a240b4afff37c0a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 7 Apr 2019 05:12:31 +0200 Subject: [PATCH 100/176] helper/command: send command output only to the right server When opening multiple telnet connections, the command output on one console is broadcast to all the other console. Send the command output only to the output handler that has been set for that context. For the moment, still broadcast the errors. Note that contexts which doesn't explicitly set the output handler (e.g. gdb_server), will inherit the global output handler configuration_output_handler() that will broadcast the output. Change-Id: I1f2d6e6a3bbf730f5fa77246730fce1445742a1e Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5093 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 0f35f8565..ddf77d187 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -676,18 +676,8 @@ int command_run_line(struct command_context *context, char *line) result = Jim_GetString(Jim_GetResult(interp), &reslen); if (reslen > 0) { - int i; - char buff[256 + 1]; - for (i = 0; i < reslen; i += 256) { - int chunk; - chunk = reslen - i; - if (chunk > 256) - chunk = 256; - strncpy(buff, result + i, chunk); - buff[chunk] = 0; - LOG_USER_N("%s", buff); - } - LOG_USER_N("\n"); + command_output_text(context, result); + command_output_text(context, "\n"); } retval = ERROR_OK; } else if (retcode == JIM_EXIT) { @@ -697,6 +687,7 @@ int command_run_line(struct command_context *context, char *line) return retcode; } else { Jim_MakeErrorMessage(interp); + /* error is broadcast */ LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL)); if (retval == ERROR_OK) { From 92b582ed62ca4f21f469d71637befb0880555b7a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 12 May 2019 14:09:51 +0200 Subject: [PATCH 101/176] helper/command: fix printing usage for incomplete commands The commit "helper/command: do not replace new commands with ocd_ prefix" breaks the print of usage text when a multi-word command is typed incompletely. Fix it by explicitly running the "usage" command. Change-Id: I46f8e521d9b6ac617bff8938cf8fc96f0ade45c8 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5166 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 66 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index ddf77d187..e8ade3f70 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -968,6 +968,65 @@ static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, return command_unknown_find(--argc, ++argv, (*out)->children, out); } +static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv) +{ + char *prev, *all; + int i; + + assert(argc >= 1); + + all = strdup(Jim_GetString(argv[0], NULL)); + if (!all) { + LOG_ERROR("Out of memory"); + return NULL; + } + + for (i = 1; i < argc; ++i) { + prev = all; + all = alloc_printf("%s %s", all, Jim_GetString(argv[i], NULL)); + free(prev); + if (!all) { + LOG_ERROR("Out of memory"); + return NULL; + } + } + + return all; +} + +static int run_usage(Jim_Interp *interp, int argc_valid, int argc, Jim_Obj * const *argv) +{ + struct command_context *cmd_ctx = current_command_context(interp); + char *command; + int retval; + + assert(argc_valid >= 1); + assert(argc >= argc_valid); + + command = alloc_concatenate_strings(argc_valid, argv); + if (!command) + return JIM_ERR; + + retval = command_run_linef(cmd_ctx, "usage %s", command); + if (retval != ERROR_OK) { + LOG_ERROR("unable to execute command \"usage %s\"", command); + return JIM_ERR; + } + + if (argc_valid == argc) + LOG_ERROR("%s: command requires more arguments", command); + else { + free(command); + command = alloc_concatenate_strings(argc - argc_valid, argv + argc_valid); + if (!command) + return JIM_ERR; + LOG_ERROR("invalid subcommand \"%s\"", command); + } + + free(command); + return retval; +} + static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { const char *cmd_name = Jim_GetString(argv[0], NULL); @@ -996,13 +1055,10 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) count = remaining + 1; start = argv + (argc - remaining - 1); } else { - c = command_find(cmd_ctx->commands, "usage"); - if (NULL == c) { - LOG_ERROR("unknown command, but usage is missing too"); - return JIM_ERR; - } count = argc - remaining; start = argv; + run_usage(interp, count, argc, start); + return JIM_ERR; } /* pass the command through to the intended handler */ if (c->jim_handler) { From 4f9ad1661073a93957b8c63554630a845b64402f Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 29 Apr 2019 12:08:05 +0200 Subject: [PATCH 102/176] target: Fix breakpoint usage Change-Id: I28630e5062ffb16939250f7ec7549200f3a9b285 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5139 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 4b4aec83c..ee6ff3016 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -6285,7 +6285,7 @@ static const struct command_registration target_exec_command_handlers[] = { .handler = handle_bp_command, .mode = COMMAND_EXEC, .help = "list or set hardware or software breakpoint", - .usage = "
[] ['hw'|'hw_ctx']", + .usage = "[
[] ['hw'|'hw_ctx']]", }, { .name = "rbp", From 6dab4c70c8687d64a3131c3feb102daa53dcf0cf Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 2 Aug 2016 18:44:10 -0700 Subject: [PATCH 103/176] jtag_vpi: correct runtest behavior Prevent the State Machine from moving at the end of several cycles during run_test_idle state. Change-Id: Iabdf90a58334dd3d0e6e34b02983a85662062825 Signed-off-by: Megan Wachs Reviewed-on: http://openocd.zylin.com/3635 Tested-by: jenkins Reviewed-by: Jan Matyas Reviewed-by: Franck Jullien Reviewed-by: Tomas Vanek --- src/jtag/drivers/jtag_vpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index 35c70312d..c69f24fd0 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -319,7 +319,7 @@ static int jtag_vpi_runtest(int cycles, tap_state_t state) if (retval != ERROR_OK) return retval; - retval = jtag_vpi_queue_tdi(NULL, cycles, TAP_SHIFT); + retval = jtag_vpi_queue_tdi(NULL, cycles, NO_TAP_SHIFT); if (retval != ERROR_OK) return retval; From b3d4c97b9f441b1dfe36f26d64bb80974ee06ee3 Mon Sep 17 00:00:00 2001 From: Jan Matyas Date: Mon, 6 May 2019 07:20:33 +0200 Subject: [PATCH 104/176] jtag_vpi: fixed state transitions in "stableclocks" In jtag_vpi_stableclocks() the TMS line needs to be set properly based on the current JTAG TAP state (TMS=1 in TAP_RESET state vs. TMS=0 in other cases). Change-Id: Id49622ba83015f97b61b6a896edde4448f1fbdc6 Signed-off-by: Jan Matyas Reviewed-on: http://openocd.zylin.com/5151 Tested-by: jenkins Reviewed-by: Franck Jullien Reviewed-by: Tomas Vanek --- src/jtag/drivers/jtag_vpi.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index c69f24fd0..1033cedb2 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -328,7 +328,27 @@ static int jtag_vpi_runtest(int cycles, tap_state_t state) static int jtag_vpi_stableclocks(int cycles) { - return jtag_vpi_queue_tdi(NULL, cycles, TAP_SHIFT); + uint8_t tms_bits[4]; + int cycles_remain = cycles; + int nb_bits; + int retval; + const int CYCLES_ONE_BATCH = sizeof(tms_bits) * 8; + + assert(cycles >= 0); + + /* use TMS=1 in TAP RESET state, TMS=0 in all other stable states */ + memset(&tms_bits, (tap_get_state() == TAP_RESET) ? 0xff : 0x00, sizeof(tms_bits)); + + /* send the TMS bits */ + while (cycles_remain > 0) { + nb_bits = (cycles_remain < CYCLES_ONE_BATCH) ? cycles_remain : CYCLES_ONE_BATCH; + retval = jtag_vpi_tms_seq(tms_bits, nb_bits); + if (retval != ERROR_OK) + return retval; + cycles_remain -= nb_bits; + } + + return ERROR_OK; } static int jtag_vpi_execute_queue(void) From ea450298296ec6db233e24dff6732257c1cfb12d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 14 May 2019 23:38:29 +0200 Subject: [PATCH 105/176] drivers/bcm2835gpio: fix build for ARM host The commit 84ca4995adfa ("drivers/bcm2835gpio: fix usage messages") has been merged before commit 6cb5ba6f1136 ("helper/command: change prototype of command_print/command_print_sameline") introducing two new call to command_print() that were not modified by the second commit. This triggers a compile error on ARM host. Fix the incorrect function call. Change-Id: I2736bae24141685b7590fd6b4aa5e6a29b2cab29 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5174 Tested-by: jenkins --- src/jtag/drivers/bcm2835gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index edec4beff..36e10b6da 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -301,7 +301,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } - command_print(CMD_CTX, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d", + command_print(CMD, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d", speed_coeff, speed_offset); return ERROR_OK; } @@ -311,7 +311,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_peripheral_base) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bcm2835_peri_base); - command_print(CMD_CTX, "BCM2835 GPIO: peripheral_base = 0x%08x", + command_print(CMD, "BCM2835 GPIO: peripheral_base = 0x%08x", bcm2835_peri_base); return ERROR_OK; } From 04ebb43f93ca4ce5ae891da1d5d819705ec9368c Mon Sep 17 00:00:00 2001 From: Jan Matyas Date: Wed, 15 May 2019 07:38:51 +0200 Subject: [PATCH 106/176] jtag/drivers/imx_gpio: fixed calls to command_print Two calls to command_print() in imx_gpio fixed - the first parameter adjusted (CMD_CTX -> CMD) per the changes from this commit: 6cb5ba6f1136df2986850f5c176cb38e34ca1795 Change-Id: I6cb0909439a632d3109edfc68070b9b561f86d49 Signed-off-by: Jan Matyas Reviewed-on: http://openocd.zylin.com/5176 Reviewed-by: Tomas Vanek Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/jtag/drivers/imx_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/imx_gpio.c b/src/jtag/drivers/imx_gpio.c index 196d0e4a1..4923dab39 100644 --- a/src/jtag/drivers/imx_gpio.c +++ b/src/jtag/drivers/imx_gpio.c @@ -323,7 +323,7 @@ COMMAND_HANDLER(imx_gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } - command_print(CMD_CTX, "imx_gpio: speed_coeffs = %d, speed_offset = %d", + command_print(CMD, "imx_gpio: speed_coeffs = %d, speed_offset = %d", speed_coeff, speed_offset); return ERROR_OK; } @@ -333,7 +333,7 @@ COMMAND_HANDLER(imx_gpio_handle_peripheral_base) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], imx_gpio_peri_base); - command_print(CMD_CTX, "imx_gpio: peripheral_base = 0x%08x", + command_print(CMD, "imx_gpio: peripheral_base = 0x%08x", imx_gpio_peri_base); return ERROR_OK; } From e162200ab2cd6c2202bd437dca91137eacf9021c Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Tue, 7 May 2019 13:20:30 +0200 Subject: [PATCH 107/176] Fix 'adapter usb location' documentation Change-Id: Ifd1d21f2a3cc25ee25e3c7dd04dbb8190d41a1ea Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5156 Tested-by: jenkins Reviewed-by: Oleksij Rempel Reviewed-by: Tomas Vanek --- doc/openocd.texi | 4 ++-- src/jtag/adapter.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 4fb7b00b1..535fe3a80 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2370,8 +2370,8 @@ Returns the name of the debug adapter driver being used. @end deffn @anchor{adapter_usb_location} -@deffn Command {adapter usb location} -[.]... -Specifies the physical USB port of the adapter to use. The path +@deffn Command {adapter usb location} [-[.]...] +Displays or specifies the physical USB port of the adapter to use. The path roots at @var{bus} and walks down the physical ports, with each @var{port} option specifying a deeper level in the bus topology, the last @var{port} denoting where the target adapter is actually plugged. diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 0a887ef20..e11f4e906 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -476,8 +476,8 @@ static const struct command_registration adapter_usb_command_handlers[] = { .name = "location", .handler = &handle_usb_location_command, .mode = COMMAND_CONFIG, - .help = "set the USB bus location of the USB device", - .usage = "-port[.port]...", + .help = "display or set the USB bus location of the USB device", + .usage = "[-port[.port]...]", }, #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */ COMMAND_REGISTRATION_DONE From 2b78f65aa9dd970ab481d16e202571c9bec450f3 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 15 May 2019 16:27:26 +0200 Subject: [PATCH 108/176] helper/command: print the command output in case of error In case of error, a command should use command_print() to report the error message, so it get printed only on the session that run the command itself, and the message can be intercepted with the tcl command catch if it has to be handled differently. Current code drops the command output when the command returns error, claiming that it's the command that *should* have printed it already. This is true only if we *abuse* of the LOG functions, but accepting the side issue of having the LOG printed in every session and being unable to catch{} the error message. Since we have switched to command_print(), change the code to propagate the command output also in case of error. Change-Id: I95de424a65e63702bdb3b2277749a0ac6aaaa503 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5178 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index e8ade3f70..3346a6c37 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -623,15 +623,13 @@ static int run_command(struct command_context *context, } } else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) { /* just fall through for a shutdown request */ - } else if (retval != ERROR_OK) { - /* we do not print out an error message because the command *should* - * have printed out an error - */ - char *full_name = command_name(c, ' '); - LOG_DEBUG("Command '%s' failed with error code %d", - full_name ? full_name : c->name, retval); - free(full_name); } else { + if (retval != ERROR_OK) { + char *full_name = command_name(c, ' '); + LOG_DEBUG("Command '%s' failed with error code %d", + full_name ? full_name : c->name, retval); + free(full_name); + } /* Use the command output as the Tcl result */ Jim_SetResult(context->interp, cmd.output); } From 5b053ffd438714bbc0b002aaa5f0f0634a0f3fe2 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 5 Oct 2018 22:48:13 +0200 Subject: [PATCH 109/176] tcl/board: Add Renesas RZ/A1H GR-Peach board Add configuration for the Renesas RZ/A1H GR-Peach board, which is a cheap development kit for the RZ/A1H SoC. Change-Id: I7f5596ae47e6dff8e6d06cffd4dddca20f57d0ca Signed-off-by: Marek Vasut Reviewed-on: http://openocd.zylin.com/5142 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/board/renesas_gr_peach.cfg | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tcl/board/renesas_gr_peach.cfg diff --git a/tcl/board/renesas_gr_peach.cfg b/tcl/board/renesas_gr_peach.cfg new file mode 100644 index 000000000..ee6efe02b --- /dev/null +++ b/tcl/board/renesas_gr_peach.cfg @@ -0,0 +1,5 @@ +# Renesas RZ/A1H GR-Peach board + +reset_config srst_only + +source [find target/renesas_r7s72100.cfg] From 82e3a0e7cfa596e1b33e924036c82ab652b51619 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 5 Oct 2018 22:48:04 +0200 Subject: [PATCH 110/176] tcl/target: Add Renesas RZ/A1H target Add configuration for the Renesas RZ/A1H target. This is an SoC with one Cortex A9 ARMv7a core and up to 10 MiB of on-SoC SRAM. Change-Id: I20fd54b385fe1ba1cc325451c3fdfa3a835d4884 Signed-off-by: Marek Vasut Reviewed-on: http://openocd.zylin.com/5141 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/renesas_r7s72100.cfg | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tcl/target/renesas_r7s72100.cfg diff --git a/tcl/target/renesas_r7s72100.cfg b/tcl/target/renesas_r7s72100.cfg new file mode 100644 index 000000000..f9466fc2f --- /dev/null +++ b/tcl/target/renesas_r7s72100.cfg @@ -0,0 +1,25 @@ +# Renesas R-Car RZ/A1H +# https://www.renesas.com/eu/en/products/microcontrollers-microprocessors/rz/rza/rza1h.html + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME r7s72100 +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f -expected-id $_DAP_TAPID + +# Configuring only one core using DAP. +# Base addresses of cores: +# core 0 - 0x80030000 +set _TARGETNAME $_CHIPNAME.ca9 +dap create ${_CHIPNAME}.dap -chain-position $_CHIPNAME.cpu +target create ${_TARGETNAME} cortex_a -dap ${_CHIPNAME}.dap -coreid 0 -dbgbase 0x80030000 + +targets ${_TARGETNAME} From af952850b549124202903a24116d413fa145a769 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 2 Apr 2019 05:28:17 +0200 Subject: [PATCH 111/176] tcl/target: Fix V3M/V3H SoC chipname The V3M SoC is R8A77970 while the V3H SoC is R8A77980 . Update the CHIPNAME and swap the SoCs to keep the list sorted. Change-Id: I7e1777c0c7181e5e0beac98333f2047cb443d0df Signed-off-by: Marek Vasut Reviewed-on: http://openocd.zylin.com/5140 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/target/renesas_rcar_gen3.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tcl/target/renesas_rcar_gen3.cfg b/tcl/target/renesas_rcar_gen3.cfg index a6eef674b..2c478b268 100644 --- a/tcl/target/renesas_rcar_gen3.cfg +++ b/tcl/target/renesas_rcar_gen3.cfg @@ -47,17 +47,17 @@ switch $_soc { set _num_cr7 1 set _boot_core CA57 } - V3H { + V3M { set _CHIPNAME r8a77970 set _num_ca57 0 - set _num_ca53 4 + set _num_ca53 2 set _num_cr7 1 set _boot_core CA53 } - V3M { + V3H { set _CHIPNAME r8a77980 set _num_ca57 0 - set _num_ca53 2 + set _num_ca53 4 set _num_cr7 1 set _boot_core CA53 } From 11e5f022760a8ba497f41d0625d5757c313dc038 Mon Sep 17 00:00:00 2001 From: Steven Stallion Date: Tue, 21 May 2019 11:29:27 -0700 Subject: [PATCH 112/176] doc/openocd.texi: fix bad aarch64 merge The documentation added for commit b3d29cb5441ee5d38e8f7b561a58f03eb269dbe4 was merged after the end of the eSi-RISC section rather than AARCH64. This patch relocates this hunk to the correct location. Change-Id: I46a2d24442556e9e8000b46a5e1af03b83de6d98 Signed-off-by: Steven Stallion Reviewed-on: http://openocd.zylin.com/5181 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- doc/openocd.texi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 535fe3a80..57d1b0959 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9190,6 +9190,14 @@ Selects whether interrupts will be processed when single stepping. The default c @option{on}. @end deffn +@deffn Command {$target_name catch_exc} [@option{off}|@option{sec_el1}|@option{sec_el3}|@option{nsec_el1}|@option{nsec_el2}]+ +Cause @command{$target_name} to halt when an exception is taken. Any combination of +Secure (sec) EL1/EL3 or Non-Secure (nsec) EL1/EL2 is valid. The target +@command{$target_name} will halt before taking the exception. In order to resume +the target, the exception catch must be disabled again with @command{$target_name catch_exc off}. +Issuing the command without options prints the current configuration. +@end deffn + @section EnSilica eSi-RISC Architecture eSi-RISC is a highly configurable microprocessor architecture for embedded systems @@ -9333,7 +9341,7 @@ collection. @deffn Command {esirisc trace init} Initialize trace collection. This command must be called any time the -configuration changes. If an trace buffer has been configured, the contents will +configuration changes. If a trace buffer has been configured, the contents will be overwritten when trace collection starts. @end deffn @@ -9367,14 +9375,6 @@ be copied to an in-memory buffer identified by the @option{address} and @option{size} options using DMA. @end deffn -@deffn Command {$target_name catch_exc} [@option{off}|@option{sec_el1}|@option{sec_el3}|@option{nsec_el1}|@option{nsec_el2}]+ -Cause @command{$target_name} to halt when an exception is taken. Any combination of -Secure (sec) EL1/EL3 or Non-Secure (nsec) EL1/EL2 is valid. The target -@command{$target_name} will halt before taking the exception. In order to resume -the target, the exception catch must be disabled again with @command{$target_name catch_exc off}. -Issuing the command without options prints the current configuration. -@end deffn - @section Intel Architecture Intel Quark X10xx is the first product in the Quark family of SoCs. It is an IA-32 From 39504a695f759970fea2bcd7036d382fa5eab557 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Wed, 10 Apr 2019 14:16:13 -0700 Subject: [PATCH 113/176] stm32f7x: Use CHIPNAME-specific name for ITCM bank Change-Id: Icf67eaecd56ac3fb88bcfa2b7084b846109454e6 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5102 Tested-by: jenkins Reviewed-by: Freddie Chopin --- tcl/target/stm32f7x.cfg | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tcl/target/stm32f7x.cfg b/tcl/target/stm32f7x.cfg index 927a3e8d0..ba1d12ffb 100755 --- a/tcl/target/stm32f7x.cfg +++ b/tcl/target/stm32f7x.cfg @@ -51,9 +51,18 @@ set _FLASHNAME $_CHIPNAME.flash flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME flash bank $_CHIPNAME.otp stm32f2x 0x1ff0f000 0 0 0 $_TARGETNAME -# Configuring the Flash via ITCM alias as virtual -set _FLASH_ITCM_VMA itcm-flash.alias -flash bank $_FLASH_ITCM_VMA virtual 0x00200000 0 0 0 $_TARGETNAME $_FLASHNAME +# On the STM32F7, the Flash is mapped at address 0x08000000 via the AXI and +# also address 0x00200000 via the ITCM. The former mapping is read-write in +# hardware, while the latter is read-only. By presenting an alias, we +# accomplish two things: +# (1) We allow writing at 0x00200000 (because the alias acts identically to the +# original bank), which allows code intended to run from that address to +# also be linked for loading at that address, simplifying linking. +# (2) We allow the proper memory map to be delivered to GDB, which will cause +# it to use hardware breakpoints at the 0x00200000 mapping (correctly +# identifying it as Flash), which it would otherwise not do. Configuring +# the Flash via ITCM alias as virtual +flash bank $_CHIPNAME.itcm-flash.alias virtual 0x00200000 0 0 0 $_TARGETNAME $_FLASHNAME # adapter speed should be <= F_CPU/6. F_CPU after reset is 16MHz, so use F_JTAG = 2MHz adapter_khz 2000 From 5fbf4d4cc3f67ec8b2fb3d8a789117583a84e1a1 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 5 May 2019 14:32:37 +0200 Subject: [PATCH 114/176] target: remove unused function target_buffer_get_u8() Left unused after commit "target: unify memory read/write commands", can be removed. Change-Id: Iea6ef9204c8071283a66a679b3d6edbb0c929c5c Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5153 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index ee6ff3016..0401ff01c 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -375,12 +375,6 @@ uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer) return be_to_h_u16(buffer); } -/* read a uint8_t from a buffer in target memory endianness */ -static __attribute__((unused)) uint8_t target_buffer_get_u8(struct target *target, const uint8_t *buffer) -{ - return *buffer & 0x0ff; -} - /* write a uint64_t to a buffer in target memory endianness */ void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value) { From f912649968c2333a7a1d19aa7106e900b3d8527a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 7 Apr 2019 12:18:05 +0200 Subject: [PATCH 115/176] helper/command: remove dead code in command_unknown() Commit 89fa493a3bc34d22eeca06fa4e78523ac3b766a8 removes the top level command "unknown" and adds in command_unknown() some unclear code that should detect a user-implemented "unknown" command. But, all the commands that trigger the execution of the function command_unknown() are registered in register_command_handler() and have the command name prefixed with "ocd_". Due to such "ocd_" prefix in cmd_name, the condition if (strcmp(cmd_name, "unknown") == 0) { ... } is always false. Nobody complained for almost 10 years so we can proceed to remove this dead code, before merging any change that obsoletes the prefix "ocd_" and potentially makes the condition true. Remove the dead code guarded by the condition above. Change-Id: Icf11a956bb2d68fc84e6eb5779edf8e35db8fa53 Fixes: 89fa493a3bc3 ("remove unknown handler") Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5096 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index 3346a6c37..ab0654b6e 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1028,12 +1028,6 @@ static int run_usage(Jim_Interp *interp, int argc_valid, int argc, Jim_Obj * con static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { const char *cmd_name = Jim_GetString(argv[0], NULL); - if (strcmp(cmd_name, "unknown") == 0) { - if (argc == 1) - return JIM_OK; - argc--; - argv++; - } script_debug(interp, cmd_name, argc, argv); struct command_context *cmd_ctx = current_command_context(interp); From 5b768b0d39e629b71b5d729fb6a6919cda342630 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 7 May 2019 17:16:15 +0200 Subject: [PATCH 116/176] cortex_m: set the debug reason to DBGRQ when NVIC_DFSR indicates EXTERNAL By definition the EXTERNAL bit in Debug Fault Status Register indicates that an external debug request (EDBGRQ) signal was asserted. Usage example: this could be done by CTI in multicore devices in order to halt all the cores together. Change-Id: I7830455ce5da6702b7d08c8fa7bfe80e4d8a5055 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5157 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/cortex_m.c | 4 +++- src/target/cortex_m.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index fba832c78..ce3ab09c0 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -392,7 +392,9 @@ static int cortex_m_examine_debug_reason(struct target *target) target->debug_reason = DBG_REASON_WATCHPOINT; else if (cortex_m->nvic_dfsr & DFSR_VCATCH) target->debug_reason = DBG_REASON_BREAKPOINT; - else /* EXTERNAL, HALTED */ + else if (cortex_m->nvic_dfsr & DFSR_EXTERNAL) + target->debug_reason = DBG_REASON_DBGRQ; + else /* HALTED */ target->debug_reason = DBG_REASON_UNDEFINED; } diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index c33486273..2f29903c8 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -127,6 +127,7 @@ #define DFSR_BKPT 2 #define DFSR_DWTTRAP 4 #define DFSR_VCATCH 8 +#define DFSR_EXTERNAL 16 #define FPCR_CODE 0 #define FPCR_LITERAL 1 From f9bd26dfe0e741ea88afc0802f42e83afb42ff1a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 4 May 2019 15:23:30 +0200 Subject: [PATCH 117/176] HACKING: fix minor typos s/additonal/additional/ s/seperately/separately/ Use uppercase after a '.' Change-Id: I933894ae44924363d634fa07d3de4ceeb4b329e2 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5162 Tested-by: jenkins Reviewed-by: Jonathan McDowell Reviewed-by: Tomas Vanek --- HACKING | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HACKING b/HACKING index 39d98bb96..c1a6b0e8a 100644 --- a/HACKING +++ b/HACKING @@ -77,7 +77,7 @@ patch: src/openocd -s ../tcl -f /path/to/openocd.cfg @endcode -Please consider performing these additonal checks where appropriate +Please consider performing these additional checks where appropriate (especially Clang Static Analyzer for big portions of new code) and mention the results (e.g. "Valgrind-clean, no new Clang analyzer warnings") in the commit message. @@ -148,7 +148,7 @@ wget http://openocd.zylin.com/tools/hooks/commit-msg mv commit-msg .git/hooks chmod +x .git/hooks/commit-msg @endcode - \note A script exists to simplify the two items above. execute: + \note A script exists to simplify the two items above. Execute: @code tools/initial.sh @endcode @@ -160,7 +160,7 @@ git config --global user.email "john@smith.org" @endcode -# Work on your patches. Split the work into multiple small patches that can be reviewed and - applied seperately and safely to the OpenOCD + applied separately and safely to the OpenOCD repository. @code while(!done) { From 545a3de09b4d0ef090c730d94ecd368626658f8f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 5 May 2019 15:45:47 +0200 Subject: [PATCH 118/176] guess-rev.sh: fix minor typo s/reecognized/recognized/ Change-Id: I7129090d464d780632c0b7504e48fb90e847b30d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5163 Tested-by: jenkins Reviewed-by: Tomas Vanek --- guess-rev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guess-rev.sh b/guess-rev.sh index 7adbe2817..efe2659f9 100755 --- a/guess-rev.sh +++ b/guess-rev.sh @@ -79,5 +79,5 @@ if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then exit fi -# There's no reecognized repository; we must be a snapshot. +# There's no recognized repository; we must be a snapshot. printf -- '-snapshot' From 9ce5e8bc26fe913331bc3aeb7c3d87b4c4674d3d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 5 May 2019 15:49:19 +0200 Subject: [PATCH 119/176] configure.ac: fix minor typo s/overide/override/ Change-Id: Iecacf0d6839a4d23cb1b029f867d7e1a21d482a4 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5164 Tested-by: jenkins Reviewed-by: Tomas Vanek --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d4338dfbd..52844feb4 100644 --- a/configure.ac +++ b/configure.ac @@ -775,7 +775,7 @@ AS_IF([test "x${gcc_werror}" = "xyes"], [ GCC_WARNINGS="${GCC_WARNINGS} -Werror" ]) -# overide default gcc cflags +# override default gcc cflags AS_IF([test "x$gcc_warnings" = "xyes"], [ AC_SUBST([GCC_WARNINGS], [$GCC_WARNINGS]) ]) From 51ef02a5d161820f6d0be8f7984c3dc057b395a9 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Thu, 22 Nov 2018 19:05:04 +0100 Subject: [PATCH 120/176] target: make handle_md_output() global Remove a copy of handle_md_output() from src/target/dsp563xx.c Change-Id: Iadd003fd1dcdbc7990d46a58ee2e7c30826ac6af Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5175 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/dsp563xx.c | 63 +------------------------------------------ src/target/target.c | 4 +-- src/target/target.h | 5 ++++ 3 files changed, 8 insertions(+), 64 deletions(-) diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index d8285e49c..ef7a31aa6 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -1875,67 +1875,6 @@ static int dsp563xx_remove_watchpoint(struct target *target, struct watchpoint * return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } -static void handle_md_output(struct command_invocation *cmd, - struct target *target, - uint32_t address, - unsigned size, - unsigned count, - const uint8_t *buffer) -{ - const unsigned line_bytecnt = 32; - unsigned line_modulo = line_bytecnt / size; - - char output[line_bytecnt * 4 + 1]; - unsigned output_len = 0; - - const char *value_fmt; - switch (size) { - case 4: - value_fmt = "%8.8x "; - break; - case 2: - value_fmt = "%4.4x "; - break; - case 1: - value_fmt = "%2.2x "; - break; - default: - /* "can't happen", caller checked */ - LOG_ERROR("invalid memory read size: %u", size); - return; - } - - for (unsigned i = 0; i < count; i++) { - if (i % line_modulo == 0) - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - "0x%8.8x: ", - (unsigned) (address + i)); - - uint32_t value = 0; - const uint8_t *value_ptr = buffer + i * size; - switch (size) { - case 4: - value = target_buffer_get_u32(target, value_ptr); - break; - case 2: - value = target_buffer_get_u16(target, value_ptr); - break; - case 1: - value = *value_ptr; - } - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - value_fmt, - value); - - if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd, "%s", output); - output_len = 0; - } - } -} - static int dsp563xx_add_custom_watchpoint(struct target *target, uint32_t address, uint32_t memType, enum watchpoint_rw rw, enum watchpoint_condition cond) { @@ -2208,7 +2147,7 @@ COMMAND_HANDLER(dsp563xx_mem_command) err = dsp563xx_read_memory(target, mem_type, address, sizeof(uint32_t), count, buffer); if (err == ERROR_OK) - handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); + target_handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); } else { b = buffer; diff --git a/src/target/target.c b/src/target/target.c index 0401ff01c..1e42c5eea 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3119,7 +3119,7 @@ COMMAND_HANDLER(handle_step_command) return target->type->step(target, current_pc, addr, 1); } -static void handle_md_output(struct command_invocation *cmd, +void target_handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -3234,7 +3234,7 @@ COMMAND_HANDLER(handle_md_command) struct target *target = get_current_target(CMD_CTX); int retval = fn(target, address, size, count, buffer); if (ERROR_OK == retval) - handle_md_output(CMD, target, address, size, count, buffer); + target_handle_md_output(CMD, target, address, size, count, buffer); free(buffer); diff --git a/src/target/target.h b/src/target/target.h index 65494afd0..e944838ac 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -36,6 +36,7 @@ struct reg; struct trace; struct command_context; +struct command_invocation; struct breakpoint; struct watchpoint; struct mem_param; @@ -729,6 +730,10 @@ int target_arch_state(struct target *target); void target_handle_event(struct target *t, enum target_event e); +void target_handle_md_output(struct command_invocation *cmd, + struct target *target, target_addr_t address, unsigned size, + unsigned count, const uint8_t *buffer); + #define ERROR_TARGET_INVALID (-300) #define ERROR_TARGET_INIT_FAILED (-301) #define ERROR_TARGET_TIMEOUT (-302) From 2288394b4568d978ac63c66dc4dc163f7117e5c5 Mon Sep 17 00:00:00 2001 From: Leonard Crestez Date: Tue, 16 Apr 2019 22:12:18 +0300 Subject: [PATCH 121/176] arm_adi_v5: Split CSW bits into AHB/APB/AXI The implementation-defined bits have different semantics for each bus and different recommended defaults. Change-Id: I562fe24643bb1f3abc696339e382a75ccf2f2873 Signed-off-by: Leonard Crestez Reviewed-on: http://openocd.zylin.com/5124 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/arm_adi_v5.c | 2 +- src/target/arm_adi_v5.h | 31 +++++++++++++++++++++++++------ src/target/arm_dap.c | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 8ff5efd7a..d772d5c29 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1745,7 +1745,7 @@ COMMAND_HANDLER(dap_apcsw_command) return ERROR_OK; case 1: if (strcmp(CMD_ARGV[0], "default") == 0) - csw_val = CSW_DEFAULT; + csw_val = CSW_AHB_DEFAULT; else COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], csw_val); diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 0b61b757a..50fd359c8 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -112,15 +112,34 @@ #define CSW_ADDRINC_PACKED (2UL << 4) #define CSW_DEVICE_EN (1UL << 6) #define CSW_TRIN_PROG (1UL << 7) -/* all fields in bits 12 and above are implementation-defined! */ + +/* All fields in bits 12 and above are implementation-defined + * Defaults for AHB/AXI in "Standard Memory Access Port Definitions" from ADI + * Some bits are shared between buses + */ #define CSW_SPIDEN (1UL << 23) -#define CSW_HPROT1 (1UL << 25) /* AHB: Privileged */ -#define CSW_MASTER_DEBUG (1UL << 29) /* AHB: set HMASTER signals to AHB-AP ID */ -#define CSW_SPROT (1UL << 30) #define CSW_DBGSWENABLE (1UL << 31) -/* initial value of csw_default used for MEM-AP transfers */ -#define CSW_DEFAULT (CSW_HPROT1 | CSW_MASTER_DEBUG | CSW_DBGSWENABLE) +/* AHB: Privileged */ +#define CSW_AHB_HPROT1 (1UL << 25) +/* AHB: set HMASTER signals to AHB-AP ID */ +#define CSW_AHB_MASTER_DEBUG (1UL << 29) +/* AHB5: non-secure access via HNONSEC + * AHB3: SBO, UNPREDICTABLE if zero */ +#define CSW_AHB_SPROT (1UL << 30) +/* AHB: initial value of csw_default */ +#define CSW_AHB_DEFAULT (CSW_AHB_HPROT1 | CSW_AHB_MASTER_DEBUG | CSW_DBGSWENABLE) + +/* AXI: Privileged */ +#define CSW_AXI_ARPROT0_PRIV (1UL << 28) +/* AXI: Non-secure */ +#define CSW_AXI_ARPROT1_NONSEC (1UL << 29) +/* AXI: initial value of csw_default */ +#define CSW_AXI_DEFAULT (CSW_AXI_ARPROT0_PRIV | CSW_AXI_ARPROT1_NONSEC | CSW_DBGSWENABLE) + +/* APB: initial value of csw_default */ +#define CSW_APB_DEFAULT (CSW_DBGSWENABLE) + /* Fields of the MEM-AP's IDR register */ #define IDR_REV (0xFUL << 28) diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 5c15f2c10..fbcfe0d4d 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -56,7 +56,7 @@ static void dap_instance_init(struct adiv5_dap *dap) /* Number of bits for tar autoincrement, impl. dep. at least 10 */ dap->ap[i].tar_autoincr_block = (1<<10); /* default CSW value */ - dap->ap[i].csw_default = CSW_DEFAULT; + dap->ap[i].csw_default = CSW_AHB_DEFAULT; } INIT_LIST_HEAD(&dap->cmd_journal); } From cbf99d2df3d55ef8805d0ca5b98128cea2a5d220 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 6 May 2019 17:09:21 +0200 Subject: [PATCH 122/176] jtag/drivers/jtag_usb_common: Remove warning The warning appears for every possible device during enumeration and provides no useful information for an end-user. Change-Id: I56e7889a5d9d4656de13ad9e21be3a6e1906e05f Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5155 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/jtag_usb_common.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index 637e6c7f2..04b846eea 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -75,9 +75,6 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, /* walked the full path, all elements match */ if (path_step == path_len && !string_lengh) equal = true; - else - LOG_WARNING("excluded by device path option: %s\n", - jtag_usb_get_location()); done: free(loc); From 37ad15bcb3dae570d48df9d3efc4b1bfb6031e8c Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Thu, 2 Aug 2018 18:13:24 +0200 Subject: [PATCH 123/176] libjaylink: Update to latest Git version This version introduces jaylink_device_get_usb_bus_ports() Change-Id: Ib3fea95c3545c1340a6798e100f5ca644ec89510 Signed-off-by: Oleksij Rempel Reviewed-on: http://openocd.zylin.com/4629 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/libjaylink | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/drivers/libjaylink b/src/jtag/drivers/libjaylink index 8645845c1..4959f4e18 160000 --- a/src/jtag/drivers/libjaylink +++ b/src/jtag/drivers/libjaylink @@ -1 +1 @@ -Subproject commit 8645845c1abebd004e991ba9a7f808f4fd0c608b +Subproject commit 4959f4e18a2bb0de21abe66bbfe403b56f599856 From 9655da5aede7927b18bd9ae92a9fe310b76a99de Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 6 May 2019 17:01:22 +0200 Subject: [PATCH 124/176] jtag/drivers/jtag_usb_common: Fix variable name Change-Id: I3773afa75724dc71801af39cc9135b7b9585bc47 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5154 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/jtag_usb_common.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index 04b846eea..a0fa05865 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -37,13 +37,13 @@ const char *jtag_usb_get_location(void) bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len) { - size_t path_step, string_lengh; + size_t path_step, string_length; char *ptr, *loc; bool equal = false; /* strtok need non const char */ loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGHT); - string_lengh = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT); + string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT); ptr = strtok(loc, "-"); if (ptr == NULL) { @@ -51,7 +51,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, goto done; } - string_lengh -= 1; + string_length -= 1; /* check bus mismatch */ if (atoi(ptr) != dev_bus) goto done; @@ -69,11 +69,11 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, break; path_step++; - string_lengh -= 2; + string_length -= 2; }; /* walked the full path, all elements match */ - if (path_step == path_len && !string_lengh) + if (path_step == path_len && !string_length) equal = true; done: From 85ed41d2100ba2f451ba8ff3d75abbeb8cf10a29 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Wed, 4 Jul 2018 16:40:58 +0200 Subject: [PATCH 125/176] jlink: add usb location support this patch needs latest extended libjaylink version Change-Id: Ib688ba18740717ccce7863e08c09425975b5f153 Signed-off-by: Oleksij Rempel Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/4596 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/jlink.c | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index cc04953cd..8ce7c0d22 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -50,6 +51,7 @@ static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]; static uint32_t serial_number; static bool use_serial_number; +static bool use_usb_location; static enum jaylink_usb_address usb_address; static bool use_usb_address; static enum jaylink_target_interface iface = JAYLINK_TIF_JTAG; @@ -534,6 +536,31 @@ static int jaylink_log_handler(const struct jaylink_context *ctx, return 0; } +static bool jlink_usb_location_equal(struct jaylink_device *dev) +{ + int retval; + uint8_t bus; + uint8_t *ports; + size_t num_ports; + bool equal = false; + + retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports); + + if (retval == JAYLINK_ERR_NOT_SUPPORTED) { + return false; + } else if (retval != JAYLINK_OK) { + LOG_WARNING("jaylink_device_get_usb_bus_ports() failed: %s.", + jaylink_strerror(retval)); + return false; + } + + equal = jtag_usb_location_equal(bus, ports, num_ports); + free(ports); + + return equal; +} + + static int jlink_init(void) { int ret; @@ -595,7 +622,9 @@ static int jlink_init(void) return ERROR_JTAG_INIT_FAILED; } - if (!use_serial_number && !use_usb_address && num_devices > 1) { + use_usb_location = (jtag_usb_get_location() != NULL); + + if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) { LOG_ERROR("Multiple devices found, specify the desired device."); jaylink_free_devices(devs, true); jaylink_exit(jayctx); @@ -605,8 +634,10 @@ static int jlink_init(void) found_device = false; for (i = 0; devs[i]; i++) { + struct jaylink_device *dev = devs[i]; + if (use_serial_number) { - ret = jaylink_device_get_serial_number(devs[i], &tmp); + ret = jaylink_device_get_serial_number(dev, &tmp); if (ret == JAYLINK_ERR_NOT_AVAILABLE) { continue; @@ -621,7 +652,7 @@ static int jlink_init(void) } if (use_usb_address) { - ret = jaylink_device_get_usb_address(devs[i], &address); + ret = jaylink_device_get_usb_address(dev, &address); if (ret == JAYLINK_ERR_NOT_SUPPORTED) { continue; @@ -635,7 +666,10 @@ static int jlink_init(void) continue; } - ret = jaylink_open(devs[i], &devh); + if (use_usb_location && !jlink_usb_location_equal(dev)) + continue; + + ret = jaylink_open(dev, &devh); if (ret == JAYLINK_OK) { found_device = true; From eea508d9afa184684bf5a4e2788b6cd4b5fdc9ab Mon Sep 17 00:00:00 2001 From: Bohdan Tymkiv Date: Tue, 16 Apr 2019 17:28:29 +0300 Subject: [PATCH 126/176] gdb_server: fix GDB_BUFFER_SIZE usage, fix unaligned access during bulk transfers Currently size of the GDB buffer is 16384 bytes but it is treated as nul-terminated string in most of the code, so effective size of the buffer is actually 16383 bytes. OpenOCD responds with `PacketSize=3fff` to qSupported request. Result of GDB's `m` command is encoded in hex so each data byte uses two bytes in the buffer. As a result GDB will split bulk read requests into chunks 0x1fff bytes each. This causes troubles on targets (or memory regions) which support only aligned, word-sized access (such as MMIO buffers). Steps to reproduce (psoc6 target): gdb> dump binary memory dump.bin 0x040320000 (0x040320000 + 65536) OpenOCD: Error: Failed to read memory at 0x40321ffe Error: Failed to read memory at 0x40321000 Error: Failed to read memory at 0x40323000 Error: Failed to read memory at 0x40325ffe Error: Failed to read memory at 0x40329ffa Error: Failed to read memory at 0x40329ffc Error: Failed to read memory at 0x4032bffc Error: Failed to read memory at 0x4032dffa Consolidate GDB_BUFFER_SIZE usage: ensure size of each buffer is (GDB_BUFFER_SIZE + 1), add explicit comment that additional byte is used for nul-termination. Report correct size of the buffer to GDB (0x4000) as recommended in GDB's docummentation: `if the stub stores packets in a NUL-terminated format, it should allow an extra byte in its buffer for the NUL` Checked with clang-asan, clang-analyzer, valgrind - no new errors. Change-Id: I909e8a2c6b010c5d4a304641808d4a807a4ec18d Signed-off-by: Bohdan Tymkiv Reviewed-on: http://openocd.zylin.com/5109 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/rtos/nuttx.c | 2 +- src/rtos/rtos.c | 2 +- src/server/gdb_server.c | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/rtos/nuttx.c b/src/rtos/nuttx.c index 61fd9aa6c..8c3076e16 100644 --- a/src/rtos/nuttx.c +++ b/src/rtos/nuttx.c @@ -174,7 +174,7 @@ static int rcmd_offset(const char *cmd, const char *name) static int nuttx_thread_packet(struct connection *connection, char const *packet, int packet_size) { - char cmd[GDB_BUFFER_SIZE / 2] = ""; + char cmd[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for nul-termination */ if (!strncmp(packet, "qRcmd", 5)) { size_t len = unhexify((uint8_t *)cmd, packet + 6, sizeof(cmd)); diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index da0a50362..20e875d8b 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -223,7 +223,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s int rtos_detected = 0; uint64_t addr = 0; size_t reply_len; - char reply[GDB_BUFFER_SIZE], cur_sym[GDB_BUFFER_SIZE / 2] = ""; + char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for nul-termination */ symbol_table_elem_t *next_sym = NULL; struct target *target = get_target_from_connection(connection); struct rtos *os = target->rtos; diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index c6cf7d350..60ed4ce04 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -67,7 +67,7 @@ struct target_desc_format { /* private connection data for GDB */ struct gdb_connection { - char buffer[GDB_BUFFER_SIZE]; + char buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */ char *buf_p; int buf_cnt; int ctrl_c; @@ -1407,8 +1407,6 @@ static int gdb_error(struct connection *connection, int retval) /* We don't have to worry about the default 2 second timeout for GDB packets, * because GDB breaks up large memory reads into smaller reads. - * - * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192????? */ static int gdb_read_memory_packet(struct connection *connection, char const *packet, int packet_size) @@ -2614,7 +2612,7 @@ static int gdb_query_packet(struct connection *connection, &pos, &size, "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read%c;qXfer:threads:read+;QStartNoAckMode+;vContSupported+", - (GDB_BUFFER_SIZE - 1), + GDB_BUFFER_SIZE, ((gdb_use_memory_map == 1) && (flash_get_bank_count() > 0)) ? '+' : '-', (gdb_target_desc_supported == 1) ? '+' : '-'); @@ -3117,7 +3115,7 @@ static void gdb_sig_halted(struct connection *connection) static int gdb_input_inner(struct connection *connection) { /* Do not allocate this on the stack */ - static char gdb_packet_buffer[GDB_BUFFER_SIZE]; + static char gdb_packet_buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */ struct target *target; char const *packet = gdb_packet_buffer; @@ -3140,7 +3138,7 @@ static int gdb_input_inner(struct connection *connection) * drain the rest of the buffer. */ do { - packet_size = GDB_BUFFER_SIZE-1; + packet_size = GDB_BUFFER_SIZE; retval = gdb_get_packet(connection, gdb_packet_buffer, &packet_size); if (retval != ERROR_OK) return retval; From 8b9560349fb78887d8e353e20b303966d9ac2d1b Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Wed, 14 Dec 2016 01:33:17 +0100 Subject: [PATCH 127/176] Convert DEBUG_JTAG_IO to LOG_DEBUG_IO Change-Id: Ifee9723a57fea93a7022be3299f69680860f236b Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/3910 Tested-by: jenkins Reviewed-by: Tomas Vanek --- configure.ac | 13 -- src/jtag/aice/aice_interface.c | 2 +- src/jtag/aice/aice_usb.c | 4 +- src/jtag/commands.c | 40 ++--- src/jtag/drivers/amt_jtagaccel.c | 28 +-- src/jtag/drivers/arm-jtag-ew.c | 20 +-- src/jtag/drivers/bitbang.c | 30 +--- src/jtag/drivers/bitq.c | 33 +--- src/jtag/drivers/buspirate.c | 16 +- src/jtag/drivers/cmsis_dap_usb.c | 36 ++-- src/jtag/drivers/ft232r.c | 2 +- src/jtag/drivers/ftdi.c | 34 ++-- src/jtag/drivers/gw16012.c | 24 +-- src/jtag/drivers/jlink.c | 20 +-- src/jtag/drivers/mpsse.c | 68 ++++---- src/jtag/drivers/opendous.c | 24 +-- src/jtag/drivers/openjtag.c | 20 +-- src/jtag/drivers/rlink.c | 32 ++-- src/jtag/drivers/ulink.c | 190 +++++++++------------ src/jtag/drivers/usb_blaster/usb_blaster.c | 36 ++-- src/jtag/drivers/usbprog.c | 104 +++++------ src/jtag/drivers/vsllink.c | 44 ++--- src/jtag/interface.c | 13 +- src/jtag/interface.h | 24 ++- src/jtag/jtag.h | 8 - 25 files changed, 360 insertions(+), 505 deletions(-) diff --git a/configure.ac b/configure.ac index 52844feb4..9991dc89c 100644 --- a/configure.ac +++ b/configure.ac @@ -172,7 +172,6 @@ AC_ARG_ENABLE([werror], [gcc_werror=$enableval], [gcc_werror=$gcc_warnings]) # set default verbose options, overridden by following options -debug_jtag_io=no debug_usb_io=no debug_usb_comms=no @@ -180,16 +179,10 @@ AC_ARG_ENABLE([verbose], AS_HELP_STRING([--enable-verbose], [Enable verbose JTAG I/O messages (for debugging).]), [ - debug_jtag_io=$enableval debug_usb_io=$enableval debug_usb_comms=$enableval ], []) -AC_ARG_ENABLE([verbose_jtag_io], - AS_HELP_STRING([--enable-verbose-jtag-io], - [Enable verbose JTAG I/O messages (for debugging).]), - [debug_jtag_io=$enableval], []) - AC_ARG_ENABLE([verbose_usb_io], AS_HELP_STRING([--enable-verbose-usb-io], [Enable verbose USB I/O messages (for debugging)]), @@ -200,12 +193,6 @@ AC_ARG_ENABLE([verbose_usb_comms], [Enable verbose USB communication messages (for debugging)]), [debug_usb_comms=$enableval], []) -AC_MSG_CHECKING([whether to enable verbose JTAG I/O messages]); -AC_MSG_RESULT([$debug_jtag_io]) -AS_IF([test "x$debug_jtag_io" = "xyes"], [ - AC_DEFINE([_DEBUG_JTAG_IO_],[1], [Print verbose JTAG I/O messages]) -]) - AC_MSG_CHECKING([whether to enable verbose USB I/O messages]); AC_MSG_RESULT([$debug_usb_io]) AS_IF([test "x$debug_usb_io" = "xyes"], [ diff --git a/src/jtag/aice/aice_interface.c b/src/jtag/aice/aice_interface.c index 2aac5e93a..c83b8c298 100644 --- a/src/jtag/aice/aice_interface.c +++ b/src/jtag/aice/aice_interface.c @@ -150,7 +150,7 @@ static int aice_execute_reset(struct jtag_command *cmd) static int last_trst; int retval = ERROR_OK; - DEBUG_JTAG_IO("reset trst: %d", cmd->cmd.reset->trst); + LOG_DEBUG_IO("reset trst: %d", cmd->cmd.reset->trst); if (cmd->cmd.reset->trst != last_trst) { if (cmd->cmd.reset->trst) diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c index f67ea7ca3..af08ace05 100644 --- a/src/jtag/aice/aice_usb.c +++ b/src/jtag/aice/aice_usb.c @@ -400,7 +400,7 @@ static int aice_usb_write(uint8_t *out_buffer, int out_length) result = usb_bulk_write_ex(aice_handler.usb_handle, aice_handler.usb_write_ep, (char *)out_buffer, out_length, AICE_USB_TIMEOUT); - DEBUG_JTAG_IO("aice_usb_write, out_length = %i, result = %i", + LOG_DEBUG_IO("aice_usb_write, out_length = %i, result = %i", out_length, result); return result; @@ -412,7 +412,7 @@ static int aice_usb_read(uint8_t *in_buffer, int expected_size) int32_t result = usb_bulk_read_ex(aice_handler.usb_handle, aice_handler.usb_read_ep, (char *)in_buffer, expected_size, AICE_USB_TIMEOUT); - DEBUG_JTAG_IO("aice_usb_read, result = %" PRId32, result); + LOG_DEBUG_IO("aice_usb_read, result = %" PRId32, result); return result; } diff --git a/src/jtag/commands.c b/src/jtag/commands.c index e2d22cc94..3352e035a 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -193,33 +193,33 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer) bit_count = 0; - DEBUG_JTAG_IO("%s num_fields: %i", + LOG_DEBUG_IO("%s num_fields: %i", cmd->ir_scan ? "IRSCAN" : "DRSCAN", cmd->num_fields); for (i = 0; i < cmd->num_fields; i++) { if (cmd->fields[i].out_value) { -#ifdef _DEBUG_JTAG_IO_ - char *char_buf = buf_to_str(cmd->fields[i].out_value, - (cmd->fields[i].num_bits > DEBUG_JTAG_IOZ) - ? DEBUG_JTAG_IOZ - : cmd->fields[i].num_bits, 16); + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { + char *char_buf = buf_to_str(cmd->fields[i].out_value, + (cmd->fields[i].num_bits > DEBUG_JTAG_IOZ) + ? DEBUG_JTAG_IOZ + : cmd->fields[i].num_bits, 16); - LOG_DEBUG("fields[%i].out_value[%i]: 0x%s", i, - cmd->fields[i].num_bits, char_buf); - free(char_buf); -#endif + LOG_DEBUG("fields[%i].out_value[%i]: 0x%s", i, + cmd->fields[i].num_bits, char_buf); + free(char_buf); + } buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits); } else { - DEBUG_JTAG_IO("fields[%i].out_value[%i]: NULL", + LOG_DEBUG_IO("fields[%i].out_value[%i]: NULL", i, cmd->fields[i].num_bits); } bit_count += cmd->fields[i].num_bits; } - /*DEBUG_JTAG_IO("bit_count totalling: %i", bit_count); */ + /*LOG_DEBUG_IO("bit_count totalling: %i", bit_count); */ return bit_count; } @@ -242,16 +242,16 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd) uint8_t *captured = buf_set_buf(buffer, bit_count, malloc(DIV_ROUND_UP(num_bits, 8)), 0, num_bits); -#ifdef _DEBUG_JTAG_IO_ - char *char_buf = buf_to_str(captured, - (num_bits > DEBUG_JTAG_IOZ) + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { + char *char_buf = buf_to_str(captured, + (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ - : num_bits, 16); + : num_bits, 16); - LOG_DEBUG("fields[%i].in_value[%i]: 0x%s", - i, num_bits, char_buf); - free(char_buf); -#endif + LOG_DEBUG("fields[%i].in_value[%i]: 0x%s", + i, num_bits, char_buf); + free(char_buf); + } if (cmd->fields[i].in_value) buf_cpy(captured, cmd->fields[i].in_value, num_bits); diff --git a/src/jtag/drivers/amt_jtagaccel.c b/src/jtag/drivers/amt_jtagaccel.c index 9808e34b7..d6864c210 100644 --- a/src/jtag/drivers/amt_jtagaccel.c +++ b/src/jtag/drivers/amt_jtagaccel.c @@ -343,35 +343,27 @@ static int amt_jtagaccel_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1) tap_set_state(TAP_RESET); amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", - cmd->cmd.runtest->num_cycles, - cmd->cmd.runtest->end_state); -#endif + LOG_DEBUG_IO("runtest %i cycles, end in %i", + cmd->cmd.runtest->num_cycles, + cmd->cmd.runtest->end_state); amt_jtagaccel_end_state(cmd->cmd.runtest->end_state); amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); amt_jtagaccel_end_state(cmd->cmd.statemove->end_state); amt_jtagaccel_state_move(); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); -#endif + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); amt_jtagaccel_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); type = jtag_scan_type(cmd->cmd.scan); @@ -382,9 +374,7 @@ static int amt_jtagaccel_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %" PRIi32, cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index 665dd4d18..285bf9b7f 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -106,7 +106,7 @@ static int armjtagew_execute_queue(void) while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %i", + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ cmd->cmd.runtest->end_state); @@ -115,14 +115,14 @@ static int armjtagew_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); armjtagew_end_state(cmd->cmd.statemove->end_state); armjtagew_state_move(); break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %i", \ + LOG_DEBUG_IO("pathmove: %i states, end in %i", \ cmd->cmd.pathmove->num_states, \ cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -131,12 +131,12 @@ static int armjtagew_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); armjtagew_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - DEBUG_JTAG_IO("scan input, length = %d", scan_size); + LOG_DEBUG_IO("scan input, length = %d", scan_size); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(buffer, (scan_size + 7) / 8); @@ -148,7 +148,7 @@ static int armjtagew_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); @@ -160,7 +160,7 @@ static int armjtagew_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); armjtagew_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; @@ -647,7 +647,7 @@ static int armjtagew_tap_execute(void) /* Copy to buffer */ buf_set_buf(tdo_buffer, first, buffer, 0, length); - DEBUG_JTAG_IO("pending scan result, length = %d", length); + LOG_DEBUG_IO("pending scan result, length = %d", length); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(buffer, byte_length); @@ -747,7 +747,7 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length) result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \ (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT); - DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result); + LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(usb_out_buffer, out_length); @@ -761,7 +761,7 @@ static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length) int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, \ (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT); - DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result); + LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(usb_in_buffer, result); diff --git a/src/jtag/drivers/bitbang.c b/src/jtag/drivers/bitbang.c index da4fb3348..b5078c080 100644 --- a/src/jtag/drivers/bitbang.c +++ b/src/jtag/drivers/bitbang.c @@ -100,7 +100,7 @@ static int bitbang_execute_tms(struct jtag_command *cmd) unsigned num_bits = cmd->cmd.tms->num_bits; const uint8_t *bits = cmd->cmd.tms->bits; - DEBUG_JTAG_IO("TMS: %d bits", num_bits); + LOG_DEBUG_IO("TMS: %d bits", num_bits); int tms = 0; for (unsigned i = 0; i < num_bits; i++) { @@ -315,11 +315,9 @@ int bitbang_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) tap_set_state(TAP_RESET); @@ -328,11 +326,9 @@ int bitbang_execute_queue(void) return ERROR_FAIL; break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); -#endif bitbang_end_state(cmd->cmd.runtest->end_state); if (bitbang_runtest(cmd->cmd.runtest->num_cycles) != ERROR_OK) return ERROR_FAIL; @@ -347,32 +343,26 @@ int bitbang_execute_queue(void) break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); -#endif bitbang_end_state(cmd->cmd.statemove->end_state); if (bitbang_state_move(0) != ERROR_OK) return ERROR_FAIL; break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1])); -#endif if (bitbang_path_move(cmd->cmd.pathmove) != ERROR_OK) return ERROR_FAIL; break; case JTAG_SCAN: bitbang_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan %d bits; end in %s", + LOG_DEBUG_IO("%s scan %d bits; end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(cmd->cmd.scan->end_state)); -#endif type = jtag_scan_type(cmd->cmd.scan); if (bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size) != ERROR_OK) @@ -383,9 +373,7 @@ int bitbang_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %" PRIi32, cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_TMS: diff --git a/src/jtag/drivers/bitq.c b/src/jtag/drivers/bitq.c index 55dfe0aa4..9b4eeed72 100644 --- a/src/jtag/drivers/bitq.c +++ b/src/jtag/drivers/bitq.c @@ -59,9 +59,7 @@ static void bitq_in_proc(void) int tdo = bitq_interface->in(); if (tdo < 0) { -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("bitq in EOF"); -#endif + LOG_DEBUG_IO("bitq in EOF"); return; } if (in_mask == 0x01) @@ -228,9 +226,7 @@ int bitq_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) @@ -241,37 +237,26 @@ int bitq_execute_queue(void) break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); bitq_end_state(cmd->cmd.runtest->end_state); bitq_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); bitq_end_state(cmd->cmd.statemove->end_state); bitq_state_move(tap_get_end_state()); /* uncoditional TAP move */ break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif bitq_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); - if (cmd->cmd.scan->ir_scan) - LOG_DEBUG("scan ir"); - else - LOG_DEBUG("scan dr"); -#endif + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan %s", cmd->cmd.scan->ir_scan ? "ir" : "dr"); bitq_end_state(cmd->cmd.scan->end_state); bitq_scan(cmd->cmd.scan); if (tap_get_state() != tap_get_end_state()) @@ -279,9 +264,7 @@ int bitq_execute_queue(void) break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); bitq_interface->sleep(cmd->cmd.sleep->us); if (bitq_interface->in_rdy()) bitq_in_proc(); diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 14c719d4c..2e771cc85 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -171,7 +171,7 @@ static int buspirate_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest ->end_state)); @@ -181,7 +181,7 @@ static int buspirate_execute_queue(void) ->num_cycles); break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove ->end_state)); buspirate_end_state(cmd->cmd.statemove @@ -189,7 +189,7 @@ static int buspirate_execute_queue(void) buspirate_state_move(); break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove ->path[cmd->cmd.pathmove @@ -199,7 +199,7 @@ static int buspirate_execute_queue(void) cmd->cmd.pathmove->path); break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %s", + LOG_DEBUG_IO("scan end in %s", tap_state_name(cmd->cmd.scan ->end_state)); @@ -214,7 +214,7 @@ static int buspirate_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); /* flush buffers, so we can reset */ @@ -226,12 +226,12 @@ static int buspirate_execute_queue(void) cmd->cmd.reset->srst); break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); buspirate_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_STABLECLOCKS: - DEBUG_JTAG_IO("stable clock %i cycles", cmd->cmd.stableclocks->num_cycles); + LOG_DEBUG_IO("stable clock %i cycles", cmd->cmd.stableclocks->num_cycles); buspirate_stableclocks(cmd->cmd.stableclocks->num_cycles); break; default: @@ -624,7 +624,7 @@ static void buspirate_runtest(int num_cycles) for (i = 0; i < num_cycles; i++) buspirate_tap_append(0, 0); - DEBUG_JTAG_IO("runtest: cur_state %s end_state %s", + LOG_DEBUG_IO("runtest: cur_state %s end_state %s", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state())); diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 14a23d442..5c7cde46e 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -1246,7 +1246,7 @@ static void cmsis_dap_flush(void) if (!queued_seq_count) return; - DEBUG_JTAG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture", + LOG_DEBUG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture", queued_seq_count, queued_seq_buf_end, pending_scan_result_count); /* prep CMSIS-DAP packet */ @@ -1268,7 +1268,7 @@ static void cmsis_dap_flush(void) } #ifdef CMSIS_DAP_JTAG_DEBUG - DEBUG_JTAG_IO("USB response buf:"); + LOG_DEBUG_IO("USB response buf:"); for (int c = 0; c < queued_seq_buf_end + 3; ++c) printf("%02X ", buffer[c]); printf("\n"); @@ -1277,7 +1277,7 @@ static void cmsis_dap_flush(void) /* copy scan results into client buffers */ for (int i = 0; i < pending_scan_result_count; ++i) { struct pending_scan_result *scan = &pending_scan_results[i]; - DEBUG_JTAG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits", + LOG_DEBUG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits", i, pending_scan_result_count, scan->length, scan->first + 2, scan->buffer_offset); #ifdef CMSIS_DAP_JTAG_DEBUG for (uint32_t b = 0; b < DIV_ROUND_UP(scan->length, 8); ++b) @@ -1302,7 +1302,7 @@ static void cmsis_dap_flush(void) static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int s_offset, bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset) { - DEBUG_JTAG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d", + LOG_DEBUG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d", queued_seq_buf_end, s_len, tms ? "HIGH" : "LOW", s_offset, tdo_buffer, tdo_buffer_offset); @@ -1310,12 +1310,12 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int return; if (s_len > 64) { - DEBUG_JTAG_IO("START JTAG SEQ SPLIT"); + LOG_DEBUG_IO("START JTAG SEQ SPLIT"); for (int offset = 0; offset < s_len; offset += 64) { int len = s_len - offset; if (len > 64) len = 64; - DEBUG_JTAG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset); + LOG_DEBUG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset); cmsis_dap_add_jtag_sequence( len, sequence, @@ -1325,7 +1325,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int tdo_buffer == NULL ? 0 : (tdo_buffer_offset + offset) ); } - DEBUG_JTAG_IO("END JTAG SEQ SPLIT"); + LOG_DEBUG_IO("END JTAG SEQ SPLIT"); return; } @@ -1362,7 +1362,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int /* queue a sequence of bits to clock out TMS, executing if the buffer is full */ static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len) { - DEBUG_JTAG_IO("%d bits: %02X", s_len, *sequence); + LOG_DEBUG_IO("%d bits: %02X", s_len, *sequence); /* we use a series of CMD_DAP_JTAG_SEQ commands to toggle TMS, because even though it seems ridiculously inefficient, it allows us to combine TMS and scan sequences into the same @@ -1383,7 +1383,7 @@ static void cmsis_dap_state_move(void) tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); - DEBUG_JTAG_IO("state move from %s to %s: %d clocks, %02X on tms", + LOG_DEBUG_IO("state move from %s to %s: %d clocks, %02X on tms", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state()), tms_scan_bits, tms_scan); cmsis_dap_add_tms_sequence(&tms_scan, tms_scan_bits); @@ -1395,7 +1395,7 @@ static void cmsis_dap_state_move(void) /* Execute a JTAG scan operation by queueing TMS and TDI/TDO sequences */ static void cmsis_dap_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ @@ -1429,7 +1429,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -1437,7 +1437,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) field->num_bits); if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) { - DEBUG_JTAG_IO("Last field and have to move out of SHIFT state"); + LOG_DEBUG_IO("Last field and have to move out of SHIFT state"); /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap * movement. This last field can't have length zero, it was checked above. */ cmsis_dap_add_jtag_sequence( @@ -1471,7 +1471,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) 0); tap_set_state(tap_state_transition(tap_get_state(), 0)); } else { - DEBUG_JTAG_IO("Internal field, staying in SHIFT state afterwards"); + LOG_DEBUG_IO("Internal field, staying in SHIFT state afterwards"); /* Clocking part of a sequence into DR or IR with TMS=0, leaving TMS=0 at the end so we can continue later */ cmsis_dap_add_jtag_sequence( @@ -1489,7 +1489,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) cmsis_dap_state_move(); } - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } @@ -1519,7 +1519,7 @@ static void cmsis_dap_pathmove(int num_states, tap_state_t *path) static void cmsis_dap_execute_pathmove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("pathmove: %i states, end in %i", + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -1557,7 +1557,7 @@ static void cmsis_dap_runtest(int num_cycles) static void cmsis_dap_execute_runtest(struct jtag_command *cmd) { - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); cmsis_dap_end_state(cmd->cmd.runtest->end_state); @@ -1566,13 +1566,13 @@ static void cmsis_dap_execute_runtest(struct jtag_command *cmd) static void cmsis_dap_execute_stableclocks(struct jtag_command *cmd) { - DEBUG_JTAG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); + LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); cmsis_dap_stableclocks(cmd->cmd.runtest->num_cycles); } static void cmsis_dap_execute_tms(struct jtag_command *cmd) { - DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); + LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); cmsis_dap_cmd_DAP_SWJ_Sequence(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits); } diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c index 0389427d8..8cda76ed2 100644 --- a/src/jtag/drivers/ft232r.c +++ b/src/jtag/drivers/ft232r.c @@ -675,7 +675,7 @@ static int syncbb_execute_tms(struct jtag_command *cmd) unsigned num_bits = cmd->cmd.tms->num_bits; const uint8_t *bits = cmd->cmd.tms->bits; - DEBUG_JTAG_IO("TMS: %d bits", num_bits); + LOG_DEBUG_IO("TMS: %d bits", num_bits); int tms = 0; for (unsigned i = 0; i < num_bits; i++) { diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index 00ae8d0e0..60387a98f 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -262,7 +262,7 @@ static void move_to_state(tap_state_t goal_state) int tms_count = tap_get_tms_path_len(start_state, goal_state); assert(tms_count <= 8); - DEBUG_JTAG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); + LOG_DEBUG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); /* Track state transitions step by step */ for (int i = 0; i < tms_count; i++) @@ -324,7 +324,7 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) int i; uint8_t zero = 0; - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); @@ -345,14 +345,14 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("runtest: %i, end in %s", + LOG_DEBUG_IO("runtest: %i, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(tap_get_end_state())); } static void ftdi_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); ftdi_end_state(cmd->cmd.statemove->end_state); @@ -368,7 +368,7 @@ static void ftdi_execute_statemove(struct jtag_command *cmd) */ static void ftdi_execute_tms(struct jtag_command *cmd) { - DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); + LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); /* TODO: Missing tap state tracking, also missing from ft2232.c! */ mpsse_clock_tms_cs_out(mpsse_ctx, @@ -384,7 +384,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) tap_state_t *path = cmd->cmd.pathmove->path; int num_states = cmd->cmd.pathmove->num_states; - DEBUG_JTAG_IO("pathmove: %i states, current: %s end: %s", num_states, + LOG_DEBUG_IO("pathmove: %i states, current: %s end: %s", num_states, tap_state_name(tap_get_state()), tap_state_name(path[num_states-1])); @@ -392,7 +392,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) unsigned bit_count = 0; uint8_t tms_byte = 0; - DEBUG_JTAG_IO("-"); + LOG_DEBUG_IO("-"); /* this loop verifies that the path is legal and logs each state in the path */ while (num_states--) { @@ -432,18 +432,18 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) static void ftdi_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ while (cmd->cmd.scan->num_fields > 0 && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) { cmd->cmd.scan->num_fields--; - DEBUG_JTAG_IO("discarding trailing empty field"); + LOG_DEBUG_IO("discarding trailing empty field"); } if (cmd->cmd.scan->num_fields == 0) { - DEBUG_JTAG_IO("empty scan, doing nothing"); + LOG_DEBUG_IO("empty scan, doing nothing"); return; } @@ -462,7 +462,7 @@ static void ftdi_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -512,14 +512,14 @@ static void ftdi_execute_scan(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } static void ftdi_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1 @@ -555,17 +555,17 @@ static void ftdi_execute_reset(struct jtag_command *cmd) ftdi_set_signal(srst, 'z'); } - DEBUG_JTAG_IO("trst: %i, srst: %i", + LOG_DEBUG_IO("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); } static void ftdi_execute_sleep(struct jtag_command *cmd) { - DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); mpsse_flush(mpsse_ctx); jtag_sleep(cmd->cmd.sleep->us); - DEBUG_JTAG_IO("sleep %" PRIi32 " usec while in %s", + LOG_DEBUG_IO("sleep %" PRIi32 " usec while in %s", cmd->cmd.sleep->us, tap_state_name(tap_get_state())); } @@ -589,7 +589,7 @@ static void ftdi_execute_stableclocks(struct jtag_command *cmd) num_cycles -= this_len; } - DEBUG_JTAG_IO("clocks %i while in %s", + LOG_DEBUG_IO("clocks %i while in %s", cmd->cmd.stableclocks->num_cycles, tap_state_name(tap_get_state())); } diff --git a/src/jtag/drivers/gw16012.c b/src/jtag/drivers/gw16012.c index f91f7ac11..2971d4663 100644 --- a/src/jtag/drivers/gw16012.c +++ b/src/jtag/drivers/gw16012.c @@ -297,43 +297,33 @@ static int gw16012_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1) tap_set_state(TAP_RESET); gw16012_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif gw16012_end_state(cmd->cmd.runtest->end_state); gw16012_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); gw16012_end_state(cmd->cmd.statemove->end_state); gw16012_state_move(); break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif gw16012_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: gw16012_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); type = jtag_scan_type(cmd->cmd.scan); -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan (%i) %i bit end in %i", (cmd->cmd.scan->ir_scan) ? "ir" : "dr", + LOG_DEBUG_IO("%s scan (%i) %i bit end in %i", (cmd->cmd.scan->ir_scan) ? "ir" : "dr", type, scan_size, cmd->cmd.scan->end_state); -#endif gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; @@ -341,9 +331,7 @@ static int gw16012_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 8ce7c0d22..dd074937c 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -124,13 +124,13 @@ static int queued_retval; static void jlink_execute_stableclocks(struct jtag_command *cmd) { - DEBUG_JTAG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); + LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); jlink_stableclocks(cmd->cmd.runtest->num_cycles); } static void jlink_execute_runtest(struct jtag_command *cmd) { - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); jlink_end_state(cmd->cmd.runtest->end_state); @@ -139,7 +139,7 @@ static void jlink_execute_runtest(struct jtag_command *cmd) static void jlink_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); jlink_end_state(cmd->cmd.statemove->end_state); jlink_state_move(); @@ -147,7 +147,7 @@ static void jlink_execute_statemove(struct jtag_command *cmd) static void jlink_execute_pathmove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("pathmove: %i states, end in %i", + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -156,7 +156,7 @@ static void jlink_execute_pathmove(struct jtag_command *cmd) static void jlink_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ @@ -190,7 +190,7 @@ static void jlink_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -242,14 +242,14 @@ static void jlink_execute_scan(struct jtag_command *cmd) jlink_state_move(); } - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } static void jlink_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); jlink_flush(); @@ -259,7 +259,7 @@ static void jlink_execute_reset(struct jtag_command *cmd) static void jlink_execute_sleep(struct jtag_command *cmd) { - DEBUG_JTAG_IO("sleep %" PRIi32 "", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32 "", cmd->cmd.sleep->us); jlink_flush(); jtag_sleep(cmd->cmd.sleep->us); } @@ -2038,7 +2038,7 @@ static int jlink_flush(void) buf_set_buf(tdo_buffer, p->first, p->buffer, p->buffer_offset, p->length); - DEBUG_JTAG_IO("Pending scan result, length = %d.", p->length); + LOG_DEBUG_IO("Pending scan result, length = %d.", p->length); } jlink_tap_init(); diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 89248921a..a881803ad 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -29,26 +29,22 @@ #define LIBUSB_CALL #endif -#ifdef _DEBUG_JTAG_IO_ -#define DEBUG_IO(expr...) LOG_DEBUG(expr) #define DEBUG_PRINT_BUF(buf, len) \ do { \ - char buf_string[32 * 3 + 1]; \ - int buf_string_pos = 0; \ - for (int i = 0; i < len; i++) { \ - buf_string_pos += sprintf(buf_string + buf_string_pos, " %02x", buf[i]); \ - if (i % 32 == 32 - 1) { \ - LOG_DEBUG("%s", buf_string); \ - buf_string_pos = 0; \ + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { \ + char buf_string[32 * 3 + 1]; \ + int buf_string_pos = 0; \ + for (int i = 0; i < len; i++) { \ + buf_string_pos += sprintf(buf_string + buf_string_pos, " %02x", buf[i]); \ + if (i % 32 == 32 - 1) { \ + LOG_DEBUG_IO("%s", buf_string); \ + buf_string_pos = 0; \ + } \ } \ + if (buf_string_pos > 0) \ + LOG_DEBUG_IO("%s", buf_string);\ } \ - if (buf_string_pos > 0) \ - LOG_DEBUG("%s", buf_string);\ } while (0) -#else -#define DEBUG_IO(expr...) do {} while (0) -#define DEBUG_PRINT_BUF(buf, len) do {} while (0) -#endif #define FTDI_DEVICE_OUT_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE) #define FTDI_DEVICE_IN_REQTYPE (0x80 | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE) @@ -458,7 +454,7 @@ static unsigned buffer_read_space(struct mpsse_ctx *ctx) static void buffer_write_byte(struct mpsse_ctx *ctx, uint8_t data) { - DEBUG_IO("%02x", data); + LOG_DEBUG_IO("%02x", data); assert(ctx->write_count < ctx->write_size); ctx->write_buffer[ctx->write_count++] = data; } @@ -466,7 +462,7 @@ static void buffer_write_byte(struct mpsse_ctx *ctx, uint8_t data) static unsigned buffer_write(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned bit_count) { - DEBUG_IO("%d bits", bit_count); + LOG_DEBUG_IO("%d bits", bit_count); assert(ctx->write_count + DIV_ROUND_UP(bit_count, 8) <= ctx->write_size); bit_copy(ctx->write_buffer + ctx->write_count, 0, out, out_offset, bit_count); ctx->write_count += DIV_ROUND_UP(bit_count, 8); @@ -476,7 +472,7 @@ static unsigned buffer_write(struct mpsse_ctx *ctx, const uint8_t *out, unsigned static unsigned buffer_add_read(struct mpsse_ctx *ctx, uint8_t *in, unsigned in_offset, unsigned bit_count, unsigned offset) { - DEBUG_IO("%d bits, offset %d", bit_count, offset); + LOG_DEBUG_IO("%d bits, offset %d", bit_count, offset); assert(ctx->read_count + DIV_ROUND_UP(bit_count, 8) <= ctx->read_size); bit_copy_queued(&ctx->read_queue, in, in_offset, ctx->read_buffer + ctx->read_count, offset, bit_count); @@ -500,10 +496,10 @@ void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_of unsigned in_offset, unsigned length, uint8_t mode) { /* TODO: Fix MSB first modes */ - DEBUG_IO("%s%s %d bits", in ? "in" : "", out ? "out" : "", length); + LOG_DEBUG_IO("%s%s %d bits", in ? "in" : "", out ? "out" : "", length); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -576,11 +572,11 @@ void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, bool tdi, uint8_t mode) { - DEBUG_IO("%sout %d bits, tdi=%d", in ? "in" : "", length, tdi); + LOG_DEBUG_IO("%sout %d bits, tdi=%d", in ? "in" : "", length, tdi); assert(out); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -626,10 +622,10 @@ void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_ void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -643,10 +639,10 @@ void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t d void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -660,10 +656,10 @@ void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -676,10 +672,10 @@ void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data) void mpsse_read_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t *data) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -694,7 +690,7 @@ static void single_byte_boolean_helper(struct mpsse_ctx *ctx, bool var, uint8_t uint8_t val_if_false) { if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -715,7 +711,7 @@ void mpsse_set_divisor(struct mpsse_ctx *ctx, uint16_t divisor) LOG_DEBUG("%d", divisor); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -817,7 +813,7 @@ static LIBUSB_CALL void read_cb(struct libusb_transfer *transfer) } } - DEBUG_IO("raw chunk %d, transferred %d of %d", transfer->actual_length, res->transferred, + LOG_DEBUG_IO("raw chunk %d, transferred %d of %d", transfer->actual_length, res->transferred, ctx->read_count); if (!res->done) @@ -832,7 +828,7 @@ static LIBUSB_CALL void write_cb(struct libusb_transfer *transfer) res->transferred += transfer->actual_length; - DEBUG_IO("transferred %d of %d", res->transferred, ctx->write_count); + LOG_DEBUG_IO("transferred %d of %d", res->transferred, ctx->write_count); DEBUG_PRINT_BUF(transfer->buffer, transfer->actual_length); @@ -851,13 +847,13 @@ int mpsse_flush(struct mpsse_ctx *ctx) int retval = ctx->retval; if (retval != ERROR_OK) { - DEBUG_IO("Ignoring flush due to previous error"); + LOG_DEBUG_IO("Ignoring flush due to previous error"); assert(ctx->write_count == 0 && ctx->read_count == 0); ctx->retval = ERROR_OK; return retval; } - DEBUG_IO("write %d%s, read %d", ctx->write_count, ctx->read_count ? "+1" : "", + LOG_DEBUG_IO("write %d%s, read %d", ctx->write_count, ctx->read_count ? "+1" : "", ctx->read_count); assert(ctx->write_count > 0 || ctx->read_count == 0); /* No read data without write data */ diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index 2f8b524f7..c0595bf9f 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -252,7 +252,7 @@ static int opendous_execute_queue(void) while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ cmd->cmd.runtest->end_state); if (cmd->cmd.runtest->end_state != -1) @@ -261,7 +261,7 @@ static int opendous_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); if (cmd->cmd.statemove->end_state != -1) opendous_end_state(cmd->cmd.statemove->end_state); @@ -269,7 +269,7 @@ static int opendous_execute_queue(void) break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %i", \ + LOG_DEBUG_IO("pathmove: %i states, end in %i", \ cmd->cmd.pathmove->num_states, \ cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -277,13 +277,13 @@ static int opendous_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); if (cmd->cmd.scan->end_state != -1) opendous_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - DEBUG_JTAG_IO("scan input, length = %d", scan_size); + LOG_DEBUG_IO("scan input, length = %d", scan_size); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(buffer, (scan_size + 7) / 8); @@ -293,7 +293,7 @@ static int opendous_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); opendous_tap_execute(); @@ -303,7 +303,7 @@ static int opendous_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); opendous_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; @@ -528,7 +528,7 @@ void opendous_simple_command(uint8_t command, uint8_t _data) { int result; - DEBUG_JTAG_IO("0x%02x 0x%02x", command, _data); + LOG_DEBUG_IO("0x%02x 0x%02x", command, _data); usb_out_buffer[0] = 2; usb_out_buffer[1] = 0; @@ -597,7 +597,7 @@ void opendous_tap_append_step(int tms, int tdi) void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command) { - DEBUG_JTAG_IO("append scan, length = %d", length); + LOG_DEBUG_IO("append scan, length = %d", length); struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length]; int i; @@ -679,7 +679,7 @@ int opendous_tap_execute(void) /* Copy to buffer */ buf_set_buf(tdo_buffer, first, buffer, 0, length); - DEBUG_JTAG_IO("pending scan result, length = %d", length); + LOG_DEBUG_IO("pending scan result, length = %d", length); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(buffer, byte_length_out); @@ -770,7 +770,7 @@ int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length) LOG_DEBUG("USB write end: %d bytes", result); #endif - DEBUG_JTAG_IO("opendous_usb_write, out_length = %d, result = %d", out_length, result); + LOG_DEBUG_IO("opendous_usb_write, out_length = %d, result = %d", out_length, result); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(usb_out_buffer, out_length); @@ -796,7 +796,7 @@ int opendous_usb_read(struct opendous_jtag *opendous_jtag) #ifdef _DEBUG_USB_COMMS_ LOG_DEBUG("USB read end: %d bytes", result); #endif - DEBUG_JTAG_IO("opendous_usb_read, result = %d", result); + LOG_DEBUG_IO("opendous_usb_read, result = %d", result); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(usb_in_buffer, result); diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 8f11b4ba1..2ca8254b7 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -292,7 +292,7 @@ static int openjtag_buf_read_standard( qty - *bytes_read); if (retval < 0) { *bytes_read = 0; - DEBUG_JTAG_IO("ftdi_read_data: %s", + LOG_DEBUG_IO("ftdi_read_data: %s", ftdi_get_error_string(&ftdic)); return ERROR_JTAG_DEVICE_ERROR; } @@ -574,7 +574,7 @@ static int openjtag_execute_tap_queue(void) while (len > 0) { if (len <= 8 && openjtag_variant != OPENJTAG_VARIANT_CY7C65215) { - DEBUG_JTAG_IO("bits < 8 buf = 0x%X, will be 0x%X", + LOG_DEBUG_IO("bits < 8 buf = 0x%X, will be 0x%X", usb_rx_buf[rx_offs], usb_rx_buf[rx_offs] >> (8 - len)); buffer[count] = usb_rx_buf[rx_offs] >> (8 - len); len = 0; @@ -609,8 +609,8 @@ static void openjtag_add_byte(char buf) { if (usb_tx_buf_offs == OPENJTAG_BUFFER_SIZE) { - DEBUG_JTAG_IO("Forcing execute_tap_queue"); - DEBUG_JTAG_IO("TX Buff offs=%d", usb_tx_buf_offs); + LOG_DEBUG_IO("Forcing execute_tap_queue"); + LOG_DEBUG_IO("TX Buff offs=%d", usb_tx_buf_offs); openjtag_execute_tap_queue(); } @@ -624,8 +624,8 @@ static void openjtag_add_scan(uint8_t *buffer, int length, struct scan_command * /* Ensure space to send long chains */ /* We add two byte for each eight (or less) bits, one for command, one for data */ if (usb_tx_buf_offs + (DIV_ROUND_UP(length, 8) * 2) >= OPENJTAG_BUFFER_SIZE) { - DEBUG_JTAG_IO("Forcing execute_tap_queue from scan"); - DEBUG_JTAG_IO("TX Buff offs=%d len=%d", usb_tx_buf_offs, DIV_ROUND_UP(length, 8) * 2); + LOG_DEBUG_IO("Forcing execute_tap_queue from scan"); + LOG_DEBUG_IO("TX Buff offs=%d len=%d", usb_tx_buf_offs, DIV_ROUND_UP(length, 8) * 2); openjtag_execute_tap_queue(); } @@ -670,7 +670,7 @@ static void openjtag_add_scan(uint8_t *buffer, int length, struct scan_command * static void openjtag_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); uint8_t buf = 0x00; @@ -703,7 +703,7 @@ static void openjtag_set_state(uint8_t openocd_state) static void openjtag_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("state move to %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("state move to %i", cmd->cmd.statemove->end_state); tap_set_end_state(cmd->cmd.statemove->end_state); @@ -719,7 +719,7 @@ static void openjtag_execute_scan(struct jtag_command *cmd) int scan_size, old_state; uint8_t *buffer; - DEBUG_JTAG_IO("scan ends in %s", tap_state_name(cmd->cmd.scan->end_state)); + LOG_DEBUG_IO("scan ends in %s", tap_state_name(cmd->cmd.scan->end_state)); /* get scan info */ tap_set_end_state(cmd->cmd.scan->end_state); @@ -778,7 +778,7 @@ static void openjtag_execute_runtest(struct jtag_command *cmd) static void openjtag_execute_command(struct jtag_command *cmd) { - DEBUG_JTAG_IO("openjtag_execute_command %i", cmd->type); + LOG_DEBUG_IO("openjtag_execute_command %i", cmd->type); switch (cmd->type) { case JTAG_RESET: openjtag_execute_reset(cmd); diff --git a/src/jtag/drivers/rlink.c b/src/jtag/drivers/rlink.c index 3f9e33268..70f8734b5 100644 --- a/src/jtag/drivers/rlink.c +++ b/src/jtag/drivers/rlink.c @@ -1299,11 +1299,9 @@ static int rlink_execute_queue(void) switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) @@ -1311,37 +1309,29 @@ static int rlink_execute_queue(void) rlink_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif if (cmd->cmd.runtest->end_state != -1) rlink_end_state(cmd->cmd.runtest->end_state); rlink_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); if (cmd->cmd.statemove->end_state != -1) rlink_end_state(cmd->cmd.statemove->end_state); rlink_state_move(); break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", - cmd->cmd.pathmove->num_states, - cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif + LOG_DEBUG_IO("pathmove: %i states, end in %i", + cmd->cmd.pathmove->num_states, + cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); rlink_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan end in %i", - (cmd->cmd.scan->ir_scan) ? "IR" : "DR", - cmd->cmd.scan->end_state); -#endif + LOG_DEBUG_IO("%s scan end in %i", + (cmd->cmd.scan->ir_scan) ? "IR" : "DR", + cmd->cmd.scan->end_state); if (cmd->cmd.scan->end_state != -1) rlink_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); @@ -1350,9 +1340,7 @@ static int rlink_execute_queue(void) retval = ERROR_FAIL; break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index 550df1c93..bbe08aae7 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -187,12 +187,7 @@ void ulink_clear_queue(struct ulink *device); int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd); int ulink_execute_queued_commands(struct ulink *device, int timeout); -#ifdef _DEBUG_JTAG_IO_ -const char *ulink_cmd_id_string(uint8_t id); -void ulink_print_command(struct ulink_cmd *ulink_cmd); -void ulink_print_queue(struct ulink *device); -static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f); -#endif +static void ulink_print_queue(struct ulink *device); int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type, @@ -708,9 +703,8 @@ int ulink_execute_queued_commands(struct ulink *device, int timeout) int ret, i, index_out, index_in, count_out, count_in, transferred; uint8_t buffer[64]; -#ifdef _DEBUG_JTAG_IO_ - ulink_print_queue(device); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + ulink_print_queue(device); index_out = 0; count_out = 0; @@ -759,71 +753,69 @@ int ulink_execute_queued_commands(struct ulink *device, int timeout) return ERROR_OK; } -#ifdef _DEBUG_JTAG_IO_ - /** * Convert an OpenULINK command ID (\a id) to a human-readable string. * * @param id the OpenULINK command ID. * @return the corresponding human-readable string. */ -const char *ulink_cmd_id_string(uint8_t id) +static const char *ulink_cmd_id_string(uint8_t id) { switch (id) { - case CMD_SCAN_IN: - return "CMD_SCAN_IN"; - break; - case CMD_SLOW_SCAN_IN: - return "CMD_SLOW_SCAN_IN"; - break; - case CMD_SCAN_OUT: - return "CMD_SCAN_OUT"; - break; - case CMD_SLOW_SCAN_OUT: - return "CMD_SLOW_SCAN_OUT"; - break; - case CMD_SCAN_IO: - return "CMD_SCAN_IO"; - break; - case CMD_SLOW_SCAN_IO: - return "CMD_SLOW_SCAN_IO"; - break; - case CMD_CLOCK_TMS: - return "CMD_CLOCK_TMS"; - break; - case CMD_SLOW_CLOCK_TMS: - return "CMD_SLOW_CLOCK_TMS"; - break; - case CMD_CLOCK_TCK: - return "CMD_CLOCK_TCK"; - break; - case CMD_SLOW_CLOCK_TCK: - return "CMD_SLOW_CLOCK_TCK"; - break; - case CMD_SLEEP_US: - return "CMD_SLEEP_US"; - break; - case CMD_SLEEP_MS: - return "CMD_SLEEP_MS"; - break; - case CMD_GET_SIGNALS: - return "CMD_GET_SIGNALS"; - break; - case CMD_SET_SIGNALS: - return "CMD_SET_SIGNALS"; - break; - case CMD_CONFIGURE_TCK_FREQ: - return "CMD_CONFIGURE_TCK_FREQ"; - break; - case CMD_SET_LEDS: - return "CMD_SET_LEDS"; - break; - case CMD_TEST: - return "CMD_TEST"; - break; - default: - return "CMD_UNKNOWN"; - break; + case CMD_SCAN_IN: + return "CMD_SCAN_IN"; + break; + case CMD_SLOW_SCAN_IN: + return "CMD_SLOW_SCAN_IN"; + break; + case CMD_SCAN_OUT: + return "CMD_SCAN_OUT"; + break; + case CMD_SLOW_SCAN_OUT: + return "CMD_SLOW_SCAN_OUT"; + break; + case CMD_SCAN_IO: + return "CMD_SCAN_IO"; + break; + case CMD_SLOW_SCAN_IO: + return "CMD_SLOW_SCAN_IO"; + break; + case CMD_CLOCK_TMS: + return "CMD_CLOCK_TMS"; + break; + case CMD_SLOW_CLOCK_TMS: + return "CMD_SLOW_CLOCK_TMS"; + break; + case CMD_CLOCK_TCK: + return "CMD_CLOCK_TCK"; + break; + case CMD_SLOW_CLOCK_TCK: + return "CMD_SLOW_CLOCK_TCK"; + break; + case CMD_SLEEP_US: + return "CMD_SLEEP_US"; + break; + case CMD_SLEEP_MS: + return "CMD_SLEEP_MS"; + break; + case CMD_GET_SIGNALS: + return "CMD_GET_SIGNALS"; + break; + case CMD_SET_SIGNALS: + return "CMD_SET_SIGNALS"; + break; + case CMD_CONFIGURE_TCK_FREQ: + return "CMD_CONFIGURE_TCK_FREQ"; + break; + case CMD_SET_LEDS: + return "CMD_SET_LEDS"; + break; + case CMD_TEST: + return "CMD_TEST"; + break; + default: + return "CMD_UNKNOWN"; + break; } } @@ -832,7 +824,7 @@ const char *ulink_cmd_id_string(uint8_t id) * * @param ulink_cmd pointer to OpenULINK command. */ -void ulink_print_command(struct ulink_cmd *ulink_cmd) +static void ulink_print_command(struct ulink_cmd *ulink_cmd) { int i; @@ -850,7 +842,7 @@ void ulink_print_command(struct ulink_cmd *ulink_cmd) * * @param device pointer to struct ulink identifying ULINK driver instance. */ -void ulink_print_queue(struct ulink *device) +static void ulink_print_queue(struct ulink *device) { struct ulink_cmd *current; @@ -860,8 +852,6 @@ void ulink_print_queue(struct ulink *device) ulink_print_command(current); } -#endif /* _DEBUG_JTAG_IO_ */ - /** * Perform JTAG scan * @@ -1367,7 +1357,6 @@ int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay) return ERROR_OK; } -#ifdef _DEBUG_JTAG_IO_ /** * Calculate frequency for a given delay value. * @@ -1378,16 +1367,14 @@ int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay) * * @param type for which command to calculate the delay value. * @param delay delay value for which to calculate the resulting TCK frequency. - * @param f where to store the resulting TCK frequency. - * @return on success: ERROR_OK - * @return on failure: ERROR_FAIL + * @return the resulting TCK frequency */ -static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f) +static long ulink_calculate_frequency(enum ulink_delay_type type, int delay) { - float t, f_float, f_rounded; + float t, f_float; if (delay > 255) - return ERROR_FAIL; + return 0; switch (type) { case DELAY_CLOCK_TCK: @@ -1421,17 +1408,12 @@ static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long t = (float)(4E-6) * (float)(delay) + (float)(1.3132E-5); break; default: - return ERROR_FAIL; - break; + return 0; } f_float = 1.0 / t; - f_rounded = roundf(f_float); - *f = (long)f_rounded; - - return ERROR_OK; + return roundf(f_float); } -#endif /******************* Interface between OpenULINK and OpenOCD ******************/ @@ -2065,31 +2047,21 @@ static int ulink_khz(int khz, int *jtag_speed) return ret; } -#ifdef _DEBUG_JTAG_IO_ - long f_tck = 0, f_tms = 0, f_scan_in = 0, f_scan_out = 0, f_scan_io = 0; - - ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck, - &f_tck); - ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms, - &f_tms); - ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in, - &f_scan_in); - ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out, - &f_scan_out); - ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io, - &f_scan_io); - - DEBUG_JTAG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),", - ulink_handle->delay_clock_tck, f_tck); - DEBUG_JTAG_IO(" delay_tms = %i (%li Hz),", - ulink_handle->delay_clock_tms, f_tms); - DEBUG_JTAG_IO(" delay_scan_in = %i (%li Hz),", - ulink_handle->delay_scan_in, f_scan_in); - DEBUG_JTAG_IO(" delay_scan_out = %i (%li Hz),", - ulink_handle->delay_scan_out, f_scan_out); - DEBUG_JTAG_IO(" delay_scan_io = %i (%li Hz),", - ulink_handle->delay_scan_io, f_scan_io); -#endif + LOG_DEBUG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),", + ulink_handle->delay_clock_tck, + ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck)); + LOG_DEBUG_IO(" delay_tms = %i (%li Hz),", + ulink_handle->delay_clock_tms, + ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms)); + LOG_DEBUG_IO(" delay_scan_in = %i (%li Hz),", + ulink_handle->delay_scan_in, + ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in)); + LOG_DEBUG_IO(" delay_scan_out = %i (%li Hz),", + ulink_handle->delay_scan_out, + ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out)); + LOG_DEBUG_IO(" delay_scan_io = %i (%li Hz),", + ulink_handle->delay_scan_io, + ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io)); /* Configure the ULINK device with the new delay values */ ret = ulink_append_configure_tck_cmd(ulink_handle, diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 8ccf87172..55b511e1a 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -174,7 +174,7 @@ static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read) int ret = info.drv->read(info.drv, buf, size, bytes_read); char *str = hexdump(buf, *bytes_read); - DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str, + LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str, *bytes_read); free(str); return ret; @@ -185,7 +185,7 @@ static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written) int ret = info.drv->write(info.drv, buf, size, bytes_written); char *str = hexdump(buf, *bytes_written); - DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str, + LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str, *bytes_written); free(str); return ret; @@ -266,7 +266,7 @@ static void ublast_queue_byte(uint8_t abyte) info.buf[info.bufidx++] = abyte; if (nb_buf_remaining() == 0) ublast_flush_buffer(); - DEBUG_JTAG_IO("(byte=0x%02x)", abyte); + LOG_DEBUG_IO("(byte=0x%02x)", abyte); } /** @@ -337,7 +337,7 @@ static void ublast_clock_tms(int tms) { uint8_t out; - DEBUG_JTAG_IO("(tms=%d)", !!tms); + LOG_DEBUG_IO("(tms=%d)", !!tms); info.tms = !!tms; info.tdi = 0; out = ublast_build_out(SCAN_OUT); @@ -354,7 +354,7 @@ static void ublast_idle_clock(void) { uint8_t out = ublast_build_out(SCAN_OUT); - DEBUG_JTAG_IO("."); + LOG_DEBUG_IO("."); ublast_queue_byte(out); } @@ -375,7 +375,7 @@ static void ublast_clock_tdi(int tdi, enum scan_type type) { uint8_t out; - DEBUG_JTAG_IO("(tdi=%d)", !!tdi); + LOG_DEBUG_IO("(tdi=%d)", !!tdi); info.tdi = !!tdi; out = ublast_build_out(SCAN_OUT); @@ -400,7 +400,7 @@ static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type) { uint8_t out; - DEBUG_JTAG_IO("(tdi=%d)", !!tdi); + LOG_DEBUG_IO("(tdi=%d)", !!tdi); info.tdi = !!tdi; info.tms = !info.tms; @@ -430,7 +430,7 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes) info.bufidx + nb_bytes); exit(-1); } - DEBUG_JTAG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes, + LOG_DEBUG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes, bytes ? bytes[0] : 0); if (bytes) memcpy(&info.buf[info.bufidx], bytes, nb_bytes); @@ -457,7 +457,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip) { int i; - DEBUG_JTAG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits); + LOG_DEBUG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits); for (i = skip; i < nb_bits; i++) ublast_clock_tms((bits[i / 8] >> (i % 8)) & 0x01); ublast_idle_clock(); @@ -469,7 +469,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip) */ static void ublast_tms(struct tms_command *cmd) { - DEBUG_JTAG_IO("(num_bits=%d)", cmd->num_bits); + LOG_DEBUG_IO("(num_bits=%d)", cmd->num_bits); ublast_tms_seq(cmd->bits, cmd->num_bits, 0); } @@ -487,7 +487,7 @@ static void ublast_path_move(struct pathmove_command *cmd) { int i; - DEBUG_JTAG_IO("(num_states=%d, last_state=%d)", + LOG_DEBUG_IO("(num_states=%d, last_state=%d)", cmd->num_states, cmd->path[cmd->num_states - 1]); for (i = 0; i < cmd->num_states; i++) { if (tap_state_transition(tap_get_state(), false) == cmd->path[i]) @@ -512,7 +512,7 @@ static void ublast_state_move(tap_state_t state, int skip) uint8_t tms_scan; int tms_len; - DEBUG_JTAG_IO("(from %s to %s)", tap_state_name(tap_get_state()), + LOG_DEBUG_IO("(from %s to %s)", tap_state_name(tap_get_state()), tap_state_name(state)); if (tap_get_state() == state) return; @@ -541,7 +541,7 @@ static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes) unsigned int retlen; int ret = ERROR_OK; - DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8); + LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8); ublast_flush_buffer(); while (ret == ERROR_OK && nb_bytes > 0) { ret = ublast_buf_read(buf, nb_bytes, &retlen); @@ -573,7 +573,7 @@ static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits) unsigned int retlen; uint8_t tmp[8]; - DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits); + LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits); /* * Ensure all previous bitbang writes were issued to the dongle, so that @@ -688,7 +688,7 @@ static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan) static void ublast_runtest(int cycles, tap_state_t state) { - DEBUG_JTAG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state); + LOG_DEBUG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state); ublast_state_move(TAP_IDLE, 0); ublast_queue_tdi(NULL, cycles, SCAN_OUT); @@ -697,7 +697,7 @@ static void ublast_runtest(int cycles, tap_state_t state) static void ublast_stableclocks(int cycles) { - DEBUG_JTAG_IO("%s(cycles=%i)", __func__, cycles); + LOG_DEBUG_IO("%s(cycles=%i)", __func__, cycles); ublast_queue_tdi(NULL, cycles, SCAN_OUT); } @@ -727,7 +727,7 @@ static int ublast_scan(struct scan_command *cmd) ublast_state_move(TAP_DRSHIFT, 0); log_buf = hexdump(buf, DIV_ROUND_UP(scan_bits, 8)); - DEBUG_JTAG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__, + LOG_DEBUG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__, cmd->ir_scan ? "IRSCAN" : "DRSCAN", type2str[type], scan_bits, log_buf, cmd->end_state); @@ -749,7 +749,7 @@ static int ublast_scan(struct scan_command *cmd) static void ublast_usleep(int us) { - DEBUG_JTAG_IO("%s(us=%d)", __func__, us); + LOG_DEBUG_IO("%s(us=%d)", __func__, us); jtag_sleep(us); } diff --git a/src/jtag/drivers/usbprog.c b/src/jtag/drivers/usbprog.c index d81c329d4..bcbaff8d8 100644 --- a/src/jtag/drivers/usbprog.c +++ b/src/jtag/drivers/usbprog.c @@ -103,62 +103,50 @@ static int usbprog_execute_queue(void) while (cmd) { switch (cmd->type) { - case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif - if (cmd->cmd.reset->trst == 1) - tap_set_state(TAP_RESET); - usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); - break; - case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", - cmd->cmd.runtest->num_cycles, - cmd->cmd.runtest->end_state); -#endif - usbprog_end_state(cmd->cmd.runtest->end_state); - usbprog_runtest(cmd->cmd.runtest->num_cycles); - break; - case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif - usbprog_end_state(cmd->cmd.statemove->end_state); - usbprog_state_move(); - break; - case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", - cmd->cmd.pathmove->num_states, - cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif - usbprog_path_move(cmd->cmd.pathmove); - break; - case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); -#endif - usbprog_end_state(cmd->cmd.scan->end_state); - scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - type = jtag_scan_type(cmd->cmd.scan); - usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); - if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) - return ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); - break; - case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif - jtag_sleep(cmd->cmd.sleep->us); - break; - default: - LOG_ERROR("BUG: unknown JTAG command type encountered"); - exit(-1); + case JTAG_RESET: + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); + if (cmd->cmd.reset->trst == 1) + tap_set_state(TAP_RESET); + usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); + break; + case JTAG_RUNTEST: + LOG_DEBUG_IO("runtest %i cycles, end in %i", + cmd->cmd.runtest->num_cycles, + cmd->cmd.runtest->end_state); + usbprog_end_state(cmd->cmd.runtest->end_state); + usbprog_runtest(cmd->cmd.runtest->num_cycles); + break; + case JTAG_TLR_RESET: + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + usbprog_end_state(cmd->cmd.statemove->end_state); + usbprog_state_move(); + break; + case JTAG_PATHMOVE: + LOG_DEBUG_IO("pathmove: %i states, end in %i", + cmd->cmd.pathmove->num_states, + cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); + usbprog_path_move(cmd->cmd.pathmove); + break; + case JTAG_SCAN: + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); + usbprog_end_state(cmd->cmd.scan->end_state); + scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); + type = jtag_scan_type(cmd->cmd.scan); + usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); + if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) + return ERROR_JTAG_QUEUE_FAILED; + if (buffer) + free(buffer); + break; + case JTAG_SLEEP: + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); + jtag_sleep(cmd->cmd.sleep->us); + break; + default: + LOG_ERROR("BUG: unknown JTAG command type encountered"); + exit(-1); } cmd = cmd->next; @@ -270,10 +258,8 @@ static void usbprog_runtest(int num_cycles) usbprog_write(0, 0, 0); } -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name( + LOG_DEBUG_IO("runtest: cur_state %s end_state %s", tap_state_name( tap_get_state()), tap_state_name(tap_get_end_state())); -#endif /* finish in end_state */ /* diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index ea9152c09..501322bba 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -82,9 +82,7 @@ struct vsllink { static int vsllink_usb_open(struct vsllink *vsllink); static void vsllink_usb_close(struct vsllink *vsllink); -#if defined _DEBUG_JTAG_IO_ static void vsllink_debug_buffer(uint8_t *buffer, int length); -#endif static int tap_length; static int tap_buffer_size; @@ -103,14 +101,14 @@ static int vsllink_execute_queue(void) enum scan_type type; uint8_t *buffer; - DEBUG_JTAG_IO("-------------------------------------" + LOG_DEBUG_IO("-------------------------------------" " vsllink " "-------------------------------------"); while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); @@ -119,7 +117,7 @@ static int vsllink_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); vsllink_end_state(cmd->cmd.statemove->end_state); @@ -127,7 +125,7 @@ static int vsllink_execute_queue(void) break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1])); @@ -135,7 +133,7 @@ static int vsllink_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("JTAG Scan..."); + LOG_DEBUG_IO("JTAG Scan..."); vsllink_end_state(cmd->cmd.scan->end_state); @@ -143,23 +141,21 @@ static int vsllink_execute_queue(void) cmd->cmd.scan, &buffer); if (cmd->cmd.scan->ir_scan) - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG Scan write IR(%d bits), " "end in %s:", scan_size, tap_state_name(cmd->cmd.scan->end_state)); else - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG Scan write DR(%d bits), " "end in %s:", scan_size, tap_state_name(cmd->cmd.scan->end_state)); -#ifdef _DEBUG_JTAG_IO_ - vsllink_debug_buffer(buffer, - DIV_ROUND_UP(scan_size, 8)); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + vsllink_debug_buffer(buffer, DIV_ROUND_UP(scan_size, 8)); type = jtag_scan_type(cmd->cmd.scan); @@ -169,7 +165,7 @@ static int vsllink_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); @@ -183,13 +179,13 @@ static int vsllink_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); vsllink_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_STABLECLOCKS: - DEBUG_JTAG_IO("add %d clocks", + LOG_DEBUG_IO("add %d clocks", cmd->cmd.stableclocks->num_cycles); switch (tap_get_state()) { @@ -219,7 +215,7 @@ static int vsllink_execute_queue(void) break; case JTAG_TMS: - DEBUG_JTAG_IO("add %d jtag tms", + LOG_DEBUG_IO("add %d jtag tms", cmd->cmd.tms->num_bits); vsllink_tms(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits); @@ -681,13 +677,11 @@ static int vsllink_jtag_execute(void) command = pending_scan_result->command; buf_set_buf(tdo_buffer, src_first, buffer, dest_first, length); -#ifdef _DEBUG_JTAG_IO_ - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG scan read(%d bits, from src %d bits to dest %d bits):", length, src_first, dest_first); - vsllink_debug_buffer(buffer + dest_first / 8, - DIV_ROUND_UP(length, 7)); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + vsllink_debug_buffer(buffer + dest_first / 8, DIV_ROUND_UP(length, 7)); if (last) { if (jtag_read_buffer(buffer, command) @@ -895,7 +889,6 @@ static void vsllink_usb_close(struct vsllink *vsllink) #define BYTES_PER_LINE 16 -#if defined _DEBUG_JTAG_IO_ static void vsllink_debug_buffer(uint8_t *buffer, int length) { char line[81]; @@ -904,15 +897,14 @@ static void vsllink_debug_buffer(uint8_t *buffer, int length) int j; for (i = 0; i < length; i += BYTES_PER_LINE) { - snprintf(line, 5, "%04x", i); + snprintf(line, 5, "%04x", i & 0xffff); for (j = i; j < i + BYTES_PER_LINE && j < length; j++) { snprintf(s, 4, " %02x", buffer[j]); strcat(line, s); } - LOG_DEBUG("%s", line); + LOG_DEBUG_IO("%s", line); } } -#endif /* _DEBUG_JTAG_IO_ */ static const struct command_registration vsllink_command_handlers[] = { { diff --git a/src/jtag/interface.c b/src/jtag/interface.c index e12b2aebb..de132bbe8 100644 --- a/src/jtag/interface.c +++ b/src/jtag/interface.c @@ -376,15 +376,13 @@ tap_state_t tap_state_by_name(const char *name) return TAP_INVALID; } -#ifdef _DEBUG_JTAG_IO_ - #define JTAG_DEBUG_STATE_APPEND(buf, len, bit) \ do { buf[len] = bit ? '1' : '0'; } while (0) #define JTAG_DEBUG_STATE_PRINT(a, b, astr, bstr) \ - DEBUG_JTAG_IO("TAP/SM: %9s -> %5s\tTMS: %s\tTDI: %s", \ + LOG_DEBUG_IO("TAP/SM: %9s -> %5s\tTMS: %s\tTDI: %s", \ tap_state_name(a), tap_state_name(b), astr, bstr) -tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, +tap_state_t jtag_debug_state_machine_(const void *tms_buf, const void *tdi_buf, unsigned tap_bits, tap_state_t next_state) { const uint8_t *tms_buffer; @@ -401,13 +399,13 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, /* set startstate (and possibly last, if tap_bits == 0) */ last_state = next_state; - DEBUG_JTAG_IO("TAP/SM: START state: %s", tap_state_name(next_state)); + LOG_DEBUG_IO("TAP/SM: START state: %s", tap_state_name(next_state)); tms_buffer = (const uint8_t *)tms_buf; tdi_buffer = (const uint8_t *)tdi_buf; tap_bytes = DIV_ROUND_UP(tap_bits, 8); - DEBUG_JTAG_IO("TAP/SM: TMS bits: %u (bytes: %u)", tap_bits, tap_bytes); + LOG_DEBUG_IO("TAP/SM: TMS bits: %u (bytes: %u)", tap_bits, tap_bytes); tap_out_bits = 0; for (cur_byte = 0; cur_byte < tap_bytes; cur_byte++) { @@ -452,11 +450,10 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, JTAG_DEBUG_STATE_PRINT(last_state, next_state, tms_str, tdi_str); } - DEBUG_JTAG_IO("TAP/SM: FINAL state: %s", tap_state_name(next_state)); + LOG_DEBUG_IO("TAP/SM: FINAL state: %s", tap_state_name(next_state)); return next_state; } -#endif /* _DEBUG_JTAG_IO_ */ void tap_use_new_tms_table(bool use_new) { diff --git a/src/jtag/interface.h b/src/jtag/interface.h index e6fa0caef..905f1eb62 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -56,18 +56,11 @@ void tap_set_state_impl(tap_state_t new_state); * @param new_state The state we think the TAPs are currently in (or * are about to enter). */ -#if defined(_DEBUG_JTAG_IO_) #define tap_set_state(new_state) \ do { \ - LOG_DEBUG("tap_set_state(%s)", tap_state_name(new_state)); \ + LOG_DEBUG_IO("tap_set_state(%s)", tap_state_name(new_state)); \ tap_set_state_impl(new_state); \ } while (0) -#else -static inline void tap_set_state(tap_state_t new_state) -{ - tap_set_state_impl(new_state); -} -#endif /** * This function gets the state of the "state follower" which tracks the @@ -164,7 +157,7 @@ void tap_use_new_tms_table(bool use_new); /** @returns True if new TMS table is active; false otherwise. */ bool tap_uses_new_tms_table(void); -#ifdef _DEBUG_JTAG_IO_ + /** * @brief Prints verbose TAP state transitions for the given TMS/TDI buffers. * @param tms_buf must points to a buffer containing the TMS bitstream. @@ -173,15 +166,18 @@ bool tap_uses_new_tms_table(void); * @param start_tap_state must specify the current TAP state. * @returns the final TAP state; pass as @a start_tap_state in following call. */ -tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, - unsigned tap_len, tap_state_t start_tap_state); -#else static inline tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned tap_len, tap_state_t start_tap_state) { - return start_tap_state; + /* Private declaration */ + tap_state_t jtag_debug_state_machine_(const void *tms_buf, const void *tdi_buf, + unsigned tap_len, tap_state_t start_tap_state); + + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + return jtag_debug_state_machine_(tms_buf, tdi_buf, tap_len, start_tap_state); + else + return start_tap_state; } -#endif /* _DEBUG_JTAG_IO_ */ /** * Represents a driver for a debugging interface. diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index a6891c03f..c93243c47 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -25,14 +25,6 @@ #include #include -#ifdef _DEBUG_JTAG_IO_ -#define DEBUG_JTAG_IO(expr ...) \ - do { if (1) LOG_DEBUG(expr); } while (0) -#else -#define DEBUG_JTAG_IO(expr ...) \ - do { if (0) LOG_DEBUG(expr); } while (0) -#endif - #ifndef DEBUG_JTAG_IOZ #define DEBUG_JTAG_IOZ 64 #endif From 7cddeb0af20049fc891ed726885aebceeb1e22b7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 6 Aug 2018 17:31:36 +0200 Subject: [PATCH 128/176] swd: remove unused API frequency() The specific SWD API to change/query the adapter speed is never called because the equivalent JTAG API is used in place of it. In the restructure of struct jtag_interface, the JTAG API is promoted as global adapter API, thus a specific SWD one is not anymore required. Change-Id: I1e810d255b4dfcd5791b4fac8ae1260c31a057fd Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4891 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/cmsis_dap_usb.c | 10 ---------- src/jtag/drivers/ftdi.c | 9 --------- src/jtag/drivers/jlink.c | 9 --------- src/jtag/drivers/vsllink.c | 1 - src/jtag/drivers/xds110.c | 8 -------- src/jtag/swd.h | 18 ------------------ 6 files changed, 55 deletions(-) diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 5c7cde46e..d52d698a4 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -1653,15 +1653,6 @@ static int cmsis_dap_khz(int khz, int *jtag_speed) return ERROR_OK; } -static int_least32_t cmsis_dap_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - cmsis_dap_speed(hz / 1000); - - return hz; -} - - COMMAND_HANDLER(cmsis_dap_handle_info_command) { if (cmsis_dap_get_version_info() == ERROR_OK) @@ -1790,7 +1781,6 @@ static const struct command_registration cmsis_dap_command_handlers[] = { static const struct swd_driver cmsis_dap_swd_driver = { .init = cmsis_dap_swd_init, - .frequency = cmsis_dap_swd_frequency, .switch_seq = cmsis_dap_swd_switch_seq, .read_reg = cmsis_dap_swd_read_reg, .write_reg = cmsis_dap_swd_write_reg, diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index 60387a98f..5cd44a9d1 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -1203,14 +1203,6 @@ static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_cl ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk); } -static int_least32_t ftdi_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - freq = mpsse_set_frequency(mpsse_ctx, hz); - - return freq; -} - static int ftdi_swd_switch_seq(enum swd_special_seq seq) { switch (seq) { @@ -1239,7 +1231,6 @@ static int ftdi_swd_switch_seq(enum swd_special_seq seq) static const struct swd_driver ftdi_swd = { .init = ftdi_swd_init, - .frequency = ftdi_swd_frequency, .switch_seq = ftdi_swd_switch_seq, .read_reg = ftdi_swd_read_reg, .write_reg = ftdi_swd_write_reg, diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index dd074937c..09b3a858b 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -1929,14 +1929,6 @@ static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_c jlink_swd_queue_cmd(cmd, value, 0, ap_delay_clk); } -static int_least32_t jlink_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - jlink_speed(hz / 1000); - - return hz; -} - /***************************************************************************/ /* J-Link tap functions */ @@ -2212,7 +2204,6 @@ static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint3 static const struct swd_driver jlink_swd = { .init = &jlink_swd_init, - .frequency = &jlink_swd_frequency, .switch_seq = &jlink_swd_switch_seq, .read_reg = &jlink_swd_read_reg, .write_reg = &jlink_swd_write_reg, diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 501322bba..4907ef0e2 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -956,7 +956,6 @@ static const char * const vsllink_transports[] = {"jtag", "swd", NULL}; static const struct swd_driver vsllink_swd_driver = { .init = vsllink_swd_init, - .frequency = vsllink_swd_frequency, .switch_seq = vsllink_swd_switch_seq, .read_reg = vsllink_swd_read_reg, .write_reg = vsllink_swd_write_reg, diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index 20b817879..f25023ba7 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -1925,13 +1925,6 @@ static int xds110_khz(int khz, int *jtag_speed) return ERROR_OK; } -static int_least32_t xds110_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - xds110_speed(hz / 1000); - return hz; -} - COMMAND_HANDLER(xds110_handle_info_command) { xds110_show_info(); @@ -2032,7 +2025,6 @@ static const struct command_registration xds110_command_handlers[] = { static const struct swd_driver xds110_swd_driver = { .init = xds110_swd_init, - .frequency = xds110_swd_frequency, .switch_seq = xds110_swd_switch_seq, .read_reg = xds110_swd_read_reg, .write_reg = xds110_swd_write_reg, diff --git a/src/jtag/swd.h b/src/jtag/swd.h index 3ff4de0bd..0b32105a2 100644 --- a/src/jtag/swd.h +++ b/src/jtag/swd.h @@ -232,24 +232,6 @@ struct swd_driver { */ int (*init)(void); - /** - * Set the SWCLK frequency of the SWD link. - * - * The driver should round the desired value, downwards if possible, to - * the nearest supported frequency. A negative value should be ignored - * and can be used to query the current setting. If the driver does not - * support a variable frequency a fixed, nominal, value should be - * returned. - * - * If the frequency is increased, it must not apply before the currently - * queued transactions are executed. If the frequency is lowered, it may - * apply immediately. - * - * @param hz The desired frequency in Hz. - * @return The actual resulting frequency after rounding. - */ - int_least32_t (*frequency)(int_least32_t hz); - /** * Queue a special SWDIO sequence. * From e26910fdad0cdbb930fbdc938e3b186f5dbaccb9 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 11 Jul 2018 10:21:04 +0200 Subject: [PATCH 129/176] jtag: simplify management of non-implemented handlers There is just a single entry point for the jtag API .khz(), .speed_div(), .power_dropout(), .srst_asserted(). Simplify the code by in-lining the default handler. The overall code behaviour is not changed. This change prevents modifying at run-time the content of struct jtag_interface. Inspired from change http://openocd.zylin.com/943 by Evan Hunter Change-Id: I09aeb76d614db57b1884ac7ee9f00c152cd77849 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4892 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/adapter.c | 39 +-------------------------------------- src/jtag/core.c | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index e11f4e906..b1be28e5f 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -66,30 +66,6 @@ static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv) return JIM_OK; } -static int default_khz(int khz, int *jtag_speed) -{ - LOG_ERROR("Translation from khz to jtag_speed not implemented"); - return ERROR_FAIL; -} - -static int default_speed_div(int speed, int *khz) -{ - LOG_ERROR("Translation from jtag_speed to khz not implemented"); - return ERROR_FAIL; -} - -static int default_power_dropout(int *dropout) -{ - *dropout = 0; /* by default we can't detect power dropout */ - return ERROR_OK; -} - -static int default_srst_asserted(int *srst_asserted) -{ - *srst_asserted = 0; /* by default we can't detect srst asserted */ - return ERROR_OK; -} - COMMAND_HANDLER(interface_transport_command) { char **transports; @@ -158,21 +134,8 @@ COMMAND_HANDLER(handle_interface_command) LOG_WARNING("Adapter driver '%s' did not declare " "which transports it allows; assuming " "legacy JTAG-only", jtag_interface->name); - retval = allow_transports(CMD_CTX, jtag_interface->transports + return allow_transports(CMD_CTX, jtag_interface->transports ? jtag_interface->transports : jtag_only); - if (ERROR_OK != retval) - return retval; - - if (jtag_interface->khz == NULL) - jtag_interface->khz = default_khz; - if (jtag_interface->speed_div == NULL) - jtag_interface->speed_div = default_speed_div; - if (jtag_interface->power_dropout == NULL) - jtag_interface->power_dropout = default_power_dropout; - if (jtag_interface->srst_asserted == NULL) - jtag_interface->srst_asserted = default_srst_asserted; - - return ERROR_OK; } /* no valid interface was found (i.e. the configuration option, diff --git a/src/jtag/core.c b/src/jtag/core.c index e57f62db7..84e939677 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1611,14 +1611,18 @@ static int adapter_khz_to_speed(unsigned khz, int *speed) { LOG_DEBUG("convert khz to interface specific speed value"); speed_khz = khz; - if (jtag != NULL) { - LOG_DEBUG("have interface set up"); - int speed_div1; - int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); - if (ERROR_OK != retval) - return retval; - *speed = speed_div1; + if (!jtag) + return ERROR_OK; + LOG_DEBUG("have interface set up"); + if (!jtag->khz) { + LOG_ERROR("Translation from khz to jtag_speed not implemented"); + return ERROR_FAIL; } + int speed_div1; + int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); + if (ERROR_OK != retval) + return retval; + *speed = speed_div1; return ERROR_OK; } @@ -1681,7 +1685,13 @@ int jtag_get_speed_readable(int *khz) int retval = jtag_get_speed(&jtag_speed_var); if (retval != ERROR_OK) return retval; - return jtag ? jtag->speed_div(jtag_speed_var, khz) : ERROR_OK; + if (!jtag) + return ERROR_OK; + if (!jtag->speed_div) { + LOG_ERROR("Translation from jtag_speed to khz not implemented"); + return ERROR_FAIL; + } + return jtag->speed_div(jtag_speed_var, khz); } void jtag_set_verify(bool enable) @@ -1712,12 +1722,20 @@ int jtag_power_dropout(int *dropout) LOG_ERROR("No Valid JTAG Interface Configured."); exit(-1); } - return jtag->power_dropout(dropout); + if (jtag->power_dropout) + return jtag->power_dropout(dropout); + + *dropout = 0; /* by default we can't detect power dropout */ + return ERROR_OK; } int jtag_srst_asserted(int *srst_asserted) { - return jtag->srst_asserted(srst_asserted); + if (jtag->srst_asserted) + return jtag->srst_asserted(srst_asserted); + + *srst_asserted = 0; /* by default we can't detect srst asserted */ + return ERROR_OK; } enum reset_types jtag_get_reset_config(void) From e5177a5ad455ac0c353fd6bb48ff288912168428 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 28 Jan 2019 18:22:21 +0100 Subject: [PATCH 130/176] helper: add bitmap helper primitives Mainly copied/inspired from Linux kernel code in - include/linux/types.h - include/linux/bitmap.h - include/linux/bitops.h Change-Id: I317b542993ab81530c86553f339b79505d0fef0f Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4894 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/Makefile.am | 1 + src/helper/bits.h | 84 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/helper/bits.h diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am index e0f7f49bb..2b3523f7a 100644 --- a/src/helper/Makefile.am +++ b/src/helper/Makefile.am @@ -16,6 +16,7 @@ noinst_LTLIBRARIES += %D%/libhelper.la %D%/jep106.c \ %D%/jim-nvp.c \ %D%/binarybuffer.h \ + %D%/bits.h \ %D%/configuration.h \ %D%/ioutil.h \ %D%/list.h \ diff --git a/src/helper/bits.h b/src/helper/bits.h new file mode 100644 index 000000000..464584db8 --- /dev/null +++ b/src/helper/bits.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + * Author(s): Antonio Borneo for STMicroelectronics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * The content of this file is mainly copied/inspired from Linux kernel + * code in include/linux/types.h include/linux/bitmap.h include/linux/bitops.h + */ + +#ifndef OPENOCD_HELPER_BITS_H +#define OPENOCD_HELPER_BITS_H + +#include + +#define BIT(nr) (1UL << (nr)) +#define BITS_PER_BYTE 8 +#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define DECLARE_BITMAP(name, bits) unsigned long name[BITS_TO_LONGS(bits)] + +/** + * bitmap_zero - Clears all the bits in memory + * @dst: the address of the bitmap + * @nbits: the number of bits to clear + */ +static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) +{ + unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memset(dst, 0, len); +} + +/** + * clear_bit - Clear a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + */ +static inline void clear_bit(unsigned int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p &= ~mask; +} + +/** + * set_bit - Set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + */ +static inline void set_bit(unsigned int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p |= mask; +} + +/** + * test_bit - Determine whether a bit is set + * @nr: bit number to test + * @addr: Address to start counting from + */ +static inline int test_bit(unsigned int nr, const volatile unsigned long *addr) +{ + return 1UL & (addr[BIT_WORD(nr)] >> (nr % BITS_PER_LONG)); +} + +#endif /* OPENOCD_HELPER_BITS_H */ From 02cd1e39cc710a6a6592486238c15f7b42c7d21c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 13 Feb 2019 17:15:58 +0100 Subject: [PATCH 131/176] target/cortex_m: remove dependency from jtag queue Since the first commit 09883194f867 that introduced cortex_m, the code has a delay of 50ms after srst has been asserted. The specific delay is implemented through the JTAG_SLEEP command sent in the jtag queue. To remove the dependency from the jtag queue, replace the delay with a transport independent function. In case of jtag transport, this change keeps the same behaviour only if the jtag queue has been flushed before the delay. This does not happen if the call to dap_dp_init(), few lines above, fails while calling a dap_queue_dp_{read,write}(); in this case the jtag queue will be flushed later, after the delay, while in the original code the delay would follow the flushing of the commands already queued. Anyway, this different behavior would only happen in case of DAP already not responsive so anticipating the delay in such error condition is not supposed to add further problems. Change-Id: If15978246764e4266b10e707d86c03e5ed907de7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4912 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/cortex_m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index ce3ab09c0..e2960391c 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1198,7 +1198,7 @@ static int cortex_m_assert_reset(struct target *target) } target->state = TARGET_RESET; - jtag_add_sleep(50000); + jtag_sleep(50000); register_cache_invalidate(cortex_m->armv7m.arm.core_cache); From 0cba5b4ea30a436e1ab381b374ea89743a23e09c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 13 Feb 2019 18:28:50 +0100 Subject: [PATCH 132/176] gdb_server: remove call to jtag_execute_queue() In the initial commit 6c9b804d6187edda4f46f8458deec0b17ec76bb9 in 2007's svn://svn.berlios.de/openocd/trunk@246 a target script gdb_program_config was called before gdb flash programming. To guarantee the script does not left any pending command in the jtag queue, a call to jtag_execute_queue() was inserted after the execution of the script. In following commit ef1cfb23947bd32798077c6abb5c25a049460ae9 in 2008's svn://svn.berlios.de/openocd/trunk@975 the script was replaced by the event "old-gdb_program_config" and the call to jtag_execute_queue() get executed in every case, even if the event handler was not present. At last, commit bb3793c9a4ccd232c4ee3ce0a36bf200589ca0bb ("target: remove legacy target events") stripped away the obsolete event but left the call to jtag_execute_queue(), now completely useless. Remove the call to jtag_execute_queue() and clean-up the code around it. Change-Id: I284f54d656d431ad6cdc25ca18218c09db31bd25 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4911 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/server/gdb_server.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 60ed4ce04..ab3e6bef8 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -903,7 +903,6 @@ static void gdb_frontend_halted(struct target *target, struct connection *connec static int gdb_target_callback_event_handler(struct target *target, enum target_event event, void *priv) { - int retval; struct connection *connection = priv; struct gdb_service *gdb_service = connection->service->priv; @@ -917,11 +916,6 @@ static int gdb_target_callback_event_handler(struct target *target, case TARGET_EVENT_HALTED: target_call_event_callbacks(target, TARGET_EVENT_GDB_END); break; - case TARGET_EVENT_GDB_FLASH_ERASE_START: - retval = jtag_execute_queue(); - if (retval != ERROR_OK) - return retval; - break; default: break; } From 159f11fefc194743a0af6e29e134b184bf26650d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 22 Jan 2019 16:03:15 +0100 Subject: [PATCH 133/176] jtag: set default "jtag_only" to uninitialized transports For legacy support, drivers that do not define a list of transports get identified as jtag_only. Cleanup this old crust and initialize properly the transports field in the jtag_interface for all the drivers. Change-Id: I9c86064e5d05bd0212bc18f4424414e615e617fe Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4893 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/adapter.c | 11 +---------- src/jtag/core.c | 13 ------------- src/jtag/drivers/amt_jtagaccel.c | 1 + src/jtag/drivers/at91rm9200.c | 1 + src/jtag/drivers/ep93xx.c | 1 + src/jtag/drivers/gw16012.c | 1 + src/jtag/drivers/opendous.c | 1 + src/jtag/drivers/openjtag.c | 1 + src/jtag/drivers/parport.c | 1 + src/jtag/drivers/presto.c | 1 + src/jtag/drivers/remote_bitbang.c | 1 + src/jtag/drivers/rlink.c | 1 + src/jtag/drivers/usb_blaster/usb_blaster.c | 1 + src/jtag/drivers/usbprog.c | 1 + src/jtag/minidummy/minidummy.c | 1 + src/jtag/zy1000/zy1000.c | 1 + 16 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index b1be28e5f..29a961338 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -126,16 +126,7 @@ COMMAND_HANDLER(handle_interface_command) jtag_interface = jtag_interfaces[i]; - /* LEGACY SUPPORT ... adapter drivers must declare what - * transports they allow. Until they all do so, assume - * the legacy drivers are JTAG-only - */ - if (!jtag_interface->transports) - LOG_WARNING("Adapter driver '%s' did not declare " - "which transports it allows; assuming " - "legacy JTAG-only", jtag_interface->name); - return allow_transports(CMD_CTX, jtag_interface->transports - ? jtag_interface->transports : jtag_only); + return allow_transports(CMD_CTX, jtag_interface->transports); } /* no valid interface was found (i.e. the configuration option, diff --git a/src/jtag/core.c b/src/jtag/core.c index 84e939677..18956f24d 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1348,19 +1348,6 @@ int adapter_init(struct command_context *cmd_ctx) return retval; jtag = jtag_interface; - /* LEGACY SUPPORT ... adapter drivers must declare what - * transports they allow. Until they all do so, assume - * the legacy drivers are JTAG-only - */ - if (!transports_are_declared()) { - LOG_ERROR("Adapter driver '%s' did not declare " - "which transports it allows; assuming " - "JTAG-only", jtag->name); - retval = allow_transports(cmd_ctx, jtag_only); - if (retval != ERROR_OK) - return retval; - } - if (jtag->speed == NULL) { LOG_INFO("This adapter doesn't support configurable speed"); return ERROR_OK; diff --git a/src/jtag/drivers/amt_jtagaccel.c b/src/jtag/drivers/amt_jtagaccel.c index d6864c210..045672f0e 100644 --- a/src/jtag/drivers/amt_jtagaccel.c +++ b/src/jtag/drivers/amt_jtagaccel.c @@ -586,6 +586,7 @@ static const struct command_registration amtjtagaccel_command_handlers[] = { struct jtag_interface amt_jtagaccel_interface = { .name = "amt_jtagaccel", + .transports = jtag_only, .commands = amtjtagaccel_command_handlers, .init = amt_jtagaccel_init, diff --git a/src/jtag/drivers/at91rm9200.c b/src/jtag/drivers/at91rm9200.c index 0360ec5de..ac655635d 100644 --- a/src/jtag/drivers/at91rm9200.c +++ b/src/jtag/drivers/at91rm9200.c @@ -192,6 +192,7 @@ static const struct command_registration at91rm9200_command_handlers[] = { struct jtag_interface at91rm9200_interface = { .name = "at91rm9200", .execute_queue = bitbang_execute_queue, + .transports = jtag_only, .commands = at91rm9200_command_handlers, .init = at91rm9200_init, .quit = at91rm9200_quit, diff --git a/src/jtag/drivers/ep93xx.c b/src/jtag/drivers/ep93xx.c index 36fc77747..4cf318485 100644 --- a/src/jtag/drivers/ep93xx.c +++ b/src/jtag/drivers/ep93xx.c @@ -55,6 +55,7 @@ struct jtag_interface ep93xx_interface = { .supported = DEBUG_CAP_TMS_SEQ, .execute_queue = bitbang_execute_queue, + .transports = jtag_only, .init = ep93xx_init, .quit = ep93xx_quit, diff --git a/src/jtag/drivers/gw16012.c b/src/jtag/drivers/gw16012.c index 2971d4663..e65f56cd1 100644 --- a/src/jtag/drivers/gw16012.c +++ b/src/jtag/drivers/gw16012.c @@ -523,6 +523,7 @@ static const struct command_registration gw16012_command_handlers[] = { struct jtag_interface gw16012_interface = { .name = "gw16012", + .transports = jtag_only, .commands = gw16012_command_handlers, .init = gw16012_init, diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index c0595bf9f..5f352af89 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -236,6 +236,7 @@ static const struct command_registration opendous_command_handlers[] = { struct jtag_interface opendous_interface = { .name = "opendous", + .transports = jtag_only, .commands = opendous_command_handlers, .execute_queue = opendous_execute_queue, .init = opendous_init, diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 2ca8254b7..7a3aa2337 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -894,6 +894,7 @@ static const struct command_registration openjtag_command_handlers[] = { struct jtag_interface openjtag_interface = { .name = "openjtag", + .transports = jtag_only, .commands = openjtag_command_handlers, .execute_queue = openjtag_execute_queue, diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c index 0e7992fe9..8e44dcb79 100644 --- a/src/jtag/drivers/parport.c +++ b/src/jtag/drivers/parport.c @@ -517,6 +517,7 @@ static const struct command_registration parport_command_handlers[] = { struct jtag_interface parport_interface = { .name = "parport", .supported = DEBUG_CAP_TMS_SEQ, + .transports = jtag_only, .commands = parport_command_handlers, .init = parport_init, diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c index 29bc81111..2a94d0618 100644 --- a/src/jtag/drivers/presto.c +++ b/src/jtag/drivers/presto.c @@ -563,6 +563,7 @@ static int presto_jtag_quit(void) struct jtag_interface presto_interface = { .name = "presto", + .transports = jtag_only, .commands = presto_command_handlers, .execute_queue = bitq_execute_queue, diff --git a/src/jtag/drivers/remote_bitbang.c b/src/jtag/drivers/remote_bitbang.c index 1f8fc1a11..a35489487 100644 --- a/src/jtag/drivers/remote_bitbang.c +++ b/src/jtag/drivers/remote_bitbang.c @@ -345,6 +345,7 @@ static const struct command_registration remote_bitbang_command_handlers[] = { struct jtag_interface remote_bitbang_interface = { .name = "remote_bitbang", .execute_queue = &bitbang_execute_queue, + .transports = jtag_only, .commands = remote_bitbang_command_handlers, .init = &remote_bitbang_init, .quit = &remote_bitbang_quit, diff --git a/src/jtag/drivers/rlink.c b/src/jtag/drivers/rlink.c index 70f8734b5..317e8b808 100644 --- a/src/jtag/drivers/rlink.c +++ b/src/jtag/drivers/rlink.c @@ -1662,6 +1662,7 @@ static int rlink_quit(void) struct jtag_interface rlink_interface = { .name = "rlink", + .transports = jtag_only, .init = rlink_init, .quit = rlink_quit, .speed = rlink_speed, diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 55b511e1a..165ebdcd3 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -1068,6 +1068,7 @@ static const struct command_registration ublast_command_handlers[] = { struct jtag_interface usb_blaster_interface = { .name = "usb_blaster", + .transports = jtag_only, .commands = ublast_command_handlers, .supported = DEBUG_CAP_TMS_SEQ, diff --git a/src/jtag/drivers/usbprog.c b/src/jtag/drivers/usbprog.c index bcbaff8d8..35a95202e 100644 --- a/src/jtag/drivers/usbprog.c +++ b/src/jtag/drivers/usbprog.c @@ -598,6 +598,7 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag) struct jtag_interface usbprog_interface = { .name = "usbprog", + .transports = jtag_only, .execute_queue = usbprog_execute_queue, .init = usbprog_init, diff --git a/src/jtag/minidummy/minidummy.c b/src/jtag/minidummy/minidummy.c index b7c989fc0..2f260040d 100644 --- a/src/jtag/minidummy/minidummy.c +++ b/src/jtag/minidummy/minidummy.c @@ -28,6 +28,7 @@ struct jtag_interface minidummy_interface = { .name = "minidummy", .execute_queue = NULL, .speed = NULL, + .transports = jtag_only, .commands = NULL, .init = NULL, .quit = NULL, diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index 4e53dd1f7..173498398 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -1242,6 +1242,7 @@ struct jtag_interface zy1000_interface = { .supported = DEBUG_CAP_TMS_SEQ, .execute_queue = NULL, .speed = zy1000_speed, + .transports = jtag_only, .commands = zy1000_commands, .init = zy1000_init, .quit = zy1000_quit, From 215f14bec87293f549639e6342b6e671faa1e7d1 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 5 Jun 2019 01:09:15 +0200 Subject: [PATCH 134/176] target/armv7m: fix register number in armv7m_get_core_reg() armv7m_get_core_reg() calls arm->read_core_reg() arm->read_core_reg() expects the register number as an index to core reglist, not an ARMv7M specific register code. Use reg->number instead of armv7m_reg->num. The change solves assert src/target/armv7m.c:222: armv7m_read_core_reg: Assertion `num < (int)armv7m->arm.core_cache->num_regs' failed. when gdb 'info reg' is issued on a Cortex-M target and no cortex_m_debug_entry() has been called since OpenOCD start (target was halted before OpenOCD start). Change-Id: I32a2294693ef979b613be93aeceb3b0eb06ee6df Ticket: https://sourceforge.net/p/openocd/tickets/216/ Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5203 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/armv7m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 3d73b2954..4b37774a5 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -191,7 +191,7 @@ static int armv7m_get_core_reg(struct reg *reg) if (target->state != TARGET_HALTED) return ERROR_TARGET_NOT_HALTED; - retval = arm->read_core_reg(target, reg, armv7m_reg->num, arm->core_mode); + retval = arm->read_core_reg(target, reg, reg->number, arm->core_mode); return retval; } From c8184bac20e328704067efb3ab63a96c9b541b89 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 31 May 2019 13:42:28 +0200 Subject: [PATCH 135/176] contrib/rpc_examples: Remove 'ocd_' command prefix The prefix is not necessary anymore. Change-Id: Ie0df06a70ff51e6719d7564396739d28618b0196 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5190 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/rpc_examples/ocd_rpc_example.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index b585aaa42..196ea05f9 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -85,14 +85,14 @@ class OpenOcd: return data def readVariable(self, address): - raw = self.send("ocd_mdw 0x%x" % address).split(": ") + raw = self.send("mdw 0x%x" % address).split(": ") return None if (len(raw) < 2) else strToHex(raw[1]) def readMemory(self, wordLen, address, n): self.send("array unset output") # better to clear the array before self.send("mem2array output %d 0x%x %d" % (wordLen, address, n)) - output = [*map(int, self.send("ocd_echo $output").split(" "))] + output = [*map(int, self.send("echo $output").split(" "))] d = dict([tuple(output[i:i + 2]) for i in range(0, len(output), 2)]) return [d[k] for k in sorted(d.keys())] @@ -116,8 +116,8 @@ if __name__ == "__main__": with OpenOcd() as ocd: ocd.send("reset") - show(ocd.send("ocd_echo \"echo says hi!\"")[:-1]) - show(ocd.send("capture \"ocd_halt\"")[:-1]) + show(ocd.send("echo \"echo says hi!\"")[:-1]) + show(ocd.send("capture \"halt\"")[:-1]) # Read the first few words at the RAM region (put starting adress of RAM # region into 'addr') From 6f87df80fe98c18c8cb0e2dfdffa074392d6f2d5 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 31 May 2019 17:03:10 +0200 Subject: [PATCH 136/176] contrib/rpc_examples: remove 'ocd_' command prefix from haskell example The prefixed commands has been removed in commit 0840414f0e57 ("helper/command: do not replace new commands with ocd_ prefix"). Change-Id: I9f101beb85533973041386896bbb215bb141962f Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5191 Tested-by: jenkins Reviewed-by: Paul Fertser --- contrib/rpc_examples/ocdrpc.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/rpc_examples/ocdrpc.hs b/contrib/rpc_examples/ocdrpc.hs index 27fb1ae60..9a80cdd84 100644 --- a/contrib/rpc_examples/ocdrpc.hs +++ b/contrib/rpc_examples/ocdrpc.hs @@ -39,7 +39,7 @@ mdwParser = (manyTill anyChar (string ": ") *> ocdMdw :: (InputStream ByteString, OutputStream ByteString) -> Integer -> Integer -> IO [Integer] ocdMdw s start count = do - s <- ocdExec s $ "ocd_mdw " ++ show start ++ " " ++ show count + s <- ocdExec s $ "mdw " ++ show start ++ " " ++ show count case parseOnly mdwParser (pack s) of Right r -> return $ concat r From ba11adb8336cd5a987a64837ca31a564d03abcbf Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Wed, 5 Jun 2019 15:23:33 -0700 Subject: [PATCH 137/176] armv7a_mmu: Check earlier for PAR read Check earlier that the read of the PAR register was successful instead of starting the decoding and then checking for an error reading that register. Change-Id: Id96c2b2f76d2d1c745fcfa55ad4c1e6db92106f9 Signed-off-by: Florian Fainelli Reviewed-on: http://openocd.zylin.com/5215 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Matthias Welwarsky --- src/target/armv7a_mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/armv7a_mmu.c b/src/target/armv7a_mmu.c index 153bfccf2..859332a44 100644 --- a/src/target/armv7a_mmu.c +++ b/src/target/armv7a_mmu.c @@ -143,14 +143,14 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, retval = dpm->instr_read_data_r0(dpm, ARMV4_5_MRC(15, 0, 0, 7, 4, 0), val); + if (retval != ERROR_OK) + goto done; /* decode memory attribute */ NOS = (*val >> 10) & 1; /* Not Outer shareable */ NS = (*val >> 9) & 1; /* Non secure */ INNER = (*val >> 4) & 0x7; OUTER = (*val >> 2) & 0x3; - if (retval != ERROR_OK) - goto done; *val = (*val & ~0xfff) + (va & 0xfff); if (meminfo) { LOG_INFO("%" PRIx32 " : %" PRIx32 " %s outer shareable %s secured", From 604dded6f1cd1e41d8ccf3185bc078ce698f391f Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Wed, 5 Jun 2019 12:37:13 -0700 Subject: [PATCH 138/176] armv7a_mmu: Remove armv7a_mmu_translate_va() This function is not used anywhere in the tree, remove it, such that we only have a single function moving forward that might need to deal with short vs. long format specifics. Change-Id: I80e81cd7eba1e028d1afaeaedb675b46c0ca6fa1 Signed-off-by: Florian Fainelli Reviewed-on: http://openocd.zylin.com/5213 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Matthias Welwarsky --- src/target/armv7a_mmu.c | 86 ----------------------------------------- src/target/armv7a_mmu.h | 1 - 2 files changed, 87 deletions(-) diff --git a/src/target/armv7a_mmu.c b/src/target/armv7a_mmu.c index 859332a44..6118417fc 100644 --- a/src/target/armv7a_mmu.c +++ b/src/target/armv7a_mmu.c @@ -34,92 +34,6 @@ #define SCTLR_BIT_AFE (1 << 29) -/* method adapted to Cortex-A : reused ARM v4 v5 method */ -int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val) -{ - uint32_t first_lvl_descriptor = 0x0; - uint32_t second_lvl_descriptor = 0x0; - int retval; - struct armv7a_common *armv7a = target_to_armv7a(target); - uint32_t ttbidx = 0; /* default to ttbr0 */ - uint32_t ttb_mask; - uint32_t va_mask; - uint32_t ttb; - - if (target->state != TARGET_HALTED) - LOG_INFO("target not halted, using cached values for translation table!"); - - /* if va is above the range handled by ttbr0, select ttbr1 */ - if (va > armv7a->armv7a_mmu.ttbr_range[0]) { - /* select ttb 1 */ - ttbidx = 1; - } - - ttb = armv7a->armv7a_mmu.ttbr[ttbidx]; - ttb_mask = armv7a->armv7a_mmu.ttbr_mask[ttbidx]; - va_mask = 0xfff00000 & armv7a->armv7a_mmu.ttbr_range[ttbidx]; - - LOG_DEBUG("ttb_mask %" PRIx32 " va_mask %" PRIx32 " ttbidx %i", - ttb_mask, va_mask, ttbidx); - retval = armv7a->armv7a_mmu.read_physical_memory(target, - (ttb & ttb_mask) | ((va & va_mask) >> 18), - 4, 1, (uint8_t *)&first_lvl_descriptor); - if (retval != ERROR_OK) - return retval; - first_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *) - &first_lvl_descriptor); - /* reuse armv4_5 piece of code, specific armv7a changes may come later */ - LOG_DEBUG("1st lvl desc: %8.8" PRIx32 "", first_lvl_descriptor); - - if ((first_lvl_descriptor & 0x3) == 0) { - /* Avoid LOG_ERROR, probably GDB is guessing the stack frame */ - LOG_WARNING("Address translation failure [1]: va %8.8" PRIx32 "", va); - return ERROR_TARGET_TRANSLATION_FAULT; - } - - if ((first_lvl_descriptor & 0x40002) == 2) { - /* section descriptor */ - *val = (first_lvl_descriptor & 0xfff00000) | (va & 0x000fffff); - return ERROR_OK; - } else if ((first_lvl_descriptor & 0x40002) == 0x40002) { - /* supersection descriptor */ - if (first_lvl_descriptor & 0x00f001e0) { - LOG_ERROR("Physical address does not fit into 32 bits"); - return ERROR_TARGET_TRANSLATION_FAULT; - } - *val = (first_lvl_descriptor & 0xff000000) | (va & 0x00ffffff); - return ERROR_OK; - } - - /* page table */ - retval = armv7a->armv7a_mmu.read_physical_memory(target, - (first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10), - 4, 1, (uint8_t *)&second_lvl_descriptor); - if (retval != ERROR_OK) - return retval; - - second_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *) - &second_lvl_descriptor); - - LOG_DEBUG("2nd lvl desc: %8.8" PRIx32 "", second_lvl_descriptor); - - if ((second_lvl_descriptor & 0x3) == 0) { - /* Avoid LOG_ERROR, probably GDB is guessing the stack frame */ - LOG_WARNING("Address translation failure [2]: va %8.8" PRIx32 "", va); - return ERROR_TARGET_TRANSLATION_FAULT; - } - - if ((second_lvl_descriptor & 0x3) == 1) { - /* large page descriptor */ - *val = (second_lvl_descriptor & 0xffff0000) | (va & 0x0000ffff); - } else { - /* small page descriptor */ - *val = (second_lvl_descriptor & 0xfffff000) | (va & 0x00000fff); - } - - return ERROR_OK; -} - /* V7 method VA TO PA */ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, uint32_t *val, int meminfo) diff --git a/src/target/armv7a_mmu.h b/src/target/armv7a_mmu.h index 4372aa8eb..513e56704 100644 --- a/src/target/armv7a_mmu.h +++ b/src/target/armv7a_mmu.h @@ -19,7 +19,6 @@ #ifndef OPENOCD_TARGET_ARMV7A_MMU_H #define OPENOCD_TARGET_ARMV7A_MMU_H -extern int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val); extern int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, uint32_t *val, int meminfo); From eeabbd58c06e8c5fc01ce87cd2b04725fbc0e2bb Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 19 Mar 2019 09:50:41 -0700 Subject: [PATCH 139/176] armv7a_mmu: Do not restrict virtual addresses to uint32_t In preparation for adding super section decoding, do not restrict armv7a_mmu_translate_va_pa() to 32-bit virtual addresses since ARMv7-A processors with VMSA extensions (including LPAE) can issue wider physical addresses. Update casting to uint32_t where necessary. Change-Id: Id1c3d0d5ac324cbdc334259d9ea75fe4981671a1 Signed-off-by: Florian Fainelli Reviewed-on: http://openocd.zylin.com/5211 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Matthias Welwarsky --- src/target/armv7a_mmu.c | 9 +++++---- src/target/armv7a_mmu.h | 2 +- src/target/cortex_a.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/target/armv7a_mmu.c b/src/target/armv7a_mmu.c index 6118417fc..aa3dc16d8 100644 --- a/src/target/armv7a_mmu.c +++ b/src/target/armv7a_mmu.c @@ -36,12 +36,12 @@ /* V7 method VA TO PA */ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, - uint32_t *val, int meminfo) + target_addr_t *val, int meminfo) { int retval = ERROR_FAIL; struct armv7a_common *armv7a = target_to_armv7a(target); struct arm_dpm *dpm = armv7a->arm.dpm; - uint32_t virt = va & ~0xfff; + uint32_t virt = va & ~0xfff, value; uint32_t NOS, NS, INNER, OUTER; *val = 0xdeadbeef; retval = dpm->prepare(dpm); @@ -56,9 +56,10 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, goto done; retval = dpm->instr_read_data_r0(dpm, ARMV4_5_MRC(15, 0, 0, 7, 4, 0), - val); + &value); if (retval != ERROR_OK) goto done; + *val = value; /* decode memory attribute */ NOS = (*val >> 10) & 1; /* Not Outer shareable */ NS = (*val >> 9) & 1; /* Non secure */ @@ -67,7 +68,7 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, *val = (*val & ~0xfff) + (va & 0xfff); if (meminfo) { - LOG_INFO("%" PRIx32 " : %" PRIx32 " %s outer shareable %s secured", + LOG_INFO("%" PRIx32 " : %" TARGET_PRIxADDR " %s outer shareable %s secured", va, *val, NOS == 1 ? "not" : " ", NS == 1 ? "not" : ""); diff --git a/src/target/armv7a_mmu.h b/src/target/armv7a_mmu.h index 513e56704..36cd9d19e 100644 --- a/src/target/armv7a_mmu.h +++ b/src/target/armv7a_mmu.h @@ -20,7 +20,7 @@ #define OPENOCD_TARGET_ARMV7A_MMU_H extern int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, - uint32_t *val, int meminfo); + target_addr_t *val, int meminfo); extern const struct command_registration armv7a_mmu_command_handlers[]; diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 9fc265288..158de0b24 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -2922,7 +2922,7 @@ static int cortex_a_virt2phys(struct target *target, if (retval != ERROR_OK) return retval; return armv7a_mmu_translate_va_pa(target, (uint32_t)virt, - (uint32_t *)phys, 1); + phys, 1); } COMMAND_HANDLER(cortex_a_handle_cache_info_command) From f935f39cda33d5d20fdfb13a294544f733671ffd Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 19 Mar 2019 10:36:39 -0700 Subject: [PATCH 140/176] armv7a_mmu: Add support for decoding Super Sections The ARMv7-A architecture supports super sections which allows mapping physical addresses up to 40-bit into a 32-bit virtual address using the short descriptor format (see ARM DDI 0406C.c section B4.1.112 for details). Change-Id: I8e64d0e93e36ae7a7da7b7bf2a8342856bb044f1 Signed-off-by: Florian Fainelli Reviewed-on: http://openocd.zylin.com/5212 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Matthias Welwarsky --- src/target/armv7a_mmu.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/target/armv7a_mmu.c b/src/target/armv7a_mmu.c index aa3dc16d8..f83228d55 100644 --- a/src/target/armv7a_mmu.c +++ b/src/target/armv7a_mmu.c @@ -42,7 +42,7 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, struct armv7a_common *armv7a = target_to_armv7a(target); struct arm_dpm *dpm = armv7a->arm.dpm; uint32_t virt = va & ~0xfff, value; - uint32_t NOS, NS, INNER, OUTER; + uint32_t NOS, NS, INNER, OUTER, SS; *val = 0xdeadbeef; retval = dpm->prepare(dpm); if (retval != ERROR_OK) @@ -59,19 +59,36 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, &value); if (retval != ERROR_OK) goto done; - *val = value; - /* decode memory attribute */ - NOS = (*val >> 10) & 1; /* Not Outer shareable */ - NS = (*val >> 9) & 1; /* Non secure */ - INNER = (*val >> 4) & 0x7; - OUTER = (*val >> 2) & 0x3; - *val = (*val & ~0xfff) + (va & 0xfff); + /* decode memory attribute */ + SS = (value >> 1) & 1; +#if !BUILD_TARGET64 + if (SS) { + LOG_ERROR("Super section found with no-64 bit address support"); + return ERROR_FAIL; + } +#endif + NOS = (value >> 10) & 1; /* Not Outer shareable */ + NS = (value >> 9) & 1; /* Non secure */ + INNER = (value >> 4) & 0x7; + OUTER = (value >> 2) & 0x3; + + if (SS) { + /* PAR[31:24] contains PA[31:24] */ + *val = value & 0xff000000; + /* PAR [23:16] contains PA[39:32] */ + *val |= (target_addr_t)(value & 0x00ff0000) << 16; + /* PA[23:12] is the same as VA[23:12] */ + *val |= (va & 0xffffff); + } else { + *val = (value & ~0xfff) + (va & 0xfff); + } if (meminfo) { - LOG_INFO("%" PRIx32 " : %" TARGET_PRIxADDR " %s outer shareable %s secured", + LOG_INFO("%" PRIx32 " : %" TARGET_PRIxADDR " %s outer shareable %s secured %s super section", va, *val, NOS == 1 ? "not" : " ", - NS == 1 ? "not" : ""); + NS == 1 ? "not" : "", + SS == 0 ? "not" : ""); switch (OUTER) { case 0: LOG_INFO("outer: Non-Cacheable"); From 88728abee1eea55e5c11bab55640ea13a1357f3a Mon Sep 17 00:00:00 2001 From: Daniel Goehring Date: Thu, 16 May 2019 16:47:57 -0400 Subject: [PATCH 141/176] ARMv8: Update rtos_reg storage from 8 to 16 bytes To support 128 bit registers, the rtos_reg structure value array needs to be updated from 8 to 16 bytes. Tested by reading ARMv8 NEON FP regs on an Ampere eMAG 8180 with GDB. Change-Id: I7f3fe1a5b2def599d021787fbe9cdd51f92859a4 Signed-off-by: Daniel Goehring Reviewed-on: http://openocd.zylin.com/5209 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/rtos/rtos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h index b34604787..93b1731aa 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -61,7 +61,7 @@ struct rtos { struct rtos_reg { uint32_t number; uint32_t size; - uint8_t value[8]; + uint8_t value[16]; }; struct rtos_type { From 48478967db9cc4a499ea821a945e81524557cfd2 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 15 Mar 2019 23:20:55 +0100 Subject: [PATCH 142/176] mem_ap: fix format of logged addresses The macro TARGET_ADDR_FMT, defined in helper/types.h, already includes the prefix "0x" in front of the hexadecimal number, being defined as: #define TARGET_ADDR_FMT "0x%8.8" TARGET_PRIxADDR An additional "0x" is present in mem_ap; it prints debug messages with a double "0x" before the address: Debug: 2921 34180 mem_ap.c:153 mem_ap_write_memory(): Writing memory at physical address 0x0x5000000c; size 4; count 1 Remove the incorrect hexadecimal prefix. Change-Id: I38f19ed2a2f542bd5df53e947a2604f1cbe80e08 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5222 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/mem_ap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/mem_ap.c b/src/target/mem_ap.c index 584e19d4c..29cd37a90 100644 --- a/src/target/mem_ap.c +++ b/src/target/mem_ap.c @@ -140,7 +140,7 @@ static int mem_ap_read_memory(struct target *target, target_addr_t address, { struct mem_ap *mem_ap = target->arch_info; - LOG_DEBUG("Reading memory at physical address 0x" TARGET_ADDR_FMT + LOG_DEBUG("Reading memory at physical address " TARGET_ADDR_FMT "; size %" PRId32 "; count %" PRId32, address, size, count); if (count == 0 || buffer == NULL) @@ -155,7 +155,7 @@ static int mem_ap_write_memory(struct target *target, target_addr_t address, { struct mem_ap *mem_ap = target->arch_info; - LOG_DEBUG("Writing memory at physical address 0x" TARGET_ADDR_FMT + LOG_DEBUG("Writing memory at physical address " TARGET_ADDR_FMT "; size %" PRId32 "; count %" PRId32, address, size, count); if (count == 0 || buffer == NULL) From 7a27423e31cee1cef205ee8ef703e6e3bf56782b Mon Sep 17 00:00:00 2001 From: Michael Schwingen Date: Thu, 25 Apr 2019 22:05:55 +0200 Subject: [PATCH 143/176] fix XScale register access since b5964191f0, all XScale-specific registers were missing, breaking config scripts. Change-Id: Ia56f3ca17500ba54bd08f417e9a5aaaa8a1be8c4 Signed-off-by: Michael Schwingen Reviewed-on: http://openocd.zylin.com/5136 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/xscale.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target/xscale.c b/src/target/xscale.c index 093925b62..1a099c946 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -2895,6 +2895,7 @@ static void xscale_build_reg_cache(struct target *target) (*cache_p)->reg_list[i].size = 32; (*cache_p)->reg_list[i].arch_info = &arch_info[i]; (*cache_p)->reg_list[i].type = &xscale_reg_type; + (*cache_p)->reg_list[i].exist = true; arch_info[i] = xscale_reg_arch_info[i]; arch_info[i].target = target; } From 20396e56b75d786c535f5655da862f1addc9e255 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Fri, 26 Apr 2019 08:44:38 +0200 Subject: [PATCH 144/176] target: make target re-configuration possible again Before commit 877cec20dca6e78f9f029f0f173879cda101a6c2 ("command: check command mode for native jim commands") all the jim commands were erroneously treated as they had mode COMMAND_ANY. The command '$_TARGET configure -xxx' was therefore applicable on running OpenOCD to change the target configuration. It is handy e.g. for changing an event handler or changes of the work area. Change 'configure' command .mode to COMMAND_ANY to make it possible again. The only parameter which cannot be re-configured after init is -gdb-port. Test the command mode and refuse setting of gdb port after init. Change-Id: I88493ac10a46647dc52a88fbc9f8ce6b5ba3bcd0 Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5214 Reviewed-by: Antonio Borneo Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/target.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 1e42c5eea..917fb6622 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4893,6 +4893,12 @@ no_params: case TCFG_GDB_PORT: if (goi->isconfigure) { + struct command_context *cmd_ctx = current_command_context(goi->interp); + if (cmd_ctx->mode != COMMAND_CONFIG) { + Jim_SetResultString(goi->interp, "-gdb-port must be configured before 'init'", -1); + return JIM_ERR; + } + const char *s; e = Jim_GetOpt_String(goi, &s, NULL); if (e != JIM_OK) @@ -5194,7 +5200,7 @@ static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const static const struct command_registration target_instance_command_handlers[] = { { .name = "configure", - .mode = COMMAND_CONFIG, + .mode = COMMAND_ANY, .jim_handler = jim_target_configure, .help = "configure a new target for use", .usage = "[target_attribute ...]", From b6fa20875942adad271833ef4dfddc1cfa971857 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Tue, 4 Jun 2019 10:28:54 -0700 Subject: [PATCH 145/176] jtag/drivers/jtag_usb_common: fix typo Change-Id: If1f56fd5d610b993a4ecbc900fac9f90638037c9 Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5202 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/drivers/jtag_usb_common.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index a0fa05865..6337272fb 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -15,18 +15,18 @@ static char *jtag_usb_location; * ------ * 16 chars */ -#define JTAG_USB_MAX_LOCATION_LENGHT 16 +#define JTAG_USB_MAX_LOCATION_LENGTH 16 void jtag_usb_set_location(const char *location) { - if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGHT) == - JTAG_USB_MAX_LOCATION_LENGHT) + if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGTH) == + JTAG_USB_MAX_LOCATION_LENGTH) LOG_WARNING("usb location string is too long!!\n"); if (jtag_usb_location) free(jtag_usb_location); - jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGHT); + jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH); } const char *jtag_usb_get_location(void) @@ -42,8 +42,8 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, bool equal = false; /* strtok need non const char */ - loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGHT); - string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT); + loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGTH); + string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH); ptr = strtok(loc, "-"); if (ptr == NULL) { From 8ed19a2e29bd438db055b2bcda336ddf5a041410 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Mon, 3 Jun 2019 21:19:07 +0200 Subject: [PATCH 146/176] jtag: drivers: buspirate: chunk SWD switch sequence transfer. Commit c2e18bfaeafd changed the size of the JTAG-to-SWD sequence from 15 bytes to 17 bytes. This broke SWD switch sequence transfer for buspirate, since buspirate packets can only hold a payload of up to 16 bytes and we tried to fit the whole sequence in a single packet. Splitting up the sequence transfer in appropriately sized packets makes buspirate SWD work again (successfully tested with buspirate firmwares v6.1 and v7.0). Change-Id: Ib5b412b9e77287d705d2762e31c16d30318b50e3 Signed-off-by: Tilman Sauerbeck Reviewed-on: http://openocd.zylin.com/5200 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- src/jtag/drivers/buspirate.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 2e771cc85..872896ba3 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -1312,7 +1312,7 @@ static int buspirate_swd_switch_seq(enum swd_special_seq seq) { const uint8_t *sequence; int sequence_len; - uint8_t tmp[64]; + uint32_t no_bytes, sequence_offset; switch (seq) { case LINE_RESET: @@ -1335,15 +1335,24 @@ static int buspirate_swd_switch_seq(enum swd_special_seq seq) return ERROR_FAIL; } - /* FIXME: all above sequences fit into one pirate command for now - * but it may cause trouble later - */ + no_bytes = sequence_len; + sequence_offset = 0; - tmp[0] = 0x10 + ((sequence_len - 1) & 0x0F); - memcpy(tmp + 1, sequence, sequence_len); + while (no_bytes) { + uint8_t tmp[17]; + uint32_t to_send; - buspirate_serial_write(buspirate_fd, tmp, sequence_len + 1); - buspirate_serial_read(buspirate_fd, tmp, sequence_len + 1); + to_send = no_bytes > 16 ? 16 : no_bytes; + + tmp[0] = 0x10 + ((to_send - 1) & 0x0F); + memcpy(tmp + 1, &sequence[sequence_offset], to_send); + + buspirate_serial_write(buspirate_fd, tmp, to_send + 1); + buspirate_serial_read(buspirate_fd, tmp, to_send + 1); + + no_bytes -= to_send; + sequence_offset += to_send; + } return ERROR_OK; } From e6990bdd00e80b48ba49e4b440c8d654a9431a34 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sat, 1 Jun 2019 14:49:36 +0200 Subject: [PATCH 147/176] flash/stm32h7x: fix register names to comply with RM0399 Rev2 and RM0433 Rev6 Change-Id: I085d86a2a47f4aeef93a99238e3b80ee294d46df Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5192 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Christopher Head Reviewed-by: Tomas Vanek --- src/flash/nor/stm32h7x.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index cb96cf265..512aca57a 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -38,18 +38,18 @@ #define FLASH_SR 0x10 #define FLASH_CCR 0x14 #define FLASH_OPTCR 0x18 -#define FLASH_OPTCUR 0x1C -#define FLASH_OPTPRG 0x20 +#define FLASH_OPTSR_CUR 0x1C +#define FLASH_OPTSR_PRG 0x20 #define FLASH_OPTCCR 0x24 -#define FLASH_WPSNCUR 0x38 -#define FLASH_WPSNPRG 0x3C +#define FLASH_WPSN_CUR 0x38 +#define FLASH_WPSN_PRG 0x3C /* FLASH_CR register bits */ #define FLASH_LOCK (1 << 0) #define FLASH_PG (1 << 1) #define FLASH_SER (1 << 2) -#define FLASH_BER_CMD (1 << 3) +#define FLASH_BER (1 << 3) #define FLASH_PSIZE_8 (0 << 4) #define FLASH_PSIZE_16 (1 << 4) #define FLASH_PSIZE_32 (2 << 4) @@ -314,7 +314,7 @@ static int stm32x_read_options(struct flash_bank *bank) stm32x_info = bank->driver_priv; /* read current option bytes */ - int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCUR, &optiondata); + int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_CUR, &optiondata); if (retval != ERROR_OK) return retval; @@ -328,13 +328,13 @@ static int stm32x_read_options(struct flash_bank *bank) LOG_INFO("Device Security Bit Set"); /* read current WPSN option bytes */ - retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSNCUR, &optiondata); + retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_CUR, &optiondata); if (retval != ERROR_OK) return retval; stm32x_info->option_bytes.protection = optiondata & 0xff; /* read current WPSN2 option bytes */ - retval = target_read_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSNCUR, &optiondata); + retval = target_read_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_CUR, &optiondata); if (retval != ERROR_OK) return retval; stm32x_info->option_bytes.protection2 = optiondata & 0xff; @@ -361,19 +361,19 @@ static int stm32x_write_options(struct flash_bank *bank) optiondata |= (stm32x_info->option_bytes.user3_options & 0xa3) << 24; /* program options */ - retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTPRG, optiondata); + retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_PRG, optiondata); if (retval != ERROR_OK) return retval; optiondata = stm32x_info->option_bytes.protection & 0xff; /* Program protection WPSNPRG */ - retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSNPRG, optiondata); + retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_PRG, optiondata); if (retval != ERROR_OK) return retval; optiondata = stm32x_info->option_bytes.protection2 & 0xff; /* Program protection WPSNPRG2 */ - retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSNPRG, optiondata); + retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_PRG, optiondata); if (retval != ERROR_OK) return retval; @@ -1030,12 +1030,12 @@ static int stm32x_mass_erase(struct flash_bank *bank) return retval; /* mass erase flash memory bank */ - retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_BER_CMD | FLASH_PSIZE_64); + retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_BER | FLASH_PSIZE_64); if (retval != ERROR_OK) return retval; retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), - FLASH_BER_CMD | FLASH_PSIZE_64 | FLASH_START); + FLASH_BER | FLASH_PSIZE_64 | FLASH_START); if (retval != ERROR_OK) return retval; From 1af83682e0d7dbed0ba6db4b2bbf2542a4f9ab0d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 26 Feb 2019 09:57:14 +0100 Subject: [PATCH 148/176] target: fix error on TCL command "return" in target event handler The TCL command "return" always returns error code JIM_RETURN, to indicate that the effective error code and message are elsewhere. In the current implementation, the caller of target's event only checks for return code JIM_OK and considers any other value, including JIM_RETURN, as an error condition, thus dumping the call-trace. The execution is not stopped because the error is not further propagated, but the error message is annoying and misleading. It can be tested running openocd -f ./test.cfg using the following script "test.cfg". You can replace the board file in line 1, to use a board available in your lab: 1 source [find board/st_nucleo_f4.cfg] 2 [target current] configure -event reset-start {} 3 [target current] configure -event reset-end {return} 4 init 5 proc a {} {[target current] invoke-event reset-start} 6 proc b {} {[target current] invoke-event reset-end} 7 proc c {} {a;b;echo "arrived at the end"} 8 c 9 shutdown The execution produces: ./test.cfg:7: Error: in procedure 'c' called at file "./test.cfg", line 8 in procedure 'b' called at file "./test.cfg", line 7 arrived at the end that shows the call-trace but does not halt the execution. The developer can avoid using the "return" command in the event body by defining a TCL procedure that implements the handler and that contains the "return" command, reducing the handler body to a simple call to the procedure above. But this approach is either not documented nor always intuitive while writing the handler, causing waste of time to look for the false error. Modify target_handle_event() to detect the specific return value of the "return" command and to test the real error code that is, eventually, specified to the TCL "return" command. Change-Id: I2b860bab7233c6ed13ee4098e348d7533e1c4626 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4974 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index 917fb6622..e6c434362 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4526,6 +4526,7 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, void target_handle_event(struct target *target, enum target_event e) { struct target_event_action *teap; + int retval; for (teap = target->event_action; teap != NULL; teap = teap->next) { if (teap->event == e) { @@ -4544,8 +4545,12 @@ void target_handle_event(struct target *target, enum target_event e) struct command_context *cmd_ctx = current_command_context(teap->interp); struct target *saved_target_override = cmd_ctx->current_target_override; cmd_ctx->current_target_override = target; + retval = Jim_EvalObj(teap->interp, teap->body); - if (Jim_EvalObj(teap->interp, teap->body) != JIM_OK) { + if (retval == JIM_RETURN) + retval = teap->interp->returnCode; + + if (retval != JIM_OK) { Jim_MakeErrorMessage(teap->interp); LOG_USER("Error executing event %s on target %s:\n%s", Jim_Nvp_value2name_simple(nvp_target_event, e)->name, From 9879f9bf0434a0ed1ebf69516a8505c2dd160a9b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 3 Jun 2019 15:30:41 +0200 Subject: [PATCH 149/176] jtag: fix error on TCL command "return" in jtag event handler The TCL command "return" always returns error code JIM_RETURN, to indicate that the effective error code and message are elsewhere. In the current implementation, the caller of jtag's event only checks for return code JIM_OK and considers any other value, including JIM_RETURN, as an error condition. It can be tested running openocd on a jtag target and adding a jtag event "setup" with a single line "return", e.g. openocd -f board/ti_cc3200_launchxl.cfg \ -c 'jtag configure cc32xx.cpu -event setup return' to get the message: ../src/jtag/core.c:1599: Error: in procedure 'jtag_init' called at file "../src/jtag/core.c", line 1599 Modify jtag_tap_handle_event() to detect the specific return value of the "return" command and to test the real error code that is, eventually, specified to the TCL "return" command. Change-Id: I6d6febc15ef169638afffbffc1810e0b84fcf5c8 Reported-by: Tomas Vanek Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5199 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/tcl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 0161b2807..cbdf2adfc 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -639,6 +639,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e) { struct jtag_tap_event_action *jteap; + int retval; for (jteap = tap->event_action; jteap != NULL; jteap = jteap->next) { if (jteap->event != e) @@ -649,7 +650,11 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e) tap->dotted_name, e, nvp->name, Jim_GetString(jteap->body, NULL)); - if (Jim_EvalObj(jteap->interp, jteap->body) != JIM_OK) { + retval = Jim_EvalObj(jteap->interp, jteap->body); + if (retval == JIM_RETURN) + retval = jteap->interp->returnCode; + + if (retval != JIM_OK) { Jim_MakeErrorMessage(jteap->interp); LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap->interp), NULL)); continue; From 18f4ef0f5ef2306d95122af5cfb5e700e9f4767b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 24 Feb 2019 18:13:44 +0100 Subject: [PATCH 150/176] target/aarch64: remove dependency from jtag queue Replace jtag specific API jtag_add_reset() with transport independent API adapter_{de}assert_reset(). Change-Id: I32c43e2e47366363521fa3f387de9e2fb1c20852 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4943 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/aarch64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/target/aarch64.c b/src/target/aarch64.c index 9e8983f3f..7acb4726a 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -29,6 +29,7 @@ #include "armv8_opcodes.h" #include "armv8_cache.h" #include "arm_semihosting.h" +#include "jtag/interface.h" #include "smp.h" #include @@ -1662,7 +1663,7 @@ static int aarch64_assert_reset(struct target *target) /* REVISIT handle "pulls" cases, if there's * hardware that needs them to work. */ - jtag_add_reset(0, 1); + adapter_assert_reset(); } else { LOG_ERROR("%s: how to reset?", target_name(target)); return ERROR_FAIL; @@ -1686,7 +1687,7 @@ static int aarch64_deassert_reset(struct target *target) LOG_DEBUG(" "); /* be certain SRST is off */ - jtag_add_reset(0, 0); + adapter_deassert_reset(); if (!target_was_examined(target)) return ERROR_OK; From 4dbcb1e79d94a113af9c3da9c6f172782515f35e Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 24 Feb 2019 18:16:39 +0100 Subject: [PATCH 151/176] target/cortex_a: remove dependency from jtag queue Replace jtag specific API jtag_add_reset() with transport independent API adapter_{de}assert_reset(). Change-Id: I1b917a4c1205115c4e0315373d81a9305e931258 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4944 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/target/cortex_a.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 158de0b24..b3a8a41d0 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -55,6 +55,7 @@ #include "target_type.h" #include "arm_opcodes.h" #include "arm_semihosting.h" +#include "jtag/interface.h" #include "transport/transport.h" #include "smp.h" #include @@ -1659,7 +1660,7 @@ static int cortex_a_assert_reset(struct target *target) */ if (transport_is_swd() || (target->reset_halt && (jtag_get_reset_config() & RESET_SRST_NO_GATING))) - jtag_add_reset(0, 1); + adapter_assert_reset(); } else { LOG_ERROR("%s: how to reset?", target_name(target)); @@ -1682,7 +1683,7 @@ static int cortex_a_deassert_reset(struct target *target) LOG_DEBUG(" "); /* be certain SRST is off */ - jtag_add_reset(0, 0); + adapter_deassert_reset(); if (target_was_examined(target)) { retval = cortex_a_poll(target); From bc94ca241a5d9b1bbd0b0e79f577a27dab58ecd0 Mon Sep 17 00:00:00 2001 From: Omair Javaid Date: Thu, 21 Mar 2019 23:33:13 +0500 Subject: [PATCH 152/176] Support for debugging on ARMv8-M CPUs This patch adds ARMv8-M CPUs detection logic in ARMv7m target specific code. Also adds a slightly different watchpoint manipulation logic for ARMv8-M. This is based on ARMv8-M architecture reference manual. Tested on ARM Musca A board. Change-Id: I0652560954ef02c378a7067fab586edf39d3e9cc Signed-off-by: Omair Javaid Reviewed-on: http://openocd.zylin.com/4997 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/cortex_m.c | 67 +++++++++++++++++++++++++++++++++---------- src/target/cortex_m.h | 10 +++++++ 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index e2960391c..9aaa5bb87 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1391,18 +1391,8 @@ int cortex_m_remove_breakpoint(struct target *target, struct breakpoint *breakpo int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint) { int dwt_num = 0; - uint32_t mask, temp; struct cortex_m_common *cortex_m = target_to_cm(target); - /* watchpoint params were validated earlier */ - mask = 0; - temp = watchpoint->length; - while (temp) { - temp >>= 1; - mask++; - } - mask--; - /* REVISIT Don't fully trust these "not used" records ... users * may set up breakpoints by hand, e.g. dual-address data value * watchpoint using comparator #1; comparator #0 matching cycle @@ -1425,11 +1415,22 @@ int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint target_write_u32(target, comparator->dwt_comparator_address + 0, comparator->comp); - comparator->mask = mask; - target_write_u32(target, comparator->dwt_comparator_address + 4, - comparator->mask); + if ((cortex_m->dwt_devarch & 0x1FFFFF) != DWT_DEVARCH_ARMV8M) { + uint32_t mask = 0, temp; - switch (watchpoint->rw) { + /* watchpoint params were validated earlier */ + temp = watchpoint->length; + while (temp) { + temp >>= 1; + mask++; + } + mask--; + + comparator->mask = mask; + target_write_u32(target, comparator->dwt_comparator_address + 4, + comparator->mask); + + switch (watchpoint->rw) { case WPT_READ: comparator->function = 5; break; @@ -1439,7 +1440,26 @@ int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint case WPT_ACCESS: comparator->function = 7; break; + } + } else { + uint32_t data_size = watchpoint->length >> 1; + comparator->mask = (watchpoint->length >> 1) | 1; + + switch (watchpoint->rw) { + case WPT_ACCESS: + comparator->function = 4; + break; + case WPT_WRITE: + comparator->function = 5; + break; + case WPT_READ: + comparator->function = 6; + break; + } + comparator->function = comparator->function | (1 << 4) | + (data_size << 10); } + target_write_u32(target, comparator->dwt_comparator_address + 8, comparator->function); @@ -1982,6 +2002,9 @@ void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target) return; } + target_read_u32(target, DWT_DEVARCH, &cm->dwt_devarch); + LOG_DEBUG("DWT_DEVARCH: 0x%" PRIx32, cm->dwt_devarch); + cm->dwt_num_comp = (dwtcr >> 28) & 0xF; cm->dwt_comp_available = cm->dwt_num_comp; cm->dwt_comparator_list = calloc(cm->dwt_num_comp, @@ -2112,6 +2135,20 @@ int cortex_m_examine(struct target *target) /* Get CPU Type */ i = (cpuid >> 4) & 0xf; + switch (cpuid & ARM_CPUID_PARTNO_MASK) { + case CORTEX_M23_PARTNO: + i = 23; + break; + + case CORTEX_M33_PARTNO: + i = 33; + break; + + default: + break; + } + + LOG_DEBUG("Cortex-M%d r%" PRId8 "p%" PRId8 " processor detected", i, (uint8_t)((cpuid >> 20) & 0xf), (uint8_t)((cpuid >> 0) & 0xf)); cortex_m->maskints_erratum = false; @@ -2138,7 +2175,7 @@ int cortex_m_examine(struct target *target) LOG_DEBUG("Cortex-M%d floating point feature FPv4_SP found", i); armv7m->fp_feature = FPv4_SP; } - } else if (i == 7) { + } else if (i == 7 || i == 33) { target_read_u32(target, MVFR0, &mvfr0); target_read_u32(target, MVFR1, &mvfr1); diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index 2f29903c8..54d7a0228 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -38,6 +38,12 @@ #define ITM_LAR_KEY 0xC5ACCE55 #define CPUID 0xE000ED00 + +#define ARM_CPUID_PARTNO_MASK 0xFFF0 + +#define CORTEX_M23_PARTNO 0xD200 +#define CORTEX_M33_PARTNO 0xD210 + /* Debug Control Block */ #define DCB_DHCSR 0xE000EDF0 #define DCB_DCRSR 0xE000EDF4 @@ -52,6 +58,9 @@ #define DWT_COMP0 0xE0001020 #define DWT_MASK0 0xE0001024 #define DWT_FUNCTION0 0xE0001028 +#define DWT_DEVARCH 0xE0001FBC + +#define DWT_DEVARCH_ARMV8M 0x101A02 #define FP_CTRL 0xE0002000 #define FP_REMAP 0xE0002004 @@ -181,6 +190,7 @@ struct cortex_m_common { /* Data Watchpoint and Trace (DWT) */ int dwt_num_comp; int dwt_comp_available; + uint32_t dwt_devarch; struct cortex_m_dwt_comparator *dwt_comparator_list; struct reg_cache *dwt_cache; From ae449bb5f964032e3fb035c49aa54b6d2a9058c5 Mon Sep 17 00:00:00 2001 From: Omair Javaid Date: Sun, 31 Mar 2019 01:35:43 +0500 Subject: [PATCH 153/176] Configs for ARM corelink SSE-200 target and Musca A board This patch adds configuration files for ARM CoreLink SSE-200 SoCs. Also adds configuration file for SSE-200 based Musca A board. Flash programming support for Musca A QSPI flash is still not functional. This configuration will be updated once that support lands into OpenOCD. Please refer to ARM documentation for more information about SSE-200 and Musca A. Change-Id: Id3783c34d6e2609d659ef91c0bf7252c39439874 Signed-off-by: Omair Javaid Reviewed-on: http://openocd.zylin.com/5006 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/board/arm_musca_a.cfg | 44 ++++++++++++++++++ tcl/target/arm_corelink_sse200.cfg | 71 ++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tcl/board/arm_musca_a.cfg create mode 100644 tcl/target/arm_corelink_sse200.cfg diff --git a/tcl/board/arm_musca_a.cfg b/tcl/board/arm_musca_a.cfg new file mode 100644 index 000000000..fa7cf5eef --- /dev/null +++ b/tcl/board/arm_musca_a.cfg @@ -0,0 +1,44 @@ +# +# Configuration script for ARM Musca-A development board +# +# For now we do not support Musca A flash programming using OpenOCD. However, a +# work area is configured for flash programming speed up. +# +# GDB considers all memory as RAM unless target supplies a memory map. +# OpenOCD will only send memory map if flash banks are configured. Otherwise, +# configure GDB after connection by issuing following commands: +# (gdb) mem 0x10200000 0x109FFFFF ro +# (gdb) mem 0x00200000 0x009FFFFF ro +# (gdb) set mem inaccessible-by-default off + +# ARM Musca A board supports both JTAG and SWD transports. +source [find target/swj-dp.tcl] + +# set a safe JTAG clock speed, can be overridden +adapter_khz 1000 + +global _CHIPNAME +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME MUSCA_A +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x6ba00477 +} + +# Enable CPU1 debugging as a separate GDB target +set _ENABLE_CPU1 1 + +# Musca A1 has 32KB SRAM banks. Override default work-area-size to 8KB per CPU +set WORKAREASIZE_CPU0 0x2000 +set WORKAREASIZE_CPU1 0x2000 + +# Set SRAM bank 1 to be used for work area. Override here if needed. +set WORKAREAADDR_CPU0 0x30008000 +set WORKAREAADDR_CPU1 0x3000A000 + +source [find target/arm_corelink_sse200.cfg] diff --git a/tcl/target/arm_corelink_sse200.cfg b/tcl/target/arm_corelink_sse200.cfg new file mode 100644 index 000000000..ca30649ce --- /dev/null +++ b/tcl/target/arm_corelink_sse200.cfg @@ -0,0 +1,71 @@ +# +# Configuration script for Arm CoreLink SSE-200 Subsystem based IoT SoCs. +# + +global TARGET +set TARGET $_CHIPNAME + +swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# +# SRAM on ARM CoreLink SSE-200 can be 4 banks of 8/16/32/64 KB +# We will configure work area assuming 8-KB bank size in SRAM bank 1. +# Also SRAM start addresses defaults to secure mode alias. +# These values can be overridden as per board configuration +# + +global _WORKAREASIZE_CPU0 +if { [info exists WORKAREASIZE_CPU0] } { + set _WORKAREASIZE_CPU0 $WORKAREASIZE_CPU0 +} else { + set _WORKAREASIZE_CPU0 0x1000 +} + +global _WORKAREAADDR_CPU0 +if { [info exists WORKAREAADDR_CPU0] } { + set _WORKAREAADDR_CPU0 $WORKAREAADDR_CPU0 +} else { + set _WORKAREAADDR_CPU0 0x30008000 +} + +# +# Target configuration for Cortex M33 Core 0 on ARM CoreLink SSE-200 +# Core 0 is the boot core and will always be configured. +# + +target create ${TARGET}.CPU0 cortex_m -dap $_CHIPNAME.dap -ap-num 1 -coreid 0 + +${TARGET}.CPU0 configure -work-area-phys $_WORKAREAADDR_CPU0 -work-area-size $_WORKAREASIZE_CPU0 -work-area-backup 0 + +${TARGET}.CPU0 cortex_m reset_config sysresetreq + +# +# Target configuration for Cortex M33 Core 1 on ARM CoreLink SSE-200 +# Core 1 is optional and locked at boot until core 0 unlocks it. +# + +if { $_ENABLE_CPU1 } { + global _WORKAREASIZE_CPU1 + if { [info exists WORKAREASIZE_CPU1] } { + set _WORKAREASIZE_CPU1 $WORKAREASIZE_CPU1 + } else { + set _WORKAREASIZE_CPU1 0x1000 + } + + global _WORKAREAADDR_CPU1 + if { [info exists WORKAREAADDR_CPU1] } { + set _WORKAREAADDR_CPU1 $WORKAREAADDR_CPU1 + } else { + set _WORKAREAADDR_CPU1 0x30009000 + } + + target create ${TARGET}.CPU1 cortex_m -dap $_CHIPNAME.dap -ap-num 2 -coreid 1 + + ${TARGET}.CPU1 configure -work-area-phys $_WORKAREAADDR_CPU1 -work-area-size $_WORKAREASIZE_CPU1 -work-area-backup 0 + + ${TARGET}.CPU1 cortex_m reset_config vectreset +} + +# Make sure the default target is the boot core +targets ${TARGET}.CPU0 From 1f1558e74bd14ba633c49916ac1d0e1867cad4f1 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 14 Jun 2019 08:08:47 +0200 Subject: [PATCH 154/176] target/arm_adiv5: Add type for AHB5-AP This access port type comes with the AMBA 5 protocol specification, see 'C1.3 AP' in ARM IHI 0031D. Change-Id: I3c4f0a69230daaf4f5f979de6213fe3c025a089a Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5231 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Muhammad Omair Javaid --- src/target/arm_adi_v5.c | 13 +++++++++---- src/target/arm_adi_v5.h | 3 ++- src/target/cortex_m.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index d772d5c29..d2ec960a8 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -914,7 +914,8 @@ int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_a ((id_val & IDR_TYPE) == type_to_find)) { /* type matches*/ LOG_DEBUG("Found %s at AP index: %d (IDR=0x%08" PRIX32 ")", - (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" : + (type_to_find == AP_TYPE_AHB3_AP) ? "AHB3-AP" : + (type_to_find == AP_TYPE_AHB5_AP) ? "AHB5-AP" : (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" : (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" : (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown", @@ -926,7 +927,8 @@ int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_a } LOG_DEBUG("No %s found", - (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" : + (type_to_find == AP_TYPE_AHB3_AP) ? "AHB3-AP" : + (type_to_find == AP_TYPE_AHB5_AP) ? "AHB5-AP" : (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" : (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" : (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown"); @@ -1466,8 +1468,11 @@ int dap_info_command(struct command_invocation *cmd, case IDR_JEP106_ARM | AP_TYPE_JTAG_AP: command_print(cmd, "\tType is JTAG-AP"); break; - case IDR_JEP106_ARM | AP_TYPE_AHB_AP: - command_print(cmd, "\tType is MEM-AP AHB"); + case IDR_JEP106_ARM | AP_TYPE_AHB3_AP: + command_print(cmd, "\tType is MEM-AP AHB3"); + break; + case IDR_JEP106_ARM | AP_TYPE_AHB5_AP: + command_print(cmd, "\tType is MEM-AP AHB5"); break; case IDR_JEP106_ARM | AP_TYPE_APB_AP: command_print(cmd, "\tType is MEM-AP APB"); diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 50fd359c8..6e2d8a182 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -326,9 +326,10 @@ enum ap_class { */ enum ap_type { AP_TYPE_JTAG_AP = 0x0, /* JTAG-AP - JTAG master for controlling other JTAG devices */ - AP_TYPE_AHB_AP = 0x1, /* AHB Memory-AP */ + AP_TYPE_AHB3_AP = 0x1, /* AHB3 Memory-AP */ AP_TYPE_APB_AP = 0x2, /* APB Memory-AP */ AP_TYPE_AXI_AP = 0x4, /* AXI Memory-AP */ + AP_TYPE_AHB5_AP = 0x5, /* AHB5 Memory-AP. */ }; /** diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 9aaa5bb87..ed9397aef 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2107,7 +2107,7 @@ int cortex_m_examine(struct target *target) if (!armv7m->stlink) { if (cortex_m->apsel == DP_APSEL_INVALID) { /* Search for the MEM-AP */ - retval = dap_find_ap(swjdp, AP_TYPE_AHB_AP, &armv7m->debug_ap); + retval = dap_find_ap(swjdp, AP_TYPE_AHB3_AP, &armv7m->debug_ap); if (retval != ERROR_OK) { LOG_ERROR("Could not find MEM-AP to control the core"); return retval; From 0d47d85ff5d3c8512d2475097ef8356267c57cda Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 14 Jun 2019 08:16:19 +0200 Subject: [PATCH 155/176] target/cortex_m: Add support for AHB5-AP The AHB5-AP is implemented in Cortex-M23/33 based devices. Change-Id: I505954a2e2c6462ce0aa96eba1d55b016c5028b9 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5232 Reviewed-by: Matthias Welwarsky Tested-by: jenkins --- src/target/cortex_m.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index ed9397aef..63603da39 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2093,6 +2093,15 @@ static void cortex_m_dwt_free(struct target *target) #define MVFR1_DEFAULT_M7_SP 0x11000011 #define MVFR1_DEFAULT_M7_DP 0x12000011 +static int cortex_m_find_mem_ap(struct adiv5_dap *swjdp, + struct adiv5_ap **debug_ap) +{ + if (dap_find_ap(swjdp, AP_TYPE_AHB3_AP, debug_ap) == ERROR_OK) + return ERROR_OK; + + return dap_find_ap(swjdp, AP_TYPE_AHB5_AP, debug_ap); +} + int cortex_m_examine(struct target *target) { int retval; @@ -2107,7 +2116,7 @@ int cortex_m_examine(struct target *target) if (!armv7m->stlink) { if (cortex_m->apsel == DP_APSEL_INVALID) { /* Search for the MEM-AP */ - retval = dap_find_ap(swjdp, AP_TYPE_AHB3_AP, &armv7m->debug_ap); + retval = cortex_m_find_mem_ap(swjdp, &armv7m->debug_ap); if (retval != ERROR_OK) { LOG_ERROR("Could not find MEM-AP to control the core"); return retval; From 56de276d91ea47cfbcaef7abd72be898609f9207 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Wed, 5 Jun 2019 13:34:29 +0200 Subject: [PATCH 156/176] tcl/target: Add initial Microchip SAML1x support There is not flash bank support at the moment. Change-Id: I833c009d9d21cdeb70b57d67eb557d50ed0fb4de Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5205 Tested-by: jenkins Reviewed-by: Tomas Vanek Reviewed-by: Matthias Welwarsky --- tcl/target/atsaml1x.cfg | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tcl/target/atsaml1x.cfg diff --git a/tcl/target/atsaml1x.cfg b/tcl/target/atsaml1x.cfg new file mode 100644 index 000000000..3486746f7 --- /dev/null +++ b/tcl/target/atsaml1x.cfg @@ -0,0 +1,31 @@ +# +# Microchip (formerly Atmel) SAM L1x target +# +# Note: These devices support SWD only. +# + +transport select swd + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME saml1x +} + +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x800 +} + +swd newdap $_CHIPNAME cpu -expected-id 0x0bf11477 +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap + +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 + +if {![using_hla]} { + cortex_m reset_config sysresetreq +} From 42cee465c24a72a07e1cc383c511be19bfd3884e Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Wed, 5 Jun 2019 13:35:14 +0200 Subject: [PATCH 157/176] tcl/board: Add SAML11 Xplained Pro Evaluation Kit Change-Id: I118929cdecd9ba1f39d6e2791c114ac7e347b3f5 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5206 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- tcl/board/microchip_saml11_xplained_pro.cfg | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tcl/board/microchip_saml11_xplained_pro.cfg diff --git a/tcl/board/microchip_saml11_xplained_pro.cfg b/tcl/board/microchip_saml11_xplained_pro.cfg new file mode 100644 index 000000000..3558a8e71 --- /dev/null +++ b/tcl/board/microchip_saml11_xplained_pro.cfg @@ -0,0 +1,10 @@ +# +# Microchip (formerly Atmel) SAM L11 Xplained Pro Evaluation Kit. +# https://www.microchip.com/DevelopmentTools/ProductDetails/dm320205 +# + +source [find interface/cmsis-dap.cfg] +adapter_khz 1000 + +set CHIPNAME saml11 +source [find target/atsaml1x.cfg] From 23b6aa9bf864d8e8648394b72f62611f442cc6d0 Mon Sep 17 00:00:00 2001 From: Kevin Gillespie Date: Wed, 12 Jun 2019 08:54:51 -0500 Subject: [PATCH 158/176] doc: makeinfo extra whitespace Extra whitespace in file creating build errors with makeinfo. Change-Id: Ib764850c1c8ff596d3c753eadd8e27f8c5982d20 Signed-off-by: Kevin Gillespie Reviewed-on: http://openocd.zylin.com/5229 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/openocd.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 57d1b0959..72986fd51 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3479,7 +3479,7 @@ How long (in milliseconds) OpenOCD should wait after deasserting nTRST (active-low JTAG TAP reset) before starting new JTAG operations. @end deffn -@anchor {reset_config} +@anchor{reset_config} @deffn {Command} reset_config mode_flag ... This command displays or modifies the reset configuration of your combination of JTAG board and target in target From 77a8914b7f960a304406ba4fd39b410c50f25be8 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Fri, 7 Jun 2019 11:40:25 -0700 Subject: [PATCH 159/176] helper/command: make command_run_line reentrant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `command_run_line` function contains a comment saying it should be reentrant. However, it isn’t: it NULLs out `current_target_override` and doesn’t restore it before returning, and it changes the `context` associated data of the `interp` object and then deletes that associated data before returning rather than restoring it to its previous value. Change-Id: I84fd46ef7173f08cf7c57b9a5b76e4986a60816f Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5223 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- src/helper/command.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/helper/command.c b/src/helper/command.c index ab0654b6e..7b93df6e1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -652,9 +652,11 @@ int command_run_line(struct command_context *context, char *line) * happen when the Jim Tcl interpreter is provided by eCos for * instance. */ + struct target *saved_target_override = context->current_target_override; context->current_target_override = NULL; Jim_Interp *interp = context->interp; + struct command_context *old_context = Jim_GetAssocData(interp, "context"); Jim_DeleteAssocData(interp, "context"); retcode = Jim_SetAssocData(interp, "context", NULL, context); if (retcode == JIM_OK) { @@ -667,7 +669,11 @@ int command_run_line(struct command_context *context, char *line) Jim_DeleteAssocData(interp, "retval"); } Jim_DeleteAssocData(interp, "context"); + int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context); + if (retcode == JIM_OK) + retcode = inner_retcode; } + context->current_target_override = saved_target_override; if (retcode == JIM_OK) { const char *result; int reslen; From a521d93b7a2763a9dcc50e8cae0f037a24f4bfa1 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 8 Jun 2019 17:29:58 +0200 Subject: [PATCH 160/176] helper/options: simplify the code using command_run_linef() Thanks to command_run_linef() there is no need to pre-build the command using alloc_printf(). Change-Id: Iccfebd6063d1ac162f090fe2309b1f51bebf0214 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5226 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/options.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/helper/options.c b/src/helper/options.c index 12755e010..b60d58de8 100644 --- a/src/helper/options.c +++ b/src/helper/options.c @@ -269,19 +269,14 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[]) break; case 'd': /* --debug | -d */ { - char *command = alloc_printf("debug_level %s", optarg ? optarg : "3"); - int retval = command_run_line(cmd_ctx, command); - free(command); + int retval = command_run_linef(cmd_ctx, "debug_level %s", optarg ? optarg : "3"); if (retval != ERROR_OK) return retval; break; } case 'l': /* --log_output | -l */ - if (optarg) { - char *command = alloc_printf("log_output %s", optarg); - command_run_line(cmd_ctx, command); - free(command); - } + if (optarg) + command_run_linef(cmd_ctx, "log_output %s", optarg); break; case 'c': /* --command | -c */ if (optarg) From 6ea43726a801baa718fd08dcdb8ae5835b8a2385 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 3 Mar 2019 00:22:37 +0100 Subject: [PATCH 161/176] cortex_m: set C_DEBUGEN in soft_reset_halt The command "soft_reset_halt" is deprecated since mid 2013 with the commit 146dfe32956d ("cortex_m: deprecate soft_reset_halt"). Nevertheless it is still extremely useful with multicore chips where it allows to reset only one of the cores, option not available through asserting the chip-wide srst. Without a better replacement of the command, it's worth fixing it. Accordingly to ARM DDI 0403E.d, chapter C1.4.1 "Entering Debug state on leaving reset state", to halt the core at reset both bits DHCSR.C_DEBUGEN and DEMCR.VC_CORERESET must be set. Current code only sets the latter bit, relying on having C_DEBUGEN already set through other commands, e.g. "halt". This prevents the command "soft_reset_halt" to work if issued as very first command. Set the bit C_DEBUGEN in command "soft_reset_halt". Change-Id: I66bfd6a0da1fca5049dea037b4d258cf6f842966 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4987 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- src/target/cortex_m.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 63603da39..7f59401b1 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -716,6 +716,11 @@ static int cortex_m_soft_reset_halt(struct target *target) * core, not the peripherals */ LOG_WARNING("soft_reset_halt is deprecated, please use 'reset halt' instead."); + /* Set C_DEBUGEN */ + retval = cortex_m_write_debug_halt_mask(target, 0, C_STEP | C_MASKINTS); + if (retval != ERROR_OK) + return retval; + /* Enter debug state on reset; restore DEMCR in endreset_event() */ retval = mem_ap_write_u32(armv7m->debug_ap, DCB_DEMCR, TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET); From 263deb3802a515ba8155b6c59146f0f539de4e43 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Wed, 26 Jun 2019 11:24:39 +0200 Subject: [PATCH 162/176] configure.ac: Fix ST-Link adapter description The ST-Link driver supports not only JTAG but also SWD and SWIM. Change-Id: I9f0e7b018cae54ed8e73a724151647e050e7bb49 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5247 Reviewed-by: Antonio Borneo Tested-by: jenkins --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9991dc89c..b84e3e8f8 100644 --- a/configure.ac +++ b/configure.ac @@ -110,7 +110,7 @@ m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])]) m4_define([USB1_ADAPTERS], [[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]], - [[stlink], [ST-Link JTAG Programmer], [HLADAPTER_STLINK]], + [[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]], [[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]], [[ulink], [Keil ULINK JTAG Programmer], [ULINK]], [[usb_blaster_2], [Altera USB-Blaster II Compatible], [USB_BLASTER_2]], From 7a93c9e087b7cb0444068a3deb506eb127f758f0 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Wed, 19 Jun 2019 10:31:05 +0200 Subject: [PATCH 163/176] mflash: Remove this broken flash driver This is causing repeated build failures. Its design is so fundamentally broken that if someone actually wants to use it, a full rewrite is the only option. So it's not even worth deprecating in the hope that someone will notice and fix it, just get rid of it. Change-Id: I513069919a3873bd69253110f7fb6f622ee7d061 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/5243 Tested-by: jenkins Reviewed-by: Jeffrey Booher-Kaeding Reviewed-by: Antonio Borneo --- doc/openocd.texi | 61 -- src/flash/Makefile.am | 3 +- src/flash/mflash.c | 1450 ----------------------------------------- src/flash/mflash.h | 289 -------- src/openocd.c | 5 - 5 files changed, 1 insertion(+), 1807 deletions(-) delete mode 100644 src/flash/mflash.c delete mode 100644 src/flash/mflash.h diff --git a/doc/openocd.texi b/doc/openocd.texi index 72986fd51..9490f88fb 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -7482,67 +7482,6 @@ or @code{read_page} methods, so @command{nand raw_access} won't change any behavior. @end deffn -@section mFlash - -@subsection mFlash Configuration -@cindex mFlash Configuration - -@deffn {Config Command} {mflash bank} soc base RST_pin target -Configures a mflash for @var{soc} host bank at -address @var{base}. -The pin number format depends on the host GPIO naming convention. -Currently, the mflash driver supports s3c2440 and pxa270. - -Example for s3c2440 mflash where @var{RST pin} is GPIO B1: - -@example -mflash bank $_FLASHNAME s3c2440 0x10000000 1b 0 -@end example - -Example for pxa270 mflash where @var{RST pin} is GPIO 43: - -@example -mflash bank $_FLASHNAME pxa270 0x08000000 43 0 -@end example -@end deffn - -@subsection mFlash commands -@cindex mFlash commands - -@deffn Command {mflash config pll} frequency -Configure mflash PLL. -The @var{frequency} is the mflash input frequency, in Hz. -Issuing this command will erase mflash's whole internal nand and write new pll. -After this command, mflash needs power-on-reset for normal operation. -If pll was newly configured, storage and boot(optional) info also need to be update. -@end deffn - -@deffn Command {mflash config boot} -Configure bootable option. -If bootable option is set, mflash offer the first 8 sectors -(4kB) for boot. -@end deffn - -@deffn Command {mflash config storage} -Configure storage information. -For the normal storage operation, this information must be -written. -@end deffn - -@deffn Command {mflash dump} num filename offset size -Dump @var{size} bytes, starting at @var{offset} bytes from the -beginning of the bank @var{num}, to the file named @var{filename}. -@end deffn - -@deffn Command {mflash probe} -Probe mflash. -@end deffn - -@deffn Command {mflash write} num filename offset -Write the binary file @var{filename} to mflash bank @var{num}, starting at -@var{offset} bytes from the beginning of the bank. -@end deffn - @node Flash Programming @chapter Flash Programming diff --git a/src/flash/Makefile.am b/src/flash/Makefile.am index a1b46f853..4c70702b5 100644 --- a/src/flash/Makefile.am +++ b/src/flash/Makefile.am @@ -1,7 +1,6 @@ noinst_LTLIBRARIES += %D%/libflash.la %C%_libflash_la_SOURCES = \ - %D%/common.c %D%/common.h \ - %D%/mflash.c %D%/mflash.h + %D%/common.c %D%/common.h %C%_libflash_la_LIBADD = \ %D%/nor/libocdflashnor.la \ diff --git a/src/flash/mflash.c b/src/flash/mflash.c deleted file mode 100644 index acf1441b7..000000000 --- a/src/flash/mflash.c +++ /dev/null @@ -1,1450 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by unsik Kim * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mflash.h" -#include -#include -#include -#include - -static int s3c2440_set_gpio_to_output(struct mflash_gpio_num gpio); -static int s3c2440_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val); -static int pxa270_set_gpio_to_output(struct mflash_gpio_num gpio); -static int pxa270_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val); - -static struct mflash_bank *mflash_bank; - -static struct mflash_gpio_drv pxa270_gpio = { - .name = "pxa270", - .set_gpio_to_output = pxa270_set_gpio_to_output, - .set_gpio_output_val = pxa270_set_gpio_output_val -}; - -static struct mflash_gpio_drv s3c2440_gpio = { - .name = "s3c2440", - .set_gpio_to_output = s3c2440_set_gpio_to_output, - .set_gpio_output_val = s3c2440_set_gpio_output_val -}; - -static struct mflash_gpio_drv *mflash_gpio[] = { - &pxa270_gpio, - &s3c2440_gpio, - NULL -}; - -#define PXA270_GAFR0_L 0x40E00054 -#define PXA270_GAFR3_U 0x40E00070 -#define PXA270_GAFR3_U_RESERVED_BITS 0xfffc0000u -#define PXA270_GPDR0 0x40E0000C -#define PXA270_GPDR3 0x40E0010C -#define PXA270_GPDR3_RESERVED_BITS 0xfe000000u -#define PXA270_GPSR0 0x40E00018 -#define PXA270_GPCR0 0x40E00024 - -static int pxa270_set_gpio_to_output(struct mflash_gpio_num gpio) -{ - uint32_t addr, value, mask; - struct target *target = mflash_bank->target; - int ret; - - /* remove alternate function. */ - mask = 0x3u << (gpio.num & 0xF)*2; - - addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value &= ~mask; - if (addr == PXA270_GAFR3_U) - value &= ~PXA270_GAFR3_U_RESERVED_BITS; - - ret = target_write_u32(target, addr, value); - if (ret != ERROR_OK) - return ret; - - /* set direction to output */ - mask = 0x1u << (gpio.num & 0x1F); - - addr = PXA270_GPDR0 + (gpio.num >> 5) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value |= mask; - if (addr == PXA270_GPDR3) - value &= ~PXA270_GPDR3_RESERVED_BITS; - - ret = target_write_u32(target, addr, value); - return ret; -} - -static int pxa270_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val) -{ - uint32_t addr, value, mask; - struct target *target = mflash_bank->target; - int ret; - - mask = 0x1u << (gpio.num & 0x1F); - - if (val) - addr = PXA270_GPSR0 + (gpio.num >> 5) * 4; - else - addr = PXA270_GPCR0 + (gpio.num >> 5) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value |= mask; - - ret = target_write_u32(target, addr, value); - - return ret; -} - -#define S3C2440_GPACON 0x56000000 -#define S3C2440_GPADAT 0x56000004 -#define S3C2440_GPJCON 0x560000d0 -#define S3C2440_GPJDAT 0x560000d4 - -static int s3c2440_set_gpio_to_output(struct mflash_gpio_num gpio) -{ - uint32_t data, mask, gpio_con; - struct target *target = mflash_bank->target; - int ret; - - if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') - gpio_con = S3C2440_GPACON + (gpio.port[0] - 'a') * 0x10; - else if (gpio.port[0] == 'j') - gpio_con = S3C2440_GPJCON; - else { - LOG_ERROR("mflash: invalid port %d%s", gpio.num, gpio.port); - return ERROR_COMMAND_SYNTAX_ERROR; - } - - ret = target_read_u32(target, gpio_con, &data); - - if (ret == ERROR_OK) { - if (gpio.port[0] == 'a') { - mask = 1 << gpio.num; - data &= ~mask; - } else { - mask = 3 << gpio.num * 2; - data &= ~mask; - data |= (1 << gpio.num * 2); - } - - ret = target_write_u32(target, gpio_con, data); - } - return ret; -} - -static int s3c2440_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val) -{ - uint32_t data, mask, gpio_dat; - struct target *target = mflash_bank->target; - int ret; - - if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') - gpio_dat = S3C2440_GPADAT + (gpio.port[0] - 'a') * 0x10; - else if (gpio.port[0] == 'j') - gpio_dat = S3C2440_GPJDAT; - else { - LOG_ERROR("mflash: invalid port %d%s", gpio.num, gpio.port); - return ERROR_COMMAND_SYNTAX_ERROR; - } - - ret = target_read_u32(target, gpio_dat, &data); - - if (ret == ERROR_OK) { - mask = 1 << gpio.num; - if (val) - data |= mask; - else - data &= ~mask; - - ret = target_write_u32(target, gpio_dat, data); - } - return ret; -} - -static int mg_hdrst(uint8_t level) -{ - return mflash_bank->gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, level); -} - -static int mg_init_gpio(void) -{ - int ret; - struct mflash_gpio_drv *gpio_drv = mflash_bank->gpio_drv; - - ret = gpio_drv->set_gpio_to_output(mflash_bank->rst_pin); - if (ret != ERROR_OK) - return ret; - - ret = gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, 1); - - return ret; -} - -static int mg_dsk_wait(mg_io_type_wait wait_local, uint32_t time_var) -{ - uint8_t status, error; - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - int ret; - long long t = 0; - - struct duration bench; - duration_start(&bench); - - while (time_var) { - - ret = target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status); - if (ret != ERROR_OK) - return ret; - - if (status & mg_io_rbit_status_busy) { - if (wait_local == mg_io_wait_bsy) - return ERROR_OK; - } else { - switch (wait_local) { - case mg_io_wait_not_bsy: - return ERROR_OK; - case mg_io_wait_rdy_noerr: - if (status & mg_io_rbit_status_ready) - return ERROR_OK; - break; - case mg_io_wait_drq_noerr: - if (status & mg_io_rbit_status_data_req) - return ERROR_OK; - break; - default: - break; - } - - /* Now we check the error condition! */ - if (status & mg_io_rbit_status_error) { - ret = target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error); - if (ret != ERROR_OK) - return ret; - - LOG_ERROR("mflash: io error 0x%02x", error); - - return ERROR_MG_IO; - } - - switch (wait_local) { - case mg_io_wait_rdy: - if (status & mg_io_rbit_status_ready) - return ERROR_OK; - /* fallthrough */ - case mg_io_wait_drq: - if (status & mg_io_rbit_status_data_req) - return ERROR_OK; - /* fallthrough */ - default: - break; - } - } - - ret = duration_measure(&bench); - if (ERROR_OK == ret) - t = duration_elapsed(&bench) * 1000.0; - else - LOG_ERROR("mflash: duration measurement failed: %d", ret); - - if (t > time_var) - break; - } - - LOG_ERROR("mflash: timeout occured"); - return ERROR_MG_TIMEOUT; -} - -static int mg_dsk_srst(uint8_t on) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - uint8_t value; - int ret; - - ret = target_read_u8(target, mg_task_reg + MG_REG_DRV_CTRL, &value); - if (ret != ERROR_OK) - return ret; - - if (on) - value |= (mg_io_rbit_devc_srst); - else - value &= ~mg_io_rbit_devc_srst; - - ret = target_write_u8(target, mg_task_reg + MG_REG_DRV_CTRL, value); - return ret; -} - -static int mg_dsk_io_cmd(uint32_t sect_num, uint32_t cnt, uint8_t cmd) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - uint8_t value; - int ret; - - ret = mg_dsk_wait(mg_io_wait_rdy_noerr, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - value = mg_io_rval_dev_drv_master | mg_io_rval_dev_lba_mode | ((sect_num >> 24) & 0xf); - - ret = target_write_u8(target, mg_task_reg + MG_REG_DRV_HEAD, value); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_CNT, (uint8_t)cnt); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_NUM, (uint8_t)sect_num); - ret |= target_write_u8(target, mg_task_reg + MG_REG_CYL_LOW, (uint8_t)(sect_num >> 8)); - ret |= target_write_u8(target, mg_task_reg + MG_REG_CYL_HIGH, (uint8_t)(sect_num >> 16)); - - if (ret != ERROR_OK) - return ret; - - return target_write_u8(target, mg_task_reg + MG_REG_COMMAND, cmd); -} - -static int mg_dsk_drv_info(void) -{ - struct target *target = mflash_bank->target; - uint32_t mg_buff = mflash_bank->base + MG_BUFFER_OFFSET; - int ret; - - ret = mg_dsk_io_cmd(0, 1, mg_io_cmd_identify); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: read drive info"); - - if (!mflash_bank->drv_info) - mflash_bank->drv_info = malloc(sizeof(struct mg_drv_info)); - - ret = target_read_memory(target, mg_buff, 2, - sizeof(mg_io_type_drv_info) >> 1, - (uint8_t *)&mflash_bank->drv_info->drv_id); - if (ret != ERROR_OK) - return ret; - - mflash_bank->drv_info->tot_sects = - (uint32_t)(mflash_bank->drv_info->drv_id.total_user_addressable_sectors_hi << 16) - + mflash_bank->drv_info->drv_id.total_user_addressable_sectors_lo; - - return target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_read); -} - -static int mg_mflash_rst(void) -{ - int ret; - - ret = mg_init_gpio(); - if (ret != ERROR_OK) - return ret; - - ret = mg_hdrst(0); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_hdrst(1); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_not_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_srst(1); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_srst(0); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_not_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: reset ok"); - - return ERROR_OK; -} - -static int mg_mflash_probe(void) -{ - int ret = mg_mflash_rst(); - if (ret != ERROR_OK) - return ret; - - return mg_dsk_drv_info(); -} - -COMMAND_HANDLER(mg_probe_cmd) -{ - int ret; - - ret = mg_mflash_probe(); - - if (ret == ERROR_OK) { - command_print(CMD, - "mflash (total %" PRIu32 " sectors) found at 0x%8.8" PRIx32 "", - mflash_bank->drv_info->tot_sects, - mflash_bank->base); - } - - return ret; -} - -static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t i, address; - int ret; - struct target *target = mflash_bank->target; - uint8_t *buff_ptr = buff; - - ret = mg_dsk_io_cmd(sect_num, sect_cnt, mg_io_cmd_read); - if (ret != ERROR_OK) - return ret; - - address = mflash_bank->base + MG_BUFFER_OFFSET; - - struct duration bench; - duration_start(&bench); - - for (i = 0; i < sect_cnt; i++) { - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); - if (ret != ERROR_OK) - return ret; - - buff_ptr += MG_MFLASH_SECTOR_SIZE; - - ret = target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_read); - if (ret != ERROR_OK) - return ret; - - LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector read", sect_num + i, - (sect_num + i) * MG_MFLASH_SECTOR_SIZE); - - ret = duration_measure(&bench); - if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) { - LOG_INFO("mflash: read %" PRIu32 "'th sectors", sect_num + i); - duration_start(&bench); - } - } - - return mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_NORMAL); -} - -static int mg_mflash_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t quotient, residue, i; - uint8_t *buff_ptr = buff; - int ret = ERROR_OK; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", - sect_num, buff_ptr); - ret = mg_mflash_do_read_sects(buff_ptr, sect_num, 256); - if (ret != ERROR_OK) - return ret; - - sect_num += 256; - buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE; - } - - if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIx32 " buff : %p", - sect_num, buff_ptr); - return mg_mflash_do_read_sects(buff_ptr, sect_num, residue); - } - - return ret; -} - -static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt, - uint8_t cmd) -{ - uint32_t i, address; - int ret; - struct target *target = mflash_bank->target; - uint8_t *buff_ptr = buff; - - ret = mg_dsk_io_cmd(sect_num, sect_cnt, cmd); - if (ret != ERROR_OK) - return ret; - - address = mflash_bank->base + MG_BUFFER_OFFSET; - - struct duration bench; - duration_start(&bench); - - for (i = 0; i < sect_cnt; i++) { - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); - if (ret != ERROR_OK) - return ret; - - buff_ptr += MG_MFLASH_SECTOR_SIZE; - - ret = target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_write); - if (ret != ERROR_OK) - return ret; - - LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector write", sect_num + i, - (sect_num + i) * MG_MFLASH_SECTOR_SIZE); - - ret = duration_measure(&bench); - if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) { - LOG_INFO("mflash: wrote %" PRIu32 "'th sectors", sect_num + i); - duration_start(&bench); - } - } - - if (cmd == mg_io_cmd_write) - ret = mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_NORMAL); - else - ret = mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_LONG); - - return ret; -} - -static int mg_mflash_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t quotient, residue, i; - uint8_t *buff_ptr = buff; - int ret = ERROR_OK; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 "buff : %p", sect_num, - buff_ptr); - ret = mg_mflash_do_write_sects(buff_ptr, sect_num, 256, mg_io_cmd_write); - if (ret != ERROR_OK) - return ret; - - sect_num += 256; - buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE; - } - - if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", sect_num, - buff_ptr); - return mg_mflash_do_write_sects(buff_ptr, sect_num, residue, mg_io_cmd_write); - } - - return ret; -} - -static int mg_mflash_read(uint32_t addr, uint8_t *buff, uint32_t len) -{ - uint8_t *buff_ptr = buff; - uint8_t sect_buff[MG_MFLASH_SECTOR_SIZE]; - uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num; - int ret = ERROR_OK; - - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - if (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK) { - - next_sec_addr = (cur_addr + MG_MFLASH_SECTOR_SIZE) & ~MG_MFLASH_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - if (end_addr < next_sec_addr) { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - end_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte from sector offset 0x%8.8" PRIx32 "", - end_addr - cur_addr, - cur_addr); - cur_addr = end_addr; - } else { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - next_sec_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte from sector offset 0x%8.8" PRIx32 "", - next_sec_addr - cur_addr, - cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - } - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - next_sec_addr = cur_addr + MG_MFLASH_SECTOR_SIZE; - - while (next_sec_addr <= end_addr) { - cnt++; - next_sec_addr += MG_MFLASH_SECTOR_SIZE; - } - - if (cnt) { - ret = mg_mflash_read_sects(buff_ptr, sect_num, cnt); - if (ret != ERROR_OK) - return ret; - } - - buff_ptr += cnt * MG_MFLASH_SECTOR_SIZE; - cur_addr += cnt * MG_MFLASH_SECTOR_SIZE; - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - memcpy(buff_ptr, sect_buff, end_addr - cur_addr); - LOG_DEBUG("mflash: copies %u byte", (unsigned)(end_addr - cur_addr)); - } - } - - return ret; -} - -static int mg_mflash_write(uint32_t addr, uint8_t *buff, uint32_t len) -{ - uint8_t *buff_ptr = buff; - uint8_t sect_buff[MG_MFLASH_SECTOR_SIZE]; - uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num; - int ret = ERROR_OK; - - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - if (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK) { - - next_sec_addr = (cur_addr + MG_MFLASH_SECTOR_SIZE) & ~MG_MFLASH_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - if (end_addr < next_sec_addr) { - memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - buff_ptr, - end_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte to sector offset 0x%8.8" PRIx32 "", - end_addr - cur_addr, - cur_addr); - cur_addr = end_addr; - } else { - memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - buff_ptr, - next_sec_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte to sector offset 0x%8.8" PRIx32 "", - next_sec_addr - cur_addr, - cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - - ret = mg_mflash_write_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - } - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - next_sec_addr = cur_addr + MG_MFLASH_SECTOR_SIZE; - - while (next_sec_addr <= end_addr) { - cnt++; - next_sec_addr += MG_MFLASH_SECTOR_SIZE; - } - - if (cnt) { - ret = mg_mflash_write_sects(buff_ptr, sect_num, cnt); - if (ret != ERROR_OK) - return ret; - } - - buff_ptr += cnt * MG_MFLASH_SECTOR_SIZE; - cur_addr += cnt * MG_MFLASH_SECTOR_SIZE; - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - memcpy(sect_buff, buff_ptr, end_addr - cur_addr); - LOG_DEBUG("mflash: copies %" PRIu32 " byte", end_addr - cur_addr); - ret = mg_mflash_write_sects(sect_buff, sect_num, 1); - } - } - - return ret; -} - -COMMAND_HANDLER(mg_write_cmd) -{ - uint32_t address, cnt, res, i; - uint8_t *buffer; - struct fileio *fileio; - int ret; - - if (CMD_ARGC != 3) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], address); - - ret = fileio_open(&fileio, CMD_ARGV[1], FILEIO_READ, FILEIO_BINARY); - if (ret != ERROR_OK) - return ret; - - size_t filesize; - buffer = malloc(MG_FILEIO_CHUNK); - if (!buffer) { - fileio_close(fileio); - return ERROR_FAIL; - } - int retval = fileio_size(fileio, &filesize); - if (retval != ERROR_OK) { - fileio_close(fileio); - free(buffer); - return retval; - } - - cnt = filesize / MG_FILEIO_CHUNK; - res = filesize % MG_FILEIO_CHUNK; - - struct duration bench; - duration_start(&bench); - - size_t buf_cnt; - for (i = 0; i < cnt; i++) { - ret = fileio_read(fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - ret = mg_mflash_write(address, buffer, MG_FILEIO_CHUNK); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - address += MG_FILEIO_CHUNK; - } - - if (res) { - ret = fileio_read(fileio, res, buffer, &buf_cnt); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - ret = mg_mflash_write(address, buffer, res); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - } - - if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD, "wrote %zu bytes from file %s " - "in %fs (%0.3f kB/s)", filesize, CMD_ARGV[1], - duration_elapsed(&bench), duration_kbps(&bench, filesize)); - } - - free(buffer); - fileio_close(fileio); - - return ERROR_OK; - -mg_write_cmd_err: - free(buffer); - fileio_close(fileio); - - return ret; -} - -COMMAND_HANDLER(mg_dump_cmd) -{ - uint32_t address, size, cnt, res, i; - uint8_t *buffer; - struct fileio *fileio; - int ret; - - if (CMD_ARGC != 4) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], address); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], size); - - ret = fileio_open(&fileio, CMD_ARGV[1], FILEIO_WRITE, FILEIO_BINARY); - if (ret != ERROR_OK) - return ret; - - buffer = malloc(MG_FILEIO_CHUNK); - if (!buffer) { - fileio_close(fileio); - return ERROR_FAIL; - } - - cnt = size / MG_FILEIO_CHUNK; - res = size % MG_FILEIO_CHUNK; - - struct duration bench; - duration_start(&bench); - - size_t size_written; - for (i = 0; i < cnt; i++) { - ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - ret = fileio_write(fileio, MG_FILEIO_CHUNK, buffer, &size_written); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - address += MG_FILEIO_CHUNK; - } - - if (res) { - ret = mg_mflash_read(address, buffer, res); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - ret = fileio_write(fileio, res, buffer, &size_written); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - } - - if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD, "dump image (address 0x%8.8" PRIx32 " " - "size %" PRIu32 ") to file %s in %fs (%0.3f kB/s)", - address, size, CMD_ARGV[1], - duration_elapsed(&bench), duration_kbps(&bench, size)); - } - - free(buffer); - fileio_close(fileio); - - return ERROR_OK; - -mg_dump_cmd_err: - free(buffer); - fileio_close(fileio); - - return ret; -} - -static int mg_set_feature(mg_feature_id feature, mg_feature_val config) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - int ret; - - ret = mg_dsk_wait(mg_io_wait_rdy_noerr, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_write_u8(target, mg_task_reg + MG_REG_FEATURE, feature); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_CNT, config); - ret |= target_write_u8(target, mg_task_reg + MG_REG_COMMAND, - mg_io_cmd_set_feature); - - return ret; -} - -static int mg_is_valid_pll(double XIN, int N, double CLK_OUT, int NO) -{ - double v1 = XIN / N; - double v2 = CLK_OUT * NO; - - if (v1 < 1000000 || v1 > 15000000 || v2 < 100000000 || v2 > 500000000) - return ERROR_MG_INVALID_PLL; - - return ERROR_OK; -} - -static int mg_pll_get_M(unsigned short feedback_div) -{ - int i, M; - - for (i = 1, M = 0; i < 512; i <<= 1, feedback_div >>= 1) - M += (feedback_div & 1) * i; - - return M + 2; -} - -static int mg_pll_get_N(unsigned char input_div) -{ - int i, N; - - for (i = 1, N = 0; i < 32; i <<= 1, input_div >>= 1) - N += (input_div & 1) * i; - - return N + 2; -} - -static int mg_pll_get_NO(unsigned char output_div) -{ - int i, NO; - - for (i = 0, NO = 1; i < 2; ++i, output_div >>= 1) - if (output_div & 1) - NO = NO << 1; - - return NO; -} - -static double mg_do_calc_pll(double XIN, mg_pll_t *p_pll_val, int is_approximate) -{ - unsigned short i; - unsigned char j, k; - int M, N, NO; - double CLK_OUT; - double DIV = 1; - double ROUND = 0; - - if (is_approximate) { - DIV = 1000000; - ROUND = 500000; - } - - for (i = 0; i < MG_PLL_MAX_FEEDBACKDIV_VAL; ++i) { - M = mg_pll_get_M(i); - - for (j = 0; j < MG_PLL_MAX_INPUTDIV_VAL; ++j) { - N = mg_pll_get_N(j); - - for (k = 0; k < MG_PLL_MAX_OUTPUTDIV_VAL; ++k) { - NO = mg_pll_get_NO(k); - - CLK_OUT = XIN * ((double)M / N) / NO; - - if ((int)((CLK_OUT + ROUND) / DIV) - == (int)(MG_PLL_CLK_OUT / DIV)) { - if (mg_is_valid_pll(XIN, N, CLK_OUT, NO) == ERROR_OK) { - p_pll_val->lock_cyc = - (int)(XIN * MG_PLL_STD_LOCKCYCLE / - MG_PLL_STD_INPUTCLK); - p_pll_val->feedback_div = i; - p_pll_val->input_div = j; - p_pll_val->output_div = k; - - return CLK_OUT; - } - } - } - } - } - - return 0; -} - -static double mg_calc_pll(double XIN, mg_pll_t *p_pll_val) -{ - double CLK_OUT; - - CLK_OUT = mg_do_calc_pll(XIN, p_pll_val, 0); - - if (!CLK_OUT) - return mg_do_calc_pll(XIN, p_pll_val, 1); - else - return CLK_OUT; -} - -static int mg_verify_interface(void) -{ - uint16_t buff[MG_MFLASH_SECTOR_SIZE >> 1]; - uint16_t i, j; - uint32_t address = mflash_bank->base + MG_BUFFER_OFFSET; - struct target *target = mflash_bank->target; - int ret; - - for (j = 0; j < 10; j++) { - for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) - buff[i] = i; - - ret = target_write_memory(target, address, 2, - MG_MFLASH_SECTOR_SIZE / 2, (uint8_t *)buff); - if (ret != ERROR_OK) - return ret; - - memset(buff, 0xff, MG_MFLASH_SECTOR_SIZE); - - ret = target_read_memory(target, address, 2, - MG_MFLASH_SECTOR_SIZE / 2, (uint8_t *)buff); - if (ret != ERROR_OK) - return ret; - - for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) { - if (buff[i] != i) { - LOG_ERROR("mflash: verify interface fail"); - return ERROR_MG_INTERFACE; - } - } - } - - LOG_INFO("mflash: verify interface ok"); - return ret; -} - -static const char g_strSEG_SerialNum[20] = { - 'G', 'm', 'n', 'i', '-', 'e', 'e', 'S', 'g', 'a', 'e', 'l', - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 -}; - -static const char g_strSEG_FWRev[8] = { - 'F', 'X', 'L', 'T', '2', 'v', '0', '.' -}; - -static const char g_strSEG_ModelNum[40] = { - 'F', 'X', 'A', 'L', 'H', 'S', '2', 0x20, '0', '0', 's', '7', - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 -}; - -static void mg_gen_ataid(mg_io_type_drv_info *pSegIdDrvInfo) -{ - /* b15 is ATA device(0) , b7 is Removable Media Device */ - pSegIdDrvInfo->general_configuration = 0x045A; - /* 128MB : Cylinder=> 977 , Heads=> 8 , Sectors=> 32 - * 256MB : Cylinder=> 980 , Heads=> 16 , Sectors=> 32 - * 384MB : Cylinder=> 745 , Heads=> 16 , Sectors=> 63 - */ - pSegIdDrvInfo->number_of_cylinders = 0x02E9; - pSegIdDrvInfo->reserved1 = 0x0; - pSegIdDrvInfo->number_of_heads = 0x10; - pSegIdDrvInfo->unformatted_bytes_per_track = 0x0; - pSegIdDrvInfo->unformatted_bytes_per_sector = 0x0; - pSegIdDrvInfo->sectors_per_track = 0x3F; - pSegIdDrvInfo->vendor_unique1[0] = 0x000B; - pSegIdDrvInfo->vendor_unique1[1] = 0x7570; - pSegIdDrvInfo->vendor_unique1[2] = 0x8888; - - memcpy(pSegIdDrvInfo->serial_number, g_strSEG_SerialNum, 20); - /* 0x2 : dual buffer */ - pSegIdDrvInfo->buffer_type = 0x2; - /* buffer size : 2KB */ - pSegIdDrvInfo->buffer_sector_size = 0x800; - pSegIdDrvInfo->number_of_ecc_bytes = 0; - - memcpy(pSegIdDrvInfo->firmware_revision, g_strSEG_FWRev, 8); - - memcpy(pSegIdDrvInfo->model_number, g_strSEG_ModelNum, 40); - - pSegIdDrvInfo->maximum_block_transfer = 0x4; - pSegIdDrvInfo->vendor_unique2 = 0x0; - pSegIdDrvInfo->dword_io = 0x00; - /* b11 : IORDY support(PIO Mode 4), b10 : Disable/Enbale IORDY - * b9 : LBA support, b8 : DMA mode support - */ - pSegIdDrvInfo->capabilities = 0x1 << 9; - - pSegIdDrvInfo->reserved2 = 0x4000; - pSegIdDrvInfo->vendor_unique3 = 0x00; - /* PIOMode-2 support */ - pSegIdDrvInfo->pio_cycle_timing_mode = 0x02; - pSegIdDrvInfo->vendor_unique4 = 0x00; - /* MultiWord-2 support */ - pSegIdDrvInfo->dma_cycle_timing_mode = 0x00; - /* b1 : word64~70 is valid - * b0 : word54~58 are valid and reflect the current numofcyls,heads,sectors - * b2 : If device supports Ultra DMA , set to one to vaildate word88 - */ - pSegIdDrvInfo->translation_fields_valid = (0x1 << 1) | (0x1 << 0); - pSegIdDrvInfo->number_of_current_cylinders = 0x02E9; - pSegIdDrvInfo->number_of_current_heads = 0x10; - pSegIdDrvInfo->current_sectors_per_track = 0x3F; - pSegIdDrvInfo->current_sector_capacity_lo = 0x7570; - pSegIdDrvInfo->current_sector_capacity_hi = 0x000B; - - pSegIdDrvInfo->multi_sector_count = 0x04; - /* b8 : Multiple secotr setting valid , b[7:0] num of secotrs per block */ - pSegIdDrvInfo->multi_sector_setting_valid = 0x01; - pSegIdDrvInfo->total_user_addressable_sectors_lo = 0x7570; - pSegIdDrvInfo->total_user_addressable_sectors_hi = 0x000B; - pSegIdDrvInfo->single_dma_modes_supported = 0x00; - pSegIdDrvInfo->single_dma_transfer_active = 0x00; - /* b2 :Multi-word DMA mode 2, b1 : Multi-word DMA mode 1 */ - pSegIdDrvInfo->multi_dma_modes_supported = (0x1 << 0); - /* b2 :Multi-word DMA mode 2, b1 : Multi-word DMA mode 1 */ - pSegIdDrvInfo->multi_dma_transfer_active = (0x1 << 0); - /* b0 : PIO Mode-3 support, b1 : PIO Mode-4 support */ - pSegIdDrvInfo->adv_pio_mode = 0x00; - /* 480(0x1E0)nsec for Multi-word DMA mode0 - * 150(0x96) nsec for Multi-word DMA mode1 - * 120(0x78) nsec for Multi-word DMA mode2 - */ - pSegIdDrvInfo->min_dma_cyc = 0x1E0; - pSegIdDrvInfo->recommend_dma_cyc = 0x1E0; - pSegIdDrvInfo->min_pio_cyc_no_iordy = 0x1E0; - pSegIdDrvInfo->min_pio_cyc_with_iordy = 0x1E0; - memset(pSegIdDrvInfo->reserved3, 0x00, 22); - /* b7 : ATA/ATAPI-7 ,b6 : ATA/ATAPI-6 ,b5 : ATA/ATAPI-5,b4 : ATA/ATAPI-4 */ - pSegIdDrvInfo->major_ver_num = 0x7E; - /* 0x1C : ATA/ATAPI-6 T13 1532D revision1 */ - pSegIdDrvInfo->minor_ver_num = 0x19; - /* NOP/READ BUFFER/WRITE BUFFER/Power management feature set support */ - pSegIdDrvInfo->feature_cmd_set_suprt0 = 0x7068; - /* Features/command set is valid/Advanced Pwr management/CFA feature set - * not support - */ - pSegIdDrvInfo->feature_cmd_set_suprt1 = 0x400C; - pSegIdDrvInfo->feature_cmd_set_suprt2 = 0x4000; - /* READ/WRITE BUFFER/PWR Management enable */ - pSegIdDrvInfo->feature_cmd_set_en0 = 0x7000; - /* CFA feature is disabled / Advancde power management disable */ - pSegIdDrvInfo->feature_cmd_set_en1 = 0x0; - pSegIdDrvInfo->feature_cmd_set_en2 = 0x4000; - pSegIdDrvInfo->reserved4 = 0x0; - /* 0x1 * 2minutes */ - pSegIdDrvInfo->req_time_for_security_er_done = 0x19; - pSegIdDrvInfo->req_time_for_enhan_security_er_done = 0x19; - /* Advanced power management level 1 */ - pSegIdDrvInfo->adv_pwr_mgm_lvl_val = 0x0; - pSegIdDrvInfo->reserved5 = 0x0; - memset(pSegIdDrvInfo->reserved6, 0x00, 68); - /* Security mode feature is disabled */ - pSegIdDrvInfo->security_stas = 0x0; - memset(pSegIdDrvInfo->vendor_uniq_bytes, 0x00, 62); - /* CFA power mode 1 support in maximum 200mA */ - pSegIdDrvInfo->cfa_pwr_mode = 0x0100; - memset(pSegIdDrvInfo->reserved7, 0x00, 190); -} - -static int mg_storage_config(void) -{ - uint8_t buff[512]; - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - mg_gen_ataid((mg_io_type_drv_info *)(void *)buff); - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_update_stgdrvinfo); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: storage config ok"); - return ret; -} - -static int mg_boot_config(void) -{ - uint8_t buff[512]; - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - memset(buff, 0xff, 512); - - buff[0] = mg_op_mode_snd; /* operation mode */ - buff[1] = MG_UNLOCK_OTP_AREA; - buff[2] = 4; /* boot size */ - *((uint32_t *)(void *)(buff + 4)) = 0; /* XIP size */ - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_update_xipinfo); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: boot config ok"); - return ret; -} - -static int mg_set_pll(mg_pll_t *pll) -{ - uint8_t buff[512]; - int ret; - - memset(buff, 0xff, 512); - /* PLL Lock cycle and Feedback 9bit Divider */ - memcpy(buff, &pll->lock_cyc, sizeof(uint32_t)); - memcpy(buff + 4, &pll->feedback_div, sizeof(uint16_t)); - buff[6] = pll->input_div; /* PLL Input 5bit Divider */ - buff[7] = pll->output_div; /* PLL Output Divider */ - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_wr_pll); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: set pll ok"); - return ret; -} - -static int mg_erase_nand(void) -{ - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_do_write_sects(NULL, 0, 0, mg_vcmd_purge_nand); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: erase nand ok"); - return ret; -} - -COMMAND_HANDLER(mg_config_cmd) -{ - double fin, fout; - mg_pll_t pll; - int ret; - - ret = mg_verify_interface(); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_rst(); - if (ret != ERROR_OK) - return ret; - - switch (CMD_ARGC) { - case 2: - if (!strcmp(CMD_ARGV[1], "boot")) - return mg_boot_config(); - else if (!strcmp(CMD_ARGV[1], "storage")) - return mg_storage_config(); - else - return ERROR_COMMAND_NOTFOUND; - break; - case 3: - if (!strcmp(CMD_ARGV[1], "pll")) { - unsigned long freq; - COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[2], freq); - fin = freq; - - if (fin > MG_PLL_CLK_OUT) { - LOG_ERROR("mflash: input freq. is too large"); - return ERROR_MG_INVALID_OSC; - } - - fout = mg_calc_pll(fin, &pll); - - if (!fout) { - LOG_ERROR("mflash: cannot generate valid pll"); - return ERROR_MG_INVALID_PLL; - } - - LOG_INFO("mflash: Fout=%" PRIu32 " Hz, feedback=%u," - "indiv=%u, outdiv=%u, lock=%u", - (uint32_t)fout, pll.feedback_div, - pll.input_div, pll.output_div, - pll.lock_cyc); - - ret = mg_erase_nand(); - if (ret != ERROR_OK) - return ret; - - return mg_set_pll(&pll); - } else - return ERROR_COMMAND_NOTFOUND; - break; - default: - return ERROR_COMMAND_SYNTAX_ERROR; - } -} - -static const struct command_registration mflash_exec_command_handlers[] = { - { - .name = "probe", - .handler = mg_probe_cmd, - .mode = COMMAND_EXEC, - .help = "Detect bank configuration information", - .usage = "", - }, - { - .name = "write", - .handler = mg_write_cmd, - .mode = COMMAND_EXEC, - /* FIXME bank_num is unused */ - .usage = "bank_num filename address", - .help = "Write binary file at the specified address.", - }, - { - .name = "dump", - .handler = mg_dump_cmd, - .mode = COMMAND_EXEC, - /* FIXME bank_num is unused */ - .usage = "bank_num filename address size", - .help = "Write specified number of bytes from a binary file " - "to the specified, address.", - }, - { - .name = "config", - .handler = mg_config_cmd, - .mode = COMMAND_EXEC, - .help = "Configure MFLASH options.", - .usage = "('boot'|'storage'|'pll' frequency)", - }, - COMMAND_REGISTRATION_DONE -}; - -static int mflash_init_drivers(struct command_context *cmd_ctx) -{ - if (!mflash_bank) - return ERROR_OK; - return register_commands(cmd_ctx, NULL, mflash_exec_command_handlers); -} - -COMMAND_HANDLER(handle_mflash_init_command) -{ - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - static bool mflash_initialized; - if (mflash_initialized) { - LOG_INFO("'mflash init' has already been called"); - return ERROR_OK; - } - mflash_initialized = true; - - LOG_DEBUG("Initializing mflash devices..."); - return mflash_init_drivers(CMD_CTX); -} - -COMMAND_HANDLER(mg_bank_cmd) -{ - struct target *target; - int i; - - if (CMD_ARGC < 4) - return ERROR_COMMAND_SYNTAX_ERROR; - - target = get_target(CMD_ARGV[3]); - if (target == NULL) { - LOG_ERROR("target '%s' not defined", CMD_ARGV[3]); - return ERROR_FAIL; - } - - mflash_bank = calloc(sizeof(struct mflash_bank), 1); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], mflash_bank->base); - /** @todo Verify how this parsing should work, then document it. */ - char *str; - mflash_bank->rst_pin.num = strtoul(CMD_ARGV[2], &str, 0); - if (*str) - mflash_bank->rst_pin.port[0] = (uint16_t) - tolower((unsigned)str[0]); - - mflash_bank->target = target; - - for (i = 0; mflash_gpio[i]; i++) { - if (!strcmp(mflash_gpio[i]->name, CMD_ARGV[0])) - mflash_bank->gpio_drv = mflash_gpio[i]; - } - - if (!mflash_bank->gpio_drv) { - LOG_ERROR("%s is unsupported soc", CMD_ARGV[0]); - return ERROR_MG_UNSUPPORTED_SOC; - } - - return ERROR_OK; -} - -static const struct command_registration mflash_config_command_handlers[] = { - { - .name = "bank", - .handler = mg_bank_cmd, - .mode = COMMAND_CONFIG, - .help = "configure a mflash device bank", - .usage = "soc_type base_addr pin_id target", - }, - { - .name = "init", - .mode = COMMAND_CONFIG, - .handler = handle_mflash_init_command, - .help = "initialize mflash devices", - .usage = "" - }, - COMMAND_REGISTRATION_DONE -}; -static const struct command_registration mflash_command_handler[] = { - { - .name = "mflash", - .mode = COMMAND_ANY, - .help = "mflash command group", - .usage = "", - .chain = mflash_config_command_handlers, - }, - COMMAND_REGISTRATION_DONE -}; -int mflash_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, mflash_command_handler); -} diff --git a/src/flash/mflash.h b/src/flash/mflash.h deleted file mode 100644 index 18da40361..000000000 --- a/src/flash/mflash.h +++ /dev/null @@ -1,289 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by unsik Kim * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -#ifndef OPENOCD_FLASH_MFLASH_H -#define OPENOCD_FLASH_MFLASH_H - -struct command_context; - -typedef unsigned long mg_io_uint32; -typedef unsigned short mg_io_uint16; -typedef unsigned char mg_io_uint8; - -struct mflash_gpio_num { - char port[2]; - signed short num; -}; - -struct mflash_gpio_drv { - const char *name; - int (*set_gpio_to_output)(struct mflash_gpio_num gpio); - int (*set_gpio_output_val)(struct mflash_gpio_num gpio, uint8_t val); -}; - -typedef struct _mg_io_type_drv_info { - - mg_io_uint16 general_configuration; /* 00 */ - mg_io_uint16 number_of_cylinders; /* 01 */ - mg_io_uint16 reserved1; /* 02 */ - mg_io_uint16 number_of_heads; /* 03 */ - mg_io_uint16 unformatted_bytes_per_track; /* 04 */ - mg_io_uint16 unformatted_bytes_per_sector; /* 05 */ - mg_io_uint16 sectors_per_track; /* 06 */ - mg_io_uint16 vendor_unique1[3]; /* 07/08/09 */ - - mg_io_uint8 serial_number[20]; /* 10~19 */ - - mg_io_uint16 buffer_type; /* 20 */ - mg_io_uint16 buffer_sector_size; /* 21 */ - mg_io_uint16 number_of_ecc_bytes; /* 22 */ - - mg_io_uint8 firmware_revision[8]; /* 23~26 */ - mg_io_uint8 model_number[40]; /* 27 */ - - mg_io_uint8 maximum_block_transfer; /* 47 low byte */ - mg_io_uint8 vendor_unique2; /* 47 high byte */ - mg_io_uint16 dword_io; /* 48 */ - - mg_io_uint16 capabilities; /* 49 */ - mg_io_uint16 reserved2; /* 50 */ - - mg_io_uint8 vendor_unique3; /* 51 low byte */ - mg_io_uint8 pio_cycle_timing_mode; /* 51 high byte */ - mg_io_uint8 vendor_unique4; /* 52 low byte */ - mg_io_uint8 dma_cycle_timing_mode; /* 52 high byte */ - mg_io_uint16 translation_fields_valid; /* 53 (low bit) */ - mg_io_uint16 number_of_current_cylinders; /* 54 */ - mg_io_uint16 number_of_current_heads; /* 55 */ - mg_io_uint16 current_sectors_per_track; /* 56 */ - mg_io_uint16 current_sector_capacity_lo; /* 57 & 58 */ - mg_io_uint16 current_sector_capacity_hi; /* 57 & 58 */ - mg_io_uint8 multi_sector_count; /* 59 low */ - mg_io_uint8 multi_sector_setting_valid; /* 59 high (low bit) */ - - mg_io_uint16 total_user_addressable_sectors_lo; /* 60 & 61 */ - mg_io_uint16 total_user_addressable_sectors_hi; /* 60 & 61 */ - - mg_io_uint8 single_dma_modes_supported; /* 62 low byte */ - mg_io_uint8 single_dma_transfer_active; /* 62 high byte */ - mg_io_uint8 multi_dma_modes_supported; /* 63 low byte */ - mg_io_uint8 multi_dma_transfer_active; /* 63 high byte */ - mg_io_uint16 adv_pio_mode; - mg_io_uint16 min_dma_cyc; - mg_io_uint16 recommend_dma_cyc; - mg_io_uint16 min_pio_cyc_no_iordy; - mg_io_uint16 min_pio_cyc_with_iordy; - mg_io_uint8 reserved3[22]; - mg_io_uint16 major_ver_num; - mg_io_uint16 minor_ver_num; - mg_io_uint16 feature_cmd_set_suprt0; - mg_io_uint16 feature_cmd_set_suprt1; - mg_io_uint16 feature_cmd_set_suprt2; - mg_io_uint16 feature_cmd_set_en0; - mg_io_uint16 feature_cmd_set_en1; - mg_io_uint16 feature_cmd_set_en2; - mg_io_uint16 reserved4; - mg_io_uint16 req_time_for_security_er_done; - mg_io_uint16 req_time_for_enhan_security_er_done; - mg_io_uint16 adv_pwr_mgm_lvl_val; - mg_io_uint16 reserved5; - mg_io_uint16 re_of_hw_rst; - mg_io_uint8 reserved6[68]; - mg_io_uint16 security_stas; - mg_io_uint8 vendor_uniq_bytes[62]; - mg_io_uint16 cfa_pwr_mode; - mg_io_uint8 reserved7[186]; - - mg_io_uint16 scts_per_secure_data_unit; - mg_io_uint16 integrity_word; - -} mg_io_type_drv_info; - -typedef struct _mg_pll_t { - unsigned int lock_cyc; - unsigned short feedback_div; /* 9bit divider */ - unsigned char input_div; /* 5bit divider */ - unsigned char output_div; /* 2bit divider */ -} mg_pll_t; - -struct mg_drv_info { - mg_io_type_drv_info drv_id; - uint32_t tot_sects; -}; - -struct mflash_bank { - uint32_t base; - - struct mflash_gpio_num rst_pin; - - struct mflash_gpio_drv *gpio_drv; - struct target *target; - struct mg_drv_info *drv_info; -}; - -int mflash_register_commands(struct command_context *cmd_ctx); - -#define MG_MFLASH_SECTOR_SIZE (0x200) /* 512Bytes = 2^9 */ -#define MG_MFLASH_SECTOR_SIZE_MASK (0x200-1) -#define MG_MFLASH_SECTOR_SIZE_SHIFT (9) - -#define MG_BUFFER_OFFSET 0x8000 -#define MG_REG_OFFSET 0xC000 -#define MG_REG_FEATURE 0x2 /* write case */ -#define MG_REG_ERROR 0x2 /* read case */ -#define MG_REG_SECT_CNT 0x4 -#define MG_REG_SECT_NUM 0x6 -#define MG_REG_CYL_LOW 0x8 -#define MG_REG_CYL_HIGH 0xA -#define MG_REG_DRV_HEAD 0xC -#define MG_REG_COMMAND 0xE /* write case */ -#define MG_REG_STATUS 0xE /* read case */ -#define MG_REG_DRV_CTRL 0x10 -#define MG_REG_BURST_CTRL 0x12 - -#define MG_OEM_DISK_WAIT_TIME_LONG 15000 /* msec */ -#define MG_OEM_DISK_WAIT_TIME_NORMAL 3000 /* msec */ -#define MG_OEM_DISK_WAIT_TIME_SHORT 1000 /* msec */ - -#define MG_PLL_CLK_OUT 66000000.0 /* 66Mhz */ -#define MG_PLL_MAX_FEEDBACKDIV_VAL 512 -#define MG_PLL_MAX_INPUTDIV_VAL 32 -#define MG_PLL_MAX_OUTPUTDIV_VAL 4 - -#define MG_PLL_STD_INPUTCLK 12000000.0 /* 12Mhz */ -#define MG_PLL_STD_LOCKCYCLE 10000 - -#define MG_UNLOCK_OTP_AREA 0xFF - -#define MG_FILEIO_CHUNK 1048576 - -#define ERROR_MG_IO (-1600) -#define ERROR_MG_TIMEOUT (-1601) -#define ERROR_MG_INVALID_PLL (-1603) -#define ERROR_MG_INTERFACE (-1604) -#define ERROR_MG_INVALID_OSC (-1605) -#define ERROR_MG_UNSUPPORTED_SOC (-1606) - -typedef enum _mg_io_type_wait { - - mg_io_wait_bsy = 1, - mg_io_wait_not_bsy = 2, - mg_io_wait_rdy = 3, - mg_io_wait_drq = 4, /* wait for data request */ - mg_io_wait_drq_noerr = 5, /* wait for DRQ but ignore the error status bit */ - mg_io_wait_rdy_noerr = 6 /* wait for ready, but ignore error status bit */ - -} mg_io_type_wait; - -/*= "Status Register" bit masks. */ -typedef enum _mg_io_type_rbit_status { - - mg_io_rbit_status_error = 0x01, /* error bit in status register */ - mg_io_rbit_status_corrected_error = 0x04, /* corrected error in status register */ - mg_io_rbit_status_data_req = 0x08, /* data request bit in status register */ - mg_io_rbit_status_seek_done = 0x10, /* DSC - Drive Seek Complete */ - mg_io_rbit_status_write_fault = 0x20, /* DWF - Drive Write Fault */ - mg_io_rbit_status_ready = 0x40, - mg_io_rbit_status_busy = 0x80 - -} mg_io_type_rbit_status; - -/*= "Error Register" bit masks. */ -typedef enum _mg_io_type_rbit_error { - - mg_io_rbit_err_general = 0x01, - mg_io_rbit_err_aborted = 0x04, - mg_io_rbit_err_bad_sect_num = 0x10, - mg_io_rbit_err_uncorrectable = 0x40, - mg_io_rbit_err_bad_block = 0x80 - -} mg_io_type_rbit_error; - -/* = "Device Control Register" bit. */ -typedef enum _mg_io_type_rbit_devc { - - mg_io_rbit_devc_intr = 0x02, /* interrupt enable bit (1:disable, 0:enable) */ - mg_io_rbit_devc_srst = 0x04 /* softwrae reset bit (1:assert, 0:de-assert) */ - -} mg_io_type_rbit_devc; - -/* "Drive Select/Head Register" values. */ -typedef enum _mg_io_type_rval_dev { - - mg_io_rval_dev_must_be_on = 0x80, /* These 1 bits are always on */ - mg_io_rval_dev_drv_master = (0x00 | mg_io_rval_dev_must_be_on), /* Master */ - mg_io_rval_dev_drv_slave0 = (0x10 | mg_io_rval_dev_must_be_on), /* Slave0 */ - mg_io_rval_dev_drv_slave1 = (0x20 | mg_io_rval_dev_must_be_on), /* Slave1 */ - mg_io_rval_dev_drv_slave2 = (0x30 | mg_io_rval_dev_must_be_on), /* Slave2 */ - mg_io_rval_dev_lba_mode = (0x40 | mg_io_rval_dev_must_be_on) - -} mg_io_type_rval_dev; - -typedef enum _mg_io_type_cmd { - mg_io_cmd_read = 0x20, - mg_io_cmd_write = 0x30, - - mg_io_cmd_setmul = 0xC6, - mg_io_cmd_readmul = 0xC4, - mg_io_cmd_writemul = 0xC5, - - mg_io_cmd_idle = 0x97, /* 0xE3 */ - mg_io_cmd_idle_immediate = 0x95, /* 0xE1 */ - - mg_io_cmd_setsleep = 0x99, /* 0xE6 */ - mg_io_cmd_stdby = 0x96, /* 0xE2 */ - mg_io_cmd_stdby_immediate = 0x94, /* 0xE0 */ - - mg_io_cmd_identify = 0xEC, - mg_io_cmd_set_feature = 0xEF, - - mg_io_cmd_confirm_write = 0x3C, - mg_io_cmd_confirm_read = 0x40, - mg_io_cmd_wakeup = 0xC3 - -} mg_io_type_cmd; - -typedef enum _mg_feature_id { - mg_feature_id_transmode = 0x3 -} mg_feature_id; - -typedef enum _mg_feature_val { - mg_feature_val_trans_default = 0x0, - mg_feature_val_trans_vcmd = 0x3, - mg_feature_val_trand_vcmds = 0x2 -} mg_feature_val; - -typedef enum _mg_vcmd { - mg_vcmd_update_xipinfo = 0xFA, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_verify_fwpatch = 0xFB, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_update_stgdrvinfo = 0xFC, /* IOM identificatin info program command */ - mg_vcmd_prep_fwpatch = 0xFD, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_exe_fwpatch = 0xFE, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_wr_pll = 0x8B, - mg_vcmd_purge_nand = 0x8C, /* Only for Seagle */ - mg_vcmd_lock_otp = 0x8D, - mg_vcmd_rd_otp = 0x8E, - mg_vcmd_wr_otp = 0x8F -} mg_vcmd; - -typedef enum _mg_opmode { - mg_op_mode_xip = 1, /* TRUE XIP */ - mg_op_mode_snd = 2, /* BOOT + Storage */ - mg_op_mode_stg = 0 /* Only Storage */ -} mg_opmode; - -#endif /* OPENOCD_FLASH_MFLASH_H */ diff --git a/src/openocd.c b/src/openocd.c index f084dd452..2a9a0b3d4 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -165,9 +164,6 @@ COMMAND_HANDLER(handle_init_command) if (command_run_line(CMD_CTX, "flash init") != ERROR_OK) return ERROR_FAIL; - if (command_run_line(CMD_CTX, "mflash init") != ERROR_OK) - return ERROR_FAIL; - if (command_run_line(CMD_CTX, "nand init") != ERROR_OK) return ERROR_FAIL; @@ -257,7 +253,6 @@ struct command_context *setup_command_handler(Jim_Interp *interp) &flash_register_commands, &nand_register_commands, &pld_register_commands, - &mflash_register_commands, &cti_register_commands, &dap_register_commands, NULL From 320f7517c438b690039b6ea3d1320b04ccfabea1 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 1 Jul 2019 14:34:30 +0200 Subject: [PATCH 164/176] contrib/rpc_examples: Adapt to new command line handling Change-Id: I844ef7fbf57a22097a936f4614b4a4c7e980bef6 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5248 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- contrib/rpc_examples/ocd_rpc_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 196ea05f9..4b1516ad9 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -92,7 +92,7 @@ class OpenOcd: self.send("array unset output") # better to clear the array before self.send("mem2array output %d 0x%x %d" % (wordLen, address, n)) - output = [*map(int, self.send("echo $output").split(" "))] + output = [*map(int, self.send("return $output").split(" "))] d = dict([tuple(output[i:i + 2]) for i in range(0, len(output), 2)]) return [d[k] for k in sorted(d.keys())] @@ -116,7 +116,7 @@ if __name__ == "__main__": with OpenOcd() as ocd: ocd.send("reset") - show(ocd.send("echo \"echo says hi!\"")[:-1]) + show(ocd.send("capture { echo \"echo says hi!\" }")[:-1]) show(ocd.send("capture \"halt\"")[:-1]) # Read the first few words at the RAM region (put starting adress of RAM From 16496488d10fc9f6c340b81446a85eef2c95ce00 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 16 Jul 2019 17:14:50 +0200 Subject: [PATCH 165/176] flash/nor/core: fix some minor typo Change-Id: I03832b3e4a6eaadfd87729a3a898e0a2cd30931a Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5264 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/flash/nor/core.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index a8edb2dc9..ff5cb60c4 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -121,7 +121,7 @@ struct flash_bank { /** * The number of sectors on this chip. This value will - * be set intially to 0, and the flash driver must set this to + * be set initially to 0, and the flash driver must set this to * some non-zero value during "probe()" or "auto_probe()". */ int num_sectors; @@ -130,12 +130,12 @@ struct flash_bank { /** * The number of protection blocks in this bank. This value - * is set intially to 0 and sectors are used as protection blocks. + * is set initially to 0 and sectors are used as protection blocks. * Driver probe can set protection blocks array to work with * protection granularity different than sector size. */ int num_prot_blocks; - /** Array of protection blocks, allocated and initilized by the flash driver */ + /** Array of protection blocks, allocated and initialized by the flash driver */ struct flash_sector *prot_blocks; struct flash_bank *next; /**< The next flash bank on this chip */ @@ -242,8 +242,8 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name); */ int get_flash_bank_by_num(int num, struct flash_bank **bank); /** - * Retreives @a bank from a command argument, reporting errors parsing - * the bank identifier or retreiving the specified bank. The bank + * Retrieves @a bank from a command argument, reporting errors parsing + * the bank identifier or retrieving the specified bank. The bank * may be identified by its bank number or by @c name.instance, where * @a instance is driver-specific. * @param name_index The index to the string in args containing the From 081954136681b26ad30db9b4cc40cb360f47602c Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 8 Apr 2019 16:42:48 -0700 Subject: [PATCH 166/176] gdb_server, rtos: Fine-grained RTOS register access 1. Add get_thread_reg() to rtos. It's used in rtos_get_gdb_reg() to read the value of a single register, instead of reading all register values by calling get_thread_reg_list(). 2. Add set_reg() to rtos. gdb_server uses this to change a single register value for a specific thread. 3. Add target_get_gdb_reg_list_noread() so it's possible for gdb to get a list of registers without attempting to read their contents. The clang static checker doesn't find any new problems with this change. Change-Id: I77f792d1238cb015b91527ca8cb99593ccc8870e Signed-off-by: Tim Newsome Reviewed-on: http://openocd.zylin.com/5114 Tested-by: jenkins Reviewed-by: Matthias Welwarsky --- src/rtos/rtos.c | 46 ++++++++++++++++----- src/rtos/rtos.h | 9 +++++ src/server/gdb_server.c | 87 ++++++++++++++++++++++------------------ src/target/register.c | 23 +++++++++++ src/target/register.h | 2 + src/target/target.c | 24 +++++++++-- src/target/target.h | 10 +++++ src/target/target_type.h | 7 ++++ 8 files changed, 158 insertions(+), 50 deletions(-) diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 20e875d8b..002d7b543 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -462,6 +462,7 @@ static int rtos_put_gdb_reg_list(struct connection *connection, return ERROR_OK; } +/** Look through all registers to find this register. */ int rtos_get_gdb_reg(struct connection *connection, int reg_num) { struct target *target = get_target_from_connection(connection); @@ -473,19 +474,31 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num) struct rtos_reg *reg_list; int num_regs; - LOG_DEBUG("RTOS: getting register %d for thread 0x%" PRIx64 - ", target->rtos->current_thread=0x%" PRIx64 "\r\n", + LOG_DEBUG("getting register %d for thread 0x%" PRIx64 + ", target->rtos->current_thread=0x%" PRIx64, reg_num, current_threadid, target->rtos->current_thread); - int retval = target->rtos->type->get_thread_reg_list(target->rtos, - current_threadid, - ®_list, - &num_regs); - if (retval != ERROR_OK) { - LOG_ERROR("RTOS: failed to get register list"); - return retval; + int retval; + if (target->rtos->type->get_thread_reg) { + reg_list = calloc(1, sizeof(*reg_list)); + num_regs = 1; + retval = target->rtos->type->get_thread_reg(target->rtos, + current_threadid, reg_num, ®_list[0]); + if (retval != ERROR_OK) { + LOG_ERROR("RTOS: failed to get register %d", reg_num); + return retval; + } + } else { + retval = target->rtos->type->get_thread_reg_list(target->rtos, + current_threadid, + ®_list, + &num_regs); + if (retval != ERROR_OK) { + LOG_ERROR("RTOS: failed to get register list"); + return retval; + } } for (int i = 0; i < num_regs; ++i) { @@ -501,6 +514,7 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num) return ERROR_FAIL; } +/** Return a list of general registers. */ int rtos_get_gdb_reg_list(struct connection *connection) { struct target *target = get_target_from_connection(connection); @@ -534,6 +548,20 @@ int rtos_get_gdb_reg_list(struct connection *connection) return ERROR_FAIL; } +int rtos_set_reg(struct connection *connection, int reg_num, + uint8_t *reg_value) +{ + struct target *target = get_target_from_connection(connection); + int64_t current_threadid = target->rtos->current_threadid; + if ((target->rtos != NULL) && + (target->rtos->type->set_reg != NULL) && + (current_threadid != -1) && + (current_threadid != 0)) { + return target->rtos->type->set_reg(target->rtos, reg_num, reg_value); + } + return ERROR_FAIL; +} + int rtos_generic_stack_read(struct target *target, const struct rtos_register_stacking *stacking, int64_t stack_ptr, diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h index 93b1731aa..a649e2449 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -20,6 +20,7 @@ #define OPENOCD_RTOS_RTOS_H #include "server/server.h" +#include "target/target.h" #include typedef int64_t threadid_t; @@ -49,7 +50,9 @@ struct rtos { symbol_table_elem_t *symbols; struct target *target; /* add a context variable instead of global variable */ + /* The thread currently selected by gdb. */ int64_t current_threadid; + /* The currently selected thread according to the target. */ threadid_t current_thread; struct thread_detail *thread_details; int thread_count; @@ -70,11 +73,15 @@ struct rtos_type { int (*create)(struct target *target); int (*smp_init)(struct target *target); int (*update_threads)(struct rtos *rtos); + /** Return a list of general registers, with their values filled out. */ int (*get_thread_reg_list)(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); + int (*get_thread_reg)(struct rtos *rtos, int64_t thread_id, + uint32_t reg_num, struct rtos_reg *reg); int (*get_symbol_list_to_lookup)(symbol_table_elem_t *symbol_list[]); int (*clean)(struct target *target); char * (*ps_command)(struct target *target); + int (*set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value); }; struct stack_register_offset { @@ -104,6 +111,8 @@ struct rtos_register_stacking { #define GDB_THREAD_PACKET_NOT_CONSUMED (-40) int rtos_create(Jim_GetOptInfo *goi, struct target *target); +int rtos_set_reg(struct connection *connection, int reg_num, + uint8_t *reg_value); int rtos_generic_stack_read(struct target *target, const struct rtos_register_stacking *stacking, int64_t stack_ptr, diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index ab3e6bef8..02020425e 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -724,7 +724,7 @@ static int gdb_output(struct command_context *context, const char *line) static void gdb_signal_reply(struct target *target, struct connection *connection) { struct gdb_connection *gdb_connection = connection->priv; - char sig_reply[45]; + char sig_reply[65]; char stop_reason[20]; char current_thread[25]; int sig_reply_len; @@ -735,17 +735,25 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio if (target->debug_reason == DBG_REASON_EXIT) { sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00"); } else { + struct target *ct; + if (target->rtos != NULL) { + target->rtos->current_threadid = target->rtos->current_thread; + target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct); + } else { + ct = target; + } + if (gdb_connection->ctrl_c) { signal_var = 0x2; } else - signal_var = gdb_last_signal(target); + signal_var = gdb_last_signal(ct); stop_reason[0] = '\0'; - if (target->debug_reason == DBG_REASON_WATCHPOINT) { + if (ct->debug_reason == DBG_REASON_WATCHPOINT) { enum watchpoint_rw hit_wp_type; target_addr_t hit_wp_address; - if (watchpoint_hit(target, &hit_wp_type, &hit_wp_address) == ERROR_OK) { + if (watchpoint_hit(ct, &hit_wp_type, &hit_wp_address) == ERROR_OK) { switch (hit_wp_type) { case WPT_WRITE: @@ -767,15 +775,9 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio } current_thread[0] = '\0'; - if (target->rtos != NULL) { - struct target *ct; - snprintf(current_thread, sizeof(current_thread), "thread:%016" PRIx64 ";", + if (target->rtos != NULL) + snprintf(current_thread, sizeof(current_thread), "thread:%" PRIx64 ";", target->rtos->current_thread); - target->rtos->current_threadid = target->rtos->current_thread; - target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct); - if (!gdb_connection->ctrl_c) - signal_var = gdb_last_signal(ct); - } sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "T%2.2x%s%s", signal_var, stop_reason, current_thread); @@ -1300,7 +1302,7 @@ static int gdb_get_register_packet(struct connection *connection, if ((target->rtos != NULL) && (ERROR_OK == rtos_get_gdb_reg(connection, reg_num))) return ERROR_OK; - retval = target_get_gdb_reg_list(target, ®_list, ®_list_size, + retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size, REG_CLASS_ALL); if (retval != ERROR_OK) return gdb_error(connection, retval); @@ -1336,37 +1338,49 @@ static int gdb_set_register_packet(struct connection *connection, { struct target *target = get_target_from_connection(connection); char *separator; - uint8_t *bin_buf; int reg_num = strtoul(packet + 1, &separator, 16); struct reg **reg_list; int reg_list_size; int retval; +#ifdef _DEBUG_GDB_IO_ LOG_DEBUG("-"); - - retval = target_get_gdb_reg_list(target, ®_list, ®_list_size, - REG_CLASS_ALL); - if (retval != ERROR_OK) - return gdb_error(connection, retval); - - if (reg_list_size <= reg_num) { - LOG_ERROR("gdb requested a non-existing register"); - return ERROR_SERVER_REMOTE_CLOSED; - } +#endif if (*separator != '=') { LOG_ERROR("GDB 'set register packet', but no '=' following the register number"); return ERROR_SERVER_REMOTE_CLOSED; } + size_t chars = strlen(separator + 1); + uint8_t *bin_buf = malloc(chars / 2); + gdb_target_to_reg(target, separator + 1, chars, bin_buf); - /* convert from GDB-string (target-endian) to hex-string (big-endian) */ - bin_buf = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8)); - int chars = (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2); - - if ((unsigned int)chars != strlen(separator + 1)) { - LOG_ERROR("gdb sent %zu bits for a %d-bit register (%s)", - strlen(separator + 1) * 4, chars * 4, reg_list[reg_num]->name); + if ((target->rtos != NULL) && + (ERROR_OK == rtos_set_reg(connection, reg_num, bin_buf))) { free(bin_buf); + gdb_put_packet(connection, "OK", 2); + return ERROR_OK; + } + + retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size, + REG_CLASS_ALL); + if (retval != ERROR_OK) { + free(bin_buf); + return gdb_error(connection, retval); + } + + if (reg_list_size <= reg_num) { + LOG_ERROR("gdb requested a non-existing register"); + free(bin_buf); + free(reg_list); + return ERROR_SERVER_REMOTE_CLOSED; + } + + if (chars != (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2)) { + LOG_ERROR("gdb sent %d bits for a %d-bit register (%s)", + (int) chars * 4, reg_list[reg_num]->size, reg_list[reg_num]->name); + free(bin_buf); + free(reg_list); return ERROR_SERVER_REMOTE_CLOSED; } @@ -1634,7 +1648,7 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection, char *separator; int retval; - LOG_DEBUG("-"); + LOG_DEBUG("[%s]", target_name(target)); type = strtoul(packet + 1, &separator, 16); @@ -2200,7 +2214,7 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o arch_defined_types = calloc(1, sizeof(char *)); - retval = target_get_gdb_reg_list(target, ®_list, + retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size, REG_CLASS_ALL); if (retval != ERROR_OK) { @@ -2388,7 +2402,7 @@ static int gdb_target_description_supported(struct target *target, int *supporte char const *architecture = target_get_gdb_arch(target); - retval = target_get_gdb_reg_list(target, ®_list, + retval = target_get_gdb_reg_list_noread(target, ®_list, ®_list_size, REG_CLASS_ALL); if (retval != ERROR_OK) { LOG_ERROR("get register list failed"); @@ -2783,13 +2797,11 @@ static bool gdb_handle_vcont_packet(struct connection *connection, const char *p if (parse[0] == 'c') { parse += 1; - packet_size -= 1; /* check if thread-id follows */ if (parse[0] == ':') { int64_t tid; parse += 1; - packet_size -= 1; tid = strtoll(parse, &endp, 16); if (tid == thread_id) { @@ -2879,10 +2891,9 @@ static int gdb_v_packet(struct connection *connection, char const *packet, int packet_size) { struct gdb_connection *gdb_connection = connection->priv; - struct target *target; int result; - target = get_target_from_connection(connection); + struct target *target = get_target_from_connection(connection); if (strncmp(packet, "vCont", 5) == 0) { bool handled; diff --git a/src/target/register.c b/src/target/register.c index 5352d2f21..4ddda6e6b 100644 --- a/src/target/register.c +++ b/src/target/register.c @@ -36,6 +36,29 @@ * may be separate registers associated with debug or trace modules. */ +struct reg *register_get_by_number(struct reg_cache *first, + uint32_t reg_num, bool search_all) +{ + unsigned i; + struct reg_cache *cache = first; + + while (cache) { + for (i = 0; i < cache->num_regs; i++) { + if (cache->reg_list[i].exist == false) + continue; + if (cache->reg_list[i].number == reg_num) + return &(cache->reg_list[i]); + } + + if (search_all) + cache = cache->next; + else + break; + } + + return NULL; +} + struct reg *register_get_by_name(struct reg_cache *first, const char *name, bool search_all) { diff --git a/src/target/register.h b/src/target/register.h index 32c1f39ac..7c53d6e16 100644 --- a/src/target/register.h +++ b/src/target/register.h @@ -159,6 +159,8 @@ struct reg_arch_type { int (*set)(struct reg *reg, uint8_t *buf); }; +struct reg *register_get_by_number(struct reg_cache *first, + uint32_t reg_num, bool search_all); struct reg *register_get_by_name(struct reg_cache *first, const char *name, bool search_all); struct reg_cache **register_get_last_cache_p(struct reg_cache **first); diff --git a/src/target/target.c b/src/target/target.c index e6c434362..51fdff342 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1215,7 +1215,24 @@ int target_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class) { - return target->type->get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); + int result = target->type->get_gdb_reg_list(target, reg_list, + reg_list_size, reg_class); + if (result != ERROR_OK) { + *reg_list = NULL; + *reg_list_size = 0; + } + return result; +} + +int target_get_gdb_reg_list_noread(struct target *target, + struct reg **reg_list[], int *reg_list_size, + enum target_register_class reg_class) +{ + if (target->type->get_gdb_reg_list_noread && + target->type->get_gdb_reg_list_noread(target, reg_list, + reg_list_size, reg_class) == ERROR_OK) + return ERROR_OK; + return target_get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); } bool target_supports_gdb_connection(struct target *target) @@ -1587,8 +1604,9 @@ int target_call_event_callbacks(struct target *target, enum target_event event) target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); } - LOG_DEBUG("target event %i (%s)", event, - Jim_Nvp_value2name_simple(nvp_target_event, event)->name); + LOG_DEBUG("target event %i (%s) for core %s", event, + Jim_Nvp_value2name_simple(nvp_target_event, event)->name, + target_name(target)); target_handle_event(target, event); diff --git a/src/target/target.h b/src/target/target.h index e944838ac..81fd9d23d 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -502,6 +502,16 @@ int target_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class); +/** + * Obtain the registers for GDB, but don't read register values from the + * target. + * + * This routine is a wrapper for target->type->get_gdb_reg_list_noread. + */ +int target_get_gdb_reg_list_noread(struct target *target, + struct reg **reg_list[], int *reg_list_size, + enum target_register_class reg_class); + /** * Check if @a target allows GDB connections. * diff --git a/src/target/target_type.h b/src/target/target_type.h index 95745c9eb..4bdea721e 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -111,6 +111,13 @@ struct target_type { int (*get_gdb_reg_list)(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class); + /** + * Same as get_gdb_reg_list, but doesn't read the register values. + * */ + int (*get_gdb_reg_list_noread)(struct target *target, + struct reg **reg_list[], int *reg_list_size, + enum target_register_class reg_class); + /* target memory access * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit) * count: number of items of From 844c82934ed5f23b62326870f9d7818afce7c4f6 Mon Sep 17 00:00:00 2001 From: Seth LaForge Date: Mon, 19 Aug 2019 10:40:07 -0700 Subject: [PATCH 167/176] src/flash/nand: Fix some operator precedence bugs. Fix two expressions where precedence of operator | vs ?: was clearly confused. Untested - was clearly not expressing the intent of the author by inspection. Found by automated tooling and rtrieu@google.com. Change-Id: I46f190154797f8affc761caf3a15a1a9db53d702 Signed-off-by: Seth LaForge Reviewed-on: http://openocd.zylin.com/5281 Tested-by: jenkins Reviewed-by: Andreas Fritiofson --- src/flash/nand/lpc3180.c | 2 +- src/flash/nand/lpc32xx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flash/nand/lpc3180.c b/src/flash/nand/lpc3180.c index 436580e37..389c18ac4 100644 --- a/src/flash/nand/lpc3180.c +++ b/src/flash/nand/lpc3180.c @@ -237,7 +237,7 @@ static int lpc3180_init(struct nand_device *nand) /* SLC_CFG = 0x (Force nCE assert, DMA ECC enabled, ECC enabled, DMA burst enabled, *DMA read from SLC, WIDTH = bus_width) */ - target_write_u32(target, 0x20020014, 0x3e | (bus_width == 16) ? 1 : 0); + target_write_u32(target, 0x20020014, 0x3e | ((bus_width == 16) ? 1 : 0)); /* SLC_IEN = 3 (INT_RDY_EN = 1) ,(INT_TC_STAT = 1) */ target_write_u32(target, 0x20020020, 0x03); diff --git a/src/flash/nand/lpc32xx.c b/src/flash/nand/lpc32xx.c index 6febe16a1..058d9a50e 100644 --- a/src/flash/nand/lpc32xx.c +++ b/src/flash/nand/lpc32xx.c @@ -332,7 +332,7 @@ static int lpc32xx_init(struct nand_device *nand) WIDTH = bus_width) */ retval = target_write_u32(target, 0x20020014, - 0x3e | (bus_width == 16) ? 1 : 0); + 0x3e | ((bus_width == 16) ? 1 : 0)); if (ERROR_OK != retval) { LOG_ERROR("could not set SLC_CFG"); return ERROR_NAND_OPERATION_FAILED; From 642a9310ca1942e97a6612c2f8cf132d933845de Mon Sep 17 00:00:00 2001 From: Han Hartgers Date: Mon, 17 Jun 2019 20:39:31 +0200 Subject: [PATCH 168/176] target/dsp563xx: dsp563xx restore reg support Added "exist=true" field to the reg_list struct to make access to the dsp563xx registers again possible. Without it defaults to exist=false and all the reg related functions will return nothing. Fixes regression from b5964191f0d2fc3ace607af001df3d57cbfbaf2b Change-Id: I9c256346735b8d66919c4ba83f528a8afca46ff9 Signed-off-by: Han Hartgers Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/5239 Tested-by: jenkins --- src/target/dsp563xx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index ef7a31aa6..6a5c8683e 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -475,6 +475,7 @@ static void dsp563xx_build_reg_cache(struct target *target) reg_list[i].value = calloc(1, 4); reg_list[i].dirty = false; reg_list[i].valid = false; + reg_list[i].exist = true; reg_list[i].type = &dsp563xx_reg_type; reg_list[i].arch_info = &arch_info[i]; } From 5a235226f0db67e85f9c71288dcd015e7081c37b Mon Sep 17 00:00:00 2001 From: Caleb Szalacinski Date: Mon, 19 Aug 2019 17:45:27 -0500 Subject: [PATCH 169/176] flash/nor: flash driver for Synwit SWM050 MCUs SWM050 is a series of MCU product by Foshan Synwit Tech, which is available in TSSOP-8 or SSOP-16 packages. Adds flash driver for the internal 8KiB flash of the MCU. The registers are based on reverse engineering the J-Flash blob provided by the vendor. Also adds a pre-made cfg file. Change-Id: I0b29f0c0d062883542ee743e0750a4c6b6609ebd Signed-off-by: Icenowy Zheng Signed-off-by: Caleb Szalacinski Reviewed-on: http://openocd.zylin.com/4927 Tested-by: jenkins Reviewed-by: Tomas Vanek Reviewed-by: Andreas Fritiofson --- doc/openocd.texi | 17 +++ src/flash/nor/Makefile.am | 1 + src/flash/nor/drivers.c | 2 + src/flash/nor/swm050.c | 211 ++++++++++++++++++++++++++++++++++++++ tcl/target/swm050.cfg | 45 ++++++++ 5 files changed, 276 insertions(+) create mode 100644 src/flash/nor/swm050.c create mode 100644 tcl/target/swm050.cfg diff --git a/doc/openocd.texi b/doc/openocd.texi index 9490f88fb..c5a926ca8 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -7002,6 +7002,23 @@ unlock str9 device. @end deffn +@deffn {Flash Driver} swm050 +@cindex swm050 +All members of the swm050 microcontroller family from Foshan Synwit Tech. + +@example +flash bank $_FLASHNAME swm050 0x0 0x2000 0 0 $_TARGETNAME +@end example + +One swm050-specific command is defined: + +@deffn Command {swm050 mass_erase} bank_id +Erases the entire flash bank. +@end deffn + +@end deffn + + @deffn {Flash Driver} tms470 Most members of the TMS470 microcontroller family from Texas Instruments include internal flash and use ARM7TDMI cores. diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am index 135128ee4..34f91ce1e 100644 --- a/src/flash/nor/Makefile.am +++ b/src/flash/nor/Makefile.am @@ -63,6 +63,7 @@ NOR_DRIVERS = \ %D%/str7x.c \ %D%/str9x.c \ %D%/str9xpec.c \ + %D%/swm050.c \ %D%/tms470.c \ %D%/virtual.c \ %D%/w600.c \ diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c index 955d149b5..551f389de 100644 --- a/src/flash/nor/drivers.c +++ b/src/flash/nor/drivers.c @@ -77,6 +77,7 @@ extern const struct flash_driver stmsmi_flash; extern const struct flash_driver str7x_flash; extern const struct flash_driver str9x_flash; extern const struct flash_driver str9xpec_flash; +extern const struct flash_driver swm050_flash; extern const struct flash_driver tms470_flash; extern const struct flash_driver virtual_flash; extern const struct flash_driver w600_flash; @@ -146,6 +147,7 @@ static const struct flash_driver * const flash_drivers[] = { &str7x_flash, &str9x_flash, &str9xpec_flash, + &swm050_flash, &tms470_flash, &virtual_flash, &xcf_flash, diff --git a/src/flash/nor/swm050.c b/src/flash/nor/swm050.c new file mode 100644 index 000000000..241207d87 --- /dev/null +++ b/src/flash/nor/swm050.c @@ -0,0 +1,211 @@ +/*************************************************************************** + * Copyright (C) 2019 Icenowy Zheng * + * Copyright (C) 2019 Caleb Szalacinski * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "imp.h" +#include + +#define SWM050_DELAY 100 + +#define SWM050_FLASH_PAGE_SIZE 0x200 +#define SWM050_FLASH_PAGES 16 + +#define SWM050_CPU_ID 0xE000ED00 +#define SWM050_CPU_ID_VAL 0x410CC200 + +#define SWM050_FLASH_REG1 0x1F000000 +#define SWM050_FLASH_REG2 0x1F000038 +#define SWM050_FLASH_KEY 0xAAAAAAAA + +#define SWM050_SYSCTL_CFG_0 0x400F0000 +#define SWM050_SYSCTL_DBLF 0x400F0008 + +static int swm050_erase(struct flash_bank *bank, int first, int last) +{ + struct target *target = bank->target; + int retval, curr_page; + uint32_t curr_addr; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + /* Perform erase */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x4); + if (retval != ERROR_OK) + return retval; + + for (curr_page = first; curr_page <= last; curr_page++) { + curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page); + /* Perform write */ + retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY); + if (retval != ERROR_OK) + return retval; + alive_sleep(SWM050_DELAY); + } + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int swm050_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) +{ + struct target *target = bank->target; + int retval; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + retval = ERROR_TARGET_NOT_HALTED; + return retval; + } + + /* Perform write */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x1); + if (retval != ERROR_OK) + return retval; + + retval = target_write_memory(target, bank->base + offset, 4, count/4, buffer); + if (retval != ERROR_OK) + return retval; + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int swm050_probe(struct flash_bank *bank) +{ + return ERROR_OK; +} + +static int swm050_mass_erase(struct flash_bank *bank) +{ + struct target *target = bank->target; + int retval; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + /* Perform mass erase */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x6); + if (retval != ERROR_OK) + return retval; + retval = target_write_u32(target, SWM050_FLASH_REG2, 0x1); + if (retval != ERROR_OK) + return retval; + retval = target_write_u32(target, 0x0, SWM050_FLASH_KEY); + if (retval != ERROR_OK) + return retval; + + alive_sleep(SWM050_DELAY); + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +COMMAND_HANDLER(swm050_handle_mass_erase_command) +{ + if (CMD_ARGC < 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct flash_bank *bank; + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); + if (ERROR_OK != retval) + return retval; + + retval = swm050_mass_erase(bank); + if (retval == ERROR_OK) + command_print(CMD, "swm050 mass erase complete"); + else + command_print(CMD, "swm050 mass erase failed"); + + return retval; +} + +FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command) +{ + if (bank->sectors) { + free(bank->sectors); + bank->sectors = NULL; + } + bank->write_start_alignment = 4; + bank->write_end_alignment = 4; + bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES; + + bank->num_sectors = SWM050_FLASH_PAGES; + bank->sectors = alloc_block_array(0, SWM050_FLASH_PAGE_SIZE, SWM050_FLASH_PAGES); + if (!bank->sectors) + return ERROR_FAIL; + + for (int i = 0; i < bank->num_sectors; i++) + bank->sectors[i].is_protected = 0; + + return ERROR_OK; +} + +static const struct command_registration swm050_exec_command_handlers[] = { + { + .name = "mass_erase", + .handler = swm050_handle_mass_erase_command, + .mode = COMMAND_EXEC, + .usage = "bank_id", + .help = "Erase entire flash device.", + }, + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration swm050_command_handlers[] = { + { + .name = "swm050", + .mode = COMMAND_ANY, + .help = "swm050 flash command group", + .usage = "", + .chain = swm050_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + +struct flash_driver swm050_flash = { + .name = "swm050", + .commands = swm050_command_handlers, + .flash_bank_command = swm050_flash_bank_command, + .erase = swm050_erase, + .write = swm050_write, + .read = default_flash_read, + .probe = swm050_probe, + .auto_probe = swm050_probe, + .erase_check = default_flash_blank_check, + .free_driver_priv = default_flash_free_driver_priv, +}; diff --git a/tcl/target/swm050.cfg b/tcl/target/swm050.cfg new file mode 100644 index 000000000..a819f9c42 --- /dev/null +++ b/tcl/target/swm050.cfg @@ -0,0 +1,45 @@ +# Synwit SWM050 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME swm050 +} +set _CHIPSERIES swm050 + +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x400 +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x410CC200 +} + +swd newdap $_CHIPNAME cpu -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME swm050 0x0 0x2000 0 0 $_TARGETNAME + + +$_TARGETNAME configure -event reset-init { + # Stop the watchdog, just to be safe + mww 0x40019000 0x00 + # Set clock divider value to 1 + mww 0x400F0000 0x01 + # Set system clock to 18Mhz + mww 0x400F0008 0x00 +} + +# SWM050 (Cortex-M0 core) supports SYSRESETREQ +if {![using_hla]} { + # if srst is not fitted use SYSRESETREQ to + # perform a soft reset + cortex_m reset_config sysresetreq +} From 5b06b88af849805480060a2dcc2189a13d23d76d Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 27 Aug 2019 14:18:21 +0200 Subject: [PATCH 170/176] flash/nor/stm32h7x: remove flash size information from device name There is no sense in displaying the max size (2M) as there is variants of this device with reduced flash size Change-Id: I40574064d75fdf2a038044c81038a6d7abc6c4dd Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5288 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Christopher Head Reviewed-by: Tomas Vanek --- src/flash/nor/stm32h7x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 512aca57a..72afc8542 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -141,7 +141,7 @@ static const struct stm32h7x_part_info stm32h7x_parts[] = { .id = 0x450, .revs = stm32_450_revs, .num_revs = ARRAY_SIZE(stm32_450_revs), - .device_str = "STM32H7xx 2M", + .device_str = "STM32H74x/75x", .page_size = 128, /* 128 KB */ .max_flash_size_kb = 2048, .first_bank_size_kb = 1024, From 09eb941cb8d2fbfa5f477e499fb231e956e214db Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 27 Aug 2019 14:44:49 +0200 Subject: [PATCH 171/176] flash/nor/stm32h7x: remove unused 'pages_per_sector' from stm32h7x_part_info Change-Id: I1b79c25cada574e3a9849f506443c836bd707604 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5289 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Christopher Head --- src/flash/nor/stm32h7x.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 72afc8542..fd6bf9a09 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -115,7 +115,6 @@ struct stm32h7x_part_info { const struct stm32h7x_rev *revs; size_t num_revs; unsigned int page_size; - unsigned int pages_per_sector; uint16_t max_flash_size_kb; uint8_t has_dual_bank; uint16_t first_bank_size_kb; /* Used when has_dual_bank is true */ From 101345270bd5b337721e2c907fe470298bc8b5c8 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Mon, 20 May 2019 23:24:26 -0700 Subject: [PATCH 172/176] esirisc_flash: Rename PAGE_SIZE to FLASH_PAGE_SIZE PAGE_SIZE is defined in system includes on some systems, this would avoid the unintended conflict Fixes | src/flash/nor/esirisc_flash.c:95:9: error: 'PAGE_SIZE' macro redefined [-Werror,-Wmacro-redefined] | #define PAGE_SIZE 4096 | ^ | /mnt/a/yoe/build/tmp/work/core2-64-yoe-linux-musl/openocd/0.10+gitrAUTOINC+7ee618692f-r0/recipe-sysroot/usr/inclu de/limits.h:89:9: note: previous definition is here | #define PAGE_SIZE PAGESIZE Change-Id: I195b303fc88a7c848ca4e55fd6ba893796df55cc Signed-off-by: Khem Raj Reviewed-on: http://openocd.zylin.com/5180 Tested-by: jenkins Reviewed-by: Steven Stallion Reviewed-by: Andreas Fritiofson --- src/flash/nor/esirisc_flash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/flash/nor/esirisc_flash.c b/src/flash/nor/esirisc_flash.c index 4e33b9429..3bed06581 100644 --- a/src/flash/nor/esirisc_flash.c +++ b/src/flash/nor/esirisc_flash.c @@ -92,7 +92,7 @@ #endif #define CONTROL_TIMEOUT 5000 /* 5s */ -#define PAGE_SIZE 4096 +#define FLASH_PAGE_SIZE 4096 #define PB_MAX 32 #define NUM_NS_PER_S 1000000000ULL @@ -264,7 +264,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last) (void)esirisc_flash_disable_protect(bank); for (int page = first; page < last; ++page) { - uint32_t address = page * PAGE_SIZE; + uint32_t address = page * FLASH_PAGE_SIZE; target_write_u32(target, esirisc_info->cfg + ADDRESS, address); @@ -464,8 +464,8 @@ static int esirisc_flash_probe(struct flash_bank *bank) if (target->state != TARGET_HALTED) return ERROR_TARGET_NOT_HALTED; - bank->num_sectors = bank->size / PAGE_SIZE; - bank->sectors = alloc_block_array(0, PAGE_SIZE, bank->num_sectors); + bank->num_sectors = bank->size / FLASH_PAGE_SIZE; + bank->sectors = alloc_block_array(0, FLASH_PAGE_SIZE, bank->num_sectors); retval = esirisc_flash_init(bank); if (retval != ERROR_OK) { From 85a460d5a38ba7ce0d6090e1d2af4d45cd0f9592 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Thu, 6 Jun 2019 13:14:29 +0200 Subject: [PATCH 173/176] tcl/board: Add Rigado BMD-300 Evaluation Kit Change-Id: Iba8e12818e2041e51214dab413eb57f0e5bf3f75 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5218 Tested-by: jenkins Reviewed-by: Spencer Oliver --- tcl/board/rigado_bmd300_ek.cfg | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tcl/board/rigado_bmd300_ek.cfg diff --git a/tcl/board/rigado_bmd300_ek.cfg b/tcl/board/rigado_bmd300_ek.cfg new file mode 100644 index 000000000..04e5e1f45 --- /dev/null +++ b/tcl/board/rigado_bmd300_ek.cfg @@ -0,0 +1,11 @@ +# +# Rigado BMD-300 Evaluation Kit +# +# https://www.rigado.com/products/modules/bmd-300/ +# + +source [find interface/jlink.cfg] +transport select swd +adapter_khz 1000 + +source [find target/nrf52.cfg] From 181d594205f91969b0effdbc97e3d689d28e4cb3 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Wed, 11 Sep 2019 11:08:29 +0200 Subject: [PATCH 174/176] flash/nor/tcl: Fix usage of 'flash erase_sector' command Change-Id: I2141e377a0531cab8d1140049a2ee7721d30cfdc Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/5299 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/tcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index b336cffda..bd313a0b5 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -985,7 +985,7 @@ static const struct command_registration flash_exec_command_handlers[] = { .name = "erase_sector", .handler = handle_flash_erase_command, .mode = COMMAND_EXEC, - .usage = "bank_id first_sector_num last_sector_num", + .usage = "bank_id first_sector_num (last_sector_num|'last')", .help = "Erase a range of sectors in a flash bank.", }, { From 31a3324b68827ed7fd6c545d04373b63bd828d6b Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Mon, 9 Sep 2019 13:52:51 -0700 Subject: [PATCH 175/176] helper/command: clear errno before calling parser The C standard says that errno is set to ERANGE if an out-of-range value is returned by strtol, strtoul, et. al., but it does not say that errno is cleared if the function is successful (and, indeed, it is not on glibc). This means that, if errno is ERANGE before strtol is called, and if the value to be converted is exactly the maximum (or, for a signed conversion, the minimum) legal value, COMMAND_PARSE_NUMBER will erroneously indicate that the value is out of range. Change-Id: I8a8b50a815b408a38235968f1c1d70297ea1a6aa Signed-off-by: Christopher Head Reviewed-on: http://openocd.zylin.com/5298 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- src/helper/command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helper/command.c b/src/helper/command.c index 7b93df6e1..d969933e2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1394,6 +1394,7 @@ void process_jim_events(struct command_context *cmd_ctx) return ERROR_COMMAND_ARGUMENT_INVALID; \ } \ char *end; \ + errno = 0; \ *ul = func(str, &end, 0); \ if (*end) { \ LOG_ERROR("Invalid command argument"); \ From 31100927203a4e9d5e4f8e019b1a9e1c9d7b51c6 Mon Sep 17 00:00:00 2001 From: Seth LaForge Date: Thu, 12 Sep 2019 09:18:45 -0700 Subject: [PATCH 176/176] src/jtag/aice: Fix obviously incorrect bit op. Fix expression "(pin_status | 0x4)" which was always true rather than testing a bit. Untested - was clearly not expressing the intent of the author by inspection. Found by automated tooling and rtrieu@google.com. Signed-off-by: Seth LaForge Change-Id: I4bb91e60e8ce9757bf21976cc48de6f85a39c68d Reviewed-on: http://openocd.zylin.com/5301 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- src/jtag/aice/aice_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c index af08ace05..324ec7c32 100644 --- a/src/jtag/aice/aice_usb.c +++ b/src/jtag/aice/aice_usb.c @@ -2812,7 +2812,7 @@ static int aice_issue_reset_hold(uint32_t coreid) /* set no_dbgi_pin to 0 */ uint32_t pin_status; aice_read_ctrl(AICE_READ_CTRL_GET_JTAG_PIN_STATUS, &pin_status); - if (pin_status | 0x4) + if (pin_status & 0x4) aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4)); /* issue restart */