imx515 开发板Android源代码编译过程

Required Packages

Android requires the following system packages:

flex: This lexical analyzer generator is used to read a given input file for a description of a scanner to generate.

bison: This is a general-purpose parser generator.

gperf: This is a perfect hash function generator.

libesd0-dev: This enlightened sound daemon (dev files) is used to mix digitized audio streams for playback by a single device.

libwxgtk2.6-dev: This package provides GUI components and other facilities for many different platforms.

build-essential: This package contains a list of packages considered fundamental to building Debian packages.

安装好jdk 1.5.0

并在/etc/profile中设置好导出的环境变量

# Begin set java environment

export JAVA_HOME=/opt/java/jdk1.5.0_22

export JRE_HOME=/opt/java/jdk1.5.0_22/jre

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

# End set java environment

Unpack i.MX Android Release Package

After you setup a Linux PC, unpack the FSL i.MX Android Release Package using the following commands:

$ cd

/opt (or any other directory you like)

$ tar xzvf

imx-android-r8.tar.gz

$ cd imx-android-r8/code

$ tar xzvf r8.tar.gz

Assume you had unzipped i.MX

Android release package to /opt/imx-android-r8/.

$ cd /opt

/imx

-android

-r8/tool

$ tar xzvf

gcc

-4.1.2-glibc

-2.5-nptl

-3.tar.gz

-C /opt

Now you can find your cross compiler at /opt/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin

设置要导出的编译器相关的环境变量

#Freescale CrossCompiler Env

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 PATH=/opt/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin:$PATH

#

Prebuilt Image for uboot :

i.MX51 BBG3 board

Booting from SD

bootloader : imx51_BBG/u-boot.bin

kernel: imx51_BBG/uImage

Android file system:

"/":  imx51_BBG/SD/uramdisk.img

"/system":  imx51_BBG/SD/system.img

"/data" : imx51_BBG/SD/userdata.img. Not provided as it's empty.

"/recovery" : imx51_BBG/SD/recovery.img

Booting from TFTP/NFS

bootloader :

bootloader in SD: Same as "Booting from SD"

bootloader in SPI NOR: imx51_BBG/u-boot.bin

kernel: same as "Booting from SD"

Android file system: all in imx51_BBG/NFS/android_fs.tar.gz

下面开始repo代码打patch

Get Android Source Code (Android /Kernel /uboot )

the Android source code is maintained as more than 100 gits in an Android repository (Visit GitWeb from browser).

To get the Android source code from Google repo , follow the steps:

Assume you had unzipped i.MX

Android release package to /opt/imx-android-r8/.

$ cd

~

$ mkdir

myandroid

$ cd

myandroid

$ curl http://android.git.kernel.org/repo > ./repo

$ chmod

a+x

./repo

$ ./repo

init -u git://android.git.kernel.org/platform/manifest.git

-b eclair

$ cp /opt/imx-android-r8/code/r8/default.xml .repo/manifests/default.xml

(To avoid loading unnecessary gits

from Google repo

, meanwhile load some gits

from Google repo

which is not included in default manifest)

$ ./repo

sync

Get a clean kernel source code from kernel.org:

$ cd

myandroid

$ git

clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6.31.y.git kernel_imx

If you use uboot as your bootloader , then you need get a clean source code base from the original git :

$ cd myandroid/bootable/bootloader

    $ git clone git://git.denx.de/u-boot.git uboot-imx

Patch Code for i.MX  

Apply all i.MX Android patches using following steps:

Assume you had unzipped i.MX

Android release package to /opt/imx-android-r8/.

$ cd

~/myandroid

$ . /opt/imx-android-r8/code/r8/and_patch.sh

$ help

Now you should see "c_patch

" function is available for you

$ c_patch /opt/imx-android-r8/code/r8 imx_r8

Here "/opt/imx-android-r8/code/r8" is the location of the patches (i.e. directory created when you unzip release package)

"imx_r8" is the branch which will be created automatically for you to hold all patches (only in those existing Google gits

).

You can choose any branch name you like instead of "imx_r8".

If everything is OK, "c_patch

" will generate the following output to indicate successful patch:

**************************************************************

Success: Now you can build android code for FSL i.MX

platform

**************************************************************

Note: The patch script ( and_patch.sh ) utalizes  some basic utilities like awk/sed . If they are not available on your LinuxPC , install them in advance.

Build uboot

$ cd ~/myandroid/bootable/bootloader/uboot-imx

$ echo $ARCH && echo $CROSS_COMPILE

    Make sure you have those 2 environment variables set

Command to build for i.MX51 BBG3 board is:

    $ make mx51_bbg_android_config

    $ make

"u-boot.bin " is generated if you have a successful build.

The above u-boot.bin has 1024KB padding at the head of file,for example first executable instruction is at the offset 1KB. If you want to generate a no-padding image, you need do below dd command in host.

    $ dd if=./u-boot.bin of=./u-boot-no-padding.bin bs =1024 skip=1

Usually this no-padding uboot image is used in the SD card, for example, program this no-padding uboot image into 1KB offset of SD card so that we do not overwrite the MBR (including partition table) within first 512B on the SD card.

Note : Any image which must be loaded by uboot must have an unique image head, for example, some data must be added at the head of loaded image to tell uboot about the image (for example, it's a kernel, or ramfs , etc) and how to load the image (for example, load/execute address).

    Therefor before you can load any image into RAM by uboot , you need a tool to add this information to generate a new image which can be recognized by uboot . Fortunately, this tool is delivered together with uboot . After you make uboot using the above steps, you can find the tool (mkimage ) under tools/.

    Later the document will describe how to use mkimage to generate the image (for example kernel image, ramfs image) to be loaded by uboot .

Build Kernel Image 

To run Android using NFS or from SD, build the kernel with the default configuration  now as follows:

Assume you had already built uboot . mkimage was generated under myandroid//bootable/bootloader/uboot-imx/tools / and it's in your PATH

    $ cd ~/myandroid/kernel_imx

$ echo $ARCH && echo $CROSS_COMPILE

    Make sure you have those 2 environment variables set

$ make imx5_android_defconfig

    Generate ".config " according to default config file under arch/arm/configs .

$ make uImage

    You can generate zImage too by "make zImage ", use following command to generate uImage from zImage .

With a successful build in either of the above case, the generated kernel image is ~/myandroid/kernel_imx/arch/arm/boot/uImage .

Generate uImage to be loaded by u-boot

To generate uImage from the built zImage , generate a uImage based on the above zImage as follows:

$ cd myandroid/kernel_imx/arch/arm/boot

    $ ~/myandroid/bootable/bootloader/uboot-imx/tools/mkimage -A arm -O linux -T kernel -C none -a 0x90008000 -e 0x90008000 -n "Android Linux Kernel" -d ./zImage ./uImage

During boot, when uboot try to load above "uImage ", it will know to load it (without image head added by mkimage tool) into 0x90008000 (specified by "-a"), and then jump to 0x90008000 (specified by "-e") to execute it. "-C none" means no compression when generating "uImage ". This is because the original zImage is already a compressed one.

Build Android image 

After applying all i.MX patches and kernel image built out, build the Android image using following steps:

$ cd

~/myandroid

Command to build for i.MX51 BBG3 board is:

$ make PRODUCT-imx51_BBG-eng | tee build_imx51_BBG_android.log

"imx51_BBG" is the product names (see ~/myandroid/vendor/fsl/product

)

After build, check build_*_android.log

to make sure no build error.

For i.MX51 BBG build, the following outputs are generated as default under myandroid/out/target/product/imx51_BBG:

root / : root file system (including init, init.rc , etc). Mounted at /

system / :  Android system binary/libraries. Mounted at /system

data / : Android data area. Mounted at /data

Above three folders can be used to create your Android file system for NFS mounting, i.e. root/  > / , system/  > /system , data/  > /data

recovery / : root file system when booting in "recovery" mode. Not directly used.

ramdisk.img : Ramdisk image generated from "root/". Not directly used.

system.img : EXT3 image generated from "system/". Can be programmed to "SYSTEM" partition on SD card with "dd "

userdata.img : EXT3 image generated from "data/".

recovery.img : EXT3 image generated from "recovery/". Can be programmed to "RECOVERY" partition on SD card with "dd " 

Generate uRamdisk to be loaded by uboot

The following steps generate a RAMDISK image recognized by uboot :

Assume you had already built uboot . mkimage was generated under myandroid//bootable/bootloader/uboot-imx/tools /

$ cd myandroid/out/target/product/imx51_BBG

    $ ~/myandroid/bootable/bootloader/uboot-imx/tools/mkimage - A arm -O linux -T ramdisk -C none -a 0x90308000 -n "Android Root Filesystem " -d ./ramdisk.img ./uramdisk.img

编译完成,我们可以逐步将img文件烧写到SD卡中.

上述过程简单,按步骤一步步进行即可,不抓图描述.

Program Bootloader into SD using dd

Insert the SD card/cardreader to the Linux PC (root privileges are needed for programming SD)

          Note : if the SD card had been previously formatted with a valid file system, usually it is automatic mounted when you insert the SD card to Linux PC. Check is the SD card has been mounted using mount (usually /dev/sdb *). Umount the SD card using sudo umount /dev/sdb *

Program the bootloader into offset 1K (1024B) of the SD card

Make sure bootloader (uboot , for 3DS or BBG3) image is used. See "Prebuilt image for using uboot ".

# dd if=your_bootloader_binfile of=/dev/sdb bs =1K seek=1

In above example, you should use no-padding version bootloader since it will be programmed to 1KB offset ("bs =1K seek=1"). If you do want to use the normal version bootloader (with 1KB padding at the head of binfile ), you can do as below.

# dd if=/dev/sdb of=./mbrbackup bs =512 count=1  [To backup MBR]

   # dd if=your_bootloader_binfile_withpadding of=/dev/sdb [To program bootloader into offset 0 on SD ]

   # dd if=./mbrbackup of=/dev/sdb   [To restore MBR]