public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area
@ 2008-10-31 22:18 Alessandro Rubini
  2008-10-31 22:40 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Alessandro Rubini @ 2008-10-31 22:18 UTC (permalink / raw)
  To: u-boot


From: Alessandro Rubini <rubini@unipv.it>

This command reads a memory area (up to a specified length) and
assigns the content to an environment variable. Any newlines are turned
into semicolons, and any hash is makes all the rest of the line to be turned
into spaces.

The command is meant to allow downloading a shell script from the network
or a storage device and then run it using the "run" command. This greatly
simplifies the task of upgrading a system from within the boot loader,
or just running some tests automatically, without the need to define the
specific commands at compile time.

Signed-off-by: Alessandro Rubini <rubini@unipv.it>
---
 README              |    2 ++
 common/cmd_nvedit.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/README b/README
index ebee20f..ef989b4 100644
--- a/README
+++ b/README
@@ -594,6 +594,7 @@ The following options need to be configured:
 		CONFIG_CMD_KGDB		* kgdb
 		CONFIG_CMD_LOADB	  loadb
 		CONFIG_CMD_LOADS	  loads
+		CONFIG_CMD_MEMENV	* set environment from memory
 		CONFIG_CMD_MEMORY	  md, mm, nm, mw, cp, cmp, crc, base,
 					  loop, loopw, mtest
 		CONFIG_CMD_MISC		  Misc functions like sleep etc
@@ -2802,6 +2803,7 @@ sspi	- SPI utility commands
 base	- print or set address offset
 printenv- print environment variables
 setenv	- set environment variables
+memenv	- set variable from memory are, stripping newlines
 saveenv - save environment variables to persistent storage
 protect - enable or disable FLASH write protection
 erase	- erase FLASH memory
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index d280cb0..2c4581b 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -488,6 +488,44 @@ int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #endif
 
 /************************************************************************
+ * Prompt for environment variable
+ */
+
+#if defined(CONFIG_CMD_MEMENV)
+int do_memenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	unsigned long len, i;
+	char *addr;
+
+	if (argc != 4) {
+		printf ("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+	addr = (char *)simple_strtol(argv[2], NULL, 16);
+	len = simple_strtol(argv[3], NULL, 16);
+	if (!addr || !len) {
+		printf ("Usage:\n%s\n", cmdtp->usage);
+		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;
+}
+#endif /* CMD_MEMENV */
+
+/************************************************************************
  * Look up variable from environment,
  * return address of storage for that variable,
  * or NULL if not found
@@ -626,6 +664,17 @@ U_BOOT_CMD(
 );
 #endif
 
+#if defined(CONFIG_CMD_MEMENV)
+
+U_BOOT_CMD(
+	memenv, 4, 0, do_memenv,
+	"memenv  - get multi-line environment variable from memory area\n",
+	"name addr maxlen\n"
+	"    - set multi-line environment variable 'name' from addr 'addr'\n"
+);
+
+#endif
+
 #if defined(CONFIG_CMD_RUN)
 int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 U_BOOT_CMD(
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area
  2008-10-31 22:18 [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area Alessandro Rubini
@ 2008-10-31 22:40 ` Wolfgang Denk
  2008-10-31 23:35   ` Alessandro Rubini
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Denk @ 2008-10-31 22:40 UTC (permalink / raw)
  To: u-boot

Dear Alessandro,

In message <20081031221826.GA9555@mail.gnudd.com> you wrote:
> 
> This command reads a memory area (up to a specified length) and
> assigns the content to an environment variable. Any newlines are turned
> into semicolons, and any hash is makes all the rest of the line to be turned
> into spaces.

Doesn't this more or less duplicate the function of the "autoscr"
command?

> The command is meant to allow downloading a shell script from the network
> or a storage device and then run it using the "run" command. This greatly
> simplifies the task of upgrading a system from within the boot loader,
> or just running some tests automatically, without the need to define the
> specific commands at compile time.

Yes, this duplicates "autoscr" (which will be renamed into "source"
soon).

I think we don't need this?

Best regards,

Wolfgang Denk

-- 
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
What the gods would destroy they first submit to  an  IEEE  standards
committee.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area
  2008-10-31 22:40 ` Wolfgang Denk
@ 2008-10-31 23:35   ` Alessandro Rubini
  0 siblings, 0 replies; 3+ messages in thread
From: Alessandro Rubini @ 2008-10-31 23:35 UTC (permalink / raw)
  To: u-boot


> Doesn't this more or less duplicate the function of the "autoscr"
> command?

After checking the source, it addresses the same needs.

While I looked hard, I didn't find this feature. After I wrote it for
a client and later found another client did it by himself, I posted it
to the list on Jul 4th and got only one positive comment, so I finally
went ahead.

I should have looked better, it seems.

Thanks
/alessandro

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-10-31 23:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-31 22:18 [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area Alessandro Rubini
2008-10-31 22:40 ` Wolfgang Denk
2008-10-31 23:35   ` Alessandro Rubini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox