Embedded Linux Encounters

A peek in to the world of Embedded Linux and stuff

  • Linux is addictive, I'm hooked!

         Geek@WastingTime>
Showing posts with label kernel. Show all posts
Showing posts with label kernel. Show all posts

Making Android gadget work on PXA270

Posted by Vaisakh P S On 10:33 PM 1 comments

Hi Everyone,

Was busy in some other work (other than Linux), so my Android porting activity got stalled for few months. Now I am back in to it.

Back to the topic, I was able to make Android Gadget and ADB work in my PXA270 board. Here are the changes that needs to made:
  1. Modified drivers/usb/gadget/android.c , to move usb_configuration structure from init data section to bss. Previously this used to create a fatal crash as this configuration is getting added in to linked list which will be later traversed during endpoint configuration setup phase, at which this will show up as a NULL reference.

diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c

index c431131..f14fedf 100644

--- a/drivers/usb/gadget/android.c

+++ b/drivers/usb/gadget/android.c

@@ -113,7 +113,7 @@ static int __init android_bind_config(struct usb_configuration *c)

return adb_function_add(c);

}

-static struct usb_configuration android_config __initdata = {

+static struct usb_configuration android_config = {

.label = "android",

.bind = android_bind_config,

.bConfigurationValue = 1,


  1. Change the USB Endpoint setup array in drivers/usb/gadget/pxa27x_udc.c, to make two sets of Bulk Endpoints(IN and out) available to android gadget driver. (I removed rest of the configurations, just because only I didn't need them)

diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c

index 7cbc78a..037e435 100644

--- a/drivers/usb/gadget/pxa27x_udc.c

+++ b/drivers/usb/gadget/pxa27x_udc.c

@@ -2171,36 +2171,19 @@ static struct pxa_udc memory = {

USB_EP_CTRL,

USB_EP_OUT_BULK(1),

USB_EP_IN_BULK(2),

- USB_EP_IN_ISO(3),

- USB_EP_OUT_ISO(4),

- USB_EP_IN_INT(5),

+ USB_EP_OUT_BULK(3),

+ USB_EP_IN_BULK(4),

+

},

.pxa_ep = {

PXA_EP_CTRL,

/* Endpoints for gadget zero */

- PXA_EP_OUT_BULK(1, 1, 3, 0, 0),

- PXA_EP_IN_BULK(2, 2, 3, 0, 0),

+ PXA_EP_OUT_BULK(1, 1, 1, 0, 0),

+ PXA_EP_IN_BULK(2, 2, 1, 0, 0),

/* Endpoints for ether gadget, file storage gadget */

- PXA_EP_OUT_BULK(3, 1, 1, 0, 0),

- PXA_EP_IN_BULK(4, 2, 1, 0, 0),

- PXA_EP_IN_ISO(5, 3, 1, 0, 0),

- PXA_EP_OUT_ISO(6, 4, 1, 0, 0),

- PXA_EP_IN_INT(7, 5, 1, 0, 0),

- /* Endpoints for RNDIS, serial */

- PXA_EP_OUT_BULK(8, 1, 2, 0, 0),

- PXA_EP_IN_BULK(9, 2, 2, 0, 0),

- PXA_EP_IN_INT(10, 5, 2, 0, 0),

- /*

- * All the following endpoints are only for completion. They

- * won't never work, as multiple interfaces are really broken on

- * the pxa.

- */

- PXA_EP_OUT_BULK(11, 1, 2, 1, 0),

- PXA_EP_IN_BULK(12, 2, 2, 1, 0),

- /* Endpoint for CDC Ether */

- PXA_EP_OUT_BULK(13, 1, 1, 1, 1),

- PXA_EP_IN_BULK(14, 2, 1, 1, 1),

+ PXA_EP_OUT_BULK(3, 3, 1, 0, 0),

+ PXA_EP_IN_BULK(4, 4, 1, 0, 0),

}

};


diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h

index 1d1b793..7a42932 100644

--- a/drivers/usb/gadget/pxa27x_udc.h

+++ b/drivers/usb/gadget/pxa27x_udc.h

@@ -409,8 +409,8 @@ struct udc_stats {

unsigned long irqs_reconfig;

};

-#define NR_USB_ENDPOINTS (1 + 5) /* ep0 + ep1in-bulk + .. + ep3in-iso */

-#define NR_PXA_ENDPOINTS (1 + 14) /* ep0 + epA + epB + .. + epX */

+#define NR_USB_ENDPOINTS (1 + 4) /* ep0 + ep1in-bulk + .. + ep3in-iso */

+#define NR_PXA_ENDPOINTS (1 + 4) /* ep0 + epA + epB + .. + epX */


  1. After these two steps, your PXA gadget will be recognized by PC. Now change the INF file in Android Windows USB Driver (available along with SDK), to recognize your device.
  2. Now I am facing some crashes because of NULL reference in Mass Storage profile of android. For recognizing in Windows, both ADB and Storage profile of Android gadget needs to be active. For development in Linux, you need not have Storage. That can be commented off in android.c
  3. Make sure that you have "UNIX PTY Support" enabled in kernel, as ADB client and server makes use of those devices for process creation and some other operations.

During booting of kernel, these are the possible error messages that may show. Here are the reasons for the same:

Kernel completely up but console is not shown
  • This could have been because of various reasons. Either the console device specified in boot arguments would be different
  • There might not be a device instance corresponding to the specified device under /dev directory.

Init not found or Failure in executing init
  • Init program might not be given execution privileges or root might not be the owner of the init executable.
  • If BusyBox is not compiled as a static binary, then failure in loading the dynamic libraries can also result this error.


Failed in mounting root file system
  • The device such as MMC card or USB will require certain amount time to be made accessible or mounted. So use the 'rootdelay' boot argument to introduce a delay before kernel tries to mount the file system.
  • If the file system is corrupted then also this error would come up. So it is advisable to maintain a back up file system image to re-flash your storage if this happens.
  • Periodically run a fsck command on the file systems used including root file system.