Flashing the SPI NOR Flash
Before proceeding further, it’s recommended to familiarize yourself with the foundational concepts detailed in the Booting Essentials chapter. It will provides instructions on how to initiate the device from any accessible boot source, enabling you to proceed with the flashing procedure. Afterwards we’ll explore different approaches to flashing NOR flash: from an SD card or over a network connection.
The phyCORE-AM62x modules are optionally equipped with SPI NOR Flash. The SPI NOR flash partition table is defined in the U-Boot-only device tree k3-am625-phyboard-lyra-rdk-u-boot.dtsi. It can be printed with:
uboot:~# mtd list
SF: Detected mt35xu512aba with page size 256 Bytes, erase size 4 KiB, total 64 MiB
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@fc40000
- driver: jedec_spi_nor
- path: /bus@f0000/bus@fc00000/spi@fc40000/flash@0
- type: NOR flash
- block size: 0x1000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000004000000 : "nor0"
- 0x000000000000-0x000000080000 : "ospi.tiboot3"
- 0x000000080000-0x000000280000 : "ospi.tispl"
- 0x000000280000-0x000000680000 : "ospi.u-boot"
- 0x000000680000-0x0000006c0000 : "ospi.env"
- 0x0000006c0000-0x000000700000 : "ospi.env.backup"
- 0x000000700000-0x000000800000 : "ospi.dtb"
- 0x000000800000-0x000001e00000 : "ospi.kernel"
- 0x000001e00000-0x000004000000 : "ospi.rootfs"
In this chapter, we will explore proceduress of flashing the OSPI NOR flash, starting from the point after the u-boot bootloader has successfully booted.
Flash SPI NOR Flash from SD Card
Flash SPI NOR from SD Card in U-Boot
The easiest way to access the SOM’s OSPI is to boot the SOM into U-Boot from an SD card (you may already be doing this). This guide will require a “Bootable SD card”, an SD card that has been flashed with the development kit’s BSP image. For instructions on how to create a bootable SD card, see this guide SD Card.
Power on the development kit and hit any key to stop in U-Boot.
Note
Be sure that you are booting the kit from SD card!
Within U-Boot, flash both SPLs and the U-Boot image into the OSPI storage device.
uboot:~# mtd list uboot:~# load mmc 1 ${loadaddr} tiboot3.bin uboot:~# mtd write ospi.tiboot3 ${loadaddr} 0 ${filesize} uboot:~# load mmc 1 ${loadaddr} tispl.bin uboot:~# mtd write ospi.tispl ${loadaddr} 0 ${filesize} uboot:~# load mmc 1 ${loadaddr} u-boot.img uboot:~# mtd write ospi.u-boot ${loadaddr} 0 ${filesize}
Note
If the flashing process did not worked, try to erase the mtd partition first using mtd erase <mtdname>.
You can also include an initramfs and kernel on the OSPI NOR, which will allow you to boot into Linux using OSPI. Again, you will need to be booted into U-Boot with an SD card, and this guide also expects that you have a USB drive with an initramfs image on it. The name of the initramfs image will vary depending on what machine you are using.
uboot:~# load mmc 1 ${loadaddr} k3-am625-phyboard-lyra-rdk.dtb uboot:~# mtd write ospi.dtb ${loadaddr} 0 ${filesize} uboot:~# setenv size_fdt $filesize uboot:~# load mmc 1 ${loadaddr} Image uboot:~# mtd write ospi.kernel ${loadaddr} 0 ${filesize} uboot:~# setenv size_kern $filesize uboot:~# usb start uboot:~# load usb 0 ${loadaddr} phytec-initramfs-phyboard-lyra-am62xx-3.cpio.xz uboot:~# mtd write ospi.rootfs ${loadaddr} 0 ${filesize} uboot:~# setenv size_fs $filesize uboot:~# saveenv uboot:~# env export -c ${loadaddr} uboot:~# sf update ${loadaddr} 0x680000 ${filesize} uboot:~# sf update ${loadaddr} 0x6c0000 ${filesize}
Flash SPI NOR from SD Card in Linux
If you have booted using the phytec-qt5demo-image-phyboard-lyra-am62xx-3.wic image, you can find all required bootloader binaries in the automatically mounted /boot/ directory.
phyboard-lyra-am62xx-3:~# ls /boot tiboot3.bin* tispl.bin* u-boot.img* ...
Find the number of blocks to erase of the U-boot partition:
phyboard-lyra-am62xx-3:~# mtdinfo /dev/mtd0 mtd0 Name: fc40000.spi.0 Type: nor Eraseblock size: 131072 bytes, 128.0 KiB Amount of eraseblocks: 512 (67108864 bytes, 64.0 MiB) Minimum input/output unit size: 1 byte Sub-page size: 1 byte Character device major/minor: 90:0 Bad blocks are allowed: false
Erase the U-Boot partition and flash it:
phyboard-lyra-am62xx-3:~# flash_erase /dev/mtd0 0 512 phyboard-lyra-am62xx-3:~# flashcp /boot/tiboot3.bin /dev/mtd0 phyboard-lyra-am62xx-3:~# flashcp /boot/tispl.bin /dev/mtd1 phyboard-lyra-am62xx-3:~# flashcp /boot/u-boot.img /dev/mtd2
Flash SPI NOR Flash from Network
Flash SPI NOR from Network in U-Boot
Similar to updating the eMMC over a network, be sure to set up the development host correctly. The IP needs to be set to 192.168.3.10, the netmask to 255.255.255.0, and a TFTP server needs to be available. Before reading and writing to the MTD partitions is possible, the MTD list needs to be initilized:
uboot:~# mtd list
SF: Detected mt35xu512aba with page size 256 Bytes, erase size 4 KiB, total 64 MiB
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@fc40000
- driver: jedec_spi_nor
- path: /bus@f0000/bus@fc00000/spi@fc40000/flash@0
- type: NOR flash
- block size: 0x1000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000004000000 : "nor0"
- 0x000000000000-0x000000080000 : "ospi.tiboot3"
- 0x000000080000-0x000000280000 : "ospi.tispl"
- 0x000000280000-0x000000680000 : "ospi.u-boot"
- 0x000000680000-0x0000006c0000 : "ospi.env"
- 0x0000006c0000-0x000000700000 : "ospi.env.backup"
- 0x000000700000-0x000000800000 : "ospi.dtb"
- 0x000000800000-0x000001e00000 : "ospi.kernel"
- 0x000001e00000-0x000004000000 : "ospi.rootfs"
Flash both SPLs and the U-Boot image into the OSPI storage device.
tftp ${loadaddr} tiboot3.bin mtd write ospi.tiboot3 ${loadaddr} 0 ${filesize} tftp ${loadaddr} tispl.bin mtd write ospi.tispl ${loadaddr} 0 ${filesize} tftp ${loadaddr} u-boot.img mtd write ospi.u-boot ${loadaddr} 0 ${filesize}
Flash SPI NOR from Network in Linux
Make sure all three bootloader binaries are available on the target, e.g. by copying them via scp:
host:~$ scp tiboot3.bin tispl.bin u-boot.img [email protected]:/root
Find the number of blocks to erase of the U-boot partition:
phyboard-lyra-am62xx-3:~# mtdinfo /dev/mtd0 mtd0 Name: fc40000.spi.0 Type: nor Eraseblock size: 131072 bytes, 128.0 KiB Amount of eraseblocks: 512 (67108864 bytes, 64.0 MiB) Minimum input/output unit size: 1 byte Sub-page size: 1 byte Character device major/minor: 90:0 Bad blocks are allowed: false
Erase the U-Boot partition and flash it:
phyboard-lyra-am62xx-3:~# flash_erase /dev/mtd0 0 512 phyboard-lyra-am62xx-3:~# flashcp tiboot3.bin /dev/mtd0 phyboard-lyra-am62xx-3:~# flashcp tispl.bin /dev/mtd1 phyboard-lyra-am62xx-3:~# flashcp u-boot.img /dev/mtd2