Project

General

Profile

Example SOM QSPI NOR

Goal

The goal of this example is to demonstrate how to use the SOM QSPI NOR storage.

This storage can be used for:

  • General purpose storage.
  • As a boot device

General Purpose Storage

Prerequisites

  • The Device needs to be divided into one or more partitions.
  • To use as a Linux file system, a file system must be created in the partition.

Steps

  • Creating partitions.

The partitions are specified in the Device Tree. See this section of am57xx-mitysom.dtsi

&qspi {
    status = "okay";

    spi-max-frequency = <76800000>;
    m25p80@0 {
        compatible = "s25fl256s1", "jedec,spi-nor";
        spi-max-frequency = <76800000>;
        reg = <0>;
        spi-tx-bus-width = <1>;
        spi-rx-bus-width = <4>;
        #address-cells = <1>;
        #size-cells = <1>;

        /* MTD partition table.
         * The ROM checks the first four physical blocks
         * for a valid file to boot and the flash here is
         * 64KiB block size.
         */
        partition@0 {
            label = "QSPI.SPL";
            reg = <0x00000000 0x000040000>;
        };
        partition@1 {
            label = "QSPI.u-boot";
            reg = <0x00040000 0x00100000>;
        };
        partition@2 {
            label = "QSPI.u-boot-spl-os";
            reg = <0x00140000 0x00080000>;
        };
        partition@3 {
            label = "QSPI.u-boot-env";
            reg = <0x001c0000 0x00010000>;
        };
        partition@4 {
            label = "QSPI.u-boot-env.backup1";
            reg = <0x001d0000 0x0010000>;
        };
        partition@5 {
            label = "QSPI.kernel";
            reg = <0x001e0000 0x0800000>;
        };
        partition@6 {
            label = "QSPI.file-system";
            reg = <0x009e0000 0x01620000>;
        };
    };
};

These can be verified by looking at /proc/mtd

root@mitysom-am57x:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "QSPI.SPL" 
mtd1: 00100000 00010000 "QSPI.u-boot" 
mtd2: 00080000 00010000 "QSPI.u-boot-spl-os" 
mtd3: 00010000 00010000 "QSPI.u-boot-env" 
mtd4: 00010000 00010000 "QSPI.u-boot-env.backup1" 
mtd5: 00800000 00010000 "QSPI.kernel" 
mtd6: 01620000 00010000 "QSPI.file-system" 
root@mitysom-am57x:~#

If you have not created any partitions, then the output of lsblk will be similar to what is shown below:

root@mitysom-am57x:~# lsblk --fs
NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
mtdblock0
mtdblock1
mtdblock2
mtdblock3
mtdblock4
mtdblock5
mtdblock6
mmcblk0
|-mmcblk0p1 vfat   boot  7BD4-7472                            /run/media/mmcblk0p1
`-mmcblk0p2 ext4   root  0df6ebe8-581f-42c9-8440-b18e6f18b5fa /
root@mitysom-am57x:~#

Creating a filesystem

To make a partition so it can be mounted and used as a regular filesystem, you can use the mkfs.ext4 command.

Example:

root@mitysom-am57x:~# mkfs.ext4 /dev/mtdblock6
mke2fs 1.44.3 (10-July-2018)
64-bit filesystem support is not enabled.  The larger fields afforded by this feature enable full-strength checksumming.  Pass -O 64bit to rectify.
Creating filesystem with 22656 1k blocks and 5664 inodes
Filesystem UUID: 92031108-5873-41bb-8c8c-c8b526f20e9e
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

root@mitysom-am57x:~#

Note that the above is a very simple example. You may want to consult the manual of the mkfs.ext3 or mkfs.ext4 and use a different filesystem type and one or more of the configuration options.

The output of lsblk is now:

root@mitysom-am57x:~# lsblk --fs
NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
mtdblock0
mtdblock1
mtdblock2
mtdblock3
mtdblock4
mtdblock5
mtdblock6   ext4         92031108-5873-41bb-8c8c-c8b526f20e9e
mmcblk0
|-mmcblk0p1 vfat   boot  7BD4-7472                            /run/media/mmcblk0p1
`-mmcblk0p2 ext4   root  0df6ebe8-581f-42c9-8440-b18e6f18b5fa /
root@mitysom-am57x:~#

