From: Eric Nelson (Boundary Devices) <eric.nelson@boundarydevices.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Add support for setting environment variable from RAM.
Date: Tue, 3 Feb 2009 08:28:11 -0700 [thread overview]
Message-ID: <1233674891-8270-1-git-send-email-eric.nelson@boundarydevices.com> (raw)
In-Reply-To: <>
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).
Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
---
common/cmd_nvedit.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 1fcb4c9..bcb6d9f 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -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(
--
1.5.5.1.382.g182fb
next reply other threads:[~2009-02-03 15:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-03 15:28 Eric Nelson [this message]
2009-02-03 16:00 ` [U-Boot] [PATCH] Add support for setting environment variable from RAM Peter Tyser
2009-02-03 18:56 ` Eric Nelson
2009-02-03 20:16 ` Wolfgang Denk
2009-02-03 21:48 ` Eric Nelson
2009-02-03 22:08 ` Wolfgang Denk
-- strict thread matches above, loose matches on Subject: below --
2009-02-03 3:28 Eric Nelson
2009-02-05 19:30 ` Wolfgang Denk
2009-02-05 21:15 ` Eric Nelson
2009-02-05 21:26 ` Wolfgang Denk
2009-02-05 21:34 ` Eric Nelson
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=1233674891-8270-1-git-send-email-eric.nelson@boundarydevices.com \
--to=eric.nelson@boundarydevices.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