Skip to contentSkip to conversation

pxe: Allow use of environment variables in append

PATCH New Hans de Goede 2 participants 5 messages Aug 6, 2014 – Aug 23, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover pxe: Allow use of environment variables in append

Hi,

Here is v2 of my patch-set to expand $() / ${} in extlinux.conf append strings.

Changes in v2:
-Add "cli: Export cli_simple_process_macros for use outside" patch -Use cli_simple_process_macros instead of run_cmd("setenv bootargs ..."), so
that only $() / ${} get processed and not ;

Regards,

Hans

#1 lore raw

PATCH v2 1/2 cli: Export cli_simple_process_macros for use outside of cli_simple

---
 common/cli_simple.c | 4 ++--
 include/cli.h       | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
common/cli_simple.c +2 -2
index 353ceeb..6c65cc6 100644
@@ -57,7 +57,7 @@ int cli_simple_parse_line(char *line, char *argv[])
 	return nargs;
 }
 
-static void process_macros(const char *input, char *output)
+void cli_simple_process_macros(const char *input, char *output)
 {
 	char c, prev;
 	const char *varname_start = NULL;
@@ -236,7 +236,7 @@ int cli_simple_run_command(const char *cmd, int flag)
 		debug_parser("token: \"%s\"\n", token);
 
 		/* find macros in this token and replace them */
-		process_macros(token, finaltoken);
+		cli_simple_process_macros(token, finaltoken);
 
 		/* Extract arguments */
 		argc = cli_simple_parse_line(finaltoken, argv);
include/cli.h +8 -0
index 6994262..6da7a4a 100644
@@ -31,6 +31,14 @@ void cli_simple_loop(void);
 int cli_simple_run_command(const char *cmd, int flag);
 
 /**
+ * cli_simple_process_macros() - Expand $() and ${} format env. variables
+ *
+ * @param input		Input string possible containing $() / ${} vars
+ * @param output	Output string with $() / ${} vars expanded
+ */
+void cli_simple_process_macros(const char *input, char *output);
+
+/**
  * cli_simple_run_command_list() - Execute a list of command
  *
  * The commands should be separated by ; or \n and will be executed
Signature · 1 line
2.0.4
#2 lore raw

PATCH v2 1/2 cli: Export cli_simple_process_macros for use outside of cli_simple

Quoted 1 line · Hans de Goede

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140823/54860475/attachment.pgp>
#3 lore raw

PATCH v2 2/2 pxe: Allow use of environment variables in append string

In reply to Hans de Goede

Use cli_simple_process_macros, so that environment variables (e.g. ${console}) can be used in append strings.

--
Changes in v2:
-Use cli_simple_process_macros instead of run_cmd("setenv bootargs ..."), so
that only $() / ${} get processed and not ;

---
 common/cmd_pxe.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
common/cmd_pxe.c +13 -16
index ba48692..bd7aa65 100644
@@ -14,6 +14,7 @@
 #include <fs.h>
 
 #include "menu.h"
+#include "cli.h"
 
 #define MAX_TFTP_PATH_LEN 127
 
@@ -577,8 +578,12 @@ static int label_localboot(struct pxe_label *label)
 	if (!localcmd)
 		return -ENOENT;
 
-	if (label->append)
-		setenv("bootargs", label->append);
+	if (label->append) {
+		char bootargs[CONFIG_SYS_CBSIZE];
+
+		cli_simple_process_macros(label->append, bootargs);
+		setenv("bootargs", bootargs);
+	}
 
 	debug("running: %s\n", localcmd);
 
@@ -606,7 +611,6 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 	char initrd_str[22];
 	char mac_str[29] = "";
 	char ip_str[68] = "";
-	char *bootargs;
 	int bootm_argc = 3;
 	int len = 0;
 
@@ -651,7 +655,6 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 		sprintf(ip_str, " ip=%s:%s:%s:%s",
 			getenv("ipaddr"), getenv("serverip"),
 			getenv("gatewayip"), getenv("netmask"));
-		len += strlen(ip_str);
 	}
 
 #ifdef CONFIG_CMD_NET
@@ -661,27 +664,21 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
 		err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
 		if (err < 0)
 			mac_str[0] = '\0';
-		len += strlen(mac_str);
 	}
 #endif
 
-	if (label->append)
-		len += strlen(label->append);
+	if ((label->ipappend & 0x3) || label->append) {
+		char bootargs[CONFIG_SYS_CBSIZE] = "";
+		char finalbootargs[CONFIG_SYS_CBSIZE];
 
-	if (len) {
-		bootargs = malloc(len + 1);
-		if (!bootargs)
-			return 1;
-		bootargs[0] = '\0';
 		if (label->append)
 			strcpy(bootargs, label->append);
 		strcat(bootargs, ip_str);
 		strcat(bootargs, mac_str);
 
-		setenv("bootargs", bootargs);
-		printf("append: %s\n", bootargs);
-
-		free(bootargs);
+		cli_simple_process_macros(bootargs, finalbootargs);
+		setenv("bootargs", finalbootargs);
+		printf("append: %s\n", finalbootargs);
 	}
 
 	bootm_argv[1] = getenv("kernel_addr_r");
Signature · 1 line
2.0.4
#4 lore raw

PATCH v2 2/2 pxe: Allow use of environment variables in append string

Quoted 4 lines · Hans de Goede

Use cli_simple_process_macros, so that environment variables (e.g. ${console}) can be used in append strings.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140823/9b13a77c/attachment.pgp>