common: cli_simple: Recursively parse variables

Message ID 1449249451-8945-1-git-send-email-nm@ti.com
State New
Headers show

Commit Message

Nishanth Menon Dec. 4, 2015, 5:17 p.m.
When we use the following in bootargs:
v1=abc
v2=123-${v1}
echo $v2
we get 123-${v1}
This is because we do not recursively check to see if v2 by itself has
a hidden variable. Fix the same with recursive call

Signed-off-by: Nishanth Menon <nm@ti.com>

---

Testing with sandbox: http://pastebin.ubuntu.com/13672432/

 common/cli_simple.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

-- 
2.6.2.402.g2635c2b

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Patch

diff --git a/common/cli_simple.c b/common/cli_simple.c
index 9c3d073d583b..63bda32c57e4 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -134,11 +134,17 @@  void cli_simple_process_macros(const char *input, char *output)
 				envval = getenv(envname);
 
 				/* Copy into the line if it exists */
-				if (envval != NULL)
-					while ((*envval) && outputcnt) {
-						*(output++) = *(envval++);
+				if (envval != NULL) {
+					char finalval[CONFIG_SYS_CBSIZE], *f;
+
+					cli_simple_process_macros(envval,
+								  finalval);
+					f = finalval;
+					while ((*f) && outputcnt) {
+						*(output++) = *(f++);
 						outputcnt--;
 					}
+				}
 				/* Look for another '$' */
 				state = 0;
 			}