Android TI Guide v2

From Variscite Wiki
Revision as of 20:31, 25 January 2024 by Diego (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release am62-android-13_09.00.00-v1.0.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
VAR-SOM-AM62 - Android 13-09.00.00 Developer Guide

Introduction

  • This page describes how to build and deploy Android Android 13 on the VAR-SOM-AM62.
  • It is based on TI's Android 13-09.00.00 release
  • The objective of this document is to guide VAR-SOM-AM62 Android developers to obtain Android 13 sources, setting up host environment, compilation, and deployment.

Hardware Requirements

You will need the Variscite VAR-SOM-AM62 based evaluation kit.

Software Requirements

Setting Up the Development Environment for Android

Before you start building Android, it is important to set up your development environment with the necessary tools and libraries. This section guides you through the installation of these prerequisites on an Ubuntu-based system.

Install General Development Tools and Libraries

1. These packages include tools and libraries essential for compiling and building software:

sudo apt -y install gnupg flex bison gperf build-essential gcc-multilib g++-multilib

2. Python is necessary for various build and development tasks:

sudo apt -y install python3-pyelftools python3-dev python3.6 python2 python-is-python3

3. These libraries provide support for 32-bit applications and include compression tools:

sudo apt -y install libc6-dev-i386 libncurses5 libncurses5-dev lib32z-dev libz-dev liblz-dev liblzo2-2 liblzo2-dev lzop lz4 cpio

4. These essential utilities are for handling graphics, XML files, and more:

sudo apt -y install libgl1-mesa-dev libxml2-utils xsltproc unzip bc libssl-dev ccache curl

5. These additional tools are required for Android development, including Git, Swig, and others:

sudo apt -y install git swig uuid uuid-dev zlib1g-dev u-boot-tools mtd-utils android-sdk-libsparse-utils device-tree-compiler gdisk m4 dwarves libgnutls28-dev libelf-dev x11proto-core-dev libx11-dev

Install Java Development Kit

Android development requires Java, so install OpenJDK version 8 which is compatible with Android 13:

sudo apt -y install openjdk-8-jdk


By following these steps, you will have prepared your Ubuntu-based development environment with all the necessary tools and libraries for building and deploying Android.

Configuring Git for Development

1. Set Your Git Username:

git config --global user.name "Your Name"

2. Set Your Git Email Address:

git config --global user.email "Your Email"


By configuring these details, you ensure that your work is properly attributed and that your team can easily identify your contributions. Remember, these settings are global and will apply to all repositories you work with on your machine.

Setting Up the Repo Command

The repo command is an essential tool in managing repositories for Android development. It streamlines working with Git in the context of the Android source tree, which consists of many Git repositories. This section will guide you through setting up the repo command on your system.

1. Create a directory to store executable binaries. This directory is typically ~/bin. Use the following command to create it:

mkdir -p ~/bin

2. Download the repo tool into your ~/bin directory. The repo tool is a Python script, and you can download it using curl:

curl -o ~/bin/repo https://commondatastorage.googleapis.com/git-repo-downloads/repo

3. After downloading, you need to make the repo script executable. This allows you to run the repo command. Change the file permissions using chmod:

chmod a+x ~/bin/repo

4. Finally, add the ~/bin directory to your PATH environment variable. This step ensures that the repo command can be run from any directory in your terminal. To update your PATH, use:

export PATH=~/bin:$PATH


Consider adding this line to your .bashrc or .bash_profile to make this change permanent across sessions. By completing these steps, you have successfully set up the repo tool on your system, which is a key component in managing and working with the Android source code repositories.

Setting Up the Android Build Environment and Toolchain

This section details the process of setting up a dedicated directory for the Android source and installing the ARM toolchains necessary for building Android for the VAR-SOM-AM62.

1. Create a directory where you will store the Android source code. This helps keep your work organized and separated from other projects. Use the following command to create the directory and navigate into it:

mkdir ~/var_aosp_ti-13_09_00_00 && cd $_

2. To make it easier to reference this directory in future commands, set an environment variable YOUR_PATH to its full path:

export YOUR_PATH=$PWD

The next step is to download and set up the ARM toolchains required for cross-compiling Android. These toolchains are specific to the ARM architecture and are necessary for building Android for the VAR-SOM-AM62.

1. Navigate to the created directory:

cd ${YOUR_PATH}/

2. Create a subdirectory for the toolchains:

mkdir -p toolchain

3. Download and extract the ARM toolchains:

wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz && \
  tar -Jxvf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C toolchain && \
  wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz && \
  tar -Jxvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz -C toolchain

4. Finally, add the paths to the ARM toolchains to your PATH environment variable. This allows you to use the toolchains from any directory:

export PATH=$PATH:${YOUR_PATH}/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin:${YOUR_PATH}/toolchain/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin


Consider adding this line to your .bashrc or .bash_profile to make this change permanent across sessions. By completing these steps, you've successfully set up a dedicated environment for Android development and installed the necessary ARM toolchains for the VAR-SOM-AM62.

Initializing and Syncing the Android Repository

After setting up your build environment, the next step is to initialize and sync the Android repository for the VAR-SOM-AM62. This involves cloning the necessary source code using the repo tool.

1. Create a directory specifically for the Variscite Android source code within your previously set path. Navigate into this new directory with the following commands:

mkdir -p ${YOUR_PATH}/ti-aosp-13 && cd $_

2. Use the repo tool to initialize the repository. This step involves specifying the remote repository's URL and the branch you want to clone. For the VAR-SOM-AM62, use the following command:

repo init -u https://github.com/varigit/variscite-bsp-platform.git -b ti-android-13.0.0_r62-var01 -m RLS_09_00.xml

3. After initializing the repository, synchronize it to retrieve the source code:

repo sync -j$(nproc)


Please note that the repo sync command may take some time to complete, as it downloads a large amount of data. It's a good opportunity to grab a cup of coffee and take a short break while your computer does the heavy lifting.

Customizing the Kernel Build

In some cases, you might need to modify the kernel build process. This section describes how to customize the kernel build for the VAR-SOM-AM62 by editing specific makefiles.

Remove References to DTB Files

If you need to exclude certain Device Tree Blob (DTB) files from the build, you can remove their references from the Makefile. Use the sed command to comment out or delete lines referencing these DTB files:

sed -i '/DTB_FILES :=/d' device/ti/am62x/build/tasks/dtimages.mk
sed -i '/$(LOCAL_DTB)\/k3-am625-sk.dtb/d' device/ti/am62x/build/tasks/dtimages.mk
sed -i '/$(LOCAL_DTB)\/k3-am62-lp-sk.dtb/d' device/ti/am62x/build/tasks/dtimages.mk

Include Custom DTB Files

If you have custom DTB files to include, modify the Makefile to add these files. This ensures that your custom configurations are included in the build:

sed -i 's/# Please keep this list fixed: add new files in the end of the list/include device\/variscite\/am62x_var_som\/build\/tasks\/dtimages.mk/g' \
       device/ti/am62x/build/tasks/dtimages.mk


By following these steps, you will have properly initialized and synchronized the Android source repository for the VAR-SOM-AM62, and customized the kernel build as needed.

Building U-Boot and Bootloader Components

This section details the process of building U-Boot and related bootloader components for the VAR-SOM-AM62. The steps include initializing the bootloader repository and building the:

  • ARM Trusted Firmware (ATF);
  • OP-TEE OS;
  • U-Boot for both R5 and A53 cores.

Initializing Bootloader Repository

1. Create a directory for the bootloader source code and navigate into it:

mkdir -p ${YOUR_PATH}/ti-bootloader-aosp/ && cd $_

2. Initialize the repository with the required bootloader XML manifest:

repo init -u https://github.com/varigit/variscite-bsp-platform.git -b ti-android-13.0.0_r62-var01 -m RLS_09_00_Bootloader.xml

3. Synchronize the repository to retrieve the source code:

repo sync -j$(nproc)


Please note that the repo sync command may take some time to complete, as it downloads a large amount of data. It's a good opportunity to grab a cup of coffee and take a short break while your computer does the heavy lifting.

4. After syncing the bootloader repository, set the environment variables to specify the locations of the bootloader components:

export G_ATF_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/arm-trusted-firmware"
export G_OPTEE_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/optee_os"
export G_CORE_LINUX_FIRMWARE_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/ti-linux-firmware"
export G_UBOOT_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/ti-u-boot"

Building ARM Trusted Firmware (ATF)

1. Navigate to the ATF source directory:

cd ${G_ATF_SRC_DIR}

2. Clean and build the ATF:

make distclean
make E=0 CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=aarch64 PLAT=k3 TARGET_BOARD=lite SPD=opteed CFLAGS+="-DK3_PM_SYSTEM_SUSPEND=1"

Building OP-TEE OS

1. Navigate to the OP-TEE OS source directory:

cd ${G_OPTEE_SRC_DIR}

2. Clean and build OP-TEE OS:

make clean && rm -rf out
make CROSS_COMPILE32=arm-none-linux-gnueabihf- CROSS_COMPILE64=aarch64-none-linux-gnu- PLATFORM=k3-am62x CFG_ARM64_core=y

Building U-Boot for R5 Core

1. Set U-Boot R5 Configuration:

export G_UBOOT_DEF_CONFIG_R="am62x_var_som_r5_defconfig"

2. Navigate to U-Boot Source Directory and Build:

cd ${G_UBOOT_SRC_DIR}
make mrproper
make ARCH=arm O=${G_UBOOT_SRC_DIR}/out/r5 CROSS_COMPILE=arm-none-linux-gnueabihf- ${G_UBOOT_DEF_CONFIG_R}
make ARCH=arm O=${G_UBOOT_SRC_DIR}/out/r5 CROSS_COMPILE=arm-none-linux-gnueabihf- BINMAN_INDIRS=${G_CORE_LINUX_FIRMWARE_SRC_DIR}
<pre/>

3. Use the find command to locate the tiboot3*.bin files for R5:
<pre>
find ${G_UBOOT_SRC_DIR} -name "tiboot3*.bin"

Building U-Boot for A53 Core with Android

1. Set U-Boot A53 Configuration:

export G_UBOOT_DEF_CONFIG_A="am62x_var_som_a53_android_defconfig"

2. Navigate to U-Boot Source Directory and Build:

cd ${G_UBOOT_SRC_DIR}
make mrproper
make ARCH=arm O=${G_UBOOT_SRC_DIR}/out/a53 CROSS_COMPILE=aarch64-none-linux-gnu- ${G_UBOOT_DEF_CONFIG_A}
make ARCH=arm O=${G_UBOOT_SRC_DIR}/out/a53 CROSS_COMPILE=aarch64-none-linux-gnu- \
       BL31=${G_ATF_SRC_DIR}/build/k3/lite/release/bl31.bin \
       TEE=${G_OPTEE_SRC_DIR}/out/arm-plat-k3/core/tee-pager_v2.bin \
       BINMAN_INDIRS=${G_CORE_LINUX_FIRMWARE_SRC_DIR}

3. Use the find command to locate the tispl.bin and u-boot.img files for A53:

 find ${G_UBOOT_SRC_DIR} -name "tispl.bin"
 find ${G_UBOOT_SRC_DIR} -name "u-boot.img" 

Copying Bootloader Images to AOSP Build

1. Copy the built bootloader binaries to the AOSP build directory:

cp ${G_UBOOT_SRC_DIR}/out/r5/tiboot3.bin \
     ${G_UBOOT_SRC_DIR}/out/r5/tiboot3-am62x-gp-evm.bin \
     ${G_UBOOT_SRC_DIR}/out/r5/tiboot3-am62x-hs-evm.bin \
     ${G_UBOOT_SRC_DIR}/out/r5/tiboot3-am62x-hs-fs-evm.bin \
     ${G_UBOOT_SRC_DIR}/out/a53/tispl.bin \
     ${G_UBOOT_SRC_DIR}/out/a53/u-boot.img \
     ${YOUR_PATH}/ti-aosp-13/vendor/variscite/am62x_var_som/bootloader/am62x-sk/

2. Check that the bootloader binaries are correctly placed in the AOSP build directory:

ls -l ${YOUR_PATH}/ti-aosp-13/vendor/variscite/am62x_var_som/bootloader/am62x-sk/ 


By following these steps, you will have successfully built and copied the necessary bootloader components for the VAR-SOM-AM62 into your AOSP build environment.

Building Linux Kernel

This section guides you through the process of setting up the kernel source repository and building the kernel for the VAR-SOM-AM62.

Initializing Kernel Repository

1. Create a directory specifically for the Variscite kernel source and navigate into it:

mkdir -p ${YOUR_PATH}/ti-kernel-aosp/ && cd $_

2. Initialize the repository with the required kernel XML manifest:

repo init -u https://github.com/varigit/variscite-bsp-platform.git -b ti-android-13.0.0_r62-var01 -m RLS_09_00_Kernel.xml

3. Synchronize the repository to retrieve the source code:

repo sync -j$(nproc)


Please note that the repo sync command may take some time to complete, as it downloads a large amount of data. It's a good opportunity to grab a cup of coffee and take a short break while your computer does the heavy lifting.

Building the Kernel

1. Once the repository is synchronized, navigate to the kernel source directory:

cd ${YOUR_PATH}/ti-kernel-aosp/

2. Define an environment variable DIST_DIR to specify the directory where the built kernel will be stored. This directory is within the AOSP device path for the VAR-SOM-AM62:

export DIST_DIR=${YOUR_PATH}/ti-aosp-13/device/variscite/am62x-kernel/kernel/6.1
mkdir -p $DIST_DIR

3. Use the provided tools to build the kernel. This step involves running a Bazel build command that compiles the kernel and outputs the necessary files to the DIST_DIR:

tools/bazel run --lto=full //common:ti_dist -- --dist_dir=$DIST_DIR


By following these steps, you will have successfully set up and built the kernel for the VAR-SOM-AM62. The built kernel will be stored in the specified distribution directory, ready for integration into your Android build.

Build Android Images

To be continued.