2015-09-10 15:55:33 -04:00
|
|
|
#!/bin/bash
|
|
|
|
FW_DIR="$(pwd)/.firmware"
|
|
|
|
FW_IMAGE_DIR="${FW_DIR}/images"
|
2015-09-12 16:53:04 -04:00
|
|
|
S3_URL="https://s3-ap-northeast-1.amazonaws.com/stak-images/firmware/chip/stable/latest"
|
2015-09-10 15:55:33 -04:00
|
|
|
|
2015-09-17 02:51:36 -04:00
|
|
|
LATEST_URL=""
|
|
|
|
|
2015-09-12 20:16:25 -04:00
|
|
|
FLASH_SCRIPT=./chip-fel-flash.sh
|
|
|
|
|
2015-09-10 15:55:33 -04:00
|
|
|
function require_directory {
|
2015-09-15 21:39:14 -04:00
|
|
|
if [[ ! -d "${1}" ]]; then
|
|
|
|
mkdir -p "${1}"
|
|
|
|
fi
|
2015-09-10 15:55:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function cache_download {
|
2015-09-15 21:39:14 -04:00
|
|
|
if [[ ! -f "${1}/${2}" ]]; then
|
2015-09-17 02:51:36 -04:00
|
|
|
|
|
|
|
if [[ -z "$LATEST_URL" ]]; then
|
|
|
|
LATEST_URL="$(wget -q -O- ${S3_URL})"
|
|
|
|
echo "LATEST_URL=$LATEST_URL"
|
|
|
|
if [[ -z "${LATEST_URL}" ]]; then
|
|
|
|
echo "error: could not get URL for latest build from ${S3_URL} - check internet connection"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD=${LATEST_URL%%/}
|
|
|
|
BUILD=${BUILD##*/}
|
|
|
|
echo "BUILD=$BUILD"
|
|
|
|
|
|
|
|
if [[ -z "${BUILD}" ]]; then
|
|
|
|
echo "error: could not extract build number from build"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-09-15 21:39:14 -04:00
|
|
|
echo "$BUILD" > ${FW_IMAGE_DIR}/build
|
2015-09-12 16:53:04 -04:00
|
|
|
|
2015-09-15 21:39:14 -04:00
|
|
|
wget -P "${FW_IMAGE_DIR}" "${LATEST_URL}images/${2}" ||
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-09-10 15:55:33 -04:00
|
|
|
}
|
2015-09-14 21:19:01 -04:00
|
|
|
|
2015-09-12 16:53:04 -04:00
|
|
|
|
2015-09-12 23:15:36 -04:00
|
|
|
while getopts "uf" opt; do
|
2015-09-12 16:53:04 -04:00
|
|
|
case $opt in
|
|
|
|
u)
|
|
|
|
echo "updating cache"
|
|
|
|
if [[ -d "$FW_IMAGE_DIR" ]]; then
|
|
|
|
rm -rf $FW_IMAGE_DIR
|
|
|
|
fi
|
|
|
|
;;
|
2015-09-12 20:16:25 -04:00
|
|
|
f)
|
|
|
|
echo "fastboot enabled"
|
|
|
|
FLASH_SCRIPT=./chip-fel-fastboot.sh
|
|
|
|
;;
|
2015-09-12 16:53:04 -04:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2015-09-10 15:55:33 -04:00
|
|
|
require_directory "${FW_IMAGE_DIR}"
|
|
|
|
cache_download "${FW_IMAGE_DIR}" rootfs.ubi
|
|
|
|
cache_download "${FW_IMAGE_DIR}" sun5i-r8-chip.dtb
|
|
|
|
cache_download "${FW_IMAGE_DIR}" sunxi-spl.bin
|
|
|
|
cache_download "${FW_IMAGE_DIR}" uboot-env.bin
|
|
|
|
cache_download "${FW_IMAGE_DIR}" zImage
|
|
|
|
cache_download "${FW_IMAGE_DIR}" u-boot-dtb.bin
|
|
|
|
|
2015-10-01 19:44:31 -04:00
|
|
|
BUILDROOT_OUTPUT_DIR="${FW_DIR}" ${FLASH_SCRIPT}
|
2015-09-14 21:40:22 -04:00
|
|
|
exit $?
|