From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] commands: setenv: allow use with hush shell
Date: Tue, 15 Sep 2020 14:08:31 +0200 [thread overview]
Message-ID: <20200915120831.20549-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200915120831.20549-1-a.fatoum@pengutronix.de>
setenv was so far restricted to the simple shell, because with hush,
users could just do dev.var=VAL for setting variables in the
environment. The hush syntax doesn't allow for setting all kinds of
environment variables though, e.g.
5c00a000.tamp@5c00a000:reboot-mode.of.param
can't be set with hush, because of the special characters. It could
still be read by using the ${variable} syntax though.
Allow setting these variables by making the setenv command generally
available. The default is chosen to be 'y', because the command is
deemed small and useful enough to have it there by default.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 13 +++++++++++++
commands/Makefile | 2 +-
commands/setenv.c | 2 ++
common/Kconfig | 1 +
common/complete.c | 6 ++++++
include/complete.h | 1 +
6 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index 608643fceb38..9114d3cb31a5 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -726,6 +726,19 @@ config CMD_SAVEENV
/dev/env0. Note that envfs can only handle files, directories are being
skipped silently.
+config CMD_SETENV
+ tristate
+ default y
+ depends on !CONFIG_SHELL_NONE
+ prompt "setenv"
+ help
+ Set environment variable
+
+ Usage: setenv NAME [VALUE]
+
+ Set environment variable NAME to VALUE.
+ If VALUE is ommitted, then the variable is deleted.
+
# end Environment commands
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 01082de44c9b..6cc4997cc546 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -41,7 +41,7 @@ obj-$(CONFIG_CMD_FLASH) += flash.o
obj-$(CONFIG_CMD_MEMINFO) += meminfo.o
obj-$(CONFIG_CMD_TIMEOUT) += timeout.o
obj-$(CONFIG_CMD_READLINE) += readline.o
-obj-$(CONFIG_SHELL_SIMPLE) += setenv.o
+obj-$(CONFIG_CMD_SETENV) += setenv.o
obj-$(CONFIG_CMD_EXPORT) += export.o
obj-$(CONFIG_CMD_PRINTENV) += printenv.o
obj-$(CONFIG_CMD_SAVEENV) += saveenv.o
diff --git a/commands/setenv.c b/commands/setenv.c
index a70a0de4cebc..ad2677065552 100644
--- a/commands/setenv.c
+++ b/commands/setenv.c
@@ -5,6 +5,7 @@
#include <command.h>
#include <errno.h>
#include <environment.h>
+#include <complete.h>
static int do_setenv(int argc, char *argv[])
{
@@ -34,5 +35,6 @@ BAREBOX_CMD_START(setenv)
BAREBOX_CMD_DESC("set environment variable")
BAREBOX_CMD_OPTS("NAME [VALUE]")
BAREBOX_CMD_GROUP(CMD_GRP_ENV)
+ BAREBOX_CMD_COMPLETE(env_param_noeval_complete)
BAREBOX_CMD_HELP(cmd_setenv_help)
BAREBOX_CMD_END
diff --git a/common/Kconfig b/common/Kconfig
index a2861bc2314c..d066261f8d83 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -411,6 +411,7 @@ choice
select COMMAND_SUPPORT
select PARAMETER
select STDDEV
+ select CMD_SETENV
help
simple shell. No if/then, no return values from commands, no loops
diff --git a/common/complete.c b/common/complete.c
index 919e5abc6a62..36e10405c850 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -336,6 +336,12 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
return 0;
}
+int env_param_noeval_complete(struct string_list *sl, char *instr)
+{
+ return env_param_complete(sl, instr, 0);
+}
+EXPORT_SYMBOL(env_param_noeval_complete);
+
static int tab_pressed = 0;
void complete_reset(void)
diff --git a/include/complete.h b/include/complete.h
index 763d256bf460..75a92fc86aa0 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -22,5 +22,6 @@ int devicetree_alias_complete(struct string_list *sl, char *instr);
int devicetree_nodepath_complete(struct string_list *sl, char *instr);
int devicetree_complete(struct string_list *sl, char *instr);
int devicetree_file_complete(struct string_list *sl, char *instr);
+int env_param_noeval_complete(struct string_list *sl, char *instr);
#endif /* __COMPLETE_ */
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-09-15 12:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 12:08 [PATCH 1/2] commands: setenv: support setenv dev.var=VAL syntax Ahmad Fatoum
2020-09-15 12:08 ` Ahmad Fatoum [this message]
2020-09-18 9:01 ` Sascha Hauer
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=20200915120831.20549-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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