OSPI Flash
A quad SPI NOR Flash (Micron MT25QU512, U62) is populated on the phyFLEX-Libra AM62Px as a programmable nonvolatile storage. It is connected to the OSPI0 interface of the phyFLEX-AM62Px. This guide will walk through how to read and write from the OSPI.
View Available NOR Partitions
Verify that the NOR interface was initialized properly.
am62pxx-phyflex-libra-rdk-1:~# mtdinfo
Count of MTD devices: 6
Present MTD devices: mtd0, mtd1, mtd2, mtd3, mtd4, mtd5
Sysfs interface supported: yes
View basic partition information.
am62pxx-phyflex-libra-rdk-1:~# cat /proc/mtd
dev: size erasesize name
mtd0: 04000000 00010000 "fc40000.spi.0"
mtd1: 00080000 00010000 "ospi.tiboot3"
mtd2: 00200000 00010000 "ospi.tispl"
mtd3: 00400000 00010000 "ospi.u-boot"
mtd4: 00040000 00010000 "ospi.env"
mtd5: 00040000 00010000 "ospi.env.backup"
mtd0 is the whole flash device. mtd1 to mtd5 are the bootloader and environment partitions inside it, starting at offset 0. The partitions come from the device tree, so they are listed even when the OSPI flash is empty, as it is on a new kit.
More detailed information can be viewed using the “mtdinfo” command on a specific partition.
am62pxx-phyflex-libra-rdk-1:~# mtdinfo /dev/mtd0
mtd0
Name: fc40000.spi.0
Type: nor
Eraseblock size: 65536 bytes, 64.0 KiB
Amount of eraseblocks: 1024 (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
Warning
The following example writes to the start of /dev/mtd0, which is where the ospi.tiboot3 bootloader partition is located. Any data stored there is overwritten.
Create a 512 kB random test file.
am62pxx-phyflex-libra-rdk-1:~# 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.
am62pxx-phyflex-libra-rdk-1:~# flashcp -v test.dat /dev/mtd0
Erasing blocks: 8/8 (100%)
Writing data: 512k/512k (100%)
Verifying data: 512k/512k (100%)
Read from OSPI
Read the same 512 kB back from /dev/mtd0 into a new file:
am62pxx-phyflex-libra-rdk-1:~# 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.
am62pxx-phyflex-libra-rdk-1:~# md5sum test.dat read.dat
3497f295076c7ef96443b109ab9be333 test.dat
3497f295076c7ef96443b109ab9be333 read.dat