Monday, December 12, 2011

Rooting Android and running Debian on a VIA WM8650

A really cheap Chinese made Android tablet available in local market for Indian Rupees 4000 rooted with Uberoid MOD and running debian in chroot.

Friday, October 7, 2011

Enabling SPI on Beagleboard xM

This is a short tutorial on enabling SPI on Beagleboard xM.

Background : SPI (Serial Perhiperal Interface) is a general-purpose digital I/O interface. SPI bus consists of at least three pins:
- Clock signal
- Slave-input/master-output (SIMO) pin
- Slave-output/master-input (SOMI) pin
- Zero or more chip-select (CS) pins.

The Beagleboard xM has four McSPI controllers out of which only SPI-3 and SPI-4 are bought out on the board. Each is capable of driving an SPI interface at up to 48 MHz.

- McSPI1: 4 channels
- McSPI2: 2 channels
- McSPI3: 3 channels (2 chip select brought out)
- McSPI4: 1 channel (1 chip select brought out)

Pre-requisite :

1. You have installed Angstrom Linux on the board. The current kernel version is 2.6.32.

2. You are using Ubuntu on the development machine. If you are using something else then the commands and package names might change. The development machine is the one on which you are doing all the development usually a x86 based system, also called as host machine. The target machine is the Beagleboard xM.

3. You need to install the ARM gcc cross-compiler on the development machine. In Ubuntu, you can do
$sudo apt-get install gcc-arm-linux-gnueabi

4. Also you will need git.
$sudo apt-get install git

Steps :

1. Download the Angstrom Linux kernel sources from and check out the "beagleboardXM" branch. The commit id that I have used in this tutorial is "12ca45fea91cfbb09df828bea958b47348caee6d"

$git clone git://
$cd angstrom-linux
$git checkout 12ca45fea91cfbb09df828bea958b47348caee6d
$git checkout -b spi

Alternatively, you can download the tar.gz file without the git history. The download link is available on on the right column "Download beagleboardXM as tar.gz"

$tar -zxvf angstrom-angstrom-linux-beagleboardXM.tar.gz

2. The SPI signals coming out of the SOC are multiplex with other signals. So, you need to set the pin multiplexer properly. There are two ways to do this, one is by setting it in the u-boot and another way is to set it in the kernel. The kernel settings will override the u-boot settings. In this guide I have not changed the u-boot, it is the default one that is available in the Angstrom demo. I have change the pin multiplexer in the kernel sources in the board file.

$gedit arch/arm/mach-omap2/board-omap3beagle.c

Add the following lines as per this patch If you not able to apply the patch you need to make the modifications manually.

Note : Always set the clock for SPI-3 & SPI-4 in input mode as :
omap_mux_init_signal("sdmmc2_clk.mcspi3_clk", OMAP_PIN_INPUT);
omap_mux_init_signal("mcbsp1_clkr.mcspi4_clk", OMAP_PIN_INPUT);

This will set the correct pin multiplexing mode and also register the SPI buses with the kernel.

3. Compile the kernel for Beagleboard

$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- mrproper
$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- omap3_beagle_defconfig
$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig

Enable the SPI related driver and make sure to compiled them directly into kernel and NOT as module.

Device Drivers > SPI Support > Debug support for SPI drivers
Device Drivers > SPI Support > McSPI driver for OMAP24xx/OMAP34xx
Device Drivers > SPI Support > User mode SPI device driver support

Save the configuration and finally compile the new kernel

$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage

4. For testing, compile the SPI test program available in kernel sources at "Documentation/spi/spidev_test.c" and save the binary output as "spitest"

$arm-linux-gnueabi-gcc Documentation/spi/spidev_test.c -o spitest

Also you need to short the SPI-4 SIMO and SOMI pins of the expansion header on the Beagleboard so that whatever data is sent the same is received back. These details are available in the ref. manual of Beagleboard

Note :
Refer page no. 107 - Figure 51 - Main Expansion Header Processor Connections
Refer page no. 108 - Table 22 - Expansion Connector Signals

You need to SHORT the PIN NO. 12 and 18 for SPI-4 of the expansion header on the Beagleboard. When you run the above test program whatever data is sent on input pins will be received back on the output pins.

5. Final step is to copy the "uImage" generated in the Step 3 and the "spitest" generated
in the Step 4 to the Beagleboard SD-Card. The "uImage" is copied to the "/boot" directory and "spitest" program is copied to the main "/" of the "ext3" partition. On booting the Beagleboard and you will get the following device files in the /dev directory. Whatever you read and write to these files in sent to the SPI pins.


Run the test program for SPI-4 and you will see the same input as output.

$./spitest -D /dev/spidev4.0

If you do not see the device files then check whether you have correctly enable the SPI drivers in the kernel in Step 3.

Thursday, September 15, 2011

Beagleboard + Angstrom Demo image

1. First thing that you need to do is partition the SD Card on your development machine as per the guide given below :

Once done with partitioning please remove and reinsert the SD Card in the development machine.

2. Now download the following files from and copy them to the first partition (FAT32) of the SD Card (Please note to first copy the MLO file before anything else, since this file needs to be in the first sector of the partition)

- u-boot.bin
- x-load.bin.ift

3. Now donwload the Angstrom-Beagleboard-demo-image-glibc-ipk-2011.1-beagleboard.rootfs.tar.bz2 or whatever is the latest version from This is the root filesystem for the device. You need to extract it to the second partition (ext3) of the SD Card.

Alternatively you can generate the root filesystem from Select "beagleboard" as machine type, also it is recommended for first timers to choose complexity as "simple" and environment as "console", later on you can select more advance options.

$sudo tar -C /media/second-ext3-partition -jxvf Angstrom-Beagleboard-demo-image-glibc-ipk-2011.1-beagleboard.rootfs.tar.bz2

Note: Please remember to change the path of the second partition (ext3) as per your setup and also the root-fs filename in the above command.

4. Unmount both the partition of the SD Card and insert it into the beagleboard.

$sudo sync
$sudo umount /media/first-partition
$sudo umount /media/second-partition

Monday, September 12, 2011

Beagleboard + Debian

We are going to use the demo image as available on

1. Download the debian demo image

2. Verify the image
$md5sum unstable-minimal-armhf-omap-2011-08-11.tar.xz
7020abf7c80e8e75eb54ba214ed9c849  unstable-minimal-armhf-omap-2011-08-11.tar.xz

2. Extract the image
tar xJf unstable-minimal-armhf-omap-2011-08-11.tar.xz
cd unstable-minimal-armhf-omap-2011-08-11

3. Install the image

Beagle Bx :
sudo ./ --mmc /dev/sdX --uboot beagle_bx

Beagle Cx, xM A/B/C :
sudo ./ --mmc /dev/sdX --uboot beagle

Panda :
sudo ./ --mmc /dev/sdX --uboot panda

Note: Replace the /dev/sdX with the sd card device name in the above commands

3. Insert the sd card into the beagleboard and reboot it, you will have debian running on the board.

The login details are :

username : root
password : root

username : debian
password : temppwd

4. To setup the network configuration, login as root and edit the /etc/network/interfaces and /etc/resolv.conf (please note that for Beagleboard xM the network device is eth0)

Link :

Sunday, August 28, 2011

Custom OpenEmbedded distribution based on Angstrom

Angstrom distribution is similar to Ubuntu or Fedora but it is specifically meant for embedded devices. Angstrom uses the OpenEmbedded system to build their distributions.

If you want a ready made image for your embedded device you can use their online builder available here.

I recently faced a situation where I had to enable SPI driver in Angstrom distribution for beagleboard. For that I had to custom compile the Linux kernel with the McSPI module enabled since it was not enabled in the default builds.

Step 1:

Create a folder in your home directory called "openembedded"
$mkdir ~/openembedded
$cd ~/openembedded

Step 2:

Download the setup scripts for Angstrom using git
$git clone git://
$cd setup-scripts

Step 3:

Start the build process for beagleboard. This will download the "bitbake" which is only a tool used to build packages and "openembedded" system which provides the "recipes" of the packages for the "bitbake" tool.
./ config beagleboard
Note: Replace beagleboard with your embedded machine name. Also note that "openembedded" git download is more than 700 MB.

Step 4:

Load the script file created in the previous step. You need to do this everytime you want to build packages from a new terminal, or you can add this line to the ~/.bashrc file
$source ~/.oe/environment-2008

Step 5:

Build your first package the famous "nano" command line editor
$bitbake nano

Now, the real thing is to build the kernel image from source
$bitbake virtual/kernel

Links :

Tuesday, August 23, 2011

Compiling Linux kernel for any CPU architecture

You can compile Linux kernel for any architecture including x86/arm/sparc/mpis etc. Inside the "arch" directory of the root kernel source tree you will find the list of the architectures supported by Linux.

For example to configure the Linux kernel for the "arm" architecture, from the root directory of the linux kernel sources tree do

$make menuconfig ARCH=arm

Note the ARCH=arm parameter in the above command. This will bring up the kernel configuration for the "arm" architecture. Similarly be replacing the ARCH parameter with name of architecture from the "arch" folder you can configure the kernel for that particular architecture.

Another example, for the "mips" architecture you can do

$make menuconfig ARCH=mips

Monday, August 22, 2011

Compiling vanilla Linux kernel in Ubuntu

This article describes how to compile a kernel downloaded from in Ubuntu. We are going to compile the latest kernel as on today which is linux-3.0.3. Lets get started...

1. Pre-requisites: Install the following packages
$sudo apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

2. Create a directory in your home directory for compilation (it is not recommended to this work inside /usr/src)
$mkdir ~/linux-kernel
$cd ~/linux-kernel

3. Download and extract the linux kernel sources from
$tar jxvf linux-3.0.3.tar.bz2
$cd linux-3.0.3
Note : You can apply any kernel patches at this stage if you want. We will skip this step.

4. Configure the kernel as per your requirements. There are many ways to do this, but the recommended method is to use your current configuration to start from.
$cp /boot/config-`uname -r` ./.config
You need to update your old configuration and bring it to the current kernel source structure.
$make oldconfig
It will ask a few questions which relate to updates that are made in the kernel sources. If you dont know just press "ENTER" to select the default options.

Now, you can customize the kernel configuration as per your requirements by doing
$make menuconfig
This will open up a ncurse based kernel configuration tool. When you are done, save and exit.

5. Build the kernel
$make-kpkg clean
$fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers 
Here you can specify your own version string by changing the "--append-to-version=" option in the previous command. Your string MUST always start with a "-". In our case it is "-custom" so the kernel will be called "3.0.3-custom"

It will take some time to build the kernel, so have a cup of coffee till then :)

6. Once the kernel has been compiled there will be two .deb packages in the parent directory. In our case they are :

Go back to the parent directory and list the files to locate the two .deb packages
$cd ..

7. The final step is to install the new kernel by using "dpkg" command. You need to be sudo to install the packages.
$sudo dpkg -i linux-image-3.0.3-custom_3.0.3-custom-10.00.Custom_i386.deb
$sudo dpkg -i linux-headers-3.0.3-custom_3.0.3-custom-10.00.Custom_i386.deb

This will also automatically copy the kernel and initrd images to /boot, copy the modules to /lib/modules and also add a entry in the GRUB boot loader. Now you are ready to boot into your new kernel ! Just restart the machine and select the new kernel from the GRUB menu. If there is any problem with booting you can go back to the old kernel which is still there in the GRUB menu list.

8. Once you have booted into the new kernel, you can verify the kernel version by
$uname -r

Also as a bonus you can use that deb file generated - in any other Ubuntu machine for installing the new kernel.

Note : You can also use the -j option to specify the number of threads to use to compile the kernel.
$fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers -j 3
Links :

Friday, August 19, 2011

How to install ARM Debian on Ubuntu using Qemu

1. Install the "qemu" and "qemu-system" packages

$sudo apt-get install qemu qemu-system

2. Download the debian initrd and kernel image for ARM


3. Create a 10 GB disk image to be used as harddisk

$qemu-img create -f raw armdisk.raw 10G

4. Start qemu

$qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-2-versatile -initrd initrd.gz -hda armdisk.raw -append "root=/dev/ram" -m 256 

This will start the debian installer for ARM platform.

At the end of installation you will get a error message that boot loader cannot be installed - just ignore it.

5. Once it has finished installing next step is to copy the vmlinuz and initrd from the installed debian system for booting.

Create a mount point:
$sudo mkdir /mnt/armdeb

Mount the harddisk image:
$sudo mount -o loop,offset=32256 armdisk.raw /mnt/armdeb

Copy the kernel and initrd image:
cp /mnt/armdeb/boot/vmlinuz-2.6.26-2-versatile .
cp /mnt/armdeb/boot/initrd.img-2.6.26-2-versatile .

Unmount the harddisk image:
$sudo umount /mnt/armdeb

6. Finally boot into the newly installed ARM debian system:
$qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-2-versatile -initrd initrd.img-2.6.26-2-versatile -hda armdisk.raw -append "root=/dev/sda1"

Monday, August 15, 2011

Build your own cross compilation tool chain in Linux

