This article talks about the U-Boot FAT and EXT file type commands that are used most commonly.
For related subjects, please refer to the SOC Table of Contents.
Note that the FAT format is typically used in Windows systems, and is the only format that the Linux boot-loader recognizes. Thus, the boot partition of the SD card is formatted into FAT formats. At the same time, the EXT formats are for Linux file systems, which involves the storage of files and data.
FAT Format File Operation Commands
Using fatinfo
fatinfo is used to search a specified MMC partition’s file system information. The formatting is as follows:
fatinfo <interface> [<dev[:part]>]
Where interface refers to the connection port, dev is the device to search, and part is the partition to search. If we were to search partition 1 of the SD card, we would use the following command:
fatinfo mmc 0:1
As seen above, partition 1 of the SD card has the format of FAT32.
Using fatls
fatls is mainly used to search for the directory of devices with the FAT format, and their file information. The formatting is as follows:
fatls <interface>[<dev[:part]>] [directory]
Where interface refers to the connection port, dev is the device to search, part is the partition to search, and directory is the directory to search. If we were to search all files and directories in partition 1 of the SD card, we would use the following command:
fatls mmc 0:1
As seen above, partition 1 of the SD card has 2 files, which is BOOT.BIN and image.ub. It did not find any directories.
Using fstype
fstype is used to view the file system format of MMC device partitions. The command formatting is as follows:
fstype <interface> <dev>:<part>
Because our SD card has two partitions, we can use this command to see each partition’s format.
fstype mmc 0:1
fstype mmc 0:2
As seen above, partition 1 has the fat format, while partition 2 has the ext4 format.
Using fatload
fatload is used to read the specified file to DRAM. The formatting is as follows:
fatload <interface> [<dev[:part]>[<addr>[<filename>[bytes[pos]]]]]
Where interface is the connection port, dev is the device, part is the partition, addr is the starting address of the position to be saved at in DRAM, filename is the name of the file to be read, bytes is the number of bytes of data to be read (if it is set as 0 or not specified, it will read the entire file), and pos is the position displacement between the file to be read and the file start address (if it is set as 0 or not specified, it will start from the file’s starting address). As an example, we will read BOOT.BIN from partition 1 of the SD card to 0x00000000 in DRAM.
fatload mmc 0:1 00000000 BOOT.BIN
Using fatwrite
fatwrite writes DRAM data to MMC devices. The formatting is as follows:
fatwrite <interface> <dev[:part]> <addr> <filename> <bytes>
Where interface is the connection port, dev is the device, part is the partition, addr is the starting address of the data to be written that is stored in DRAM, filename is the name of the file to be read, and bytes is the number of bytes of data to be read (if it is set as 0 or not specified, it will read the entire file). fatwrite can also be used to update Linux mirror images and device trees.
As an example, we will be updating the Linux mirror image image.ub. First, we will need to copy the image.ub mirror image file from our project folder in our Ubuntu machine to the tftpboot directory if it isn’t there already. If you followed our previous tutorials, the tftpboot directory should be in the root directory. When the PetaLinux project finishes building, it will automatically copy it to under the tftp service directory
Now, we can use the tftpboot command to download the image.ub file to 0x00000000 in DRAM.
tftpboot 00000000 image.ub
We can see above that the file has a size of 4160484 bytes, which is equivalent to 3f7be4 in hexadecimal. We can use fatwrite to write it to partition 1 in the SD card, and use fatls to verify if the file was successfully transferred.
fatwrite mmc 0:1 00000000 image.ub 0x3f7be4
EXT Format File Operation Commands
U-Boot has commands for ext2 and ext4 file systems. The most commonly used commands are: ext2load, ext2ls, ext4load, ext4ls, and ext4write. Note that these commands are used the same way as fatload, fatls, and fatwrite. The only difference is the targeted file system format type. As an example, we will use ext4ls to view the files and directories in partition 2 of the SD card, as it has the ext4 format.
ext4ls mmc 0:2