SD Card

The SD card interface can be used as a boot device or plug-and-play external media. This guide will walk through reading and writing to the phyCORE-AM57x development kit’s SD card. For information on how to boot the development kit from SD card see the guide SD Card. More information on the SD card, please section 7 in the Hardware Manual.

Note

In order to make use of the SD card slot on the carrier board as a removable data storage device, your kit must first be booting from eMMC to make this slot available. See the eMMC guide.

Requirements

  • SDHC SD card, at least 4GB (Included in development kit)

  • SD card reader (operational under Linux) (Only for Transfering Media from Host)

  • Bootable eMMC

    • See the eMMC guide on how to boot from eMMC.

Transfering Media on Target

This portion of the guide will show how to read and write files with the SD card interface from the development kit.

Mounting the SD Card

  • Create a temporary directory to mount your desired SD card partition:

    Target (Linux)
    mkdir ~/temp
    
  • Mount the partition. You will need to create new directories if you want to mount more than one partition on the card to the system.

    Target (Linux)
    mount /dev/mmcblk0p1 ~/temp
    

Note

eMMC uses the partition /dev/mmcblk1*. While the SD card uses /dev/mmcblk0*.

  • See the contents of the SD card.

    Target (Linux)
    ls ~/temp
    

Write to the SD Card

  • Create a text file and copy (cp) the file to the SD card.

    Target (Linux)
    echo "SD card Test" > sdcard.txt
    cp sdcard.txt temp/sdcard.txt
    
  • Verify that the file wasn’t corrupted with md5sum. Both the hashes should match.

    Target (Linux)
    md5sum sdcard.txt temp/sdcard.txt
    
    Expected Output
    root@phycore-am57xx-1:~# md5sum sdcard.txt temp/sdcard.txt
    01c82790018de260b8f61b370b889931  sdcard.txt
    01c82790018de260b8f61b370b889931  temp/sdcard.txt
    

Read from the SD Card

  • Copy the file from the SD card to the root directory

    Target (Linux)
    cp temp/sdcard.txt ~/read-sd.txt
    
  • Verify that the file wasn’t corrupted with md5sum. Both the hashes should match.

    Target (Linux)
    md5sum temp/sdcard.txt read-sd.txt
    
    Expected Output
    root@phycore-am57xx-1:~# md5sum temp/sdcard.txt  ~/read-sd.txt
    01c82790018de260b8f61b370b889931  temp/sdcard.txt
    01c82790018de260b8f61b370b889931  /root/read-sd.txt
    

Unmounting the SD Card

  • Make sure you umount the SD card before unplugging the device from the kit.

    Target (Linux)
    umount ~/temp
    

Seeing SD card media on Host

Linux Host Machine

  • Power off and remove the power supply from the development kit.

    Target (Linux)
    poweroff
    
  • Insert the SD card into the reader which is connected to your Linux Host machine.

  • Two USB partitions should appear. Double click both.

  • One of these should be the root filesystem which will be labeled ‘/boot’

  • In the ‘/boot’ parition you should see the file sdcard.txt

    ../_images/pb-057948_sd-media-linux-drives.png ../_images/pb-057948_sd-media-linux.png

Windows Host Machine

  • Power off and remove the power supply from the development kit.

    Target (Linux)
    poweroff
    
  • Insert the SD card into the reader which is connected to your Host machine.

  • A File Explorer window should appear on your screen showing the SD card boot parition contents.

    ../_images/pb-057948_sd-media-windows.png

Transfering Media from Host

Media can be transferred to the boot parition from either a Windows or Linux Host machine. This is possible due to this partition being formatted as a vfat. The root filesystem (/root) can only be access in a Linux Host machine as it is formatted as a ext4.

Linux Host Machine

  • Power off and remove the power supply from the development kit.

    Target (Linux)
    poweroff
    
  • Insert the SD card into the reader which is connected to your Linux Host machine.

  • Two USB partitions should appear. Double click both.

  • Move or copy media to either partition. This example is transferring files to the root filesystem.

    While it is possible to drag and drop files into the partitions, it is suggested to move files via terminal commands to avoid file corruption.

    Host (Linux)
    cp <path to files you want to transfer> /media/<user>/root/ && sync
    
  • Close partition windows and eject SD card.

  • Insert the SD card back into powered off the development kit.

  • Supply power and boot up kit.

  • Mount the partition. You will need to create new directories if you want to mount more than one partition on the card to the system.

    Target (Linux)
    mount /dev/mmcblk0p1 ~/temp
    
  • After the SD card is mounted you can navigate through the directories just like you normally would in Linux. Verify that the transferred files are present.

    Target (Linux)
    ls ~/temp
    

Windows Host Machine

  • Power off and remove the power supply from the development kit.

    Target (Linux)
    poweroff
    
  • Insert the SD card into the reader which is connected to your Host machine.

  • A File Explorer window should appear on your screen showing the SD card boot parition.

  • While it is possible to drag and drop files into the partitions, it is suggested to move files via Windows Command Prompt Terminal tool to avoid file corruption.

    Note

    Access the Windows Command Prompt Tool by typing “cmd” into the Windows search bar.

Host (Windows)
copy <path to files you want to transfer> <path to boot partition>

Increasing the Root Filesystem

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. A Linux Host machine is necessary for this action.

  • 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.

    4. 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
      
    5. 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)
      
    6. 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.

    7. 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-AM57x into Linux, using the same SD Card, your file should be present in the filesystem.