This article describes how to setup your machine to cross compile programs for some other architecture. This involves setting up is called as a "cross compile tool chain". We are going to use crosstool-ng for this purpose. It is a collection of scripts that will download, compile, install the entire tool chain required for cross compiling. We will create a "ARM" based tool chain in this example.

We will be installing the toolchain in the "cctools" directory inside our home folder. Also note that all commands are run as normal user unless otherwise mentioned. Let us create the directory for the same.

$mkdir $HOME/cctools
$cd $HOME/cctools

Now, go to and download and extract the stable version of the script.

$tar jxvf crosstool-ng-1.12.0.tar.bz2
$cd crosstool-ng-1.12.0

You also need to install the following packages (run as root):
$sudo apt-get install libtool automake texinfo flex bison subversion cvs expat libexpat1-dev python-dev libncurses5-dev

Once this is done, we will create a separate build directory.
$mkdir $HOME/cctools/build

Now, let us configure crosstool-ng to build in that directory.
$./configure --prefix=$HOME/cctools/build

Compile and install crosstool-ng.
$make install
This will install crosstool-ng inside the build directory that we specified. We need to add this build directory to the PATH shell variable.
$export PATH="${PATH}:$HOME/cctools/build/bin"
This has completed the installation of the crosstool-ng.
(Note : You can add this to your ~/.bashrc file for future use)

Next step is to setup the system for cross compilation. We will create a separate directory for the "ARM" tool chain.
$mkdir $HOME/cctools/arm
$cd $HOME/cctools/arm

Now run the crosstool-ng configuration script in this directory.
$ct-ng menuconfig

This will show you a menu driven interface for selecting the target architecture, path for download and installation of the tool chains, architecture specific optimization and features, etc. In this configuration window change the relevant options for "ARM" based tool chain.

You can directly copy a predefined configuration file for the architecture from the $HOME/cctools/crosstool-ng-1.12.0/samples folder and then run the above "$ct-ng menuconfig" tool.

eg :
$cp $HOME/cctools/crosstool-ng-1.12.0/samples/arm-cortex_a8-linux-gnueabi/crosstool.config .config

Also you need to change the prefix directory where you want the tool chain installed. We will build it inside the build directory where we initially installed the crosstool-ng.
Paths and misc options > Prefix directory : ${HOME}/cctools/build/${CT_TARGET}

Once this is done press "ESCAPE" and save the configuration file. The file is saved as ".config", you can even hand edit this file directly if you want.

Now the final step is download, extract and build the tool chain. All of this is done automatically by the crosstool-ng by executing:
$ct-ng build
It downloads around 200MB source files and takes around 1 hour on a "3 Ghz dual core with 4 GB RAM" machine for compilation. The source files are downloaded in the ".build" directory. Once this completes the tool chain is available in the ${HOME}/cctools/build/ directory, the folder name is dependent of the architecture selected. You can add this to the PATH shell variable.
$export PATH="${PATH}:$HOME/cctools/build/arm-cortex_a8-linux-gnueabi/bin"
(Note : You can add this to your ~/.bashrc file for future use)

Let us cross-compile one sample "Hello World" C program that will execute on a "ARM" machine. The C program filename is "sample.c"
$arm-cortex_a8-linux-gnueabi-gcc sample.c -o sample -Wall
This will compile the executable file "sample" for the "ARM" architecture.

Sunday, July 24, 2011

Building the Real Time Linux Kernel

We are going to use the linux-3.0.0 kernel and Ubuntu/Debian based system in this example.

1. Download the linux-3.0.0 kernel sources from

2. Extract the kernel sources in the current directory (around 530 MB)
$tar jxvf linux-3.0.tar.bz2

3. Install the quilt tool using apt-get or synaptic
$sudo apt-get install quilt

4. Download the quilt based patches for the Real Time Linux from

5. Extract the RT kernel patches in the "patches" directory in the Linux kernel source tree. Please make sure the quilt patches are present in the "patches" directory inside the root of the Linux kernel source tree that we extracted in the above step 2.
$cd linux-3.0
$tar jxvf ../patches-3.0-rt3.tar.bz2

6. Now its time to apply the patches using quilt. Run the quilt tool from inside the root of the Linux kernel source tree.
$quilt push -a
The -a option will apply all the patches from the "patches" directory automatically. You can navigate inside the "patches" directory to see the list of all the patches and also use "quilt pop" to remove a particular patch.

This step should not show any errors. If all the patches applies correctly you can proceed to the next step.

