* [U-Boot-Users] [PATCH] Add setexpr command
@ 2008-02-13 22:53 Kumar Gala
2008-02-13 23:07 ` Wolfgang Denk
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Kumar Gala @ 2008-02-13 22:53 UTC (permalink / raw)
To: u-boot
Add a simple expr style command that will set an env variable as the result
of the command. This allows us to do simple math in shell. The following
operations are supported: &, |, ^, +, -, *, /.
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
this was the expr patch, but renamed based on comments on the list.
Still open issue about should this be in config_cmd_default.h
- k
common/cmd_setexpr.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
create mode 100644 common/cmd_setexpr.c
diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c
new file mode 100644
index 0000000..2e49b6d
--- /dev/null
+++ b/common/cmd_setexpr.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * This file provides a shell like 'expr' function to return.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+
+int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ ulong a, b;
+ char buf[16];
+
+ /* Validate arguments */
+ if ((argc != 5) || (strlen(argv[3]) != 1)) {
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ a = simple_strtoul(argv[2], NULL, 16);
+ b = simple_strtoul(argv[4], NULL, 16);
+
+ switch (argv[3][0]) {
+ case '|': sprintf(buf, "%lx", (a | b)); break;
+ case '&': sprintf(buf, "%lx", (a & b)); break;
+ case '+': sprintf(buf, "%lx", (a + b)); break;
+ case '^': sprintf(buf, "%lx", (a ^ b)); break;
+ case '-': sprintf(buf, "%lx", (a - b)); break;
+ case '*': sprintf(buf, "%lx", (a * b)); break;
+ case '/': sprintf(buf, "%lx", (a / b)); break;
+ case '%': sprintf(buf, "%lx", (a % b)); break;
+ default:
+ printf("invalid op\n");
+ return 1;
+ }
+
+ setenv(argv[1], buf);
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ setexpr, 5, 0, do_setexpr,
+ "setexpr - set environment variable as the result of eval expression\n",
+ "name value1 <op> value2\n"
+ " - set environment variable 'name' to the result of the evaluated\n"
+ " express specified by <op>. <op> can be &, |, ^, +, -, *, /, %\n"
+);
--
1.5.3.8
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 22:53 [U-Boot-Users] [PATCH] Add setexpr command Kumar Gala
@ 2008-02-13 23:07 ` Wolfgang Denk
2008-02-13 23:42 ` Kumar Gala
2008-02-14 9:14 ` Matthias Fuchs
2008-03-25 21:14 ` Wolfgang Denk
2 siblings, 1 reply; 11+ messages in thread
From: Wolfgang Denk @ 2008-02-13 23:07 UTC (permalink / raw)
To: u-boot
In message <Pine.LNX.4.64.0802131648030.23661@blarg.am.freescale.net> you wrote:
> Add a simple expr style command that will set an env variable as the result
> of the command. This allows us to do simple math in shell. The following
> operations are supported: &, |, ^, +, -, *, /.
>
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
> ---
>
> this was the expr patch, but renamed based on comments on the list.
<grumble>
Well, *my* command was *not* to rename it.
</grumble>
At least, please don't make it a default command, then.
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
1000 pains = 1 Megahertz
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 23:07 ` Wolfgang Denk
@ 2008-02-13 23:42 ` Kumar Gala
2008-02-14 0:35 ` Wolfgang Denk
2008-02-14 12:41 ` Jerry Van Baren
0 siblings, 2 replies; 11+ messages in thread
From: Kumar Gala @ 2008-02-13 23:42 UTC (permalink / raw)
To: u-boot
On Feb 13, 2008, at 5:07 PM, Wolfgang Denk wrote:
> In message <Pine.LNX.
> 4.64.0802131648030.23661 at blarg.am.freescale.net> you wrote:
>> Add a simple expr style command that will set an env variable as
>> the result
>> of the command. This allows us to do simple math in shell. The
>> following
>> operations are supported: &, |, ^, +, -, *, /.
>>
>> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
>> ---
>>
>> this was the expr patch, but renamed based on comments on the list.
>
> <grumble>
> Well, *my* command was *not* to rename it.
sorry, saw your post after I sent this :)
>
> </grumble>
>
> At least, please don't make it a default command, then.
If you are good with calling it expr so am I. I'd prefer not
confusing 'setenv' with 'setexpr'. If we call it expr add it to the
default list?
- k
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 23:42 ` Kumar Gala
@ 2008-02-14 0:35 ` Wolfgang Denk
2008-02-14 12:41 ` Jerry Van Baren
1 sibling, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2008-02-14 0:35 UTC (permalink / raw)
To: u-boot
In message <ECA572BB-0720-4BD4-9A91-AEBC1056DCA4@kernel.crashing.org> you wrote:
>
> > Well, *my* command was *not* to rename it.
Can't even type any more. I intended to write "comment".
> > At least, please don't make it a default command, then.
>
> If you are good with calling it expr so am I. I'd prefer not
> confusing 'setenv' with 'setexpr'. If we call it expr add it to the
> default list?
Well, given the fact that only very few boards need it but it adds to
the memory footprint I recommend to not add it to the defaults list.
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
"Any excuse will serve a tyrant." - Aesop
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 22:53 [U-Boot-Users] [PATCH] Add setexpr command Kumar Gala
2008-02-13 23:07 ` Wolfgang Denk
@ 2008-02-14 9:14 ` Matthias Fuchs
2008-02-14 14:36 ` Kumar Gala
2008-02-14 19:02 ` Wolfgang Denk
2008-03-25 21:14 ` Wolfgang Denk
2 siblings, 2 replies; 11+ messages in thread
From: Matthias Fuchs @ 2008-02-14 9:14 UTC (permalink / raw)
To: u-boot
Hi Kumar,
nice idea. Can you at a little prose to the README
(perhaps with a little usage example).
Matthias
On Wednesday 13 February 2008 23:53, Kumar Gala wrote:
> Add a simple expr style command that will set an env variable as the result
> of the command. This allows us to do simple math in shell. The following
> operations are supported: &, |, ^, +, -, *, /.
>
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 23:42 ` Kumar Gala
2008-02-14 0:35 ` Wolfgang Denk
@ 2008-02-14 12:41 ` Jerry Van Baren
2008-02-14 14:35 ` Kumar Gala
2008-02-14 19:05 ` Wolfgang Denk
1 sibling, 2 replies; 11+ messages in thread
From: Jerry Van Baren @ 2008-02-14 12:41 UTC (permalink / raw)
To: u-boot
Kumar Gala wrote:
> On Feb 13, 2008, at 5:07 PM, Wolfgang Denk wrote:
>
>> In message <Pine.LNX.
>> 4.64.0802131648030.23661 at blarg.am.freescale.net> you wrote:
>>> Add a simple expr style command that will set an env variable as
>>> the result
>>> of the command. This allows us to do simple math in shell. The
>>> following
>>> operations are supported: &, |, ^, +, -, *, /.
>>>
>>> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
>>> ---
>>>
>>> this was the expr patch, but renamed based on comments on the list.
>> <grumble>
>> Well, *my* command was *not* to rename it.
>
> sorry, saw your post after I sent this :)
>> </grumble>
>>
>> At least, please don't make it a default command, then.
>
> If you are good with calling it expr so am I. I'd prefer not
> confusing 'setenv' with 'setexpr'. If we call it expr add it to the
> default list?
>
> - k
OK, time to educate Jerry since I'm too lazy to check myself. Does our
hush shell support back ticks? If we have back tick support, or can add
that support, we should call it expr and return a value which then gets
placed properly. That would be IDEAL.
setenv foo `expr 2 + 3`
gvb
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-14 12:41 ` Jerry Van Baren
@ 2008-02-14 14:35 ` Kumar Gala
2008-02-14 19:05 ` Wolfgang Denk
1 sibling, 0 replies; 11+ messages in thread
From: Kumar Gala @ 2008-02-14 14:35 UTC (permalink / raw)
To: u-boot
On Feb 14, 2008, at 6:41 AM, Jerry Van Baren wrote:
> Kumar Gala wrote:
>> On Feb 13, 2008, at 5:07 PM, Wolfgang Denk wrote:
>>> In message <Pine.LNX. 4.64.0802131648030.23661@blarg.am.freescale.net
>>> > you wrote:
>>>> Add a simple expr style command that will set an env variable as
>>>> the result
>>>> of the command. This allows us to do simple math in shell. The
>>>> following
>>>> operations are supported: &, |, ^, +, -, *, /.
>>>>
>>>> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
>>>> ---
>>>>
>>>> this was the expr patch, but renamed based on comments on the list.
>>> <grumble>
>>> Well, *my* command was *not* to rename it.
>> sorry, saw your post after I sent this :)
>>> </grumble>
>>>
>>> At least, please don't make it a default command, then.
>> If you are good with calling it expr so am I. I'd prefer not
>> confusing 'setenv' with 'setexpr'. If we call it expr add it to
>> the default list?
>> - k
>
> OK, time to educate Jerry since I'm too lazy to check myself. Does
> our hush shell support back ticks? If we have back tick support, or
> can add that support, we should call it expr and return a value
> which then gets placed properly. That would be IDEAL.
> setenv foo `expr 2 + 3`
no we dont' support back ticks like this.
- k
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-14 9:14 ` Matthias Fuchs
@ 2008-02-14 14:36 ` Kumar Gala
2008-02-14 19:02 ` Wolfgang Denk
1 sibling, 0 replies; 11+ messages in thread
From: Kumar Gala @ 2008-02-14 14:36 UTC (permalink / raw)
To: u-boot
On Feb 14, 2008, at 3:14 AM, Matthias Fuchs wrote:
> Hi Kumar,
>
> nice idea. Can you at a little prose to the README
> (perhaps with a little usage example).
I can do this.
- k
>
> Matthias
>
> On Wednesday 13 February 2008 23:53, Kumar Gala wrote:
>> Add a simple expr style command that will set an env variable as
>> the result
>> of the command. This allows us to do simple math in shell. The
>> following
>> operations are supported: &, |, ^, +, -, *, /.
>>
>> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-14 9:14 ` Matthias Fuchs
2008-02-14 14:36 ` Kumar Gala
@ 2008-02-14 19:02 ` Wolfgang Denk
1 sibling, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2008-02-14 19:02 UTC (permalink / raw)
To: u-boot
In message <200802141014.21407.matthias.fuchs@esd-electronics.com> you wrote:
>
> nice idea. Can you at a little prose to the README
> (perhaps with a little usage example).
Or (and better *and*) to the manual, please?
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
When a child is taught ... its programmed with simple instructions --
and at some point, if its mind develops properly, it exceeds the sum
of what it was taught, thinks independently.
-- Dr. Richard Daystrom, "The Ultimate Computer",
stardate 4731.3.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-14 12:41 ` Jerry Van Baren
2008-02-14 14:35 ` Kumar Gala
@ 2008-02-14 19:05 ` Wolfgang Denk
1 sibling, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2008-02-14 19:05 UTC (permalink / raw)
To: u-boot
In message <47B43701.1070102@ge.com> you wrote:
>
> OK, time to educate Jerry since I'm too lazy to check myself. Does our
> hush shell support back ticks? If we have back tick support, or can add
No, we don't, and it's not trivial to add. [Feel free to prove me
worng :-) ]
> that support, we should call it expr and return a value which then gets
> placed properly. That would be IDEAL.
> setenv foo `expr 2 + 3`
Agreed. BUt that's the very reason not to call it expr, because it
doesn't work this way.
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
You can observe a lot just by watchin'. - Yogi Berra
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot-Users] [PATCH] Add setexpr command
2008-02-13 22:53 [U-Boot-Users] [PATCH] Add setexpr command Kumar Gala
2008-02-13 23:07 ` Wolfgang Denk
2008-02-14 9:14 ` Matthias Fuchs
@ 2008-03-25 21:14 ` Wolfgang Denk
2 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2008-03-25 21:14 UTC (permalink / raw)
To: u-boot
In message <Pine.LNX.4.64.0802131648030.23661@blarg.am.freescale.net> you wrote:
> Add a simple expr style command that will set an env variable as the result
> of the command. This allows us to do simple math in shell. The following
> operations are supported: &, |, ^, +, -, *, /.
>
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
> ---
>
> this was the expr patch, but renamed based on comments on the list.
>
> Still open issue about should this be in config_cmd_default.h
>
> - k
>
> common/cmd_setexpr.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 70 insertions(+), 0 deletions(-)
> create mode 100644 common/cmd_setexpr.c
Applied, thanks.
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
An armed society is a polite society.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-03-25 21:14 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-13 22:53 [U-Boot-Users] [PATCH] Add setexpr command Kumar Gala
2008-02-13 23:07 ` Wolfgang Denk
2008-02-13 23:42 ` Kumar Gala
2008-02-14 0:35 ` Wolfgang Denk
2008-02-14 12:41 ` Jerry Van Baren
2008-02-14 14:35 ` Kumar Gala
2008-02-14 19:05 ` Wolfgang Denk
2008-02-14 9:14 ` Matthias Fuchs
2008-02-14 14:36 ` Kumar Gala
2008-02-14 19:02 ` Wolfgang Denk
2008-03-25 21:14 ` Wolfgang Denk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.