CHIP-tools/chip-update-firmware.sh

224 lines
5.8 KiB
Bash
Raw Normal View History

#!/bin/bash
2016-12-09 16:01:04 -05:00
set -x
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"
2016-06-23 22:44:39 -04:00
DL_URL="http://opensource.nextthing.co/chip/images"
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-680"
2016-10-27 18:40:12 -04:00
2016-12-05 19:56:05 -05:00
while getopts "sgpbfnrhB:N:F:L:" opt; do
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
;;
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
;;
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
;;
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-12-02 19:15:24 -05:00
r)
echo "== Reset after flash =="
RESET_COMMAND="reset"
;;
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-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-12-05 19:56:05 -05:00
L)
LOCALDIR="$OPTARG"
echo "== Local directory '${LOCALDIR}' 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 ""
2016-12-09 16:01:04 -05:00
echo " -s -- Server [Debian + Headless] "
echo " -g -- GUI [Debian + XFCE] "
echo " -p -- PocketCHIP [CHIP on the go!] "
echo " -b -- Buildroot [Tiny, but powerful] "
echo " -f -- Force clean [re-download if applicable]"
2016-12-01 22:55:18 -05:00
echo " -n -- No limit [enable greater power draw]"
2016-12-09 16:01:04 -05:00
echo " -r -- Reset [reset device after flash] "
echo " -B -- Branch [eg. -B testing] "
echo " -N -- Build# [eg. -N 150] "
echo " -F -- Format [eg. -F Toshiba_4G_MLC] "
echo " -L -- Local [eg. -L ../img/buildroot/] "
2016-10-27 18:40:12 -04:00
echo ""
echo ""
exit 0
;;
\?)
2016-10-27 19:30:12 -04:00
echo "== Invalid option: -$OPTARG ==" >&2
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-12-09 16:01:04 -05:00
if [ -z $CACHENUM ] && [ -z $LOCALDIR ]; then
CACHENUM=$(curl -s $DL_URL/$BRANCH/$FLAVOR/latest)
fi
2016-12-05 19:56:05 -05:00
if [[ ! -d "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}" ]] && [[ -z $LOCALDIR ]]; 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
2016-12-05 19:56:05 -05:00
echo "== Local/cached probe files located =="
fi
2016-11-28 18:38:15 -05:00
echo "== Staging for NAND probe =="
2016-12-05 20:49:22 -05:00
if [ -z $LOCALDIR ];then
2016-12-05 19:56:05 -05:00
ln -s ../../$DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}/ $IMAGESDIR
else
ln -s ../../$LOCALDIR $IMAGESDIR
fi
if [[ -f ${IMAGESDIR}/ubi_type ]]; then rm ${IMAGESDIR}/ubi_type; fi
if [ -z $FORMAT ]; then
2016-12-05 19:56:05 -05:00
detect_nand || exit 1
else
case $FORMAT in
"Hynix_8G_MLC")
2016-12-09 16:01:04 -05:00
echo hello
export nand_erasesize=400000
export nand_oobsize=680
export nand_writesize=4000
;;
"Toshiba_4G_MLC")
export nand_erasesize=400000
export nand_oobsize=500
export nand_writesize=4000
;;
2016-12-09 16:01:04 -05:00
"Toshiba_512M_SLC")
echo correct
export nand_erasesize=40000
export nand_oobsize=100
export nand_writesize=1000
;;
2016-12-09 16:01:04 -05:00
*)
echo "== Invalid format: $FORMAT =="
exit 1
2016-12-09 16:01:04 -05:00
;;
esac
2016-12-05 19:56:05 -05:00
UBI_TYPE="$nand_erasesize-$nand_writesize-$nand_oobsize"
2016-12-09 16:01:04 -05:00
echo $UBI_TYPE > ${IMAGESDIR}/ubi_type
fi
2016-11-28 18:38:15 -05:00
2016-12-05 19:56:05 -05:00
if [[ ! -f "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX" ]] && [ -z $LOCALDIR ]; 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 !!"
2016-12-05 19:56:05 -05:00
exit $?
fi
popd > /dev/null
2016-12-05 19:56:05 -05:00
else
if [ -z $LOCALDIR ]; then
echo "== Cached UBI located =="
2016-12-05 19:56:05 -05:00
else
if [[ ! -f "$IMAGESDIR/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX" ]]; then
echo "Could not locate UBI files"
exit 1
else
echo "== Cached UBI located =="
fi
fi
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"
2016-11-28 21:17:49 -05:00
exit 1
2016-11-28 20:08:58 -05:00
)
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"
)