7. Configure the real time kernel options in the kernel configuration.
$make menuconfig

Inside the "Processor type and features" you will get a item for "Preemption Model (current option that is selected)". Inside that you will have two options
1. Preemptible Kernel (Basic RT)
2. Fully Preemptible Kernel (RT)
Select the second option.

Now go ahead and compile your Real Time Patched Linux kernel...

Links :

Sunday, June 26, 2011

Linux kenel make options

There are various make options for configuring the Linux kernel compilation

1. "make config" - Simple plain text interface. It is hard to use and requires you to go through each and every option manually. Not recommended.

2. "make menuconfig" - ncurse based text based interface with color menus, radiolists & dialogs. It needs the ncurse package to be installed in the system. Highly recommended. There are different variation of it that run on X based interface :
a. "make xconfig" - Qt (X windows) based configuration tool.
b. "make gconfig" - GTK (X windows) based configuration tool.

3. "make nconfig" - similar to "make menuconfig" above but a better text based color menus.

4. "make oldconfig" - Default all questions based on the contents of your existing ./.config file and asking about new config symbols. You need to copy your old kernel .config file to the current location.

5. "make silentoldconfig"- Like above, but avoids cluttering the screen with questions already answered. Additionally updates the dependencies.

6. "make defconfig" - Create a ./.config file by using the default symbol values from either arch/$ARCH/defconfig or arch/$ARCH/configs/${PLATFORM}_defconfig, depending on the architecture.

7. "make ${PLATFORM}_defconfig" - Create a ./.config file by using the default symbol values from arch/$ARCH/configs/${PLATFORM}_defconfig. Use "make help" to get a list of all available
platforms of your architecture.

8. "make localmodconfig" - Runs "lsmod" to find all the modules loaded on the current running system. Reads all the Makefiles to locate which CONFIG enables a module. Reads the Kconfig files to find the dependencies and selects that is needed to support a CONFIG. Finally, reads the .config file and removes any module "=m" that is not needed to enable the currently loaded modules.

9. "make allyesconfig" - Create a ./.config file by setting symbol values to 'y' as much as possible.

10. "make allmodconfig" - Create a ./.config file by setting symbol values to 'm' as much as possible.

11. "make allnoconfig" - Create a ./.config file by setting symbol values to 'n' as much as possible.

12. "make randconfig" - Create a ./.config file by setting symbol values to random values.

More information is available in the ./README file of the kernel source tree.

Friday, June 24, 2011

Make only specific kernel modules

1. You need to first create the .config file by running any of the various "make config" commands
$make menuconfig

2. Then run the "make" command to build the basic kernel tree

3. Now to build the specific kernel module you can do

$make modules SUBDIRS=drivers/staging

Wednesday, June 1, 2011

Customize compiling the Linux kernel

There are various ways to customize the Linux kernel compilation to make it more interesting and fun :

1. You can use a tool called "colormake" to show the output of make in a much more readable format.

2. "$make -s" wont print any commands (as if every command was prefixed by @). If the commands themselves are printing output, redirect standard output to /dev/null but still show the standard error by using "$make -s > /dev/null"

More information on various gcc options is available here

Friday, April 22, 2011

Compiling comedi sample programs

First thing you will have to do is install the "comedi" library. Under Ubuntu the package name is "libcomedi0" and "libcomedi-dev". Both packages are available in the Ubuntu "universe" repository.

Once you have the comedi library installed, the command to compile comedi programs using gcc/linux is

$gcc -Wall -O2 <program_name>.c -lcomedi -lm

Sample program :

#include <stdio.h>   /* for printf() */
#include <comedilib.h>
int subdev = 0;         /* change this to your input subdevice */
int chan = 0;           /* change this to your channel */
int range = 0;          /* more on this later */
int aref = AREF_GROUND; /* more on this later */

int main(int argc,char *argv[])
  comedi_t *it;
  lsampl_t data;
  comedi_data_read(it,subdev,chan,range,aref, & data);
  return 0;

Monday, April 11, 2011

Develop against linux-next

First thing is to download the git tree for linux-next

$git clone git://

To follow changes to the linux-tree tree you need to first do a remote update (this will get all the changes from the remote linux-next branch to the local origin/master tracking branch) and then reset the HEAD pointer of current checked out branch to the HEAD of linux-next remote tracking branch (i.e origin/master).

$git remote update
$git reset --hard origin/master

This will make your current branch (master) *exactly* like the remote linux-next tree. You cannot do pull or merge from the remote tracking branch.

Links :