Archive for category Embbeded

Using scratchbox2 and Ubuntu 11.10

Local machine environment:
- Ubuntu 11.10 64bits

Emulated environment:
- Debian Squeeze armel

Install in local machine:

sudo apt-get install scratchbox2 fakeroot
sudo apt-get install qemu-user qemu
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install cpp-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi gcc-4.4-arm-linux-gnueabi-base
sudo apt-get install cpp-4.5-arm-linux-gnueabi g++-4.5-arm-linux-gnueabi gcc-4.5-arm-linux-gnueabi

Init scratchbox configuration:

fakeroot debootstrap --variant=scratchbox --foreign --arch armel squeeze /path/root_fs
sb2-init -n -c /usr/bin/qemu-arm MACHINE_NAME "arm-linux-gnueabi-gcc"

Install into emulated system:

apt-get install g++ rpm zlib1g-dev m4 bison libncurses5-dev gettext build-essential intltool libxml2-dev libtool

Compile outside the box:

cd source
sb2 ./configure
sb2 make -jN
sb2 make install DESTDIR=/path/root_fs

To change the crosscompiler toolchain install the script /usr/local/bin/


if [ -z $1 ]; then
echo -e "\n Error: you need to define the arm-linux-gnueabi version"
echo -e " Usage: \n"

if [ ! -f /usr/bin/arm-linux-gnueabi-cpp-$1 ]; then
echo -e "\n Error: arm-linux-gnueabi version $1 do not exist\n"

# Unlink symbolic links
sudo unlink /usr/bin/arm-linux-gnueabi-cpp
sudo unlink /usr/bin/arm-linux-gnueabi-gcc
sudo unlink /usr/bin/arm-linux-gnueabi-gcov

#Define new links for arm-linux-gnueabi
sudo ln -s /usr/bin/arm-linux-gnueabi-cpp-$1 /usr/bin/arm-linux-gnueabi-cpp
sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-$1 /usr/bin/arm-linux-gnueabi-gcc
sudo ln -s /usr/bin/arm-linux-gnueabi-gcov-$1 /usr/bin/arm-linux-gnueabi-gcov


1 Comment

Emulate ARM in Qemu

#Download Kernel and initrd


#Create disk

qemu-img create -f raw debian.img 5G

#Start qemu
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.gz -hda debian.img -append “root=/dev/rasudo kpartx -av debian.img

#Mount filesystem after install and copy kernel and initrd
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loopm”
sudo kpartx -av debian.img
sudo mount /dev/mapper/loop1p1 ./mnt/ -o loop

#Start qemu again
qemu-system-arm -m 256 -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img -hda debian.img -append “root=/dev/sda1”

More reliable information at

Leave a comment

Generating Debian FS directly into iMXT

Generating Debian FS directly into iMXT

This how to will show you how to build a Debian FS into iMXT SDCARD.


- iMXT running android from NAND with rooting capabilities
- Busybox
- Internet connection
- 2GB SDcard


* Resize you SDcard, leave at least the first 8 cylinders free to host uboot and kernel
* Format the the SDcard as ext3 ie: mkfs.ext3 /dev/sdd1
* Download Debian bootstrap

sudo apt-get install debootstrap

mkdir $HOME/debootstrap

sudo debootstrap --arch armel --foreign squeeze $HOME/debootstrap

#This may take a while

I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional required dependencies: insserv libbz2-1.0 libdb4.8 libslang2
I: Found additional base dependencies: libnfnetlink0 libsqlite3-0
I: Checking component main on
I: Retrieving libacl1
I: Validating libacl1
I: Retrieving adduser
I: Validating adduser
I: Retrieving apt-utils
I: Validating apt-utils
I: Retrieving apt
I: Validating apt
I: Retrieving aptitude
I: Validating aptitude
I: Retrieving libattr1
I: Validating libattr1
I: Retrieving base-files
I: Validating base-files
I: Retrieving base-passwd
I: Validating base-passwd
I: Retrieving bash
I: Validating bash
I: Retrieving libboost-iostreams1.42.0
I: Validating libboost-iostreams1.42.0
I: Retrieving bsdmainutils
I: Validating bsdmainutils
I: Retrieving libbz2-1.0
I: Validating libbz2-1.0
I: Retrieving coreutils
I: Validating coreutils
I: Retrieving cpio

