Commit 4823b45da2b5d434b1009f8b511a8fc846c7a252
Committed by
Tom Rini
1 parent
2400727318
Exists in
master
and in
54 other branches
Add a simple load option to setexpr
Make setexpr accept a 2 parameter variant that will simply load a value into a variable. This is useful for loading a value from memory. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Showing 1 changed file with 16 additions and 3 deletions Side-by-side Diff
common/cmd_setexpr.c
... | ... | @@ -57,12 +57,22 @@ |
57 | 57 | int w; |
58 | 58 | |
59 | 59 | /* Validate arguments */ |
60 | - if ((argc != 5) || (strlen(argv[3]) != 1)) | |
60 | + if (argc != 5 && argc != 3) | |
61 | 61 | return CMD_RET_USAGE; |
62 | + if (argc == 5 && strlen(argv[3]) != 1) | |
63 | + return CMD_RET_USAGE; | |
62 | 64 | |
63 | 65 | w = cmd_get_data_size(argv[0], 4); |
64 | 66 | |
65 | 67 | a = get_arg(argv[2], w); |
68 | + | |
69 | + if (argc == 3) { | |
70 | + sprintf(buf, "%lx", a); | |
71 | + setenv(argv[1], buf); | |
72 | + | |
73 | + return 0; | |
74 | + } | |
75 | + | |
66 | 76 | b = get_arg(argv[4], w); |
67 | 77 | |
68 | 78 | switch (argv[3][0]) { |
69 | 79 | |
... | ... | @@ -87,9 +97,12 @@ |
87 | 97 | U_BOOT_CMD( |
88 | 98 | setexpr, 5, 0, do_setexpr, |
89 | 99 | "set environment variable as the result of eval expression", |
90 | - "[.b, .w, .l] name value1 <op> value2\n" | |
100 | + "[.b, .w, .l] name [*]value1 <op> [*]value2\n" | |
91 | 101 | " - set environment variable 'name' to the result of the evaluated\n" |
92 | 102 | " express specified by <op>. <op> can be &, |, ^, +, -, *, /, %\n" |
93 | - " size argument is only meaningful if value1 and/or value2 are memory addresses" | |
103 | + " size argument is only meaningful if value1 and/or value2 are\n" | |
104 | + " memory addresses (*)\n" | |
105 | + "setexpr[.b, .w, .l] name *value\n" | |
106 | + " - load a memory address into a variable" | |
94 | 107 | ); |