2010-11-01 16:33:02 +02:00
|
|
|
#!/bin/bash
|
2010-11-20 11:29:28 +02:00
|
|
|
# version of me
|
|
|
|
__VERSION__="2011-11-20"
|
2010-11-01 16:33:02 +02:00
|
|
|
|
|
|
|
# use 'http' to download and flash images, use 'file' to flash images present in the <WORKING_DIR>
|
|
|
|
PROTOCOL="http"
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
# NanoNote images Version
|
|
|
|
VERSION="latest"
|
|
|
|
|
2010-11-01 16:33:02 +02:00
|
|
|
# working directory
|
|
|
|
WORKING_DIR="${HOME}/.qi/nanonote/ben/${VERSION}"
|
|
|
|
|
|
|
|
# URL to images ($URL/$VERSION/$[images])
|
|
|
|
BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/NanoNote/Ben"
|
|
|
|
|
|
|
|
# names of images
|
|
|
|
LOADER="openwrt-xburst-qi_lb60-u-boot.bin"
|
|
|
|
KERNEL="openwrt-xburst-qi_lb60-uImage.bin"
|
|
|
|
ROOTFS="openwrt-xburst-qi_lb60-root.ubi"
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
# options for reflash bootloader, kernel, rootfs
|
2010-11-01 16:33:02 +02:00
|
|
|
B="TRUE"
|
|
|
|
K="TRUE"
|
|
|
|
R="TRUE"
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
while getopts d:l:h OPTIONS
|
2010-11-01 16:33:02 +02:00
|
|
|
do
|
|
|
|
case $OPTIONS in
|
|
|
|
d)
|
|
|
|
VERSION=$OPTARG # override version by first argument if passed
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
WORKING_DIR=$OPTARG
|
|
|
|
PROTOCOL="file"
|
2010-11-20 17:25:56 +02:00
|
|
|
VERSION="Local"
|
2010-11-01 16:33:02 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "\
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
Usage: $0 [-d <version>] [-l <path to local images>] [-h]
|
|
|
|
-d <> I will download and flash a specific version of OpenWrt images
|
2010-11-01 16:33:02 +02:00
|
|
|
|
|
|
|
-l <> I will flash images present in <arg>
|
2010-11-20 11:29:28 +02:00
|
|
|
(missing files will be skipped)
|
2010-11-01 16:33:02 +02:00
|
|
|
|
|
|
|
-h you already found out
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
without any arguments, I will download and flash the latest OpenWrt images
|
|
|
|
(includes bootloader, kernel and rootfs)
|
2010-11-01 16:33:02 +02:00
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
OpenWrt reflash script for qi-hardware Ben NanoNote
|
2010-11-01 16:33:02 +02:00
|
|
|
written by: Mirko Vogt (mirko.vogt@sharism.cc)
|
|
|
|
Xiangfu Liu (xiangfu@sharism.cc)
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
version: ${__VERSION__}
|
2010-11-01 16:33:02 +02:00
|
|
|
Please report bugs to developer@lists.qi-hardware.com"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-11-24 09:59:27 +02:00
|
|
|
# where the verbose output goes to
|
|
|
|
LOG_FILE="${WORKING_DIR}/log.txt"
|
|
|
|
|
2010-11-01 16:33:02 +02:00
|
|
|
# create working directory
|
|
|
|
mkdir -p ${WORKING_DIR}
|
2010-11-20 11:29:28 +02:00
|
|
|
# purge logfile if exists
|
|
|
|
date > "${LOG_FILE}"
|
2010-11-01 16:33:02 +02:00
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
log() {
|
2010-11-01 16:33:02 +02:00
|
|
|
echo -e "$1"
|
|
|
|
echo -e "$1" >> "${LOG_FILE}"
|
|
|
|
}
|
|
|
|
|
2010-11-20 11:29:28 +02:00
|
|
|
abort() {
|
2010-11-01 16:33:02 +02:00
|
|
|
log "==="
|
|
|
|
log "fatal error occured - ABORTED"
|
|
|
|
log "==="
|
|
|
|
log "$1"
|
|
|
|
log "==="
|
|
|
|
log "Before reporting this as a bug"
|
2010-11-20 17:25:56 +02:00
|
|
|
log "Please ensure you're using the latest available version of this reflash script"
|
|
|
|
log "http://downloads.qi-hardware.com/software/images/NanoNote/Ben/reflash_ben.sh"
|
2010-11-01 16:33:02 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:31:38 +02:00
|
|
|
progress_prepare () {
|
|
|
|
WIDTH=$(tput cols)
|
|
|
|
HEIGHT=$(tput lines)
|
|
|
|
i=1
|
|
|
|
DONE=0
|
|
|
|
FITFR=0
|
|
|
|
echo "Done:"
|
|
|
|
echo -n "["
|
|
|
|
tput cup $HEIGHT $WIDTH; echo -n "]"
|
|
|
|
}
|
|
|
|
|
|
|
|
progress_draw () {
|
|
|
|
ILINE="$1"
|
|
|
|
if [[ "$ILINE" =~ It\ will\ cause\ [[:digit:]]+\ times\ buffer\ transfer\.$ ]]; then
|
|
|
|
TOTAL=${ILINE#*cause\ }
|
|
|
|
TOTAL=${TOTAL%\ times*}
|
|
|
|
FIT=$(echo "($WIDTH-2)/$TOTAL" | bc -l)
|
|
|
|
tput cup $(( $HEIGHT-2 )) 7; echo -n 0/$TOTAL
|
|
|
|
fi
|
|
|
|
if [[ "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ Comparing\ [[:digit:]]+\ bytes\ -\ SUCCESS$ || "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ no\ check\!\ End\ at\ Page\:\ [[:digit:]]+ ]]; then
|
|
|
|
FITFR=$(echo $FITFR+$FIT | bc -l)
|
|
|
|
((DONE++))
|
|
|
|
tput cup $(( $HEIGHT-2 )) 7; echo -n $DONE/$TOTAL
|
|
|
|
if [ $(echo "$FITFR >= 1" | bc) -eq 1 ]; then
|
|
|
|
tput cup $HEIGHT $i;
|
|
|
|
i=$(( $i+${FITFR%.*} ))
|
|
|
|
for j in $(seq 1 ${FITFR%.*}); do echo -n "#"; done
|
|
|
|
FITFR=0.${FITFR#*.}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
progress_finish () {
|
|
|
|
tput cup $HEIGHT $WIDTH
|
|
|
|
echo
|
|
|
|
tmp=$(<"${LOG_FILE}.err")
|
|
|
|
cat "${LOG_FILE}.err" >> "${LOG_FILE}"
|
|
|
|
}
|
|
|
|
|
2010-11-01 16:33:02 +02:00
|
|
|
[ "$(whoami)" == "root" ] || abort "this script must be run as root"
|
|
|
|
|
|
|
|
log "working dir: ${WORKING_DIR}"
|
|
|
|
log "chosen method: ${PROTOCOL}"
|
|
|
|
test ${VERSION} && log "chosen version: ${VERSION}"
|
|
|
|
log "==="
|
|
|
|
|
|
|
|
if [ "$PROTOCOL" == "http" ]; then
|
|
|
|
|
|
|
|
MD5SUMS_SERVER=$(wget -O - ${BASE_URL_HTTP}/${VERSION}/md5sums 2> /dev/null | grep -E "(${LOADER}|${KERNEL}|${ROOTFS})" | sort)
|
|
|
|
[ "${MD5SUMS_SERVER}" ] || abort "can't fetch files from server"
|
|
|
|
|
|
|
|
MD5SUMS_LOCAL=$( (cd "${WORKING_DIR}" ; md5sum --binary "${LOADER}" "${KERNEL}" "${ROOTFS}" 2> /dev/null) | sort )
|
|
|
|
|
|
|
|
if [ "${MD5SUMS_SERVER}" == "${MD5SUMS_LOCAL}" ]; then
|
|
|
|
log "present files are identical to the ones on the server - do not download them again"
|
|
|
|
else
|
|
|
|
rm -f "${WORKING_DIR}/${LOADER}" "${WORKING_DIR}/${KERNEL}" "${WORKING_DIR}/${ROOTFS}"
|
|
|
|
if [ "$B" == "TRUE" ]; then
|
|
|
|
log "fetching bootloader..."
|
|
|
|
wget \
|
|
|
|
-a "${LOG_FILE}" \
|
|
|
|
-P "${WORKING_DIR}" \
|
|
|
|
"${BASE_URL_HTTP}/${VERSION}/${LOADER}"
|
|
|
|
fi
|
|
|
|
if [ "$K" == "TRUE" ]; then
|
|
|
|
log "fetching kernel..."
|
|
|
|
wget \
|
|
|
|
-a "${LOG_FILE}" \
|
|
|
|
-P "${WORKING_DIR}" \
|
|
|
|
"${BASE_URL_HTTP}/${VERSION}/${KERNEL}"
|
|
|
|
fi
|
|
|
|
if [ "$R" == "TRUE" ]; then
|
2010-11-20 11:29:28 +02:00
|
|
|
log "try fetching .ubi.bz2 rootfs..."
|
2010-11-01 16:33:02 +02:00
|
|
|
wget \
|
|
|
|
-a "${LOG_FILE}" \
|
|
|
|
-P "${WORKING_DIR}" \
|
2010-11-20 11:29:28 +02:00
|
|
|
"${BASE_URL_HTTP}/${VERSION}/${ROOTFS}.bz2" && \
|
2010-11-20 17:25:56 +02:00
|
|
|
(cd ${WORKING_DIR}; bzip2 -d ${ROOTFS}.bz2)
|
2010-11-20 11:29:28 +02:00
|
|
|
|
2010-11-25 16:01:04 +02:00
|
|
|
if [ "$?" != "0" ]; then
|
2010-11-20 11:29:28 +02:00
|
|
|
log "fetching .ubi rootfs..."
|
|
|
|
wget \
|
|
|
|
-a "${LOG_FILE}" \
|
|
|
|
-P "${WORKING_DIR}" \
|
|
|
|
"${BASE_URL_HTTP}/${VERSION}/${ROOTFS}"
|
|
|
|
fi
|
2010-11-01 16:33:02 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "booting device..."
|
|
|
|
usbboot -c "boot" >> "${LOG_FILE}" || abort "can't boot device - xburst-tools setup correctly? device in boot-mode? device connected?"
|
|
|
|
|
|
|
|
if [ "$B" == "TRUE" ]; then
|
|
|
|
log "flashing bootloader..."
|
2010-12-01 09:31:38 +02:00
|
|
|
progress_prepare
|
|
|
|
while read ILINE
|
|
|
|
do progress_draw "$ILINE"
|
|
|
|
done< <(usbboot -c "nprog 0 ${WORKING_DIR}/${LOADER} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
|
|
|
|
progress_finish
|
2010-11-01 16:33:02 +02:00
|
|
|
test "${tmp}" && abort "error while flashing bootloader:\n${tmp}"
|
|
|
|
fi
|
|
|
|
if [ "$K" == "TRUE" ]; then
|
|
|
|
log "flashing kernel..."
|
2010-12-01 09:31:38 +02:00
|
|
|
progress_prepare
|
|
|
|
while read ILINE
|
|
|
|
do progress_draw "$ILINE"
|
|
|
|
done< <(usbboot -c "nprog 1024 ${WORKING_DIR}/${KERNEL} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
|
|
|
|
progress_finish
|
2010-11-01 16:33:02 +02:00
|
|
|
test "${tmp}" && abort "error while flashing kernel:\n${tmp}"
|
|
|
|
fi
|
|
|
|
if [ "$R" == "TRUE" ]; then
|
|
|
|
log "erase nand rootfs partition..."
|
2010-11-06 09:49:44 +02:00
|
|
|
usbboot -c "boot;nerase 16 1024 0 0" >> "${LOG_FILE}" 2>&1
|
2010-11-01 16:33:02 +02:00
|
|
|
log "flashing rootfs..."
|
2010-12-01 09:31:38 +02:00
|
|
|
progress_prepare
|
|
|
|
while read ILINE
|
|
|
|
do progress_draw "$ILINE"
|
|
|
|
done< <(usbboot -c "nprog 2048 ${WORKING_DIR}/${ROOTFS} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}")
|
|
|
|
progress_finish
|
2010-11-01 16:33:02 +02:00
|
|
|
test "${tmp}" && abort "error while flashing rootfs:\n${tmp}"
|
|
|
|
fi
|
|
|
|
log "done"
|