How to start with Android

Content

Setup a host computer

Note: If you need, more detailed instructions can be found at L3.0.35_4.1.0_LINUX_DOCS in the file Android User's Guide.pdf You need a host computer to compile the Linux and uBoot source code. Follow these steps: 1. Download VMware player (it's free). Select 64-bit version. 2. Download and Install Ubuntu 11.04 64-bit desktop version into the vMware virtual machine 3. Update sources.list
sudo gedit /etc/apt/sources.list
Replace the sources.list content with:
# deb cdrom:[Ubuntu 11.04 _Natty Narwhal_ - Release amd64 (20110427.1)]/ natty main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://old-releases.ubuntu.com/ubuntu/ natty main restricted
deb-src http://old-releases.ubuntu.com/ubuntu/ natty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://old-releases.ubuntu.com/ubuntu/ natty-updates main restricted
deb-src http://old-releases.ubuntu.com/ubuntu/ natty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://old-releases.ubuntu.com/ubuntu/ natty universe
deb-src http://old-releases.ubuntu.com/ubuntu/ natty universe
deb http://old-releases.ubuntu.com/ubuntu/ natty-updates universe
deb-src http://old-releases.ubuntu.com/ubuntu/ natty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://old-releases.ubuntu.com/ubuntu/ natty multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ natty multiverse
deb http://old-releases.ubuntu.com/ubuntu/ natty-updates multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ natty-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://old-releases.ubuntu.com/ubuntu/ natty-backports main restricted universe multiverse
# deb-src http://old-releases.ubuntu.com/ubuntu/ natty-backports main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu natty-security main restricted
deb-src http://old-releases.ubuntu.com/ubuntu natty-security main restricted
deb http://old-releases.ubuntu.com/ubuntu natty-security universe
deb-src http://old-releases.ubuntu.com/ubuntu natty-security universe
deb http://old-releases.ubuntu.com/ubuntu natty-security multiverse
deb-src http://old-releases.ubuntu.com/ubuntu natty-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu natty partner
# deb-src http://archive.canonical.com/ubuntu natty partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://old-releases.ubuntu.com/ubuntu natty main
deb-src http://old-releases.ubuntu.com/ubuntu natty main
deb http://archive.canonical.com/ lucid partner
deb-src http://archive.canonical.com/ lucid partner
4. Upgrade to the latest packages
  • Open up System -> Administration -> Update Manager
  • Click on Settings.
  • Open the Updates Tab.
  • Set 'Release upgrade' to 'Never'.
  • Close the settings dialog box.
  • Click on 'Check' to check for upgraded packages. It will look for packages that are upgraded from the version that is installed on your box.
  • Choose to install the upgrades. This will take a while on a freshly installed box.
  • Restart the machine.
5. Install Java JDK package. Go to Java Download page and download the file jdk-6u45-linux-x64.bin.
Note: You need to be logged in and accept the licence agreement. Run the binary JDK file:
# mkdir ~/andoid-jb-4.3.1.1-source-files
# cd ~/andoid-jb-4.3.1.1-source-files
# chmod u+x jdk-6u45-linux-x64.bin
# sudo ./jdk-6u45-linux-x64.bin
# sudo mv jdk1.6.0_45 /usr/lib/jvm/
Install all binaries and give them the highest priority.
# sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_45/bin/java 1
# sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_45/bin/javac 1
# sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_45/bin/javaws 1
# sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_45/bin/jar 1
# sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_45/bin/javadoc 1
Now JDK is configured. To check if it is done execute:
# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
Note: If you installed Java on your computer before, you need to go also through some additional steps. (Refer to the Freescale community page for more details.) 6. Install all other the necessary packages required for an Android build. For more details go to Android initialization page.
# sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
  libxml2-utils xsltproc
# sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
7. Configure USB access on host computer
# sudo nano /etc/udev/rules.d/51-android.rules
Paste this content to the file. Note: Replace fedevel with your actual username.
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="fedevel"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="fedevel"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="fedevel"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="fedevel"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="fedevel"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="fedevel"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="fedevel"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="fedevel"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="fedevel"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="fedevel"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="fedevel"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="fedevel"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="fedevel"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="fedevel"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="fedevel"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="fedevel"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="fedevel"
8. Install additioanl package required by Freescale
# sudo apt-get install uuid uuid-dev
# sudo apt-get install zlib1g-dev liblz-dev
# sudo apt-get install liblzo2-2 liblzo2-dev
# sudo add-apt-repository ppa:git-core/ppa
# sudo apt-get update
# sudo apt-get install git-core curl
9. Download and unpack the Android files provided by Freescale. Note: we will created a new directory and place there all the files:
# mkdir ~/android-jb4.3.1.1.0-source-files
Download the documentation, the binary demo files and the source code. 9. DownloadAndroid release package Create directory where you will place android files (For more info look at the Freescale community page).
# mkdir ~/andoid-jb-4.3.1.1-source-files
1
Download and copy there <a href="https://www.freescale.com/webapp/Download?colCode=IMX6_JB43_110_ANDROID_SOURCE_BSP&appType=license&location=null&fpsp=1&WT_TYPE=Board%20Support%20Packages&WT_VENDOR=FREESCALE&WT_FILE_FORMAT=gz&WT_ASSET=Downloads&sr=100&Parent_nodeId=1337694700967726419044&" target="_blank">Android release package</a>.

<h1>Running Android with Prebuilt Image</h1>
1. Prepare a SD card for an Android

Create a script for setting up all the required partitions:
1
# sudo nano fsl-sdcard-partition.sh
Filled the file with the content below:
#!/bin/bash

# partition size in MB
BOOTLOAD_RESERVE=8
BOOT_ROM_SIZE=8
SYSTEM_ROM_SIZE=512
DATA_SIZE=1024
CACHE_SIZE=256
RECOVERY_ROM_SIZE=8
VENDER_SIZE=8
MISC_SIZE=8

help() {

bn=`basename $0`
cat << EOF
usage $bn <option> device_node

options:
  -h				displays this help message
  -s				only get partition size
  -np 				not partition.
  -f 				flash android image.
EOF

}

# check the if root?
userid=`id -u`
if [ $userid -ne "0" ]; then
	echo "you're not root?"
	exit
fi


