#!/bin/bash # EXERCISE THE USB PORTS and eMMC partition # -> Script usage: # Ex. ./usb_emmc_test.sh sda1, ./usb_emmc_test.sh sdb1, ./usb_emmc_test.sh sdc1 or ./usb_emmc_test.sh mmcblk0p4 # Note: The script assumes all the USB ports have USB flash drives connected during testing # make file system as Read-Write file system #mount -o remount,rw / # Check to see if particular USB/eMMC partition exist (sda1,sdb1,sdc1 or mmcblk0p4) PART_EXIST=$(cat /proc/partitions | grep -w $1) # Check to see if particular USB partition exist # Check to see if USB0_DRVBUS and USB1_DRVBUS ststus is High if [[ ("$PART_EXIST" != "") && ("$(devmem 0x47401018 | grep -w '0x00000001')" != "") && ("$(devmem 0x47401818 | grep -w '0x00000001')" != "") ]]; then # Check if mount directory is created under /mnt # Create mount directory under /mnt if not present/created if [ ! -e /mnt/$1 ] ; then mkdir /mnt/$1 fi # Check if partition is mounted # If partition is not mounted, then try to mount the partition # Exit script in case of failure to mount partition if ! mountpoint -q /mnt/$1/ ; then if ! mount /dev/$1 /mnt/$1/ ; then exit 1 fi fi # Check if file exists on mounted partition, if not then copy file # Copy test file to mounted partition, and force changed blocks to disk using 'sync' command # Exit script in case of failure to copy file if [ ! -e /mnt/$1/testFileCopy.bin ] ; then echo "Copy File" if ! dd if=./testFile.bin of=/mnt/$1/testFileCopy.bin ; then exit 1 else sync fi else echo "File Exists" fi # Compare original and copied file, if files are not identical exit script # first, make sure the file system cache is cleared, so that we actually read from the flash disk under test echo 3 > /proc/sys/vm/drop_caches if ! diff -s ./testFile.bin /mnt/$1/testFileCopy.bin ; then exit 1 fi # delete copied file from mounted partition, exit script if file delete fails # if ! rm -rf /mnt/$1/testFileCopy.bin ; then # exit 1 # fi else # re-initialize the USB peripheral # re-initializing USB0 as well as USB1, id DRVBUS status is observed to be LOW or any of the USB block partitions are missing # unmount already mounted USB flash drivs, so that after USB reset we get same partion numbers umount /mnt/sda1/ umount /mnt/sdb1/ umount /mnt/sdc1/ #USB0 echo 0 > /sys/kernel/debug/musb-hdrc.0/softconnect usleep 100 echo 1 > /sys/kernel/debug/musb-hdrc.0/softconnect #USB1 echo 0 > /sys/kernel/debug/musb-hdrc.1/softconnect usleep 100 echo 1 > /sys/kernel/debug/musb-hdrc.1/softconnect exit 1 fi sleep 1