Last edited 3 weeks ago

How to populate boards for Android

Applicable for STM32MP25x lines

Warning DB.png Important
OpenSTDroid is validated against the ecosystem release v5.1.0 . It has not been ported yet on ecosystem release v6.0.0 More info.png .

This article describes how to load AndroidTM distribution images, built for the STM32MPU, to defined Flash device partitions. It is intended for Distribution Package users.

1. Prerequisites[edit | edit source]

The recommended host PC setup is specified in the following article: PC prerequisites.

The environment must be installed using the Distribution Package adapted to the selected microprocessor device.

It is assumed that:


Additionally, Fastboot mode is useful to accelerate the device provisioning (commands sent through USB).

In Linux environments, the Android USB drivers are built-in. The only action required is to set the target device information.

Info white.png Information
To perform this action, you need administrator rights. In addition, you may need to add sudo in front of each executed command

To do this, open a terminal and

  • Create (or update if it already exists) the 51-android.rules file in /etc/udev/rules.d/ with the following information
    • idVendor = 0483 (STMicroelectronics vendor)
    • idProduct = 5720 or 0afb (depends on board configuration)
    • Mode = 0660 (read/write permissions)
    • Group = plugdev (Unix group which owns the device node)
Info white.png Information
Check if you belong to the plugdev group by executing the following command:
$ groups

Example:

# Fastboot on STMicroelectronics devices
SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="0afb", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="5720", MODE="0660", GROUP="plugdev"
  • Make sure that the access rights to the created file are the correct ones:
 chmod a+r /etc/udev/rules.d/51-android.rules

At this stage, your USB driver is correctly installed and configured.

2. Populate a board[edit | edit source]

The out/target/product/<BoardId> directory contains all images built for the selected board during the setup (lunch step).

The STM32CubeProgrammer tool is used to flash the first stages of the images to the board. Then fastboot is used to flash the remaining images.

The board shall be started in "Forced USB boot for flashing" mode (also named DFU), selecting it through boot switches as explained in the article <your board reference - hardware description>, chapter Boot related switches (for example, Boot switches on the STM32MP257x-EV1 board for the STM32MP257F-EV1 board).


Connect the board to the host PC through USB.

The board can be designed to support several flash devices, for example: microSD, eMMC and so on. This document uses the eMMC as the Flash device example for this article.

  • Go to the distribution root directory, and run flash-device:
flash-device

Once the DFU flashing is completed, the boot switches must be configured so that the correct Flash device (e.g. eMMC) is selected as the boot source.

  • Press the reset button and keep the USER 2 button (refer to LEDs and buttons on STM32 MPU boards) pressed until the board enters fastboot. The device provisioning continues until the required images have been loaded.
This operation takes several minutes.
  • When the download is finished, press the reset button in the board. The Android software then starts.

3. Populate a microSD card (case hybrid)[edit | edit source]

In case of hybrid (eMMC / microSD card) configuration, you have to flash the data partitions (metadata and userdata) in a microSD card.

First you need to create the disk image:

create-disk --hybrid

At this stage, the image st-android-optee-sd.raw has been created in the out subdirectory.


It's then possible to copy this image on a microSD card:

Linux (ex: Ubuntu) host

dd if=st-android-optee-sd.raw of=<device_path> bs=8M conv=fdatasync status=progress
sgdisk --move-second-header <device_path>

With:

  • <device_path>: the device identified in the system to access the microSD card (/dev/sdX for microSD card connected through USB dongle or /dev/mmcblkX for microSD card connected through reader, X is the instance associated to the Flash device).

Windows host

Example using HDD Raw Copy Tool :

  • Select the SOURCE: st-android-<boot_mode>-sd.raw
  • Select the TARGET: microSD card
  • Click on “START” button

4. Flash a dedicated image[edit | edit source]

If an Android distribution is already installed and booted on the board, it's possible to update partitions one by one depending on the need. For example, if the kernel is rebuilt, just flash the boot (kernel), the dt (device tree) and the vendor images (modules).


First the device has to be restarted in fastboot mode:

  • Keep the reset button pressed until the board enters fastboot (USER1 for Evaluation board).

or

  • Run the command
adb reboot bootloader


Finally, execute the flashing command:

provision-device -i reboot
  • -i option means that a confirmation will be needed for flashing each partition at a time (select the partitions that need to be updated)
  • reboot option means that the device will reboot automatically at the end

5. Update an Android distribution[edit | edit source]

If the content of the partitions dedicated to AndroidTM needs to be updated (vendor,system, system_ext or product) after a rebuild, use ADB tool.

An overlayfs mechanism is used to allow updating files in read-only partitions, the first time you have to execute the following commands:

adb root
adb remount
adb reboot

It is then possible to update the AndroidTM partitions.

adb root
adb remount
adb sync

Finally, the device needs to be rebooted to take these changes into account

adb reboot

If the modifications that you made concern a (some) specific service(s), it might be enough to restart these services to take these modifications into account, instead of rebooting the device:

adb shell stop <targeted services>; adb shell start <targeted services>

For example, if only the vendor camera code is modified, it is enough to restart the associate service ("vendor.camera.provider.stm32mpu"):

adb shell stop vendor.camera.provider.stm32mpu; adb shell start vendor.camera.provider.stm32mpu