odroid-n2:software:building_android

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.
If you use Ubuntu 20.04 or later, you should install python 2.7 before 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.

Before building Android, you must change the default shell from dash to bash.

host
$ sudo dpkg-reconfigure dash

Answer:No

If you build the Android OS on Ubuntu 22.04, you might need to run the following commands before start building.

host
cd prebuilts/misc/linux-x86/flex
rm flex-2.5.39
tar zxf flex-2.5.39.tar.gz
cd flex-2.5.39
./configure
make
mv flex ../
cd ../
rm -rf flex-2.5.39
mv flex flex-2.5.39

Hit from a forum user @Richard Schaefer : Forum Link

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.

host
$ 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.

host
$ mkdir odroid-n2
$ cd odroid-n2
$ repo init -u https://github.com/hardkernel/android.git -b g12_p_master
$ repo sync
host
$ source build/envsetup.sh
$ lunch odroidn2-eng
$ make -j<core number> && 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.

You can also builds be separated images like root, system, vendor and dtbs image.

host
$ make bootimage
$ make systemimage
$ make vendorimage
$ make dtbsimage

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.

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.

host
$ make -j<core number> selfinstall

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

host
$ sudo dd if=out/target/product/odroidn2/selfinstall-odroidn2.img of=/dev/sdd
$ sync
$ sudo eject /dev/sdd

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. 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”.

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.

host
$ 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,

target
$ fastboot
host
$ fastboot oem fdisk
$ fastboot reboot-bootloader

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

Android root and Kernel

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

Kernel dtb

host
$ fastboot flash dtbs out/target/product/odroidn2/dtbs.img

Recovery

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

Vendor

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

System

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

Data

data partition should be formatted at first.

host
$ fastboot erase data

After flashing all partiton, please reboot the device.

host
$ fastboot reboot

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.

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.

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.

  • odroid-n2/software/building_android.txt
  • Last modified: 2023/06/01 17:33
  • by codewalker