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.

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

    Host (Ubuntu)
    cd <insert-path-to-files>
    
  • Use the following command to transfer your file:

    Host (Ubuntu)
    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 Hardware, just flip the source and destination arguments:

    Host (Ubuntu)
    sudo scp root@<insert-IP-address>:<insert-name-of-file> <insert-path-to-destination>
    

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 for long term development.

Host Setup

  • 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 chmod 777 /mnt/testNFS
    
  • 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
    
  • 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
    
  • Add the following line to the end of the file (replace Xs with your phyCORE-AM62Ax’s IP address):

    Host (Ubuntu)
    /mnt/testNFS XXX.XXX.XXX.XXX(rw,sync,no_root_squash,no_subtree_check)
    
  • Save and close the file.

  • Export the NFS Server:

    Host (Ubuntu)
    sudo exportfs -ra
    
  • Modify your firewall to allow your phyCORE-AM62Ax to mount the NFS Server’s filesystem:

    Host (Ubunutu)
    firewall-cmd --add-port=2049/tcp
    
  • Restart your NFS Server:

    Host (Ubunutu)
    sudo systemctl restart nfs-kernel-server
    
  • Now, you can add files to /mnt/testNFS to make them available to any clients that mount this NFS server.

Client Setup

Now that the Host Machine is setup as a NFS server, it is time to configure the phyCORE-AM62Ax as the client.

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

    Target (Linux)
    mkdir ~/testNFS
    
  • Mount the NFS Server (replace <host ip address> with the ip address of your Host Machine you set the NFS server on):

    Target (Linux)
    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:

    Target (Linux)
    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-AM62Ax development kit booted into Linux, verify that there are 3 USB devices. There should be 2 devices on bus 001.

    Target (Linux)
    lsusb
    
    Expected Output
    root@phyboard-lyra-am62axx-1:~# lsusb
    Bus 001 Device 002: ID 0424:2514
    Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.33-bsp-yocto-ampliphy-am62ax-pd23.1.0 xhci-hcd xHCI Host Controller
    
  • Insert a USB device into either x43 (Double stack USB-A port) or x34 (USB-C). This guide demonstrates the USB-A bottom port.

    Expected Output
    root@phyboard-lyra-am62axx-1:~# [ 1103.995685] usb 1-1.2: new high-speed USB device number 3 using xhci-hcd
    [ 1104.101203] usb 1-1.2: New USB device found, idVendor=0781, idProduct=5591, bcdDevice= 1.00
    [ 1104.109724] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [ 1104.117146] usb 1-1.2: Product:  SanDisk 3.2Gen1
    [ 1104.121870] usb 1-1.2: Manufacturer:  USB
    [ 1104.125981] usb 1-1.2: SerialNumber: 0401b360e7f994fa1045253b46381e7f4adf9e70e08383c7595d67e9a36da3592f6c0000000000000000000000c41f01009e5d18915581076e2cc63b
    [ 1104.197541] usb-storage 1-1.2:1.0: USB Mass Storage device detected
    [ 1104.204385] scsi host0: usb-storage 1-1.2:1.0
    [ 1104.209411] usbcore: registered new interface driver usb-storage
    [ 1105.232338] scsi 0:0:0:0: Direct-Access      USB      SanDisk 3.2Gen1 1.00 PQ: 0 ANSI: 6
    [ 1105.242820] sd 0:0:0:0: [sda] 30031872 512-byte logical blocks: (15.4 GB/14.3 GiB)
    [ 1105.251756] sd 0:0:0:0: [sda] Write Protect is off
    [ 1105.257122] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
    [ 1105.274728] sd 0:0:0:0: [sda] Attached SCSI removable disk
    
  • Verifiy that the USB was properly recongnized by development kit.

    Target (Linux)
    lsusb
    
    Expected Output
    root@phyboard-lyra-am62axx-1:~# lsusb
    Bus 001 Device 003: ID 0781:5591  USB  SanDisk 3.2Gen1
    Bus 001 Device 002: ID 0424:2514
    Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.33-bsp-yocto-ampliphy-am62ax-pd23.1.0 xhci-hcd xHCI Host Controller
    
  • To list more information about the USB device and buses on the development kit use the following command.

    Target (Linux)
    lsusb -v -s 001:003
    

    Note

    “001” refers to bus 001 and “003” refers to the device number, both of these can be found in the lsusb command.

Mounting USB Stroage Devices

  • Make a directory for mounting the USB device.

    Target (Linux)
     mkdir ~/usb_sda
    
  • Mount the USB device to the directory.

    Target (Linux)
    mount /dev/sda ~/usb_sda/
    

    Note

    In this example the device name for the USB drive is “sda”. The device name can be found when plugging the USB drive into the development kit.

  • See what media is on the USB drive.

    Target (Linux)
     ls ~/usb_sda/
    

Write to the USB Host Device

  • Generate a random 10 MB file to test transferring data from the storage device.

    Target (Linux)
    dd if=/dev/urandom of=test.file count=10 bs=1M
    
  • Copy the file to your storage device.

    Target (Linux)
     cp test.file ~/usb_sda/ && sync
    

Read from the USB Host Device

  • Copy the test file we previously created during the write process back to the host:

    Target (Linux)
    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:

    Target (Linux)
    md5sum test.file readback-usb.file
    
    Expected Output
    root@phyboard-lyra-am62axx-1:~# md5sum test.file readback-usb.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  test.file
    d3aa3ee1db746d6f7fb66c9b42f4ea6b  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

Target (Linux)
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 want to power off the development kit before removing the primary booting device.

  • Power off the development kit.

    Target (Linux)
    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 is formatted for Linux. Windows does not recognize the format.

    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.

    1. Run the following command without the SD card connected to the host machine.

      Host (Ubuntu)
      ls /dev/sd*
      
    2. Connect the bootable SD card to your Ubuntu host machine.

    3. Run the following command with the SD card connected to the host machine.

      Host (Ubuntu)
      ls /dev/sd*
      

      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.

    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.

    1. 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:

      Host (Ubuntu)
      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
      
    2. Use the fdisk utility and provided command sequence to create a new, larger root filesystem partition in the SD card’s partition table:

      Host (Ubuntu)
      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)
      
    3. 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.

    4. Finally, grow the root filesystem to take up the entire space in the partition:

      Host (Ubuntu)
      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. See the above section “Transfering Media from Target” for more information.

  • The next time you boot your phyCORE-AM62Ax into Linux, using the same SD Card, your file should be present in the filesystem.