Wednesday, October 28, 2009

How to make your N810 Internet Tablet recognizes an USB webcam and take pictures by flashing a new kernel image

This post will demonstrate how to make N810 recognizes an USB webcam and take pictures by flashing a new kernel image on device.

The equipments you need to execute this demonstration are follow:
  • A laptop or desktop computer
  • A N810 Internet Tablet
  • An UVC webcam: Logitech Quickcam Pro 9000
  • A self-powered USB hub

Download (clone) and compile kernel

In your computer (laptop or desktop), download (clone) linux-omap kernel tree to your desired directory:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git

Change to linux-omap-2.6 directory:


$ cd linux-omap-2.6

For this experiment, it's necessary to change to a specific commit:


$ git checkout 58cf2f1425abfd3a449f9fe985e48be2d2555022


This branch is related to v2.6.29-omap1 which it's possible to compile a bootable kernel image to N810. So, let's create a local development branch:

$ git checkout -b v2.6.29-omap1

Load N810 defconfig file:

$ make n800_defconfig


And before compile the kernel image, it's necessary to make some changes on defconfig, using:

$ make menuconfig

These changes are related to USB Gadget, Filesystem and UVC camera driver. DMA must be disabled in USB driver. In host mode DMA is not very usable, it's one transfer per packet. Find below the changes:

Device Drivers --->
Multimedia devices --->
[*] Video capture adapters --->
[*] V4L USB devices --->
<> USB Video Class (UVC)
[*] UVC input events device support

Device Drivers --->
[*] USB support --->
<*> USB Gadget Support --->
<*> USB Gadget Drivers (Ethernet Gadget (with CDC Ethernet support)) --->
(X) Ethernet Gadget (with CDC Ethernet support)

Device Drivers --->
[*] USB support --->
<*> Disable DMA (always use PIO)

File systems --->
<*> Second extended fs support
<*> Ext3 journalling file system support


It's necessary to install in your computer a cross-compiler. For this demonstration, I'm using the CodeSourcery cross-compiler, release 2007q3-53.

To compile the image and modules:


$ make zImage
$ make modules


The zImage can be found at arch/arm/boot/. The UVC camera driver module can be found at drivers/media/video/uvc/uvcvideo.ko. This module must be copied to the module kernel source directory structure of your N810 device.

Flashing the new kernel

To flash the new kernel in your device, you must use the flasher tool.

For this development purposes, some flasher options must be enabled:


# flasher --enable-rd-mode --set-rd-flags=no-omap-wd,no-lifeguard-reset


R&D mode was enabled in order to be able to use gainroot.

Flash the new kernel:


# flasher -k /location/of/your/kernel/arch/arm/boot/zImage -f -R

Activate host mode on N810

In your N810 device, activate host mode on N810. On device, start 'X terminal' application on Utilities menu and type:

$ sudo gainroot
# echo host > /sys/devices/platform/musb_hdrc/mode


Loading UVC camera module

Copy the UVC camera module from your memory card to the module kernel source directory structure:

# cp /media/mmc1/uvcvideo.ko /mnt/initfs/lib/modules/2.6.21-omap1/

And load the module with insmod utility:

# cd /mnt/initfs/lib/modules/2.6.21-omap1/
# insmod uvcvideo.ko


So, just connect the USB hub to your N810 and then connect the Logitech Quickcam to the USB hub.

The camera will be recognized and a new entry - /dev/video1 - related to this camera device is created. /dev/video1 it's a V4L2 device capable of video/streaming capture and supports MJPEG and YUV 4:2:2 (YUYV) formats.


Taking pictures from command line on N810

To take pictures from command line on N810, we can use gstreamer or uvccapture.

* Gstreamer

Using Gstreamer, it's necessary to install the packages gstreamer0.10-tools and gstreamer0.10-plugins-extra (from extras repository). gstreamer0.10-tools is a package of command-line tools to use Gstreamer.

On device, start 'X terminal' application on Utilities menu and type:


$ sudo gainroot
# apt-get install gstreamer0.10-tools gstreamer0.10-plugins-extra


Now, you can take a picture with:

# gst-launch-0.10 v4l2src device=/dev/video1 num-buffers=1 ! video/x-raw-yuv,width=352,height=288,framerate=10/1 ! ffmpegcolorspace ! jpegenc ! filesink location=/home/user/MyDocs/.images/file.jpg

With gstreamer, it's possible to take pictures without problems with resolutions up to 352x288.

* uvccapture

uvccapture is a command-line application to UVC cameras.


# ./uvccapture -x960 -y720 -d/dev/video1 -o/home/user/MyDocs/.images/file.jpg


Using uvccapture, it's possible to take pictures with resolutions up to 960x720.

Revert Changes

If you want to revert the changes applied:

# flasher -F FIASCO_IMAGE --flash-only kernel -f -R

You can download the FIASCO image (N810 OS image) to reflash your tablet here.

Known Issues

Find below some issues related to this demonstration:
  • Unfortunately, WLAN is not working for this kernel version (in fact for any recent omap kernel version). Looks like currently there's no way to compile firmware for it against the current kernels.
  • But for this kernel version, MMC (internal and external) card does work :) That's why I'm using it to transfer files from computer to device.
  • Last, but not least, for this kernel version, some keys on keyboard are no working. Actually, this problem was already solved and on the next post I'll explain how to fix it.
Some References

2 comments:

Antonio said...

coool stuff

Rodrigo Souza said...

That's cool! I don’t know too much about open source devel. but my wife does. My name's Rodrigo Augusto Aguiar de Souza and I'm from MAO-AM. So I wanna ask you if this name sounds familiar...
pls contact me. rodrigoa8@gmail.com.