Linux下的Android环境:
The Android build is routinely tested on recent versions of Ubuntu (6.06 and later), but reports of successes or failures on other distributions are welcome.
Ubuntu Linux (32-bit x86)
To set up your Linux development environment, make sure you have the following:
* Required Packages:
o Git 1.5.4 or newer and the GNU Privacy Guard.
o JDK 5.0, update 12 or higher. Java 6 is not supported, because of incompatibilities with @Override.
o flex, bison, gperf, libsdl-dev, libesd0-dev, libwxgtk2.6-dev (optional), build-essential, zip, curl.
$ sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
* You might also want Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.
$ sudo apt-get install valgrind
* Intrepid (8.10) users may need a newer version of libreadline:
$ sudo apt-get install lib32readline5-dev
按照手册安装好相应的 工具后,我们就可以开始下载源码了。
后面的源码下载,我们主要还是根据飞思卡尔的项目进行。
Setup your PC
To build the Android source files, you will need to use Linux PC. It's suggested that you use recent version of Ubuntu which is the mostly tested OS for Android build.
After installing Linux PC, you need check whether you have all necessary packages installed for Android build. Refer to "Setting up your machine" on Android web site.
Note:
Install JDK1.5 instead of JDK1.6, otherwise error may occur during "make sdk"
Unpack i.MX Android Release Package
After setup Linux PC, you need unpack FSL i.MX Android Release Package:
$ cd /opt (or any other directory you like)
$ tar xzvf imx-android-r2.tar.gz
$ cd imx-android-r2/code
$ tar xzvf android-R2.tar.gz
Get some useful tools ready
ATK is a windows based tool which we will use to erase and program NAND. We will use it to program kernel image into NAND later.
Please install it in advance according to it's user guide which is included this release package.
If you don't have built your own compiler, you can use the prebuilt gcc cross-compiler in release package for kernel compile:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ cd /opt/imx-android-r2/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
Export below environment variables (e.g. in your ~/.profile)
so that you don't need set them manually each time when compiling kernel:
$ 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-
And it's always useful to setup tftp server (for kernel loading to board) and nfs server (for file system mounting)
Install/configuration steps are not described here.
We will assume the following directory name in the whole guide:
tftp server: /opt/tftproot as tftp server root
nfs server: /opt/nfsroot as nfs server root
Trial Android with prebuilt image
If you'd like to trial Android before building any code, you can use those prebuilt images under image/.
You can either run Android from TFTP/NFS or load/run Android from NAND by following steps in "Load and run".
Get Android source code
Android soruce code is maintained as more than 100 gits in Android repository (Visit GitWeb from browser).
To get Android source code from Google repo, follow the steps:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ 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
$ cp /opt/imx-android-r2/code/R2/default.xml .repo/manifests/default.xml (To avoid loading unnecessary gits from Google repo)
$ ./repo sync
Also need 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.26.y.git kernel_imx
To build Android for i.MX based platform, you need apply i.MX related patches to Android source code and then build Android image and kernel image separately.
Patch code for i.MX
Apply all i.MX Android patch with following steps:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ cd ~/myandroid
$ . /opt/imx-android-r2/code/R2/and_patch.sh
$ help
Now you should see "c_patch" function is available for you
$ c_patch /opt/imx-android-r2/code/R2 imx_R2
Here "/opt/imx-android-r2/code/R2" is the location of the patches (i.e. directory created when you unzip release package)
"imx_R2" 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_R2".
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) utilize some basic utilities like awk/sed. If they are not available on your LinuxPC, install them in advance.
Build Android image
After applying all i.MX patches, you can build Android image by following steps:
$ cd ~/myandroid
$ make PRODUCT-imx51_3stack-eng | tee build_imx51_3stack_android.log
"imx51_3stack" is the product name (see ~/myandroid/vendor/fsl/product)
After build, check build_imx51_3stack_android.log to make sure no error.
With a successful build, you will get below outputs under ~/myandroid/out/target/product/imx51_3stack/:
* system.img and userdata.img
File system image (in UBIFS) to programmed into NAND flash if you want to run Android from NAND
* root/,system/,data/
Directory which can be used as Android file system if you want to run Android via NFS
Build kernel image
If you want to run Android via NFS, then you can build kernel with default config now:
$ cd ~/myandroid/kernel_imx
Note! There is another kernel dir "~/myandroid/kernel". Don't use it
$ echo $ARCH && echo $CROSS_COMPILE
Make sure you have those 2 environment variables set
$ make imx51_3stack_defconfig
Generate ".config" according to default config file under arch/arm/configs.
$ make -j2
If you want to run Android directly from NAND flash, then you will need config kernel using RAMDISK as rootfs:
$ cd ~/myandroid/kernel_imx
Note! There is another kernel dir "~/myandroid/kernel". Don't use it
$ echo $ARCH && echo $CROSS_COMPILE
Make sure you have those 2 environment variables set
$ make imx51_3stack_defconfig
Generate ".config" according to default config file under arch/arm/configs.
Use imx31_3stack_defconfig for i.MX31 instead
$ make menuconfig
"General Setup" -> Select "Initial RAM filesysttem and RAM disk (initramfs/initrd) support" option
And set "Initramfs source file" below the above option to the "root/" dir generated during above Android build, i.e.
"~/myandroid/out/target/product/imx51_3stack/root"
NOTE! Replace "~" with absolute path here.
Now build kernel
$ make -j2
-j2可以提高编译的速度
With a successful build in either of above 2 cases, you will get the generated kernel image as ~/myandroid/kernel_imx/arch/arm/boot/zImage
编译完,就是如何去在我们的板子上运行的问题了,这个有其他文档说明指导。
The Android build is routinely tested on recent versions of Ubuntu (6.06 and later), but reports of successes or failures on other distributions are welcome.
Ubuntu Linux (32-bit x86)
To set up your Linux development environment, make sure you have the following:
* Required Packages:
o Git 1.5.4 or newer and the GNU Privacy Guard.
o JDK 5.0, update 12 or higher. Java 6 is not supported, because of incompatibilities with @Override.
o flex, bison, gperf, libsdl-dev, libesd0-dev, libwxgtk2.6-dev (optional), build-essential, zip, curl.
$ sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
* You might also want Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.
$ sudo apt-get install valgrind
* Intrepid (8.10) users may need a newer version of libreadline:
$ sudo apt-get install lib32readline5-dev
按照手册安装好相应的 工具后,我们就可以开始下载源码了。
后面的源码下载,我们主要还是根据飞思卡尔的项目进行。
Setup your PC
To build the Android source files, you will need to use Linux PC. It's suggested that you use recent version of Ubuntu which is the mostly tested OS for Android build.
After installing Linux PC, you need check whether you have all necessary packages installed for Android build. Refer to "Setting up your machine" on Android web site.
Note:
Install JDK1.5 instead of JDK1.6, otherwise error may occur during "make sdk"
Unpack i.MX Android Release Package
After setup Linux PC, you need unpack FSL i.MX Android Release Package:
$ cd /opt (or any other directory you like)
$ tar xzvf imx-android-r2.tar.gz
$ cd imx-android-r2/code
$ tar xzvf android-R2.tar.gz
Get some useful tools ready
ATK is a windows based tool which we will use to erase and program NAND. We will use it to program kernel image into NAND later.
Please install it in advance according to it's user guide which is included this release package.
If you don't have built your own compiler, you can use the prebuilt gcc cross-compiler in release package for kernel compile:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ cd /opt/imx-android-r2/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
Export below environment variables (e.g. in your ~/.profile)
so that you don't need set them manually each time when compiling kernel:
$ 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-
And it's always useful to setup tftp server (for kernel loading to board) and nfs server (for file system mounting)
Install/configuration steps are not described here.
We will assume the following directory name in the whole guide:
tftp server: /opt/tftproot as tftp server root
nfs server: /opt/nfsroot as nfs server root
Trial Android with prebuilt image
If you'd like to trial Android before building any code, you can use those prebuilt images under image/.
You can either run Android from TFTP/NFS or load/run Android from NAND by following steps in "Load and run".
Get Android source code
Android soruce code is maintained as more than 100 gits in Android repository (Visit GitWeb from browser).
To get Android source code from Google repo, follow the steps:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ 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
$ cp /opt/imx-android-r2/code/R2/default.xml .repo/manifests/default.xml (To avoid loading unnecessary gits from Google repo)
$ ./repo sync
Also need 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.26.y.git kernel_imx
To build Android for i.MX based platform, you need apply i.MX related patches to Android source code and then build Android image and kernel image separately.
Patch code for i.MX
Apply all i.MX Android patch with following steps:
Assume you had unzipped i.MX Android release package to /opt/imx-android-r2/.
$ cd ~/myandroid
$ . /opt/imx-android-r2/code/R2/and_patch.sh
$ help
Now you should see "c_patch" function is available for you
$ c_patch /opt/imx-android-r2/code/R2 imx_R2
Here "/opt/imx-android-r2/code/R2" is the location of the patches (i.e. directory created when you unzip release package)
"imx_R2" 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_R2".
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) utilize some basic utilities like awk/sed. If they are not available on your LinuxPC, install them in advance.
Build Android image
After applying all i.MX patches, you can build Android image by following steps:
$ cd ~/myandroid
$ make PRODUCT-imx51_3stack-eng | tee build_imx51_3stack_android.log
"imx51_3stack" is the product name (see ~/myandroid/vendor/fsl/product)
After build, check build_imx51_3stack_android.log to make sure no error.
With a successful build, you will get below outputs under ~/myandroid/out/target/product/imx51_3stack/:
* system.img and userdata.img
File system image (in UBIFS) to programmed into NAND flash if you want to run Android from NAND
* root/,system/,data/
Directory which can be used as Android file system if you want to run Android via NFS
Build kernel image
If you want to run Android via NFS, then you can build kernel with default config now:
$ cd ~/myandroid/kernel_imx
Note! There is another kernel dir "~/myandroid/kernel". Don't use it
$ echo $ARCH && echo $CROSS_COMPILE
Make sure you have those 2 environment variables set
$ make imx51_3stack_defconfig
Generate ".config" according to default config file under arch/arm/configs.
$ make -j2
If you want to run Android directly from NAND flash, then you will need config kernel using RAMDISK as rootfs:
$ cd ~/myandroid/kernel_imx
Note! There is another kernel dir "~/myandroid/kernel". Don't use it
$ echo $ARCH && echo $CROSS_COMPILE
Make sure you have those 2 environment variables set
$ make imx51_3stack_defconfig
Generate ".config" according to default config file under arch/arm/configs.
Use imx31_3stack_defconfig for i.MX31 instead
$ make menuconfig
"General Setup" -> Select "Initial RAM filesysttem and RAM disk (initramfs/initrd) support" option
And set "Initramfs source file" below the above option to the "root/" dir generated during above Android build, i.e.
"~/myandroid/out/target/product/imx51_3stack/root"
NOTE! Replace "~" with absolute path here.
Now build kernel
$ make -j2
-j2可以提高编译的速度
With a successful build in either of above 2 cases, you will get the generated kernel image as ~/myandroid/kernel_imx/arch/arm/boot/zImage
编译完,就是如何去在我们的板子上运行的问题了,这个有其他文档说明指导。