summarylogtreecommitdiffstats
path: root/0008-python3-firmware.patch
blob: 85626947aa89eb5b4221ff7ecdfa3c5776715c6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff -pNaru5 a/DM-Firmware-Updater.py b/DM-Firmware-Updater.py
--- a/DM-Firmware-Updater.py	2022-09-25 23:06:30.913939525 -0400
+++ b/DM-Firmware-Updater.py	2022-09-25 23:07:09.284353072 -0400
@@ -11,21 +11,23 @@ def getVersionString(s):
     resp = s.recv(1024)
     fmt = ">LLLLLL64s6sLBBHBBBB"
     devIpAddr, defRoute, srvIpAddr, ipMask, availMemAddr, availMemLength, version, macAddr, \
     modelId, archId, numPorts, progId, boardRev, bootRevMajor, bootRevMinor, numApps \
       = struct.unpack(fmt,resp[:struct.calcsize(fmt)])
+    if sys.hexversion >= 0x030000F0:
+        version=version.decode() # byte array to string array
     return version[:version.index('\x00')]
 
-def getArch((host,port),useIPv6=0):
+def getArch(hostport,useIPv6=0):
 
     if useIPv6:
         s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
     else:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.settimeout(15)
     try:
-        s.connect((host,port))
+        s.connect(hostport)
     except socket.timeout:
         return "network connection timeout";
     except (OSError, socket.error) as e:
         return "Error opening connection: " + str(e)
 
@@ -40,26 +42,31 @@ def getArch((host,port),useIPv6=0):
     except socket.timeout:
         return "network connection timeout";
     except (OSError, socket.error) as e:
         return "error requesting device ID info: " + str(e)
 
-    return ord(resp[98])
+    if sys.hexversion >= 0x030000F0:
+        #print(resp[98])      # 3 for me
+        return resp[98]      # python3 byte array
+    else:
+        #print(ord(resp[98])) # 3 for me
+        return ord(resp[98]) # python2 str array
 
 
 # return error message if failure otherwise return None
-def uploadFile((host,port),filedata,doreset,callback,useIPv6=0):
+def uploadFile(hostport,filedata,doreset,callback,useIPv6=0):
     filesize = len(filedata)
 
     if doreset:
         if useIPv6:
             s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
         else:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         callback(0,"opening connection")
         s.settimeout(15)
         try:
-            s.connect((host,port))
+            s.connect(hostport)
         except socket.timeout:
             return("network connection timeout");
         except (OSError, socket.error) as e:
             return "Error opening connection: " + str(e)
         callback(0,"sending reset command")
