Fast Boot Demonstration - SAM9X60-EK

Introduction

Booting an embedded Linux system quickly is crucial for time-critical applications and plays a major role in improving the user experience. This training topic gives some important tips and techniques to achieve fast boot on Microchip microprocessor units (MPUs).

Video: EGT/Linux Fast Boot Demonstration

Linux Boot Process

To begin, let us review the standard boot process on Microchip MPUs running embedded Linux.

linux_boot_process.png

A typical embedded Linux boot process involves the following steps:

  1. ROM bootloader: This is the ROM boot code contained in the embedded ROM, also known as the first-stage bootloader. It initializes the master clock, configures peripherals and locates the second stage bootloader stored in external Non-Volatile Memory (NVM) and loads it to internal SRAM.
  2. at91bootstrap: The second-stage bootloader that initializes clock generator and external DRAM and loads the next stage. The next stage could be a third-stage bootloader (such as U-Boot) or the Linux kernel.
  3. U-Boot: Third stage bootloader, which is optional.
  4. Linux kernel.
  5. Linux target applications.

In this training, you will learn how to launch an Ensemble Graphics Toolkit (EGT) GUI-based application on a Microchip MPU running Linux in under 3 seconds.

Ensemble Graphics Toolkit (EGT) is a C++ based graphical Linux toolkit for Microchip microprocessors. For more information, visit the Microchip Technology Ensemble Graphics Toolkit website.

Summary of Steps:

In this training tutorial you may either:
1. download and build the individual files as instructed, or
2. download the binary files necessary to flash an SD Memory Card.


Prerequisites

  • Knowledge of the general Boot process is required
    • SAM9X60 Data Sheet (Section 11 – Boot Strategies)

Hardware

You will use the SAM9X60-EK Evaluation Kit and a TM5000 High-Performance WVGA Display Module with Max-Touch® Technology.

Refer to "SAM9X60-EK -- Attaching the TM5000 WVGA Display" for instructions on how to assemble the LCD display onto the SAM9X60-EK.

sam9x60-ek-wvga-assembled.png

Minimize Boot Time

In this section, you will download, configure, and build the second-stage bootloader, at91bootstrap, for fast booting.

For more in depth information about at91bootstrap, see the at91bootstrap – Second Stage Bootloader training.

1

Create project directory:

Name your project directory, fastboot.

$ mkdir fastboot

2

Download at91bootstrap from the linux4sam remote repository in GitHub:

$ cd ~/fastboot
$ git clone git://github.com/linux4sam/at91bootstrap.git

When you git clone from a remote repository, you are creating a copy on your host computer’s project directory (also known to git as the working directory or local directory).

3

Configure using sam9x60eksd_linux_image_dt_defconfig:

Once you have cloned at91bootstrap to your project directory, you can configure the build. In this step, you will use a default configuration file, sam9x60eksd_linux_image_dt_defconfig, located in the ~/fastboot/at91bootstrap/board/ directory. This will configure the at91bootstrap (second-stage bootloader) to load the Linux kernel directly, thereby eliminating U-Boot (third-stage bootloader) from the boot sequence.

The config files are annotated with the choice of external boot memory. In this case, we choose to boot at91bootstrap from SD Memory Card.

  • sd – SD Memory Card

The default configuration files are also annotated with the choice of what at91bootstrap will load next, either a third-stage bootloader (uboot) and/or application (linux_image_dt). Here we choose to load the Linux kernel.

  • linux_image_dt – Linux kernel and Device Tree

Change the directory to the ~/fastboot/at91bootstrap folder and begin the configuration process:

$ cd ~/fastboot/at91bootstrap
$ make sam9x60eksd_linux_image_dt_defconfig

4

Customize the at91bootstrap configuration to minimize boot time.

To customize the default configuration settings, use menuconfig. Menuconfig allows you to view the default configuration and make the required changes.

$ make menuconfig

at91bootstrap_config.png

a

Observe that the Board Type (sam9x60ek) ---> has been selected.

b

Highlight Image Loading Strategy and observe that Support loading Linux directly has been selected.

image_loading_strategy.png

c

Highlight [ ] Debug Support from the main menu and de-select it by pressing <N>.

d

Highlight Hardware Initialization Options ---> and press Enter.

e

De-select Display banner option by pressing <N>. Select <Exit>.

hw_init_options.png

f

Highlight Slow Clock Configuration Options ---> and press Enter.

g

Highlight Select slow clock configuration profile and change the setting to Use Internal RC oscillator as a source of slow clock.

Switching the slow clock source to the internal oscillator will eliminate the settling time required by the external crystal (which is selected by default). This will reduce boot time by almost one second.

