Building Gadget USB Module

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(Ubuntu Feisty 7.0.4)
m (Category: -Software (non-openmoko), +Debian)
 
(26 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 +
{{Todo|Please add a description of what this is.}}
 +
 
== General Comments ==
 
== General Comments ==
You will most likely need kernel version 2.6.20 or higher
 
  
== Ubuntu Feisty 7.0.4 ==
+
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 / Hardy 8.04 ==
 
To prepare your environment run the following:
 
To prepare your environment run the following:
<pre>
+
sudo apt-get install linux-source linux-headers-`uname -r`
sudo apt-get install linux-kernel-source linux-kernel-headers
+
 
</pre>
+
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 [[Openmoko_under_QEMU#Setting_up_USB_connection|these instructions]].
 +
 
 +
It's now time to compile your kernel. Type:
 +
  make-kpkg -us -uc --initrd kernel_image kernel_headers
  
Uncompress /usr/src/linux-source-2.6.##.tar.gz, link it to /usr/src/linux, and ensure /lib/modules/`uname -r`/build exists, then run the following:
+
If all goes well, install your freshly created kernel:
<pre>
+
  dpkg -i /usr/src/linux-{image,headers}-VERSION_XXXXX_ARCH.deb
mkdir usb_module_dir
+
cd usb_module_dir
+
cp -r /usr/src/linux/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
+
</pre>
+
  
Once the kernel modules ( dummy_hcd.ko and gadgetfs.ko ) are built, you must remove (or move) the gadgetfs and net2280 as follows:
+
Update the boot loader configuration if necessary, and reboot using the created kernel.
<pre>
+
sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/gadget/net2280.ko ./original_net2280.ko
+
sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/gadget/gadget.ko ./original_gadgetfs.ko
+
</pre>
+
  
and replace them with the new modules:
+
''NOTE'': Before installing the kernel, you should also prepare the firmware directory by creating a link to the current kernel firmware directory:
<pre>
+
  ln -s /lib/firmware/`uname -r` /lib/firmware/VERSION
sudo cp dummy_hcd.ko and gadgetfs.ko /lib/modules/`uname -r`/kernel/drivers/usb/gadget/
+
where VERSION is the full version of the created kernel (e.g. 2.6.20.3-ubuntu1)
sudo depmod
+
</pre>
+
  
The net2280 module provides conflicting symbols and causes interference with the dummy_hcd module.
+
This is a hack, but works for me.
 +
[[Category:Debian]]

Latest revision as of 20:58, 14 September 2008

TODO: Please add a description of what this is. (See: To-Do List)

[edit] 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.

[edit] Debian GNU/Linux Lenny and Ubuntu Feisty Fawn 7.04 / Hardy 8.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`

[edit] 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.

Personal tools

General Comments

You will most likely need kernel version 2.6.20 or higher

Ubuntu Feisty 7.0.4

To prepare your environment run the following:

sudo apt-get install linux-kernel-source linux-kernel-headers

Uncompress /usr/src/linux-source-2.6.##.tar.gz, link it to /usr/src/linux, and ensure /lib/modules/`uname -r`/build exists, then run the following:

mkdir usb_module_dir
cd usb_module_dir
cp -r /usr/src/linux/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

Once the kernel modules ( dummy_hcd.ko and gadgetfs.ko ) are built, you must remove (or move) the gadgetfs and net2280 as follows:

sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/gadget/net2280.ko ./original_net2280.ko
sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/gadget/gadget.ko ./original_gadgetfs.ko

and replace them with the new modules:

sudo cp dummy_hcd.ko and gadgetfs.ko /lib/modules/`uname -r`/kernel/drivers/usb/gadget/
sudo depmod

The net2280 module provides conflicting symbols and causes interference with the dummy_hcd module.