1# Copyright 2011, 2016 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15 16DEVICE_DIR=device/linaro/hikey/ 17DEVICE=hikey 18PRODUCT=hikey 19 20BUILD=eng.`whoami` 21BUILDNAME=`ls ${ANDROID_BUILD_TOP}/${PRODUCT}-img-${BUILD}.zip 2> /dev/null` 22if [ $? -ne 0 ]; then 23 VERSION=linaro-`date +"%Y.%m.%d"` 24else 25 BUILDNAME=`ls ${ANDROID_BUILD_TOP}/${PRODUCT}-img-*.zip 2> /dev/null` 26 BUILD=`basename ${BUILDNAME} | cut -f3 -d'-' | cut -f1 -d'.'` 27 VERSION=$BUILD 28fi 29 30# Prepare the staging directory 31rm -rf tmp 32mkdir -p tmp/$PRODUCT-$VERSION 33 34# copy over flashing tool, and bootloader binaries 35cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/README tmp/$PRODUCT-$VERSION/ 36cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/hisi-idt.py tmp/$PRODUCT-$VERSION/ 37cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/l-loader.bin tmp/$PRODUCT-$VERSION/ 38cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/ptable-aosp-8g.img tmp/$PRODUCT-$VERSION/ 39cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/ptable-aosp-4g.img tmp/$PRODUCT-$VERSION/ 40cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/fip.bin tmp/$PRODUCT-$VERSION/ 41cp $ANDROID_BUILD_TOP/$DEVICE_DIR/installer/hikey/nvme.img tmp/$PRODUCT-$VERSION/ 42 43cp ${SRCPREFIX}$PRODUCT-img-$BUILD.zip tmp/$PRODUCT-$VERSION/image-$PRODUCT-$VERSION.zip 44 45 46# Write flash-all.sh 47cat > tmp/$PRODUCT-$VERSION/flash-all.sh << EOF 48#!/bin/bash 49 50# Copyright 2012, 2016 The Android Open Source Project 51# 52# Licensed under the Apache License, Version 2.0 (the "License"); 53# you may not use this file except in compliance with the License. 54# You may obtain a copy of the License at 55# 56# http://www.apache.org/licenses/LICENSE-2.0 57# 58# Unless required by applicable law or agreed to in writing, software 59# distributed under the License is distributed on an "AS IS" BASIS, 60# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 61# See the License for the specific language governing permissions and 62# limitations under the License. 63 64 65if [ \$# -eq 0 ] 66 then 67 echo "Provide the right /dev/ttyUSBX specific to recovery device" 68 exit 69fi 70 71if [ ! -e "\${1}" ] 72 then 73 echo "device: \${1} does not exist" 74 exit 75fi 76DEVICE_PORT="\${1}" 77 78PTABLE=ptable-aosp-8g.img 79if [ \$# -gt 1 ] 80 then 81 if [ "\${2}" = '4g' ] 82 then 83 PTABLE=ptable-aosp-4g.img 84 fi 85fi 86 87python hisi-idt.py --img1=l-loader.bin -d "\${DEVICE_PORT}" 88sleep 3 89# set a unique serial number 90serialno=\`fastboot getvar serialno 2>&1 > /dev/null\` 91if [ "\${serialno:10:6}" == "(null)" ]; then 92 fastboot oem serialno 93else 94 if [ "\${serialno:10:15}" == "0123456789abcde" ]; then 95 fastboot oem serialno 96 fi 97fi 98fastboot flash ptable "\${PTABLE}" 99fastboot flash fastboot fip.bin 100fastboot flash nvme nvme.img 101fastboot format userdata 102fastboot format cache 103fastboot update image-$PRODUCT-$VERSION.zip 104EOF 105 106chmod a+x tmp/$PRODUCT-$VERSION/flash-all.sh 107 108# Create the distributable package 109(cd tmp ; zip -r ../$PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION) 110mv $PRODUCT-$VERSION-factory.zip $PRODUCT-$VERSION-factory-$(sha256sum < $PRODUCT-$VERSION-factory.zip | cut -b -8).zip 111 112# Clean up 113rm -rf tmp 114