summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2013-03-23 23:50:33 +0000
committerTom Rini <trini@ti.com>2013-05-01 16:24:01 -0400
commit103c94b10481cf8479c9d0356e5202bc9200a04f (patch)
tree4114a9c68dd848df4ec62f5512f55b4210f7289c
parentbe29df6a1ac286e6c482828db28ca96e187c7e00 (diff)
downloadu-boot-imx-103c94b10481cf8479c9d0356e5202bc9200a04f.zip
u-boot-imx-103c94b10481cf8479c9d0356e5202bc9200a04f.tar.gz
u-boot-imx-103c94b10481cf8479c9d0356e5202bc9200a04f.tar.bz2
setexpr: simplify code, improve help message
Simplify the argument checking for the "setexpr" command. This is done mainly to make future extensions easier. Also improve the help message for the one argument version of the command - this does not "load an address", but a value, which in this context may be a plain number or a pointer dereference. Signed-off-by: Wolfgang Denk <wd@denx.de>
-rw-r--r--common/cmd_setexpr.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c
index 7a38e94..ccd87f4 100644
--- a/common/cmd_setexpr.c
+++ b/common/cmd_setexpr.c
@@ -56,22 +56,26 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ulong value;
int w;
- /* Validate arguments */
- if (argc != 5 && argc != 3)
- return CMD_RET_USAGE;
- if (argc == 5 && strlen(argv[3]) != 1)
+ if (argc < 3)
return CMD_RET_USAGE;
w = cmd_get_data_size(argv[0], 4);
a = get_arg(argv[2], w);
+ /* plain assignment: "setexpr name value" */
if (argc == 3) {
setenv_hex(argv[1], a);
-
return 0;
}
+ /* standard operators: "setexpr name val1 op val2" */
+ if (argc != 5)
+ return CMD_RET_USAGE;
+
+ if (strlen(argv[3]) != 1)
+ return CMD_RET_USAGE;
+
b = get_arg(argv[4], w);
switch (argv[3][0]) {
@@ -117,6 +121,6 @@ U_BOOT_CMD(
" express specified by <op>. <op> can be &, |, ^, +, -, *, /, %\n"
" size argument is only meaningful if value1 and/or value2 are\n"
" memory addresses (*)\n"
- "setexpr[.b, .w, .l] name *value\n"
- " - load a memory address into a variable"
+ "setexpr[.b, .w, .l] name [*]value\n"
+ " - load a value into a variable"
);