Compile Android Firmware

Preparation

Compiling Android requires higher configuration requirements for the machine:

  • 64 bits CPU.

  • 16GB physical memory + swap memory.

  • 30GB the free disk space is used for the build, and the source tree takes up an additional approximately 25GB.

The official recommendation of Ubuntu 16.04 operating system. Initialization of the compilation environment is referred to http://source.android.com/source/initializing.html.

  • Install OpenJDK 8:

sudo apt-get install openjdk-8-jdk

Tip: Install openjdk-8-jdk would changed the default link to the JDK. We can do as follow to switch JDK versions:

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

SDK will use the JDK path set internally when the default JDK of the operating system cannot be found. Therefore, to enable the same machine to compile Android 5.1 and previous versions, it is more convenient to remove the link:

$ sudo /var/lib/dpkg/info/openjdk-8-jdk:amd64.prerm remove
  • Ubuntu 12.04 package installation:

sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
g++-multilib mingw32 tofrodos gcc-multilib ia32-libs \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386 \
lzop libssl1.0.0 libssl-dev
  • Ubuntu 14.04 package installation:

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 \
libssl1.0.0 libssl-dev

Download Android SDK

Android SDK source package is relatively large, you can obtain the Android 7.1 source package through the following ways: Download link

  • Verify MD5 code after downloading:

$ md5sum /path/to/rk3399_firefly_industry_android7.1_20190628.7z.001

92084d35f40bebea6466d39d52bf9704  rk3399_firefly_industry_android7.1_20190628.7z.001

$ md5sum /path/to/rk3399_firefly_industry_android7.1_20190628.7z.002

f25da955fdb9700fcf53569b27debdfe  rk3399_firefly_industry_android7.1_20190628.7z.002

After confirmation, you can decompress:

mkdir -p ~/proj/firefly-rk3399
cd ~/proj/firefly-rk3399
7z x /path/to/rk3399_firefly_industry_android7.1_20190628.7z.001 -r -o./
git reset --hard

Note: be sure to update the remote warehouse after unpacking. The following method is updated from gitlab:

# Enter SDK root directory
cd ~/proj/firefly-rk3399

# Clone bundle from gitlab
git clone https://gitlab.com/TeeFirefly/rk3399-industry-nougat-bundle.git .bundle

# After that, run command below to update SDK
.bundle/update (or run command: ./rk3399-industry-nougat-bundle/update)

# Download the code for your own branch
git rebase FETCH_HEAD

Face-RK3399 Compiling method

Overall Compilation

Face-RK3399 default display interface is MIPI DSI, at the time of compilation by adding -o face option to specify whether to compile the boot of Face recognition APK (FaceApp).

  • Without FaceApp

cd ~/proj/firefly-rk3399/
./FFTools/make.sh  -d rk3399-firefly-face-mipi8 -j8 -l rk3399_firefly_face-userdebug
./FFTools/mkupdate/mkupdate.sh -l rk3399_firefly_face-userdebug
  • With FaceApp

cd ~/proj/firefly-rk3399/
./FFTools/make.sh  -i face -d rk3399-firefly-face-mipi8 -j8 -l rk3399_firefly_face-userdebug
./FFTools/mkupdate/mkupdate.sh -l rk3399_firefly_face-userdebug

Compile step by step

Before compilation, execute the following command to configure the 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
  • Compile the kernel:

cd ~/proj/firefly-rk3399/kernel/
make ARCH=arm64 firefly_defconfig
make -j8 ARCH=arm64 rk3399-firefly-face-mipi8.img
  • Compile the uboot:

cd ~/proj/firefly-rk3399/u-boot/
make rk3399_box_defconfig
make ARCHV=aarch64 -j8
  • Compile the Android (Without FaceApp):

cd ~/proj/firefly-rk3399/
source build/envsetup.sh
export FIREFLY_FACE_APP=false
lunch rk3399_firefly_face-userdebug
make installclean
make -j8
./mkimage.sh
  • Compile the Android (With FaceApp):

cd ~/proj/firefly-rk3399/
source build/envsetup.sh
export FIREFLY_FACE_APP=true
lunch rk3399_firefly_face-userdebug
make installclean
make -j8
./mkimage.sh

Package into unified firmware - update.img

After compiling, you can package the unified firmware with the official script of Firefly, and execute the following command:

./FFTools/mkupdate/mkupdate.sh

When the packaging is complete, the unified firmware Face-RK3399_Android1.1.2_DEFAULT_xxxxxx.img will be generated under rockdev/Image-rk3399_firefly_face/.

Is also easy to package update.img under Windows. Copy the compiled files to rockdev\Image directory of AndroidTool, and then run ./mkupdate.bat under rockdev directory to create update.img and store it in rockdev\Image directory.

Upgrade partition images

boot.img and system.img will be repackaged when you execute ./mkimage.sh during compilation. And the other related image files will be copy into rockdev/Image-rk3399_firefly_face.

The following is a list of image files commonly used:

  • boot.img: Android’s initial file image, which initializes and loads the system partition.

  • kernel.img: The kernel image

  • misc.img: misc partition image, responsible for initiating mode switching and parameter passing of first-aid mode.

  • parameter.txt: Partition information for emmc.

  • recovery.img: Image of first aid mode.

  • resource.img: resource image, which contains boot image and kernel device tree information.

  • system.img: Android system partition image, ext4 file system format.

  • trust.img: sleep to wake up relevant files.

  • rk3399_loader_v1.08.106.bin: Loader file.

  • uboot.img: uboot file.

Refer to How to upgrade firmware to burn the partition image file.

If you are using Windows system, copy the above image files to rockdev\Image directory of AndroidTool (The firmware upgrade tool under Windows), and then upgrade the partition image according to the upgrade document. The advantage is that you can use the default configuration without changing the path of the file.

update.img is convenient for firmware release, for end users to upgrade the system. It is generally convenient to use partition images during development.