Skip to contentSkip to conversation

Add support for setting environment variable from RAM.

PATCH New Eric Nelson (Boundary Devices) 2 participants 5 messages Feb 3, 2009 – Feb 5, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for setting environment variable from RAM.

This is useful for allowing scripts to read environment variables from file, among other things.

This is a slightly modified version of what Alessandro submitted to the mailing list last July:
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg07932.html

I changed the name from 'setenvram' to 'ramenv' to prevent breakage of scripts that use the abbreviation 'set' (which my handss have the habit of doing).

---
 common/cmd_nvedit.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
common/cmd_nvedit.c +46 -0
index 1fcb4c9..bcb6d9f 100644
@@ -494,6 +494,44 @@ int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #endif
 
 /************************************************************************
+ * Set a new environment variable from RAM.
+ * Requires three arguments: the variable name, a memory address and a length.
+ *
+ * Deletes the environment variable if the length is zero.
+ */
+int do_ramenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	unsigned long len, i;
+	char *addr;
+
+	if (argc != 4) {
+		cmd_usage(cmdtp);
+		return 1;
+	}
+	addr = (char *)simple_strtol(argv[2], NULL, 16);
+	len = simple_strtol(argv[3], NULL, 16);
+	if (!addr || !len) {
+		cmd_usage(cmdtp);
+		return 1;
+	}
+	addr[len] = '\0';
+	for (i = 0; i < len; i++) {
+		/* turn newlines into semicolon */
+		if (addr[i] == '\n')
+			addr[i] = ';'; /* ignore dos-style newlines */
+		if (addr[i] == '\r')
+			addr[i] = ' '; /* accept sh-comments and discard them */
+		if (addr[i] == '#') {
+			while (addr[i] && addr[i] != '\n')
+				addr[i++] = ' ';
+			i--;
+		}
+	}
+	setenv(argv[1], addr);
+	return 0;
+}
+
+/************************************************************************
  * Look up variable from environment,
  * return address of storage for that variable,
  * or NULL if not found
@@ -605,6 +643,14 @@ U_BOOT_CMD(
 	"    - delete environment variable 'name'\n"
 );
 
+U_BOOT_CMD(
+	ramenv, 4, 0, do_ramenv,
+	"ramenv  - get environment variable from ram\n",
+	"name addr maxlen\n"
+	"    - set environment variable 'name' from addr 'addr'\n"
+	"    - delete environment variable if maxlen is 0\n"
+);
+
 #if defined(CONFIG_CMD_ASKENV)
 
 U_BOOT_CMD(
Signature · 1 line
1.5.5.1.382.g182fb
#1 lore raw

PATCH 1/1 Add support for setting environment variable from RAM.

Dear "Eric Nelson (Boundary Devices)",

Quoted 11 lines · In message <1233631739-17568-1-git-send-email-eric.nelson@boundarydevices.com>…

This is useful for allowing scripts to read environment variables from file, among other things.

This is a slightly modified version of what Alessandro submitted to the mailing list last July:
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg07932.html

I changed the name from 'setenvram' to 'ramenv' to prevent breakage of scripts that use the abbreviation 'set' (which my handss have the habit of doing).

We discussed thsi before, and I already NAKed it.

I hereby NAK it again.

This command makes no sense (especially since it will process only a single variable).

Please use a script image with "askenv" instead.

Note: if the code would process a list of variables, say, in internal U-Boot environment format (separated by single NUL, terminated by double NUL characters), that could be a useful building block to implement the "reset to default environment" / "reset factory defaults" command we discussed earlier (see mailing list archive) - and as such, it had much better chances to be considered.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Question: How does one get fresh air into a Russian church?
Answer:   One clicks on an icon, and a window opens!
#2 lore raw

PATCH 1/1 Add support for setting environment variable from RAM.

Quoted 10 lines · Wolfgang Denk

Dear "Eric Nelson (Boundary Devices)",

Quoted 7 lines · In message <1233631739-17568-1-git-send-email-eric.nelson@boundarydevices.com>…

This is useful for allowing scripts to read environment variables from file, among other things.

This is a slightly modified version of what Alessandro submitted to the mailing list last July:
http://www.mail-archive.com/u-boot-users at lists.sourceforge.net/msg07932.html

Quoted 9 lines
Quoted 4 lines

I changed the name from 'setenvram' to 'ramenv' to prevent breakage of scripts that use the abbreviation 'set' (which my handss have the habit of doing).

We discussed thsi before, and I already NAKed it.

I hereby NAK it again.

I'm not sure how this made it back onto the list. Sorry about that.

Quoted 5 lines

This command makes no sense (especially since it will process only a single variable).

Please use a script image with "askenv" instead.

Thanks for the tip. I hadn't noticed askenv previously.

Quoted 11 lines

Note: if the code would process a list of variables, say, in internal U-Boot environment format (separated by single NUL, terminated by double NUL characters), that could be a useful building block to implement the "reset to default environment" / "reset factory defaults" command we discussed earlier (see mailing list archive) - and as such, it had much better chances to be considered.

Best regards,

Wolfgang Denk

#3 lore raw

PATCH 1/1 Add support for setting environment variable from RAM.

Dear Eric Nelson,

Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 3 lines

Please use a script image with "askenv" instead.

Thanks for the tip. I hadn't noticed askenv previously.

Sorry, typo. I meant "autoscr".

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Killing is stupid; useless!
	-- McCoy, "A Private Little War", stardate 4211.8
#4 lore raw

PATCH 1/1 Add support for setting environment variable from RAM.

Quoted 9 lines · Wolfgang Denk

Dear Eric Nelson,

Quoted 3 lines · In message <[email protected]> you wrote:
Quoted 2 lines

Please use a script image with "askenv" instead.

Thanks for the tip. I hadn't noticed askenv previously.

Sorry, typo. I meant "autoscr".

Muscle memory. Can't live with it, can't turn it off...

Still and all, askenv's kinda cool.

Thanks,

Eric