mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Aleksander Morgado <aleksander@aleksander.es>
To: barebox@lists.infradead.org, s.hauer@pengutronix.de
Cc: Aleksander Morgado <aleksander@aleksander.es>
Subject: [PATCH v3 8/9] ratp: new reset command
Date: Sat, 24 Feb 2018 16:01:20 +0100	[thread overview]
Message-ID: <20180224150121.28309-9-aleksander@aleksander.es> (raw)
In-Reply-To: <20180224150121.28309-1-aleksander@aleksander.es>

E.g.:
    $ ./bbremote -v --port /dev/ttyUSB2 reset

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
 common/ratp/Makefile         |  1 +
 common/ratp/reset.c          | 55 ++++++++++++++++++++++++++++++++++++++++++++
 include/ratp_bb.h            |  1 +
 scripts/remote/controller.py |  9 +++++---
 scripts/remote/main.py       | 13 +++++++++++
 scripts/remote/messages.py   | 16 +++++++++++++
 6 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 common/ratp/reset.c

diff --git a/common/ratp/Makefile b/common/ratp/Makefile
index d4cfdf95f..2c6d674f6 100644
--- a/common/ratp/Makefile
+++ b/common/ratp/Makefile
@@ -3,3 +3,4 @@ obj-y += ping.o
 obj-y += getenv.o
 obj-y += md.o
 obj-y += mw.o
+obj-y += reset.o
diff --git a/common/ratp/reset.c b/common/ratp/reset.c
new file mode 100644
index 000000000..ca8be4e62
--- /dev/null
+++ b/common/ratp/reset.c
@@ -0,0 +1,55 @@
+/*
+ * reset.c - reset the cpu
+ *
+ * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <ratp_bb.h>
+#include <complete.h>
+#include <getopt.h>
+#include <restart.h>
+
+struct ratp_bb_reset {
+	struct ratp_bb header;
+	uint8_t        force;
+} __attribute__((packed));
+
+static int ratp_cmd_reset(const struct ratp_bb *req, int req_len,
+			  struct ratp_bb **rsp, int *rsp_len)
+{
+	struct ratp_bb_reset *reset_req = (struct ratp_bb_reset *)req;
+
+	if (req_len < sizeof (*reset_req)) {
+		printf ("ratp reset ignored: size mismatch (%d < %zu)\n", req_len, sizeof (*reset_req));
+		return 2;
+	}
+
+	debug("running reset %s\n", reset_req->force ? "(forced)" : "");
+
+	if (!reset_req->force)
+		shutdown_barebox();
+
+	restart_machine();
+	/* Not reached */
+	return 1;
+}
+
+BAREBOX_RATP_CMD_START(RESET)
+	.request_id = BB_RATP_TYPE_RESET,
+	.cmd = ratp_cmd_reset
+BAREBOX_RATP_CMD_END
diff --git a/include/ratp_bb.h b/include/ratp_bb.h
index 00b165f77..3a80cf6ae 100644
--- a/include/ratp_bb.h
+++ b/include/ratp_bb.h
@@ -16,6 +16,7 @@
 #define BB_RATP_TYPE_MD_RETURN		11
 #define BB_RATP_TYPE_MW			12
 #define BB_RATP_TYPE_MW_RETURN		13
