Sunday, April 15, 2012

Perf tool

Perf is a performance monitoring tool for Linux kernel available under "tools/perf". Install it on ubuntu :

$sudo apt-get install linux-tools-common linux-tools

More information is available at :

https://perf.wiki.kernel.org/
https://perf.wiki.kernel.org/articles/t/u/t/Tutorial.html
http://vger.kernel.org/~acme/perf/lk2010-perf-paper.pdf

Thursday, March 22, 2012

Distributed Kernel Compilation in Ubuntu

We are going to use "distcc" which is a distributed C/C++ compiler.

1. We have one host machine (Machine A) on which we have downloaded the latest linux kernel sources. The IP address of this machine is 10.1.1.1

We have one more machine (Machine B) which we are going to run the distributed compiler. The IP address of this machine is 10.1.1.2

Both the machines are running Ubuntu.

2. On Machine A do the following :

Install distcc :
$sudo apt-get install distcc

Add entry for Machine B in the '/etc/distcc/hosts' file. Comment out '+zeroconf' as given below since we are not going to use it :
# Add a list of hostnames in one line, seperated by spaces, here.
# +zeroconf
10.1.1.2

Check if the host is added :
$distcc --show-hosts

3. On Machine B do the following :

Install distcc :
$sudo apt-get install distcc

Edit the '/etc/default/distcc' file and set the following parameters :
STARTDISTCC="true"
ALLOWEDNETS="127.0.0.1 10.1.1.1/24"
LISTENER="10.1.1.2"
ZEROCONF="false"

Start the "distcc" service :
$sudo service distcc start

Now we are ready to start the distributed kernel compilation.

4. Download the latest linux kernel source from http://kernel.org and extract it on Machine A. Setup the kernel .config file (refer this guide for more information). Now to start the distributed compilation and even time it :
$time make -j8 CC=distcc
This will start 8 threads and distribute the compilation between Machine A and Machine B

5. Test results :
kernel compilation using single machine :
real 50m55.498s
user 71m4.967s
sys 6m55.030s

kernel compilation using three machines:
real 28m21.146s
user 17m32.862s
sys 4m35.537s

Monday, February 20, 2012

Kernel Error Codes

All error codes for the kernel are available in the following files in the kernel source tree :

include/asm-generic/errno-base.h
include/asm-generic/errno.h

----------------------include/asm-generic/errno-base.h----------------------

#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */

-------------------------include/asm-generic/errno.h----------------------

#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED 125 /* Operation Canceled */
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define ERFKILL 132 /* Operation not possible due to RF-kill */
#define EHWPOISON 133 /* Memory page has hardware error */

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