Aquila AM69/TDA4 Setup for Machine Learning
This article contains instructions that are experimental and may not be stable for production use. Toradex recommends using this guide as a reference for development and evaluation purposes only.
Introduction
This article will guide you through integrating hardware acceleration for Machine Learning on the Aquila AM69/TDA4 System-on-Module (SoM). It will also provide a basic setup for integrating the Texas Instruments Yocto SDK into the Toradex BSP.
By the end of this guide, you will have built a reference image suitable for developing and testing Machine Learning applications on the Aquila AM69/TDA4 SoM.
Prerequisites
-
Hardware Prerequisites:
- Aquila AM69/TDA4 SoM
- A compatible Carrier Board
-
Software Prerequisites:
- A configured build environment as described in the Host Machine Setup for Building with Yocto documentation
- Read the Build a Reference Image with Yocto Project article
Setup Instructions
Download System Packages
First, ensure you have the necessary packages installed to run the Texas Instruments (TI) layer setup script. Install the dependencies using the following commands:
$ sudo apt-get update
$ sudo apt-get -f -y install \
bison build-essential chrpath cpio curl debianutils diffstat dos2unix \
doxygen file flex g++-multilib gawk gcc git git-lfs iputils-ping \
jq libc6-dev-i386 libacl1 liblz4-tool libssl-dev locales lz4 \
mono-complete mono-devel pigz pseudo python3 python3-distutils \
python3-git python3-jinja2 python3-pexpect python3-pip python3-sphinx \
python3-subunit repo socat texinfo u-boot-tools unzip wget xz-utils \
zstd
$ sudo locale-gen en_US.UTF-8
Download the Layers From TI
The recommended way to obtain the necessary layers from TI is to use their provided script, which downloads the layers and sets up the environment.
$ cd /tmp
$ git clone https://git.ti.com/git/arago-project/oe-layersetup.git yocto-build
$ cd yocto-build
$ ./oe-layertool-setup.sh -f configs/processor-sdk-analytics/processor-sdk-analytics-11.00.00-config.txt
The oe-layertool-setup.sh script downloads the dependencies and populates the sources directory with the fetched layers. Copy only the required layers into the Toradex BSP directory:
$ cd sources
$ sudo cp -a meta-arago/ <toradex_bsp_yocto_dir>/layers/
$ sudo cp -a meta-clang/ <toradex_bsp_yocto_dir>/layers/
$ sudo cp -a meta-edgeai/ <toradex_bsp_yocto_dir>/layers/
$ sudo cp -a meta-tisdk/ <toradex_bsp_yocto_dir>/layers/
To ensure the TI layers build correctly in the Toradex BSP environment, include the Toradex-provided compatibility layer from the meta-edgeai-custom repository in your bblayers.conf file. This layer contains the required modifications to maintain compatibility between the Toradex BSP and the TI Edge AI layers.
BBLAYERS += " \
${TOPDIR}/../layers/meta-edgeai-custom \
${TOPDIR}/../layers/meta-arago/meta-arago-distro \
${TOPDIR}/../layers/meta-arago/meta-arago-extras \
${TOPDIR}/../layers/meta-arago/meta-arago-test \
${TOPDIR}/../layers/meta-clang \
${TOPDIR}/../layers/meta-edgeai \
${TOPDIR}/../layers/meta-tisdk/meta-ti-foundational \
"
Configure and Build the Image
Run the following steps to build an image based on the Toradex Reference Multimedia Image, with the necessary packages to run edge AI applications:
-
Apply the following patch to
meta-edgeai/conf/layer.confto ensure the Aquila AM69/TDA4 device trees are included in the final image:index 587607cbcd17..b1fa09c93446 100644
--- i/conf/layer.conf
+++ w/conf/layer.conf
@@ -36,6 +36,6 @@ require conf/distro/include/edgeai-source-ipk.inc
TI_TEST_TI_TOOLS:remove:pn-ti-test = "videnc-test-app"
-KERNEL_DEVICETREE_PREFIX:append:j721s2 = "ti/k3-j721s2"
-KERNEL_DEVICETREE_PREFIX:append:j784s4 = "ti/k3-j784s4"
-KERNEL_DEVICETREE_PREFIX:append:j721e = "ti/k3-j721e" -
Add the following lines to your
local.conffile to define the machine and accept the commercial license:local.confMACHINE ?= "aquila-am69"
LICENSE_FLAGS_ACCEPTED += "commercial" -
Finally, build the image with the command below:
$ bitbake edgeai-reference-imageOptimize Yocto Build RAM and CPU Usage
Your computer may run out of RAM while compiling some packages (such as Qt, in the
tdx-reference-multimedia-image).To reduce RAM usage, set the environment variables
PARALLEL_MAKEandBB_NUMBER_THREADSto a limited number of threads.make.PARALLEL_MAKE: Number of threads used bymakeBB_NUMBER_THREADS: Number of threads used bybitbake. SettingBB_NUMBER_THREADSalso limits the number of download and configuration threads.
$ PARALLEL_MAKE="-j 4" BB_NUMBER_THREADS="6" bitbake <image>warningIf a build fails due to lack of RAM, some files could be corrupted. Trying to build again may not solve this issue. In this situation:
- Delete the corrupted package
state - Delete all temporary files
- Attempt to build the image again
After the build completes, you can flash the generated image to your Aquila AM69/TDA4 SoM using Toradex Easy Installer.
Configure U-Boot
The Linux boot process starts the remote processors using remoteproc. However, a race condition where one of the cores fails to start correctly may occur, leading to failures when running Machine Learning applications.
To resolve this, patch your U-Boot environment to execute boot_rproc after bootcmd_prepare to ensure the remote processors initialize in the correct order:
> env set init_rproc 'rproc init;rproc list;'
> env set init_r5f0_0 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f0_0-fw;rproc load 2 0x90000000 0x${filesize};rproc start 2;'
> env set init_r5f0_1 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f0_1-fw;rproc load 3 0x90000000 0x${filesize};rproc start 3;'
> env set init_r5f1_0 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f1_0-fw;rproc load 4 0x90000000 0x${filesize};rproc start 4;'
> env set init_r5f1_1 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f1_1-fw;rproc load 5 0x90000000 0x${filesize};rproc start 5;'
> env set init_r5f2_0 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f2_0-fw;rproc load 6 0x90000000 0x${filesize};rproc start 6;'
> env set init_r5f2_1 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-main-r5f2_1-fw;rproc load 7 0x90000000 0x${filesize};rproc start 7;'
> env set init_c71_0 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-c71_0-fw;rproc load 8 0x90000000 0x${filesize};rproc start 8;'
> env set init_c71_1 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-c71_1-fw;rproc load 9 0x90000000 0x${filesize};rproc start 9;'
> env set init_c71_2 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-c71_2-fw;rproc load 10 0x90000000 0x${filesize};rproc start 10;'
> env set init_c71_3 'load mmc 0:2 0x90000000 /lib/firmware/j784s4-c71_3-fw;rproc load 11 0x90000000 0x${filesize};rproc start 11;'
> env set boot_rproc 'run init_rproc;run init_r5f0_0;run init_r5f0_1;run init_r5f1_0;run init_r5f1_1;run init_r5f2_0;run init_r5f2_1;run init_c71_0;run init_c71_1;run init_c71_2;run init_c71_3;'
> env set bootcmd 'run boot_rproc; bootflow scan -b'
> env save
To ensure the remote cores were initialized correctly, check the logs with the following command:
# dmesg | grep -E "remoteproc|rpmsg|c7x|r5f|mcu"
Next Steps
After following the steps presented in this article, you should now have a working setup with hardware acceleration for Machine Learning on the Aquila AM69/TDA4 SoM. For more information on developing and deploying Machine Learning applications, refer to Build Machine Learning Applications With TI Edge AI Stack.
Toradex provides additional resources to help you get started with Machine Learning on our System-on-Modules: