diff options
author | Christoph Muellner <christoph.muellner@theobroma-systems.com> | 2019-04-05 11:54:04 +0200 |
---|---|---|
committer | Christoph Muellner <christoph.muellner@theobroma-systems.com> | 2019-06-24 19:19:11 +0200 |
commit | e53ff3c012518c0b4b08cc1e52528a2f3c59dc9e (patch) | |
tree | a4043b5faff1b0f33756379ee681a7f93007a609 | |
parent | db20755690fa1713c207b6a738883b02fb211ecf (diff) |
common: command: Add command execution tracer.
When using boot scripts it can become quite hard to understand
which commands are actually executed during bootup (e.g. where
is a kernel image loaded from or which DTB is in use).
Shell scripts suffer from a similar problem and many shells address
this problem with a command execution tracer (e.g. BASH has xtrace,
which can be enabled by "set -x").
This patch introduces a command tracer for U-Boot, which prints
every command with its arguments before it is executed.
Signed-off-by: Christoph Muellner <christoph.muellner@theobroma-systems.com>
-rw-r--r-- | cmd/Kconfig | 11 | ||||
-rw-r--r-- | common/command.c | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 11e1d8a79a..b06f387801 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -30,6 +30,17 @@ config SYS_PROMPT This string is displayed in the command line to the left of the cursor. +config SYS_XTRACE + string "Command execution tracer" + depends on CMDLINE + default y if CMDLINE + help + This option enables the possiblity to print all commands before + executing them and after all variables are evaluated (similar + to Bash's xtrace/'set -x' feature). + To enable the tracer a variable "xtrace" needs to be defined in + the environment. + menu "Autoboot options" config AUTOBOOT diff --git a/common/command.c b/common/command.c index e5d9b9cf95..ffe4a03fb2 100644 --- a/common/command.c +++ b/common/command.c @@ -509,6 +509,20 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[], enum command_ret_t rc = CMD_RET_SUCCESS; cmd_tbl_t *cmdtp; +#if defined(CONFIG_SYS_XTRACE) + char *xtrace; + + xtrace = env_get("xtrace"); + if (xtrace) { + puts("+"); + for (int i = 0; i < argc; i++) { + puts(" "); + puts(argv[i]); + } + puts("\n"); + } +#endif + /* Look up command in command table */ cmdtp = find_cmd(argv[0]); if (cmdtp == NULL) { |