freemyipod r953 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r952‎ | r953 | r954 >
Date:14:45, 16 June 2014
Author:theseven
Status:new
Tags:
Comment:
emCORE/UMSboot: Fix some more USB trouble
Modified paths:
  • /emcore/trunk/tools/libemcore.py (modified) (history)
  • /emcore/trunk/usb/usb.c (modified) (history)
  • /emcore/trunk/usb/usbdebug.c (modified) (history)
  • /umsboot/src/protocol/usb/usb.c (modified) (history)

Diff [purge]

Index: umsboot/src/protocol/usb/usb.c
@@ -377,7 +377,7 @@
378378 {
379379 int epidx;
380380 int ifidx;
381 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 381+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
382382 if (!endpoint) data->driver->unconfigure_ep(data, epnum);
383383 else if (endpoint->timeout) endpoint->timeout(data, ifidx, epidx, bytesleft);
384384 }
@@ -404,7 +404,7 @@
405405 {
406406 int epidx;
407407 int ifidx;
408 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 408+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
409409 if (!endpoint) usb_unconfigure_ep(data, epnum);
410410 else if (endpoint->xfer_complete) endpoint->xfer_complete(data, ifidx, epidx, bytesleft);
411411 }
@@ -420,7 +420,7 @@
421421 {
422422 int epidx;
423423 int ifidx;
424 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 424+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
425425 if (!endpoint) usb_unconfigure_ep(data, epnum);
426426 else if (endpoint->setup_received) endpoint->setup_received(data, ifidx, epidx);
427427 }
Index: emcore/trunk/usb/usbdebug.c
@@ -174,9 +174,9 @@
175175 case 1: // START MEMORY TRANSFER
176176 bulk_state[bulk_ctrlreq_ep].addr = (void*)buf[1];
177177 bulk_state[bulk_ctrlreq_ep].size = buf[2];
178 - usbdebug_bulk_xfer_complete(data, 0, bulk_ctrlreq_ep, 0); // Convenient way to start a transfer.
179178 usb_set_stall(data, ep0out, true);
180179 usb_ep0_start_tx(data, NULL, 0, NULL);
 180+ usbdebug_bulk_xfer_complete(data, 0, bulk_ctrlreq_ep, 0); // Convenient way to start a transfer.
181181 break;
182182 default:
183183 usb_set_stall(data, ep0out, true);
Index: emcore/trunk/usb/usb.c
@@ -377,7 +377,7 @@
378378 {
379379 int epidx;
380380 int ifidx;
381 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 381+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
382382 if (!endpoint) data->driver->unconfigure_ep(data, epnum);
383383 else if (endpoint->timeout) endpoint->timeout(data, ifidx, epidx, bytesleft);
384384 }
@@ -404,7 +404,7 @@
405405 {
406406 int epidx;
407407 int ifidx;
408 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 408+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
409409 if (!endpoint) usb_unconfigure_ep(data, epnum);
410410 else if (endpoint->xfer_complete) endpoint->xfer_complete(data, ifidx, epidx, bytesleft);
411411 }
@@ -420,7 +420,7 @@
421421 {
422422 int epidx;
423423 int ifidx;
424 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx);
 424+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &ifidx, &epidx);
425425 if (!endpoint) usb_unconfigure_ep(data, epnum);
426426 else if (endpoint->setup_received) endpoint->setup_received(data, ifidx, epidx);
427427 }
Index: emcore/trunk/tools/libemcore.py
@@ -127,7 +127,7 @@
128128 """
129129 return self.lib.monitorcommand(struct.pack("<IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
130130
131 - @command()
 131+ @command(timeout = 10000)
132132 def _readmem_bulk(self, addr, size):
133133 """ Reads the memory from location 'addr' with size 'size'
134134 from the device. Can handle unlimited amounts of bytes,
@@ -135,7 +135,7 @@
136136 """
137137 return self.lib.recvbulk(struct.pack("<III", 1, addr, size), size)
138138
139 - @command()
 139+ @command(timeout = 10000)
140140 def _writemem_bulk(self, addr, data):
141141 """ Writes the data in 'data' to the location 'addr'
142142 in the memory of the device. Can handle unlimited amounts of bytes,
@@ -199,10 +199,11 @@
200200 size -= align
201201 align = size & 63
202202 size -= align
203 - data += self._readmem_bulk(addr, size)
204 - addr += size
 203+ if size:
 204+ data += self._readmem_bulk(addr, size)
 205+ addr += size
