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 as 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 mke2fs command.

Example:

root@mitysom-am57x:~# mkfs.ext2 /dev/mtdblock6
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 22656 1k blocks and 5664 inodes
Filesystem UUID: 3869c9f6-64b4-4380-b5e0-ccb739014fab
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: 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.ext2 (or mke2fs) 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   ext2         3869c9f6-64b4-4380-b5e0-ccb739014fab
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 is:

root@mitysom-am57x:~/mtd0# parted -l
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:

Error: /dev/mtdblock2: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock2: 524kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

Error: /dev/mtdblock0: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock0: 262kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

Error: /dev/mtdblock5: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock5: 8389kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

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:

Error: /dev/mtdblock1: unrecognised disk label
Model: Unknown (unknown)
Disk /dev/mtdblock1: 1049kB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

Model: SD GB1QT (sd/mmc)
Disk /dev/mmcblk0: 32.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4096B   24.8MB  24.8MB  primary  fat16        boot, lba
 2      24.8MB  11.1GB  11.0GB  primary  ext4

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  ext2

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
[ 4348.387528] EXT4-fs (mtdblock6): mounting ext2 file system using the ext4 subsystem
[ 4348.600949] EXT4-fs (mtdblock6): mounted filesystem without journal. 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 ext2 (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 Nov 15 20:42 lost+found
-rw-r--r--    1 root     root             0 Nov 15 20:50 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 Nov 15 20:50 hello
drwx------    2 root     root         12288 Nov 15 20:42 lost+found
-rw-r--r--    1 root     root             0 Nov 15 20:50 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.

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)