Android NXP Guide

From Variscite Wiki
DART-MX8M-MINI - Android 11.0.0_r4 Developer Guide

1 Introduction

This page describes how to build and deploy Android 11 on the DART-MX8M-MINI. It is based on NXP's i.MX android-11.0.0_1.0.0_ANDROID release

2 Overview

The objective of this document is to guide DART-MX8M-MINI Android developers to obtain Android 11 sources, setting up host environment, compilation, and deployment.

This document contains instructions for:

  • Hardware and software requirements.
  • Setup the hardware.
  • Setup the toolchain.
  • Download & build the sources.
  • Install the binaries on the DART-MX8M-MINI SOM and variants.

3 Supported hardware and features

Feature
Description
SOM support
DART-MX8M-MINI VAR-SOM-MX8M-MINI
Carrier Board support
VAR-DT8MCustomBoard Symphony Board (VAR-SOM-MX8-Mini only)
CPU

i.MX8M Mini

eMMC
up to 64GB
LPDDR4 size support configuration
up to 4GB
SD card
+
Wired Network
10/100/1000 Mbps Ethernet
Wireless Network
Support for LWB5, 802.11 ac/a/b/g/n STA, AP, & Wi-Fi Direct Mode SmartConfig
Bluetooth
4.2 / BLE
SPI
+
I2C
+
USB host
+
USB OTG
Host and Device
Uarts
x4, up to 4 Mbps.
RTC
+
Display LVDS Dual 1920×1080 24-bit
MIPI-DSI 1920×1080 24-bit
Audio Line IN / HP
Camera 1x MIPI-CSI2
PCIE +


4 Hardware Requirements

You will need the Variscite DART-MX8M-MINI based evaluation kit.

4.1 Host (PC) setup requirements

The host development environment for Android is based on Ubuntu, please install Ubuntu version 16.04/18.04 64bit LTS http://www.ubuntu.com/download/desktop

If you are running Linux in a virtual machine you need at least 16GB of RAM/swap.

Note: Do not use other Ubuntu releases other than the ones recommended above.

4.1.1 Install required packages on host PC

$ sudo apt-get -y install gnupg flex bison gperf build-essential zip gcc-multilib g++-multilib 
$ sudo apt-get -y install libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libz-dev libssl-dev
$ sudo apt-get -y install ccache libgl1-mesa-dev libxml2-utils xsltproc unzip bc
$ sudo apt-get -y install uuid uuid-dev zlib1g-dev liblz-dev liblzo2-2 liblzo2-dev lzop git curl
$ sudo apt-get -y install u-boot-tools mtd-utils android-tools-fsutils device-tree-compiler gdisk m4

4.1.2 Configure Git

$ git config --global user.name "Your Name"
$ git config --global user.email "Your Email"

4.1.3 Install the OpenJDK

To install it:

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk


If your Ubuntu version is missing the package (which shouldn't happen), add the PPA repository and run the previous commands again:

$ sudo add-apt-repository ppa:openjdk-r/ppa


Update the default Java version by running:

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

Note: The build process requires about 500GB of free space.

5 Obtain source code

Variscite's Linux kernel and U-Boot are available through Github.
Required patches for the Android file system are under: ftp://customerv:Variscite1@ftp.variscite.com/VAR-SOM-MX8X/Software/Android/Android_iMX8_1100_100/ in Variscite's FTP

Files:

  • imx-android-11.0.0_1.0.0.tar.gz - NXP's i.MX android-11.0.0_1.0.0 original BSP patch files.

5.1 Get NXP's Android Release Package

$ mkdir ~/var_imx-android-11.0.0_1.0.0
$ cd ~/var_imx-android-11.0.0_1.0.0
$ curl -o ~/Downloads/imx-android-11.0.0_1.0.0.tar.gz ftp://customerv:Variscite1@ftp.variscite.com/VAR-SOM-MX8X/Software/Android/Android_iMX8_1100_100/imx-android-11.0.0_1.0.0.tar.gz
$ tar xvf ~/Downloads/imx-android-11.0.0_1.0.0.tar.gz

5.2 Download Google Android 11.0.0_r4

$ mkdir -p ~/bin
$ curl -o ~/bin/repo https://commondatastorage.googleapis.com/git-repo-downloads/repo
$ chmod a+x ~/bin/repo
$ export PATH=~/bin:$PATH
$ cd ~/var_imx-android-11.0.0_1.0.0
$ source imx-android-11.0.0_1.0.0/imx_android_setup.sh

Wait for the script to finish running, and it should create following folders

$ ~/var_imx-android-11.0.0_1.0.0/android_build/device/variscite/
$ ~/var_imx-android-11.0.0_1.0.0/android_build/vendor/variscite/kernel_imx and
$ ~/var_imx-android-11.0.0_1.0.0/android_build/vendor/variscite/uboot-imx

5.3 Apply Variscite's i.MX platforms patches

$ cd ~/var_imx-android-11.0.0_1.0.0/android_build/device
$ variscite/scripts/install.sh

6 Build Android Images

Change to Android top level directory.

$ cd ~/var_imx-android-11.0.0_1.0.0/android_build
$ source build/envsetup.sh
$ lunch dart_mx8mm-userdebug

Note: userdebug build creates a debuggable version of Android. eng build creates an engineering version of Android. Development mode enable and development tools are available on target.

$ export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH

6.1 Switching from eMMC build to SD card build and vice versa

Unlike previous Android BSPs, the boot media is autodetected at boot time.

6.2 Build Android

./imx-make.sh -j4 2>&1 | tee build1-1.log

6.3 Images created by the Android build

The resulted images are located in out/target/product/dart_mx8mm.


Image
Description
u-boot-imx8mm-var-dart.imx U-Boot for eMMC/SD card boot.
SOM agnostics.
boot.img Android kernel image file.
SOM agnostics.
vendor_boot.img A composite image, which includes another part of ramdisk and boot parameters.
SOM agnostics.
super.img Android super image file.
SOM agnostics.
dtbo-<name>.img
vbmeta-<name>.img
configuration dependent
<name> is: imx8mm-var-dart-dt8mcustomboard - Supports LVDS / SD / WiFi (DART-MX8M-MINI on DT8MCustomBoard 2.x)
imx8mm-var-dart-dt8mcustomboard-legacy - Supports LVDS / SD / WiFi (DART-MX8M-MINI on DT8MCustomBoard 1.x)
imx8mm-var-som-symphony - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI on a Symphony-Board V1.4A and above)
imx8mm-var-som-symphony-legacy - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI on a Symphony-Board V1.4 and below)
imx8mm-var-dart-dt8mcustomboard-legacy-m4 - Supports LVDS / SD / WiFi (DART-MX8M-MINI-M4 on DT8MCustomBoard 1.x)
imx8mm-var-dart-dt8mcustomboard-m4 - Supports LVDS / SD / WiFi (DART-MX8M-MINI-M4 on DT8MCustomBoard 2.x)
imx8mm-var-som-symphony-legacy-m4 - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI-M4 on a Symphony-Board V1.4 and below)
imx8mm-var-som-symphony-m4 - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI-M4 on a Symphony-Board V1.4A and above)


7 Boot options

Boot options of the Android:
1. Directly from SD card
2. U-Boot boots from on-SOM eMMC

7.1 Flash and boot Android from SD card

7.1.1 Create a bootable SD card

Partition and format SD card, and copy all images

$ sudo ./var-mksdcard.sh -f <name> /dev/sdX;sync

7.1.2 Boot From SD card

  • Power-off the board.
  • Insert the SD card into the SD card slot of the carrier board (DVK)
  • Make sure the Boot Mode is set to SD card: see Setting the Boot Mode section
  • Power up the board - it will boot into Linux from the SD card


7.2 Flash and boot Android from eMMC

7.2.1 Preparing images

The default super.img, vendor_boot.img format is suitable for flashing using fastboot, and must be modified for flashing using 'dd'.

$ cd out/target/product/dart_mx8mm
$ simg2img super.img super_raw.img
$ simg2img vendor_boot.img vendor_boot_raw.img

7.2.2 Flashing Android from Linux shell (when the primary installation android)

An example of flashing eMMC, can be found here.

Follow the following steps instructions above:

1. Preparing a rescue SD card;

2. Flash from command line (use the install_android.sh script)


Further, follow the steps described in paragraph "Flashing Android with USB Fastboot"


7.2.3 Flashing Android with USB Fastboot

7.2.3.1 Install tools on host

$ sudo apt-get install android-tools-adb android-tools-fastboot

Note: Make sure you built Android for eMMC
Connect the target with host PC at fastboot mode:

  1. Connect a USB OTG cable from the target board OTG port to a your host machine USB HOST port.
  2. Power up the board and hit return/space to stop the boot at U-Boot.
  3. type fastboot 0 in the U-Boot command line.

On the Host PC:

$ sudo `which fastboot` flash dtbo_a out/target/product/dart_mx8mm/dtbo-<name>.img
$ sudo `which fastboot` flash dtbo_b out/target/product/dart_mx8mm/dtbo-<name>.img
$ sudo `which fastboot` flash boot_a out/target/product/dart_mx8mm/boot.img
$ sudo `which fastboot` flash boot_b out/target/product/dart_mx8mm/boot.img
$ sudo `which fastboot` flash vendor_boot_a out/target/product/dart_mx8mm/vendor_boot.img
$ sudo `which fastboot` flash vendor_boot_b out/target/product/dart_mx8mm/vendor_boot.img
$ sudo `which fastboot` flash super out/target/product/dart_mx8mm/super.img
$ sudo `which fastboot` flash vbmeta_a out/target/product/dart_mx8mm/vbmeta-<name>.img
$ sudo `which fastboot` flash vbmeta_b out/target/product/dart_mx8mm/vbmeta-<name>.img
$ sudo `which fastboot` reboot

Replace <name> with the actual desired setup name according to the table in the "Images created by the Android build" section.

7.2.4 Android recovery mode

7.2.4.1 Enter board in Android Recovery mode

If you are using DT8MCustomBoard or you implemented any recovery key detection in uboot, the device can powered on in recovery mode by holding down the "back" (or any other recovery key) button until the end of the boot, showing the "Android Recovery" menu.

Alternatively you can issue the command reboot recovery from the Android console (or using adb shell).

7.2.4.2 Control menu in Android Recovery Mode

If the board has UP, DOWN keys (like DT8MCustomBoard)

  1. To cycle between menu items, use a short press of UP or DOWN buttons
  2. To highlight an item, use a long press of BACK or HOME buttons or long touch the touchscreen
  3. To activate an item, use a short press of ON/OFF button

If the board has no UP and DOWN keys (like SymphonyBoard)

  1. To cycle between menu items, use a short press of any buttons or select the item with the touchscreen
  2. To activate an item, use a long press of any buttons or of the touchscreen

7.2.4.3 Update Android firmware

7.2.4.3.1 Generate OTA packages

For generating "OTA" packages, use the following commands:

$ cd ~/var_imx-android-11.0.0_1.0.0/android_build
$ source build/envsetup.sh 
$ lunch PRODUCT=dart_mx8mm-userdebug
$ ./imx-make.sh bootloader kernel -j4
$ make otapackage -j4
7.2.4.3.2 Install OTA package to device
  • extract payload.bin and payload_properties.txt from OTA zip file
  • Push payload.bin to board's /data/ota_package dir: adb push payload.bin /data/ota_package/ .
  • open payload_properties.txt on an editor to copy its content, lets suppose it's like in the NXP manual:
 FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
 FILE_SIZE=379074366
 METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ/de8Dgp9zFXt8Fo+Hxccp465uTOvKNsteWU=
 METADATA_SIZE=46866
 
  • Input the following command on the board's console to update:
 su
 update_engine_client --payload=file:///data/ota_package/payload.bin --update --headers="FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
 FILE_SIZE=379074366
 METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ/de8Dgp9zFXt8Fo+Hxccp465uTOvKNsteWU=
 METADATA_SIZE=46866"

