All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maxin B. John" <maxin.john@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>
Subject: [PATCH] doc: cmd: add documentation for binop
Date: Sat, 31 Oct 2026 12:35:59 +0200	[thread overview]
Message-ID: <20261031103603.1807331-1-maxin.john@gmail.com> (raw)

Add documentation for the binop command.

Signed-off-by: Maxin B. John <maxin.john@gmail.com>
---
 doc/usage/cmd/binop.rst | 103 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
 create mode 100644 doc/usage/cmd/binop.rst

diff --git a/doc/usage/cmd/binop.rst b/doc/usage/cmd/binop.rst
new file mode 100644
index 000000000000..e14b799ea7f2
--- /dev/null
+++ b/doc/usage/cmd/binop.rst
@@ -0,0 +1,103 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+.. index::
+   single: binop (command)
+
+binop command
+=============
+
+Synopsis
+--------
+
+::
+
+    binop op count src1 src2 [dest]
+
+Description
+-----------
+
+The binop command applies a bitwise binary operation to two byte arrays of
+count bytes. Bytes are processed independently; no endian or word-size
+conversion is performed. The result is written to dest or, if dest is
+omitted, printed to the console.
+
+op
+    Operation to perform:
+
+    * ``xor`` - set each bit where the operands differ
+    * ``or`` - set each bit that is set in either operand
+    * ``and`` - set each bit that is set in both operands
+
+count
+    Number of bytes to process, specified in decimal. Must be
+    greater than zero.
+
+src1, src2
+    Input operands. Each operand is either:
+
+    - an environment variable name, whose value is parsed as a hex string
+    - a hex string, if no environment variable with that name exists
+    - a memory address prefixed with '*', in which case count bytes are
+      read from that address
+
+    An existing environment variable takes precedence over interpreting
+    the argument as a hex string. Prefixing an argument with ``*``
+    explicitly selects memory access. Hex strings must contain an even
+    number of hexadecimal digits and may not describe more than count
+    bytes. Shorter values are zero-padded at the end.
+
+dest
+    Optional destination. If prefixed with '*', the result is written to
+    that memory address. Otherwise dest is the name of an environment
+    variable which receives the result as a lowercase hex string with two
+    hex digits per byte. If dest is omitted, the result is printed as hex
+    bytes separated by spaces, 16 bytes per line.
+
+Addresses are parsed as hexadecimal numbers. The caller is responsible
+for ensuring that the specified memory is accessible and, for
+destinations, writable.
+
+Invalid counts, operators, addresses or hex strings are rejected and the
+destination is left unchanged.
+
+Examples
+--------
+
+XOR two hex strings and store the result in an environment variable::
+
+    => binop xor 4 01020304 ffffffff binop_out
+    => printenv binop_out
+    binop_out=fefdfcfb
+
+AND two hex strings::
+
+    => binop and 4 0f0f0f0f 00ff00ff binop_out
+    => printenv binop_out
+    binop_out=000f000f
+
+Read an operand from an environment variable. The short value is
+zero-padded::
+
+    => setenv binop_a 0102
+    => binop or 4 binop_a 03 binop_out
+    => printenv binop_out
+    binop_out=03020000
+
+Print the result to the console::
+
+    => binop xor 2 0102 0304
+    02 06
+
+Read from and write to memory (addresses are hexadecimal)::
+
+    => binop xor 4 *0x80000000 01010101 *0x80000010
+
+Configuration
+-------------
+
+The binop command is available if CONFIG_CMD_BINOP=y.
+
+Return value
+------------
+
+The return value $? is 0 on success and 1 on failure.
-- 
2.47.3


             reply	other threads:[~2026-10-31 10:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 10:35 Maxin B. John [this message]
2026-11-01 17:26 ` [PATCH] doc: cmd: add documentation for binop Simon Glass

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=20261031103603.1807331-1-maxin.john@gmail.com \
    --to=maxin.john@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.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 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.