Android TI Guide v2: Difference between revisions

From Variscite Wiki
(Created page with "<!-- Set release according to "release" parameter in URL and use am62-android-13_09.00.00-v1.0 as default --> {{INIT_RELEASE_PARAM|am62-android-13_09.00.00-v1.0}}<!-- --> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM|am62-android-13_09.00.00-v1.0}}}} <!-- --> {{PageHeader|{{#var:HARDWARE_NAME}} - {{#var:ANDROID_TI_VERSION}} Developer Guide}} {{DocImage|category1=Android|category2={{#var:HARDWARE_NAME}}}} __toc__ = Introduction<br/> = This page describes how...")
 
No edit summary
 
Line 3: Line 3:
--> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM|am62-android-13_09.00.00-v1.0}}}} <!--
--> {{#lst:Android_Platform_Customization|{{#var:RELEASE_PARAM|am62-android-13_09.00.00-v1.0}}}} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} - {{#var:ANDROID_TI_VERSION}} Developer Guide}} {{DocImage|category1=Android|category2={{#var:HARDWARE_NAME}}}} __toc__
--> {{PageHeader|{{#var:HARDWARE_NAME}} - {{#var:ANDROID_TI_VERSION}} Developer Guide}} {{DocImage|category1=Android|category2={{#var:HARDWARE_NAME}}}} __toc__
= Introduction<br/> =


This page describes how to build and deploy {{#switch: Android 13 = {{#var:ANDROID_NAME}} | Android {{#var:ANDROID_NAME}} }} on the {{#var:HARDWARE_NAME}}.<br> It is based on TI's {{#var:ANDROID_TI_VERSION}} release
= Introduction =


= Overview =
* This page describes how to build and deploy {{#switch: Android 13 = {{#var:ANDROID_NAME}} | Android {{#var:ANDROID_NAME}} }} on the {{#var:HARDWARE_NAME}}.
* It is based on TI's {{#var:ANDROID_TI_VERSION}} release
* The objective of this document is to guide {{#var:HARDWARE_NAME}} Android developers to obtain {{#switch: {{#var:ANDROID_NAME}} | Android 10 = {{#var:ANDROID_NAME}} | Android 11 = {{#var:ANDROID_NAME}} | | Android 12 = {{#var:ANDROID_NAME}} | Android 13 = {{#var:ANDROID_NAME}} | Android {{#var:ANDROID_NAME}} }} sources, setting up host environment, compilation, and deployment.


The objective of this document is to guide {{#var:HARDWARE_NAME}} Android developers to obtain {{#switch: {{#var:ANDROID_NAME}} | Android 10 = {{#var:ANDROID_NAME}} | Android 11 = {{#var:ANDROID_NAME}} | | Android 12 = {{#var:ANDROID_NAME}} | Android 13 = {{#var:ANDROID_NAME}} | Android {{#var:ANDROID_NAME}} }} sources, setting up host environment, compilation, and deployment.
= Hardware Requirements =
 
You will need the Variscite {{#var:HARDWARE_NAME}} 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:
<pre>
sudo apt -y install gnupg flex bison gperf build-essential gcc-multilib g++-multilib
</pre>
 
2. Python is necessary for various build and development tasks:
<pre>
sudo apt -y install python3-pyelftools python3-dev python3.6 python2 python-is-python3
</pre>


This document contains instructions for:
3. These libraries provide support for 32-bit applications and include compression tools:
<pre>
sudo apt -y install libc6-dev-i386 libncurses5 libncurses5-dev lib32z-dev libz-dev liblz-dev liblzo2-2 liblzo2-dev lzop lz4 cpio
</pre>


*Hardware and software requirements.
4. These essential utilities are for handling graphics, XML files, and more:
*Setup the hardware.
<pre>
*Setup the toolchain.
sudo apt -y install libgl1-mesa-dev libxml2-utils xsltproc unzip bc libssl-dev ccache curl
*Download & build the sources.
</pre>
*Install the binaries on the {{#var:HARDWARE_NAME}} SOM and variants.
*Making Changes to kernel/configuration and update {{#var:HARDWARE_NAME}} SOM and variants.


= Supported hardware and features =
5. These additional tools are required for Android development, including Git, Swig, and others:
= Hardware Requirements =
<pre>
You will need the Variscite {{#var:HARDWARE_NAME}} based evaluation kit.
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
</pre>


== Host (PC) setup requirements ==
=== Install Java Development Kit ===


The host development environment for Android is based on Ubuntu, please install one of the following Ubuntu versions:
Android development requires Java, so install OpenJDK version 8 which is compatible with Android 13:
* Ubuntu {{#switch: {{#var:ANDROID_NAME}} | Android 10 = 16.04/18.04 | Android 11 = 18.04/20.04/22.04 | Android 12 = 18.04/20.04/22.04 | Android 13 = 20.04/22.04 | 16.04/18.04 }} 64bit LTS [http://www.ubuntu.com/download/desktop http://www.ubuntu.com/download/desktop]
<pre>
sudo apt -y install openjdk-8-jdk
</pre>


If you are running Linux in a virtual machine you need at least 16GB of RAM and 32 GB of swap. <br>
{{Note|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.}}
The build process requires ~250GB of free storage space of SSD. <br>
Before starting a build, make sure you have adequate free space available.


{{Note|'''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.
== Configuring Git for Development ==


To learn more, please see Variscite's [[Docker_Build_Environment | Docker Build Environment]] guide.
1. Set Your Git Username:
Windows with WSL/WSL2 is not supported for Android BSP}}
<pre>
git config --global user.name "Your Name"
</pre>


=== Install required packages on host PC ===
2. Set Your Git Email Address:
<pre>
<pre>
$ sudo apt-get -y install gnupg flex bison gperf build-essential zip gcc-multilib g++-multilib
git config --global user.email "Your Email"
$ sudo apt-get -y install libc6-dev-i386 libncurses5 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 
$ 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 python-is-python3
</pre>
</pre>


For Ubuntu 20.04 and above:<br>
{{Note|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.}}
The package '''android-tools-fsutils''' is obsolete and has been replaced by '''android-sdk-libsparse-utils'''.
 
== 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:
<pre>
<pre>
$ sudo apt-get -y install android-sdk-libsparse-utils
mkdir -p ~/bin
</pre>
</pre>


=== Configure Git ===
2. Download the repo tool into your '''~/bin''' directory. The repo tool is a Python script, and you can download it using curl:
$ git config --global user.name "Your Name"
<pre>
$ git config --global user.email "Your Email"
curl -o ~/bin/repo https://commondatastorage.googleapis.com/git-repo-downloads/repo
</pre>


=== Install the OpenJDK ===
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:
To install it:
<pre>
chmod a+x ~/bin/repo
</pre>


$ sudo apt-get update
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:
$ sudo apt-get install openjdk-8-jdk
<pre>
export PATH=~/bin:$PATH
</pre>


If your Ubuntu version is missing the package (which shouldn't happen), add the PPA repository and run the previous commands again:
{{Note|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.}}


$ sudo add-apt-repository ppa:openjdk-r/ppa
== Setting Up the Android Build Environment and Toolchain ==


Update the default Java version by running:
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.


$ sudo update-alternatives --config java
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:
$ sudo update-alternatives --config javac
<pre>
mkdir ~/var_aosp_ti-13_09_00_00 && cd $_
</pre>


<span style="color:red">Note:</span> The build process requires about 500GB of free space.
2. To make it easier to reference this directory in future commands, set an environment variable YOUR_PATH to its full path:
{{#switch: {{#var:ANDROID_NAME}} | Android 10 = {{#vardefine:HOST_OS|UBUNTU_16_04_18_04}} | Android 11 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} | Android 12 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} |
<pre>
Android 13 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} | {{#vardefine:HOST_OS|UBUNTU_16_04_18_04}}}}
export YOUR_PATH=$PWD
</pre>


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.


=== Check python version ===
1. Navigate to the created directory:
In the next steps, we will download (from Google repositories) the command repo, used to download all the Android source repositories.
<pre>
{{#switch: {{#var:ANDROID_NAME}} | Android 10 = {{#vardefine:HOST_OS|UBUNTU_16_04_18_04}} | Android 11 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} | Android 12 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} | Android 13 = {{#vardefine:HOST_OS|UBUNTU_18_04_20_04_22_04}} | {{#vardefine:HOST_OS|UBUNTU_16_04_18_04}}}}
cd ${YOUR_PATH}/
</pre>


{{#ifeq:{{#var:HOST_OS}}|UBUNTU_16_04_18_04 |
2. Create a subdirectory for the toolchains:
Recent versions of command repo, rely on python 3.6, not available in Ubuntu 16.04.
<pre>
mkdir -p toolchain
</pre>


Ubuntu 16.04 LTS users can install it running
3. Download and extract the ARM toolchains:
<pre>
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
</pre>


$ sudo add-apt-repository ppa:deadsnakes/ppa
4. Finally, add the paths to the ARM toolchains to your PATH environment variable. This allows you to use the toolchains from any directory:
$ sudo apt-get update
<pre>
$ sudo apt-get install python3.6 python2
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
|
</pre>
Certain tools like bpttools requires python2 which is not available default on Ubuntu 20.04 or 22.04 LTS. <br>
Ubuntu 20.04/22.04 LTS users can install it running


  $ sudo apt-get install software-properties-common
{{Note|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.}}
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.6 python2


{{#switch: {{#var:ANDROID_NAME}} | Android 10 =
= Initializing and Syncing the Android Repository =
Ubuntu 22.04 LTS users you need to setup python2 as default python for the bpttools if you are building Android 10 or older other build tools to work. <br>
Assuming you have installed python3.6 and python2 packages
$ cd /usr/bin
$ sudo ln -sf /usr/bin/python2 python
|
Make sure you use latest repo tool for all bug fixes
}}
}}


= Obtain source code =
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.


Variscite's Linux kernel and U-Boot are available through Github.<br>
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:
Required patches for the Android file system are pre-installed<br>
<pre>
<br>
mkdir -p ${YOUR_PATH}/ti-aosp-13 && cd $_
</pre>


== Download Google Repo Tool ==
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:
$ mkdir -p ~/bin
<pre>
$ curl -o ~/bin/repo https://commondatastorage.googleapis.com/git-repo-downloads/repo
repo init -u https://github.com/varigit/variscite-bsp-platform.git -b ti-android-13.0.0_r62-var01 -m RLS_09_00.xml
$ chmod a+x ~/bin/repo
</pre>
$ export PATH=~/bin:$PATH


== Clone Variscite's U-Boot and Linux kernel sources ==
3. After initializing the repository, synchronize it to retrieve the source code:
$ mkdir {{#var:BUILD_FOLDER}} && cd $_
<pre>
$ export YOUR_PATH=$PWD
repo sync -j$(nproc)
$ mkdir -p ${YOUR_PATH}/ti-bootloader-aosp/ && cd $_
</pre>
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b {{#var:ANDROID_MANIFEST_BRANCH}} -m {{#var:AM62_BOOTLOADER_MANIFEST}}.xml
$ repo sync -j4
$ mkdir -p ${YOUR_PATH}/ti-kernel-aosp/ && cd $_
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b {{#var:ANDROID_MANIFEST_BRANCH}} -m {{#var:AM62_KERNEL_MANIFEST}}.xml
$ repo sync -j4


== Clone Variscite's AOSP sources ==
{{Note|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.}}
$ mkdir -p ${YOUR_PATH}/ti-aosp-13 && cd $_
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b {{#var:ANDROID_MANIFEST_BRANCH}} -m {{#var:AM62_AOSPFS_MANIFEST}}.xml
  $ repo sync -j4
$ 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
$ 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


= Build Bootloader Components =
== Customizing the Kernel Build ==


== Download Toolchain and setup PATH ==
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.
$ cd ${YOUR_PATH}/ti-bootloader-aosp/
$ mkdir -p toolchain
$ 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
$ export PATH=$PATH:${YOUR_PATH}/ti-bootloader-aosp/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin:${YOUR_PATH}/ti-bootloader-aosp/toolchain/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin
$ export G_CORE_SECDEV_K3_SRC_DIR="${DEF_SRC_DIR}/core-secdev-k3"
$ export G_CORE_K3_IMAGE_GEN_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/k3-image-gen"
$ export G_CORE_LINUX_FIRMWARE_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/ti-linux-firmware"
$ 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_UBOOT_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/ti-u-boot"
$ export G_UBOOT_DEF_CONFIG_R="am62x_var_som_r5_defconfig"
$ export G_UBOOT_DEF_CONFIG_A="am62x_var_som_a53_android_defconfig"
$ export G_CROSS_COMPILER_JOPTION="-j $(nproc)"


== Build ATF ==
=== Remove References to DTB Files ===
$ cd ${YOUR_PATH}/ti-bootloader-aosp/
$ make -C ${G_ATF_SRC_DIR} clean
$ make -C ${G_ATF_SRC_DIR} E=0 CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=aarch64 PLAT=k3 TARGET_BOARD=lite SPD=opteed CFLAGS+="-DK3_PM_SYSTEM_SUSPEND=1"


== Build OPTEE ==
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:
$ cd ${YOUR_PATH}/ti-bootloader-aosp/
<pre>
$ make -C ${G_OPTEE_SRC_DIR} clean
sed -i '/DTB_FILES :=/d' device/ti/am62x/build/tasks/dtimages.mk
$ make -C ${G_OPTEE_SRC_DIR} CROSS_COMPILE32=arm-none-linux-gnueabihf- CROSS_COMPILE64=aarch64-none-linux-gnu- PLATFORM=k3-am62x CFG_ARM64_core=y
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
</pre>


== Build ti-boot3 R5 ==
=== Include Custom DTB Files ===
$ cd ${YOUR_PATH}/ti-bootloader-aosp/ti-u-boot
$ rm -rf out
$ cd ${YOUR_PATH}/ti-bootloader-aosp
$ make -C ${G_UBOOT_SRC_DIR} mrproper
$ make -C ${G_UBOOT_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm O=${G_UBOOT_SRC_DIR}/out/r5 \
                CROSS_COMPILE=arm-none-linux-gnueabihf- \
                ${G_UBOOT_DEF_CONFIG_R}
$ make -C ${G_UBOOT_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm O=${G_UBOOT_SRC_DIR}/out/r5 \
                CROSS_COMPILE=arm-none-linux-gnueabihf-


== Build tiboot3-am62x-gp-evm.bin (GP) ==
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:
$ make -C ${G_CORE_K3_IMAGE_GEN_SRC_DIR} mrproper
<pre>
$ make -C ${G_CORE_K3_IMAGE_GEN_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm \
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' \
                CROSS_COMPILE=arm-none-linux-gnueabihf- \
      device/ti/am62x/build/tasks/dtimages.mk
                SOC=am62x SOC_TYPE=gp SBL=$G_UBOOT_SRC_DIR/out/r5/spl/u-boot-spl.bin \
</pre>
                SYSFW_DIR=${G_CORE_LINUX_FIRMWARE_SRC_DIR}/ti-sysfw


== Build tiboot3-am62x-hs-evm.bin (HS-SE) ==
{{Note|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.}}
$ make -C ${G_CORE_K3_IMAGE_GEN_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm \
                CROSS_COMPILE=arm-none-linux-gnueabihf- \
                SOC=am62x SOC_TYPE=hs SBL=$G_UBOOT_SRC_DIR/out/r5/spl/u-boot-spl.bin \
                SYSFW_DIR=${G_CORE_LINUX_FIRMWARE_SRC_DIR}/ti-sysfw \
                TI_SECURE_DEV_PKG=${G_CORE_SECDEV_K3_SRC_DIR}


== Build tiboot3-am62x-hs-fs-evm.bin (HS-FS) ==
= Building U-Boot and Bootloader Components =
$ make -C ${G_CORE_K3_IMAGE_GEN_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm \
                CROSS_COMPILE=arm-none-linux-gnueabihf- \
                SOC=am62x SOC_TYPE=hs-fs SBL=$G_UBOOT_SRC_DIR/out/r5/spl/u-boot-spl.bin \
                SYSFW_DIR=${G_CORE_LINUX_FIRMWARE_SRC_DIR}/ti-sysfw \
                TI_SECURE_DEV_PKG=${G_CORE_SECDEV_K3_SRC_DIR}


== Build u-boot A53 with Android ==
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:
$ cd ${YOUR_PATH}/ti-bootloader-aosp
$ make -C ${G_UBOOT_SRC_DIR} mrproper
$ make -C ${G_UBOOT_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm O=${G_UBOOT_SRC_DIR}/out/a53 \
                CROSS_COMPILE=aarch64-none-linux-gnu- \
                ${G_UBOOT_DEF_CONFIG_A}


== Build tispl.bin and u-boot.img ==
* ARM Trusted Firmware (ATF);
$ make -C ${G_UBOOT_SRC_DIR} ${G_CROSS_COMPILER_JOPTION} ARCH=arm O=${G_UBOOT_SRC_DIR}/out/a53 \
* OP-TEE OS;
                CROSS_COMPILE=aarch64-none-linux-gnu- \
* U-Boot for both R5 and A53 cores.
                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}


== Copy bootloader images to AOSP build ==
== Initializing Bootloader Repository ==
$ cp ${G_CORE_K3_IMAGE_GEN_SRC_DIR}/tiboot3.bin \
                ${G_CORE_K3_IMAGE_GEN_SRC_DIR}/tiboot3-am62x-gp-evm.bin \
                ${G_CORE_K3_IMAGE_GEN_SRC_DIR}/tiboot3-am62x-hs-evm.bin \
                ${G_CORE_K3_IMAGE_GEN_SRC_DIR}/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/


= Build Kernel Image =
1. Create a directory for the bootloader source code and navigate into it:
$ cd ${YOUR_PATH}/ti-kernel-aosp/
<pre>
$ export DIST_DIR=${YOUR_PATH}/ti-aosp-13/device/variscite/am62x-kernel/kernel/6.1
mkdir -p ${YOUR_PATH}/ti-bootloader-aosp/ && cd $_
$ mkdir -p $DIST_DIR
</pre>
$ tools/bazel run --lto=full //common:ti_dist -- --dist_dir=$DIST_DIR
<span style="color:red">Note:</span> The build process uses bazel tool. <br> This is not a standard kernel build process unlike make/soong. Google has published the guideline and package GKI bazel build, refer to https://source.android.com/docs/core/architecture/kernel/generic-kernel-image for more details.


== To re-build Kernel fast for changes from the previous full build ==
2. Initialize the repository with the required bootloader XML manifest:
$ tools/bazel run --config=fast //common:ti_dist -- --dist_dir=$DIST_DIR
<pre>
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
</pre>


= Build Android Images =
3. Synchronize the repository to retrieve the source code:
<pre>
repo sync -j$(nproc)
</pre>


Change to Android top level directory.
{{Note|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.}}
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_ANDROID}}
  $ source build/envsetup.sh
$ lunch {{#var:ANDROID_MACHINE_NAME}}-userdebug
{{#ifeq:{{#var:ANDROID_USERBUILD_SUPPORT}}|true |
or
$ lunch {{#var:ANDROID_MACHINE_NAME}}-user
}}


<span style="color:red">Note:</span> {{#switch: {{#var:ANDROID_NAME}} |Android 10 = userdebug build creates a debuggable version of Android.|Android 11 = userdebug build creates a debuggable version of Android.
4. After syncing the bootloader repository, set the environment variables to specify the locations of the bootloader components:
  |Android 12 = userdebug build creates a debuggable version of Android.
<pre>
  |Android 13 = userdebug build creates a debuggable version of Android.
export G_ATF_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/arm-trusted-firmware"
  |userdebug build creates a debuggable version of Android.
export G_OPTEE_SRC_DIR="${YOUR_PATH}/ti-bootloader-aosp/optee_os"
eng build creates an engineering version of Android. Development mode enable and development tools are available on target.
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"
{{#ifeq:{{#var:ANDROID_USERBUILD_SUPPORT}}|true |
</pre>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user build creates a production version of Android.
</span>
}}
$ export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
== Build Android ==
=== Switching from eMMC build to SD card build and vice versa ===
* For eMMC boot
$ m TARGET_AVB_ENABLE=true -j4  2>&1 {{!}} tee build1-1.log
* For SD boot (Booting the entire Android from SDCard only)
=== Patch U-boot to be able to flash Android on sdcard via fastboot ===
Apply this patch in the U-boot source code and re-build, copy bootloader components as per above steps:
<syntaxhighlight lang="diff">
diff --git a/configs/am62x_var_som_a53_android_defconfig b/configs/am62x_var_som_a53_android_defconfig
index 43ebd4e2f2..91e7ee0b47 100644
--- a/configs/am62x_var_som_a53_android_defconfig
+++ b/configs/am62x_var_som_a53_android_defconfig
@@ -125,7 +125,7 @@ CONFIG_USB_FUNCTION_FASTBOOT=y
CONFIG_FASTBOOT_BUF_ADDR=0xC0000000
CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
CONFIG_TI_SCI_PROTOCOL=y
CONFIG_SPL_DM_GPIO_LOOKUP_LABEL=y
</syntaxhighlight>
$ m TARGET_SDCARD_BOOT=true TARGET_AVB_ENABLE=true -j4 2>&1 {{!}} tee build1-1.log


== Images created by the Android build ==
== Building ARM Trusted Firmware (ATF) ==
The resulted images are located in out/target/product/{{#if: {{#var:ANDROID_PRODUCT_NAME}} | {{#var:ANDROID_PRODUCT_NAME}} | {{#var:ANDROID_MACHINE_NAME}} }}.
{{#lst:Android_Platform_Customization|{{#var:ANDROID_IMAGES_SECTION}}}}
{{#lst:APC_VAR-SOM-AM62|{{#var:ANDROID_IMAGES_SECTION}}}}


= Boot options=
1. Navigate to the ATF source directory:
<pre>
cd ${G_ATF_SRC_DIR}
</pre>


Boot options of the Android:<br>
2. Clean and build the ATF:
1. U-Boot boots from on-SOM eMMC<br>
<pre>
2. Directly from SD card (Requires separate build for bootloader and AOSP images see above)<br>
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"
</pre>


== Building OP-TEE OS ==


== Flash and boot Android from SD card ==
1. Navigate to the OP-TEE OS source directory:
=== Create a bootable SD card ===
<pre>
<pre>
$ cd ${YOUR_PATH}/ti-aosp-13/out/target/product/am62x_var_som
cd ${G_OPTEE_SRC_DIR}
$ sudo ./flashall.sh --board am62x-sk --hsfs /dev/sdX;sync
</pre>
</pre>
OR
 
If you want to boot entire Android from SD Card
2. Clean and build OP-TEE OS:
<pre>
<pre>
$ cd ${YOUR_PATH}/ti-aosp-13/out/target/product/am62x_var_som
make clean && rm -rf out
$ sudo ./flashall.sh --board am62x-sk --sdcard --hsfs /dev/sdX;sync
make CROSS_COMPILE32=arm-none-linux-gnueabihf- CROSS_COMPILE64=aarch64-none-linux-gnu- PLATFORM=k3-am62x CFG_ARM64_core=y
</pre>
</pre>
* Replace /dev/sdX with your true device, You can identify it with dmesg.


=== Boot From SD card ===
== Building U-Boot for R5 Core ==
{{#lst:Android_Recovery_SD_card|BOOT_FROM_SD_CARD}}


== Flash and boot Android from eMMC ==
1. Set U-Boot R5 Configuration:
<pre>
export G_UBOOT_DEF_CONFIG_R="am62x_var_som_r5_defconfig"
</pre>


=== Flashing Android from Linux shell (when the primary installation android) ===
2. Navigate to U-Boot Source Directory and Build:
An example of flashing eMMC, can be found {{Varlink|Android Recovery SD card|{{#var:RELEASE_PARAM|RELEASE_O8.1.0_1.3.0_8M_DART-MX8M}}|here}}.
<pre>
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/>


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


1. Preparing a rescue SD card;
== Building U-Boot for A53 Core with Android ==


2. Flash from command line (use the install_android.sh script)
1. Set U-Boot A53 Configuration:
<pre>
export G_UBOOT_DEF_CONFIG_A="am62x_var_som_a53_android_defconfig"
</pre>


2. Navigate to U-Boot Source Directory and Build:
<pre>
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}
</pre>


Further, follow the steps described in paragraph "'''Flashing Android with USB Fastboot'''"
3. Use the find command to locate the tispl.bin and u-boot.img files for A53:
<pre>
find ${G_UBOOT_SRC_DIR} -name "tispl.bin"
find ${G_UBOOT_SRC_DIR} -name "u-boot.img"  
</pre>


== Copying Bootloader Images to AOSP Build ==


=== Flashing Android with USB Fastboot ===
1. Copy the built bootloader binaries to the AOSP build directory:
<pre>
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/
</pre>


==== Install tools on host ====
2. Check that the bootloader binaries are correctly placed in the AOSP build directory:
<pre>
<pre>
$ sudo apt-get install android-tools-adb android-tools-fastboot
ls -l ${YOUR_PATH}/ti-aosp-13/vendor/variscite/am62x_var_som/bootloader/am62x-sk/
</pre>
</pre>


<span style="color:red">Note:</span> Make sure you built Android for eMMC
{{Note|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.}}
<br>
'''Connect the target with host PC at fastboot mode:'''
#Connect a USB OTG cable from the target board OTG port to a your host machine USB HOST port.
#Power up the board and hit return/space to stop the boot at U-Boot.
#type '''fastboot 0''' in the U-Boot command line.


'''On the Host PC:'''
= Building Linux Kernel =
{{#lst:Android_Platform_Customization|{{#var:ANDROID_FASTBOOT_SECTION}}}}


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


==== Generate OTA packages ====
== Initializing Kernel Repository ==


===== For generating "OTA" packages, use the following commands: =====
1. Create a directory specifically for the Variscite kernel source and navigate into it:
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_ANDROID}}
<pre>
$ source build/envsetup.sh
mkdir -p ${YOUR_PATH}/ti-kernel-aosp/ && cd $_
$ lunch PRODUCT={{#var:ANDROID_MACHINE_NAME}}-userdebug
</pre>
$ m otapackage TARGET_AVB_ENABLE=true


===== Install OTA package to device: =====
2. Initialize the repository with the required kernel XML manifest:
* Extract payload.bin and payload_properties.txt from OTA zip file
<pre>
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 11 |
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
* Push payload.bin to board's /data/ota_package dir: adb push payload.bin /data/ota_package/ .
</pre>
  |
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 10 |
* Push payload.bin to board's /sdcard dir: adb push payload.bin /sdcard/ .
  |
* Push file payload.bin to somewhere on the device (typically /data/ota_package folder)
  adb push payload.bin /data/ota_package/payload.bin
  }}}}
* Open payload_properties.txt on an editor to copy its content, lets suppose it's like in the TI manual:
  FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
  FILE_SIZE=379074366
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 10 |
  METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ=
  |
  METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ/de8Dgp9zFXt8Fo+Hxccp465uTOvKNsteWU=
  }}
  METADATA_SIZE=46866
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 11 | Android 12 |
* Input the following command on the board's console to update:
  su
  setenforce 0
  update_engine_client --payload=file:///data/ota_package/payload.bin --update --headers="FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
  |
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 10 |
* Input the following command on the board's console to update:
  su
  setenforce 0
  update_engine_client --payload=file:///sdcard/payload.bin --update --headers="FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
  |
* Issue the following command on adb shell:
  update_engine_client --payload=file:///cache/payload.bin --update --headers="FILE_HASH=0fSBbXonyTjaAzMpwTBgM9AVtlBeyOigpCCgkoOfHKY=
  }}}}
  FILE_SIZE=379074366
  {{#ifeq: {{#var:ANDROID_NAME}} | Android 10 |
  METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ=
  |
  METADATA_HASH=Icrs3NqoglzyppyCZouWKbo5f08IPokhlUfHDmz77WQ/de8Dgp9zFXt8Fo+Hxccp465uTOvKNsteWU=
  }}
  METADATA_SIZE=46866"


{{#ifeq: {{#var:ANDROID_NAME}} | Android 11 |Android 12 | Android 13
3. Synchronize the repository to retrieve the source code:
Make sure that the -- header equals to the exact content of payload_properties.txt without "space" or "return"
<pre>
character.
repo sync -j$(nproc)
|
</pre>
{{#ifeq: {{#var:ANDROID_NAME}} | Android 10 |
Make sure that the -- header equals to the exact content of payload_properties.txt without "space" or "return"
character.
|
Note that the command argument --headers="..." contains the exact (4-line) content of the payload_properties.txt file between quotes (you can copy and paste it), including 3 newline characters.
}}}}
After issuing the command, nothing seems to happen on the device, but you can monitor logcat for operation progress. After a successful update, you can reboot into the updated version (_b/_a) slot.


= Manual operations =
{{Note|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.}}


== Build boot.img ==
== Building the Kernel ==
When you perform changes to the kernel, you may build boot.img solely instead of building the whole Android.
$ cd ${YOUR_PATH}/ti-kernel-aosp/
$ export DIST_DIR=${YOUR_PATH}/ti-aosp-13/device/variscite/am62x-kernel/kernel/6.1
$ tools/bazel run --lto=full //common:ti_dist -- --dist_dir=$DIST_DIR
$ cd ${YOUR_PATH}/ti-aosp-13
$ lunch am62x_var_som-userdebug
$ m TARGET_AVB_ENABLE=true


== Menu Config ==
1. Once the repository is synchronized, navigate to the kernel source directory:
$ cd ${YOUR_PATH}/ti-kernel-aosp/
<pre>
$ tools/bazel run //common:ti_config -- menuconfig
cd ${YOUR_PATH}/ti-kernel-aosp/
</pre>


== Porting Drivers Notes ==
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:
* Actual Kernel source code is in ${YOUR_PATH}/ti-kernel-aosp/common
<pre>
* Defconfig Used in the kernel is from Google: ${YOUR_PATH}/ti-kernel-aosp/common/arch/arm64/configs/gki_defconfig
export DIST_DIR=${YOUR_PATH}/ti-aosp-13/device/variscite/am62x-kernel/kernel/6.1
* All drivers and SOC infrastructure is via modules and is setup by: ${YOUR_PATH}/ti-kernel-aosp/common/arch/arm64/configs/ti_gki.fragment
mkdir -p $DIST_DIR
* Your driver/ kernel module .ko must be added to GKI module list
<pre>
    module_outs = COMMON_GKI_MODULES_LIST + [
    "net/wireless/your_module.ko",   
    "drivers/spi/your_driver.ko",
    ]
</pre>
</pre>


* Your driver module dependencies must be resolved and must align ${YOUR_PATH}/ti-aosp-13/device/variscite/am62x_var_som/BoardConfig.mk
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: 
with following
<pre>
<pre>
BOARD_VENDOR_RAMDISK_KERNEL_MODULES += \
tools/bazel run --lto=full //common:ti_dist -- --dist_dir=$DIST_DIR
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/zsmalloc.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/zram.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/ti-msgmgr.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/ti_sci.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/ti_sci_pm_domains.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/phy-omap-usb2.ko \
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/syscon-clk.ko \
                |                                  |
                |                                  |
        device/variscite/am62x-kernel/kernel/$(TARGET_KERNEL_USE)/your_driver.ko
</pre>
</pre>
{{Note|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.

Latest revision as of 20:31, 25 January 2024

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.