# Try it out: Ethos-U on NXP FRDM i.MX 93 Development Board

Run a TensorFlow Lite model on the Arm Ethos-U65 NPU of the NXP FRDM-IMX93 board, using upstream Linux and Mesa.


This guide turns the Open Inference Stack
[base requirements](/getting-started/integration/) into concrete steps for the
[NXP FRDM i.MX93 Development Board](https://www.nxp.com/design/design-center/development-boards-and-designs/FRDM-IMX93)
which includes an **Arm Ethos-U65** NPU.

After completing this guide, you will have a complete Linux distro installation
using mainline kernel and Mesa with the open `ethosu` NPU drivers fully
operational.

It's a quick way to see the whole stack working end to end, meant for evaluation
and demos, and as a reference for
[your own implementation](/getting-started/integration/).

## Required Software Versions

| Component | Minimum version | Notes |
|---|---|---|
| Linux | 6.19 | `CONFIG_DRM_ACCEL_ARM_ETHOSU` must be enabled |
| Mesa | 26.0 | built with `-Dgallium-drivers=ethosu` |

## Yocto Reference Image

We will build a custom image of Yocto's reference distribution (Poky) for this
board with the open stack included, as well as TensorFlow Lite and some sample
models/tools.

> [!NOTE]
> Torx is not yet included in this image. This will be added soon!

### 1. Build the image

To build the image, follow the
[Yocto Project Quick Build](https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html)
instructions with the following selections and modifications:

* Build from `master` branch (some required components have not yet made it into
  the released versions)
* Add the `meta-freescale` layer and configure appropriately:
  * Enable the `machine/imx93-11x11-lpddr4x-frdm` fragment to select the
    FRDM-IMX93 platform as the target for this build.
  * Enable the `bsp/fslc` fragment to select the mainline kernel instead of the
    vendor kernel.
  * Enable `eula/accept-fsl-eula` to indicate acceptance of the NXP EULA, which
    is required to build the bootloader.
* Enable the `meta-tensorflow` layer and its dependencies (`meta-oe`,
  `meta-python`)
* Enable installation of Teflon and TensorFlow Lite in the final image

The end result is that while `meta-freescale` is used to place the
vendor-specific early boot setup in the image, the `fslc` fragment causes system
boot to proceed with mainline u-boot and mainline Linux. `meta-freescale` also
configures Mesa to be built with `teflon` and `ethosu` included. And that's all
that is needed to get the Open Inference Stack up and running!

Adapting the Quick Build guide to those changes, the resultant commands are
e.g.:

```sh
python3 -m venv --clear ./bitbake-setup-venv
. ./bitbake-setup-venv/bin/activate
pip install bitbake-setup
bitbake-setup init --non-interactive poky-master poky-with-sstate distro/poky machine/qemuarm64

cd bitbake-builds/poky-master
. build/init-build-env

# bitbake-layers takes care of dependencies automatically
bitbake-layers layerindex-fetch -b master -f ../layers meta-freescale meta-tensorflow

bitbake-config-build enable-fragment machine/imx93-11x11-lpddr4x-frdm \
    freescale-layer/bsp/fslc freescale-layer/eula/accept-fsl-eula \
    core/yocto/root-login-with-empty-password
echo 'CORE_IMAGE_EXTRA_INSTALL += "libteflon tensorflow-lite"' >> conf/local.conf

bitbake core-image-sato
```

> [!IMPORTANT]
> `accept-fsl-eula` accepts the NXP EULA, which covers the DDR and EdgeLock
> Enclave (ELE) firmware that goes into `flash.bin`. Read the EULA before you
> enable the fragment.

> [!WARNING]
> Poky is intended as a reference distribution, and the image below is
> considered to be a demonstration/prototype. Note that the image will let
> anyone log in as `root` without a password.

### 2. Flash the eMMC

1. Install NXP's [uuu](https://github.com/nxp-imx/mfgtools) flashing tool.
1. Set the SW1 boot switch to serial download mode (1000)
1. Connect the USB-C download port and power.
1. Save the following as `flash-frdm.uuu` in the deploy directory:

    ```text
    uuu_version 1.5.0
    SDPS: boot -f flash.bin
    FB: ucmd setenv fastboot_dev mmc
    FB: ucmd setenv mmcdev 0
    FB: ucmd mmc dev 0 0
    FB: flash -raw2sparse -bmap core-image-sato-imx93-11x11-lpddr4x-frdm.rootfs.wic.bmap all core-image-sato-imx93-11x11-lpddr4x-frdm.rootfs.wic.gz/*
    FB: done
    ```

1. Then run it:

    ```sh
    cd bitbake-builds/poky-master/build/tmp/deploy/images/imx93-11x11-lpddr4x-frdm
    uuu flash-frdm.uuu
    ```

1. Set SW1 back to eMMC boot (0100) and power-cycle the board.

### 3. Run a model on the NPU

The image includes a quantized MobileNet model with test data.

1. Connect to the debug UART console on the other USB-C port (115200 8N1; it
   appears as `/dev/ttyACM0` on a Linux host).

1. Log in as `root` with no password.

1. Run the benchmark on the CPU and then on the NPU through Teflon:

    ```sh
    M=/usr/share/label_image
    
    # CPU, 2 threads: about 30 ms per inference
    benchmark_model --graph=$M/mobilenet_v1_1.0_224_quant.tflite --num_threads=2
    
    # NPU through Teflon: about 4.7 ms per inference
    benchmark_model --graph=$M/mobilenet_v1_1.0_224_quant.tflite \
        --external_delegate_path=/usr/lib/libteflon.so
    ```

1. Classify an image. The top result should be "military uniform", with or
without the delegate:

    ```sh
    label_image -m $M/mobilenet_v1_1.0_224_quant.tflite -i $M/grace_hopper.bmp \
        -l $M/labels_mobilenet_quant_v1_224.txt \
        --external_delegate_path=/usr/lib/libteflon.so
    ```


---
Source: http://model-citizen.ai/getting-started/frdm-imx93/
