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 http://gitorious.org/angstrom/angstrom-linux and check out the "beagleboardXM" branch. The commit id that I have used in this tutorial is "12ca45fea91cfbb09df828bea958b47348caee6d"

$git clone git://gitorious.org/angstrom/angstrom-linux.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 http://gitorious.org/angstrom/angstrom-linux/commits/beagleboardXM on the right column "Download beagleboardXM as tar.gz"

$wget http://gitorious.org/angstrom/angstrom-linux/archive-tarball/beagleboardXM
$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 http://elinux.org/BeagleBoard/SPI/Patch-2.6.37. 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
http://beagleboard.org/static/BBxMSRM_latest.pdf.

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.

/dev/spidev3.0
/dev/spidev3.1
/dev/spidev4.0

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 :
http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat

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

2. Now download the following files from http://www.angstrom-distribution.org/demo/beagleboard/ 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)

- MLO
- 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 http://www.angstrom-distribution.org/demo/beagleboard/. 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 http://www.angstrom-distribution.org/narcissus/. 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 http://rcn-ee.net/

1. Download the debian demo image
$wget http://rcn-ee.net/deb/rootfs/unstable/unstable-minimal-armhf-omap-2011-08-11.tar.xz

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 ./setup_sdcard.sh --mmc /dev/sdX --uboot beagle_bx

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

Panda :
sudo ./setup_sdcard.sh --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 : http://elinux.org/BeagleBoardDebian#Debian_armhf_port

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://git.angstrom-distribution.org/setup-scripts
$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.
./oebb.sh 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 :
http://www.angstrom-distribution.org/building-angstrom

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 kernel.org 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 kernel.org
$wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.3.tar.bz2
$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 :
linux-headers-3.0.3-custom_3.0.3-custom-10.00.Custom_i386.deb
linux-image-3.0.3-custom_3.0.3-custom-10.00.Custom_i386.deb

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

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 :
http://www.howtoforge.com/kernel_compilation_ubuntu