+#define BB_RATP_TYPE_RESET		14
 
 struct ratp_bb {
 	uint16_t type;
diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
index eaab9f8f6..2ed834613 100644
--- a/scripts/remote/controller.py
+++ b/scripts/remote/controller.py
@@ -46,9 +46,6 @@ def unpack(data):
     elif p_type == BBType.fs_return:
         logging.debug("received: fs_return")
         return BBPacketFSReturn(raw=data)
-    elif p_type == BBType.md:
-        logging.debug("received: md")
-        return BBPacketMd(raw=data)
     elif p_type == BBType.md_return:
         logging.debug("received: md_return")
         return BBPacketMdReturn(raw=data)
@@ -58,6 +55,9 @@ def unpack(data):
     elif p_type == BBType.mw_return:
         logging.debug("received: mw_return")
         return BBPacketMwReturn(raw=data)
+    elif p_type == BBType.reset:
+        logging.debug("received: reset")
+        return BBPacketReset(raw=data)
     else:
         logging.debug("received: UNKNOWN")
         return BBPacket(raw=data)
@@ -136,6 +136,9 @@ class Controller(Thread):
         logging.info("Mw return: %r", r)
         return (r.exit_code,r.written)
 
+    def reset(self, force):
+        self._send(BBPacketReset(force=force))
+
     def close(self):
         self.conn.close()
 
diff --git a/scripts/remote/main.py b/scripts/remote/main.py
index 29f601e9f..38d280bfe 100644
--- a/scripts/remote/main.py
+++ b/scripts/remote/main.py
@@ -98,6 +98,13 @@ def handle_mw(args):
     return res
 
 
+def handle_reset(args):
+    ctrl = get_controller(args)
+    ctrl.reset(args.force)
+    ctrl.close()
+    return 0
+
+
 def handle_listen(args):
     port = serial.serial_for_url(args.port, args.baudrate)
     conn = SerialRatpConnection(port)
@@ -181,6 +188,12 @@ parser_mw.add_argument('address', type=auto_int, help="address")
 parser_mw.add_argument('data', help="data")
 parser_mw.set_defaults(func=handle_mw)
 
+parser_reset = subparsers.add_parser('reset', help="run reset command")
+parser_reset_force = parser_reset.add_mutually_exclusive_group(required=False)
+parser_reset_force.add_argument('--force', dest='force', action='store_true')
+parser_reset_force.add_argument('--no-force', dest='force', action='store_false')
+parser_reset.set_defaults(func=handle_reset,force=False)
+
 parser_listen = subparsers.add_parser('listen', help="listen for an incoming connection")
 parser_listen.set_defaults(func=handle_listen)
 
diff --git a/scripts/remote/messages.py b/scripts/remote/messages.py
index 4f4d8e97f..729f2e617 100644
--- a/scripts/remote/messages.py
+++ b/scripts/remote/messages.py
@@ -21,6 +21,7 @@ class BBType(object):
     md_return = 11
     mw = 12
     mw_return = 13
+    reset = 14
 
 
 class BBPacket(object):
@@ -241,3 +242,18 @@ class BBPacketMwReturn(BBPacket):
     def _pack_payload(self):
         # header size is always 4 bytes (HH) and we have 8 bytes of fixed data (HLH), so buffer offset is 14
         return struct.pack("!HLH", 12, self.exit_code, self.written)
+
+
+class BBPacketReset(BBPacket):
+    def __init__(self, raw=None, force=None):
+        self.force = force
+        super(BBPacketReset, self).__init__(BBType.reset, raw=raw)
+
+    def __repr__(self):
+        return "BBPacketReset(force=%c)" % (self.force)
+
+    def _unpack_payload(self, payload):
+        self.force = struct.unpack("?", payload[:1])
+
+    def _pack_payload(self):
+        return struct.pack("?", self.force)
-- 
2.15.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2018-02-24 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-24 15:01 [PATCH v3 0/9] ratp: new generic RATP command support Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 1/9] ratp: implement generic " Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 2/9] ratp: moved logic to its own subdirectory Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 3/9] ratp: allow building without full console support Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 4/9] ratp: implement ping as a standard ratp command Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 5/9] ratp: implement getenv " Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 6/9] ratp: use xstrndup() instead of a custom xmemdup_add_zero() Aleksander Morgado
2018-02-24 15:01 ` [PATCH v3 7/9] ratp: new md and mw commands Aleksander Morgado
2018-02-24 15:01 ` Aleksander Morgado [this message]
2018-02-24 15:01 ` [PATCH v3 9/9] docs: add reference to libratp-barebox in the remote-control docs Aleksander Morgado
2018-03-01  8:48 ` [PATCH v3 0/9] ratp: new generic RATP command support Sascha Hauer

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=20180224150121.28309-9-aleksander@aleksander.es \
    --to=aleksander@aleksander.es \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox