Android NXP Guide

From Variscite Wiki


DART-MX8M-PLUS - Android 13.0.0_1.0.0 Developer Guide

Introduction

This page describes how to build and deploy Android 13 on the DART-MX8M-PLUS.
It is based on NXP's i.MX android-13.0.0_1.0.0 release

Overview

The objective of this document is to guide DART-MX8M-PLUS Android developers to obtain Android 13 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-PLUS SOM and variants.

Supported hardware and features

Feature
Description
SOM support
DART-MX8M-PLUS VAR-SOM-MX8M-PLUS
Carrier Board support
VAR-DT8MCustomBoard Symphony Board (VAR-SOM-IMX8M-Plus only)
CPU

i.MX8M Plus

eMMC
up to 64GB
LPDDR4 size support configuration
up to 4GB
SD card
+
Wired Network
10/100/1000 Mbps Ethernet
1 × Ethernet with TSN support
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 5 Mbps.
RTC
+
Display Dual LVDS up to 1080p60
MIPI-DSI 1920×1080p60
HDMI v2.0a up to 4Kp30,
Audio Line IN / HP
Camera 2x MIPI-CSI2
PCIE +


Hardware Requirements

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

Host (PC) setup requirements

The host development environment for Android is based on Ubuntu, please install one of the following Ubuntu versions:

If you are running Linux in a virtual machine you need at least 16GB of RAM and 32 GB of swap.
The build process requires ~250GB of free storage space. Before starting a build, make sure you have adequate free space available.


Note: Do not use other Ubuntu releases other than the ones recommended above. Variscite provides Docker containers that can be used for a development environment as an alternative to using a virtual machine or a dedicated computer.

To learn more, please see Variscite's Docker Build Environment guide.

Windows with WSL/WSL2 is not supported for Android BSP

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 libncurses5-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 lib32ncurses5-dev 
$ sudo apt-get -y install u-boot-tools mtd-utils android-tools-fsutils device-tree-compiler gdisk m4 dwarves libgnutls28-dev
$ sudo apt-get -y install libelf-dev cpio lz4
$ sudo apt-get -y install swig libdw-dev ninja-build clang liblz4-tool libncurses5 make tar rsync

For Ubuntu 20.04 and above:
The package android-tools-fsutils is obsolete and has been replaced by android-sdk-libsparse-utils.

$ sudo apt-get -y install android-sdk-libsparse-utils

Configure Git

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

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.


Check python version

In the next steps, we will download (from Google repositories) the command repo, used to download all the Android source repositories.


Certain tools like bpttools requires python2 which is not available default on Ubuntu 20.04 or 22.04 LTS.
Ubuntu 20.04/22.04 LTS users can install it running

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6 python2
Make sure you use latest repo tool for all bug fixes

Obtain source code

Variscite's Linux kernel and U-Boot are available through Github.
Required patches for the Android file system are under: https://variscite-public.nyc3.cdn.digitaloceanspaces.com/Android/Android_iMX8_1300_100/ in Variscite's FTP

Files:

  • imx-android-13.0.0_1.0.0.tar.gz - NXP's Android 13.0.0_1.0.0 original BSP patch files.

Get NXP's Android Release Package

$ mkdir ~/var_imx-android-13.0.0_1.0.0
$ cd ~/var_imx-android-13.0.0_1.0.0
$ curl -o ~/Downloads/imx-android-13.0.0_1.0.0.tar.gz https://variscite-public.nyc3.cdn.digitaloceanspaces.com/Android/Android_iMX8_1300_100/imx-android-13.0.0_1.0.0.tar.gz
$ tar xvf ~/Downloads/imx-android-13.0.0_1.0.0.tar.gz

Download Google Android 13.0.0_r7

Important update:

As of March 31, 2023, all codeaurora.org repositories have been migrated to other platforms and the project has been shut down.
For more information, please visit: https://bye.codeaurora.org/

In this context, errors may occur when downloading the source code running the script, such as:
fatal: unable to look up source.codeaurora.org (port 9418) (No address associated with hostname)

Variscite has updated all relevant software repositories. Please re-download https://variscite-public.nyc3.cdn.digitaloceanspaces.com/Android/Android_iMX8_1300_100/imx-android-13.0.0_1.0.0.tar.gz and the full Android source code from Variscite FTP

$ 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-13.0.0_1.0.0
$ source imx-android-13.0.0_1.0.0/imx_android_setup.sh

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

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

Apply Variscite's i.MX platforms patches

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

Build Android Images

Change to Android top level directory.

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

or

$ lunch dart_mx8mp-user

Note: userdebug build creates a debuggable version of Android.
           user build creates a production version of Android.


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

Switching from eMMC build to SD card build and vice versa

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

Build Android

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

Images created by the Android build

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


Image
Description
u-boot-imx8mp-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 vendor part of ramdisk and ko modules.
SOM agnostics.
init_boot.img A composite image, which includes init process.
SOM agnostics.
super.img Android system image file.
SOM agnostics.
dtbo-<name>.img
vbmeta-<name>.img
configuration dependent
<name> is: imx8mp-var-som-symphony - Supports Variscite VAR-SOM-MX8M-PLUS LVDS on Symphony-Board
imx8mp-var-som-symphony-hdmi - Supports Variscite VAR-SOM-MX8M-PLUS HDMI on Symphony-Board
imx8mp-var-som-symphony-m7 VAR-SOM-MX8M-PLUS M7 LVDS on Symphony-Board
imx8mp-var-som-symphony-2nd-ov5640 - Supports Variscite VAR-SOM-MX8M-PLUS with 2nd OV5640 on Symphony-Board
imx8mp-var-som-symphony-2nd-ov5640-m7 - Supports Variscite VAR-SOM-MX8M-PLUS M7 with 2nd OV5640 on Symphony-Board
imx8mp-var-som-symphony-basler-isp0 - Supports Variscite VAR-SOM-MX8M-PLUS with Basler camera on Symphony-Board
imx8mp-var-dart-dt8mcustomboard - Supports Variscite DART-MX8M-PLUS LVDS on DT8MCustomBoard 2.x
imx8mp-var-dart-dt8mcustomboard-m7 - Supports Variscite DART-MX8M-PLUS M7 LVDS on DT8MCustomBoard 2.x
imx8mp-var-dart-dt8mcustomboard-hdmi - Supports Variscite DART-MX8M-PLUS HDMI on DT8MCustomBoard 2.x
imx8mp-var-dart-dt8mcustomboard-legacy - Supports Variscite DART-MX8M-PLUS LVDS on DT8MCustomBoard 1.x
imx8mp-var-dart-dt8mcustomboard-legacy-m7 - Supports Variscite DART-MX8M-PLUS M7 LVDS on DT8MCustomBoard 1.x
imx8mp-var-dart-dt8mcustomboard-legacy-hdmi - Supports Variscite DART-MX8M-PLUS HDMI on DT8MCustomBoard 1.x
imx8mp-var-dart-dt8mcustomboard-basler-isp0 - Supports Variscite DART-MX8M-PLUS with Basler camera DT8MCustomBoard 2.x

Note: To create images with no dynamic support please follow Android_10_no_dynamic_partition

Boot options

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

Flash and boot Android from SD card

Create a bootable SD card

Partition and format SD card, and copy all images

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

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


Flash and boot Android from eMMC

Preparing images

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

$ cd out/target/product/dart_mx8mp
$ simg2img super.img super_raw.img

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"


Flashing Android with USB Fastboot

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_mx8mp/dtbo-<name>.img
$ sudo `which fastboot` flash dtbo_b out/target/product/dart_mx8mp/dtbo-<name>.img
$ sudo `which fastboot` flash boot_a out/target/product/dart_mx8mp/boot.img
$ sudo `which fastboot` flash boot_b out/target/product/dart_mx8mp/boot.img
$ sudo `which fastboot` flash init_boot_a out/target/product/dart_mx8mp/init_boot.img
$ sudo `which fastboot` flash init_boot_b out/target/product/dart_mx8mp/init_boot.img
$ sudo `which fastboot` flash vendor_boot_a out/target/product/dart_mx8mp/vendor_boot.img
$ sudo `which fastboot` flash vendor_boot_b out/target/product/dart_mx8mp/vendor_boot.img
$ sudo `which fastboot` flash super out/target/product/dart_mx8mp/super.img
$ sudo `which fastboot` flash vbmeta_a out/target/product/dart_mx8mp/vbmeta-<name>.img --disable-verity
$ sudo `which fastboot` flash vbmeta_b out/target/product/dart_mx8mp/vbmeta-<name>.img --disable-verity
$ 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.


Update Android firmware

Generate OTA packages

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

$ cd ~/var_imx-android-13.0.0_1.0.0/android_build
$ source build/envsetup.sh 
$ lunch dart_mx8mp-userdebug
$ ./imx-make.sh bootloader kernel -j4
$ make otapackage -j4 2>&1
Install OTA package to device
  • Extract payload.bin and payload_properties.txt from OTA zip file
  • Push file payload.bin to somewhere on the device (typically /cache folder)
  • 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.

Manual operations

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-13.0.0_1.0.0/android_build
$ source build/envsetup.sh
$ lunch dart_mx8mp-userdebug
$ ./imx-make.sh kernel -j4

Toolchain setup for manual build

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

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

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.

Note:The specific version of UUU is required to use this release, as VID/PIDs have been updated in the u-boot by NXP.
Please download/build specific version of UUU on your host machine

Running a M7 demo

Please choose one of the below <name> while flashing Android from Linux shell

imx8mp-var-dart-dt8mcustomboard-m7 (Variscite DART-MX8M-PLUS with LVDS and Cortex M7 on DT8MCustomBoard 2.x)
imx8mp-var-som-symphony-2nd-ov5640-m7 (Variscite VAR-SOM-MX8M-PLUS with 2nd OV5640 and Cortex M7 on Symphony-Board)
imx8mp-var-som-symphony-m7 (VAR-SOM-MX8M-PLUS with LVDS and Cortex M7 on Symphony-Board)

Running a demo from Linux

Boot Android to the shell

Increase kernel loglevel while debugging:

 sysctl kernel.printk=7;
 

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

cat /sys/class/remoteproc/remoteproc0/state

If the state is 'running', stop the m7

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.dart > /sys/class/remoteproc/remoteproc0/firmware OR
echo rpmsg_lite_pingpong_rtos_linux_remote.elf.som > /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-13.0.0_1.0.0/android_build/out/target/product/dart_mx8mp/obj/KERNEL_OBJ/drivers/rpmsg/imx_rpmsg_pingpong.ko /data

From device shell

$ su
$ cd /data
$ insmod imx_rpmsg_pingpong.ko

Running a demo from U-Boot

Enable below node in -m7.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 = 0x0000051D...
u-boot=> run bootcmd

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


Running Camera app using Basler ISP camera

Connect basler camera Flash any of the following dtbo and vbmeta images depending on your platform

  • imx8mp-var-som-symphony-basler-isp0 - Supports Variscite VAR-SOM-MX8M-PLUS with Basler camera on Symphony-Board
  • imx8mp-var-dart-dt8mcustomboard-basler-isp0 - Supports Variscite DART-MX8M-PLUS with Basler camera DT8MCustomBoard 2.x
  • imx8mp-var-dart-dt8mcustomboard-legacy-basler-isp0 - Supports Variscite DART-MX8M-PLUS with Basler camera DT8MCustomBoard 1.x


  • Note: This requires either device unlocked via fastboot or use UUU or recovery sdcard method to program proper images.

Please follow the steps to change the default camera configuration file to support Basler ISP Camera. Unlock the device as per section 8.3

# boot up the system
adb root
# remount after reboot
adb remount
adb reboot
# boot up the system
adb root
# remount after reboot
adb remount
adb shell cp /vendor/etc/configs/camera_config_imx8mp-basler-isp0.json /vendor/etc/configs/camera_config_imx8mp.json
#reboot

Launch Camera application using Basler ISP camera.