How to build bootloaders for Android

Revision as of 14:58, 23 August 2019 by Registered User (→‎Load the bootloader sources)

This article explains how to rebuild the primary and the secondary bootloaders. It is intended for Distribution Package users.

1. Prerequisites[edit source]

The environment must be installed using the Distribution Package adapted to your selected microprocessor device. See the list of Android Distribution Package.

To be able to execute following instructions you need to work from your distribution root directory and initialise your environment:

 source build/envsetup.sh
 bspsetup
 lunch aosp-<BoardId>-userdebug
Info white.png Information
The bspsetup command needs to be run only once for the distribution

2. Partition layout[edit source]

The Trusted Firmware (TF-A) is used as the primary bootloader in the STM32MPU distribution for Android™. The TF-A binary file is part of the fsbl partition.

The Universal Bootloader (U-Boot) is used as the secondary bootloader in the STM32MPU distribution for Android™. The U-Boot binary file is part of the ssbl partition.

The binaries are available in device/stm/<STM32Series>-bootloader/prebuilt.

For the complete partition layout please see STM32MP15 Flash mapping for Android.

3. Load the bootloader sources[edit source]

By default, the bootloader sources are not part of the STM32MPU distribution for Android. To load the sources, execute the following command:

 load_bootloader

It will load both the TF-A and U-Boot sources.

Info white.png Information

The load_bootloader script uses the configuration file android_fsbl.config (resp. android_ssbl.config) available in the device/stm/<STM32Series>-bootloader/source/patch/<fsbl-version>/ (resp. .../<ssbl-version>/) directory.

The bootloader sources can then be found at:

  • TF-A: device/stm/<STM32Series>-bootloader/tf-a-<STM32Series>
  • U-Boot: device/stm/<STM32Series>-bootloader/u-boot-<STM32Series>
Info white.png Information

By default, only the archive is loaded from the remote repository (reducing size). If required you can instead clone the remote repository to get all the git history.

For that purpose, you have to replace in android_fsbl.config (resp. android_ssbl.config) file BOOTLOADER_ARCHIVE_PATH by BOOTLOADER_GIT_PATH. Then execute load_bootloader again (with -f option if need to replace previously loaded source.

4. Build the bootloaders[edit source]

To build both the FSBL and the SSBL, run:

 build_bootloader

This command generate TF-A and U-Boot for every available boards, memory and boot mode in optee and trusted configuration.

To only generate for one set of configuration:

 build_bootloader --<BootMode> -b <BoardId> -m <MemoryType>

As example BootMode options are:

  • optee
  • trusted

As example MemoryType options are:

  • sd
  • emmc
Usage: build_bootloader [Options] [Mode options] [Board options]

  This script allows building the bootloaders source (TF-A and U-Boot)

Options:
  -h/--help: print this message
  -v/--version: get script version
  -i/--install: update prebuilt images
  --verbose <level>: enable verbosity (1 or 2 depending on level of verbosity required)

Mode options (exclusive, default = both optee and trusted):
  -o/--optee: set optee mode for bootloaders
  or
  -t/--trusted: set trusted mode for bootloaders (non op-tee option)
  or
  -p/--programmer: build dedicated programmer version (-i option is mandatory)

Board options: (exclusive, default = all possibilities)
  -c/--current: build only for current configuration (board and memory)
  or
  -b/--board <name>: set board name = eval or disco (default: all)
  -m/--mem <name>: set memory configuration = sd or emmc (default: all), ignored if board = disco

5. Integrate the bootloaders[edit source]

To update prebuilt images add -i option:

 build_bootloader -i

Or use the specific configuration method with -i option.

 build_bootloader -i --<BootMode> -b <BoardId> -m <MemoryType>

To integrate the updated prebuilt images, execute:

 make -j

Then you can update associated partitions on your device. Please refer to How to populate boards for Android