Optimizing Linux Boot Time on STM32MP1-Based Systems: An Introductory Guide

I asked ChatGPT’s image generator the other day to put into an image form, the intricacies of optimizing boot time for an Embedded Linux system and the result was a perfectly unhinged display that captures none of the grinding aspects of what we are about to discuss. Let’s jump in, shall we?

When designing an embedded system with OSD32MP1 System-in-Package (SiP), optimizing Linux boot time can be critical for improving user experience, reducing power consumption, and meeting real-time constraints. As embedded engineers, we often find ourselves needing to strike a balance between feature-richness and performance. A slow boot time can delay critical application processes, impact startup energy efficiency, and create a perception of sluggishness in the system. Fortunately, by understanding the Linux boot sequence and identifying bottlenecks, we can make targeted optimizations that dramatically reduce boot time.

If you have more specific questions feel free to post them over in our forum!


Understanding the Linux Boot Process on STM32MP1

Before diving into optimizations, it’s essential to break down the Linux boot process into key stages:

  1. ROM Bootloader (BootROM): The built-in STM32MP1 bootloader initializes the SoC, essential clocks, peripherals needed to load the next stage and loads the next stage.
  2. Trusted Firmware-A (TF-A): This stage initializes secure components, sets up memory, and hands off control to U-Boot.
  3. Secondary Bootloader (U-Boot): Loads the Linux kernel and device tree, and optionally runs scripts for system configuration.
  4. Kernel Initialization: The Linux kernel initializes hardware drivers, the root filesystem, and system services.
  5. User-Space Initialization: Systemd (or another init system) launches user applications and services.

Each of these stages contributes to the total boot time. The goal is to analyze and optimize the slowest sections.


Tips to Optimize Linux Boot Time on STM32MP1

The key thing to keep in mind is to make sure NOT to get rid of and optimize the tools and features that allow you to measure and determine what aspects of each boot stage can be modified to boot faster.

Tip: Use grabserial or bootgraph.pl (as mentioned in the BootLin training referenced below) script to visualize boot delays.

2. Optimize TF-A (Trusted Firmware-A) Execution

Trusted Firmware-A (TF-A) is a critical early-stage boot component that can add noticeable delays if not optimized. To streamline TF-A:

  • Enable Optimized Configuration: Use LOG_LEVEL=0 in the TF-A build configuration to disable debugging overhead.
  • Reduce Initialization Steps: Remove unused secure services from the TF-A build to speed up initialization.
  • Use a Minimal BL2 Implementation: Ensure only the necessary components are included in BL2 to reduce execution time.

3. Optimize U-Boot for Faster Execution

The U-Boot bootloader can be contributing to slow boot times. Below are some things you can change:

  • U-Boot Boot Time Analysis: Enable CONFIG_BOOTSTATS in U-Boot to measure execution time.
  • Reduce U-Boot Timeout: Set CONFIG_BOOTDELAY=0 to remove unnecessary wait time.
  • Disable Unused Features: Disable unnecessary boot options, networking, or commands in U-Boot configuration. You can create a custom bootcmd that streamlines the loading of the device tree, kernel and other components needed to start the kernel.
  • Use a Minimalist Device Tree: Remove unused peripherals and drivers in U-Boot’s device tree.
  • Enable Falcon Mode: Falcon Mode allows U-Boot to directly load the kernel without going through full U-Boot execution.

4. Optimize Kernel Boot Time

Here are some tips to optimize things in the kernel:

  • Kernel Boot Charting: Use initcall_debug and dmesg timestamps to analyze slow kernel initialization functions.
  • Reduce Kernel Image Size: Strip unnecessary drivers and features by configuring the kernel with menuconfig or nconfig. You will need to make incremental changes and make sure to test each change in order to prevent breaking something in your system.
  • Disable Debugging Options: Disable CONFIG_DEBUG_KERNEL and logging features to speed up execution.
  • Optimize Device Tree: Remove unused device nodes and peripherals that aren’t required for early boot.
  • Boot log level: Add quiet loglevel=3 to the kernel command line to reduce boot log overhead.

5. Speed Up Root Filesystem Mounting

  • Systemd Analysis: Run systemd-analyze blame and systemd-analyze critical-chain to profile service startup delays.
  • INITRAMFS: Consider using initramfs to start critical applications before mounting the full root filesystem
  • Tracing your application: Use tools like strace, ltrace, valgrind and perf to profile your application’s use of system calls, shared library calls and memory management

Tip: Use boot time measurement time stamping tools described above to track improvements for changes you make to each of the boot components


References

For further details on boot time optimization, refer to these resources:


How have you optimized boot time in your projects? Any key areas we missed? Share your insights in the comments!

Want to stay up to date on our latest updates. Sign up for our newsletter!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*