Android

This page will introduce you to how you can download and build the Android source tree to customize it for your usage.

If you have not built Android on your desktop yet, please read Android's official build environment set up guide https://source.android.com/source/initializing.html carefully before you proceed. Otherwise, you may experience unexpected errors and will need to read a long and complicated build log to find the problem.

We have used only Ubuntu 16.04 and 18.04 64bit with 8GB RAM since other newer versions had some issues while building the Android OS.
Android 9.x (Pie) build needs the OpenJDK 8, not the Oracle-Java-JDK.
Also note that you need around 210GB of free space in your storage to get the full source code and binary space. https://source.android.com/source/requirements.html

If you want to build the full Android source tree, don't download & build the kernel source separately.
Separate Kernel build might break the Android build process.

For Linux kernel and U-boot, you must install specific toolchains. Android will use its prebuilt ARM toolchain.
Extract the toolchains to /opt/toolchains/

U-boot

Linux kernel

And Please set the PATH to use the toolchains. You should set it before building the Android.

$ export PATH=$PATH:/opt/toolchains/gcc-linaro-aarch64-none-elf-4.9-2014.09_linux/bin
$ export PATH=$PATH:/opt/toolchains/gcc-linaro-arm-none-eabi-4.8-2014.04_linux/bin
$ export PATH=$PATH:/opt/toolchains/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin

This command will initiate to download the Android source tree for ODROID-N2.
The full source includes u-boot, kernel and Android repositories.

$ mkdir odroid-n2
$ cd odroid-n2
$ repo init -u https://github.com/hardkernel/android.git -b s922_9.0.0_master
$ repo sync

Android

$ source build/envsetup.sh
$ lunch odroidn2-eng
$ make -j<core number> selfinstall

You can set the number on the <core number> for simultaneous compile as much as number of core on your build machine.

Once Android build is complete, you will have all necessary files to download into your MicroSD/eMMC. You can install the Android image by two ways. First, using the self-install image. you just flashing this image and that's all. After booting, Android will be installed by automatically. And as other way, you can flash each images by manual.

One touch self install

This is the same way the Hardkernel team creates Android release image and easiest way to have bootable media on your ODROID-N2 if you proceed one more build step. This procedure combines all required image files created by Android build into a single file, out/target/product/odroidn2/selfinstall-odroidn2.img.

You also can make a bootable media by using the self-install image, and you already made it.

$ make -j<core number> selfinstall

you can write the self-install image via etcher or the dd commands.

$ sudo dd if=out/target/product/odroidn2/selfinstall-odroidn2.img of=/dev/sdd
$ sync
$ sudo eject /dev/sdd
 
==== Manual install ====
Once Android build is complete, you will have all necessary files to download into your %%MicroSD%%/eMMC. If you already have a boot media and can switch to fastboot mode is U-boot, you can proceed to update while executing below commands one by one or ignore particular steps.
[[getting_start:adb_fastboot|How to use fastboot]]
 
=== Boot loader ===
To use media on the ODROID-N2, you should flash bootloader to boot media first.
We supposed emmc node as /dev/sdd. you can find the media node by "sudo fdisk -l".
 
<code bash host>
$ cd <android_root>
$ cd bootloader/uboot/sd_fuse
$ ./sd_fusing.sh /dev/sdd

If you have installed media, you can flash bootloader via fastboot command.

$ fastboot flash bootloader bootloader/uboot/sd_fuse/u-boot.bin

After flashing the bootloader, you can use fastboot command to flash images. This command be done on u-boot.

On the board,

$ fastboot
$ fastboot oem fdisk
$ fastboot reboot-bootloader

Then, try belows to flash the images on your pc.

Android root and Kernel

$ fastboot flash boot out/target/product/odroidn2/boot.img

Kernel dtb

$ fastboot flash dtbs out/target/product/odroidn2/obj/KERNEL_OBJ/arch/arm64/boot/dts/amlogic/meson64_odroidn2_android.dtb

Recovery

$ fastboot flash recovery out/target/product/odroidn2/recovery.img

Vendor

$ fastboot flash vendor out/target/product/odroidn2/vendor.img

System

$ fastboot flash system out/target/product/odroidn2/system.img

Data

data partition should be formatted at first.

$ fastboot erase data

After flashing all partiton, please reboot the device.

$ fastboot reboot

How can I get into fastboot mode to download Android images

You need USB-serial kit. Press any key on your keyboard when ODROID-N2 is started. This will stop booting and give you U-boot command line, just execute the command fastboot.

I do not have a boot media yet, how can I download Android images to my MicroSD or eMMC?

Obviously you must have a boot media can boot from ODROID-N2 directly in order to enter fastboot mode in U-boot. Otherwise you are not able to download Android image to dedicated partitions (system/userdata/cache). The image files for such partitions can not be downloaded from a desktop directly with dd. For example, since these images are compressed and fastboot extract while installing for each partitions.

I do not have USB-serial kit, so I am not able to get into U-boot

The current U-boot does not support any other input device except serial console, hence you need USB-serial kit. Possible work around is to install a released Android image by Hardkernel team, and execute a command reboot fastboot from Android's shell command line. It will restart ODROID-N2 and stop on U-boot to get into fastboot mode. You can execute command fastboot from your desktop while USB cable is connected with ODROID-N2.