Compiling Android 7.1

Preparation

Hardware Requiremnts

Recommended hardware requirement of development workstation compiling Android 7.1:

  • 64 bit CPU

  • 16GB Physical memory + Swap memory

  • 30GB Free disk space is used for building, and the source tree takes about 8GB

See also the hardware and software configuration stated in Google official document:

Software Requiements

Installing JDK 8

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk

Installing required packages

sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev \
  libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl \
  libncurses5-dev zlib1g-dev pngcrush schedtool libxml2 libxml2-utils \
  xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev \
  lib32readline-gplv2-dev gcc-multilib libswitch-perl

sudo apt-get install gcc-arm-linux-gnueabihf \
  libssl1.0.0 libssl-dev \
  p7zip-full

Downloading Android SDK

Due to the huge size of the Android SDK, please select one of the following clouds to download firefly_rk3328_android7.1_git_20211216:

After the download completes, verify the MD5 checksum before extraction:

$md5sum ~/firefly_rk3328_android7.1_git_20211216.7z.001
$md5sum ~/firefly_rk3328_android7.1_git_20211216.7z.002
$md5sum ~/firefly_rk3328_android7.1_git_20211216.7z.003

f4d62bfbb401f596328435e61cb1c68d  firefly_rk3328_android7.1_git_20211216.7z.001
0bb35911c8740119f789926d6d21c550  firefly_rk3328_android7.1_git_20211216.7z.002
19eebf52e1e033cea682cdd306d8f75a  firefly_rk3328_android7.1_git_20211216.7z.003

Then extract it:

mkdir -p  ~/proj/firefly_rk3328_android7.1
cd ~/proj/firefly_rk3328_android7.1
7z x ~/firefly_rk3328_android7.1_git_20211216.7z.001 -r -o.
git reset --hard

Synchronize source code from gitlab:

git pull gitlab roc-rk3328-pc:roc-rk3328-pc

git checkout roc-rk3328-pc

Compiling with Firefly Scripts

Automatic compilation

./build.sh roc-rk3328-pc

After executing the above command, it will compile the Uboot, kernel and upper layer of Android, sort out the partition Image and generate unified firmware update.img, and put it in the directory of rockdev/ image-roc_rk3328_pc_box /

Modular compilation

Compiling configuration file

./FFTools/make.sh roc-rk3328-pc (Note: "Compiling configuration file" is a prerequisite. You must complete this step before proceeding )

Compiling Kernel

./FFTools/make.sh -k -j8

Compiling U-Boot

./FFTools/make.sh -u -j8

Compiling Android

./FFTools/make.sh -a -j8

Compiling all Image

This will compile kernel, U-Boot and Android with a single command:

./FFTools/make.sh -j8

Compiling Without Script

Before compilation, execute the following commands to configure environment variables:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

Compiling Kernel

make ARCH=arm64 firefly_defconfig
make -j8 ARCH=arm64 rk3328-roc-pc.img

Compiling U-Boot

make rk3328_box_defconfig
make ARCHV=aarch64 -j8

Compiling Android

source build/envsetup.sh
lunch roc_rk3328_pc_box-userdebug
make installclean
make -j8
./mkimage.sh

Packing Rockchp Firmware

Packing Fimware in Linux

After compiling you can use Firefly official script to pack all partition image files into the one true Rockchip firmware or the one true original firmware, by executing the following command:

rk firmware:
./FFTools/mkupdate/mkupdate.sh update

The resulting file is rockdev/Image-roc_rk3328_pc_box/update.img.

The RK firmware needs to use the SD_Firmware_Tool tool and the function mode to select SD Startup to create the boot card

Packing Fimware in Windows

It is also very simple in packaging Rockchip firmware update.img under Windows:

  1. Copy all the compiled files in rockdev/Image-roc_rk3328_pc_box/ to the rockdev\Image directory of AndroidTool

  2. Run the mkupdate.bat batch file in the rockdev directory of AndroidTool.

  3. update.img will be created in rockdev\Image directory.

Partition Images

update.img is the firmware released to end users, which is convenient to upgrade the system of the deveopment board.

During development cycle, it is a great time saving to only flash modified partition images.

Here’s a table summarising the partition image in various stage:

|------------------|---------------------|-----------|
| Stage            | Product             | Partition |
|------------------|---------------------|-----------|
| Compiling Kernel | kernel/kernel.img   | kernel    |
|                  | kernel/resource.img | resource  |
|------------------|---------------------|-----------|
| Compiling U-Boot | u-boot/uboot.img    | uboot     |
|------------------|---------------------|-----------|
| ./mkimage.sh     | boot.img            | boot      |
|                  | system.img          | system    |
|------------------|---------------------|-----------|

Note that by excuting ./mkimage.sh, boot.img and system.img will be repacked wth the compiled results of Android in out/target/product/rk3328_firefly_box/ directory, and all related image files will be copied to the directory rockdev/Image-rk3328_firefly_box/.

The following is a list of the image files:

  • boot.img: Android initramfs image, contains base filesystem of Android root directory, whcih is responsible for initializing and loading the system partition.

  • system.img: Android system partition image in ext4 filesystem format.

  • kernel.img: kernel image.

  • resource.img: Resource image, containing boot logo and kernel device tree blob.

  • misc.img: misc partition image, responsible for starting the mode switch and first aid mode parameter transfer.

  • recovery.img: Recovery mode image.

  • rk3328_loader_v1.08.244.bin: Loader files.

  • uboot.img: U-Boot image file.

  • trust.img: Arm trusted file (ATF) image file.

  • parameter.txt: Partition layout and kernel command line.

Flash Image

Reference: 《Flash Image》