Template:GLSDK Using QSPI Boot

Using QSPI Boot
QSPI is a serial peripheral interface like SPI the major difference being the support for Quad read, uses 4 data lines for read compared to 2 lines used by the traditional SPI.

Supported boot modes

 * QSPI Production Boot mode
 * QSPI Development Boot mode

QSPI Production Boot Mode
This boot mode also called as 'spl_early_boot' in Processor SDK Linux Automotive.


 * In this boot mode SPL(first stage of Uboot) directly boots the Linux kernel.
 * The executables - MLO, dtb, uImage & IPU are stored in QSPI flash memory. Refer the "Memory Layout" section for offset details.
 * eMMC partition 2 contains the filesystem & is mounted as rootfs.
 * Build MLO and u-boot.img.

Note: By continuous press of character 'c' key on keyboard and resetting the EVM, SPL will load u-boot and enter into second stage boot loader.

SYS BOOT Switch Settings
change the boot switches to QSPI boot mode as: SW2[5:0] = 110110 for development (jump to u-boot) SW2[5:0] = 110111 for production mode (jump to MLO->kernel) Also SW5.4 = 0 (OFF)

Memory Layout of QSPI Flash
++ 0x00000 |     MLO       | |               | ++ 0x040000 |  u-boot.img   | |               | ++ 0x140000 |  DRA7-evm.dtb | ++ 0x1c0000 |  u-boot env   | ++ 0x1d0000 |  u-boot env   | |   (backup)    | ++ 0x1e0000 |               | |     uImage     | |               | |                | ++ 0x9e0000 |               | |     IPU exe    | |               | ++

Build kernel uImage for QSPI boot mode
In 'spl_early_boot' mode, While building kernel uImage, set CONFIG_CMDLINE bootargs appropriately and set rootfs=/dev/mmcblk0p2 (eMMC device) and set kernel CONFIG_CMDLINE bootargs @menuconfig->Boot options->"Default kernel command string".

for example: CONFIG_CMDLINE = "elevator=noop console=ttyO0,115200n8 root= rw rootwait earlyprintk fixrtc omapdrm.num_crtc=2 consoleblank=0 cma=64M rootfstype=ext4"; where can be /dev/mmcblk0p2 for eMMC or /dev/mmcblk1p2 for mmc/sd.

alternate option: Add the bootargs in chosen node in DTB file, using fdtput utility. #fdtput -v -t s  "/chosen" bootargs "elevator=noop console=ttyO0,115200n8 root= rw rootwait earlyprintk fixrtc omapdrm.num_crtc=2 consoleblank=0 cma=64M rootfstype=ext4" where can be /dev/mmcblk0p2 for eMMC or /dev/mmcblk1p2 for mmc/sd.

Flashing the Image to QSPI from Linux kernel
The mk-qspi-boot.sh will be available at home direcotry of "Processor SDK Linux Automotive" filesystem. The mk-qspi-boot.sh runs on the target. The scripts reads the binaries (MLO, u-boot.img, kernel/dtb, ipu images) from MMC/SD and flashes into QSPI flash memory at appropriate partition described in above table. Also format & creates rootfs partition in eMMC and copies the filesystem the eMMC rootfs parition.

Usage: target#mk-qspi-boot.sh --device1  --device2  --bootmode

--device1 - devfs entry for qspi flash as char device node e.g /dev/mtd

--device2 - devfs entry for eMMC flash as block device node e.g /dev/mmcblk0

--bootmode - 'spl_early_boot' & 'two_stage_boot' spl_early_boot - ROM=>SPL=>uImage two_stage_boot - ROM=>SPL=>u-boot.img=>uImage e.g target#: mk-qspi-boot.sh --device1 /dev/mtd --device2 /dev/mmcblk0 --bootmode spl_early_boot

Note: Defualt DTB is dra7-evm-lcd-osd.dtb. Do change DTB in script if you want to boot the board with different device tree. You can modify the mk-qspi-boot.sh, make sure "emmc_dev" and "main_dev" in mk-qspi-boot.sh point to appropriate "/dev/mmcblkX" device node and also set DTB_FILE_PATH, UIMAGE_FILE_PATH and IPU_FILE_PATH point to correct source.