The output of the parted command for the /dev/mtdblock* devices is:

root@mitysom-am57x:~# for ii in /dev/mtdblock*
> do
> echo "=====================================> "$ii
> parted $ii print
> done
=====================================> /dev/mtdblock0
Error: /dev/mtdblock0: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock0: 262kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock1
Error: /dev/mtdblock1: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock1: 1049kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock2
Error: /dev/mtdblock2: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock2: 524kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock3
Error: /dev/mtdblock3: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock3: 65.5kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock4
Error: /dev/mtdblock4: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock4: 65.5kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock5
Error: /dev/mtdblock5: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock5: 8389kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
=====================================> /dev/mtdblock6
Model: Unknown (unknown)
Disk /dev/mtdblock6: 23.2MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  23.2MB  23.2MB  ext4

root@mitysom-am57x:~#

Mounting the filesystem

To mount the filesystem, create a mount point (a directory) and use the mount command.

root@mitysom-am57x:~# cd
root@mitysom-am57x:~# mkdir mnt
root@mitysom-am57x:~# mount /dev/mtdblock6 mnt
[ 4637.165665] EXT4-fs (mtdblock6): mounted filesystem with ordered data mode. Opts: (null)
root@mitysom-am57x:~# mount
/dev/mmcblk0p2 on / type ext4 (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=775152k,nr_inodes=97529,mode=755)
.
.
.
/dev/mtdblock6 on /home/root/mnt type ext4 (rw,relatime)
root@mitysom-am57x:~#

Using the mounted filesystem

The partition can now be used as a regular directory.

# see what files exist
root@mitysom-am57x:~# ls mnt
lost+found
#
# Create a file
#
root@mitysom-am57x:~# touch mnt/my_file
#
# See what files exist
# 
root@mitysom-am57x:~# ls -l mnt
drwx------    2 root     root         12288 Aug  2 16:15 lost+found
-rw-r--r--    1 root     root             0 Aug  2 16:22 my_file
# 
# Create a second file
# 
root@mitysom-am57x:~# echo Hello >mnt/hello
root@mitysom-am57x:~# ls -l mnt
-rw-r--r--    1 root     root             6 Aug  2 16:23 hello
drwx------    2 root     root         12288 Aug  2 16:15 lost+found
-rw-r--r--    1 root     root             0 Aug  2 16:22 my_file
# 
# Verify the contents of the second file
# 
root@mitysom-am57x:~# cat mnt/hello
Hello
root@mitysom-am57x:~#

Persistent mount

To have a persistent mount on reboot, you may want to make an entry in /etc/fstab.

Unmount the file system

root@mitysom-am57x:~# umount /dev/mtdblock6
root@mitysom-am57x:~#

Wipe out the filesystem

To remove the filesystem from the device, do the following:

root@mitysom-am57x:~# dd if=/dev/zero of=/dev/mtdblock6 bs=1M count=1
1+0 records in
1+0 records out
root@mitysom-am57x:~# parted /dev/mtdblock6 print
Error: /dev/mtdblock6: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock6: 23.2MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
root@mitysom-am57x:~#

Boot Device

To use QSPI NOR as a boot device, the following would need to be done:

  • Make a file system image to fit in 32MB.
    • Write the uboot image and kernel images to the QSPI NOR
  • Change jumper JP8 to boot from QSPI.
    • Open is SD, EMMC, USB
    • Short is QSPI, SD, USB
  • Change the uboot environment variables to read the images from QSPI instead of mmc
    #  use commands like (exact offsets and sizes may vary)
    sf probe 0:0 6000000
    sf read 42000000 100000 400000
    bootm 0x42000000 
    

Conclusion

This example has demonstrated how to use the QSPI NOR as a regular filesystem and how it could be used as a boot device.

Go to top
Add picture from clipboard (Maximum size: 1 GB)