*Copy all files from $HOME/debootstrap/ to your SDcard ext3 partition

*Insert the SDcard into your Android device

*Mount the SDcard, example

adb shell
mkdir -p /data/local/mnt
mount -t ext3 /dev/block/mmcblk0p1 /data/local/mnt

*Change root (takes a while)

export PATH=/usr/bin:/usr/sbin:/bin:$PATH

chroot /data/local/mnt/ /debootstrap/debootstrap --second-stage
I: Installing core packages...
I: Unpacking required packages...
I: Unpacking libacl1...
I: Unpacking libattr1...
I: Unpacking base-files...
I: Unpacking base-passwd...
I: Unpacking bash...
I: Unpacking libbz2-1.0...
I: Unpacking coreutils...
I: Unpacking dash...
I: Unpacking libdb4.8...
I: Unpacking debconf-i18n...
I: Unpacking debconf...
I: Unpacking debianutils...
I: Unpacking diffutils...
I: Unpacking dpkg...
I: Unpacking e2fslibs...
I: Unpacking e2fsprogs...
I: Unpacking libcomerr2...

... It takes a while

*After rooting

echo 'nameserver' > /data/local/mnt/etc/resolv.conf
mkdir -p /data/local/mnt/etc/firmware
cp /system/etc/firmware/fw_bcm4329.bin /data/local/mnt/etc/firmware/
cp /system/etc/firmware/nvram.txt /data/local/mnt/etc/firmware/
cp /sbin/adbd /data/local/mnt/sbin/adbd
sysctl -w net.ipv4.ip_forward=1
export PATH=/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root

Setup mount points:

chroot /data/local/mnt /bin/bash
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mkdir -p /system/bin/
ln -s /bin/bash /system/bin/sh
echo 'deb squeeze main' >> /etc/apt/sources.list

#U-boot configuration

loadkernel=nand read ${loadaddr} 0x200000 0x400000
loadrd=nand read ${rd_loadaddr} 0x600000 0x80000
bootcmd=mmc read 0 0x90800000 0x800 1800 ; bootm
bootargs=console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7


Leave a comment

U-Boot Boot Debian from SDCARD


setenv loadaddr 0x90800000
setenv bootcmd 'mmc read 0 0x90800000 0x800 1800 ; bootm '
setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7'

The full script is:

Hit any key to stop autoboot: 0
BBG U-Boot (SD) > printenv
bootcmd=mmc read 0 0x90800000 0x800 1800 ; bootm
bootargs=console=ttymxc0,115200 root=/dev/mmcblk0p1 rootwait init=/sbin/init di1_primary calibration loglevel=7

Leave a comment

MTD-Utils for Android

git clone git:// mtd-utils

[to do]

Leave a comment

Cross Compiling streamer from xawtv using LTIB

1 – Get source code from

2 – Aplly these patches

diff -urN ../tmp-orig/xawtv-3.95/console/fbtools.c ./console/fbtools.c
--- xawtv-3.95/console/fbtools.c 2003-02-14 14:14:04.000000000 +0000
+++ xawtv-3.95/console/fbtools.c 2011-03-12 10:57:40.000000000 +0000
@@ -21,8 +21,6 @@

#include "fbtools.h"