Make sure that the -- header equals to the exact content of payload_properties.txt without "space" or "return" character.

After issuing the command, nothing seems to happen on the device, but you can monit logcat for operation progress. After a successful update you can reboot into the updated version.

You can check chapter 7 of official NXP "Android User Guide" for further "Over-The-Air (OTA) Update" examples.

8 Manual operations

8.1 Build boot.img

When you perform changes to the kernel, you may build boot.img solely instead of building the whole Android.

$ cd ~/var_imx-android-11.0.0_1.0.0/android_build
$ source build/envsetup.sh
$ lunch dart_mx8mm-userdebug
$ make bootimage

8.2 Toolchain setup for manual build

Setup the toolchain path to point to arm-linux-androideabi- tools in prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin

$ export ARCH=arm64
$ export CROSS_COMPILE=~/var_imx-android-11.0.0_1.0.0/android_build/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-

8.3 Unlock device for fastboot

Our build behaves like any other standard Android device.

To use fastboot, you should go through the following steps

  • Settings => System => About Tablet => Build number
  • keep on tapping until you see a prompt that says "You are now a developer!"
  • Settings => System => Advanced => Developer options => OEM unlocking
  • reboot to bootloader
  • type "fastboot 0" in the U-Boot command line
  • run "sudo `which fastboot` oem unlock" from the Host PC
  • wait until the unlock process is complete
  • proceed for flashing

9 Flashing Using NXP MFGTools - UUU (Universal Update Utility)

To flash Android OS without using a recovery SD card, UUU (MFG Tools 3.0) can be used.
Please refer to Flashing Android OS using UUU - USB Boot.

10 Running a M4 demo

Please choose one of the below options while flashing Android from Linux shell

imx8mm-var-dart-dt8mcustomboard-legacy-m4 - Supports LVDS / SD / WiFi (DART-MX8M-MINI-M4 on DT8MCustomBoard 1.x)
imx8mm-var-dart-dt8mcustomboard-m4 - Supports LVDS / SD / WiFi (DART-MX8M-MINI-M4 on DT8MCustomBoard 2.x)
imx8mm-var-som-symphony-legacy-m4 - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI-M4 on a Symphony-Board V1.4 and below)
imx8mm-var-som-symphony-m4 - Supports LVDS / SD / WiFi (VAR-SOM-MX8M-MINI-M4 on a Symphony-Board V1.4A and above)

10.1 Running a demo from Linux

Boot Android to the shell

Increase kernel loglevel while debugging:

 sysctl kernel.printk=7;
 

Check the state of the m4, it should be running already by U-Boot

cat /sys/class/remoteproc/remoteproc0/state

If the state is 'running', stop the m4

echo stop > /sys/class/remoteproc/remoteproc0/state

Load new firmware (.elf file must already exist in /lib/firmware directory)

echo rpmsg_lite_pingpong_rtos_linux_remote.elf > /sys/class/remoteproc/remoteproc0/firmware

Change the state to running

echo start > /sys/class/remoteproc/remoteproc0/state

Copy and run demo module

From Host PC
$ adb root
$ adb push ~/var_imx-android-11.0.0_1.0.0/android_build/out/target/product/dart_mx8mm/obj/KERNEL_OBJ/drivers/rpmsg/imx_rpmsg_pingpong.ko /data

From device shell

$ su
$ cd /data
$ insmod imx_rpmsg_pingpong.ko

10.2 Running a demo from U-Boot

Enable below node in -m4.dtsi and re-build images as per "Build Android Images" section and follow the steps described in paragraph "Flashing Android with USB Fastboot" to flash the images

 &rpmsg{
       status = "okay";
 };

From U-Boot shell execute below commands

u-boot=> bootmcu
run command: 'bootaux 0x7e0000'
## Starting auxiliary core stack = 0x20020000, pc = 0x1FFE035D...
u-boot=> run bootcmd

Follow steps as described in "Copy and run demo module"