Required PackagesAndroid 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.
apt-get install flex bison gperf libesd0-dev libwxgtk2.6-dev zlib1g-dev build-essential安装好jdk 1.5.0并在/etc/profile中设置好导出的环境变量# Begin set java environmentexport JAVA_HOME=/opt/java/jdk1.5.0_22export JRE_HOME=/opt/java/jdk1.5.0_22/jreexport CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATHexport 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 xzv 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
kernelimx51_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 > ./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]
由于我们生成了nopading的uboot,我们直接执行前者语句即可,烧写uboot后上电测试.
进入uboot目录
cd workdir/freescale/android/bootable/bootloader/uboot-imx/
生成nopading的uboot
sudo dd if=./u-boot.bin of=./u-boot-no-padding.bin bs=1024 skip=1
148+1 records in
148+1 records out
151952 bytes (152 kB) copied,0.000897465 秒,169 MB/秒
该命令参数的含义
skip = blocks 跳过读入缓冲区开头的ibs*blocks块。
bs=bytes同时设置读写块的大小为 bytes ,可代替 ibs 和 obs 。
烧写uboot
sudo dd if=u-boot-no-padding.bin of=/dev/sdb bs=1K seek=1
148+1 records in
148+1 records out
151952 bytes (152 kB) copied,0.202129 秒,752 kB/秒
seek=blocks 从输出文件开头跳过 blocks 个块后再开始复制。(通常只有当输出文件是磁盘或磁带时才有效)
设置为uboot启动模式,并上电测试:
Setup the correct boot DIP configuration.
i.MX51 BBG3, load bootloader from SD:
* 7/8 ON; all others off
view plaincopy to clipboardprint?
U-Boot
2009.08-00099-gc1a8812 ( 6月 22 2010 - 15:55:43)
CPU: Freescale i.MX51 family 3.0V at 800 MHz
mx51 pll1: 800MHz
mx51 pll2: 665MHz
mx51 pll3: 216MHz
ipg clock : 66500000Hz
ipg per clock : 665000000Hz
uart clock : 66500000Hz
cspi clock : 54000000Hz
Board: MX51 BABBAGE 3.0 [POR]
Boot Device: MMC
DRAM: 512 MB
MMC: FSL_ESDHC: 0
*** Warning - bad CRC or MMC, using default environment
In: serial
Out: serial
Err: serial
Press home + power to enter recovery mode ...
Net: FEC0 [PRIME]
Hit any key to stop autoboot: 0
Unknown command 'mmcinit' - try 'help'
Wrong Image Format for bootm command
ERROR: can't get kernel image!
BBG U-Boot >
分别写入内核与文件系统到SD卡中,用dd或tftp均可.
Use dd on Linux PC to program kernel and ramdisk rootfs into SD:
# dd if=your_kernel_uImage of=/dev/sdb bs =1M seek=1
# dd if=your_uramdisk of=/dev/sdb bs =4M seek=1
sudo dd if=arch/arm/boot/uImage of=/dev/sdb bs=1M seek=1
2+1 records in
2+1 records out
2352920 bytes (2.4 MB) copied,0.504715 秒,4.7 MB/秒
sudo dd if=out/target/product/imx51_BBG/uramdisk.img of=/dev/sdb bs=4M seek=1
0+1 records in
0+1 records out
207807 bytes (208 kB) copied,0.0672214 秒,3.1 MB/秒
Next, program the Android file system image into each partition.
If you are using the prebuilt image, pick up the correct Android file system image (see "Prebuilt image for using uboot ")
If you are building your own image, the images (system.img , userdata.img , recovery.img ) are generated under out/target/product/imx51_BBG
# dd if=your_system.img of=/dev/sdb2 (Program system.img into SYSTEM partition which will be mounted as "/system")
# dd if=your_recovery.img of=/dev/sdb4 (Program recovery.img into RECOVERY partition which will mounted as "/" in recovery mode)
sudo dd if=out/target/product/imx51_BBG/system.img of=/dev/sdb2
187536+0 records in
187536+0 records out
96018432 bytes (96 MB) copied,51.4244 秒,1.9 MB/秒
sudo dd if=out/target/product/imx51_BBG/recovery.img of=/dev/sdb4
9184+0 records in
9184+0 records out
4702208 bytes (4.7 MB) copied,4.43228 秒,1.1 MB/秒
Note: You can dd userdata.img if there are files to be added. Make sure data partition size is set correctly in session TARGET_USERIMAGES_BLOCKS : = 204800 of file vendor/fsl/imx51_BBG/BoardConfig.mk.
插入SD卡,启动设备,进入uboot命令行,执行:
BBG U-Boot > setenv bootcmd 'run bootcmd_SD1 bootcmd_SD2'
BBG U-Boot > setenv bootcmd_SD1 'run bootargs_base bootargs_android bootargs_SD '
BBG U-Boot > setenv bootcmd_SD2 'mmc read 0 ${loadaddr } 0x800 0x1280;mmc read 0 ${rd_loadaddr } 0x2000 0x258;bootm ${loadaddr} ${rd_loadaddr }'
BBG U-Boot > setenv bootargs_base 'setenv bootargs console=ttymxc0,115200'
BBG U-Boot > setenv bootargs_SD 'setenv bootargs ${bootargs }'
BBG U-Boot > setenv bootargs_android 'setenv bootargs ${bootargs } init=/init androidboot.console =ttymxc0 wvga calibration'
BBG U-Boot > setenv loadaddr 0x90800000
BBG U-Boot > setenv rd_loadaddr 0x90B00000
BBG U-Boot > saveenv
第一次启动需要校准触摸屏,请认真设置,如果设置不准确用起来就麻烦了.
对于在windows上使用adb工具,安装好对应驱动即可.
在ubuntu linux上使用adb工具或adt工具连接物理设备,google的文档中有描述:
If you're developing on Ubuntu Linux, you need to add a rules file that contains a USB configuration for each type of device you want to use for development. Each device manufacturer uses a different vendor ID. The example rules files below show how to add an entry for a single vendor ID (the HTC vendor ID). In order to support more devices, you will need additional lines of the same format that provide a different value for the SYSFS{idVendor} property. For other IDs, see the table of USB Vendor IDs below.
Log in as root and create this file: /etc/udev/rules.d/51-android.rules .
For Gusty/Hardy, edit the file to read:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
For Dapper, edit the file to read:
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
但是实际上的USB Vendor ID的表并不正确
在这里我使用下面的方法解决
1.插拔连接设备的USB线,并分别用lsusb打印 usb信息.
我们可以看到我们的vendor信息, High Tech Computer Corp.为我们的设备.
lsusb
Bus 002 Device 093: ID 0bb4:0c02 High Tech Computer Corp.
Bus 002 Device 082: ID 14cd:8123 Super Top
Bus 002 Device 075: ID 046d:c01f Logitech, Inc.
Bus 002 Device 028: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 004: ID 0c45:6450 Microdia
Bus 002 Device 002: ID 8087:0020
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hup.
将 /etc/udev/rules.d/51- android.rules中vendor值修改为 0bb4使用eclipse的adt工具连接,正常.
可以加载hello world测试.正常.
加载歌曲到sd卡媒体分区中,播放歌曲,无声音,原因是 codec没有编译进去,现在把codec加载并编译.