NOR

Flashing the NOR from an SD Card

The phyCORE-i.MX7 comes equipped with a 16 MiB QSPI NOR Flash populated directly on the SOM. NOR flash memory is more expensive than NAND/eMMC and its slower to write to but NOR flash has the advantage when it comes to read speeds. This makes it useful as a read only memory device to store images such as the Linux kernel and U-Boot. In this guide, we will walk through the steps to flash both the Linux kernel and U-boot to the NOR Flash and how to use it as a boot device.

Flashing U-Boot to the NOR Flash

Configuring U-Boot

In order to follow this guide you must have completed the steps outlined in the Build the BSP guide and have successfully built either the fsl-image-validation-imx or u-boot-phytec targets. This will provide you access to the u-boot repo where we will have to enable the QSPI interface for boot. The standard u-boot configuration DOES NOT include QSPI Boot support by default.

  • Using the same Terminal session you used to build using bitbake, navigate to the U-boot source repo that was cloned locally to your machine during the build:

    Host (Ubuntu)
    cd $YOCTO_DIR/build/tmp/work/imx7d_phyboard_zeta_004-poky-linux-gnueabi/u-boot-phytec/2018.03+git_v2018.03-phy1-r0/git
    
  • Generate a new kernel configuration with the default configuration file for your phyCORE-i.MX7:

    Host (Ubuntu)
    make mx7d_pcm061_21x_defconfig
    
  • Start the menuconfig tool to help us modify the Linux source:

    Host (Ubuntu)
    make menuconfig
    
  • Once presented with a GUI, navigate to ‘Boot media →’ using the Arrow and Enter keys of your keyboard.

    ../_images/pcm-061_nor-gui.png
  • Enable ‘Support for booting from QSPI flash’ using the ‘Y’ key of your keyboard.

    ../_images/pcm-061_nor-gui1.png
  • Save the configuration file using the default file name ‘.config

    ../_images/pcm-061_nor-gui2.png
  • Exit menuconfig.

  • Build U-Boot:

    Host (Ubuntu)
    make ARCH=arm CROSS_COMPILE=/opt/fsl-imx-x11/4.9.11-1.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi- u-boot.imx
    
  • Once the build completes you should see a new u-boot.imx image in the current working directory. Transfer this file to the /home/root directory of your phyCORE-i.MX7’s SD Card. See Copying Files to the Device to the Device to help you accomplish this.

Flashing U-Boot to the NOR

  • With your phyCORE-i.MX7 booted into Linux and your new u-boot.imx image present in the /home/root directory, use the following commands to clear the NOR flash:

    Target (Linux)
    dd if=/dev/zero of=zero.dat bs=16777216 count=1
    flashcp -v zero.dat /dev/mtd0
    
  • Now flash the NOR:

    Target (Linux)
    flashcp -v u-boot.imx /dev/mtd0
    

Boot using U-Boot stored on the NOR flash

In order to load the U-Boot image stored on the NOR flash set the Boot Switches of the phyCORE-i.MX7 development kit to the following.

../_images/pcm-061_boot-nor.png

This will configure the ROM loader to search for a valid boot device via the QSPI interface. The ROM loader will then load the u-boot.imx image from the NOR flash into memory. U-boot will then load Linux from an SD Card by default.

Flashing Linux to the NOR Flash

  • Power on your phyCORE-i.MX7 development kit and stop in U-Boot when prompted.

  • In U-boot, probe the QSPI NOR flash and erase enough space for the Linux kernel and device tree:

    Target (U-Boot)
    sf probe
    sf erase 0 0x770000
    

    Note

    If you have made significant changes to your kernel you may need to clear more room on the NOR flash to store it. Use the folllowing command in U-Boot to check the size of your kernel (zImage) and device tree file (.dtb):

    Target (U-Boot)
    fatls mmc 0:1
    

    The image size values are presented in decimal and must be converted to hexadecimal in order to satisfy to hexadecimal argument in the command ‘sf probe’.

  • In U-Boot, flash the kernel and device tree from the SD card to QSPI NOR flash:

    Target (U-Boot)
    setenv zImage_size 0x760000
    setenv fdt_size 0xE900
    saveenv
    
    mw.b ${loadaddr} 0xff ${zImage_size}
    fatload mmc 0:1 ${loadaddr} zImage
    sf write ${loadaddr} 0 ${zImage_size}
    
    mw.b ${fdt_addr} 0xff ${fdt_size}
    fatload mmc 0:1 ${fdt_addr} ${fdt_file}
    
    sf write ${fdt_addr} ${zImage_size} ${fdt_size}
    

Configuring U-Boot to Load Linux from NOR

In order to use the Linux image stored on the NOR flash we will have to configure U-Boot to search for it there instead of the SD Card which it does by default. This example will require U-boot to be loaded from some other boot media such as the SD Card or eMMC. For more information about how to flash U-Boot to these devices please see Create a Bootable SD Card and Flashing and Booting From eMMC.

  • Reset the board and stop in U-boot again when prompted:

    Target (U-Boot)
    reset
    
  • Clear memory where the kernel and device tree will be loaded:

    Target (U-Boot)
    mw.b ${loadaddr} 0xff ${zImage_size}
    mw.b ${fdt_addr} 0xff ${fdt_size}
    
  • Read the kernel and device tree from QSPI NOR flash and boot (use mmcargs to set the serial console and root filesystem, which will still be loaded from the SD card):

    Target (U-Boot)
    run mmcargs
    sf probe
    sf read ${loadaddr} 0 ${zImage_size}
    sf read ${fdt_addr} ${zImage_size} ${fdt_size}
    bootz ${loadaddr} - ${fdt_addr};