Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] fixed a TypeError in the read (-r) function of stm32loader.py

11 views
Skip to first unread message

Ivan Shmakov

unread,
May 13, 2013, 7:32:41 AM5/13/13
to
Archive-name: stm32loader.py-2013-is
Submitted-by: onei...@gmail.com
Last-modified: 2013-05-13 +00:00
Copyright-Notice: Released under the CC0 Public Domain Dedication;
(but are probably too trivial to be copyrightable, anyway.)

[Followup-To: set to news:alt.sources.d, as per the
news:alt.sources' charter, and also news:comp.sys.arm, and
news:comp.arch.embedded.]


Summary

The patch suggested fixes a bug in stm32loader.py [1] where the
.write () method ends up being called with a list argument,
resulting in an error, like:

$ python stm32loader.py \
-l 65536 -b 115200 -r -p /dev/ttyUSB0 \
"$(mktemp -- ./bin.XXXXXXXX)"
Bootloader version 22
Chip id `['0x4', '0x10']'
Read 256 bytes at 0x8000000
...
Read 256 bytes at 0x800FF00
Traceback (most recent call last):
File
"stm32loader.py",
line 391, in <module>
file(args[0], 'wb').write(rdata)
TypeError: must be string or buffer, not list
$

[1] http://elua-development.2368040.n2.nabble.com/attachment/2499766/0/stm32loader.py


The ChangeLog entry

2013-05-13 Ivan Shmakov <onei...@gmail.com>

* stm32loader.py: Turn the (octet) string returned by
.cmdReadMemory () into a list of integer octet values before
comparing to such a list read from a file when verifying (-v.)
(CommandInterface.cmdReadMemory): Fixed: return an octet
string (was: a list of octet values.)
(CommandInterface.readMemory): Likewise.


The patch

--- elua-development.2368040.n2.nabble.com/attachment/2499766/0/stm32loader.py
+++ stm32loader.py
@@ -148,7 +148,7 @@ class CommandInterface: def cmdReadMemory(self, addr, lng):
crc = N ^ 0xFF
self.sp.write(chr(N) + chr(crc))
self._wait_for_ask("0x11 length failed")
- return map(lambda c: ord(c), self.sp.read(lng))
+ return self.sp.read(lng)
else:
raise CmdException("ReadMemory (0x11) failed")

@@ -248,7 +248,7 @@ class CommandInterface:
# Complex commands section

def readMemory(self, addr, lng):
- data = []
+ data = ''
while lng > 256:
mdebug(5, "Read %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
data = data + self.cmdReadMemory(addr, 256)
@@ -376,7 +376,7 @@ if __name__ == "__main__":
cmd.writeMemory(conf['address'], data)

if conf['verify']:
- verify = cmd.readMemory(conf['address'], len(data))
+ verify = map(lambda c: ord(c), cmd.readMemory(conf['address'], len(data)))
if(data == verify):
print "Verification OK"
else:

--
FSF associate member #7257
0 new messages