@@ -69,11 +76,11 @@ def uploadFile((host,port),filedata,dore
         except socket.timeout:
             return("timeout sending reset command");
         except (OSError, socket.error) as e:
             return "Error sending reset command: " + str(e)
         # wait 3 seconds for the unit to reset and come back up
-        for i in xrange(6):
+        for i in range(6):
             time.sleep(0.5)
             callback((filesize*i)/6)
         callback(filesize)
 
     if useIPv6:
@@ -81,11 +88,11 @@ def uploadFile((host,port),filedata,dore
     else:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     callback(0,"opening connection")
     s.settimeout(15)
     try:
-        s.connect((host,port))
+        s.connect(hostport)
     except socket.timeout:
         return("Timeout opening connection");
     except (OSError, socket.error) as e:
         return "Error opening connection: " + str(e)
 
@@ -126,10 +133,11 @@ def uploadFile((host,port),filedata,dore
 
 if sys.hexversion >= 0x030000F0:
     from tkinter import *
     from tkinter.ttk import *
     import tkinter.filedialog as filedialog
+    import tkinter.messagebox as messagebox
 else:
     from Tkinter import *
     from ttk import *
     import tkFileDialog as filedialog
     import tkMessageBox as messagebox
diff -pNaru5 a/dmupdate.py b/dmupdate.py
--- a/dmupdate.py	2022-09-25 23:06:30.923939633 -0400
+++ b/dmupdate.py	2022-09-25 23:06:33.043962526 -0400
@@ -77,11 +77,11 @@ def getIdentReply(s):
     s.send(struct.pack("<BBHL",cmd,index,length,addr))
     resp = s.recv(1024)
     signal.alarm(0)
 
     if verbose>1:
-        print "[%d] %s" % (len(resp),toHex(resp))
+        print("[%d] %s" % (len(resp),toHex(resp)))
 
     return resp
 
 def getArch(hostName):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -137,33 +137,33 @@ def isRedBoot(s,verbose=False):
             edata = remaining[:elen]
             remaining = remaining[elen:]
             extData.append((etype,elen,edata))
 
     if verbose:
-        print "%15s: %s" % ("devIpAddr",fmtIP(devIpAddr))
-        print "%15s: %s" % ("defRoute",fmtIP(defRoute))
-        print "%15s: %s" % ("srvIpAddr",fmtIP(srvIpAddr))
-        print "%15s: %s" % ("ipMask",fmtIP(ipMask))
-        print "%15s: %s" % ("availMemAddr",hex(availMemAddr))
-        print "%15s: %s" % ("availMemLength",hex(availMemLength))
+        print("%15s: %s" % ("devIpAddr",fmtIP(devIpAddr)))
+        print("%15s: %s" % ("defRoute",fmtIP(defRoute)))
+        print("%15s: %s" % ("srvIpAddr",fmtIP(srvIpAddr)))
+        print("%15s: %s" % ("ipMask",fmtIP(ipMask)))
+        print("%15s: %s" % ("availMemAddr",hex(availMemAddr)))
+        print("%15s: %s" % ("availMemLength",hex(availMemLength)))
         if verbose>1:
-            print "%15s: %s" % ("version",repr(version))
+            print("%15s: %s" % ("version",repr(version)))
         else:
-            print "%15s: %s" % ("version",version[:version.index('\x00')])  # ignore trailing NULs
-        print "%15s: %s" % ("macAddr", macToStr(macAddr))
-        print "%15s: %s" % ("modelId",modelId)
-        print "%15s: %s" % ("archId",archId)
-        print "%15s: %s" % ("numPorts",numPorts)
-        print "%15s: %s" % ("progId",progId)
-        print "%15s: %s" % ("boardRev",boardRev)
-        print "%15s: %s" % ("bootRevMajor",bootRevMajor)
-        print "%15s: %s" % ("bootRevMinor",bootRevMinor)
-        print "%15s: %s" % ("numApps",numApps)
-        print "%15s: %s" % ("appRecords",appRecords)
-        print "%15s: %s" % ("numUserBytes",numUserBytes)
-        print "%15s: %s" % ("appEnables",hex(appEnables))
-        print "%15s:" % ("extData:")
+            print("%15s: %s" % ("version",version[:version.index('\x00')])) # ignore trailing NULs
+        print("%15s: %s" % ("macAddr", macToStr(macAddr)))
+        print("%15s: %s" % ("modelId",modelId))
+        print("%15s: %s" % ("archId",archId))
+        print("%15s: %s" % ("numPorts",numPorts))
+        print("%15s: %s" % ("progId",progId))
+        print("%15s: %s" % ("boardRev",boardRev))
+        print("%15s: %s" % ("bootRevMajor",bootRevMajor))
+        print("%15s: %s" % ("bootRevMinor",bootRevMinor))
+        print("%15s: %s" % ("numApps",numApps))
+        print("%15s: %s" % ("appRecords",appRecords))
+        print("%15s: %s" % ("numUserBytes",numUserBytes))
+        print("%15s: %s" % ("appEnables",hex(appEnables)))
+        print("%15s:" % ("extData:"))
         for e in extData:
             descr = "             type:%d len:%d data: %s" % (e[0],e[1],toHex(e[2]))
             if e[0] == 2:
                 descr += " -- " + decodeFeatureBits(ord(e[2][0]))
             elif e[0] == 3:
@@ -172,11 +172,11 @@ def isRedBoot(s,verbose=False):
                 descr += " -- ipv6 mode"
             elif e[0] == 5:
                 descr += " -- ipv4 configured address"
             elif e[0] == 6:
                 descr += " -- ipv6 current address"
-            print descr
+            print(descr)
 
     return version.startswith("Bootloader") and (progId == 0)
 
 
 def downloadFile(hostName,fileobj,go=0,quiet=0,skip=0,base=0,entry=None,verify_redboot=0):
@@ -188,11 +188,11 @@ def downloadFile(hostName,fileobj,go=0,q
     isrb = isRedBoot(s,verbose)
 
     alarm(0)
 
     if verify_redboot and not isrb:
-        print "Failed to re-connect to RedBoot, found running application."
+        print("Failed to re-connect to RedBoot, found running application.")
         sys.exit(1)
 
     bytecount = len(fileobj.read(skip))
     index = 0
     while 1: