meta-hxt: add soc update script

Add a simple script to help update the soc(host) firmware by flashcp.
Usage:
	Format: socupdate.sh FileName IP
	Example: socupdate.sh 0ACJAXXX.ROM 192.168.1.1

Change-Id: I56cdfe0f1f413448d943dc5dad71e53ae124750a
Signed-off-by: Yuan Yao <yao.yuan@hxt-semitech.com>
diff --git a/meta-stardragon4800-rep2/recipes-phosphor/socupdate/files/socupdate.sh b/meta-stardragon4800-rep2/recipes-phosphor/socupdate/files/socupdate.sh
new file mode 100644
index 0000000..640ad76
--- /dev/null
+++ b/meta-stardragon4800-rep2/recipes-phosphor/socupdate/files/socupdate.sh
@@ -0,0 +1,129 @@
+#!/bin/sh -e
+# SOC update tool, need two parameter(soc update file name and TFTP ip)
+
+if [ ! -n "$1" -o ! -n "$2" ] ;then
+    echo "Please enter SOC-ImageName and TFTP-IP."
+    echo "Format: socupdate.sh FileName IP"
+    echo "Example: socupdate.sh 0ACJAXXX.ROM 192.168.1.1"
+    exit
+fi
+
+echo "SOC update start."
+
+echo "Check BMC status."
+checkbmc='gpioutil -p Q4'
+if $checkbmc = "1"; then
+    echo "BMC is ready."
+else
+    echo "BMC isn't ready."
+    exit
+fi
+
+echo "Check SOC image does it exist."
+cd /tmp/
+FILEEXIST=0
+if [ -f "/tmp/$1" ]; then
+    GETFILE=`du -k $1 | awk '{print $1}'`
+    if [ "$GETFILE" -eq "65536" ]; then
+        FILEEXIST=1
+        echo "SOC image is exist."
+    else
+        FILEEXIST=0
+    fi
+fi
+
+if [ $FILEEXIST -eq 0 ]; then
+    echo "Get SOC image from TFTP server."
+    echo "Please wait a few minutes."
+    tftp -g -r $1 $2 &
+    sleep 2
+    LENGTH=0
+    ERRCOUNT=0
+    while true
+    do
+        echo -ne "\r["
+        usleep 500000
+        while [ $LENGTH -le 30 ]
+        do
+                usleep 500000
+                echo -n ">"
+                LENGTH=$(($LENGTH+1))
+                if [ -f "/tmp/$1" ]; then
+                    GETFILE=`du -k $1 | awk '{print $1}'`
+                    if [ $GETFILE -eq 65536 ]; then
+                        echo -en "\r"
+                        echo -en "--- Image download completed --- \n"
+                        usleep 1000000
+                        break 2
+                    fi
+                else
+                    ERRCOUNT=$(($ERRCOUNT+1))
+                    if [ $ERRCOUNT -le 10 ]; then
+                        echo -en "\r"
+                        echo -en "SOC-ImageName or TFTP-IP is ERROR. \n"
+                        usleep 500000
+                        exit
+                    fi
+                fi
+        done
+        echo -n "]"
+        LENGTH=0
+        usleep 500000
+        echo -en "\r                                "
+    done
+fi
+sleep 3
+
+echo "Switch the host SPI bus to BMC."
+cmd='gpioutil -p C7 -v 1'
+if $cmd 1>/dev/null 2>&1; then
+    echo "Switch completed."
+else
+    echo "Switch failed."
+fi
+echo "Load the ASpeed SMC driver"
+echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/bind
+sleep 2
+chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
+echo "---Current Chassisstate $chassisstate---"
+if [ "$chassisstate" == 'On' ];
+then
+    echo "---Chassis on turning it off---"
+    obmcutil chassisoff
+    sleep 10
+fi
+
+echo "Flashcp to update SOC."
+echo "Please wait a few minutes."
+flashcp -v /tmp/$1 /dev/mtd6
+sleep 3
+
+echo "Switch the host SPI bus to HOST."
+cmd1='gpioutil -p C7 -v 0'
+if $cmd1 1>/dev/null 2>&1; then
+    echo "Switch completed."
+else
+    echo "Switch failed."
+fi
+echo "unLoad the ASpeed SMC driver"
+echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/unbind
+echo -ne "SOC update steps is complete.\n"
+if [ "$chassisstate" == 'On' ];
+then
+    echo "5 sec later will be power-on."
+    echo "If wantn't power-on, please CTRL + C leave script."
+    WAITSEC=5
+    while [ $WAITSEC -ge 0 ]
+    do
+        echo -n "Countdown seconds:$WAITSEC"
+        sleep 1
+        echo -en "\r"
+        WAITSEC=$(($WAITSEC-1))
+        if [ $WAITSEC -eq 0 ]; then
+            echo -en "\r"
+            echo -en "--- Power-on ---       \n"
+            obmcutil chassison
+            break 1
+        fi
+    done
+fi
diff --git a/meta-stardragon4800-rep2/recipes-phosphor/socupdate/socupdate.bb b/meta-stardragon4800-rep2/recipes-phosphor/socupdate/socupdate.bb
new file mode 100644
index 0000000..e2ae60a
--- /dev/null
+++ b/meta-stardragon4800-rep2/recipes-phosphor/socupdate/socupdate.bb
@@ -0,0 +1,13 @@
+SUMMARY = "HXT SOC update"
+DESCRIPTION = "A sample script to help update the host(soc) firmware"
+HOMEPAGE = ""
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${HXTBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+SRC_URI += "file://socupdate.sh"
+
+do_install() {
+        install -d ${D}${bindir}
+        install -m 0755 ${WORKDIR}/socupdate.sh ${D}${bindir}/socupdate.sh
+}