Copying Files to the Device
There are several ways of transferring files to and from your target device. Please reference the following for some possible methods.
Using a Network
Note
Before being able to transfer files using network protocols, you will first need to establish a network connection and know the ip address of the target device. See the Ethernet interface guide for more information.
Secure Copy Protocol
Secure Copy Protocol (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.
Note
The following SCP section can be done in a Linux machine (Ubuntu) or in Windows via command prompt. Window’s command prompt can be access easily by hitting the Window’s key and typing “cmd” + Enter.
Using the terminal on your host machine, navigate to the directory containing the file you wish to transfer to the target device.
cd <insert-path-to-files>
Use the following command to transfer your file:
sudo scp <insert-name-of-file> root@<insert-IP-address>:~
Your copied file will appear in the root directory on the target device.
To go the other direction and retrieve files from the target device, just flip the source and destination arguments:
sudo scp root@<insert-IP-address>:<insert-name-of-file> <insert-path-to-destination>
Trivial File Transfer Protocol
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.
Setup the TFTP Server
Install TFTP server functionality on your Host PC:
sudo apt-get update sudo apt-get install tftpd-hpa
Using your favorite text editor (the following command will use vim), open the TFTP configuration file. Here you can specify a folder (this will behave as the file server) 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.
sudo vim /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/var/lib/tftpboot" TFTP_ADDRESS=":69" TFTP_OPTIONS="--secure --create"
Remember to save any changes you may have made.
If you made any changes to the settings of the TFTP server, you need to restart it for them to take effect.
sudo systemctl restart tftpd-hpa
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):
sudo chmod ugo+rwx /var/lib/tftpboot
Configure your firewall to allow TFTP connections (these occur via UDP on port 69 by default):
firewall-cmd --add-port=69/udp
Note
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:
sudo apt-get update sudo apt-get install firewalld
For the sake of testing, lets throw a test file into the server we just setup to practice retrieving it:
echo "test" > /var/lib/tftpboot/testS.txt
The final step for the TFTP Server setup is simply knowing the server’s IPv4 address. You can find this using this command:
ifconfig
TFTP Client Setup
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:
tftp -gr testS.txt XXX.XXX.XXX.XXX:69
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:
echo "test" > testC.txt tftp -pr testC.txt XXX.XXX.XXX.XXX:69
Network Filesystem Server
A Network Filesystem Server (NFS) gives other systems the ability to mount a filesystem stored on a Host PC which is exported over the network. Aside from the initial setup, this is the easiest way to transfer files back and forth between systems and PHYTEC recommends using the strategy during application development.
NFS Server Setup
On your Host Machine, create a directory to use as the filesystem on the NFS Server and ensure it is accessible:
sudo mkdir -p /mnt/testNFS sudo chown nobody:nogroup /mnt/testNFS sudo chmod 777 /mnt/testNFS
Run the following to update/install NFS packages on your Ubuntu host Machine:
sudo apt-get update sudo apt install nfs-kernel-server
Using your favorite text editor, open the file configuring exported filesystems. Use the following command to do this using the Vim Text Editor:
sudo vim /etc/exports
Add the following line to the end of the file (replace Xs with your AM57x’s IP address and network mask in the command using this format, <ip address>/<net mask>):
/mnt/testNFS XXX.XXX.XXX.XXX/XXX.XXX.XXX.XXX(rw,sync,no_root_squash,no_subtree_check)
Save and close the file.
Export the NFS Server:
sudo exportfs -va
Modify your firewall to allow your AM57x to mount the NFS Server’s filesystem:
firewall-cmd --add-port=2049/tcp
Restart your NFS Server:
sudo systemctl restart nfs-kernel-server
NFS Client Setup
Create a directory to mount the NFS Server’s filesystem to:
mkdir ~/testNFS
Mount the NFS Server (replace <host ip address> with the ip address of your Host Machine you set the NFS server on):
mount -t nfs <host ip address>:/mnt/testNFS ~/testNFS/
Now check out the contents of the mounted NFS server. The file we placed there previously should already be there:
ls ~/testNFS/
You should find that when you add a file to this NFS directory (from either the side of the Server of the Client) that it appears automatically wherever the NFS server is mounted.
Using Removable Storage Devices
USB Storage Device
These instructions walkthrough exercising the USB Host interface on the development kit, but since your Ubuntu Host Machine is also a Linux system, you can similarly transfer files to the same storage media to exchange files.
What You Will Need
Verifying USB Interface
With the phyCORE-AM57x development kit booted into Linux, verify that there are 4 USB devices.
lsusb
root@phycore-am57xx-1:~# lsusb Bus 004 Device 001: ID 1d6b:0003 Bus 003 Device 001: ID 1d6b:0002 Bus 002 Device 001: ID 1d6b:0003 Bus 001 Device 001: ID 1d6b:0002
Insert a USB device into X9.
root@phycore-am57xx-1:~# [ 32.154693] usb 3-1: new high-speed USB device number 2 using xhci-hcd [ 32.336120] usb 3-1: New USB device found, idVendor=090c, idProduct=1000, bcdDevice=11.00 [ 32.344360] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 32.352355] usb 3-1: Product: USB Flash Disk [ 32.356689] usb 3-1: Manufacturer: General [ 32.360839] usb 3-1: SerialNumber: 04NO3BEZ826XRN7H [ 32.384979] usb-storage 3-1:1.0: USB Mass Storage device detected [ 32.392700] scsi host1: usb-storage 3-1:1.0 [ 32.398284] usbcore: registered new interface driver usb-storage [ 32.407379] usbcore: registered new interface driver uas [ 33.696716] scsi 1:0:0:0: Direct-Access General USB Flash Disk 1100 PQ: 0 ANSI: 4 [ 33.706268] sd 1:0:0:0: [sda] 31506432 512-byte logical blocks: (16.1 GB/15.0 GiB) [ 33.717529] sd 1:0:0:0: [sda] Write Protect is off [ 33.726043] sd 1:0:0:0: [sda] No Caching mode page found [ 33.731384] sd 1:0:0:0: [sda] Assuming drive cache: write through [ 33.808105] sda: sda1 [ 33.812774] sd 1:0:0:0: [sda] Attached SCSI removable disk [ 34.192993] cryptd: max_cpu_qlen set to 1000
Verify that the USB was properly recongnized by development kit.
lsusb
root@phycore-am57xx-1:~# lsusb Bus 004 Device 001: ID 1d6b:0003 Bus 003 Device 002: ID 090c:1000 General USB Flash Disk Bus 003 Device 001: ID 1d6b:0002 Bus 002 Device 001: ID 1d6b:0003 Bus 001 Device 001: ID 1d6b:0002
Mounting USB Storage Devices
Make a directory for mounting the USB device.
mkdir ~/usb_sda
Format file type.
mkfs.vfat /dev/sda
Mount the USB device to the directory.
mount /dev/sda ~/usb_sda/
See what media is on the USB drive.
ls ~/usb_sda/
Write to the USB Host Device
Generate a random 10 MB file to test transferring data from the storage device.
dd if=/dev/urandom of=test.file count=10 bs=1M
Copy the file to your storage device.
cp test.file ~/usb_sda/ && sync
Verify that the file wasn’t corrupted with md5sum. Both the hashes should match.
md5sum test.file ~/usb_sda/test.fileroot@phycore-am57xx-1:~# md5sum test.file ~/usb_sda/test.file ad3de54f2681aa83e87d80a9acaa4d16 test.file ad3de54f2681aa83e87d80a9acaa4d16 /root/usb_sda/test.file
Read from the USB Host Device
Copy the test file we previously created during the write process back to the host:
cp ~/usb_sda/test.file readback-usb.file && sync
We can double check that the file was successfully copied to and from the USB device by checking the md5sum of the file:
md5sum test.file readback-usb.file
root@phycore-am57xx-1:~# md5sum test.file readback-usb.file ad3de54f2681aa83e87d80a9acaa4d16 test.file ad3de54f2681aa83e87d80a9acaa4d16 readback-usb.file
Unmounting the Drive
Warning
Make sure the drive is unmounted prior to physically disconnecting the device. Failure to do so may result in loss of data and corruption of files
umount ~/usb_sda/
umount /dev/sda
SD Card (Root Partition)
Since our Host Machines have access to the SD Card readers, we can use the bootable SD Card itself to transfer files to and from the development kit too, the only down side for this is that you will need to power off the development kit before removing the primary boot media.
Power off the development kit.
poweroff
Remove the SD card and connect it to your Linux machine via an SD card reader.
Note
You will not be able to place files on the SD card using Windows because the SD Card’s rootfs partition is formatted for Linux. Windows does not recognize the format the ext4 format used.
The SD Card is formatted with a minimal root filesystem size by default and in order to transfer larger files it may become necessary to increase its size to take advantage of the full size of the SD Card.
Increase the root filesystem partition of the SD card.
Run the following command without the SD card connected to the host machine.
ls /dev/sd*
Connect the bootable SD card to your Ubuntu host machine.
Run the following command with the SD card connected to the host machine.
The SD card device name is of the form /dev/sd[a-z] in Ubuntu and the letter identifier along with any partitions (signified by the numbers following the letter) on the SD card are enumerated upon connection to the host machine. Look at the second output of the command and look for new devices that appeared there, the new device will correspond to the SD card. Remember the /dev/sdX identifier corresponding to your SD card as you will need to use this in the following step.
ls /dev/sd*
Be confident you have the correct */dev/sdX* device identified for your SD card before proceeding. Specifying the incorrect disk using the ‘fdisk’ utility in the steps below can potentially destroy your Virtual Machine and will require you to set it back up again from scratch.
It is best to first backup the SD card to a file just in case something goes terribly wrong and you end up losing its contents:
umount /dev/sdX* #unmount the entire SD Card, not just any single partition sudo dd if=/dev/sdX of=~/backup.sdcard bs=1M conv=fsync && sync
Use the fdisk utility and provided command sequence to create a new, larger root filesystem partition in the SD card’s partition table:
sudo fdisk /dev/sdX # fdisk is an interactive utility, use the following command sequence # p (print the partition table and note the starting sector of the 2nd partition, call this START2. START2=196608 using the pre-built software) # d (delete a partition) # 2 (select the root filesystem) # n (create a new partition) # p (make it a primary partition) # 2 (make it the second partition) # START2 (specify the same starting sector for the 2nd partition as before) # ENTER (just hit ENTER to use the default size, which will automatically use up the remaining space on the SD Card) # w (write the changes)
Disconnect and reconnect the SD card from the host machine at this point to ensure the new partition table is being picked up by the kernel.
Finally, grow the root filesystem to take up the entire space in the partition:
sudo resize2fs /dev/sdX2
Drag and drop the file to the rootfs partition of the SD card using the GUI.
In order to copy files to the SD card using the terminal, this can be done with the standard ‘cp’ (copy) command.
The next time you boot your phyCORE-AM57x into Linux, using the same SD Card, your file should be present in the filesystem.