diff --git a/docs/howto-setup-build-env.md b/docs/howto-build-aosp-riscv.md similarity index 100% rename from docs/howto-setup-build-env.md rename to docs/howto-build-aosp-riscv.md diff --git a/docs/howto-build-emu-riscv.md b/docs/howto-build-emu-riscv.md new file mode 100644 index 0000000000000000000000000000000000000000..d8de545a54ff37c51f8ce8ea7ae40561da61698e --- /dev/null +++ b/docs/howto-build-emu-riscv.md @@ -0,0 +1,144 @@ +**How to build android emulator for riscv** + + + +- [1. Hardware environment](#1-hardware-environment) +- [2. Install dependent software](#2-install-dependent-software) +- [3. Install repo](#3-install-repo) +- [4. Download source code](#4-download-source-code) +- [5. Build](#5-build) + - [5.1. Incremental builds](#51-incremental-builds) + - [5.2. Speeding up builds with ‘ccache’](#52-speeding-up-builds-with-ccache) +- [6. Test with the generated AOSP system image](#6-test-with-the-generated-aosp-system-image) + + + +# 1. Hardware environment + +All operations in this article have been verified under the following system environment: + +``` +$ lsb_release -a +No LSB modules are available. +Distributor ID: Ubuntu +Description: Ubuntu 18.04.6 LTS +Release: 18.04 +Codename: bionic +``` + +# 2. Install dependent software + +``` +$ sudo apt-get install -y git build-essential python qemu-kvm ninja-build \ + python-pip ccache +``` + +# 3. Install repo + +First we need to obtain the repo tool. + +``` +$ mkdir $HOME/bin +$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > $HOME/bin/repo +$ chmod 700 $HOME/bin/repo +``` + +Make sure to add `$HOME/bin` to your path, if it is not already there. + +``` +export PATH=$PATH:$HOME/bin +``` + +Do not forget to add this to your `.bashrc` file. + +After the installation is complete, you can run `repo version` to check the effect. An output similar to the following shows that the installation is successful. The repo version needs to be 2.15 or higher. + +``` +$ repo version + +repo launcher version 2.17 + (from /home/wangchen/bin/repo) +git 2.17.1 +Python 3.6.9 (default, Jan 26 2021, 15:33:00) +[GCC 8.4.0] +OS Linux 4.15.0-144-generic (#148-Ubuntu SMP Sat May 8 02:33:43 UTC 2021) +CPU x86_64 (x86_64) +Bug reports: https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue +``` + +# 4. Download source code + +Create an emulator source code build directory, here assume it is `/home/u/emu-master-dev`, and then enter the directory. + +``` +$ mkdir -p /home/u/emu-master-dev && cd /home/u/emu-master-dev +``` + +After entering the build directory, execute the following command to download +the source code. + +``` +$ repo init -u git@github.com:aosp-riscv/platform_manifest -b riscv64-emu-master-dev +$ repo sync -j8 +``` + +# 5. Build + +``` +$ cd external/qemu && android/rebuild.sh +``` + +If all goes well you should have a freshly build emulator in the objs directory. + +You can pass the flag `--help` to the rebuild script to get an idea of which +options you can pass in. + +## 5.1. Incremental builds + +The rebuild script does a complete clean build. You can use ninja to partial builds: + +``` +$ ninja -C objs +``` + +## 5.2. Speeding up builds with ‘ccache’ + +It is highly recommended to install the ‘ccache’ build tool on your development +machine(s). The Android emulator build scripts will probe for it and use it if +available, which can speed up incremental builds considerably. + +``` +sudo apt-get install ccache +``` + +# 6. Test with the generated AOSP system image + +It is also possible to try booting an Android system image built from a fresh +AOSP platform checkout. One has to select an emulator-compatible build product, +e.g.: + +``` +$ cd $AOSP/ +$ . build/envsetup.sh +$ lunch sdk_phone_arm64-eng +$ make -j8 +``` + +Recommended build products are 'sdk_phone_arm64-eng ' or 'sdk_phone_x86_64-eng'. + +To boot the generated system image: + +``` +$ cd /home/u/emu-master-dev/external/qemu +$ ./android/rebuild.sh +$ export ANDROID_BUILD_TOP=/path/to/aosp +$ objs/emulator +``` + +Note: +- If you want to launch emulator without GUI(headless mode), you can add + `-no-window` option. +- If you see error: "pulseaudio: Failed to initialize PA contextaudio: Could not + init `pa' audio driver", you can add `-no-audio` option. +- If you see error: "PCI bus not available for hda", you can add `-qemu -machine virt`. +- If you want to see kernel log in headless mode, you can add `-show-kernel` option. \ No newline at end of file diff --git a/docs/zh/howto-setup-build-env.md b/docs/zh/howto-build-aosp-riscv.md similarity index 72% rename from docs/zh/howto-setup-build-env.md rename to docs/zh/howto-build-aosp-riscv.md index 063accfab126930cbbdf1271b61ce873faddb8d2..00221f1426f832bd982d2c25f836cdfb5b50c165 100644 --- a/docs/zh/howto-setup-build-env.md +++ b/docs/zh/howto-build-aosp-riscv.md @@ -37,16 +37,16 @@ $ sudo apt install git-core gnupg flex bison build-essential zip curl zlib1g-dev # 3. 安装 repo +下载(参考 [清华大学开源软件镜像站 Git Repo 镜像使用帮助](https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/)) + ``` -$ mkdir ~/bin -$ export PATH=~/bin:$PATH -$ export REPO=$(mktemp /tmp/repo.XXXXXXXXX) -$ curl -o ${REPO} https://storage.googleapis.com/git-repo-downloads/repo -$ gpg --keyserver keyserver.ubuntu.com --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65 -$ curl -s https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ${REPO} && install -m 755 ${REPO} ~/bin/repo +$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo +$ chmod +x repo ``` +为了方便可以将其拷贝到你的 PATH 里。 -其中 export 的 PATH 以后可以写入 `~/.bashrc` 文件中去,避免以后每次定义。 +repo 运行过程中会尝试访问官方的 git 源更新自己,如果想使用 tuna 的镜像源进行更新,可以 +将如下内容复制到你的 `~/.bashrc` 里并重启终端生效。 安装好后可以运行 `repo version` 检查效果,出现类似以下输出说明安装成功。repo 版本需要 2.15 以上。 @@ -63,8 +63,6 @@ CPU x86_64 (x86_64) Bug reports: https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue ``` -如果你的机器是在中国大陆内还需要定义并导出一个环境变量:`export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'`,否则在后面执行 repo init 的时候会默认去 google 的网站下载 repo 的第二阶段,但由于网络原因会导致连接不上,所以改成国内的 git-repo 镜像地址。其中 export 的 PATH 以后可以写入 `~/.bashrc` 文件中去,避免以后每次定义。 - # 4. 下载源码 创建一个 AOSP 的源码构建目录,这里假设为 `/home/u/aosp`,然后进入 aosp 目录 diff --git a/docs/zh/howto-build-emu-riscv.md b/docs/zh/howto-build-emu-riscv.md new file mode 100644 index 0000000000000000000000000000000000000000..04c74d904d2913fea719a698077aa3f6aeddb1be --- /dev/null +++ b/docs/zh/howto-build-emu-riscv.md @@ -0,0 +1,140 @@ +**如何编译 android emulator** + +注:提供此文档为方便国内参与小伙伴。 + + + +- [1. 硬件环境](#1-硬件环境) +- [2. 安装依赖软件](#2-安装依赖软件) +- [3. 安装 repo](#3-安装-repo) +- [4. 下载源码](#4-下载源码) +- [5. 构建](#5-构建) + - [5.1. 增量构建](#51-增量构建) + - [5.2. 使用 “ccache” 加速构建](#52-使用-ccache-加速构建) +- [6. 使用生成的 AOSP 系统映像进行测试](#6-使用生成的-aosp-系统映像进行测试) + + + +# 1. 硬件环境 + +本文所有操作在以下系统环境下验证通过: + +``` +$ lsb_release -a +No LSB modules are available. +Distributor ID: Ubuntu +Description: Ubuntu 18.04.6 LTS +Release: 18.04 +Codename: bionic +``` + +# 2. 安装依赖软件 + +``` +$ sudo apt-get install -y git build-essential python qemu-kvm ninja-build \ + python-pip ccache +``` + +# 3. 安装 repo + +下载(参考 [清华大学开源软件镜像站 Git Repo 镜像使用帮助](https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/)) + +``` +$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo +$ chmod +x repo +``` +为了方便可以将其拷贝到你的 PATH 里。 + +repo 运行过程中会尝试访问官方的 git 源更新自己,如果想使用 tuna 的镜像源进行更新,可以 +将如下内容复制到你的 `~/.bashrc` 里并重启终端生效。 + +``` +export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo' +``` + +安装好后可以运行 `repo version` 检查效果,出现类似以下输出说明安装成功。repo 版本需要 2.15 以上。 + +``` +$ repo version + +repo launcher version 2.17 + (from /home/wangchen/bin/repo) +git 2.17.1 +Python 3.6.9 (default, Jan 26 2021, 15:33:00) +[GCC 8.4.0] +OS Linux 4.15.0-144-generic (#148-Ubuntu SMP Sat May 8 02:33:43 UTC 2021) +CPU x86_64 (x86_64) +Bug reports: https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue +``` + +# 4. 下载源码 + +创建一个模拟器源码构建目录,这里假设是`/home/u/emu-master-dev`,然后进入该目录。 + +``` +$ mkdir -p /home/u/emu-master-dev && cd /home/u/emu-master-dev +``` + +进入构建目录后,执行以下命令下载源代码。 + +``` +$ repo init -u git@github.com:aosp-riscv/platform_manifest -b riscv64-emu-master-dev +$ repo sync -j8 +``` + +# 5. 构建 + +``` +$ cd external/qemu && android/rebuild.sh +``` + +如果一切顺利,你应该在 objs 目录中看到生成的模拟器。 + +您可以在运行 `rebuild.sh` 脚本时带上 `--help` 查看更多帮助。 + +## 5.1. 增量构建 + +`rebuild.sh` 脚本会进行完全干净的构建。 您可以使用 ninja 进行部分构建: + +``` +$ ninja -C objs +``` + +## 5.2. 使用 “ccache” 加速构建 + +强烈建议在您的开发中安装 “ccache”, Android 模拟器构建脚本将探测它并使用它, 这可以大大 +加快增量构建的速度。 + +``` +sudo apt-get install ccache +``` + +# 6. 使用生成的 AOSP 系统映像进行测试 + +可以尝试使用基于 AOSP 源码做出来的 Android 系统映像来启动我们自己构建的模拟器。基于 AOSP +源码制作 Android 系统镜像首先要选择一个支持模拟器的产品,例如: + +``` +$ cd $AOSP/ +$ . build/envsetup.sh +$ lunch sdk_phone_arm64-eng +$ make -j8 +``` + +推荐选择的产品类型有 'sdk_phone_arm64-eng' 或者 'sdk_phone_x86_64-eng'。 + +利用我们自己构建的模拟器启动 AOSP 系统镜像的方法如下: + +``` +$ cd /home/u/emu-master-dev/external/qemu +$ ./android/rebuild.sh +$ export ANDROID_BUILD_TOP=/path/to/aosp +$ objs/emulator +``` + +注意: +- 如果您想在没有图形界面的的模式(headless mode)下启动模拟器,您可以添加 `-no-window` 选项。 +- 如果您看到错误:“pulseaudio: Failed to initialize PA contextaudio: Could not + init 'pa' audio driver”,您可以添加 `-no-audio` 选项。 +- 如果您看到错误:“PCI bus not available for hda”,您可以添加 `-qemu -machine virt`。 +- 如果您想在 headless mode 下查看内核日志,可以添加 `-show-kernel` 选项。