You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CHIP-tools/chip-update-firmware.sh

135 lines
2.9 KiB

#!/bin/bash
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
6 years ago
DL_DIR=".dl"
IMAGESDIR=".new/firmware/images"
DL_URL="http://opensource.nextthing.co/chip/images"
6 years ago
WGET="wget -q --show-progress"
6 years ago
FLAVOR=server
BRANCH=stable
6 years ago
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 "sgpbhB:N:" opt; do
case $opt in
s)
6 years ago
echo "== Server selected =="
6 years ago
FLAVOR=server
;;
6 years ago
g)
6 years ago
echo "== Gui selected =="
6 years ago
FLAVOR=gui
;;
p)
6 years ago
echo "== Pocketchip selected =="
6 years ago
FLAVOR=pocketchip
;;
b)
6 years ago
echo "== Buildroot selected =="
6 years ago
FLAVOR=buildroot
;;
B)
BRANCH="$OPTARG"
6 years ago
echo "== ${BRANCH} branch selected =="
;;
N)
CACHENUM="$OPTARG"
echo "== Build number ${CACHENUM} selected =="
;;
6 years ago
h)
echo ""
6 years ago
echo "== help =="
6 years ago
echo ""
echo " -s -- Server [Debian + Headless]"
echo " -g -- GUI [Debian + XFCE]"
echo " -p -- PocketCHIP"
echo " -b -- Buildroot"
echo " -B -- Branch(optional) [eg. -B testing]"
echo ""
echo ""
exit 0
;;
\?)
6 years ago
echo "== Invalid option: -$OPTARG ==" >&2
exit 1
;;
esac
done
function require_directory {
if [[ ! -d "${1}" ]]; then
mkdir -p "${1}"
fi
}
6 years ago
function dl_probe {
if [ -z $CACHENUM ]; then
CACHENUM=$(curl -s $DL_URL/$BRANCH/$FLAVOR/latest)
fi
6 years ago
if [[ ! -d "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}" ]]; then
6 years ago
echo "== New image available =="
6 years ago
rm -rf $DL_DIR/$BRANCH-$FLAVOR*
mkdir -p $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}
6 years ago
pushd $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM} > /dev/null
6 years ago
echo "== Downloading.. =="
6 years ago
for FILE in ${PROBES[@]}; do
6 years ago
if ! $WGET $DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/$FILE; then
echo "!! download of $BRANCH-$FLAVOR-$METHOD-b${CACHENUM} failed !!"
6 years ago
exit $?
fi
done
6 years ago
popd > /dev/null
6 years ago
else
6 years ago
echo "== Cached probe files located =="
6 years ago
fi
6 years ago
echo "== Staging for NAND probe =="
6 years ago
ln -s ../../$DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}/ $IMAGESDIR
6 years ago
if [[ -f ${IMAGESDIR}/ubi_type ]]; then rm ${IMAGESDIR}/ubi_type; fi
6 years ago
detect_nand
if [[ ! -f "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX" ]]; then
6 years ago
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
6 years ago
popd > /dev/null
else
6 years ago
echo "== Cached UBI located =="
fi
}
6 years ago
echo == preparing images ==
require_directory "$IMAGESDIR"
rm -rf ${IMAGESDIR}
require_directory "$DL_DIR"
dl_probe
6 years ago
flash_images
rm ${IMAGESDIR}/ubi_type
ready_to_roll