Commit be19d324edc1a1d7f393d24e10d164cd94c91a00

Authored by Remy Bohmer
Committed by Markus Klotzbuecher
1 parent 87b4ef560c

Fix for USB sticks not working on ARM while using GCC 4.x compilers

The GCC-compiler makes an optimisation error while optimising the routine
usb_set_maxpacket(). This should be fixed in the compiler in the first place,
but there lots of compilers out there that makes this error, that it is
probably wiser to workaround it in U-boot itself.

What happens is that the register r3 is used as loop-counter 'i', but gets
overwritten later on. From there it starts using register r3 for several other
things and the assembler code is becoming a big mess. This is clearly a compiler bug.

This error occurs on at least several versions of Code Sourcery Lite compilers
for ARM. Like the Edition 2008q1, and 2008q3, It has also been seen on other
compilers, while compiling for armv4t, or armv5te with Os, O1 and O2.

We work around it by splitting up this routine in 2 parts, and making sure that
the split out part is NOT inlined any longer. This will make GCC spit out assembler
that do not show this problem. Another possibility is to adapt the Makefile to stop
optimisation for the complete file. I think this solution is nicer.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Markus Klotzbuecher <mk@denx.de>

Showing 1 changed file with 46 additions and 27 deletions Side-by-side Diff

... ... @@ -245,40 +245,59 @@
245 245 return(dev->epmaxpacketin[((pipe>>15) & 0xf)]);
246 246 }
247 247  
  248 +/* The routine usb_set_maxpacket_ep() is extracted from the loop of routine
  249 + * usb_set_maxpacket(), because the optimizer of GCC 4.x chokes on this routine
  250 + * when it is inlined in 1 single routine. What happens is that the register r3
  251 + * is used as loop-count 'i', but gets overwritten later on.
  252 + * This is clearly a compiler bug, but it is easier to workaround it here than
  253 + * to update the compiler (Occurs with at least several GCC 4.{1,2},x
  254 + * CodeSourcery compilers like e.g. 2007q3, 2008q1, 2008q3 lite editions on ARM)
  255 + */
  256 +static void __attribute__((noinline))
  257 +usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_descriptor *ep)
  258 +{
  259 + int b;
  260 +
  261 + b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  262 +
  263 + if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  264 + USB_ENDPOINT_XFER_CONTROL) {
  265 + /* Control => bidirectional */
  266 + dev->epmaxpacketout[b] = ep->wMaxPacketSize;
  267 + dev->epmaxpacketin [b] = ep->wMaxPacketSize;
  268 + USB_PRINTF("##Control EP epmaxpacketout/in[%d] = %d\n",
  269 + b, dev->epmaxpacketin[b]);
  270 + } else {
  271 + if ((ep->bEndpointAddress & 0x80) == 0) {
  272 + /* OUT Endpoint */
  273 + if (ep->wMaxPacketSize > dev->epmaxpacketout[b]) {
  274 + dev->epmaxpacketout[b] = ep->wMaxPacketSize;
  275 + USB_PRINTF("##EP epmaxpacketout[%d] = %d\n",
  276 + b, dev->epmaxpacketout[b]);
  277 + }
  278 + } else {
  279 + /* IN Endpoint */
  280 + if (ep->wMaxPacketSize > dev->epmaxpacketin[b]) {
  281 + dev->epmaxpacketin[b] = ep->wMaxPacketSize;
  282 + USB_PRINTF("##EP epmaxpacketin[%d] = %d\n",
  283 + b, dev->epmaxpacketin[b]);
  284 + }
  285 + } /* if out */
  286 + } /* if control */
  287 +}
  288 +
248 289 /*
249 290 * set the max packed value of all endpoints in the given configuration
250 291 */
251 292 int usb_set_maxpacket(struct usb_device *dev)
252 293 {
253   - int i,ii,b;
254   - struct usb_endpoint_descriptor *ep;
  294 + int i, ii;
255 295  
256   - for(i=0; i<dev->config.bNumInterfaces;i++) {
257   - for(ii=0; ii<dev->config.if_desc[i].bNumEndpoints; ii++) {
258   - ep = &dev->config.if_desc[i].ep_desc[ii];
259   - b=ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  296 + for (i = 0; i < dev->config.bNumInterfaces; i++)
  297 + for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++)
  298 + usb_set_maxpacket_ep(dev,
  299 + &dev->config.if_desc[i].ep_desc[ii]);
260 300  
261   - if((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)==USB_ENDPOINT_XFER_CONTROL) { /* Control => bidirectional */
262   - dev->epmaxpacketout[b] = ep->wMaxPacketSize;
263   - dev->epmaxpacketin [b] = ep->wMaxPacketSize;
264   - USB_PRINTF("##Control EP epmaxpacketout/in[%d] = %d\n",b,dev->epmaxpacketin[b]);
265   - }
266   - else {
267   - if ((ep->bEndpointAddress & 0x80)==0) { /* OUT Endpoint */
268   - if(ep->wMaxPacketSize > dev->epmaxpacketout[b]) {
269   - dev->epmaxpacketout[b] = ep->wMaxPacketSize;
270   - USB_PRINTF("##EP epmaxpacketout[%d] = %d\n",b,dev->epmaxpacketout[b]);
271   - }
272   - }
273   - else { /* IN Endpoint */
274   - if(ep->wMaxPacketSize > dev->epmaxpacketin[b]) {
275   - dev->epmaxpacketin[b] = ep->wMaxPacketSize;
276   - USB_PRINTF("##EP epmaxpacketin[%d] = %d\n",b,dev->epmaxpacketin[b]);
277   - }
278   - } /* if out */
279   - } /* if control */
280   - } /* for each endpoint */
281   - }
282 301 return 0;
283 302 }
284 303