You cannot 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

129 lines
2.8 KiB
Bash

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