Overview

This page describes the process of booting Linux from QSPI.

The default GSRD configuration is to boot from SD/MMC because it is a very convenient to use medium. However, with a minimal set of changes, the system can be booted from QSPI.

Note that the on-board QSPI flash memory is small (128 or 64MB) so it will not fit the full GSRD filesystem (~150MB). Therefore a reduced filesystem image is used.

Procedure

A. Configure Preloader to Boot from QSPI

Generate the Preloader as described in Generating and Compiling the Preloader but configure it to boot from QSPI instead of SD/MMC. This is achieved by changing the following boot settings in the Preloader Generator GUI before clicking the Generate button at step 8:
  • Un-check BOOT_FROM_SDMMC
  • Check BOOT_FROM_QSPI

bsp-boot-from-qspi.png.

After generating the Preloader, compile it as described in Generating and Compiling the Preloader to obtain the Preloader image file cv_soc_devkit_ghrd/software/spl-bsp/preloader-mkpimage.bin.

B. Configure U-boot to Store Environment in QSPI

The default behavior of U-boot is to store the environment in the SD/MMC.This section presents how to configure U-boot to store the environment in the QSPI.

1. Build U-boot from the Yocto package as shown in GSRD - Using Yocto Source Package using the command
$ source ~/yocto/altera-init ~/build
$ bitbake virtual/bootloader 

2. Edit the following U-boot file ~/build/tmp/work/armv7ahf-vfp-neon-poky-linux-gnueabi/u-boot-altera-dist-1.0-r0/uboot-socfpga/board/altera/socfpga/build.hto use QSPI instead on SD/MMC:
#define CONFIG_PRELOADER_BOOT_FROM_QSPI     (1)
#define CONFIG_PRELOADER_BOOT_FROM_SDMMC    (0)
#define CONFIG_PRELOADER_BOOT_FROM_RAM      (0)

3. Rebuild the Preloader by forcing a recompile
$ source ~/yocto/altera-init ~/build
$ bitbake -f -c compile virtual/bootloader 
$ bitbake -f -c deploy virtual/bootloader 

This will update the U-boot image in the Yocto deploy folder: ~/build/tmp/deploy/images/u-boot-socfpga_cyclone5.img

We will use this file as the U-boot image that we will write in the QSPI.

C. Create Minimal Root Filesystem

The regular GSRD root filesystem image is too large to fit the QSPI Flash. Follow the instructions from GSRD - Using Yocto Source Package to build the minimal root filesystem image altera-image-minimal-socfpga_cyclone5.jffs2.

D. Update QSPI Partitioning in Device Tree

The Device Tree file included with the GSRD defines two QSPI partitions, each of 8MB. Since the minimal root filesystem is ~12MB, we need to increase the size of the second partition to 16MB. We also need to add a 3rd partition to hold the FPGA image.

1. Edit the file cv_soc_devkit_ghrd/soc_system_board_info.xml:
  • Change the size of the second partition (part1) from 0x800000 (8MB) to 0x1000000 (16MB)
  • Add a new partition of 16MB (part2)
</DTAppend>
<DTAppend name="partition@800000" type="node" parentlabel="flash0" newlabel="part1"/>
<DTAppend name="label" type="string" parentlabel="part1" val="Flash 1 jffs2 Filesystem"/>
<DTAppend name="reg" parentlabel="part1">
<val type="hex">0x800000</val>    <!--  Second partition start address -->
<val type="hex">0x1000000</val>  <!--  Second partition size -->
</DTAppend>
<DTAppend> 
<DTAppend name="partition@1800000" type="node" parentlabel="flash0" newlabel="part2"/> 
<DTAppend name="label" type="string" parentlabel="part2" val="FPGA Image"/> 
<DTAppend name="reg" parentlabel="part2"> 
<val type="hex">0x1800000</val>  <!-- Third partition start address -->  
<val type="hex">0x800000</val> <!-- Third partition size --> 
</DTAppend>

2. Generate the Device Tree Source
$ ~/altera/13.1/embedded/embedded_command_shell.sh
$ cd ~/cv_soc_devkit_ghrd/
$ sopc2dts --input soc_system.sopcinfo\
  --output socfpga.dts\
  --board soc_system_board_info.xml\
  --board hps_clock_info.xml 

This will create or update the DTS file socfpga.dts

3. Compile the Device Tree Source:
$ dtc -I dts -O dtb -o socfpga.dtb socfpga.dts

This will create or update the DTB file socfpga.dtb

For more details about Device Tree see the following pages:

E. Write Files to QSPI Flash

This section describes how to write the necessary files to QSPI Flash. It uses the SD card as a transfer medium between host PC and target board, and Linux to program the QSPI flash.

1. Obtain SD card that boots Linux, from the binaries package, as described in Booting Linux.

2. Update the socfpga.dtbon the DOS partition on the SD card with the updated one, to have the new QSPI partitioning.
$ sudo mkdir sdcard
$ sudo mount /dev/sdx1 sdcard/
$ sudo cp ~/cv_soc_devkit_ghrd/socfpga.dtb  sdcard/
$ sudo umount sdcard 

Notes:
  • Replace sdx with the corresponding SD card on your host system.
  • No need to create the sdcard folder if it is already created. Just a place to mount the SD card.
  • The above assumes the GHRD was stored in the user home folder
  • On some Linux systems, the DOS partition is automatically mounted, and files can also be copied by copy-paste.

3. Boot Linux and run the following command to verify that the QSPI partitioning is correct:
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00800000 00010000 "Flash 0 Raw Data"
mtd1: 01000000 00010000 "Flash 1 jffs2 Filesystem"
mtd2: 00800000 00010000 "FPGA Image"

4. Gather the following files on your host PC:

File Description
preloader-mkpimage.bin Preloader image file
u-boot-socfpga_cyclone5.img U-Boot image
socfpga.dtb Device Tree Blob
soc_system.rbf Compressed FPGA configuration file
zImage Compressed kernel image
altera-image-minimal-socfpga_cyclone5.jffs2 Minimal root filesystem as jffs2 image
3. Write the above files to the SD card DOS partition, in a new folder named qspi_files
$ sudo mkdir sdcard
$ sudo mount /dev/sdx1 sdcard/
$ sudo mkdir qspi_files
$ sudo cp ~/cv_soc_devkit_ghrd/software/spl-bsp/preloader-mkpimage.bin  sdcard/qspi_files
...
$ sudo umount sdcard 

4. Boot Linux from the SD card as described in Booting Linux

5. From the Linux command prompt, mount the SD card DOS partition and obtain the file sizes
# mount /dev/mmcblk0p1 sdcard
# cd sdcard/qspi_files
# ls -la 

The file sizes will be displayed similar with the following listing:
11796480 altera-image-minimal-socfpga_cyclone5.rootfs.jffs2
  262144 preloader-mkpimage.bin
 2256304 soc_system.rbf
   18101 socfpga.dtb
  258060 u-boot-socfpga_cyclone5.img
 3202832 zImage

6. Write the files from the SD card to the QSPI Flash, using the correct file sizes as displayed on your target and shown in your listing.
# flash_erase /dev/mtd0 0 0 
# flash_erase /dev/mtd1 0 0 
# flash_erase /dev/mtd2 0 0 
# mtd_debug write /dev/mtd0 0 262144 preloader-mkpimage.bin
# mtd_debug write /dev/mtd0 0x50000 18029 socfpga.dtb
# mtd_debug write /dev/mtd0 0x60000 258060 u-boot-socfpga_cyclone5.img
# mtd_debug write /dev/mtd0 0xa0000 3202832 zImage
# flashcp altera-image-minimal-socfpga_cyclone5.rootfs.jffs2 /dev/mtd1
# flashcp soc_system.rbf /dev/mtd2

gsrd-qspi-partition.png

Other QSPI flash programming options are available when Linux boot from SD card is not available:
  • Using HPS Flash Programmer (for smaller files)
  • Using U-boot console

F. Update U-boot Environment to Boot From QSPI

This section will present how to update the U-boot environment to achieve the following:
  • Boot from QSPI (default is boot from SD/MMC)
  • Program FPGA from QSPI (default is from SD/MMC)

1. Configure board to boot from QSPI:

Jumper Setting
J28 right shorted
J29 left shorted
J30 left shorted
2. Boot board, and press any button at U-boot console to stop the boot process.

ubot-qspi.png.

3. On the U-boot console, update the environment variables to boot from QSPI instead of SD/MMC
# setenv qspifpgaaddr 0x1800000
# setenv qspifpga  sf probe $\{qspiloadcs\}\; sf read $\{fpgadata\} $\{qspifpgaaddr\} $\{fpgadatasize\}\; fpga load $\{qspiloadcs\} $\{fpgadata\} $\{filesize\};
# setenv bootcmd run qspifpga\; run bridge_enable_handoff\; run qspiload\; run qspiboot 

5. On the U-boot console, save the environment:
# saveenv 

G. Boot Linux from QSPI

Reset or power cycle the board, or run boot command at U-boot prompt to boot Linux.

Note that because of the reduced size filesystem, not all the features of the GSRD will be available.

linux-qspi.png.
Copyright &© 1999-2014 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RocketBoards.org? Send feedback