How to build g_file_storage.ko for G1 rc29?

185 views
Skip to first unread message

ronald

unread,
Jan 7, 2009, 5:39:40 AM1/7/09
to android-platform
(especially to Mike Lockwood)

I am trying to mount one block device file on G1 (RC29) as a flash
disk to PC. I want to use drivers/usb/gadget/file_storage.c.

The problem is that the running RC29 kernel does not supoort gadget,
so there is no usb_gadget_register_driver() and
usb_gadget_unregister_driver() exported in the kernel.

To export such symbols, I configiure m66592-udc.c as a kernel module
(according to menuconfig, this is the only "USB peripheral Controller"
candidate).

But when I insert the module (m66592-udc.ko), kernel reports:

insmod: init_module `./m66592-udc.ko' failed (No such device)

Do I choose the right controller? What kind of peripheral controlled
is used in G1?
What should I do to build g_file_storage.ko?

I hope Google guys help me.

Thanks,

Mike Lockwood

unread,
Jan 7, 2009, 5:53:54 AM1/7/09
to android-...@googlegroups.com
Hi Ronald,

The M66592 driver won't work on the G1 (it is for some other chipset).
We have a gadget driver for the MSM 72K under development in our
2.6.27 sources. See:

http://android.git.kernel.org/?p=kernel/msm.git;a=blob;f=drivers/usb/gadget/msm72k_udc.c

This is in the android-msm-2.6.27 branch, but it would probably be
trivial to backport to the 2.6.25 kernel. Once you get that working,
you would need to disable CONFIG_USB_FUNCTION and enable
CONFIG_USB_GADGET and CONFIG_USB_GADGET_MSM_72K. Then you should be
able to use the g_file_storage gadget driver.

Mike

--
Mike Lockwood
Google android team

Xiangfeng ZHANG

unread,
Jan 7, 2009, 10:32:03 PM1/7/09
to android-...@googlegroups.com
Hi, Mike,

Thanks for your quick reply. After downloading msm72k_udc.c, msm72k_udc.h, arch_arm_mach-msm_include_mach_board.h, arch-arm-mach-msm-include-mach-msm_hsusb.h, and modifying related Kconfig & Makefile, I can finally begin to compile kernel source. But several errors block me:

ERROR: "clk_enable" [drivers/usb/gadget/msm72k_udc.ko] undefined!
ERROR: "clk_disable" [drivers/usb/gadget/msm72k_udc.ko] undefined!
ERROR: "clk_put" [drivers/usb/gadget/msm72k_udc.ko] undefined!
ERROR: "clk_get" [drivers/usb/gadget/msm72k_udc.ko] undefined!
ERROR: "__msm_ioremap" [drivers/usb/gadget/msm72k_udc.ko] undefined!

I search the whole source tree, but did not find the sysmbol "clk_***" for mach-msm.

I found definition of __msm_ioremap() at the end of arch/arm/mach-msm/io.c, but the symbole is not exported, so I COPY the definition into file msm72k_udc.c (I want a kernel module). Hope this is ok to run my module (although not available now).

Could you give some advice for me to get  the definiton of "clk_**" functions for msm72k_udc ?

Thanks
--
Best regards

Xiangfeng ZHANG

unread,
Jan 7, 2009, 10:40:25 PM1/7/09
to android-...@googlegroups.com
Hi, Mike,

still some questions.

I find "CONFIG_USB_FUNCTION" is just defined in msm_defconfig and is never used elsewhere (in kernel source tree 2.6.25 and 2.6.27). How should I disable it as you suggested?

Similar things happen to "CONFIG_USB_FUNCTION***" macros.

Do I get the wrong source tree? Or there is something I do not know. Please help me.

Thanks.



On Wed, Jan 7, 2009 at 6:53 PM, Mike Lockwood <lock...@android.com> wrote:



--
Best regards

maximuska

unread,
Jan 8, 2009, 10:33:18 AM1/8/09
to android-platform
> ERROR: "clk_enable" [drivers/usb/gadget/msm72k_udc.ko] undefined!
> ERROR: "clk_disable" [drivers/usb/gadget/msm72k_udc.ko] undefined!
> ERROR: "clk_put" [drivers/usb/gadget/msm72k_udc.ko] undefined!
> ERROR: "clk_get" [drivers/usb/gadget/msm72k_udc.ko] undefined!

I had a similar issue with backporting of pxa27xx driver.
The implementation of clk methods was under arch/arm/mach-pxa/

I've resolved it (Q&D) by defining the following macros at the top of
the driver:
#define clk_get(dev,name) NULL
#define clk_enable(clk) pxa_set_cken(CKEN11_USB, 1);
#define clk_disable(clk) pxa_set_cken(CKEN11_USB, 0);
#define clk_put(clk)

> ERROR: "__msm_ioremap" [drivers/usb/gadget/msm72k_udc.ko] undefined!
I haven't had this problem, I guess the solution is similar.

Mike Lockwood

unread,
Jan 8, 2009, 11:39:37 AM1/8/09
to android-...@googlegroups.com
CONFIG_USB_FUNCTION is used to enable the drivers in
drivers/usb/function/ This code is in the android kernel, but not the
standard Linux sources. You definitely do not want to have this
enabled if you are using gadget. Otherwise, you will end up with two
different USB drivers trying to control the USB hardware.

Mike

Mike Lockwood

unread,
Jan 8, 2009, 11:41:27 AM1/8/09
to android-...@googlegroups.com
Right, the clk_* calls changed a bit between 2.6.25 and 2.6.27. To
see what changes you will need to backport msm72k_udc to 2.6.25, try
looking at drivers/usb/function/msm_hsusb.c and comparing the 2.6.25
and 2.6.27 versions of this file.

Mike

--

Xiangfeng ZHANG

unread,
Jan 9, 2009, 6:24:58 AM1/9/09
to android-...@googlegroups.com
Hi, Mike,

thank you.

I re-download the 2.6.25 kernel (http://android.git.kernel.org/?p=kernel/msm.git;a=snapshot;h=refs/heads/msm-2.6.25;sf=tgz) and repeat my work, and things get much better. I can compile the kernel and modules. the new source tree contains clk_*() function for mach-msm, but __msm_ioremap stll missing (I copied one).

Now I want to put my new kernel to g1, and I meet new problems.


According to http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images,  two .pl scripts are available to help unpack/pack boot images. I packed my new kernel and the original ramdisk image into a new  a boot.img. but after unpacking the new image, I found my kernel size changed (300bytes longer than it should be)

see below:

zxf@zxfpc-desktop:~/tmp$ ls -l boot-new/
-rw-r--r-- 1 zxf zxf 2504704 2009-01-09 19:19 mtd2.img
-rwxr-xr-x 1 zxf zxf 1273556 2009-01-09 13:57 mtd2.img-kernel.gz
                             (^^^^^^^^^)
drwxr-xr-x 2 zxf zxf    4096 2009-01-09 16:39 mtd2.img-ramdisk
-rw-r--r-- 1 zxf zxf 1228800 2009-01-09 14:01 mtd2.img-ramdisk.cpio.gz
-rwxr-xr-x 1 zxf zxf     442 2009-01-09 18:56 new-boot.sh

zxf@zxfpc-desktop:~/tmp$ ls -l boot-unpack/
-rw-r--r-- 1 zxf zxf 2504704 2009-01-09 19:19 mtd2.img
-rw-r--r-- 1 zxf zxf 1273856 2009-01-09 19:19 mtd2.img-kernel.gz
                             (^^^^^^^^^)
drwxr-xr-x 8 zxf zxf    4096 2009-01-09 19:19 mtd2.img-ramdisk
-rw-r--r-- 1 zxf zxf 1228800 2009-01-09 19:19 mtd2.img-ramdisk.cpio.gz
zxf@zxfpc-desktop:~/tmp$


Originally I did not notice this. After flash the new kernel, G1 can not boot normally.  after almost two hours' check, I found the difference in size.

Could you help me find what is wrong?
--
Best regards

Mike Lockwood

unread,
Jan 9, 2009, 11:39:17 AM1/9/09
to android-...@googlegroups.com
Sorry, I don't know anything about the tools on android-dls.com You
might try the g1-ha...@telesphoreo.org mailing list.

Mike

ronald

unread,
Jan 15, 2009, 8:24:29 PM1/15/09
to android-platform
Hi, Mike,


I make some progress, and new problem appears.

After re-checking the source tree (
http://android.git.kernel.org/?p=kernel/msm.git;a=snapshot;h=refs/heads/android-msm-htc-2.6.25;sf=tgz),
I built a new kernel, using the default kernel config (retrieved from
a
running g1 RC29).

Following the steps of building new boot image, flash it to g1, and
reboot,
I find g1 can boot normally. After modifying the kernel config
slightly and
repeating the steps, g1 can also boot normally (except tiwlan.ko can
not be
loaded). So, the split_bootimg.pl and mkbootimage run quite well,
and the
whole process is ok.


After getting files msm72k_udc.[ch], gadget_chips.h from 2.6.27 tree
and do
some small changes to Makefile & Kconfig, I can finally get follwoing
modules:

g_ether.ko
g_file_storage.ko
msm72k_udc.ko

My objective is to link g1 and my PC through USB ethernet link.

On g1 side, I do following things in sequence:
# insmod ./msm72k_udc.ko # this command succede
# echo $?
0

# dmesg
init: untracked pid 236 exited
msm72k_udc: msm72k_probe
msm72k_udc: msm72k_probe() io=c6808000, irq=47, dma=ffc03000
(49e60000)


# insmod ./g_ether.ko
# echo $?
0
# dmesg
msm72k_udc: msm72k_udc:registered gadget driver 'ether'
msm72k_udc:IDLE -> ONLINE
msm72k_udc: msm72k_udc: reset controller
msm72k_udc: ulpi: write 0x40 to 0x31
msm72k_udc: ulpi: write 0x1d to 0x0d
msm72k_udc: ulpi: write 0x1d to 0x10
msm72k_udc: ept #0 out max:64 head:ffc03000 bit:0
msm72k_udc: ept #1 out max 512 head:ffc03080 bit:1
...(ept #2 -- #15)...
msm72k_udc: ept #0 in max:64 head:ffc03040 bit:16
msm72k_udc: ept #1 in max:512 head:ffc030c0 bit:17
... (ept #2 -- #15)...
usb: notify offline
msm72k_udc: ONLINE -> OFFLINE
usb: notify offline
#

then I can see the device in file /proc/net/dev.

# ifconfig usb0 192.168.1.9 up


On PC (ubuntu) side:
$ sudo dmesg -c
$ sudo modprobe usbnet
$ ehco $?
0
Connect g1 and PC with USB cable:
$ ifconfig
eth0 .....
lo .....

NO usb0 found!
NO usb0 found!
NO usb0 found!

I tried other PCs running Linux and XP, the problem persists and it
seems that neither side can detect the USB connection.

What is wrong?

It is worth noting that the driver files (msm72k_udc.[ch] and
gadget_chips.h
are from 2.6.27) are from tree
http://android.git.kernel.org/?p=kernel/msm.git;a=tree;f=drivers;hb=android-msm-2.6.27




On Jan 10, 12:39 am, "Mike Lockwood" <lockw...@android.com> wrote:
> Sorry, I don't know anything about the tools on android-dls.com  You
> might try the g1-hack...@telesphoreo.org mailing list.
>
> Mike
>
>
>
> On Fri, Jan 9, 2009 at 6:24 AM, Xiangfeng ZHANG <mailof...@gmail.com> wrote:
> > Hi, Mike,
>
> > thank you.
>
> > I re-download the 2.6.25 kernel
> > (http://android.git.kernel.org/?p=kernel/msm.git;a=snapshot;h=refs/hea...)
> > and repeat my work, and things get much better. I can compile the kernel and
> > modules. the new source tree contains clk_*() function for mach-msm, but
> > __msm_ioremap stll missing (I copied one).
>
> > Now I want to put my new kernel to g1, and I meet new problems.
>
> > According to
> >http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_...,
> > two .pl scripts are available to help unpack/pack boot images. I packed my
> > new kernel and the original ramdisk image into a new  a boot.img. but after
> > unpacking the new image, I found my kernel size changed (300bytes longer
> > than it should be)
>
> > see below:
>
> > zxf@zxfpc-desktop:~/tmp$ ls -l boot-new/
> > -rw-r--r-- 1 zxf zxf 2504704 2009-01-09 19:19 mtd2.img
> > -rwxr-xr-x 1 zxf zxf 1273556 2009-01-09 13:57 mtd2.img-kernel.gz
> >                              (^^^^^^^^^)
> > drwxr-xr-x 2 zxf zxf    4096 2009-01-09 16:39 mtd2.img-ramdisk
> > -rw-r--r-- 1 zxf zxf 1228800 2009-01-09 14:01 mtd2.img-ramdisk.cpio.gz
> > -rwxr-xr-x 1 zxf zxf     442 2009-01-09 18:56 new-boot.sh
>
> > zxf@zxfpc-desktop:~/tmp$ ls -l boot-unpack/
> > -rw-r--r-- 1 zxf zxf 2504704 2009-01-09 19:19 mtd2.img
> > -rw-r--r-- 1 zxf zxf 1273856 2009-01-09 19:19 mtd2.img-kernel.gz
> >                              (^^^^^^^^^)
> > drwxr-xr-x 8 zxf zxf    4096 2009-01-09 19:19 mtd2.img-ramdisk
> > -rw-r--r-- 1 zxf zxf 1228800 2009-01-09 19:19 mtd2.img-ramdisk.cpio.gz
> > zxf@zxfpc-desktop:~/tmp$
>
> > Originally I did not notice this. After flash the new kernel, G1 can not
> > boot normally.  after almost two hours' check, I found the difference in
> > size.
>
> > Could you help me find what is wrong?
>
> > On Fri, Jan 9, 2009 at 12:41 AM, Mike Lockwood <lockw...@android.com> wrote:
>
> >> Right, the clk_* calls changed a bit between 2.6.25 and 2.6.27.  To
> >> see what changes you will need to backport msm72k_udc to 2.6.25, try
> >> looking at drivers/usb/function/msm_hsusb.c and comparing the 2.6.25
> >> and 2.6.27 versions of this file.
>
> >> Mike
>

Mike Lockwood

unread,
Jan 16, 2009, 10:35:20 AM1/16/09
to android-...@googlegroups.com
Hi Ronald,

I have not tried building the msm72k_udc driver as a module yet. It
could be that there are some problems related to that. Does it work
for you if you build it directly into the kernel? Also, the driver is
still under development so there could be other issues. We are not
planning on using this driver until after cupcake, and I won't have
much time to work on it until after cupcake is further along.

You might want to stick with the drivers in drivers/usb/function/ if
you have trouble with the gadget driver. I'm not entirely clear
exactly what you are trying to do. If you need USB mass storage
support, we already have that working in the stock kernel on the G1.

Mike

Xiangfeng ZHANG

unread,
Jan 18, 2009, 10:46:50 PM1/18/09
to android-...@googlegroups.com
Hi, Mike,

I must build mass storage gadget in kernel module because a few seconds later I will unload the module and load another gadget module (g_ether), and I do not need both modules at the same time. That means I will change the role of the gadget on the fly.

Now the most urgent thing for me is how to detect whether the USB cable is plugged in (for g1) and how to inform the host that the cable is plugged in.

Could you give me some guidance to set/test cable events in msm72u_udc, for g1 and for host?

thanks
--
Best regards

ronald

unread,
Feb 8, 2009, 10:27:36 PM2/8/09
to android-platform
Hi, Mike,

After a long holiday, I am now back to working on USB gadget driver.

I added the following code at the end of function
usb_gadget_register_driver() in file msm72k_udc.c:

retval = driver->bind(&ui->gadget);
+ usb_gadget_connect(&ui->gadget); //to enable pullup
+ usb_gadget_vbus_connect(&ui->gadget);
usb_start(ui);
return 0;

After re-compiling the msm72k_udc module and loading it and g_ether.ko
into kernel, I find that kernel messages in function usb_interrupt(int
irq, void *data) can be got by "dmesg" when I connect the usb cable to
my PC (running Ubuntu 7.10).
An interface usb0 can be found on the G1 side when the cable is
connected, however there is no such interface on Ubuntu side. In fact,
there is no new dmesg on Ubuntu at all.

I put more printk() in function usb_interrupt(), and I find in usb
interrupts (all triggered by connecting USB cable?), the related
values after executing "n = readl(USB_USBSTS); writel(n, USB_USBSTS);"
are always as following:

ui->running: 1;
n: 0x81;
n & STS_PCI: 0;
n & STS_URI: 0;
n & STS_SLI: 0;
n & STS_UI: 1;

however, after executing "n=readl(USB_ENDPTSETUPSTAT);" , the "n"
changes like this after connecting the usb cable:
1,1,0,1,1,0,1,0,0

I know little about the usb controller. So could you please help me
find out what is wrong with the driver? Any more detail do you need?




On Jan 19, 11:46 am, "Xiangfeng ZHANG" <mailof...@gmail.com> wrote:
> Hi, Mike,
>
> I must build mass storage gadget in kernel module because a few seconds
> later I will unload the module and load another gadget module (g_ether), and
> I do not need both modules at the same time. That means I will change the
> role of the gadget on the fly.
>
> Now the most urgent thing for me is how to detect whether the USB cable is
> plugged in (for g1) and how to inform the host that the cable is plugged in.
>
> Could you give me some guidance to set/test cable events in msm72u_udc, for
> g1 and for host?
>
> thanks
>
> On Fri, Jan 16, 2009 at 11:35 PM, Mike Lockwood <lockw...@android.com>wrote:
>
>
>
>
>
> > Hi Ronald,
>
> > I have not tried building the msm72k_udc driver as a module yet.  It
> > could be that there are some problems related to that.  Does it work
> > for you if you build it directly into the kernel?  Also, the driver is
> > still under development so there could be other issues.  We are not
> > planning on using this driver until after cupcake, and I won't have
> > much time to work on it until after cupcake is further along.
>
> > You might want to stick with the drivers in drivers/usb/function/ if
> > you have trouble with the gadget driver.   I'm not entirely clear
> > exactly what you are trying to do.  If you need USB mass storage
> > support, we already have that working in the stock kernel on the G1.
>
> > Mike
>
> > On Thu, Jan 15, 2009 at 8:24 PM, ronald <mailof...@gmail.com> wrote:
>
> > > Hi, Mike,
>
> > > I make some progress, and new problem appears.
>
> > > After re-checking the source tree (
>
> >http://android.git.kernel.org/?p=kernel/msm.git;a=snapshot;h=refs/hea...
> > ),
> >http://android.git.kernel.org/?p=kernel/msm.git;a=tree;f=drivers;hb=a...
Reply all
Reply to author
Forward
0 new messages