execute own code from iram, however READ attention text before doing
[pyfrprog.git] / frprog.py
index 260fda1d1908f35a62b060318903d25fa1647411..1f0a1fbb07a9ea2949c2afdcaa3dd4b876f163d0 100755 (executable)
--- a/frprog.py
+++ b/frprog.py
@@ -2,6 +2,13 @@
 import sys, time
 from SerialPort_linux import *
 
+# serial device to communicate with
+DEVICE="/dev/ttyUSB0"
+# baudrate used for initialization
+INIT_BAUDRATE=9600
+# baudrate used for communication after init
+REAL_BAUDRATE=38400
+
 # contains the last received checksum from a READ, WRITE or CHECKSUM command
 last_checksum = 0
 
@@ -25,7 +32,6 @@ def recvByte():
 
 def recvChecksum():
        global last_checksum
-       # get checksum
        last_checksum = recvByte()
        last_checksum |= (recvByte() << 8)
 
@@ -65,6 +71,32 @@ def cmdWRITE(address, size, data):
        # get checksum
        recvChecksum()
 
+# TODO: test this function!
+def cmdCALL(address):
+       # send CALL command
+       sendByte(0x01)
+       if (recvByte() != 0xF1):
+               raise Exception
+       sendByte(0x04)
+       if (recvByte() != 0x84):
+               raise Exception
+       # tell desired address
+       sendDWord(address)
+       # wait for return parameter - not needed here!
+       #return recvByte()
+
+# TODO: test this function!
+def cmdCHECKSUM():
+       # call CHECKSUM command
+       sendByte(0x01)
+       if (recvByte() != 0xF1):
+               raise Exception
+       sendByte(0x05)
+       if (recvByte() != 0x84):
+               raise Exception
+       # get checksum
+       recvChecksum()
+
 def cmdBAUDRATE(baudrate):
        global last_checksum
 
@@ -82,7 +114,7 @@ def cmdBAUDRATE(baudrate):
        sendByte((baudrate >> 24) & 0xFF)
 
 print "Initializing serial port..."
-tty = SerialPort("/dev/ttyUSB0", 100, 9600)
+tty = SerialPort(DEVICE, 100, INIT_BAUDRATE)
 
 print "Please press RESET on your 1337 board..."
 
@@ -99,8 +131,8 @@ while 1:
 print "OK, trying to set baudrate..."
 
 # set baudrate
-cmdBAUDRATE(38400)
-tty = SerialPort("/dev/ttyUSB0", 100, 38400)
+cmdBAUDRATE(REAL_BAUDRATE)
+tty = SerialPort(DEVICE, 100, REAL_BAUDRATE)
 """
 print
 sendByte(0x01)
@@ -109,8 +141,22 @@ sendByte(0x02)
 print recvByte()
 sys.exit(0)
 """
+"""
+# execute (existing) program in ram
+cmdCALL(0x00033ffc)
+sys.exit(0)
+"""
+
+# read something from the IRAM
+#print cmdREAD(0x00030000, 32)
 
+#data = []
+#for i in range(0, 32):
+#      data.append(i)
+#cmdWRITE(0x00030000, 32, data)
 
+
+"""
 # write something to the begin of the IRAM
 data_wr = []
 checksum = 0
@@ -128,3 +174,69 @@ print
 print "Reading from the IRAM again..."
 data_re = cmdREAD(0x00030000, len(data_wr))
 print "Received data:", data_re, "Checksum:", last_checksum
+"""
+
+"""
+# see whats in the iram at the moment
+data_wr = []
+print "Reading from the IRAM..."
+data_re = cmdREAD(0x00030000, 0x10000-4)
+print "Received data:", data_re, "Checksum:", last_checksum
+"""
+
+"""
+# see whats in the dram at the moment
+data_wr = []
+print "Reading from the DRAM..."
+data_re = cmdREAD(0x0002C000, 0x10000-0xC000-4)
+print "Received data:", data_re, "Checksum:", last_checksum
+"""
+
+"""
+# blank the iram
+data_wr = []
+for i in range(0, 0x10000-4):
+       value = 0
+       data_wr.append(value)
+
+print "Writing", data_wr, "to the IRAM..."
+cmdWRITE(0x00030000, len(data_wr), data_wr)
+print "Received Checksum:", last_checksum
+print
+"""
+
+"""
+# blank the dram
+data_wr = []
+for i in range(0, 0x10000-0xC000-4):
+       value = 0
+       data_wr.append(value)
+
+print "Writing", data_wr, "to the DRAM..."
+cmdWRITE(0x0002C000, len(data_wr), data_wr)
+print "Received Checksum:", last_checksum
+print
+"""
+
+
+"""
+S006000066756AB4
+S20E0F40009B000D4ECFF11601E0FFF6
+S214148000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF67
+S804000000FB
+
+NOP = 0x9fa0
+"""
+# write some data in the iram and try to execute it
+# ATTENTION: before running this, run a program on the board (e.g. flashdemo).
+# the bytecode will be executed after copied into iram, however it won't stop
+# and executes the stuff after it in the iram. after a powerreset this can be
+# randomcrap and this could be very dangerous! so pay attention please
+data_wr =[0x9B,0x00,0x0D,0x4e,0xcf,0xf1,0x16,0x01,0xe0,0xff,0xf6,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0xe0,
+               0xcb,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,
+               0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0]
+print "Writing", data_wr, "to the IRAM..."
+cmdWRITE(0x00030000, len(data_wr), data_wr)
+print "Received Checksum:", last_checksum
+print
+cmdCALL(0x00030000)