SAM9X60-EK Evaluation Kit - Booting from QSPI Flash Memory

Last modified by Microchip on 2024/06/20 12:44

Introduction

This training topic explains how to configure and program the SAM9X60-EK Evaluation Kit to boot the second- and third-stage bootloaders  at91bootstrap  and  u-boot-at91 from Quad Serial Peripheral Interface (QSPI) Flash Memory, and the Flattened Image Tree (FIT) (containing the Linux® kernel and Device Tree) and Root File System from the SD memory card.

You will use the SAM-BA® In-System Programmer to write at91bootstrap and {u-boot-at91 to QSPI Flash memory.

Steps

  • SAM-BA In-System Programmer
  • Erase QSPI Flash memory
  • Build at91bootstrap and write to QSPI Flash memory
  • Build u-boot-at91 write to QSPI Flash memory
  • Create u-boot-env.bin and write to QSPI Flash memory
  • Build the Linux® kernel and Device Tree Blob (DTB)
  • Create Flattened Image Tree and write to QSPI Flash
  • Prepare a Root File System (ROOTFS) for SD memory card
  • Write Image Tree Blob (ITB) to SD memory card
  • Boot from QSPI Flash memory

Back to Top

Prerequisites

Back to Top

Hardware

SAM9x60 EK board

For this training topic, you will be using the SAM9X60-EK Evaluation Kit. You will also need two USB Micro-B cables. One cable will connect the Host PC to the target console to view the SAM-BA Monitor log message. The second cable will connect the Host PC to the target USBA port (J7) so that the SAM-BA Host can communicate with the SAM-BA Monitor.

Bootable Memory

For this training, you will use the Quad Serial I/O™ (QSPI) Flash memory (U8) (64 Mbit Quad Serial I/O Flash memory SST26VF064B to boot the second- and third-stage bootloaders, at91bootstrap and u-boot-at91.

SAM9x60 EK QSPI Flash

As the QSPI Flash memory is not large enough to hold all the bootable images, you will boot the kernel image (linux_at91) and root filesystem (RootFS) from the SD memory card (J4).

SAM9x60 EK QSPI memory map color

Back to Top

SAM-BA In-System Programmer

In this section, you will load the SAM-BA Host Application (if you have not already done so) and set up Console and SAM-BA Host to Monitor communications.

Back to Top

Setup SAM9X60-EK Console Serial Communications

To view the SAM-BA Monitor log messages, set up console serial communications following the instructions in the topic: SAM9X60-EK Console Serial Communications.

You have two choices in connecting to a serial port on the SAM9X60-EK:

  • The first is using a USB cable to connect to the J-LINK-OB port (J22). This method has the added benefit of powering the SAM9X60-EK.
  • The second is using a USB-to-TTL converter to connect to the Universal Asynchronous Receiver Transmitter (UART) Debug port (J24). With this option, to power the SAM9X60-EK, you will need to:
  • Use an external 5 VDC power supply connected to J1 (coaxial power jack), or:
  • Use a USB cable connect to the USBA port (J7). As you’ll be connecting a USB cable in Step 3 below (SAM-BA Host to Monitor Communications), this is the easiest method.

SAM9x60 EK J-Link-OB port

Information

Note: Operation of the J-Link Debugger will be displayed by a green LED (D9).

SAM9x60 EK serial UART debug port

Back to Top


If it is not already installed, install the SAM-BA Host Application.
Information

Note: SAM-BA ISP should be added to the system PATH variable.

$ export PATH=$PATH:<path_to_sam-ba>

This will enable you to access the SAM-BA ISP from anywhere on your system.

Back to Top


Setup the SAM-BA Host to Monitor Serial Communications

a. To communicate with SAM-BA Monitor on the target, you must have installed the SAM-BA Host on a Linux PC (Step 2 above), and connect a USB Micro-B cable from the host PC to the USBA port (J7) on the SAM9X60-EK as shown in the accompanying figure.

SAM9x60 EK SAM-BA communications J13 open
 

Information

Note: You may power the SAM9X60-EK one of two ways:

  1. Using an external 5 VDC power supply connected to J1 (coaxial power jack), or:
  2. Using a USB cable connected to the USBA port (J7).

b. Ensure there is no SD memory card inserted in slot J4.

c. Open the DISABLE_BOOT (J13) jumper.

This will allow booting from the onboard memories (NAND and QSPI Flash).

d. Press both the DIS_BOOT (SW4) and RESET (SW3) push buttons.

Pressing the DIS_BOOT (SW4) push button disables booting from the onboard memories.

e. Continue pressing DIS_BOOT(SW4) while releasing the RESET (SW3) push button.

The SAM9X60-EK will boot to the SAM-BA Monitor and start communications with the SAM-BA Host. Observe ROMBoot on the Console (terminal emulator) indicating the SAM-BA Monitor is running.

Back to Top


Erase QSPI Flash Memory

In this section, you will erase the contents of the QSPI Flash memory located on the SAM9X60-EK. This is a necessary step before writing data to the QSPI Flash memory.

Back to Top

Erase QSPI Flash Memory

Erase the contents of the QSPI Flash memory on the SAM9X60-EK with the following command:

$ sam-ba -p serial -b sam9x60-ek -a qspiflash -c erase
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 8388608 bytes.
Page size is 256 bytes.
Buffer is 112644 bytes (44 pages) at address 0x0030a3e0.
Supported erase block size: 4K
Executing command 'erase'
Erased 4096 bytes at address 0x00000000 (0.05%)
Erased 4096 bytes at address 0x00010000 (0.10%)
..
..
Erased 4096 bytes at address 0x003e0000 (99.95%)
Erased 4096 bytes at address 0x003f0000 (100.00%)
Connection closed.

 

Back to Top

Build at91bootstrap and Write to QSPI Flash Memory

In this section, you will configure and build the second-stage bootloader, at91bootstrap, from source code to boot from QSPI Flash memory and write it to QSPI Flash memory.

Information

Note: For more information, including how to download, see the at91bootstrap: A Second Stage Bootloader for Microchip MPUs training.

Back to Top

Change directory into the at91bootstrap directory:
$ cd ~/at91bootstrap

Back to Top


Using a default configuration file, configure at91bootstrap to boot u-boot from QSPI Flash memory:
$ make mrproper
# CLEAN obj and miss files!
# CLEAN configuration files!
# CLEAN binary files!


$ make sam9x60ekdf_qspi_uboot_defconfig
#
# configuration written to .config
#
#
# make dependencies written to .auto.deps
# See top of this file before playing with these auto-prerequisites!
#

Information

Note: What is the difference between make clean and make mrproper?

  • make clean- Remove most generated files but keep the config and enough build support to build external modules.
  • make mrproper- Remove all generated files + config + various backup files.

Anytime the configuration is changed, you should execute make mrproper.

Information

Note: Default configuration (defconfig) files are provided for the many evaluation kits sold by Microchip Technology Inc. They are located in the ~/at91bootstrap/board/ directory.

Back to Top


Optional: If you would like to verify the QSPI Flash memory settings or make any customizations:​
$ make menuconfig

SAM9x60 EK at91bootstrap config

a. Observe that Board Type (sam9X60ek) has been selected.

b. Highlight Memory selection ---> and press ENTER.

c. Highlight QSPI flash configuration ---> and press ENTER.

You can see QSPI Bus Select is QSPI Bus 0.

You may exit menuconfig by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.

Back to Top


Build at91bootstrap:​
$ make
Warning

Alert! A working cross-toolchain for Arm-based MPU target is required to build at91bootstrap.

Warning

Alert! Ensure you set the CROSS_COMPILE=<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-

Another method is to include these as command variables. For example:

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

Once the build is complete, the resulting binary files are in the /at91bootstrap/binaries/ directory:​
 

$ cd ~/at91bootstrap/binaries
$ ls
at91bootstrap.bin
boot.bin
sam9x60ek-dataflashboot—uboot-3.9.2.bin
sam9x60ek-dataflashboot-uboot—3.9.2.elf
sam9x60ek-dataflashboot-uboot—3.9.2.map

Back to Top


From the SAM-BA Host command line, write at91bootstrap.bin to QSPI Flash memory starting at location 0x0 using the qspiflash applet writeboot command:​
$ sam-ba -p serial -b sam9x60-ek -a qspiflash -c writeboot:at91bootstrap.bin
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 8388608 bytes.
Page size is 256 bytes.
Buffer is 112644 bytes (44 pages) at address 0x0030a3e0.
Supported erase block sizes: 4K
Executing command 'writeboot:at91bootstrap.bin'
Appending 8 bytes of padding to fill the last written page
Wrote 11264 bytes at address 0x00000000 (65.676%)
Wrote 5888 bytes at address 0x00002c00 (100%)
Connection closed.
Warning

Alert! The writeboot command should only be used when programming a bootstrap file into an external QSPI Flash memory boot partition.

Warning

Alert! The writeboot command modifies the relevant unused Arm exception vector to store the size of the bootstrap binary as required by the ROM Boot code during the boot process.

Information

Note: For more information on the SAM-BA Applet qspiflash command, see the "Program External QSPI Flash Memory qspiflash" section on the SAM-BA In-System Programmer Applets page.

The result is at91bootstrap.bin is stored in the QSPI Flash Memory starting at address 0x0.

SAM9x60 EK QSPI memory map at91bootstrap

Back to Top

Build u-boot-at91 and Write to QSPI Flash Memory

In this section, you will configure and build the third-stage bootloader, u-boot-at91, from source code to boot from QSPI Flash memory and write it to QSPI Flash memory.

Information

Note: u-boot-at91is maintained by Microchip Technology Inc. and hosted on GitHub.

Information

Note: For more information about the third-stage bootloader see: Das U-Boot – The Universal Boot Loader.

Back to Top

Change the directory to your working directory containing the u-boot-at91:
​$ cd ~/u-boot-at91

Back to Top


Using a default configuration file, configure u-boot-at91 for QSPI Flash memory:​
$ make sam9x60ek_qspiflash_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written .config
#

Back to Top


Optional: If you would like to verify settings for booting from QSPI Flash memory or make any customizations, type:
​$ make menuconfig

SAM9x60 EK Uboot config

a. Highlight Boot media ---> and press ENTER.

sam9x60 ek qspi flash boot boot media
 

b. Observe that [*] Support for booting from QSPI flash ---> has been selected.

You may exit menuconfig by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.

Back to Top


Build u-boot-at91:
$ make
Warning

Alert! A working cross-toolchain for Arm-based MPU target is required to build u-boot-at91.

Warning

Alert! Ensure you set the CROSS_COMPILE=<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-

Another method is to include these as command variables. For example:

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

Once the build is complete, the resulting binary file u-boot.bin is in the u-boot-at91 directory.

Back to Top


From the SAM-BA Host command line, write u-boot.bin to QSPI Flash memory starting at location 0x40000 using the applet -a qspiflash -c write command:​
$ sam-ba -p serial -b sam9x60-ek -a qspiflash -c write:u-boot.bin:0x40000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 8388608 bytes.
Page size is 256 bytes.
Buffer is 112644 bytes (44 pages) at address 0x0030a3e0.
Supported erase block sizes: 4K
Executing command 'write:u-boot.bin:0x40000'
Appending 210 bytes of padding to fill the last written page
Wrote 11264 bytes at address 0x00040000 (1.87%)
Wrote 11264 bytes at address 0x00042c00 (3.73%)


Wrote 11264 bytes at address 0x000cf000 (98.86%)
Wrote 11264 bytes at address 0x00d1cc00 (100.00%)
Connection closed.

The result is u-boot.bin is stored on the QSPI Flash memory starting at address 0x40000.

SAM9x60 EK QSPI memory map Uboot

Back to Top

Create u-boot-env.bin and Write to QSPI Flash Memory

Configuration of U-Boot is performed using environment variables. They are stored in binary format, generally, on the same boot memory (mass storage) that U-Boot is stored.

In this section, you will create a U-Boot environment binary file by first creating a text file. The text file is then converted to binary format using a utility program mkenvimage. Finally, you will write the file to QSPI Flash memory using the SAM-BA In-System Programmer (ISP).

Information

Note: More information on U-Boot Environment Variables can be found in the U-Boot Manual Section 5.10.

Back to Top

Using your favorite text editor, create a text file with the following information. Name the text file u-boot-env.txt.
bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4
bootcmd=ext4load mmc 0:2 0x24000000 boot/sam9x60ek.itb; bootm 0x24000000#kernel_dtb
bootdelay=1
ethact=gmac0
stderr=serial
stdin=serial
stdout=serial

The bootargs line tells U-Boot:

  • The console device and baud
  • The root= location of the root filesystem and permissions
  • The rootfstype= root filesystem type

The bootcmd= line tells U-Boot to load the sam9x60ek.itb file (Flattened Image Tree (FIT)) from the EXT4 formatted partition 2 on the SD Memory Card (which you will prepare in future sections) to external DDR2 SDRAM starting at address 0x24000000.

SAM9x60 EK QSPI memory map full with SD memory card

Back to Top


Convert the text file u-boot-env.txt into a binary file u-boot-env.bin using the utility program mkenvimage.
$ mkenvimage -s 0x20000 -o u-boot-env.bin u-boot-env.txt

Back to Top


From the SAM-BA Host command line, write u-boot-env.bin to QSPI Flash memory starting at location 0x140000 using the applet -a qspiflash -c write command:
$ sam-ba -p serial -b sam9x60-ek -a qspiflash -c write:u-boot-env.bin:0x140000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 8388608 bytes.
Page size is 256 bytes.
Buffer is 112644 bytes (44 pages) at address 0x0030a3e0.
Supported erase block sizes: 4K
Executing command 'write:u-boot-env.bin:0x140000'
Appending 210 bytes of padding to fill the last written page
Wrote 11264 bytes at address 0x00140000 (8.59%)
Wrote 11264 bytes at address 0x00142c00 (17.19%)


Wrote 11264 bytes at address 0x00015b800 (94.53%)
Wrote 11264 bytes at address 0x0015e400 (100.00%)
Connection closed.

The result is u-boot environment is stored in the QSPI Flash Memory starting at address 0x140000.

SAM9x60 EK QSPI memory map

Back to Top


Build the Linux Kernel Image and Device Tree Blob (DTB)

In this section, you will configure the Linux kernel and device tree for the SAM9X60-EK Evaluation Kit using the default configuration and build the files. In the next section, you will use these files to create a Flattened Image Tree image and write it to the SD memory card.

Note: linux-at91 is maintained by Microchip Technology Inc. and hosted on GitHub

Back to Top

Change directory to your working directory containing the linux-at91 source code:
​$ cd ~/linux-at91

Back to Top


Using default configuration files, configure the Linux kernel using the following command:​
$ make ARCH=arm at91_dt_defconfig

HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer/lex.o
HOSTCC scripts/kconfig/parser.tab.o
HOSTCC scripts/kconfig/preprocess.o
HOSTCC scripts/kconfig/symbol.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config

Back to Top


Optional: If you would like to verify settings or make customization changes type:
$ make menuconfig

SAM9x60 EK Linux config

You may exit menuconfigby repeatedly typing "ESC-ESC" until it closes. Do not save any changes.

Back to Top


Build linux-at91:​
$ make ARCH=arm
Warning

Alert! A working cross-toolchain for an Arm-based MPU target is required to build linux-at91.

Warning

Alert! Ensure you set the CROSS_COMPILE=<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-

Another method is to include these as command variables. For example:

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

Once the build is complete, the resulting binary files are created:

/arch/arm/boot/zImage
/arch/arm/boot/dts/at91-sam9x60ek.dtb

Back to Top

Create a Flattened Image Tree

In this section, you will create a Flattened Image Tree (FIT). The FIT image allows for more flexibility in handling images of various types and enhances the integrity protection of images with stronger checksums. An Image Source (*.its) file and a set of data files are used as an input. An Image Tree Blob (*.itb) file is generated as the output. Finally, you will write the FIT image to the SD memory card.

Back to Top

Git clone the Device Tree Overlay files from the Linux4SAM repository:​
$ git clone git://github.com/linux4sam/dt-overlay-at91.git

Back to Top


Change the directory to your working directory containing the dt-overlay-at91:​
$ cd ~/dt-overlay-at91

Back to Top


Open Makefile with your favorite editor and verify that the KERNEL_DIR is pointing to your linux-at91 directory:
CC?=$(CROSS_COMPILE)gcc
DTC_OPTIONS?=-@
DTC_OPTIONS += -Wno-unit_address_vs_reg -Wno-graph_child_address -Wno_pwms_property
KERNEL_DIR?=../linux-at91 <--- Ensure pointing to your linux-at91 directory
KERNEL_BUILD_DIR?=$(KERNEL_DIR)
DTC?=$(KERNEL_BUILD_DIR)/scripts/dtc/dtc

Or you can set the KERNEL_DIR environment variable:

$ export KERNEL_DIR=path

$ echo $KERNEL_DIR

 

Back to Top


Build the *.itb image file:
​$ make sam9x60ek.itb

Once the build is complete, the resulting image file sam9x60ek.itb is located in the dt-overlay-at91 directory.

Remember this directory location as you will be copying the sam9x60ek.itb image to the SD memory card.

In the next section, you will prepare an SD memory card.

Back to Top

Prepare a Root File System (ROOTFS) for SD Memory Card

In this section, you will download a demonstration image from the Linux4SAM website to use the Root File System on the image. You will Flash the image to an SD memory card and delete the files in the BOOT partition. Finally, you will copy the Flattened Image Tree file that you created in the previous section to the ROOTFS/boot directory.

Back to Top

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

Note: 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

Any one of the images can be used for this step. If you are undecided, choose the linux4sam-buildroot-sam9x60ek-headless file.

Back to Top


Flash the demo image to an SD memory card.

Back to Top


Insert the SD memory card into a Linux desktop computer.

Back to Top


Delete the files in the BOOT(FAT32) partition.

Back to Top


Write Image Tree Blob to SD Memory Card

Copy the sam9x60ek.itb file to the ROOTFS/boot directory.​

$ cd ~/dt-overlay-at91
$ cp sam9x60ek.itb /media/<username>/ROOTFS/boot

Back to Top

Boot from QSPI Flash Memory

Check that you have Console Serial Communications established.

Review Step 1 of the SAM-BA In-System Programmer section above.

Back to Top


Check that jumper in the DIS_BOOT (J13) is open.

This will allow booting from the onboard memories (NAND and QSPI Flash).

Back to Top


Insert the SD memory card into J4.

Back to Top


Press the Reset button SW3 (nRST).

The boot log will display in the terminal emulator. In the end, the command line will prompt the user to log in. Login as root. There is no password required to login.

SAM9x60 EK loginProper operation of the image will be indicated by a flashing blue RGB LED (LD1).

If Console Serial Communications is connected to J22, the operation of the onboard J-Link Debugger will be indicated by a Flashing green LED (D9).

Congratulations! You have created an embedded Linux system that boots from QSPI Flash memory.

Back to Top

Summary

In this training topic, you configured and built the second-stage bootloader at91bootstap and the third-stage bootloader u-boot-at91 from source code. You wrote the second- and third-stage bootloaders into QSPI Flash memory. You also prepared an SD memory card with Flattened Image Tree (containing the Linux kernel and Device Tree) and Root File System. The result is an embedded Linux system that boots from QSPI Flash memory.

Back to Top

What's Next?

Back to Top