Building Gadget USB Module
From Openmoko
General Comments
The guide is currently valid for Debian-based distros. Feel free to add instructions for others as well.
You will most likely need kernel version 2.6.20 or higher.
Debian GNU/Linux Lenny and Ubuntu Feisty Fawn 7.04
To prepare your environment run the following:
sudo apt-get install linux-source linux-headers-`uname -r`
Create and enter working dir (e.g. ~/gadgetfs)
mkdir $WD cd $WD
Uncompress the kernel source (pick one and adjust the minor version number):
tar xfz /usr/src/linux-source-2.6.##.tar.gz tar xfj /usr/src/linux-source-2.6.##.tar.bz2
Note: This will place the source in the current working directory.
Then run the following:
mkdir usb_module_dir cd usb_module_dir cp -r ../linux-source-2.6.##/drivers/usb/* . cd gadget echo "KDIR := /lib/modules/`uname -r`/build" >> Makefile echo "PWD := `pwd`" >> Makefile echo "obj-m := dummy_hcd.o gadgetfs.o" >> Makefile echo "default: " >> Makefile echo -e "\t\$(MAKE) -C \$(KDIR) SUBDIRS=\$(PWD) modules" >> Makefile make
If everything went fine you will find dummy_hcd.ko and gadgetfs.o along with other files in the current directory. Load the modules whenever you need them by issuing
sudo insmod ./dummy_hcd.ko sudo insmod ./gadgetfs.ko default_uid=`id -u`
If you get the following error (happens for example on Ubunutu 8.04 - 2.6.24-19-generic)
insmod: error inserting './dummy_hcd.ko': -1 Invalid module format
try to unload the net2280 module, because it might blocking the dummy_hcd.ko module
sudo rmmod net2280
after that try it again
sudo insmod ./dummy_hcd.ko sudo insmod ./gadgetfs.ko default_uid=`id -u`
Debian/Ubuntu - full kernel recompilation using make-kpkg
Gain root priviledges
sudo su -
Prepare your environment by installing some packages:
apt-get install kernel-package linux-source libncurses5-dev
Optionally, edit /etc/kernel-pkg.conf and fill in email and maintener fields.
Untar the kernel sources, and enter them
tar -C /usr/src -xjf /usr/src/linux-source-2.6.##.tar.bz2 cd /usr/src/linux-source.2.6.##
Prepare your kernel tree: copy the current kernel configuration and start kernel configuration
cp /boot/config-`uname -r` .config make menuconfig
Find and enable all the necessary modules by following these instructions.
It's now time to compile your kernel. Type:
make-kpkg -us -uc --initrd kernel_image kernel_headers
If all goes well, install your freshly created kernel:
dpkg -i /usr/src/linux-{image,headers}-VERSION_XXXXX_ARCH.deb
Update the boot loader configuration if necessary, and reboot using the created kernel.
NOTE: Before installing the kernel, you should also prepare the firmware directory by creating a link to the current kernel firmware directory:
ln -s /lib/firmware/`uname -r` /lib/firmware/VERSION
where VERSION is the full version of the created kernel (e.g. 2.6.20.3-ubuntu1)
This is a hack, but works for me.