2015-09-10 15:55:33 -04:00
|
|
|
#!/bin/bash
|
2015-09-17 02:51:36 -04:00
|
|
|
|
2015-10-23 16:25:44 -04:00
|
|
|
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
source $SCRIPTDIR/common.sh
|
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
DL_DIR=".dl"
|
|
|
|
IMAGESDIR=".new/firmware/images"
|
2015-10-30 20:12:09 -04:00
|
|
|
|
2016-06-23 22:44:39 -04:00
|
|
|
DL_URL="http://opensource.nextthing.co/chip/images"
|
2015-10-30 20:12:09 -04:00
|
|
|
|
2016-11-28 20:15:19 -05:00
|
|
|
WGET="wget"
|
2016-10-27 19:30:12 -04:00
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
FLAVOR=server
|
2015-12-29 18:37:48 -05:00
|
|
|
BRANCH=stable
|
2015-09-12 20:16:25 -04:00
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
PROBES=(spl-40000-1000-100.bin
|
|
|
|
spl-400000-4000-500.bin
|
|
|
|
spl-400000-4000-680.bin
|
|
|
|
sunxi-spl.bin
|
|
|
|
u-boot-dtb.bin
|
|
|
|
uboot-40000.bin
|
|
|
|
uboot-400000.bin)
|
|
|
|
|
|
|
|
UBI_PREFIX="chip"
|
|
|
|
UBI_SUFFIX="ubi.sparse"
|
|
|
|
UBI_TYPE="400000-4000"
|
|
|
|
|
2016-11-10 20:35:02 -05:00
|
|
|
while getopts "sgpbfnhB:N:F:" opt; do
|
2015-09-12 16:53:04 -04:00
|
|
|
case $opt in
|
2016-06-23 22:44:39 -04:00
|
|
|
s)
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== Server selected =="
|
2016-10-27 18:40:12 -04:00
|
|
|
FLAVOR=server
|
2015-10-27 21:06:06 -04:00
|
|
|
;;
|
2016-10-27 18:40:12 -04:00
|
|
|
g)
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== Gui selected =="
|
2016-10-27 18:40:12 -04:00
|
|
|
FLAVOR=gui
|
2015-09-12 20:16:25 -04:00
|
|
|
;;
|
2016-01-02 05:29:53 -05:00
|
|
|
p)
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== Pocketchip selected =="
|
2016-10-27 18:40:12 -04:00
|
|
|
FLAVOR=pocketchip
|
2016-06-23 22:44:39 -04:00
|
|
|
;;
|
|
|
|
b)
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== Buildroot selected =="
|
2016-10-27 18:40:12 -04:00
|
|
|
FLAVOR=buildroot
|
|
|
|
;;
|
2016-11-02 17:58:29 -04:00
|
|
|
f)
|
|
|
|
echo "== Force clean and download =="
|
|
|
|
rm -rf .dl/ .new/
|
|
|
|
;;
|
2016-11-10 20:35:02 -05:00
|
|
|
n)
|
|
|
|
echo "== No Limit mode =="
|
|
|
|
NO_LIMIT="while itest.b *0x80400000 -ne 03; do i2c mw 0x34 0x30 0x03; i2c read 0x34 0x30 1 0x80400000; done; "
|
|
|
|
;;
|
2016-10-27 18:40:12 -04:00
|
|
|
B)
|
2016-06-23 22:44:39 -04:00
|
|
|
BRANCH="$OPTARG"
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== ${BRANCH} branch selected =="
|
2016-07-11 20:26:14 -04:00
|
|
|
;;
|
2016-10-31 16:29:58 -04:00
|
|
|
N)
|
|
|
|
CACHENUM="$OPTARG"
|
|
|
|
echo "== Build number ${CACHENUM} selected =="
|
|
|
|
;;
|
2016-10-31 21:10:45 -04:00
|
|
|
F)
|
|
|
|
FORMAT="$OPTARG"
|
|
|
|
echo "== Format ${FORMAT} selected =="
|
|
|
|
;;
|
2016-10-27 18:40:12 -04:00
|
|
|
h)
|
|
|
|
echo ""
|
2016-10-31 21:10:45 -04:00
|
|
|
echo "== Help =="
|
2016-10-27 18:40:12 -04:00
|
|
|
echo ""
|
|
|
|
echo " -s -- Server [Debian + Headless]"
|
|
|
|
echo " -g -- GUI [Debian + XFCE]"
|
|
|
|
echo " -p -- PocketCHIP"
|
|
|
|
echo " -b -- Buildroot"
|
2016-11-02 17:58:29 -04:00
|
|
|
echo " -f -- Force clean"
|
2016-10-27 18:40:12 -04:00
|
|
|
echo " -B -- Branch(optional) [eg. -B testing]"
|
2016-10-31 21:10:45 -04:00
|
|
|
echo " -N -- Build#(optional) [eg. -N 150]"
|
|
|
|
echo " -F -- Format(optional) [eg. -F Toshiba_4G_MLC]"
|
2016-10-27 18:40:12 -04:00
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
exit 0
|
2016-01-02 05:29:53 -05:00
|
|
|
;;
|
2015-09-12 16:53:04 -04:00
|
|
|
\?)
|
2016-10-27 19:30:12 -04:00
|
|
|
echo "== Invalid option: -$OPTARG ==" >&2
|
2015-09-12 16:53:04 -04:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-06-23 22:44:39 -04:00
|
|
|
function require_directory {
|
|
|
|
if [[ ! -d "${1}" ]]; then
|
|
|
|
mkdir -p "${1}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
function dl_probe {
|
2016-11-28 18:38:15 -05:00
|
|
|
|
2016-11-02 17:58:29 -04:00
|
|
|
if [ -z $CACHENUM ]; then
|
|
|
|
CACHENUM=$(curl -s $DL_URL/$BRANCH/$FLAVOR/latest)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}" ]]; then
|
|
|
|
echo "== New image available =="
|
|
|
|
|
|
|
|
rm -rf $DL_DIR/$BRANCH-$FLAVOR*
|
|
|
|
|
|
|
|
mkdir -p $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}
|
|
|
|
pushd $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM} > /dev/null
|
|
|
|
|
|
|
|
echo "== Downloading.. =="
|
|
|
|
for FILE in ${PROBES[@]}; do
|
|
|
|
if ! $WGET $DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/$FILE; then
|
|
|
|
echo "!! download of $BRANCH-$FLAVOR-$METHOD-b${CACHENUM} failed !!"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd > /dev/null
|
|
|
|
else
|
|
|
|
echo "== Cached probe files located =="
|
|
|
|
fi
|
2016-11-28 18:38:15 -05:00
|
|
|
|
2016-11-02 17:58:29 -04:00
|
|
|
echo "== Staging for NAND probe =="
|
|
|
|
ln -s ../../$DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}/ $IMAGESDIR
|
|
|
|
if [[ -f ${IMAGESDIR}/ubi_type ]]; then rm ${IMAGESDIR}/ubi_type; fi
|
|
|
|
|
|
|
|
if [ -z $FORMAT ]; then
|
|
|
|
detect_nand
|
|
|
|
else
|
|
|
|
case $FORMAT in
|
|
|
|
"Hynix_8G_MLC")
|
|
|
|
export nand_erasesize=400000
|
|
|
|
export nand_oobsize=680
|
|
|
|
export nand_writesize=4000
|
|
|
|
UBI_TYPE="400000-4000"
|
|
|
|
;;
|
|
|
|
"Toshiba_4G_MLC")
|
|
|
|
export nand_erasesize=400000
|
|
|
|
export nand_oobsize=500
|
|
|
|
export nand_writesize=4000
|
|
|
|
UBI_TYPE="400000-4000"
|
|
|
|
;;
|
|
|
|
"Toshiba_512M_MLC")
|
|
|
|
export nand_erasesize=40000
|
|
|
|
export nand_oobsize=100
|
|
|
|
export nand_writesize=1000
|
|
|
|
UBI_TYPE="400000-1000"
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "== Invalid format: $FORMAT ==" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2016-11-28 18:38:15 -05:00
|
|
|
|
2016-11-02 17:58:29 -04:00
|
|
|
if [[ ! -f "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX" ]]; then
|
|
|
|
echo "== Downloading new UBI, this will be cached for future flashes. =="
|
|
|
|
pushd $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM} > /dev/null
|
|
|
|
if ! $WGET $DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX; then
|
|
|
|
echo "!! download of $BRANCH-$FLAVOR-$METHOD-b${CACHENUM} failed !!"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
popd > /dev/null
|
|
|
|
else
|
|
|
|
echo "== Cached UBI located =="
|
|
|
|
fi
|
2016-06-23 22:44:39 -04:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
echo == preparing images ==
|
|
|
|
require_directory "$IMAGESDIR"
|
|
|
|
rm -rf ${IMAGESDIR}
|
|
|
|
require_directory "$DL_DIR"
|
2016-11-28 20:08:58 -05:00
|
|
|
|
|
|
|
##pass
|
|
|
|
dl_probe || (
|
|
|
|
##fail
|
|
|
|
echo -e "\n FLASH VERIFICATION FAILED.\n\n"
|
|
|
|
echo -e "\tTROUBLESHOOTING:\n"
|
|
|
|
echo -e "\tIs the FEL pin connected to GND?"
|
|
|
|
echo -e "\tHave you tried turning it off and turning it on again?"
|
|
|
|
echo -e "\tDid you run the setup script in CHIP-SDK?"
|
|
|
|
echo -e "\tDownload could be corrupt, it can be re-downloaded by adding the '-f' flag."
|
|
|
|
echo -e "\n\n"
|
|
|
|
)
|
2015-10-21 17:26:59 -04:00
|
|
|
|
2016-11-28 18:38:15 -05:00
|
|
|
##pass
|
|
|
|
flash_images && ready_to_roll || (
|
|
|
|
##fail
|
|
|
|
echo -e "\n FLASH VERIFICATION FAILED.\n\n"
|
|
|
|
echo -e "\tTROUBLESHOOTING:\n"
|
|
|
|
echo -e "\tIs the FEL pin connected to GND?"
|
|
|
|
echo -e "\tHave you tried turning it off and turning it on again?"
|
|
|
|
echo -e "\tDid you run the setup script in CHIP-SDK?"
|
|
|
|
echo -e "\tDownload could be corrupt, it can be re-downloaded by adding the '-f' flag."
|
|
|
|
echo -e "\n\n"
|
|
|
|
)
|