205206 size = align
206 - except: self.logger.warn("Bulk read interface failed, falling back to slow reads\n")
 207+ except: raise#self.logger.warn("Bulk read interface failed, falling back to slow reads\n")
207208 while size > 0:
208209 readsize = min(size, 0xf00)
209210 data += self._readmem(addr, readsize)
@@ -228,9 +229,10 @@
229230 size -= align
230231 align = size & 63
231232 size -= align
232 - self._writemem_bulk(addr, data[offset:offset+size])
233 - offset += size
234 - addr += size
 233+ if size:
 234+ self._writemem_bulk(addr, data[offset:offset+size])
 235+ offset += size
 236+ addr += size
235237 size = align
236238 except: self.logger.warn("Bulk write interface failed, falling back to slow writes\n")
237239 while size > 0:
@@ -1104,11 +1106,11 @@
11051107 return writelen
11061108
11071109 def sendbulk(self, cmd, data):
1108 - self.logger.debug("Sending bulk command [0x%s]\n" % base64.b16encode(cmd[3::-1]).decode("ascii"))
 1110+ self.logger.debug("Sending bulk command [0x%s] with %d bytes\n" % (base64.b16encode(cmd[3::-1]).decode("ascii"), len(data)))
11091111 return self.dev.sendbulk(cmd, data)
11101112
11111113 def recvbulk(self, cmd, size):
1112 - self.logger.debug("Receiving bulk command [0x%s]\n" % base64.b16encode(cmd[3::-1]).decode("ascii"))
 1114+ self.logger.debug("Receiving bulk command [0x%s] with %d bytes\n" % (base64.b16encode(cmd[3::-1]).decode("ascii"), size))
11131115 return self.dev.recvbulk(cmd, size)
11141116
11151117
@@ -1198,9 +1200,9 @@
11991201 return data
12001202
12011203 def sendbulk(self, cmd, data):
1202 - size = self.dev.ctrl_transfer(0x42, 0x00, 0, self.bulkout.bEndpointAddress, cmd, self.timeout)
1203 - if size != len(cmd):
1204 - raise SendError("Bulk send command could not be fully sent (%d of %d)!" % (size, len(cmd)))
 1204+ cmdsize = self.dev.ctrl_transfer(0x42, 0x00, 0, self.bulkout.bEndpointAddress, cmd, self.timeout)
 1205+ if cmdsize != len(cmd):
 1206+ raise SendError("Bulk send command could not be fully sent (%d of %d)!" % (cmdsize, len(cmd)))
12051207 size = self.bulkout.write(data, self.timeout)
12061208 if size != len(data):
12071209 raise SendError("Bulk data could not be fully sent (%d of %d)!" % (size, len(data)))
@@ -1207,12 +1209,12 @@
12081210 return size
12091211
12101212 def recvbulk(self, cmd, size):
1211 - size = self.dev.ctrl_transfer(0x42, 0x00, 0, self.bulkin.bEndpointAddress, cmd, self.timeout)
1212 - if size != len(cmd):
1213 - raise ReceiveError("Bulk receive command could not be fully sent (%d of %d)!" % (size, len(cmd)))
 1213+ cmdsize = self.dev.ctrl_transfer(0x42, 0x00, 0, self.bulkin.bEndpointAddress, cmd, self.timeout)
 1214+ if cmdsize != len(cmd):
 1215+ raise ReceiveError("Bulk receive command could not be fully sent (%d of %d)!" % (cmdsize, len(cmd)))
12141216 data = self.bulkin.read(size, self.timeout)
12151217 if len(data) != size:
1216 - raise SendError("Bulk data could not be fully received (%d of %d)!" % (len(cmd), size))
 1218+ raise SendError("Bulk data could not be fully received (%d of %d)!" % (len(data), size))
12171219 return data
12181220
12191221