CHIP-tools/chip-update-firmware.sh

172 lines
3.9 KiB
Bash
Raw Normal View History

#!/bin/bash
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
2016-10-27 22:40:12 +00:00
DL_DIR=".dl"
IMAGESDIR=".new/firmware/images"
2016-06-24 02:44:39 +00:00
DL_URL="http://opensource.nextthing.co/chip/images"
2016-10-27 23:30:12 +00:00
WGET="wget -q --show-progress"
2016-10-27 22:40:12 +00:00
FLAVOR=server
2015-12-29 23:37:48 +00:00
BRANCH=stable
2015-09-13 00:16:25 +00:00
2016-10-27 22:40:12 +00: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"
while getopts "sgpbfhB:N:F:" opt; do
case $opt in
2016-06-24 02:44:39 +00:00
s)
2016-10-27 23:30:12 +00:00
echo "== Server selected =="
2016-10-27 22:40:12 +00:00
FLAVOR=server
;;
2016-10-27 22:40:12 +00:00
g)
2016-10-27 23:30:12 +00:00
echo "== Gui selected =="
2016-10-27 22:40:12 +00:00
FLAVOR=gui
2015-09-13 00:16:25 +00:00
;;
p)
2016-10-27 23:30:12 +00:00
echo "== Pocketchip selected =="
2016-10-27 22:40:12 +00:00
FLAVOR=pocketchip
2016-06-24 02:44:39 +00:00
;;
b)
2016-10-27 23:30:12 +00:00
echo "== Buildroot selected =="
2016-10-27 22:40:12 +00:00
FLAVOR=buildroot
;;
f)
echo "== Force clean and download =="
rm -rf .dl/ .new/
;;
2016-10-27 22:40:12 +00:00
B)
2016-06-24 02:44:39 +00:00
BRANCH="$OPTARG"
2016-10-27 23:30:12 +00:00
echo "== ${BRANCH} branch selected =="
;;
2016-10-31 20:29:58 +00:00
N)
CACHENUM="$OPTARG"
echo "== Build number ${CACHENUM} selected =="
;;
2016-11-01 01:10:45 +00:00
F)
FORMAT="$OPTARG"
echo "== Format ${FORMAT} selected =="
;;
2016-10-27 22:40:12 +00:00
h)
echo ""
2016-11-01 01:10:45 +00:00
echo "== Help =="
2016-10-27 22:40:12 +00:00
echo ""
echo " -s -- Server [Debian + Headless]"
echo " -g -- GUI [Debian + XFCE]"
echo " -p -- PocketCHIP"
echo " -b -- Buildroot"
echo " -f -- Force clean"
2016-10-27 22:40:12 +00:00
echo " -B -- Branch(optional) [eg. -B testing]"
2016-11-01 01:10:45 +00:00
echo " -N -- Build#(optional) [eg. -N 150]"
echo " -F -- Format(optional) [eg. -F Toshiba_4G_MLC]"
2016-10-27 22:40:12 +00:00
echo ""
echo ""
exit 0
;;
\?)
2016-10-27 23:30:12 +00:00
echo "== Invalid option: -$OPTARG ==" >&2
exit 1
;;
esac
done
2016-06-24 02:44:39 +00:00
function require_directory {
if [[ ! -d "${1}" ]]; then
mkdir -p "${1}"
fi
}
2016-10-27 22:40:12 +00:00
function dl_probe {
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-10-27 23:30:12 +00: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-10-27 22:40:12 +00: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-24 02:44:39 +00:00
}
2016-10-27 22:40:12 +00:00
echo == preparing images ==
require_directory "$IMAGESDIR"
rm -rf ${IMAGESDIR}
require_directory "$DL_DIR"
dl_probe
2015-10-21 21:26:59 +00:00
2016-10-27 22:40:12 +00:00
flash_images
2015-10-21 21:26:59 +00:00
ready_to_roll