hikey: Package factory image from an existing image am: 2a31c3a592 am: f5c971add1
am: 59ba72969c

Change-Id: I8d7cb38b66693d4315d4e0703a8c3007ff0b39bd
diff --git a/factory-images/README b/factory-images/README
index 2d7ee90..aaa1fb0 100644
--- a/factory-images/README
+++ b/factory-images/README
@@ -6,3 +6,7 @@
 $ cd out/dist/
 $ . ../../device/linaro/hikey/factory-images/generate-factory-images-package.sh
 
+# Package with an existing image
+# First download the image to the android build top directory
+
+$ device/linaro/hikey/factory-images/generate-factory-images-package.sh
diff --git a/factory-images/generate-factory-images-hikey.sh b/factory-images/generate-factory-images-hikey.sh
old mode 100644
new mode 100755
index c844ad9..b01e5c1
--- a/factory-images/generate-factory-images-hikey.sh
+++ b/factory-images/generate-factory-images-hikey.sh
@@ -13,12 +13,24 @@
 # limitations under the License.
 
 
+DEVICE_DIR=device/linaro/hikey/
+DEVICE=hikey
+PRODUCT=hikey
+
+BUILD=eng.`whoami`
+BUILDNAME=`ls ${ANDROID_BUILD_TOP}/${PRODUCT}-img-${BUILD}.zip 2> /dev/null`
+if [ $? -eq 0 ]; then
+  VERSION=linaro-`date +"%Y.%m.%d"`
+else
+  BUILDNAME=`ls ${ANDROID_BUILD_TOP}/${PRODUCT}-img-*.zip 2> /dev/null`
+  BUILD=`basename ${BUILDNAME} | cut -f3 -d'-' | cut -f1 -d'.'`
+  VERSION=$BUILD
+fi
+
 # Prepare the staging directory
 rm -rf tmp
 mkdir -p tmp/$PRODUCT-$VERSION
 
-DEVICE_DIR=device/linaro/hikey/
-
 # copy over flashing tool, and bootloader binaries
 cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/README tmp/$PRODUCT-$VERSION/
 cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hisi-idt.py tmp/$PRODUCT-$VERSION/
diff --git a/factory-images/generate-factory-images-package.sh b/factory-images/generate-factory-images-package.sh
index 316aa3e..9ee2ae8 100755
--- a/factory-images/generate-factory-images-package.sh
+++ b/factory-images/generate-factory-images-package.sh
@@ -14,10 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+ANDROID_BUILD_TOP=.
+
 source $ANDROID_BUILD_TOP/device/common/clear-factory-images-variables.sh
-BUILD=eng.`whoami`
-DEVICE=hikey
-PRODUCT=hikey
-VERSION=linaro-`date +"%Y.%m.%d"`
 # HiKey unfortunately can't use the ./generate-factory-images-common.sh script
 source $ANDROID_BUILD_TOP/device/linaro/hikey/factory-images/generate-factory-images-hikey.sh