ATSAMA5D27-SOM1-EK1 - Boot from QSPI Flash Memory

Introduction

In this topic you will configure and program the ATSAMA5D27-SOM1-EK1 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 (ROOTFS) from SD Memory Card. You will use the SAM-BA® In-System Programmer to write at91bootstrap and u-boot-at91 to QSPI Flash Memory.

Steps:


Prerequisites

A working cross-toolchain for ARM-based MPU target is required

Basic knowledge of the SAM-BA In-System Programmer is required to use the software utility to write to QSPI Flash Memory:

Knowledge of the Boot Process is required as this topic discusses how to load the bootloaders to QSPI Flash memory and Linux kernel/Device Tree/Root File System to SD Memory Card:

See also:


Hardware

ATSAMA5D27_SOM1_EK1_contents.png

You will be using the ATSAMA5D27-SOM1-EK1 evaluation kit.

SOM1-EK1_bootable_memory.png

The ATSAMA5D27-SOM1-EK1 evaluation kit has four bootable memories:

  • J12 – MMCplus/SD Memory Card
  • J14 – microSD Memory Card
  • U4 – QSPI Flash Memory (that is integral with the ATSAMA5D27-SOM1 System on Module (SoM)
  • U9 – Printed Circuit Board (PCB) footprint for QSPI Flash Memory (Unpopulated)
ATSAMA5D27_SOM1_02.png

You will configure and build bootable files at91bootstrap and u-boot-at91 to be flashed into U4, the QSPI Flash Memory (a 64 Mbit Quad Serial I/O™ Flash Memory (SST26VF064B)) using the SAM-BA In-System Programmer.


SAM-BA In-System Programmer

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

For more information about the SAM-BA ISP, see: SAM-BA ISP – Introduction

The SAM-BA ISP Host to Monitor Serial Communications is shown in the figure below:

host_to_target_usb.png

Read and Configure the Boot Configuration Word

In this section, you will use the SAM-BA In-System Programmer to read the Boot Configuration Word from the ATSAMA5D27-SOM1-EK1 evaluation kit, then configure the Boot Configuration Word to Backup Register 0 (BUREG0), and finally, set the Boot Configuration Word in BUREG0 to boot from QSPI Flash Memory.

For more information on the SAMA5D2 Series Boot Process, see Boot Process – SAMA5D2 Series.

Read the Boot Configuration Word

The first step is to read the Boot Configuration Word to learn where it is stored (fuse or backup register) and which one is active.

For more information on reading and writing the Boot Configuration Word, see: SAM-BA Applets – Read and Write Boot Configuration (bootconfig)

1

Read the Boot Configuration Word

To read the Boot Configuration Word located in the Secure Fuse Controller (SFC), execute the following command on the SAM-BA Host command line:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c readcfg:fuse

The result:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c readcfg:fuse
Opening serial port 'ttyACM1'
Connection opened.
Executing command 'readcfg:fuse'
FUSE=0x00020000 / QSPI0_IOSET1,QSPI1_IOSET1,SPI0_IOSET1,SPI1_IOSET1,NFC_IOSET1,SDMMC0,
SDMMC1,UART1_IOSET1,JTAG_IOSET3
Connection closed.

.
SAMA5D2 Series Boot Process

Observe that the Boot Configuration Word bit 22 (DISABLE_BSCR), disable read of Boot Sequence Controller Configuration Register (BSC_CR), is cleared. Therefore, the MPU will read the Boot Sequence Controller Configuration Register (BSC_CR).

You can read the Boot Sequence Controller Configuration Register (BSC_CR) with the following command:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c readcfg:bscr

The result:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c readcfg:bscr
Opening serial port 'ttyACM1'
Connection opened.
Executing command 'readcfg:bscr'
BSCR=0x00000000 / BUREG0
Connection closed.

Observe that the Boot Sequence Controller Configuration Register (BSC_CR) bit 2, validate the data in BUGREG_INDEX field, is cleared. Therefore, no BUREG contains valid boot configuration data.

In summary, the MPU reads the active Boot Configuration Word stored in the SFC. Bit 18, Enable Boot on External Memories, is set/enabled. All remaining bits are in their cleared/default state.

2

The Boot Configuration Word stored in the SFC can be overridden by the contents of one of four Backup Registers (BUREG). In this step, you will configure the MPU to read the Boot Configuration Word from Backup Register 0 (BUREG0), and in Step 3, you will set the Boot Configuration Word to boot from QSPI Flash Memory.

For more information on the Backup Registers, see SAMA5D2 Series Datasheet (Section 16 – Boot Strategies)

During prototyping and development, it is highly recommended to use the Backup Registers (BUREG) to load the Boot Configuration Word. This will allow the developer to test the options of Boot Configuration Word in the Boot Process. Also, without permanently setting any bits in the SFC.

Once the device is put into production, it is highly recommended that the Boot Configuration Word be programmed into the SFC Data Register 16, bit 22 (SFC_DR16:22) must be set by the user.

To enable reading of the Boot Configuration Word from Backup Register 0 (BUREG0), perform the following steps:

a

Observe that the SFC Data Register 16, bit 22 (SFC_DR16:22), disable read of Boot Sequence Controller Configuration Register (BSC_CR), must be cleared to allow the reading of the Boot Sequence Controller Configuration Register (BSC_CR). As we observed in Step 1 above, this is true: SFC_SR16:22 = 0b0. The result will be when the MPU executes the first-stage bootloader (ROM Boot Code) it will read the Boot Sequence Controller Configuration Register.

b

Set the Boot Sequence Controller Configuration Register (BSC_CR) bit 2, Backup Register Valid (BUREG_VALID) bit. The result will be that the first-stage bootloader will read the BUREG pointed to by the Backup Register Index bits (shown in the next step).

The BSC_CR:BUREG_VALID bit can be set with the following command:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c writecfg:bscr:0x4

The result:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c writecfg:bscr:0x4
Opening serial port 'ttyACM1'
Connection opened.
Executing command 'writecfg:bscr:0x4'
Setting BSCR to 0x00000004 (BUREG0, VALID)
Connection closed.

c

Backup Register Index bits indicate which BUREG will be used.

The Backup Register Index bits = 0b00. The result will be that Backup Register 0 (BUREG0) will be the register read during the first-stage boot process.

3

Set the Boot Configuration Word in BUREG0 to boot from QSPI Flash Memory

The following command will write a Boot Configuration Word to Backup Register 0 (BUREG0) to:

  • Boot from external memory, and
  • Configure peripheral QSPI1 to IOSET2. This will allow the use of the QSPI Flash Memory located on the ATSAMA5D27-SOM1 module (Jumper J13 must be open).

The command also disables reading from QSPI0, SDMMC0, and SDMMC1.

For more information on the QSPI, see Section 50 of the SAMA5D2 Series Datasheet (DS60001476)

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c writecfg:bureg0:QSPI0_DISABLED,QSPI1_IOSET2,SDMMC0_DISABLED,SDMMC1_DISABLED,EXT_MEM_BOOT

The result:

$ sam-ba -p serial -b sama5d27-som1-ek -a bootconfig -c writecfg:bureg0: QSPI0_DISABLED,QSPI1_IOSET2,SDMMC0_DISABLED,SDMMC1_DISABLED,EXT_MEM_BOOT
Opening serial port 'ttyACM1'
Connection opened.
Executing command 'writecfg:bureg0:QSPI0_DISABLED,QSPI1_IOSET2,SDMMC0_DISABLED,
SDMMC1_DISABLED,EXT_MEM_BOOT'
Setting BUREG0 to 0x00040c07 (QSPI0_DISABLED,QSPI1_IOSET2,SPI0_IOSET1,SPI1_IOSET1,NFC_IOSET1,
SDMMC0_DISABLED,SDMMC1_DISABLED,UART1_IOSET1,JTAG_IOSET1,EXT_MEM_BOOT)
Connection closed.

Upon the next reset, the ATSAMA5D27-SOM1-EK1 evaluation kit will boot from QSPI Flash Memory located on the SAMA5D27-SOM1 module. However, the QSPI Flash Memory is likely to be empty or hold old code. In the following sections, we show you how to first erase the QSPI Flash Memory and then program the second- and third-stage bootloaders, at91bootstrap and u-boot-at91.


Erase QSPI Flash Memory

In this section, you will erase the contents of the QSPI Flash Memory located on the ATSAMA5D27-SOM1-EK1 evaluation kit. This is a necessary step prior to writing data to the QSPI Flash Memory.

1

Erase the QSPI Flash Memory on the SAMA5D27-SOM1

Erase the contents of the QSPI Flash Memory on the SAMA5D27-SOM1 with the following command:

$ sam-ba -p serial -b sama5d27-som1-ek -a qspiflash -c erase
Opening serial port 'ttyACM1'
Connection opened.
Applet serialflash found
Detected memory size is 4194304 bytes.
Executing command 'erase'
Erased 65536 bytes at address 0x00000000 (1.56%)
Erased 65536 bytes at address 0x00010000 (3.13%)
..
..
Erased 65536 bytes at address 0x003e0000 (98.44%)
Erased 65536 bytes at address 0x003f0000 (100.00%)
Connection closed.


Build and Write at91bootstrap to QSPI Flash Memory

In this section, you will configure and build the at91bootstrap from source code to boot from QSPI Flash Memory.

1

Change directory to your working directory containing the at91bootstrap

$ cd at91bootstrap

2

Using a default configuration file, configure at91bootstrap with u-boot for QSPI Flash Memory:

$ make mrproper
$ make sama5d27_som1_ekqspi_uboot_defconfig
#
# configuration written to .config
#
#
# make dependencies written to .auto.deps
# See top of this file before playing with this auto-preprequisites!
#

You can view the available default configuration files in the directory: ~/project_1/at91bootstrap/board

If you would like to verify the QSPI Flash Memory settings or make customization changes:

$ make menuconfig

at91bootstrap_configuration.png

Observe that Board Type (sama5d27_som1_ek) has been selected.

Highlight Memory selection ---> and press ENTER.

Highlight QSPI Configuration ---> and press ENTER.

Highlight QSPI IOSET Select ---> and press ENTER.

qspi_ioset_select.png

Observe that QSPI IOSET (QSPI1 IOSET 2) ---> has been selected.

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

3

Build at91bootstrap:

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

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-

$ make

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

$ cd binaries
$ ls -l
at91bootstrap.bin -> sama5d27_som1_ek-dataflashboot—3.8.12.bin
boot.bin -> sama5d27_som1_ek-dataflashboot—3.8.12.bin
sama5d27_som1_ek-dataflashboot—3.8.12.map
sama5d27_som1_ek-dataflashboot—3.8.12.bin
sama5d27_som1_ek-dataflashboot—3.8.12.elf

4

From the SAM-BA Host command line, write at91bootstrap.bin to QSPI Flash Memory starting at location 0x0 using the writeboot command:

$ sam-ba -p serial -b sama5d27-som1-ek -a qspiflash -c writeboot:at91bootstrap.bin
Opening serial port 'ttyACM1'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'writeboot:at91bootstrap.bin'
Patched file length (10704) at offset 20
Added 48 bytes of padding to align to page size
Wrote 10752 bytes at address 0x00000000 (100.00%)
Connection closed.

The -a qspiflash -c writeboot command should only be used when programming a bootstrap file into an external QSPI NOR Flash Memory boot partition.

The -a qspiflash -c 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.

For more information on the SAM-BA Applet qspiflash command, see SAM-BA ISP Applets – Program External QSPI NOR Flash Memory

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

qspi_boot_bin_memory_map.png

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

In this section, you will configure and build the u-boot-at91 from source code to boot from QSPI Flash Memory.

u-boot-at91 is maintained by Microchip Technology and hosted on GitHub

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

1

Change directory to your working directory containing the u-boot-at91:

$ cd u-boot-at91

2

Using a default configuration file, configure u-boot-at91 for QSPI Flash Memory:

$ make sama5d27_som1_ek_qspiflash_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written .config
#

If you would like to verify settings for booting from QSPI Flash Memory or make customization changes:

$ make menuconfig

u_boot_menuconfig.png

Highlight Boot media ---> and press ENTER.

u_boot_media.png

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

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

3

Build u-boot-at91:

$ make

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

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-

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

4

From the SAM-BA Host command line, write u-boot.bin to QSPI Flash Memory starting at location 0x4000 using the applet -a qspiflash -c write command:

$ sam-ba -p serial -b sama5d27-som1-ek -a qspiflash -c write:u-boot.bin:0x40000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 8388608 bytes.
Executing command 'write:u-boot.bin:0x40000'
Added 192 bytes of padding to align to page size
Wrote 95232 bytes at address 0x00008000 (33.97%)
Wrote 95232 bytes at address 0x0001f400 (67.95%)
Wrote 89856 bytes at address 0x00036800 (100.00%)

For more information on the SAM-BA Applet qspiflash command, see SAM-BA ISP – Applets: Program External QSPI NOR Flash Memory ({{qspiflash}})

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

qspi_u_boot_bin_memory_map.png

Create and Write u-boot.env 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.

u-boot-at91 is maintained by Microchip Technology and hosted on GitHub

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

1

Using your favorite text editor, create a text file with the following information. Name the text file u-boot-env.txt.

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

bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4 
bootcmd=ext4load mmc 0:2 0x24000000 boot/sama5d27_som1_ek.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= that the root filesystem type

The bootcmd= line tells U-Boot to load the sama5d27_som1_ek.itb file (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.

memory_map.png

Notice that the BOOT partition (partition 1) is empty in this example. It will not be used as U-Boot will be loaded from QSPI Flash memory. It is left here as you may create the SD Memory card image using balenaEtcher (explained below) which will create two partitions as shown in the figure above.

loading_itb.png

2

Convert the text file u-boot-env.txt into a binary file u-boot-env.bin using the utility program mkenvimage.

The mkenvimage utility program is part of the U-Boot software package. See directory ../u-boot-at91/tools/

$ mkenvimage -s 0x20000 -o u-boot-env.bin u-boot-env.txt

3

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 sama5d27-som1-ek -a qspiflash -c write:u-boot-env.bin:0x140000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'write:u-boot-env.bin:0x140000'
Wrote 8192 bytes at address 0x00140000 (100.00%)
Connection closed.

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

qspi_memory_map.png

Build the Linux Kernel Image and DTB

In this section, you will configure the Linux kernel and Device Tree for the ATSAMA5D27-SOM1-EK1 evaluation kit using default configuration files and build the files. In the next section you use these files to create a FIT image to write to the SD Memory Card.

linux-at91 is maintained by Microchip Technology and hosted on GitHub

1

Change directory to your working directory containing the linux-at91:

$ cd linux-at91

2

Using default configuration files, configure the Linux kernel:

$ make ARCH=arm sama5_defconfig

HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#

If you would like to verify settings or make customization changes:

$ make menuconfig

linux_at91_menuconfig.png

3

Build linux-at91:

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

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-

$ make ARCH=arm

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

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


Create FIT Image

In this section, you will create a FIT image. The FIT image allows for more flexibility in handling images of various types and enhances 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.

1

Git clone the Device Tree Overlay files from the Linux4SAM repository:

2

Change directory to your working directory containing the dt-overlay-at91:

$ cd dt-overlay-at91

3

Open Makefile with your favorite editor and verify 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

4

Build the *.itb image file:

$ make sama5d27_som1_ek.itb

Once the build is complete, the resulting image file sama5d27_som1_ek.itb is located in the dt-overlay-at91 directory. Please remember this because later you will be copying the sama5d27_som1_ek.itb image to the SD Memory Card.

In the next section, you will prepare a SD Memory Card.


Prepare a ROOTFS for SD Memory Card

In this section, you will download a demonstration image from the Linux4SAM website for the purpose of using the ROOTFS 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 FIT file that you created in the previous section to the ROOTFS/boot directory.

1

Download ATSAMA5D27-SOM1-EK1 demonstration image from the Linux4SAM website.

The latest demonstration images for the ATSAMA5D27-SOM1-EK1 are available on the Linux4SAM.org 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 buildroot_sama5d27_som1_ek-headless file.

2

Flash the demo image to SD Memory Card.

3

Insert the SD Memory Card into a Linux desktop computer.

4

Delete the files in the BOOT (FAT32) partition.

memory_map.png

Notice that the BOOT partition (partition 1) is empty in this example. It will not be used as U-Boot will be loaded from QSPI Flash Memory.


Write ITB to SD Memory Card

1

Copy the sama5d27_som1_ek.itb file to the ROOTFS/boot directory.

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

loading_itb.png

Boot from QSPI Flash Memory

1

Connect a Host PC to J10 using a Micro-B USB Cable.

2

Start a terminal emulation program and configure it to the USB COM port connected to J10.

These two steps set up Console Serial Communications with the target device.

3

Insert the SD Memory Card into J12.

4

Press the Reset button PB1.

The boot sequence will display in the terminal window. At the end the command line will prompt the user to log in.

Proper operation of the image will be indicated by LED D5 flashing blue which indicates operation of the Linux operating system image

Proper operation of the on-board J-Link Debugger will be indicated by LED D4 flashing green which indicates operation of the J-Link Debugger

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


Summary

In this topic, you configured and built the second-stage bootloader at91bootstap and the third-stage bootloader u-boot-at91 from source code. You configured the boot process on the ATSAMA5D27-SOM1-EK1 evaluation kit to boot from QSPI Flash memory. You wrote the second- and third-stage bootloaders into QSPI Flash Memory. You also prepared a SD Memory Card with FIT (containing the Linux kernel and Device Tree) and ROOTFS. The result is an embedded Linux system that boots from QSPI Flash Memory.

© 2020 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.