OSPI Flash
An Octal Serial Peripheral Interface (OSPI) Flash is populated on the phyCORE-AM64x 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 Flashing the SPI NOR Flash 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-electra-am64xx-2:~# mtdinfo
Count of MTD devices: 6
Present MTD devices: mtd0, mtd1, mtd2, mtd3, mtd4, mtd5
Sysfs interface supported: yes
View basic partition information.
sh-phyboard-electra-am64xx-2:~# cat /proc/mtd
dev: size erasesize name
mtd0: 04000000 00020000 "fc40000.spi.0"
mtd1: 00080000 00020000 "ospi.tiboot3"
mtd2: 00200000 00020000 "ospi.tispl"
mtd3: 00400000 00020000 "ospi.u-boot"
mtd4: 00040000 00020000 "ospi.env"
mtd5: 00040000 00020000 "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.
sh-phyboard-electra-am64xx-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
Warning
The following example writes to the start of /dev/mtd0, which is where the ospi.tiboot3 bootloader partition is located. Any bootloader stored in the OSPI flash is overwritten. The development kit ships without a bootloader in the OSPI flash, so this is safe on a new kit. To boot from OSPI afterwards, flash the bootloader again as described in Flashing the SPI NOR Flash.
Create a 512 kB random test file.
sh-phyboard-electra-am64xx-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-electra-am64xx-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
Read the same 512 kB back from /dev/mtd0 into a new file:
sh-phyboard-electra-am64xx-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-electra-am64xx-2:~# md5sum test.dat read.dat
3497f295076c7ef96443b109ab9be333 test.dat
3497f295076c7ef96443b109ab9be333 read.dat