从源代码编译Android 11系统

Google 建议使用 Linux 的发行版 Ubuntu 来编译 Android 固件。 编译Android固件,需要根据需要在Ubuntu PC上搭建合适的环境。

编译准备

编译Android需要很高的机器配置:

  • 64位系统 (打开系统设置 –> 关于 –> xx-bit系统来检查这项)

  • 16GB 物理内存 + 交换内存 (打开系统设置 –> 关于 –> xx 内存来检查这项)

  • 250GB 可用磁盘空间 (打开终端 –> 输入“df -h”命令来检查) 官方推荐的是 Ubuntu 18.04 操作系统。 (打开系统设置–>关于–>系统版本来检查这项) 编译环境的初始化可以参考 http://source.android.com/source/initializing.html .

Download Source Code

下载Edge 2 Android SDK压缩包,然后解压生成repo-edge2目录,推荐使用http的下载工具(如freedownloadmanager)下载Edge 2 Android SDK压缩包。 注意:购买了 Mixte Edge 2 的客户将收到一封电子邮件,邮件包含下载Edge 2 Android SDK压缩包的链接,请查收电子邮件。 如果未收到邮件,您可能需要手动向info@mixtile.com索取Edge 2 Android SDK

准备好 Edge 2 Android SDK 包后,请执行以下命令:

tar -xzvf mixtile-edge2_android11_sdk.tar.gz

Clone the kernel repository (If there is error, please run it again)

cd repo-edge2
git clone https://github.com/mixtile/linux.git -b  mixtile/edge2/android11/kernel4.19/pad kernel

构建编译环境

为了不影响主机环境的配置,推荐使用docker来构建编译环境

在 Ubuntu 上安装 Docker

如果已存在,请先删除旧的docker

sudo apt-get remove docker docker-engine docker.io containerd runc

安装docker

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce

测试docker

sudo docker run hello-world

Below is the result after running above command:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  (amd64)
3. The Docker daemon created a new container from that image which runs the
  executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
  to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

下载Dockerfile文件

It is recommended to download the correct Dockerfile by the following URL. If necessary, you can refer to and modify the Dockerfile to meet your requirements. Please download here the Dockerfile.zip

生成Docker镜像文件

After download correct dockerfile, follow the below steps.

  1. Unzip the Dockerfile.zip which you downloaded just now.

  2. Enter the Dockerfile folder which you just unzipped, change the file name from “Dockerfile.txt” to “Dockerfile”

  3. Please perform the following operations in the same directory as “Dockerfile”

sudo docker build -t edge2_build_env .

If generating is successful, the following information will be printed to the terminal and it’s the last sentence:

Successfully tagged edge2_build_env:latest

引导编译环境

创建脚本

touch edge2-build.sh
chmod +x edge2-build.sh

(edge2-build.sh could be created in any folder)

the content of this script can be referred to as follows, you can copy the following content into the script

#!/bin/bash
export ANDROID_BUILD_TOP=/home/userx/xxx/repo-edge2
sudo docker run -it --rm -v $ANDROID_BUILD_TOP:/build edge2_build_env:latest

note:

ANDROID_BUILD_TOP: absolute path of local source code
/build: absolute path of source code in docker environment
edge2_build_env:latest: docker image for build aosp

引导脚本启动

./edge2-build.sh

The message of terminal after perform script