QSPI Development Boot Mode
This boot mode also called as 'two_stage_boot' in "Processor SDK Linux Automotive"


 * In this boot mode SPL(first stage of Uboot) brings-up u-boot.img(second part of u-boot).
 * The second stage of u-boot, then, loads & boots the Linux kernel.
 * Build MLO and u-boot.img for QSPI boot mode (use "dra7xx_evm_defconfig").
 * Only MLO and u-boot.img are stored in QSPI flash memory.
 * DTB & uImage are stored in MMC/SD boot parition.
 * The rootfs is mounted from MMC/SD partition 2

Note: By continuous press of character 'c' key on keyboard and resetting the EVM, SPL will load u-boot and enter into second stage boot loader.

SYS BOOT Switch Settings
change the boot switches to QSPI boot mode as:

SW2[5:0] = 100110 for development (jump to u-boot) SW2[5:0] = 100111 for production mode (single stage) Also, SW5.4 = 0 (OFF)

Flashing UBoot to QSPI from Linux kernel
The mk-qspi-boot.sh will be available at home direcotry of Processor SDK Linux Automotive filesystem. The mk-qspi-boot.sh runs on the target. It reads the executables from MMC/SD & flashes into QSPI flash memory for 'two_stage_boot'

For Usage of mk-spi-boot.sh refer to above section "Flashing_Image_to_QSPI_from_Linux"

Also QSPI flash can be accessed from kernel through MTD device.

Following commands demonstrate how to flash MLO and u-boot from SD card to QSPI.

target# mount /dev/mmcblk1p1 /mnt target# cat /proc/mtd target# flash_erase -N /dev/mtd0 0 4 target# flash_erase -N /dev/mtd1 0 16 target# mtd_debug write /dev/mtd0 0x0 $(ls -l /mnt/MLO | awk '{ print $5 }') /mnt/MLO target# mtd_debug write /dev/mtd1 0x0 $(ls -l /mnt/u-boot.img | awk '{ print $5 }') /mnt/u-boot.img

Flashing UBoot to QSPI from UBoot
UBoot can be flashed to QSPI from any boot mode, here we are using MMC boot mode as an example Boot from SD card and at the U-Boot prompt, Choose the mmc card to read from uboot# mmc dev 0 uboot# mmc0 is current device


 * Probe the flash to see if there is a device connected,

NOTE: Do NOT copy-paste the commands, please type them at the prompt SF: Detected S25FL256S with page size 64 KiB, total 32 MiB, mapped at 5c000000
 * 1) sf probe 0

NOTE: Do NOT copy-paste the commands, please type them at the prompt where, offset - qspi flash offset address start from 0. size  - erase region size. This is automatically rounded up to the block size. where, memory-address - source data to read from offset - qspi offset location to write len   - length of the data to be written
 * Erase flash before writing the bin
 * 1) sf erase +
 * 1) sf write

Flashing MLO to QSPI uboot# fatload mmc 0 0x82000000 MLO.qspi uboot# sf erase 0 +${filesize} uboot# sf write 0x82000000 0x0 ${filesize}
 * Load the MLO (to offset 0x0) and u-boot.img(to offset 0x40000) to QSPI flash

Flashing u-boot.img to QSPI uboot# fatload mmc 0 0x83000000 u-boot.img uboot# sf erase 40000 60000; uboot# sf write 0x83000000 0x40000 0x60000

Flashing kernel(uImage) to QSPI uboot# fatload mmc 0 0x82000000 uImage uboot# sf erase 1e0000 500000; uboot# sf write 82000000 1e0000 500000;
 * Build kernel to create uImage and dtb files. Load the uImage(to offset 0x1e0000) and DTB files (to offset 0x140000) to QSPI flash

Flashing dtb file to QSPI uboot# fatload mmc 0 0x83000000 uboot# sf erase 140000 20000; uboot# sf write 0x83000000 0x140000 0x20000

After reset, you should be able to boot from QSPI flash.