Understanding STM32H7 SOM Boot Architecture Print

 

This application note explains the memory and boot architecture of the STM32H7 System-On-Module SOM.

STM32H7 SOM Hardware Block Diagram

The STM32H7 SOM boot architecture is defined by the hardware architecture of the SOM:

STM32H7 SOM Hardware Block Diagram

Click to enlarge

U-Boot as Initial Firmware and RTOS Bootloader

U-Boot Overview

The STM32H7 SOM makes use of the U-Boot firmware as the RTOS OS bootloader. U-Boot is a sophisticated open-source, GPL-licensed firmware monitor that supports, off-the-shelf, various I/O interfaces and functionalities that are important for purposes of this project. Specifically, the following capabilities of U-Boot will be used:

  • Serial console command interface with various set-up, test and maintenance commands;
  • Environment variables allowing customisation of a unit;
  • Sophisticated OS auto-boot sequence;
  • Partitioning and UBI management of QSPI Flash;
  • Initial installation of OS images to QSPI Flash;
  • Reliable upgrade of redundant OS images in QSPI Flash.

STM32H7 SOM U-Boot Configuration

This project makes use of U-Boot version 2019.04-rc3. It is built, configured, ported and otherwise enhanced specifically for the STM32H750 System-on-Module and development carrier board, running RTOS. Key U-Boot files specific to the STM32H750 System-on-Module are as follows, in the U-Boot source tree:

  • include/configs/stm32h7-som.h - U-Boot configuration file specific to the STM32H750 System-on-Module and development carrier board;
  • board/emcraft/stm32h7-som/ - U-Boot code specific to support of the STM32H750 System-on-Module;
  • arch/arm/dts/stm32h7-som.dts - U-Boot run-time I/O configuration file.

U-Boot SPL and U-Boot "Proper"

It is important to note that the STM32H750 device has only 128KB of internal (on-chip) Flash. This implies that the initial firmware binary must be small enough to fit into this amount of Flash. U-Boot supports this, by implementing the concept of the "U-Boot SPL". When the U-Boot SPL build-time option (CONFIG_SPL_BUILD) is enabled in the U-Boot configuration file (include/configs/stm32h7-som.h), the U-Boot build procedure will build two separately loadable firmware images:

  • U-Boot SPL - first-stage bootloader is the U-Boot SPL. The U-Boot SPL is called by the STM32H750 hardware from internal Flash on power-on / reset. This is a minimal stand-alone configuration of U-Boot that is small in size. The U-Boot SPL performs basic initialization of the system and then loads the main U-Boot from external storage device to RAM and invokes the main U-Boot in RAM. On the STM32H750 System-on-Module, the U-Boot SPL will load the U-Boot image from QSPI Flash to SRAM and then pass control to the main U-Boot which relocates to SDRAM.
  • Main U-Boot (or "U-Boot proper") - second-stage bootloader, which is the regular full-fledged U-Boot with all the features and capabilities. It is larger in size (typically, size is larger than 250KB). On the STM32H750 System-on-Module, the main U-Boot will be responsible, among other things, for fully initializing the system, selecting an appropriate bootable RTOS image out of the two redundant OS images, relocating the OS image from Flash to RAM and finally calling RTOS in RAM.

U-Boot Command Monitor

Both the U-Boot SPL and main U-Boot support an interactive command interface (also referred to as the "command monitor") via the UART-based serial console. The U-Boot SPL provides a very minimal set of user commands, sufficient for basic examination of the system as well as load and installation of bootable images. The main U-Boot provides a sophisticated command monitor with various commands and scripting capabilities.

The UART based serial console is a standard feature of U-Boot. On the STM32H750 System-on-Module, USART1 is configured as the U-Boot serial console (refer to include/configs/stm32h7-som.h).

The serial console is available both in the U-Boot SPL and main U-Boot. It is important to note that in order to make sure that the USART1 related definitions are not truncated from the U-Boot SPL run-time configuration file (arch/arm/dts/stm32h7-som.dts), special constructs must be included in the .dts file, for the USART1 node and associated STM32 pins, as follows:

&usart1 { u-boot,dm-spl; ...

SDRAM Initialization

The U-Boot initializes the SDRAM controller and sets it up for optimal performance of the specific SDRAM device used in the STM32H750 SOM design. There are two assembly-build-time configurations of the hardware SOM that will be supported by U-Boot, defined by the value of the PE2 GPIO input at boot time:

  • 0 (low) implies that the SOM is populated with 1 SDRAM chip (32MB 16-bit SDRAM);
  • 1 (active) implies that the SOM is populated with 2 SDRAM chips (64MB 32-bit SDRAM).

The U-Boot reads the value of the PE2 GPIO input and configures the SDRAM interface appropriately, setting it up for one of the two SDRAM assembly options above. Namely, the sdram init function from board/emcraft/stm32h7-som/stm32h7-som.c calls the detect_sdram_size function from this module to get the value of the PE2 GPIO input. In case of PE2 GPIO input active, the dts_fixup function residing in this module is also called. This function patches the u-boot device tree to provide the correct values for the U-Boot memory controller driver.

Having initialized SDRAM, the U-Boot relocates to appropriate addresses in RAM memory map and then calls the main U-Boot entry point. From that point on, the main U-Boot controls the system.

Amount of available SDRAM is stored in the U-Boot mem environment variable.

Understanding Software Installation Procedure

Understanding Software Installation Procedure Overview

Procedure to install U-Boot to the STM32H750 consists of two parts:

  • Installation the U-Boot SPL image to the internal Flash of the STM32H750;
  • Installation the main U-Boot and RTOS images to the QSPI Flash.

Using ST-LINK to Install U-Boot SPL to Internal Flash

The SWD or JTAG interface along with the STM32 ST-LINK utility must be used to install the U-Boot SPL (spl/u-boot-spl.bin) to the internal Flash of the STM32H750.

Installing U-Boot "Proper" and RTOS to External Flash via UART

The dedicated kermit script is provided to install the main U-Boot "proper" and RTOS images to the QSPI Flash. The script is available as board/emcraft/stm32h7-som/stm32h7-som-prog.kermit from the U-Boot source tree. This script must be used for the initial system installation, including installation of the U-Boot image, creating the UBI volumes, installation of the RTOS image and installation of the splash screen image. Usage is as follows:

./stm32h7-som-prog.kermit <tty> <uboot_img> [<rtos_img>] [<splash_img>]

  • tty - is a serial device name as seen on the Linux host, e.g. /dev/ttyUSB0, where the debug console of the STM32H750 is connected to (mandatory);
  • uboot_img - is the path to the main U-Boot image, i.e. u-boot.img (mandatory);
  • rtos_img - is the path to the RTOS image, i.e. freertos_stm32h750.img (optional);
  • splash_img - is the path to the splash screen image (optional).

The stm32h7-som-prog.kermit can be used to update only the U-Boot image without affecting the previously installed RTOS and the splash screen images on the QSPI Flash. For this the kermit script must be called without the rtos_img and splash_img arguments:

./stm32h7-som-prog.kermit <tty> <uboot_img>