There are several ways of transferring files to and from your target device. Please reference the following for some possible methods.

Using Removable Storage Devices:

 Using a USB drive

Storage devices formatted with a FAT32 file system, when connected, are automatically mounted to "/run/media/sda1". 

 Reformat your Flash Drive to FAT32

This process will erase all data on the flash drive. It is highly recommended to back up the contents of your Flash Drive before following these steps.

  • Connect your Flash Drive to your Windows Host Machine
  • Hit the windows key, type "Disk Management" and then hit Enter.
  • Right click your flash drive and select "Format"

  • Select FAT32 under File System and then press OK.

  • Now right click the device in File Explorer and select Eject to safely disconnect the device from your Host Machine.
  • To verify the mount point of your Flash device using the following command: 

    Target (Linux)

    mount
    CODE

    Pro Tip! Try using this command once before and after connecting the Flash Drive to your hardware. This will make it easy to notice which one is the new one and where it is mounted.

  • Insert a USB storage device into the USB Type-A connector. The mount point should be sda1 in the directory /run/media/ and this can be confirmed in the printed messages output to the console when the device is registered.
  • Generate a random 100 MB file to test writing to and from the storage device. 

    Target (Linux)

    dd if=/dev/urandom of=test1.file count=100 bs=1M
    CODE
  • Copy the file to your storage device:

    Target (Linux)

    cp test1.file /run/media/sda1/ && sync
    CODE
  •  Copy the file back to the root file system: 

    Target (Linux)

    cp /run/media/sda1/test1.file test2.file && sync
    CODE
  • To check that the read file is the same as the one that was written, you can use md5sum to compare and verify the data transfer was successful: 

    Target (Linux)

    md5sum test1.file && md5sum test2.file
    CODE

    The above command will generate a long and seemingly random string of characters for both files. This long string is called a "hash" and it uniquely identifies the files. If the hash for both files match then you can be confident that both files (down to each bit) are identical. 

    Expected Output

    root@imx7d-phyboard-zeta-004:~# md5sum test1.file && md5sum test2.file
    81ad66df7f773128aef1ec7966180ebf  test1.file
    81ad66df7f773128aef1ec7966180ebf  test2.file
    CODE

Removing storage devices

  • Ensure that peripheral devices are unmounted properly before disconnecting to avoid data corruption. Enter the following before disconnecting the storage device. 

    Target (Linux)

    umount /dev/sda1
    CODE

 Using an SD Card

In order to make the microSD connector available you will have to first boot from eMMC.

When an external SD Card is inserted, it will be mounted automatically and will also be available as /dev/mmcblk0 in Linux when booting from eMMC.

Write to the SD Card

You can use basic Linux commands to create and write files to the SD card. Below is an example:

Target (Linux)

echo "Hello World" > ~/test.txt
cp ~/test.txt /run/media/mmcblk0p1
CODE

Read from the SD Card

To read what was just written to the SD card in the previous example, use the following command:

Target (Linux)

cp /run/media/mmcblk0p1/test.txt ~/read.txt
CODE

To check that the file read (read.txt) is the same that was written (test.txt) you can use md5sum to compare and verify the data transfer was successful:

Target (Linux)

md5sum ~/test.txt && md5sum ~/read.txt
CODE

The above command will generate a long and seemingly random string of characters for both files. This long string is called a "hash" and it uniquely identifies the files. If the hash for both files match then you can be confident that both files (down to each bit) are identical. 

Unmount the SD Card

Before unplugging the device from the development kit, make sure to unmount it. You can do this by running the following command:

Target (Linux)

umount /run/media/mmcblk0p*
CODE

Using the Network:

 Using the Secure Copy Protocol (SCP)

SCP is built around a Secure Shell connection (SSH) and offers all the same security features. One advantage of using this method for transferring single files is that it is generally pretty fast but you won't get interactive functionality when pulling multiple files from a remote server. For example, you won't be able to list out directory contents and see what other files are available. SCP also has no file size limitations.

Before being able to transfer files using the SCP protocol, you will first need to establish a network connection and know the ip address of the target device. See the Ethernet Peripheral Guide

Ubuntu Host Machine

  • Using the Terminal on your host machine, navigate to the directory containing the file you wish to transfer to the target device. 

    Host

    cd <insert-path-to-files>
    CODE
  • Use the following command to transfer your file:

    Host

    sudo scp <insert-name-of-file> root@<insert-IP-address>:~
    CODE
  • Your copied file will appear in the root directory on the target device.

  • To go the other direction, transferring files from the Target Hardware to the Host, just flip the source and destination arguments: 

    Host

    sudo scp root@<insert-IP-address>:<insert-name-of-file> <insert-path-to-destination>
    CODE

Windows Host Machine

In order to use the SCP protocol you will first need the PSCP command line utility (which is not a standard internal command). 

  • Use this link to download the most recent, stable version of pscp.exe (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).
  • Move pscp.exe to your Programs Folder and setup a PATH variable for ease of use.
  • Using the Command Prompt on your host machine, navigate to the directory containing the file you wish to transfer to the target device. 

    Host

    dir <insert-path-to-files>
    CODE
  • Use the following command to transfer your file: 

    Host

    pscp -scp <insert-name-of-file> root@<insert-IP-address>:~
    CODE
  • Your copied file will appear in the root directory on the target device.

  • To go the other direction, transferring files from the Target Hardware to the Host, just flip the source and destination arguments:  

    Host

    pscp -scp root@<insert-IP-address>:<insert-name-of-file> <insert-path-to-destination>
    CODE
 Using the Trivial File Transfer Protocol (TFTP)

