OSPI NOR Flash
A 64 MB OSPI NOR Flash is populated on the phyCORE-AM65x development kit and is available for use as volatile or non-volatile memory. The NOR Flash is accessible through the OSPI interface and can also be used as an alternative boot source.
This guide will show you how to read from and write to the OSPI NOR.
Partition Information
To view the software-defined partitions for the OSPI NOR Flash, enter the following commands:
mtdinfo cat /proc/mtd
You can expect an output similar to the one below. In this example the OSPI NOR Flash has 7 partitions.
root@am65xx-phycore-kit:~# mtdinfo Count of MTD devices: 7 Present MTD devices: mtd0, mtd1, mtd2, mtd3, mtd4, mtd5, mtd6 Sysfs interface supported: yes root@am65xx-phycore-rdk:~# cat /proc/mtd dev: size erasesize name mtd0: 00080000 00020000 "ospi.tiboot3" mtd1: 00200000 00020000 "ospi.tispl" mtd2: 00400000 00020000 "ospi.u-boot" mtd3: 00020000 00020000 "ospi.env" mtd4: 00020000 00020000 "ospi.env.backup" mtd5: 00100000 00020000 "ospi.sysfw" mtd6: 03800000 00020000 "ospi.rootfs"
If you would like to take a closer look at each partition you can run the following command:
mtdinfo /dev/mtd0
Below is the expected output. In this case you can see that the first partition of the OSPI NOR is named ospi.tiboot3 and is 512 kBytes.
root@am65xx-phycore-kit:~# mtdinfo /dev/mtd0 mtd0 Name: ospi.tiboot3 Type: nor Eraseblock size: 131072 bytes, 128.0 KiB Amount of eraseblocks: 4 (524288 bytes, 512.0 KiB) 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
Write to OSPI
Using this example you can create a random file equal in size to the /dev/mtd0 partition (512 kBytes) and transfer it to the OSPI NOR using the flashcp command. Run the following from the command line:
dd if=/dev/urandom of=test.dat bs=1k count=512 flashcp -v test.dat /dev/mtd0
Below is the expected output:
root@am65xx-phycore-kit:~# dd if=/dev/urandom of=test.dat bs=1k count=512 512+0 records in 512+0 records out root@am65xx-phycore-kit:~# flashcp -v test.dat /dev/mtd0 Erasing blocks: 4/4 (100%) Writing data: 512k/512k (100%) Verifying data: 512k/512k (100%)
Read from OSPI
Going the opposite direction of the previous example, to read the OSPI NOR flash, you can dump the contents of /dev/mtd0 to a new file:
dd if=/dev/mtd0 of=read.dat bs=1k count=512
The file read (read.dat) should be identical to the file written in the previous example (test.dat). Use md5sum to compare and verify the data transfer was successful:
md5sum test.dat && md5sum read.dat
Below is the expected output:
root@am65xx-phycore-kit:~# dd if=/dev/mtd0 of=read.dat bs=1k count=512 512+0 records in 512+0 records out root@am65xx-phycore-kit:~# md5sum test.dat && md5sum read.dat 066206f95d3d324048c55b6840998e0c test.dat 066206f95d3d324048c55b6840998e0c read.dat