OSPI Flash

An Octal Serial Peripheral Interface (OSPI) Flash is populated on the phyCORE-AM62Ax as a programmable nonvolatile storage. The OSPI interface supports single, dual, quad, or octal read/write access to the flash device. This guide will walk through how to read and write from the OSPI. The OSPI Flash can be used for a fast boot source, see the guide ospiBoot-62A for more on booting from OSPI. For more information on the OSPI interface, see the OSPI chapter in the Hardware Manual

View Available NOR Partitions

  • Verify that the NOR interface was initialized properly.

sh-phyboard-lyra-am62axx-2:~# mtdinfo
Count of MTD devices:           1
Present MTD devices:            mtd0
Sysfs interface supported:      yes
  • View basic partition information.

sh-phyboard-lyra-am62axx-2:~# cat /proc/mtd
  • More detailed information can be viewed using the “mtdinfo” command on a specific partition.

sh-phyboard-lyra-am62axx-2:~# 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
Device is writable:             true

Configuring NOR Partitions

The NOR flash partitions are defined in the U-Boot device tree file (files ending with -u-boot.dtsi). These partition definitions are automatically carried over to the OS device tree.

Each partition is defined with:

  • A unique base address

  • A descriptive label

  • A size specification in the reg property (offset and length)

Here’s an example configuration showing the standard partition layout:

&ospi0 {
        bootph-all;

        flash@0 {
                bootph-all;
                partitions {
                        compatible = "fixed-partitions";
                        #address-cells = <1>;
                        #size-cells = <1>;

                        partition@0 {
                                label = "ospi.tiboot3";
                                reg = <0x00000 0x80000>;
                        };
                        partition@80000 {
                                label = "ospi.tispl";
                                reg = <0x080000 0x200000>;
                        };
                        partition@280000 {
                                label = "ospi.u-boot";
                                reg = <0x280000 0x400000>;
                        };
                        partition@680000 {
                                label = "ospi.env";
                                reg = <0x680000 0x40000>;
                        };
                        partition@6c0000 {
                                label = "ospi.env.backup";
                                reg = <0x6c0000 0x40000>;
                        };
                };
        };
};

Make sure partitions don’t overlap and align them to the flash erase block size (typically 64 KB or 128 KB).

Write to OSPI

  • Create a random file equal to the size of the /dev/mtd0 partition (512 kBytes).

sh-phyboard-lyra-am62axx-2:~# dd if=/dev/urandom of=test.dat bs=1k count=512
512+0 records in
512+0 records out
524288 bytes (524 kB, 512 KiB) copied, 0.0152006 s, 34.5 MB/s
  • Copy the generated file to the mtd0 partition.

sh-phyboard-lyra-am62axx-2:~# flashcp -v test.dat /dev/mtd0
Erasing blocks: 4/4 (100%)
Writing data: 512k/512k (100%)
Verifying data: 512k/512k (100%)

Read from OSPI

  • Dump the contents of /dev/mtd0 partition to a new file:

sh-phyboard-lyra-am62axx-2:~# dd if=/dev/mtd0 of=read.dat bs=1k count=512
512+0 records in
512+0 records out
524288 bytes (524 kB, 512 KiB) copied, 0.167633 s, 3.1 MB/s
  • Verify that the output files were not corrupted during the transfer using md5sum.

sh-phyboard-lyra-am62axx-2:~# md5sum test.dat read.dat
3497f295076c7ef96443b109ab9be333  test.dat
3497f295076c7ef96443b109ab9be333  read.dat