In its current form, this cannot be done with the u-boot echo
and shell right now. This is because replacing the macro that you see with echo
is done by the u-boot command line interpreter before running the echo
command. The entire echo command basically prints an array of strings passed to it.
In particular, if you look at common/cli_simple.c
from the current (7/29/15) git u-boot repository, you will find the cli_simple_run_command
function. This function is passed the cmd
string, which may contain several commands separated by ;
. If you look inside the loop by dividing this line, you will find cli_simple_process_macros
, after which you will find the call cli_simple_parse_line
followed by cmd_process
. Skipping cli_simple_process_macros
at the moment, cli_simple_parse_line
basically takes a string and breaks it into an array of strings, similar to how the shell was set, giving you argv
and argc
, which it passes to cmd_process
, which executes the command that is in argv[0]
.
The interesting part is cli_simple_process_macros
. This takes the input string as the first argument and the output string as the second. This function is a simple state machine that looks for u-boot environment variables (or macros, as the name of the function suggests) and replaces them with the value of the environment variable. This is visible with a call to getenv
and then a copy to the output line. If you look at how cli_simple_process_macros
works, you will notice that it skips only one, that is, if the environment variable contains another environment variable, it does not process the second environment variable, but simply copies the string value.
Finally, if you look at the source for the echo
command, you will see that it is very simple by simply going through argv
and printing each line with the corresponding spaces.
Basically, if you want the desired behavior, you need to either change cli_simple_process_macros
to an iterative environment variable, or change echo
to view the environment variables. You can also modify cli_simple_run_command
to call cli_simple_process_macros
several times so that all nested environment variables are expanded.
source share