Compile the Android firmware

Preparatory work

The configuration requirements for compiling Android on the machine are high:

  • 64-bit CPU

  • 16GB physical memory + swap memory

  • 30GB of free disk space is used for building. In addition, about 25GB of disk space is used for the source code tree

The Ubuntu 14.04 operating system is officially recommended, and after testing, Ubuntu 12.04 can be compiled successfully, it only needs to meet the requirements of software and hardware configuration in the http://source.android.com/source/building.html.You can refer to http://source.android.com/source/initializing.html for the initialization of the compilation environment.

  • Install the OpenJDK 7:

sudo apt-get install openjdk-7-jdk  

Tip: the default link of JDK will be changed when you install the openjdk-7-jdk, at this time, you can use:

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

to switch the JDK version. The SDK will use the internally set JDK path when the default JDK in the operating system is not found. Therefore, it is more convenient to remove the link in order to allow the same machine to compile Android 5.1 and previous versions:

$ sudo /var/lib/dpkg/info/openjdk-7-jdk:amd64.prerm remove   
  • Ubuntu 12.04 software 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 software 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 the Android SDK

The source code package of the Android SDK is large (approximately 6.3G), and the source code package can be obtained by:

verify the MD5 code when the download is complete:

$ md5sum /path/to/firefly-rk3288_android5.1_git_20180126.tar.gz
dad080373115053de3367c21289562d2  firefly-rk3288_android5.1_git_20180126.tar.gz

Once confirmed, you will be able to extract:

mkdir -p ~/proj/firefly-rk3288-lollipop
cd ~/proj/firefly-rk3288-lollipop
tar xzf /path/to/firefly-rk3288_android5.1_git_20180126.tar.gz
git reset --hard
git remote add bitbucket https://bitbucket.org/T-Firefly/firenow-lollipop.git

You can update directly from bitbucket in the future

git pull bitbucket Firefly-RK3288:Firefly-RK3288

You can also browse the source code online at https://bitbucket.org/T-Firefly/firenow-lollipop/commits/branch/Firefly-RK3288.

Overall compilation(uboot、Android、kernel)

./FFTools/make.sh -d firefly-rk3288-aio-3288c -j8 -l rk3288_aio_3288c_box-userdebug
./FFTools/mkupdate/mkupdate.sh -l rk3288_aio_3288c_box-userdebug

Manually compile

Compile the kernel:

cd ~/proj/firefly-rk3288-lollipop/kernel
make firefly_defconfig
make firefly-rk3288-aio-3288c.img -j4

Compile the Android:

cd ~/proj/firefly-rk3288-lollipop
source build.sh
lunch rk3288_aio_3288c_box-userdebug
make -j8
./mkimage.sh

The default target build variation (TARGET_BUILD_VARIANT) is userdebug. There are three common variations, user, userdebug and eng, their differences are:

  • user

    • Only install the modules whose label is user

    • Set the property ro.secure=1, and turn on the security check function

    • Set the property ro.debuggable=0, and turn off the application debugging function

    • Turn off the adb function by default

    • Turn on the Proguard obfuscator

    • Turn on the DEXPREOPT pre-compilation optimization

  • userdebug

    • Install the modules whose label is user or debug

    • Set the property ro.secure=1, and turn on the security check function

    • Set the property ro.debuggable=1, and turn on the application debugging function

    • Turn on the ADB function by default

    • Turn on the Proguard obfuscator

    • Turn on the DEXPREOPT pre-compilation optimization

  • eng

    • Install the modules whose label is user, debug or eng

    • Set the property ro.secure=0, and turn off the security check function

    • Set the property ro.debuggable=1, and turn on the application debugging function

    • Set the property ro.kernel.android.checkjni=1, and enable the JNI call checking

    • Turn on the adb function by default

    • Turn off the Proguard obfuscator

    • Turn off the DEXPREOPT pre-compilation optimization

If the target build variation is user, the adb cannot get the root privileges.If you want to select a target build variation, you can add the parameters at the make command line, for example:

make -j8 PRODUCT-rk3288_aio_3288c_box-user
make -j8 PRODUCT-rk3288_aio_3288c_box-userdebug
make -j8 PRODUCT-rk3288_aio_3288c_box-eng 

Flash the partition image

The ./mkimage.sh from the previous step will repack the boot.img and system.img and copy other related image files to the rockdev/Image-rk3288_aio_3288c_box/ directory. The following lists the image files used by the general firmware:

  • boot.img :the initial file image for Android is responsible for initializing and loading the system partition.

  • kernel.img :kernel image.

  • misc.img :misc partition image is responsible for initiating the mode switching and passing the parameter in the emergency mode.

  • recovery.img :image in the emergency mode.

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

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

Please refer to How to upgrade the firmware to flash the partition image file.If the Windows system is used, you can copy the image file above to the rockdev\Image directory of the AndroidTool (firmware upgrade tool under Windows), and then refer to the upgrade document to flash the partition image, the benefit is to use the default configuration without modifying the path of the file.

Pack into a unified firmware update.img

After compiling, you can use the script of Firefly to pack into the unified firmware, the command is:

./FFTools/mkupdate/mkupdate.sh -l rk3288_aio_3288c_box-userdebug

The firmware is generated in the rockdev/Image-rk3288_aio_3288c_box/ directory after packing. It is easy to pack the unified firmware update.img under Windows, you can copy the file to the rockdev\Image directory of the AndroidTool by following the previous steps, and then run the mkupdate.bat batch file in the rockdev directory to create the update.img and save it to the rockdev\Image directory.The update.img is easy to release the firmware and is used for upgrading the system by the end user. It is convenient to use a partition image for general development.