slow_clk_config.png

h

You may exit menuconfig by repeatedly typing ESC-ESC until it closes. Save changes before exiting.

4

Build at91bootstrap.

Now that you have made all the configuration changes to reduce boot time, you can build at91bootstrap.

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

A working cross-toolchain for ARM-based MPU target is required to build at91bootstrap.

Ensure you set the CROSS_COMPILE=<path_to>/<cross_compiler> and ARCH=arm environment variables.

For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

A second method is you may include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

The resulting binary images will be found in the at91bootstrap/binaries directory. The at91bootstrap.bin image will be used in a later section.

In this training tutorial you may either:
1. download and build the individual files as instructed, or
2. download the binary files necessary to flash an SD Memory Card.


Minimizing Linux Kernel Load and Startup Time

min_boot_time.png

The Linux kernel load and startup time can be drastically reduced by configuring only the necessary peripherals and subsystems required by the Ensemble Graphics Toolkit (EGT) application. Therefore, from the SAM9X60 default device tree you will disable all the peripherals that are not used by the EGT application. You will also disable them from the kernel configuration. The fewer subsystems and drivers the Kernel must initialize, the faster it will boot. Finally, you will add support for the LCD display.

1

Get linux-at91.

Download linux-at91 from the Microchip GitHub repository.

$ cd fastboot
$ git clone https://github.com/linux4sam/linux-at91.git -b linux4sam-2020.04

2

Open device tree file and disable all unused peripherals.

To make changes to the device tree, open the at91-sam9x60-ek.dts file using a text editor of your choice.

$ cd linux-at91/arch/arm/boot/dts
$ vi at91-sam9x60ek.dts

Now you can edit the *.dts file.

a

Add the following highlighted line:

The loglevel is set to 0 which indicates minimal kernel debug messages and only the ones with utmost priority.

b

Change the status from “okay” to “disable” for the following peripherals: adc, can0, can1, classd, dbgu, flx4, flx5, flx6, i2s, macb0, pwm0, sdmmc1, qspi, usb0, usb1, usb2, isi.

c

Add support for the pda5 display in the device tree file at the end.

Refer dt-overlay-at91 from linux4sam repository in GitHub for the PDA5 screen support for the SAM9X60-EK.

d

Save and exit the file.

3

Disable peripherals from the kernel configuration.

Make the following changes to the kernel configurations by running menuconfig.

$ cd ~/fastboot/linux-at91/
$ make at91_dt_defconfig ARCH=arm
$ make menuconfig

Ensure you set the CROSS_COMPILE=<path_to>/<cross_compiler> and ARCH=arm environment variables.

For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

A second method is you may include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

a

Navigate to Networking Support and de-select it by pressing <N>.

kernel_config.png

b

Highlight Device Drivers ---> and press Enter.

c

Navigate to each of the following unused peripherals and exclude them by pressing <N>.

  • Memory Technology device (MTD) support
  • Block devices
  • SCSI Device support
  • SPI support
  • PPS support
  • Hardware Monitoring support
  • Multimedia support
  • Sound card support
  • USB support
  • Staging drivers
  • Industrial I/O support
device_drivers_1_hl.png
device_drivers_2_hl.png
device_drivers_3_hl.png

d

Exit menuconfig by repeatedly typing ESC-ESC until it closes. Save changes before exiting.

4

Build linux-at91.

Run the make command along with ARCH and CROSS_COMPILE variables.

$ cd fastboot/linux-at91
$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

A working cross-toolchain for ARM-based MPU target is required to build linux-at91.

Ensure you set the CROSS_COMPILE=<path_to>/<cross_compiler> and ARCH=arm environment variables.

For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

A second method is you may include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

The resulting device tree image is linux-at91/arch/arm/boot/dts/at91-sam9x60ek.dtb and the kernel image is linux-at91/arch/arm/boot/zImage.

In this training tutorial you may either:
1. download and build the individual files as instructed, or
2. download the binary files necessary to flash an SD Memory Card.


Minimize Application Startup Time

The Linux kernel loads an init script that loads other services and applications. To minimize boot time, you will replace the standard init script with a minimal script.

The minimal script performs the following:

  • Mounts /sysfs, which is needed to control the backlight brightness from within the application.
  • Loads the final application, which is a basic automotive dashboard graphical display developed using the Ensemble Graphics Toolkit (EGT).

The application is compiled as a static executable. All the images, logos, and resources are compiled directly into the application and statically linked to it. Therefore, the resources are immediately available and mapped into the application’s address space.

1

Create Custom init script.

a

Create an init file and open using a text editor of your choice.

$ cd ~/fastboot
$ vi init

b

Copy the following lines.

#!/bin/sh

mount -t sysfs none /sys
/usr/bin/egt_dashboard_fastboot
exec /bin/sh

c

Save the file and exit.

d

Change the init script to executable.

$ cd ~/fastboot
$ chmod +x init

2

Download Ensemble Graphics Toolkit (EGT) application.

Download the EGT application, egt_dashboard_fastboot, to your ~/fastboot directory and change the image to an executable.

Files

$ cd ~/fastboot
$ chmod +x egt_dashboard_fastboot

You will be copying the executable init and egt_dashboard_fastboot files to the Root File System (RootFS) of final image.

In this training tutorial you may either:
1. download and build the individual files as instructed, or
2. download the binary files necessary to flash an SD Memory Card.


Preparing SD Memory Card Image

In this section, you will download a demonstration image from the Linux4SAM website for the purpose of using the Root File System on the image. You will flash the image to a SD Memory Card and delete the files in the BOOT partition. Finally, you will copy the at91bootstrap.bin, at91-sam9x60ek.dtb and zImage files that you created in the previous section.

1

Download the SAM9X60-EK demonstration image from the Linux4SAM website.

The latest demonstration images for the SAM9X60-EK are available on the Linux4SAM website.

There you will find three sets of images created from one of three Build Systems:

  • The Yocto Project
  • Buildroot
  • OpenWRT

Choose the Buildroot based demo image with graphics support: linux4sam-buildroot-sam9x60ek-graphics-X.Y.img.bz2 where X.Y is the version number (X is year and Y is month of release).

demo_image.png

2

Flash the demo image to the SD Memory Card.

Follow the steps in the "Flash Image with Etcher" page.

3

Insert the SD Memory Card into a Linux desktop computer.

4

Delete the files in the BOOT(FAT32) partition.

In this training tutorial you may either:
1. download and build the individual files as instructed, or
2. download the binary files necessary to flash an SD Memory Card.

5

Write binary files, which were created in the previous sections to BOOT partition of SD memory card.

a

Copy the at91bootrap.bin file.

$ cd ~/fastboot/at91bootstrap/binaries
$ cp at91bootstrap.bin /media/<username>/<partion_name>/boot.bin

b

Copy the at91-sam9x60ek.dtb and zImage files.

$ cd ~/fastboot/linux-at91/arch/arm/boot/dts/
$ cp at91-sam9x60ek.dtb /media/<username>/<partion_name>/at91-sam9x60ek.dtb

$ cd ~/fastboot/linux-at91/arch/arm/boot/
$ cp zImage /media/<username>/<partion_name>/zImage

Now you have an SD Memory Card with the bootloader image (boot.bin), Linux kernel device tree (at91-sam9x60ek.dtb) and the kernel (zImage) in the BOOT partition. You also have the Root File System in the ROOTFS partition of the SD card.

6

Copy init and egt_dashboard_fastboot image to RootFS partition of SD card.

$ cd ~/fastboot
$ sudo cp –p init /media/<username>/ROOTFS/sbin/init
$ sudo cp egt_dashboard_fastboot /media/<username>/ROOTFS/usr/bin/

sd_memory_map.png

Remove the SD Memory Card from the Linux computer. You have now created a bootable Linux system image on the SD Memory Card.

Note that there are no u-boot images on the SD Memory Card. Recall that you configured and built at91bootstrap to load the Linux kernel directly. This will reduce boot time.


Fast Boot from SD Memory Card

1

The SAM9X60-EK can be powered by one of two methods:

  • J1: An external power jack to supply +5 VDC via a 2.1 mm center-positive plug
  • J7: Powered through the USB Micro-B connector USB port A

2

Insert the SD card to slot J4 on the SAM9X60-EK target board.

SAM9X60_EK_mass_storage.png

4

Press the RESET push button SW3 (nRST).

fast_boot_demo.png

Congratulations! You have reduced the boot time of embedded Linux system with an Ensemble Graphics Toolkit (EGT) application up and running!


Summary

In this training, you changed the standard Linux boot process on the Microchip Microprocessors to reduce the boot time.

  • You configured and built at91bootstrap to load the Linux kernel directly.
  • You removed all subsystems and kernel drivers that are not used by the final application.
  • You used a pre-built RootFS on SD card and replaced the standard init script with a minimal script that just loads the sysfs and EGT application.
  • The final application is a EGT Dashboard graphical demo on Microchip PDA5 touchscreen.

The result is a fast boot of the EGT application in less than three seconds on cold reset!

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.