Aosp risc-v 架构镜像编译笔记

First Post:
Last Update:

优先参考文档:

https://github.com/aosp-riscv/working-group/blob/master/docs/zh/howto-build-aosp-riscv.md

CN-gitee(清华镜像源拉取):

工作区:https://gitee.com/aosp-riscv/working-group

清单:https://gitee.com/aosp-riscv/platform_manifest

README文件引用:

如何编译 aosp-riscv

注:提供此文档为方便国内参与小伙伴。

1. 硬件环境

本文所有操作在以下系统环境下验证通过

1
2
3
4
5
6
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic

2. 安装依赖软件

1
2
3
4
$ sudo apt install git-core gnupg flex bison build-essential zip curl zlib1g-dev \
gcc-multilib g++-multilib libc6-dev-i386 libncurses5 \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev \
libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig python

3. 安装 repo

下载(参考 清华大学开源软件镜像站 Git Repo 镜像使用帮助

1
2
$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
$ chmod +x repo

为了方便可以将其拷贝到你的 PATH 里。

repo 运行过程中会尝试访问官方的 git 源更新自己,如果想使用 tuna 的镜像源进行更新,可以
将如下内容复制到你的 ~/.bashrc 里并重启终端生效。

安装好后可以运行 repo version 检查效果,出现类似以下输出说明安装成功。repo 版本需要 2.15 以上。

1
2
3
4
5
6
7
8
9
10
$ repo version
<repo not installed>
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. 下载源码

创建一个 AOSP 的源码构建目录,这里假设为 /home/u/aosp,然后进入 aosp 目录

1
2
$ mkdir -p /home/u/aosp
$ cd /home/u/aosp

进入 AOSP 构建目录后执行以下命令下载 AOSP 的源码

注:由于采用的是 Gitee 上的 aosp-riscv 开发仓库,以及采用国内清华源的 AOSP 镜像作为缺省 remote,将大大方便国内用户下载代码。

1
2
$ repo init -u git@gitee.com:aosp-riscv/platform_manifest.git -b riscv64-android-12.0.0_dev_cn
$ repo sync -j8

5. 编译

注意:因为还在开发过程中,当前还不支持完整的编译 m

下面是一个例子,编译 aosp 但不运行最终的 ninja 构建。

1
2
3
4
$ cd /home/u/aosp
$ source ./build/envsetup.sh
$ lunch aosp_riscv64-eng
$ m --skip-ninja

6. 构建 Clang llvm 工具链

1
2
3
4
$ mkdir llvm-toolchain && cd llvm-toolchain
$ repo init -u git@github.com:aosp-riscv/platform_manifest.git -b riscv64-llvm-master
$ repo sync -c
$ python toolchain/llvm_android/build.py

7. 构建 Rust 工具链

1
2
3
4
$ mkdir rust-toolchain && cd rust-toolchain
$ repo init -u git@github.com:riscv-android-src/manifest.git -b riscv64-android12-rust-toolchain-dev
$ repo sync -c
$ python toolchain-android_rust/build.py

以下为我个人尝试的操作:

安装依赖:

1
2
3
sudo apt-get install git build-essential python3  qemu-kvm  ninja-build python3-pip ccache
#python3和官方不一样 换成了python3 如果有问题请换回python2
#python3-pip和官方不一样 python-pip已经弃用

安装repo(官方和清华版本二选一):

1
2
3
mkdir $HOME/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > $HOME/bin/repo
chmod 700 $HOME/bin/repo

安装清华repo:

1
2
3
4
5
mkdir $HOME/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo > $HOME/bin/repo
chmod +x repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'#推荐添加
#详细介绍:https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/

添加到系统变量:

1
2
sudo nano /etc/profile
source /etc/profile #刷新变量

基本构建命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mkdir ~/riscv-android-src && cd ~/riscv-android-src
repo init -u git@gitee.com:aosp-riscv/platform_manifest.git -b riscv64-android-12.0.0_dev_cn
repo sync -j8
# 经测试,这部分命令并未生效
# cd prebuilts/rust/
# git lfs pull
# cd -
# cd prebuilts/clang/host/linux-x86/
# git lfs pull
# cd -
# rm external/angle/Android.bp
source build/envsetup.sh
lunch sdk_phone64_riscv64
m -j8

以下为报错和相关处理:

/usr/bin/env: “python”: 没有那个文件或目录——解决办法

如果没有安装Python,安装Python3.8

1
sudo apt-get install python3

如果安装了Python3.8,则没配置Python软链接

1
2
3
4
5
#找Python3.8位置
whereis python3.8
#配置软连接
cd /usr/bin
sudo ln -s /usr/bin/python3.8 python

报错:ERROR: Unable to locate libtinfo.so.5(下面还有一个解决办法)

README引用:

ubuntu19.04/Manjro编译Android Pie源码缺少libtinfo.so.5问题

背景

使用ubuntu19.04编译Android源码的时候,报缺少libtinfo.so.5

解决方法

通过find命令查看,发现确实没有这个文件,默认已经升级到libinfo.so.6版本了,搜索发现重装个包就可以了.

查看一下库:

1
2
ls /lib/x86_64-linux-gnu/libtinfo.so.* #查看一下库
/lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/libtinfo.so.6.2

安装缺少的库:

1
sudo apt install libncurses5

装完后,可能需要重启terminal才能生效

Manjaro

1
2
3
4
sudo pacman -S ncurses5-compat-libs
#或
sudo pacman -S libtinfo5
#这两条命令会安装一样的包

附软链接删除命令:

1
sudo rm libtinfo.so.5 #已测试有效性未测试安全性

来源:https://blog.csdn.net/yongwn/article/details/97610813

如果你发现你一直连不上git 说你没有权限 你可以先去生成个ssh再试试(不要像我个笨蛋一直以为自己网络有问题)

设置用户:

1
2
git config --global user.name "your name"
git config --globa user.email "your email.com"

生成密钥

1
2
ssh-keygen -t rsa -C "your_email@example.com" #记得把目录记录下来
ssh -T git@github.com #测试

编译时候有可能内存不够,需要点swap来帮助一下

1
2
3
4
5
6
7
8
9
cd / #到根目录
sudo mkdir swap
cd /swap/
sudo dd if=/dev/zero of=swapfile bs=1M count=20480 #新建20GBswap文件
sudo mkswap swapfile
sudo swapon swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swap/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab #将swapfile路径内容写入到/etc/fstab文件当中
free -h

/bin/bash: m4未找到命令:

1
sudo apt install m4 #m4是个什么奇怪东西

libncurses.so.5找不到:

1
2
3
4
5
6
7
8
9
ls /lib/x86_64-linux-gnu/libtinfo.so.* #查看一下库
#新版Ubuntu似乎没有这个库了
libncurses.so.5: cannot open shared object file: No such file or directory
sudo apt-get install libncurses5-dev
#不知道哪个有用 建议都试试(
sudo apt install apt-file
sudo apt-file update
sudo apt-file find libncurses.so.5
sudo apt install libncurses5

git:’lfs’ 不是一个 git 命令。参见 ‘git –help’:

1
sudo apt install git-lfs

repo sync多线程(效果很明显 推荐使用):

1
repo sync -j 4 #四个线程下载 默认为两个

Android repo技巧:repo sync同步Android源码时减少同步时间和代码空间
在使用 repo sync 同步 Android 源码时,可以添加一些选项来减少同步时间和要下载的代码空间。具体的命令是:

1
repo sync -c --no-tags --prune -j 4

查看 repo help status 的帮助信息,对所给的各个选项具体说明如下:

-c, –current-branch fetch only current branch from server.
这个选项指定只获取执行 repo init 时 -b 选项所指定的分支,不会获取远端服务器的分支信息。
例如服务器上新增了其他分支,使用 -c 选项同步后,在本地 git 仓库执行 git branch -r 命令看不到服务器新增的分支名。如果不加 -c 选项,那么同步的时候,会打印 [new branch] 这样的信息,使用 git branch -r 命令可查看到服务器新增的分支。

–no-tags don’t fetch tags.
该选项指定不获取服务器上的tag信息。
–prune delete refs that no longer exist on the remote.
如果远端服务器已经删除了某个分支,在 repo sync 时加上 --prune 选项,可以让本地仓库删除对这个分支的跟踪引用。

查看 repo 的 .repo/repo/project.py 源码,这个选项实际上是作为 git fetch 命令的选项来执行。查看 man git-fetch 对自身 --prune 选项的说明如下,可供参考:

-p, –prune
After fetching, remove any remote-tracking references that no longer exist on the remote.
-j JOBS, –jobs=JOBS projects to fetch simultaneously (default 2).
指定启用多少个线程来同步。
例如上面的 -j 4 指定用4个线程来同步。如果没有提供该选项,默认是用2个线程。

总的来说,在 repo sync -c --no-tags --prune -j 4 命令中,使用 -c 和 –no-tags 选项可以减少需要同步的内容,从而减少要占用的本地代码空间,也可以减少一些同步时间。

使用 -j 选项来指定启用多线程进行同步,可以加快执行速度,也就减少了同步时间。

使用 –prune 选项去掉已删除分支的跟踪引用,一般不会用到,这个选项可加可不加。

文章来源:https://segmentfault.com/a/1190000020983392

libstd_x86_64-unknown-linux-gnu错误:

The libtest_x86_64-unknown-linux-gnu lib is available in https://cs.android.com/android/platform/superproject/+/master:prebuilts/rust/linux-x86/1.58.0/lib/rustlib/x86_64-unknown-linux-gnu/lib/

This lib will be downloaded as part of AOSP code in prebuilts/rust.git. Try syncing this project again

1
repo sync prebuilts/rust

The sync was failing for me with below error:

1
error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function

After installing gnutls-bin package it synced successfully.

1
sudo apt install gnutls-bin

文章来源:https://stackoverflow.com/questions/68436057/how-to-fix-libtest-x86-64-unknown-linux-gnu-module-dependencies

基本的意思就是在prebuilts/rust目录下的文件并没有git同步成功,尝试重新拉取一下.以下是我的方法.

1
2
cd prebuilts/rust
repo sync #这边可以加个-j参数,多线程加快一下速度