/* -------------------------------------------------------------------- */
@@ -424,7 +422,7 @@
goto err;
- fb_mem_offset = (unsigned long)(fb_fix.smem_start) & (~PAGE_MASK);
+ fb_mem_offset = (unsigned long)(fb_fix.smem_start) & ~(sysconf(_SC_PAGE_SIZE)-1);
fb_mem = mmap(NULL,fb_fix.smem_len+fb_mem_offset,
if (-1L == (long)fb_mem) {
diff -urN ../tmp-orig/xawtv-3.95/console/matrox.c ./console/matrox.c
--- xawtv-3.95/console/matrox.c 2005-02-03 10:40:41.000000000 +0000
+++ xawtv-3.95/console/matrox.c 2011-03-12 11:09:51.000000000 +0000
@@ -9,7 +9,6 @@

-#include /* PAGE_SIZE */

#include "byteswap.h"
@@ -226,7 +225,7 @@
return -1;
off = (unsigned long)fb_fix.mmio_start -
- ((unsigned long)fb_fix.mmio_start & ~(PAGE_SIZE-1));
+ ((unsigned long)fb_fix.mmio_start & ~(sysconf(_SC_PAGE_SIZE)-1));
bmmio += off;
mmio = (uint32_t*)bmmio;
return 0;

3- Prepare the compilatio using

./configure –disable-xfree-ext  –disable-xvideo  –disable-lirc –disable-quicktime –disable-motif –disable-aa–disable-alsa  –disable-zvbi –disable-gl  –disable-dv  –disable-xft –without-x

4- After configure, modify Makefile

# include stuff
# must come firstinclude $(srcdir)/common/
# subdirsinclude $(srcdir)/console/Subdir.mkinclude $(srcdir)/debug/Subdir.mkinclude $(srcdir)/frequencies/Subdir.mkinclude $(srcdir)/libng/Subdir.mkinclude $(srcdir)/libng/plugins/ $(srcdir)/libng/contrib-plugins/ $(srcdir)/man/ $(srcdir)/scripts/ $(srcdir)/vbistuff/ $(srcdir)/x11/
# dependencies-include $(depfiles)
#Compiling only streamer
# targets to buildTARGETS-console := \    console/streamer
console/streamer: \    console/streamer.o \    common/channel-no-x11.o \    $(OBJS-common-capture)
console/streamer : LDLIBS  += $(THREAD_LIBS) -ljpeg -lm -L${JPEG_ROOT}/libconsole/streamer : LDFLAGS := $(DLFLAGS)
# global targetsall:: $(TARGETS-console)

install::    $(INSTALL_PROGRAM) $(TARGETS-console) $(bindir)
distclean::    rm -f $(TARGETS-console

5- Run make

Thanks to Jeyner Gil Caga

Leave a comment

Compiling Busybox for ARM and Android

# Download the source from git

hamilton@saygon:/tmp$ git clone git://

hamilton@saygon:/tmp$ cd busybox/

#Export ARCH and  CROSS_COMPILE (check your toolchain)

export ARCH=arm
export CROSS_COMPILE=/opt/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-

#Enter the configuration interface

hamilton@saygon:/tmp/busybox$ make menuconfig

#and follow these procedures

$ Busybox Settings --> Build Options --> Build Busybox as a static binary (no shared libs)  -  Enable this option by pressing "Y"
$ Busybox Settings --> Build Options --> Cross compiler prefix  -  Set this option equal to "arm-none-linux-gnueabi-"
$ Busybox Settings --> Installation Options --> Don't use /usr  -  Enable this option by pressing "Y"
$ Linux Module Utilities --> () Default directory containing modules - Set this option to nothing
$ Linux Module Utilities --> () Default name of modules.dep - Set this option to nothing

#Select desired packages and save your configuration and run make, after compilation you will have a busybox binary

hamilton@saygon:/tmp/busybox$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped

#Upload the file to your adb device and install busybox using ./busybox –install -s

#You can find more tips here


Ltib fails to compile in Ubuntu 10.10 file not recognized problem

ccache /usr/bin/gcc -B/usr/bin/  -g -O2   -o makedoc  makedoc.o ../lib/libtxi.a -lncurses

makedoc.o: file not recognized: File format not recognized

collect2: ld returned 1 exit status

make[4]: *** [makedoc] Error 1

make[4]: Leaving directory `/opt/freescale/ltib/usr/src/rpm/BUILD/texinfo-4.8/tools/info’

To solve that just

$ sudo rm -rf ~/.ccache

and start all over.

Leave a comment

Step by step to create/modify ramdisk.img

Benno’s blog has an article to change the ramdisk image, I tried it and give more details here.

ramdisk.img is included in the google android sdk, it exists in folder $SDK_ROOT/tools/lib/images/ramdisk.img. The ramdisk.img included in the google android sdk is a gzipped ramdisk.cpio file.

Here is the steps:

  1. Upload the ramdisk.img to your linux machine
  2. Change the ramdisk.img name to ramdisk.cpio.gz, and extract it by: # gzip -d ramdisk.cpio.gz
  3. Create a temporary folder, say tmp, copy ramdisk.cpio to tmp folder
  4. Extract the ramdisk.cpio in the tmp folder with command: # cpio -i -F ramdisk.cpio
  5. Remove the ramdisk.cpio in the tmp folder, and make any changes you want to the extracted ramdisk.cpio in tmp folder
  6. Recreate the ramdisk.cpio with command: # cpio -i -t -F ../ramdisk.cpio | cpio -o -H newc -O ../ramdisk_new.cpio

Some notes:

  1. I change ramdisk.img to ramdisk.cpio.gz, and unzip it. It is because I find the -z parameter is not supported with my cpio. I tried the latest cpio (2.9), it doesn’t work too.
  2. Check cpio version by # cpio –version. I’m using cpio version 2.4.
  3. Find the latest cpio (v 2.9) on site: gnu cpio
  4. Notice that in step 6, the command includes two O’s. First o is lower-case, second is up-case.
  5. Notice in step 6, please remain ramdisk.cpio in up folder of tmp folder. The command need it there.

Read the original at :


Android on iMx51EVK with 3G modem

You can find the original article here

Android Installation  

1. Install JDK

Install JDK 5 from here :

NOTE : JDK 6 is not compatible. JDK 5 is essential

Installation notes for JDK 5 are here:
Download the .bin file into /usr/java and install

2. Setup other packages for Android based on instructions here :

3. Edit ~/.profile and add the following commands :

export ARCH=arm
export CROSS_COMPILE=/opt/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-
export JAVA_HOME=/usr/java/jdk1.5.0_22
export PATH=$JAVA_HOME/bin:$PATH

4. gcc-4.3 and g++4.3 must be installed to compile the SDK.

However, gcc and g++ installed using sudo apt-get install will pull in gcc4.4 and g++4.4
This will not lead to issues in compilation.

Follow all the steps in User guide.

Errors during build :

Hardware for USB Modem

Huawei E180
Bought from :
Reference manual :

SIM Card
Tmobile 3G with voice and data plan

How to get Log messages ?

Connect 3G module with SIM inserted and then bootup to Android shell:
$ dmesg
$ ls /dev/ttyUSB*
$ logcat -b radio &
$ logcat pppd:* *:S &

* E180 is identified by kernel as two USB serial ports:
# ls /dev/ttyUSB*

But our default configuration for RIL daemon is to listen on ttyUSB3. So change /init.rc as below:
service ril-daemon .... -d /dev/ttyUSB3 -u /dev/ttyUSB0
service ril-daemon --- -d /dev/ttyUSB1 -u /dev/ttyUSB0

init.rc is in the root partition of Android root filesystem. After you build Android, it's under ~/myAndroid/out/target/product/imx51_BBG/

How to change init.rc and integrate into rootfs ?
On host machine
$ cd ~/myAndroid
$ rm out/target/imx51_BBG/ramdisk.img
$ CHANGE out/target/imx51_BBG/root/init.rc per your needs
$ make
ramdisk.img will be re-generated
or if you don't want to make whole Android, you can:
out/host/linux-x86/bin/mkbootfs out/target/product/imx51_BBG/root | out/host/linux-x86/bin/minigzip > out/target/product/imx51_BBG/ramdisk.img

If you only have ramdisk.img but don't have corresponding "root/" directory, you can get it by:
$ gunzip ramdisk.img
$ mkdir root
$ cd root
$ sudo cpio -i --make-directories < ../ramdisk.img
$ ls
Now you have your "root/". You can change anything (e.g. init.rc) and the re-create the ramdisk.img with method above.

How to detect that you are connected to the network ?

The entire log is attached. But the following sections indicate connection was successful. 

D/GSM     ( 2057): [GsmDataConnectionTracker] setState: INITING
D/AT      ( 1955): AT< OK
D/AT      ( 1955): AT> AT+CGQREQ=1
D/AT      ( 1955): AT< OK
D/AT      ( 1955): AT> AT+CGQMIN=1
D/AT      ( 1955): AT< OK
D/AT      ( 1955): AT> AT+CGEREP=1,0
D/AT      ( 1955): AT< OK
D/AT      ( 1955): AT> AT+CGACT=0,1
D/AT      ( 1955): AT< OK
D/AT      ( 1955): AT> ATD*99***1#
D/AT      ( 1955): AT< CONNECT 236800
D/RIL     ( 1955): PPPd started

The other obvious check would be to check if we get an IP address. 

Sometimes, if you are booting from SD, the excetution mode of "/etc/init.gprs-pppd" is not set which will cause it to fail while bringing up PPP.
To fix this, you need to change the mode in system partition on the SD card after connecting it to the linux host. 

$ chmod 777 /etc/init.gprs-pppd

Radio Interface Layer Sites

Android Developers Site

1 Comment