root@c9fa6274dd9f:/#
root@c9fa6274dd9f:/# cd build/
root@c9fa6274dd9f:/build# ls -l
total 172
lrwxrwxrwx 1 1000 1000 19 Dec 7 08:14 Android.bp -> build/soong/root.bp
-r--r--r-- 1 1000 1000 92 Dec 7 08:14 Makefile
drwxr-xr-x 4 1000 1000 4096 Dec 7 08:14 RKDocs
drwxr-xr-x 5 1000 1000 4096 Dec 7 08:14 RKTools
drwxr-xr-x 35 1000 1000 4096 Dec 7 08:14 art
drwxr-xr-x 15 1000 1000 4096 Dec 7 08:14 bionic
drwxr-xr-x 3 1000 1000 4096 Dec 7 08:14 bootable
lrwxrwxrwx 1 1000 1000 26 Dec 7 08:14 bootstrap.bash -> build/soong/bootstrap.bash
drwxr-xr-x 5 1000 1000 4096 Dec 7 08:14 build
lrwxrwxrwx 1 1000 1000 46 Dec 7 08:15 build.sh -> device/rockchip/common/build/rockchip/build.sh
drwxr-xr-x 3 1000 1000 4096 Dec 7 08:14 compatibility
drwxr-xr-x 14 1000 1000 4096 Dec 7 08:14 cts
drwxr-xr-x 8 1000 1000 4096 Dec 7 08:15 dalvik
drwxr-xr-x 5 1000 1000 4096 Dec 7 08:15 developers
drwxr-xr-x 21 1000 1000 4096 Dec 7 08:15 development
drwxr-xr-x 8 1000 1000 4096 Dec 7 08:15 device
drwxr-xr-x 322 1000 1000 12288 Dec 7 08:17 external
drwxr-xr-x 16 1000 1000 4096 Dec 7 08:25 frameworks
drwxr-xr-x 13 1000 1000 4096 Dec 7 08:18 hardware
-r--r--r-- 1 1000 1000 162 Dec 7 08:15 javaenv.sh
drwxr-xr-x 20 1000 1000 4096 Dec 7 08:18 libcore
drwxr-xr-x 8 1000 1000 4096 Dec 7 08:18 libnativehelper
drwxr-xr-x 11 1000 1000 4096 Dec 7 08:18 mkcombinedroot
-r-xr-xr-x 1 1000 1000 9093 Dec 7 08:15 mkimage.sh
-rwxrwxr-x 1 1000 1000 10503 Feb 18 08:55 mkimage_ab.sh
drwxr-xr-x 9 1000 1000 4096 Dec 7 08:19 packages
drwxr-xr-x 6 1000 1000 4096 Dec 7 08:19 pdk
drwxr-xr-x 10 1000 1000 4096 Dec 7 08:19 platform_testing
drwxr-xr-x 33 1000 1000 4096 Dec 7 08:25 prebuilts
-r-xr-xr-x 1 1000 1000 519 Dec 7 08:25 restore_patches.sh
drwxr-xr-x 9 1000 1000 4096 Mar 29 06:57 rkbin
drwxr-xr-x 5 1000 1000 4096 Dec 7 08:25 rkst
drwxr-xr-x 24 1000 1000 4096 Dec 7 08:25 sdk
drwxr-xr-x 44 1000 1000 4096 Jan 19 06:56 system
drwxr-xr-x 10 1000 1000 4096 Dec 7 08:25 test
drwxr-xr-x 4 1000 1000 4096 Dec 7 08:25 toolchain
drwxr-xr-x 23 1000 1000 4096 Dec 7 08:26 tools
drwxr-xr-x 29 1000 1000 4096 Mar 29 07:02 u-boot
drwxr-xr-x 7 1000 1000 4096 Dec 14 03:20 vendor

编译

编译统一固件

After booting script, the sdk is expanded in /build directory which on docker environment.

Note: When running “lunch mixtile_edge2-userdebug” command as below, it will take over 5 minutes, please keep patient and wait it to finish.

source build/envsetup.sh
lunch mixtile_edge2-userdebug
./build.sh -CKAUBuo

sdk compilation requires a long wait,after successful compilation, serval image files will be generated in directory rockdev/Image-mixtile_edge2

The image files will be named as image-release-ota-unknown.zip, image-release-unknown.img

cd rockdev/Image-mixtile_edge2
ls -l
baseparameter.img
boot-debug.img
boot.img
config.cfg
dtbo.img
image-release-mixtile_edge2-v1.0.7.img
image-release-ota-mixtile_edge2-v1.0.7.zip
MiniLoaderAll.bin
misc.img
parameter.txt
pcba_small_misc.img
pcba_whole_misc.img
resource.img
super.img
uboot.img
vbmeta.img

系统镜像描述

image-release-mixtile_edge2-v1.0.7.img is a unified firmware,this firmware needs to be upgraded by RKDevTool or making sd card that by Rockchip Create Upgrade Disk Tool,after upgrading this firmware, all user data will be lost,The field description is as follows:

image-release-: Fixed field, no meaning
mixtile_edge2: product name
v1.0.7: firmware version

image-release-ota-mixtile_edge2-v1.0.7.zip is a local update package,after upgrading this firmware, all user data will not be lost, this way is too simple,please refer to local upgrade doc.the field description of this firmware is the same as image-release-mixtile_edge2-v1.0.7.img

编译 u-boot

After u-boot source code is compiled, uboot.img will be packaged and generated. There are two ways to compile u-boot separately. ● Method 1 Enter the u-boot source directory to compile u-boot.

./make.sh mixtile-edge2

● Method 2 Enter the sdk source directory to compile u-boot.

source build/envsetup.sh
lunch mixtile_edge2-userdebug
./build.sh -U

After the compilation is complete, enter the source directory of u-boot to find the uboot.img. uboot.img can be burned into the Edge 2 independently by burning tool. Please refer to Update Firmware for more details.

编译内核

Kernel source code is compiled to generate kenrel.img and resource.img, which are finally compiled and packaged as boot.img by Android.

source build/envsetup.sh
lunch mixtile_edge2-userdebug
./build.sh -CKA

After the compilation is complete, enter the out/target/product/mixtile-edge2 directory, and you can find boot.img, which can be burned to the Edge 2 motherboard with the burning tool separately. For more details, please refer to Update Firmware.

编译Android系统

After the Android source code is compiled, super.img is finally generated.

source build/envsetup.sh
lunch mixtile_edge2-userdebug
./build.sh -A

After the compilation is complete, super.img can be found in the out/target/product/mixtile-edge2 directory. It can be burned to the Edge 2 motherboard separately with the burning tool. For more details, please refer to Update Firmware.