ATSAMA5D27-SOM1-EK1 - Booting from QSPI Flash Memory
Contents
- Introduction
- Prerequisites
- Hardware
- SAM-BA In-System Programmer
- Read and Configure the Boot Configuration Word
- Erase QSPI Flash Memory
- Build and Write at91bootstrap to QSPI Flash Memory
- Build and Write u-boot-at91 to QSPI Flash Memory
- Create and Write u-boot.env to QSPI Flash Memory
- Build the Linux Kernel Image and DTB
- Create FIT Image
- Prepare a ROOTFS for SD Memory Card
- Write ITB to SD Memory Card
- Boot from QSPI Flash Memory
- Summary
Introduction
In this training, 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 NOR Flash Quad Serial Peripheral Interface (QSPI) memory and the Flattened Image Tree (FIT) (containing the Linux® kernel and Device Tree) and Root File System (ROOTFS) from an SD memory card. You will use the SAM-BA® In-System Programmer to write at91bootstrap and u-boot-at91 to QSPI Flash memory.
You will also 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.
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
You will be using the ATSAMA5D27-SOM1-EK1 evaluation kit.
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 integrated in the ATSAMA5D27-SOM1 System on Module (SoM))
- U9 – Printed Circuit Board (PCB) footprint for QSPI Flash memory (Unpopulated)
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.
The SAM-BA ISP Host to Monitor serial communications is shown in the accompanying figure.
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.
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.
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. To read the Boot Configuration Word located in the Secure Fuse Controller (SFC), execute the following command on the SAM-BA Host command line:
The result:
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:
The result:
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.
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.
To enable reading of the Boot Configuration Word from Backup Register 0 (BUREG0), perform the following steps:
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:
The result:
Opening serial port 'ttyACM1'
Connection opened.
Executing command 'readcfg:bscr'
BSCR=0x00000000 / BUREG0
Connection closed.
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.
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.
writecfg:bureg0:QSPI0_DISABLED,QSPI1_IOSET2,SDMMC0_DISABLED,SDMMC1_DISABLED,EXT_MEM_BOOT
The result:
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.
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:
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.
Change the directory to your working directory containing the at91bootstrap.
Using a default configuration file, configure at91bootstrap with u-boot for QSPI Flash memory:
$ 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!
If you would like to verify the QSPI Flash memory settings or make customization changes:
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.
Observe that QSPI IOSET (QSPI1 IOSET 2) ---> has been selected.
You may exit menu config by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.
Build at91bootstrap:
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:
$ 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
From the SAM-BA Host command line, write at91bootstrap.bin to QSPI Flash memory starting at location 0x0 using the writeboot command:
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 result is at91bootstrap.bin is stored in the QSPI Flash memory starting at address 0x0.
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.
Change directory to your working directory containing the u-boot-at91:
Using a default configuration file, configure u-boot-at91 for QSPI Flash memory:
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:
Highlight Boot media ---> and press ENTER.
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.
Build u-boot-at91:
Once the build is complete, the resulting binary file u-boot.bin is located in the u-boot-at91 directory.
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:
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%)
The result is u-boot.bin is stored on the QSPI Flash memory starting at address 0x40000.
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.
Using your favorite text editor, create a text file with the following information. Name the text file u-boot-env.txt.
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.
Convert the text file u-boot-env.txt into a binary file u-boot-env.bin using the utility program mkenvimage.
From the SAM-BA Host command line, write u-boot-env.bin to QSPI Flash momory at location 0x140000 using the applet -a qspiflash -c write command:
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.
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.
Change directory to your working directory containing the linux-at91:
Using default configuration files, configure the Linux kernel:
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:
Build linux-at91:
$ 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 Flattened Image Tree (FIT) image. 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.
Git clone the Device Tree Overlay files from the Linux4SAM repository:
Change directory to your working directory containing the dt-overlay-at91:
Open Makefile with your favorite editor and verify the KERNEL_DIR is pointing to your linux-at91 directory:
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:
$ echo $KERNEL_DIR
Build the *.itb image file:
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 an 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 an 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.
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.
Delete the files in the BOOT (FAT32) partition.
Write ITB to SD Memory Card
Copy the sama5d27_som1_ek.itb file to the ROOTFS/boot directory.
$ cp sama5d27_som1_ek.itb /media/<username>/ROOTFS/boot
Boot from QSPI Flash Memory
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.
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 an 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.