Index: embios/trunk/tools/embios.py |
— | — | @@ -325,6 +325,7 @@ |
326 | 326 | self.logger.info("Writing file '"+filename+"' to memory at "+self._hex(addr)+"...")
|
327 | 327 | with f:
|
328 | 328 | self.embios.write(addr, f.read())
|
| 329 | + f.close()
|
329 | 330 | self.logger.info("done\n")
|
330 | 331 |
|
331 | 332 | @command
|
— | — | @@ -344,6 +345,7 @@ |
345 | 346 | self.logger.info("Reading data from address "+self._hex(addr)+" with the size "+self._hex(size)+" to '"+filename+"'...")
|
346 | 347 | with f:
|
347 | 348 | f.write(self.embios.read(addr, size))
|
| 349 | + f.close()
|
348 | 350 | self.logger.info("done\n")
|
349 | 351 |
|
350 | 352 | @command
|
— | — | @@ -358,7 +360,7 @@ |
359 | 361 | if integer > 0xFFFFFFFF:
|
360 | 362 | raise ArgumentError("Specified integer too long")
|
361 | 363 | data = chr(integer)
|
362 | | - self.embios.writemem(addr, data)
|
| 364 | + self.embios.write(addr, data)
|
363 | 365 | self.logger.info("Integer '"+self._hex(integer)+"' written successfully to "+self._hex(addr))
|
364 | 366 |
|
365 | 367 | @command
|
— | — | @@ -368,7 +370,7 @@ |
369 | 371 | <offset>: the address to download the integer from
|
370 | 372 | """
|
371 | 373 | addr = self._hexint(addr)
|
372 | | - data = self.embios.readmem(addr, 1)
|
| 374 | + data = self.embios.read(addr, 1)
|
373 | 375 | integer = ord(data)
|
374 | 376 | self.logger.info("Integer '"+self._hex(integer)+"' read from address "+self._hex(addr))
|
375 | 377 |
|
— | — | @@ -495,7 +497,7 @@ |
496 | 498 | """
|
497 | 499 | self.logger.info("Will now lock scheduler\n")
|
498 | 500 | self.embios.lockscheduler()
|
499 | | -
|
| 501 | +
|
500 | 502 | @command
|
501 | 503 | def unlockscheduler(self):
|
502 | 504 | """
|
— | — | @@ -503,7 +505,7 @@ |
504 | 506 | """
|
505 | 507 | self.logger.info("Will now unlock scheduler\n")
|
506 | 508 | self.embios.unlockscheduler()
|
507 | | -
|
| 509 | +
|
508 | 510 | @command
|
509 | 511 | def suspendthread(self, threadid):
|
510 | 512 | """
|
— | — | @@ -664,7 +666,7 @@ |
665 | 667 | " and saving it to "+self._hex(destination)+" - "+self._hex(destination+sha1size)+"...")
|
666 | 668 | self.embios.hmac_sha1(addr, size, destination)
|
667 | 669 | self.logger.info("done\n")
|
668 | | - data = self.embios.readmem(destination, sha1size)
|
| 670 | + data = self.embios.read(destination, sha1size)
|
669 | 671 | hash = ord(data)
|
670 | 672 | self.logger.info("The generated hash is "+self._hex(hash))
|
671 | 673 |
|
Index: embios/trunk/tools/libembios.py |
— | — | @@ -88,6 +88,33 @@ |
89 | 89 | tailsize = end - tailaddr
|
90 | 90 | return (headsize, tailaddr - bodyaddr, tailsize)
|
91 | 91 |
|
| 92 | + def _readmem(self, addr, size):
|
| 93 | + """ Reads the memory from location 'addr' with size 'size'
|
| 94 | + from the device.
|
| 95 | + """
|
| 96 | + resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
| 97 | + return resp.data
|
| 98 | +
|
| 99 | + def _writemem(self, addr, data):
|
| 100 | + """ Writes the data in 'data' to the location 'addr'
|
| 101 | + in the memory of the device.
|
| 102 | + """
|
| 103 | + return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
| 104 | +
|
| 105 | + def _readdma(self, addr, size):
|
| 106 | + """ Reads the memory from location 'addr' with size 'size'
|
| 107 | + from the device. This uses DMA and the data in endpoint.
|
| 108 | + """
|
| 109 | + self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
| 110 | + return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
| 111 | +
|
| 112 | + def _writedma(self, addr, data):
|
| 113 | + """ Writes the data in 'data' to the location 'addr'
|
| 114 | + in the memory of the device. This uses DMA and the data out endpoint.
|
| 115 | + """
|
| 116 | + self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
| 117 | + return self.lib.dev.dout(data)
|
| 118 | +
|
92 | 119 | def getversioninfo(self):
|
93 | 120 | """ This returns the emBIOS version and device information. """
|
94 | 121 | return self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
— | — | @@ -131,19 +158,19 @@ |
132 | 159 | data = ""
|
133 | 160 | (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
134 | 161 | if headsize != 0:
|
135 | | - data += self.readmem(addr, headsize)
|
| 162 | + data += self._readmem(addr, headsize)
|
136 | 163 | addr += headsize
|
137 | 164 | while bodysize > 0:
|
138 | 165 | if bodysize >= 2 * cin_maxsize:
|
139 | 166 | readsize = min(bodysize, din_maxsize)
|
140 | | - data += self.readdma(addr, readsize)
|
| 167 | + data += self._readdma(addr, readsize)
|
141 | 168 | else:
|
142 | 169 | readsize = min(bodysize, cin_maxsize)
|
143 | | - data += self.readmem(addr, readsize)
|
| 170 | + data += self._readmem(addr, readsize)
|
144 | 171 | addr += readsize
|
145 | 172 | bodysize -= readsize
|
146 | 173 | if tailsize != 0:
|
147 | | - data += self.readmem(addr, tailsize)
|
| 174 | + data += self._readmem(addr, tailsize)
|
148 | 175 | return data
|
149 | 176 |
|
150 | 177 | def write(self, addr, data):
|
— | — | @@ -156,50 +183,23 @@ |
157 | 184 | (headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
158 | 185 | offset = 0
|
159 | 186 | if headsize != 0:
|
160 | | - self.writemem(addr, data[offset:offset+headsize])
|
| 187 | + self._writemem(addr, data[offset:offset+headsize])
|
161 | 188 | offset += headsize
|
162 | 189 | addr += headsize
|
163 | 190 | while bodysize > 0:
|
164 | 191 | if bodysize >= 2 * cout_maxsize:
|
165 | 192 | writesize = min(bodysize, dout_maxsize)
|
166 | | - self.writedma(addr, data[offset:offset+writesize])
|
| 193 | + self._writedma(addr, data[offset:offset+writesize])
|
167 | 194 | else:
|
168 | 195 | writesize = min(bodysize, cout_maxsize)
|
169 | | - self.writemem(addr, data[offset:offset+writesize])
|
| 196 | + self._writemem(addr, data[offset:offset+writesize])
|
170 | 197 | offset += writesize
|
171 | 198 | addr += writesize
|
172 | 199 | bodysize -= writesize
|
173 | 200 | if tailsize != 0:
|
174 | | - self.writemem(addr, data[offset:offset+tailsize])
|
| 201 | + self._writemem(addr, data[offset:offset+tailsize])
|
175 | 202 | return data
|
176 | 203 |
|
177 | | - def readmem(self, addr, size):
|
178 | | - """ Reads the memory from location 'addr' with size 'size'
|
179 | | - from the device.
|
180 | | - """
|
181 | | - resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
182 | | - return resp.data
|
183 | | -
|
184 | | - def writemem(self, addr, data):
|
185 | | - """ Writes the data in 'data' to the location 'addr'
|
186 | | - in the memory of the device.
|
187 | | - """
|
188 | | - return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
189 | | -
|
190 | | - def readdma(self, addr, size):
|
191 | | - """ Reads the memory from location 'addr' with size 'size'
|
192 | | - from the device. This uses DMA and the data in endpoint.
|
193 | | - """
|
194 | | - self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
195 | | - return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
196 | | -
|
197 | | - def writedma(self, addr, data):
|
198 | | - """ Writes the data in 'data' to the location 'addr'
|
199 | | - in the memory of the device. This uses DMA and the data out endpoint.
|
200 | | - """
|
201 | | - self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
202 | | - return self.lib.dev.dout(data)
|
203 | | -
|
204 | 204 | def readstring(self, addr, maxlength = 256):
|
205 | 205 | """ Reads a zero terminated string from memory
|
206 | 206 | Reads only a maximum of 'maxlength' chars.
|
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
209 | 209 | string = ""
|
210 | 210 | while (len(string) < maxlength or maxlength < 0):
|
211 | | - data = self.readmem(addr, min(maxlength - len(string), cin_maxsize))
|
| 211 | + data = self._readmem(addr, min(maxlength - len(string), cin_maxsize))
|
212 | 212 | length = data.find("\0")
|
213 | 213 | if length >= 0:
|
214 | 214 | string += data[:length]
|
— | — | @@ -342,9 +342,6 @@ |
343 | 343 | threads.append(info)
|
344 | 344 | id += 1
|
345 | 345 | return threads
|
346 | | -
|
347 | | -
|
348 | | - return self.lib.monitorcommand(struct.pack("IIII", 15, offset, size, 0), "III%ds" % size, ("structver", "tablesize", None, "data"))
|
349 | 346 |
|
350 | 347 | def lockscheduler(self, freeze=True):
|
351 | 348 | """ Freezes/Unfreezes the scheduler """
|