# parse command line
moreoptions=1
node="na"
cal_only=0
flash_images=0
not_partition=0
not_format_fs=0
while [ "$moreoptions" = 1 -a $# -gt 0 ]; do
	case $1 in
	    -h) help; exit ;;
	    -s) cal_only=1 ;;
	    -f) flash_images=1 ;;
	    -np) not_partition=1 ;;
	    -nf) not_format_fs=1 ;;
	    *)  moreoptions=0; node=$1 ;;
	esac
	[ "$moreoptions" = 0 ] && [ $# -gt 1 ] && help && exit
	[ "$moreoptions" = 1 ] && shift
done

if [ ! -e ${node} ]; then
	help
	exit
fi


# call sfdisk to create partition table
# get total card size
seprate=40
total_size=`sfdisk -s ${node}`
total_size=`expr ${total_size} / 1024`
rom_size=`expr ${BOOT_ROM_SIZE} + ${SYSTEM_ROM_SIZE} + ${DATA_SIZE}`
rom_size=`expr ${rom_size} + ${CACHE_SIZE} + ${RECOVERY_ROM_SIZE} + ${MISC_SIZE} + ${VENDER_SIZE} + ${seprate}`
boot_start=`expr ${BOOTLOAD_RESERVE}`
boot_rom_sizeb=`expr ${BOOT_ROM_SIZE} + ${BOOTLOAD_RESERVE}`
recovery_start=`expr ${boot_start} + ${BOOT_ROM_SIZE} + 1`
extend_start=`expr ${recovery_start} + 1`
extend_size=`expr ${SYSTEM_ROM_SIZE} + ${DATA_SIZE} + ${CACHE_SIZE} + ${VENDER_SIZE} + ${MISC_SIZE} + ${seprate}`
system_start=`expr ${extend_start} + 1`
cache_start=`expr ${extend_start} + ${SYSTEM_ROM_SIZE} + 1`
data_start=`expr ${cache_start} + ${CACHE_SIZE} + 1`
misc_start=`expr ${data_start} + ${DATA_SIZE}`
vfat_start=`expr ${extend_start} + ${extend_size}`
vfat_size=`expr ${total_size} - ${rom_size}`

# create partitions
if [ "${cal_only}" -eq "1" ]; then
cat << EOF
BOOT   : ${boot_rom_sizeb}MB
RECOVERY: ${RECOVERY_ROM_SIZE}MB
SYSTEM : ${SYSTEM_ROM_SIZE}MB
CACHE  : ${CACHE_SIZE}MB
DATA   : ${DATA_SIZE}MB
MISC   : ${MISC_SIZE}MB
VFAT   : ${vfat_size}MB
EOF
exit
fi

function format_android
{
    echo "formating android images"
    mkfs.vfat ${node}4
    mkfs.ext4 ${node}5 -Lsystem
    mkfs.ext4 ${node}6 -O^extents  -Lcache
    mkfs.ext4 ${node}7 -Ldata
    mkfs.ext4 ${node}8 -O^extents -Lvender
}

function flash_android
{
if [ "${flash_images}" -eq "1" ]; then
    echo "flashing android images..."    
    dd if=u-boot.bin of=${node} bs=1k seek=1 skip=1
    dd if=/dev/zero of=${node} bs=512 seek=1536 count=16
    dd if=boot.img of=${node}1
    dd if=recovery.img of=${node}2
    dd if=system.img of=${node}5
fi
}

if [[ "${not_partition}" -eq "1" && "${flash_images}" -eq "1" ]] ; then
    flash_android
    exit
fi


# destroy the partition table
dd if=/dev/zero of=${node} bs=1024 count=1

sfdisk --force -uM ${node} << EOF
,${boot_rom_sizeb},83
,${RECOVERY_ROM_SIZE},83
,${extend_size},5
,${vfat_size},b
,${SYSTEM_ROM_SIZE},83
,${CACHE_SIZE},83
,${DATA_SIZE},83
,${VENDER_SIZE},83
,${MISC_SIZE},83
EOF

# adjust the partition reserve for bootloader.
# if you don't put the uboot on same device, you can remove the BOOTLOADER_ERSERVE
# to have 8M space.
# the minimal sylinder for some card is 4M, maybe some was 8M
# just 8M for some big eMMC 's sylinder
sfdisk --force -uM ${node} -N1 << EOF
${BOOTLOAD_RESERVE},${BOOT_ROM_SIZE},83
EOF

# format the SDCARD/DATA/CACHE partition
part=""
echo ${node} | grep mmcblk > /dev/null
if [ "$?" -eq "0" ]; then
	part="p"
fi

format_android
flash_android


# For MFGTool Notes:
# MFGTool use mksdcard-android.tar store this script
# if you want change it.
# do following:
#   tar xf mksdcard-android.sh.tar
#   vi mksdcard-android.sh 
#   [ edit want you want to change ]
#   rm mksdcard-android.sh.tar; tar cf mksdcard-android.sh.tar mksdcard-android.sh
Plug in the SD card. Find where it is mapped:
# dmesg | tail
In our case we have an SD card located in /dev/sdb. Update the permission and run it. Select the directory where the SD card is located (e.g. in /dev/sdb):
# chmod +x ./fsl-sdcard-partition.sh
# ./fsl-sdcard-partition.sh /dev/sdb
2. Unpack the prebuild files Unpack the image files:
# cd ~/android-jb4.3.1.1.0-source-files/
# gunzip -c android_jb4.3_1.1.0-ga_image_bundle.gz > android_jb4.3_1.1.0-ga_image_bundle.tar
# mkdir image-files
# tar -xvf android_jb4.3_1.1.0-ga_image_bundle.tar -C image-files/
We will use SABRE SD board as a starting point:
# cd image-files/
# tar -xvf android_jb4.3_1.1.0-ga_image_6qsabresd.tar.gz
3. Copy files to the defined partitions
# cd ~/android-jb4.3.1.1.0-source-files/image-files/android_jb4.3_1.1.0-ga_image_6qsabresd/SD
# mkfs.ext4 /dev/sdb1
# mkdir /media/sdcard
# mount /dev/sdb1 /media/sdcard/
# cp -prv boot.img /media/sdcard/
# umount /media/sdcard
# mkfs.ext4 /dev/sdb2
# mount /dev/sdb2 /media/sdcard/
# cp -prv recovery.img /media/sdcard/
# umount /media/sdcard
# mount /dev/sdb5 /media/sdcard/
# cp -prv system.img /media/sdcard/
# umount /media/sdcard
4. Unpack the u-boot
We need to use u-boot from SABRE AI wich supports NAND boot storage. We will also unpack the package this board:
# cd ~/android-jb4.3.1.1.0-source-files/image-files
# tar xvf android_jb4.3_1.1.0-ga_image_6qsabreauto.tar.gz 
4. Update the u-boot
Send the android u-boot file u-boot-mx6q-nand.bin locatede in ~/android-jb4.3.1.1.0-source-files/image-files/android_jb4.3_1.1.0-ga_image_6qsabreauto into iMX6 Rex on board flash.
Plug the created SD card (to the holder on the edge), connect the board with the PC via serial console. Plug the power and stop autoboot. Send a file:
> mw.b 0x10800000 0xFF 0x80000; loadb
Now use in your terminal: Load file -> Kermit -> Send -> select u-boot-6q.bin file
> sf probe 3:2; sf erase 0x0 0x80000; sf write 0x10800000 0x0 0x80000
Unzip the package:
# cd ~/andoid-jb-4.3.1.1-source-files
# tar xzvf android_jb4.3_1.1.0-ga_source.gz
# tar xzvf android_jb4.3_1.1.0-ga_source.tar.gz
# cd android_jb4.3_1.1.0-ga_source/code
# tar xzvf jb4.3_1.1.0-ga.tar.gz
Unpack the source files
# cd ~/android-jb4.3.1.1.0-source-files/
# gunzip -c android_jb4.3_1.1.0-ga_source.gz > android_jb4.3_1.1.0-ga_source.tar
# mkdir source-files
# tar -xvf android_jb4.3_1.1.0-ga_source.tar -C source-files/
# tar -xvf android_jb4.3_1.1.0-ga_source.tar.gz
# cd android_jb4.3_1.1.0-ga_source/code/
# tar -xvf jb4.3_1.1.0-ga.tar.gz
10. Get Android Source Code
# cd ~
# mkdir myandroid
# mkdir bin
# cd myandroid
# curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
# chmod a+x ~/bin/repo
# ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-4.3_r2.1
# ~/bin/repo sync
Last two command may take a while to proceed. Get jb4.3_1.1.0-ga kernel source code from Freescale open source git:
# cd myandroid
11. Get jb4.3_1.1.0-ga kernel
# cd ~/myandroid
# git clone git://git.freescale.com/imx/linux-2.6-imx.git
# cd kernel_imx
# git checkout jb4.3_1.1.0-ga
12. Patch Code for i.MX
# sudo cp -pr android_jb4.3_1.1.0-ga_source/ /opt/
# cd ~/myandroid
# source /opt/android_jb4.3_1.1.0-ga_source/code/jb4.3_1.1.0-ga/and_patch.sh
# help
Now you should see that the "c_patch" function is available
$ c_patch /opt/android_jb4.3_1.1.0-ga_source/code/jb4.3_1.1.0-ga imx_jb4.3_1.1.0-ga
If everything is OK, "c_patch" will generate the following output to indicate successful patch:
**************************************************************
Success: Now you can build the Android code for FSL i.MX platform
**************************************************************
Update u-boot command:
> setenv fastboot_dev mmc1
> setenv bootcmd booti mmc1
> setenv bootargs console=ttymxc0,115200 init=/init video=mxcfb0:dev=hdmi,1280x720M@60,if=RGB666 vmalloc=400M fbmem=28M fbcon=28M androidboot.console=ttymxc0 androidboot.hardware=freescale
> saveenv
The SD card partitions are ready. Copy there files from unzipped package (android_jb4.3_1.1.0-ga_image_6qsabresd.tar.gz located in packaqge android_jb4.3_1.1.0-ga_image_bundle.gz).
# cd /home/fedevel/android\ files/android_jb4.3_1.1.0-ga_image_6qsabresd/SD/
# mount /dev/sdb1 /media/sdcard/
# 
Test Android before you will build any code. We will use files for SABRE SD board. Download prebuild files from Freescale website. Unzip manually android_jb4.3_1.1.0-ga_source.gz than android_jb4.3_1.1.0-ga_image_bundle.tar. Unzip the files first:
# cd ~/andoid-jb-4.3.1.1-source-files/android_jb4.3_1.1.0-ga_image_bundle
# tar -tvf android_jb4.3_1.1.0-ga_image_6qsabresd.tar.gz
android_jb4.3_1.1.0-ga_image_bundle.tar