#!/bin/bash

# A simple script to gather state-dump information for mmc parts.  Data will
# be gathered for any device matching the pattern /dev/mmcblk?.

function dump_emmc() {
    for mmcdev in /dev/mmcblk? ; do
        local a
        # subtract the /dev/ string from the start of the input string
        local mmc_name="${mmcdev#/dev}"

        for a in type manfid oemid name prv serial date fwrev cid csd ocr dsr ; do
            local attr="/sys/block/${mmc_name}/device/${a}"
            echo "${attr}"
            cat "${attr}" || return
        done

        echo
        echo /ciena/bin/emmcutil -VlBEbI $mmcdev
        /ciena/bin/emmcutil -VlBEbI $mmcdev || return
    done
}

delay="5"

dump_emmc || {
    echo "mmc is busy. Retrying in ${delay} seconds"
    sleep ${delay}
    dump_emmc || echo "** Failed to get mmc data"
}

if [ -e "/tmp/mmc_refresh_scan.dat" ] ; then
    echo
    echo "mmc_refresh_scan last lba:"
    cat "/tmp/mmc_refresh_scan.dat"
fi
