This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM5728: Issue Running Industrial Ethernet/IP Demo Application

Part Number: AM5728

Tool/software: TI-RTOS

I am trying to get the Industrial Ethernet/IP demo working on the AM5728IDK, but I have run into several issues during this process. When I ran the EIP app out of the box (by following the instructions here: http://processors.wiki.ti.com/index.php/Industrial_Protocol_Package_Getting_Started_Guide#Building_and_Running_Sample_Application), the app tried to read the Ethernet configs from SPI Flash, but instead it just got back all 1's (garbage). I assumed that I was missing a step and I should have somehow programmed the SPI Flash with correct config values, although I am unsure what those should be and how to do that. In an effort to get something working quickly, I set the configurations in code, like IP address (forced DHCP), subnet mask, gateway, ACD, etc. This appeared to work because I was able to get a valid IP address, which confirmed that DHCP was working. I was also able to ping the port and when I opened up the Molex EIP Scanner Windows app, I could see that the TI/Molex Ethernet adapter showed up in the app. At this point I assumed all was well, but when I went to read some of the attributes using the EIP Scanner tool, I kept getting a timeout error on the scanner side. I further confirmed this using wireshark. The only form of a response that I saw from the adapter was an ACK whenever I sent a TCP message. There was no response when using UDP.

I did a lot of troubleshooting with break points and print statements through the entire EIP initialization process. Through this I discovered that the issue appears to occur in eip_main.c > EIPAPP_main() > EIPAPP_init() > EIPAPP_initSample() > EIP_Online(pstEipOnline). This returns "false" just before printing the app menu. Consequently, the EIPAPP_initSample() returns "false" and EIPAPP_init() function returns "-1". The return value is not caught in EIPAPP_main(), and as a result, the program continues on like everything is normal. It eventually hangs in IO_SetModeRun() and never gets past this point. Unfortunately, both EIP_Online() and IO_SetModeRun() appear to be closed-source, pre-compiled functions with just header files available, so we cannot troubleshoot the source code of these functions. I have reached out to TMG yesterday who I was referred to by Molex and is now maintaining the SW stack after Molex. I have not heard back from them yet, so I figured I would post here in hopes that someone else has encountered this issue as well and can help me out. I have attached a copy of the Ethernet/IP application which I have made a number of minor alterations (manually set network configs, add print statements, and comments). Please let me know if you need any more information.

3240.ethernetip_adapter.zip

  • Hi Devon, I will give a try. Please give me few days as I am catching on other activities. Quick question, Did you tried to change IP address from Out-Box-Demo console menu? I need to run it on AM57x, but at least in AM35x this works OK. Just curious, did you tried to connect PRU-ICSS EthernetIP adapter to an EthernetIP scanner? if so, how that worked?

    thank you,
    Paula
  • Hello Paula, I was able to get the pre-built binary to run (although I did have to fix a bug in the create-sdcard script). The prebuilt version works great as far as I can tell on the AM5728, and I am presented with menu where I can start/stop the EIP stack and perform other functions. I am able to connect to the adapter using the Molex EIP Scanner windows application where I can read various attributes. So it looks like this is an issue with how I am building the app from source, because the prebuilt version works just fine, but when I build from source, that is when I have issues. When I build form source, I am loading the .out file with the debugger in CCS. Perhaps there is a way for me to build the source into the same format as the pre-built binaries and load that onto an SD card with the MLO like I did with the prebuilt?

  • Hi Devon, Maybe is the combination of PRU-ICSS EthernetIP version and PSDK version you are using.. No sure, but maybe..

    Which version of PRU-ICSS EthernetIP are you trying?. If possible please try the latest which currently is PRU-ICSS EtherNet/IP Adapter 01.00.03.04

    This EIP 2.0.3.4 version works on top of TI-RTOS Processor SDK 5.1.0.11

    Using CCS and JTAG after for loading your application should work OK. But, you can also use "app" binary for running from SD card. "app" is built along with *.out, you will find it in the same location.

    By the way which issues did you find with create-sdcard script? 

    thank you,

    Paula

  • That was it! Incompatible PRU-ICSS EthernetIP and PSDK. I was using processor_sdk_rtos_am57xx_5_00_00_15. After downloading/installing processor_sdk_rtos_am57xx_5_01_00_11, reinstalling the PRU-ICSS EthernetIP Adapter package, and rebuilding the project, it is now working as expected. Thanks for the help!

    As for the create-sdcard script, the script kept erroring out because during the "Partitioning Boot" step, it tries to create and mount a partition called "mmcblk0p" which does not exist because in the previous step, all the partitions were destroyed. Instead, the script should be referencing "mmcblk0". So I commented out the "if" statement that is responsible for adding the 'p' to the end of the drive name and removed all the references to the $P variable in the subsequent lines, and that fixed the issue. I have attached both the original and my modified versions of the script for your reference.

    #!/bin/bash
    # Authors:
    #    LT Thomas <ltjr@ti.com>
    #    Chase Maupin
    #    Franklin Cooper Jr.
    #
    # create-sdcard.sh v0.3
    
    # This distribution contains contributions or derivatives under copyright
    # as follows:
    #
    # Copyright (c) 2010-2015, Texas Instruments Incorporated
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions
    # are met:
    # - Redistributions of source code must retain the above copyright notice,
    #   this list of conditions and the following disclaimer.
    # - Redistributions in binary form must reproduce the above copyright
    #   notice, this list of conditions and the following disclaimer in the
    #   documentation and/or other materials provided with the distribution.
    # - Neither the name of Texas Instruments nor the names of its
    #   contributors may be used to endorse or promote products derived
    #   from this software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
    # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    # Force locale language to be set to English. This avoids issues when doing
    # text and string processing.
    export LANG=C
    
    # Determine the absolute path to the executable
    # EXE will have the PWD removed so we can concatenate with the PWD safely
    PWD=`pwd`
    EXE=`echo $0 | sed s=$PWD==`
    EXEPATH="$PWD"/"$EXE"
    clear
    cat << EOM
    
    ################################################################################
    
    This script will create a bootable SD card from custom or pre-built binaries.
    
    The script must be run with root permissions and from the bin directory of
    the SDK
    
    Example:
     $ sudo ./create-sdcard.sh path/to/sdcard/files
    
    Formatting can be skipped if the SD card is already formatted and
    partitioned properly.
    
    ################################################################################
    
    EOM
    
    AMIROOT=`whoami | awk {'print $1'}`
    if [ "$AMIROOT" != "root" ] ; then
    
    	echo "	**** Error *** must run script with sudo"
    	echo ""
    	exit
    fi
    
    THEPWD=$EXEPATH
    
    check_for_sdcards()
    {
            # find the avaible SD cards
            ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`
            PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
            if [ "$PARTITION_TEST" = "" ]; then
    	        echo -e "Please insert a SD card to continue\n"
    	        while [ "$PARTITION_TEST" = "" ]; do
    		        read -p "Type 'y' to re-detect the SD card or 'n' to exit the script: " REPLY
    		        if [ "$REPLY" = 'n' ]; then
    		            exit 1
    		        fi
    		        ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`
    		        PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
    	        done
            fi
    }
    
    # find the avaible SD cards
    ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-9`
    if [ "$ROOTDRIVE" = "root" ]; then
        ROOTDRIVE=`readlink /dev/root | cut -c1-3`
    else
        ROOTDRIVE=`echo $ROOTDRIVE | cut -c1-3`
    fi
    
    PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
    
    # Check for available mounts
    check_for_sdcards
    
    echo -e "\nAvailable Drives to write images to: \n"
    echo "#  major   minor    size   name "
    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
    echo " "
    
    DEVICEDRIVENUMBER=
    while true;
    do
    	read -p 'Enter Device Number or 'n' to exit: ' DEVICEDRIVENUMBER
    	echo " "
            if [ "$DEVICEDRIVENUMBER" = 'n' ]; then
                    exit 1
            fi
    
            if [ "$DEVICEDRIVENUMBER" = "" ]; then
                    # Check to see if there are any changes
                    check_for_sdcards
                    echo -e "These are the Drives available to write images to:"
                    echo "#  major   minor    size   name "
                    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
                    echo " "
                   continue
            fi
    
    	DEVICEDRIVENAME=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $5}'`
    	if [ -n "$DEVICEDRIVENAME" ]
    	then
    	        DRIVE=/dev/$DEVICEDRIVENAME
    	        DEVICESIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $4}'`
    		break
    	else
    		echo -e "Invalid selection!"
                    # Check to see if there are any changes
                    check_for_sdcards
                    echo -e "These are the only Drives available to write images to: \n"
                    echo "#  major   minor    size   name "
                    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
                    echo " "
    	fi
    done
    
    echo "$DEVICEDRIVENAME was selected"
    #Check the size of disk to make sure its under 16GB
    if [ $DEVICESIZE -gt 17000000 ] ; then
    cat << EOM
    
    ################################################################################
    
    		**********WARNING**********
    
    	Selected Device is greater then 16GB
    	Continuing past this point will erase data from device
    	Double check that this is the correct SD Card
    
    ################################################################################
    
    EOM
    	ENTERCORRECTLY=0
    	while [ $ENTERCORRECTLY -ne 1 ]
    	do
    		read -p 'Would you like to continue [y/n] : ' SIZECHECK
    		echo ""
    		echo " "
    		ENTERCORRECTLY=1
    		case $SIZECHECK in
    		"y")  ;;
    		"n")  exit;;
    		*)  echo "Please enter y or n";ENTERCORRECTLY=0;;
    		esac
    		echo ""
    	done
    
    fi
    echo ""
    
    DRIVE=/dev/$DEVICEDRIVENAME
    NUM_OF_DRIVES=`df | grep -c $DEVICEDRIVENAME`
    
    # This if statement will determine if we have a mounted sdX or mmcblkX device.
    # If it is mmcblkX, then we need to set an extra char in the partition names, 'p',
    # to account for /dev/mmcblkXpY labled partitions.
    if [[ ${DEVICEDRIVENAME} =~ ^sd. ]]; then
    	echo "$DRIVE is an sdx device"
    	P=''
    else
    	echo "$DRIVE is an mmcblkx device"
    	P='p'
    fi
    
    if [ "$NUM_OF_DRIVES" != "0" ]; then
            echo "Unmounting the $DEVICEDRIVENAME drives"
            for ((c=1; c<="$NUM_OF_DRIVES"; c++ ))
            do
                    unmounted=`df | grep '\<'$DEVICEDRIVENAME$P$c'\>' | awk '{print $1}'`
                    if [ -n "$unmounted" ]
                    then
                         echo " unmounted ${DRIVE}$P$c"
                         sudo umount -f ${DRIVE}$P$c
                    fi
    
            done
            echo " unmounted ${DRIVE}$P"
            sudo umount -f ${DRIVE}$P
    else
            echo " unmounted ${DRIVE}$P"
            sudo umount -f ${DRIVE}$P
    fi
    
    # Refresh this variable as the device may not be mounted at script instantiation time
    # This will always return one more then needed
    NUM_OF_PARTS=`cat /proc/partitions | grep -v $ROOTDRIVE | grep -c $DEVICEDRIVENAME`
    for ((c=1; c<"$NUM_OF_PARTS"; c++ ))
    do
            SIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME$P$c'\>'  | awk '{print $3}'`
            echo "Current size of $DEVICEDRIVENAME$P$c $SIZE bytes"
    done
    
    #Section for partitioning the drive
    #create 1 partition
    
    cat << EOM
    
    ################################################################################
    
    		Now erasing partition table
    
    ################################################################################
    
    EOM
    dd if=/dev/zero of=$DRIVE bs=1024 count=1024
    
    
    cat << EOM
    
    ################################################################################
    
    		Partitioning Boot
    
    ################################################################################
    EOM
    	mkfs.vfat -I -F 32 -n "boot" ${DRIVE}${P}
    
    #Add directories for images
    export START_DIR=$PWD
    export PATH_TO_SDBOOT=boot
    
    echo " "
    echo "Mount the partitions "
    mkdir $PATH_TO_SDBOOT
    
    sudo mount -t vfat ${DRIVE}${P} boot/
    
    echo " "
    echo "Emptying partitions "
    echo " "
    sudo rm -rf  $PATH_TO_SDBOOT/*
    
    echo ""
    echo "Syncing...."
    echo ""
    sync
    sync
    sync
    
    cat << EOM
    ################################################################################
    
    	Copying files now... will take minutes
    
    ################################################################################
    
    Copying boot partition
    EOM
    
    echo ""
    #copy boot files out of board support
    if [ -f "$1/MLO" ] ; then
       cp -f $1/* $PATH_TO_SDBOOT/
    else
    cat << EOM
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ERROR: SD card file directory does not exist 
    ERROR: ($1)
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    EOM
    fi
    
    echo ""
    echo ""
    echo "Syncing..."
    sync
    sync
    sync
    
    echo " "
    echo "Un-mount the partitions "
    sudo umount -f $PATH_TO_SDBOOT
    
    
    echo " "
    echo "Remove created temp directories "
    sudo rm -rf $PATH_TO_SDBOOT
    
    
    echo " "
    echo "Operation Finished"
    echo " "
    
    #!/bin/bash
    # Original Authors:
    #    LT Thomas <ltjr@ti.com>
    #    Chase Maupin
    #    Franklin Cooper Jr.
    #
    # Adapted by:
    #    Devon Clark
    # create-sdcard.sh v0.4
    #
    # This distribution contains contributions or derivatives under copyright
    # as follows:
    #
    # Copyright (c) 2010-2015, Texas Instruments Incorporated
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions
    # are met:
    # - Redistributions of source code must retain the above copyright notice,
    #   this list of conditions and the following disclaimer.
    # - Redistributions in binary form must reproduce the above copyright
    #   notice, this list of conditions and the following disclaimer in the
    #   documentation and/or other materials provided with the distribution.
    # - Neither the name of Texas Instruments nor the names of its
    #   contributors may be used to endorse or promote products derived
    #   from this software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
    # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    # Change log:
    # - v0.3: Original release included in Processor SDK RTOS for AM57xx, version number 5.0.0.15
    # - v0.4: This script has been updated to fix a bug when partitioning/writing to SD cards
    
    # Force locale language to be set to English. This avoids issues when doing
    # text and string processing.
    export LANG=C
    
    # Determine the absolute path to the executable
    # EXE will have the PWD removed so we can concatenate with the PWD safely
    PWD=`pwd`
    EXE=`echo $0 | sed s=$PWD==`
    EXEPATH="$PWD"/"$EXE"
    clear
    cat << EOM
    
    ################################################################################
    
    This script will create a bootable SD card from custom or pre-built binaries.
    
    The script must be run with root permissions and from the bin directory of
    the SDK
    
    Example:
     $ sudo ./create-sdcard.sh path/to/sdcard/files
    
    NOTE: path/to/sdcard/file should be the path to the directory containing
    the files you wish to write to the SD card like the MLO and app files. 
    This is not the path to the SD card (i.e. /media/<username>/<drive label>)
    
    Formatting can be skipped if the SD card is already formatted and
    partitioned properly.
    
    ################################################################################
    
    EOM
    
    AMIROOT=`whoami | awk {'print $1'}`
    if [ "$AMIROOT" != "root" ] ; then
    
    	echo "	**** Error *** must run script with sudo"
    	echo ""
    	exit
    fi
    
    THEPWD=$EXEPATH
    
    check_for_sdcards()
    {
            # find the avaible SD cards
            ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`
            PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
            if [ "$PARTITION_TEST" = "" ]; then
    	        echo -e "Please insert a SD card to continue\n"
    	        while [ "$PARTITION_TEST" = "" ]; do
    		        read -p "Type 'y' to re-detect the SD card or 'n' to exit the script: " REPLY
    		        if [ "$REPLY" = 'n' ]; then
    		            exit 1
    		        fi
    		        ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`
    		        PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
    	        done
            fi
    }
    
    # find the avaible SD cards
    ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-9`
    if [ "$ROOTDRIVE" = "root" ]; then
        ROOTDRIVE=`readlink /dev/root | cut -c1-3`
    else
        ROOTDRIVE=`echo $ROOTDRIVE | cut -c1-3`
    fi
    
    PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
    
    # Check for available mounts
    check_for_sdcards
    
    echo -e "\nAvailable Drives to write images to: \n"
    echo "#  major   minor    size   name "
    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
    echo " "
    
    DEVICEDRIVENUMBER=
    while true;
    do
    	read -p 'Enter Device Number or 'n' to exit: ' DEVICEDRIVENUMBER
    	echo " "
            if [ "$DEVICEDRIVENUMBER" = 'n' ]; then
                    exit 1
            fi
    
            if [ "$DEVICEDRIVENUMBER" = "" ]; then
                    # Check to see if there are any changes
                    check_for_sdcards
                    echo -e "These are the Drives available to write images to:"
                    echo "#  major   minor    size   name "
                    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
                    echo " "
                   continue
            fi
    
    	DEVICEDRIVENAME=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $5}'`
    	if [ -n "$DEVICEDRIVENAME" ]
    	then
    	        DRIVE=/dev/$DEVICEDRIVENAME
    	        DEVICESIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $4}'`
    		break
    	else
    		echo -e "Invalid selection!"
                    # Check to see if there are any changes
                    check_for_sdcards
                    echo -e "These are the only Drives available to write images to: \n"
                    echo "#  major   minor    size   name "
                    cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
                    echo " "
    	fi
    done
    
    echo "$DEVICEDRIVENAME was selected"
    #Check the size of disk to make sure its under 16GB
    if [ $DEVICESIZE -gt 17000000 ] ; then
    cat << EOM
    
    ################################################################################
    
    		**********WARNING**********
    
    	Selected Device is greater then 16GB
    	Continuing past this point will erase data from device
    	Double check that this is the correct SD Card
    
    ################################################################################
    
    EOM
    	ENTERCORRECTLY=0
    	while [ $ENTERCORRECTLY -ne 1 ]
    	do
    		read -p 'Would you like to continue [y/n] : ' SIZECHECK
    		echo ""
    		echo " "
    		ENTERCORRECTLY=1
    		case $SIZECHECK in
    		"y")  ;;
    		"n")  exit;;
    		*)  echo "Please enter y or n";ENTERCORRECTLY=0;;
    		esac
    		echo ""
    	done
    
    fi
    echo ""
    
    DRIVE=/dev/$DEVICEDRIVENAME
    NUM_OF_DRIVES=`df | grep -c $DEVICEDRIVENAME`
    
    # This if statement will determine if we have a mounted sdX or mmcblkX device.
    # If it is mmcblkX, then we need to set an extra char in the partition names, 'p',
    # to account for /dev/mmcblkXpY labled partitions.
    # * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    # Block commented out by DRC because adding a "p" to 
    # the partition label causes the script to fail
    #
    #if [[ ${DEVICEDRIVENAME} =~ ^sd. ]]; then
    #	echo "$DRIVE is an sdx device"
    #	P=''
    #else
    #	echo "$DRIVE is an mmcblkx device"
    #	P='p'
    #fi
    #
    #if [ "$NUM_OF_DRIVES" != "0" ]; then
    #        echo "Unmounting the $DEVICEDRIVENAME drives"
    #        for ((c=1; c<="$NUM_OF_DRIVES"; c++ ))
    #        do
    #                unmounted=`df | grep '\<'$DEVICEDRIVENAME$P$c'\>' | awk '{print $1}'`
    #                if [ -n "$unmounted" ]
    #                then
    #                     echo " unmounted ${DRIVE}$P$c"
    #                     sudo umount -f ${DRIVE}$P$c
    #                fi
    #
    #        done
    #        echo " unmounted ${DRIVE}$P"
    #        sudo umount -f ${DRIVE}$P
    #else
    #        echo " unmounted ${DRIVE}$P"
    #        sudo umount -f ${DRIVE}$P
    #fi
    # * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    
    echo " unmounted ${DRIVE}"
    sudo umount -f ${DRIVE}
    
    # Refresh this variable as the device may not be mounted at script instantiation time
    # This will always return one more then needed
    #NUM_OF_PARTS=`cat /proc/partitions | grep -v $ROOTDRIVE | grep -c $DEVICEDRIVENAME`
    #for ((c=1; c<"$NUM_OF_PARTS"; c++ ))
    #do
    #        SIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME$P$c'\>'  | awk '{print $3}'`
    #        echo "Current size of $DEVICEDRIVENAME$P$c $SIZE bytes"
    #done
    
    SIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME'\>'  | awk '{print $3}'`
    echo "Current size of $DEVICEDRIVENAME $SIZE bytes"
    
    #Section for partitioning the drive
    
    #Section for partitioning the drive
    #create 1 partition
    
    cat << EOM
    
    ################################################################################
    
    		Now erasing partition table
    
    ################################################################################
    
    EOM
    dd if=/dev/zero of=$DRIVE bs=1024 count=1024
    
    
    cat << EOM
    
    ################################################################################
    
    		Partitioning Boot
    
    ################################################################################
    EOM
    	mkfs.vfat -I -F 32 -n "boot" ${DRIVE}
    
    #Add directories for images
    export START_DIR=$PWD
    export PATH_TO_SDBOOT=boot
    
    echo " "
    echo "Mount the partitions "
    mkdir $PATH_TO_SDBOOT
    
    sudo mount -t vfat ${DRIVE} boot/
    
    echo " "
    echo "Emptying partitions "
    echo " "
    sudo rm -rf  $PATH_TO_SDBOOT/*
    
    echo ""
    echo "Syncing...."
    echo ""
    sync
    sync
    sync
    
    cat << EOM
    ################################################################################
    
    	Copying files now... will take minutes
    
    ################################################################################
    
    Copying boot partition
    EOM
    
    echo ""
    #copy boot files out of board support
    if [ -f "$1/MLO" ] ; then
       cp -f $1/* $PATH_TO_SDBOOT/
    else
    cat << EOM
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ERROR: SD card file directory does not exist 
    ERROR: ($1
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    EOM
    fi
    
    echo ""
    echo ""
    echo "Syncing..."
    sync
    sync
    sync
    
    echo " "
    echo "Un-mount the partitions "
    sudo umount -f $PATH_TO_SDBOOT
    
    
    echo " "
    echo "Remove created temp directories "
    sudo rm -rf $PATH_TO_SDBOOT
    
    
    echo " "
    echo "Operation Finished"
    echo " "