Skip to contentSkip to conversation

itest: Add bitwise and operator

PATCH New Eric Nelson 2 participants 3 messages May 3, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 itest: Add bitwise and operator

---
 common/cmd_itest.c        |    4 ++++
 doc/README.commands.itest |   10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
common/cmd_itest.c +4 -0
index 2c8e5d0..0629b09 100644
@@ -38,6 +38,7 @@
 #define GT	3
 #define LE	4
 #define GE	5
+#define AND	6
 
 struct op_tbl_s {
 	char	*op;		/* operator string */
@@ -60,6 +61,8 @@ static const op_tbl_t op_table [] = {
 	{ ">=" , GE },
 	{ "-le", LE },
 	{ "<=" , LE },
+	{ "-and", AND },
+	{ "&" , AND },
 };
 
 static long evalexp(char *s, int w)
@@ -126,6 +129,7 @@ static int arithcomp (char *s, char *t, int op, int w)
 	case GT: return (l > r);
 	case LE: return (l <= r);
 	case GE: return (l >= r);
+	case AND: return (l & r);
 	}
 	return (0);
 }
doc/README.commands.itest +9 -1
index 5e0fe86..0058155 100644
@@ -2,7 +2,7 @@ A slow day today so here is a revised itest command with provisional
 support for comparing strings as well :-))
 
 Now table driven to allow the operators
--eq, -ne, -lt, -gt, -le, -ge, ==, !=, <>, <, >, <=, >=
+-eq, -ne, -lt, -gt, -le, -ge, -and, ==, !=, <>, <, >, <=, >=, &
 
 Uses the expected command modifier for integer compares of width 1, 2 or
 4 bytes of .b, .w, .l and the new modifer of .s for a string compare.
@@ -14,3 +14,11 @@ if itest.l *40000 == 12345678 then; ....
 if itest.w *40000 != 1234 then; ....
 if itest.b *40000 >= 12 then; ....
 if itest.s *40000 -eq hello then; ....
+
+Note that "&" (-and) operator only operates on integers and
+that the '&' will need to be quoted.
+
+e.g.:
+	if itest.l 0x80 '&' *0x020D8044 then; ...
+or
+	if itest.l 0x80 -and *0x020D8044 then; ...
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 itest: Add bitwise and operator

Dear Eric Nelson,

Quoted 11 lines · In message <1367606863-14846-1-git-send-email-eric.nelson@boundarydevices.com>…
---
 common/cmd_itest.c        |    4 ++++
 doc/README.commands.itest |   10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
common/cmd_itest.c +0 -0
index 2c8e5d0..0629b09 100644

common/cmd_itest.c line 41

Quoted 4 lines
common/cmd_itest.c +1 -0
@@ -38,6 +38,7 @@
 #define GT	3
 #define LE	4
 #define GE	5
+#define AND	6

It does not make much sense to me to add AND, when you not also add OR (and eventually XOR).

Also, now the help message is no longer correct - it says:

189 U_BOOT_CMD(

190         itest, 4, 0, do_itest,
191         "return true/false on integer compare",
192         "[.b, .w, .l, .s] [*]value1 <op> [*]value2"

193 );

but we no longer compare...

Hm, re-reading this I think this is the wrong approach. This stuff does not belong into the "itest" command which really is for comparing, and NOT for operations on the arguments.

If you need operations, then please use "setexpr" - which already has all of this, and more.

Best regards,

Wolfgang Denk

Signature · 7 lines
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
"Pardon me for breathing, which I never do anyway so I don't know why
I bother to say it, oh God, I'm so depressed. Here's another of those
self-satisfied doors. Life! Don't talk to me about life."
                                        - Marvin the Paranoid Android
#2 lore raw

PATCH 1/1 itest: Add bitwise and operator

Hi Wolfgang,

Quoted 9 lines · Wolfgang Denk

Dear Eric Nelson,

Quoted 6 lines · In message <1367606863-14846-1-git-send-email-eric.nelson@boundarydevices.com>…
---
  common/cmd_itest.c        |    4 ++++
  doc/README.commands.itest |   10 +++++++++-
  2 files changed, 13 insertions(+), 1 deletion(-)
Quoted 13 lines

common/cmd_itest.c line 41

Quoted 9 lines
common/cmd_itest.c +1 -0
index 2c8e5d0..0629b09 100644
@@ -38,6 +38,7 @@
  #define GT	3
  #define LE	4
  #define GE	5
+#define AND	6

It does not make much sense to me to add AND, when you not also add OR (and eventually XOR).

I only needed to test a bit.

Quoted 8 lines

Also, now the help message is no longer correct - it says:

189 U_BOOT_CMD(

190         itest, 4, 0, do_itest,
191         "return true/false on integer compare",
192         "[.b, .w, .l, .s] [*]value1 <op> [*]value2"

193 );

Quoted 9 lines

but we no longer compare...

Hm, re-reading this I think this is the wrong approach. This stuff does not belong into the "itest" command which really is for comparing, and NOT for operations on the arguments.

If you need operations, then please use "setexpr" - which already has all of this, and more.

As always, thanks for the guidance.

I hadn't noticed that setexpr supported indirection.

In case this helps someone else, I was looking for a way to detect Android "recovery" mode, which is flagged by bit seven in the SRC_GPR10 register (address 0x020d8044).

And setexpr can be used like so:

	U-Boot > md.l 0x020d8044
	020d8044: 00000080                               ....
	U-Boot > setexpr rval *0x020D8044 \& 0x80
	U-Boot > print rval
	rval=80
	U-Boot > setexpr rval *0x020D8044 \& 0x40
	U-Boot > print rval
	rval=0

Regards,

Eric