TFTP can be used for transferring files to and from your Host Machine and Target Hardware very quickly. While it is very fast, it is a NON-SECURE way of transferring files as it doesn't use any kind of encryption. You should only use this method of transferring files when working on your Local Area Network.

Before being able to transfer files using TFTP, you will first need to establish a network connection with your Target Hardware. See the Ethernet Peripheral Guide

Setup the TFTP Server:

Install the TFTP server on your Host PC:

Host (Ubuntu)

sudo apt-get update
sudo apt-get install tftpd-hpa
CODE

Using your favorite text editor (the following command will use gedit), open the TFTP configuration file. Specify a folder where the files will reside on your Host PC by replacing the folder path for ''TFTP_DIRECTORY'' with whatever folder you wish to use as your TFTP file storage location, or leave the folder as the default.

Host (Ubuntu)

sudo gedit /etc/default/tftpd-hpa
CODE

/etc/default/tftpd-hpa (Default Content)

# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure --create"
CODE

Remember to save any changes you made.

  • If you made any changes to the settings of the TFTP server, you need to restart it for them to take effect.

    Host (Ubuntu)

    sudo systemctl restart tftpd-hpa
    CODE

If you would like to grant every user on the system permission to place files in the TFTP directory, use the following command (you will have to specify your storage location if you changed the default location):

Host (Ubuntu)

sudo chmod ugo+rwx /var/lib/tftpboot
CODE

Configure your firewall to allow TFTP connections (these occur via UDP on port 69 by default):

Host (Ubuntu)

firewall-cmd --add-port=69/udp
CODE

If you get an error about firewall-cmd being an unrecognized command then we will have to install it before running the above step. SKIP THIS if you didn't have trouble running that last step: 

Host (Ubuntu)

sudo apt-get update
sudo apt-get install firewalld
CODE

The final step for the TFTP Server setup is simply knowing the server's IPv4 address. You can find this using this command:

Host (Ubuntu)

ifconfig
CODE

For the sake of testing, lets throw a test file into the server we just setup to practice retrieving it:

Host (Ubuntu)

echo "test" > /var/lib/tftpboot/testS.txt
CODE

Setup the TFTP Client

With your target hardware connected to the same network as your Host Machine, enter the following command to retrieve the test file we created on the server. You will need to replace the Xs with the IPv4 address of the server we found earlier:

Target (Linux)

tftp -gr testS.txt XXX.XXX.XXX.XXX:69
CODE

In order to move files in the opposite direction, from the Target Hardware to the Host Machine, we just need to change the "get" option to a "put" and then specify the file we are moving:

Target (Linux)

echo "test" > testC.txt
tftp -pr testC.txt XXX.XXX.XXX.XXX:69
CODE
 Using a Network Filesystem Server

A Network Filesystem Server (NFS) gives other systems the ability to mount a filesystem stored on the Host PC which is exported over the network. Setting up an NFS server on your Linux Host PC gives you access to the target boards root filesystem which will allow you to quickly test applications and evaluate different filesystem setups for the target board.

Before being able to transfer files using NFS, you will first need to establish a network connection and know the ip address of the target device. See the Ethernet Peripheral Guide

Setup the NFS Server (Host Machine)

  • On your Host Machine, create a directory to use as the filesystem on the NFS Server and ensure it is accessible:

    Host (Ubuntu)

    sudo mkdir -p /mnt/testNFS
    sudo chown nobody:nogroup /mnt/testNFS
    sudo chown 777 /mnt/share
    CODE

  • Run the following to update/install NFS packages on your Ubuntu host Machine: 

    Host (Ubuntu)

    sudo apt-get update
    sudo apt install nfs-kernel-server
    CODE

  • Using your favorite text editor, open the file configuring exported filesystems. Use the following command to do this using the Vim Text Editor: 

    Host (Ubuntu)

    sudo vim /etc/exports
    CODE

  • Add the following line to the end of the file (replace Xs with your i.MX7's IP address and network mask in the command using this format, <ip address>/<net mask>): 

    Added Line in /etc/exports

    /mnt/testNFS XXX.XXX.XXX.XXX/XXX.XXX.XXX.XXX(rw,sync,no_root_squash,no_subtree_check)
    CODE

  • Save the file.
  • Export the NFS Server: 

    Host (Ubuntu)

    sudo exportfs -va
    CODE

  • Modify your firewall to allow your i.MX7 to mount the NFS Server's filesystem: 

    Host (Ubuntu)

    firewall-cmd --add-port=2049/tcp
    CODE

  • Restart your NFS Server: 

    Host (Ubuntu)

    sudo systemctl restart nfs-kernel-server
    CODE

Setup the NFS Client

  • Create a directory to mount the NFS Server's filesystem to: 

    Target (Linux)

    mkdir ~/testNFS
    CODE

  • Mount the NFS Server (replace <host ip address> with the ip address of your Host Machine you set the NFS server on): 

    Target (Linux)

    sudo mount -t nfs <host ip address>:/mnt/testNFS ~/testNFS/
    CODE

Now try adding a file to the directory the server is mounted on (in this case /mnt/testNFS on the Host Machine and ~/testNFS on the Target). You should see the file appear on both machines in their respective NFS locations.