From: Alessandro Rubini <rubini-list@gnudd.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area
Date: Fri, 31 Oct 2008 23:18:26 +0100 [thread overview]
Message-ID: <20081031221826.GA9555@mail.gnudd.com> (raw)
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
next reply other threads:[~2008-10-31 22:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-31 22:18 Alessandro Rubini [this message]
2008-10-31 22:40 ` [U-Boot] [PATCH] Add "memenv" command, to set environment from a memory area Wolfgang Denk
2008-10-31 23:35 ` Alessandro Rubini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081031221826.GA9555@mail.gnudd.com \
--to=rubini-list@gnudd.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox