Overview
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:
.
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.
- Build U-boot from the Yocto package as shown in GSRD v13.1 - Using Yocto Source Package using the command
$ source ~/yocto/altera-init ~/build $ bitbake virtual/bootloader
- 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.h to 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)
- 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 v13.1 - 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.
- Edit the file cv_soc_devkit_ghrd/soc_system_board_info.xml:
</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>
- 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
- 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.
- Obtain SD card that boots Linux, from the binaries package, as described in Booting Linux.
- Update the socfpga.dtb on 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:
- 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 |
$ 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
- Boot Linux from the SD card as described in Booting Linux
- 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
- 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
Other QSPI flash programming options are available when Linux boot from SD card is not available:
F. Update U-boot Environment to Boot From QSPI
This section will present how to update the U-boot environment to achieve the following:
1. Configure board to boot from QSPI:
Jumper | Setting |
---|---|
J28 | left shorted |
J29 | left shorted |
J30 | left shorted |
.
- 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
- 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.
.