X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=contrib%2Frpc_examples%2Focd_rpc_example.py;h=53e3e2afcfd86a5a500f9cdecf4c2f9365b4bc47;hb=abe5f015c501942c0c71741f95c49994e386df61;hp=196ea05f929a4c609364024828309c751bc5cc39;hpb=c8184bac20e328704067efb3ab63a96c9b541b89;p=fw%2Fopenocd diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 196ea05f9..53e3e2afc 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-or-later + """ OpenOCD RPC example, covered by GNU GPLv3 or later Copyright (C) 2014 Andreas Ortmann (ortmann@finf.uni-hannover.de) @@ -49,10 +51,16 @@ class OpenOcd: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def __enter__(self): - self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + self.connect() return self def __exit__(self, type, value, traceback): + self.disconnect() + + def connect(self): + self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + + def disconnect(self): try: self.send("exit") finally: @@ -89,24 +97,16 @@ class OpenOcd: return None if (len(raw) < 2) else strToHex(raw[1]) def readMemory(self, wordLen, address, n): - self.send("array unset output") # better to clear the array before - self.send("mem2array output %d 0x%x %d" % (wordLen, address, n)) - - output = [*map(int, self.send("echo $output").split(" "))] - d = dict([tuple(output[i:i + 2]) for i in range(0, len(output), 2)]) - - return [d[k] for k in sorted(d.keys())] + output = self.send("read_memory 0x%x %d %d" % (address, wordLen, n)) + return [*map(lambda x: int(x, 16), output.split(" "))] def writeVariable(self, address, value): assert value is not None self.send("mww 0x%x 0x%x" % (address, value)) - def writeMemory(self, wordLen, address, n, data): - array = " ".join(["%d 0x%x" % (a, b) for a, b in enumerate(data)]) - - self.send("array unset 1986ве1т") # better to clear the array before - self.send("array set 1986ве1т { %s }" % array) - self.send("array2mem 1986ве1т 0x%x %s %d" % (wordLen, address, n)) + def writeMemory(self, wordLen, address, data): + data = "{" + ' '.join(['0x%x' % x for x in data]) + "}" + self.send("write_memory 0x%x %d %s" % (address, wordLen, data)) if __name__ == "__main__": @@ -116,10 +116,10 @@ if __name__ == "__main__": with OpenOcd() as ocd: ocd.send("reset") - show(ocd.send("echo \"echo says hi!\"")[:-1]) + show(ocd.send("capture { echo \"echo says hi!\" }")[:-1]) show(ocd.send("capture \"halt\"")[:-1]) - # Read the first few words at the RAM region (put starting adress of RAM + # Read the first few words at the RAM region (put starting address of RAM # region into 'addr') addr = 0x10000000