Build x86 Android for PC like EeePC

来源:互联网 发布:ims 的数据是什么 编辑:程序博客网 时间:2024/04/30 09:37

关于如何获取Android源代码,也可以参考http://source.android.com/download.

 

1. 准备Build环境

安装Ubuntu 32bit x86,然后更新所需的开发包以及工具。

$ 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

$ sudo apt-get install valgrind

 

2. 安装Repo工具
  $ cd ~
  $ mkdir bin

  $ export PATH=$PATH:~/bin
  $ echo $PATH

  下载Repo工具
  $ curl http://android.git.kernel.org/repo >~/bin/repo

  $ chmod a+x ~/bin/repo 

3. 初始化Repo Client
$ mkdir android_x86 && cd android_x86
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
$ repo sync

这里repo sync可能要花很长时间,中间还可能断掉,可以编写一个shell脚本来做sync,断掉后自动重试,命名为repo_sync.sh:

$ gedit repo_sync.sh

#!/bin/bash
echo "============start repo sync================="
repo sync
while [ $? = 1 ]; do
echo "============sync failed, re-sync again ====="
sleep 3
repo sync
done

创建local_manifest.xml文件
$ vi ./.repo/local_manifest.xml

<?xml version="1.0" encoding="UTF-8"?>
  <manifest>
    <project name="platform/vendor/asus/eee_701" path="vendor/asus/eee_701"/>
  </manifest>

$ repo sync

4. 开始Build android x86代码
开始build前,可以到http://code.google.com/p/patch-hosting-for-android-x86-support/下载一些patch.

下载后可以通过下面脚本把所有patch都打上:

 

for patch in `pwd`/../*patch ; do
project=`awk '/^project /{print $2}' $patch`
(cd $project && patch -p1 < $patch)
done

 

然后开始build:
$ TARGET_ARCH=x86 TARGET_PRODUCT=eee_701 DISABLE_DEXPREOPT=true make -j2 installer_img

 

Build 成功后,通过下面命令查看产生的结果文件:

$ ls -lh out/target/product/eee_701/

$ file out/target/product/eee_701/installer.img

$ file out/target/product/eee_701/system.img

$ file out/target/product/eee_701/userdata.img

$ sudo mount -o loop boot.img /mnt

$ cat /mnt/cmndline
console=tty0 console=ttyS1,115200n8 console=tty0
androidboot.hardware=eee_701

 

$ cp /mnt/ramdisk /tmp/ramdisk.gz
$ cd /tmp
$ gunzip ramdisk.gz
$ cpio -iv < ramdisk
sys
init.goldfish.rc
system
data
init.rc
proc
init
default.prop
sbin
sbin/adbd
init.eee_701.rc
lib
lib/modules
lib/modules/i915.ko
lib/modules/font.ko
lib/modules/drm.ko
lib/modules/cfbcopyarea.ko
lib/modules/cfbimgblt.ko
lib/modules/bitblit.ko
lib/modules/cfbfillrect.ko
lib/modules/softcursor.ko
lib/modules/fbcon.ko
lib/modules/atl2.ko
dev
2955 blocks

 

$ file /tmp/init
/tmp/init: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
statically linked, not stripped

 

5. 最后制作U盘安装盘

使用fdisk或者gparted来对U盘分区,划成一个Primary Partition, bootable分区,然后格式化成ext2或ext3文件系统。

对U盘设备进行分区时,可以用 sudo fdisk -l /dev/<usbstick device no>(不带后面标号sdb,而不是sdb1).


$ dd if=out/target/product/eee_701/installer.img of=/dev/<usbstick device no>(不带后面标号sdb,而不是sdb1)

或者用GUI 工具usb-imagewriter.

 

6.我们也可以直接从另外一个小组的代码分支来sync x86-port代码,不用打patch,直接build就可以,可以参考http://code.google.com/p/android-x86/wiki/GetSourceCode

这个会产生一个eeepc.iso可以直接刻录成光盘运行,也可以installer.img成U盘安装,另外还可以制作U盘运行版:

  • partition your USB drive with fdisk or gpartd and mark the partition as bootable
  • format that partition to ext3 (recommended) or vfat.
  • mount your usb drive to /mnt
  • cd /mnt
  • grub-install --root-directory=. --no-floppy /dev/<your usb device node name>(like /dev/sdb, not /dev/sdb1) 
  • cd /boot/grub
  • create your menu.lst
title Run Android
kernel
/android/kernel root=/dev/ram0 androidboot.hardware=eeepc SRC=/android
initrd /
android/initrd.img

title
Run Android (VESA mode)
kernel
/android/kernel root=/dev/ram0 androidboot.hardware=eeepc vga=788 SRC=/android
initrd /
android/initrd.img

title
Run Android (Debug mode)
kernel
/android/kernel root=/dev/ram0 androidboot.hardware=eeepc vga=788 SRC=/android DEBUG=1
initrd /
android/initrd.img
  • create /android directory in the USB disk, and copy the four files kernel initrd.img ramdisk.img system.sfs (or system.img if you set USE_SQUASHFS=0) to it.

 

7.还有另外一个小组发布的live-android,可以下载iso烧录成光盘直接运行,http://code.google.com/p/live-android/