OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | #!/bin/bash |
| 2 | # version of me |
| 3 | __VERSION__="2011-12-12" |
| 4 | |
| 5 | # use 'http' to download and flash images, use 'file' to flash images present in the <WORKING_DIR> |
| 6 | PROTOCOL="http" |
| 7 | |
| 8 | # NanoNote images Version |
| 9 | VERSION="latest" |
| 10 | |
| 11 | # working directory |
| 12 | WORKING_DIR="${HOME}/.qi/nanonote/ben/${VERSION}" |
| 13 | |
| 14 | # URL to images ($URL/$VERSION/$[images]) |
| 15 | BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/NanoNote/Ben" |
| 16 | |
| 17 | # names of images |
| 18 | LOADER="openwrt-xburst-qi_lb60-u-boot.bin" |
| 19 | KERNEL="openwrt-xburst-qi_lb60-uImage.bin" |
| 20 | ROOTFS="openwrt-xburst-qi_lb60-root.ubi" |
| 21 | |
| 22 | # options for reflash bootloader, kernel, rootfs |
| 23 | B="FALSE" |
| 24 | K="FALSE" |
| 25 | R="FALSE" |
| 26 | ALL="TRUE" |
| 27 | |
| 28 | while getopts d:t:v:l:hbkr OPTIONS |
| 29 | do |
| 30 | case $OPTIONS in |
| 31 | d) |
| 32 | BASE_URL_HTTP="http://fidelio.qi-hardware.com/~xiangfu/build-nanonote/" |
| 33 | VERSION=$OPTARG # override version by first argument |
| 34 | WORKING_DIR=${VERSION} |
| 35 | ;; |
| 36 | t) |
| 37 | BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/NanoNote/Ben/testing" |
| 38 | VERSION=$OPTARG |
| 39 | WORKING_DIR=${VERSION} |
| 40 | ;; |
| 41 | v) |
| 42 | VERSION=$OPTARG |
| 43 | WORKING_DIR="${HOME}/.qi/nanonote/ben/${VERSION}" |
| 44 | ;; |
| 45 | l) |
| 46 | PROTOCOL="file" |
| 47 | VERSION="local" |
| 48 | WORKING_DIR=$OPTARG |
| 49 | ;; |
| 50 | b) |
| 51 | ALL="FALSE" |
| 52 | B="TRUE" |
| 53 | ;; |
| 54 | k) |
| 55 | ALL="FALSE" |
| 56 | K="TRUE" |
| 57 | ;; |
| 58 | r) |
| 59 | ALL="FALSE" |
| 60 | R="TRUE" |
| 61 | ;; |
| 62 | *) |
| 63 | echo "\ |
| 64 | |
| 65 | Usage: $0 [-d <dailybuild version>] [-t <testing version>] [-v <version>] [-l <path to local images>] [-b] [-k] [-r] [-h] |
| 66 | -d <> I will download and flash a [dailybuild] version of OpenWrt images |
| 67 | |
| 68 | -t <> I will download and flash a [testing] version of OpenWrt images |
| 69 | |
| 70 | -v <> I will download and flash a [specific] version of OpenWrt images |
| 71 | |
| 72 | -l <> I will flash images present in folder: <arg> |
| 73 | (missing files will be skipped) |
| 74 | |
| 75 | -b flash bootloader(u-boot) |
| 76 | -k linux kernel |
| 77 | -r root filesystem |
| 78 | |
| 79 | -h you already found out |
| 80 | |
| 81 | without any arguments, I will download and flash the latest OpenWrt images |
| 82 | (includes bootloader, kernel and rootfs) |
| 83 | |
| 84 | OpenWrt reflash script for Qi Hardware Ben NanoNote |
| 85 | written by: Mirko Vogt (mirko.vogt@sharism.cc) |
| 86 | Xiangfu Liu (xiangfu@sharism.cc) |
| 87 | |
| 88 | version: ${__VERSION__} |
| 89 | Please report bugs to developer@lists.qi-hardware.com" |
| 90 | exit 1 |
| 91 | ;; |
| 92 | esac |
| 93 | done |
| 94 | |
| 95 | if [ "$ALL" == "TRUE" ]; then |
| 96 | B="TRUE" |
| 97 | K="TRUE" |
| 98 | R="TRUE" |
| 99 | fi |
| 100 | |
| 101 | # where the verbose output goes to |
| 102 | LOG_FILE="${WORKING_DIR}/log.txt" |
| 103 | |
| 104 | # create working directory |
| 105 | mkdir -p ${WORKING_DIR} |
| 106 | # purge logfile if exists |
| 107 | date > "${LOG_FILE}" |
| 108 | |
| 109 | log() { |
| 110 | echo -e "$1" |
| 111 | echo -e "$1" >> "${LOG_FILE}" |
| 112 | } |
| 113 | |
| 114 | abort() { |
| 115 | log "===" |
| 116 | log "fatal error occured - ABORTED" |
| 117 | log "===" |
| 118 | log "$1" |
| 119 | log "===" |
| 120 | log "Before reporting this as a bug" |
| 121 | log "Please ensure you're using the latest available version of this reflash script" |
| 122 | log "http://downloads.qi-hardware.com/software/images/NanoNote/Ben/reflash_ben.sh" |
| 123 | exit 1 |
| 124 | } |
| 125 | |
| 126 | progress_prepare () { |
| 127 | WIDTH=$(tput cols) |
| 128 | HEIGHT=$(tput lines) |
| 129 | i=1 |
| 130 | DONE=0 |
| 131 | FITFR=0 |
| 132 | echo "Done:" |
| 133 | echo -n "[" |
| 134 | tput cup $HEIGHT $WIDTH; echo -n "]" |
| 135 | } |
| 136 | |
| 137 | progress_draw () { |
| 138 | ILINE="$1" |
| 139 | if [[ "$ILINE" =~ It\ will\ cause\ [[:digit:]]+\ times\ buffer\ transfer\.$ ]]; then |
| 140 | TOTAL=${ILINE#*cause\ } |
| 141 | TOTAL=${TOTAL%\ times*} |
| 142 | FIT=$(echo "($WIDTH-2)/$TOTAL" | bc -l) |
| 143 | tput cup $(( $HEIGHT-2 )) 7; echo -n 0/$TOTAL |
| 144 | fi |
| 145 | if [[ "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ Comparing\ [[:digit:]]+\ bytes\ -\ SUCCESS$ || "$ILINE" =~ Checking\ [[:digit:]]+\ bytes\.\.\.\ no\ check\!\ End\ at\ Page\:\ [[:digit:]]+ ]]; then |
| 146 | FITFR=$(echo $FITFR+$FIT | bc -l) |
| 147 | ((DONE++)) |
| 148 | tput cup $(( $HEIGHT-2 )) 7; echo -n $DONE/$TOTAL |
| 149 | if [ $(echo "$FITFR >= 1" | bc) -eq 1 ]; then |
| 150 | tput cup $HEIGHT $i; |
| 151 | i=$(( $i+${FITFR%.*} )) |
| 152 | for j in $(seq 1 ${FITFR%.*}); do echo -n "#"; done |
| 153 | FITFR=0.${FITFR#*.} |
| 154 | fi |
| 155 | fi |
| 156 | } |
| 157 | |
| 158 | progress_finish () { |
| 159 | tput cup $HEIGHT $WIDTH |
| 160 | echo |
| 161 | tmp=$(<"${LOG_FILE}.err") |
| 162 | cat "${LOG_FILE}.err" >> "${LOG_FILE}" |
| 163 | } |
| 164 | |
| 165 | log "working dir: ${WORKING_DIR}" |
| 166 | log "chosen method: ${PROTOCOL} ${BASE_URL_HTTP}" |
| 167 | test ${VERSION} && log "chosen version: ${VERSION}" |
| 168 | log "===" |
| 169 | |
| 170 | if [ "$PROTOCOL" == "http" ]; then |
| 171 | |
| 172 | MD5SUMS_SERVER=$(wget -O - ${BASE_URL_HTTP}/${VERSION}/md5sums 2> /dev/null | grep -E "(${LOADER}|${KERNEL}|${ROOTFS})" | sort) |
| 173 | [ "${MD5SUMS_SERVER}" ] || abort "can't fetch files from server" |
| 174 | |
| 175 | if [ ! -f "${WORKING_DIR}/${ROOTFS}" ] && [ -f "${WORKING_DIR}/${ROOTFS}.bz2" ] ; then |
| 176 | log "found .ubi.bz2 rootfs, decompressing to .ubi ..." |
| 177 | (cd "${WORKING_DIR}"; bzip2 -d "${ROOTFS}.bz2") |
| 178 | fi |
| 179 | |
| 180 | MD5SUMS_LOCAL=$( (cd "${WORKING_DIR}" ; md5sum --binary "${LOADER}" "${KERNEL}" "${ROOTFS}" 2> /dev/null) | sort ) |
| 181 | |
| 182 | if [ "${MD5SUMS_SERVER}" == "${MD5SUMS_LOCAL}" ]; then |
| 183 | log "present files are identical to the ones on the server - do not download them again" |
| 184 | else |
| 185 | rm -f "${WORKING_DIR}/${LOADER}" "${WORKING_DIR}/${KERNEL}" "${WORKING_DIR}/${ROOTFS}" |
| 186 | if [ "$B" == "TRUE" ]; then |
| 187 | log "fetching bootloader..." |
| 188 | wget \ |
| 189 | -a "${LOG_FILE}" \ |
| 190 | -O "${WORKING_DIR}/${LOADER}" \ |
| 191 | "${BASE_URL_HTTP}/${VERSION}/${LOADER}" |
| 192 | fi |
| 193 | if [ "$K" == "TRUE" ]; then |
| 194 | log "fetching kernel..." |
| 195 | wget \ |
| 196 | -a "${LOG_FILE}" \ |
| 197 | -O "${WORKING_DIR}/${KERNEL}" \ |
| 198 | "${BASE_URL_HTTP}/${VERSION}/${KERNEL}" |
| 199 | fi |
| 200 | if [ "$R" == "TRUE" ]; then |
| 201 | log "try fetching .ubi.bz2 rootfs..." |
| 202 | wget \ |
| 203 | -a "${LOG_FILE}" \ |
| 204 | -O "${WORKING_DIR}/${ROOTFS}.bz2" \ |
| 205 | "${BASE_URL_HTTP}/${VERSION}/${ROOTFS}.bz2" && \ |
| 206 | (cd ${WORKING_DIR}; bzip2 -d ${ROOTFS}.bz2) |
| 207 | |
| 208 | if [ "$?" != "0" ]; then |
| 209 | log "fetching .ubi rootfs..." |
| 210 | wget \ |
| 211 | -a "${LOG_FILE}" \ |
| 212 | -O "${WORKING_DIR}/${ROOTFS}" \ |
| 213 | "${BASE_URL_HTTP}/${VERSION}/${ROOTFS}" |
| 214 | fi |
| 215 | fi |
| 216 | fi |
| 217 | fi |
| 218 | |
| 219 | log "booting device..." |
| 220 | usbboot -c "boot" >> "${LOG_FILE}" || abort "can't boot device - xburst-tools setup correctly? device in boot-mode? device connected?" |
| 221 | |
| 222 | if [ "$ALL" == "TRUE" ]; then |
| 223 | log "clean bootloader env data ..." |
| 224 | usbboot -c "nerase 2 2 0 0" >> "${LOG_FILE}" 2>&1 |
| 225 | fi |
| 226 | if [ "$B" == "TRUE" ]; then |
| 227 | log "flashing bootloader..." |
| 228 | progress_prepare |
| 229 | while read ILINE |
| 230 | do progress_draw "$ILINE" |
| 231 | done< <(usbboot -c "nprog 0 ${WORKING_DIR}/${LOADER} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}") |
| 232 | progress_finish |
| 233 | test "${tmp}" && abort "error while flashing bootloader:\n${tmp}" |
| 234 | fi |
| 235 | if [ "$K" == "TRUE" ]; then |
| 236 | log "flashing kernel..." |
| 237 | progress_prepare |
| 238 | while read ILINE |
| 239 | do progress_draw "$ILINE" |
| 240 | done< <(usbboot -c "nprog 1024 ${WORKING_DIR}/${KERNEL} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}") |
| 241 | progress_finish |
| 242 | test "${tmp}" && abort "error while flashing kernel:\n${tmp}" |
| 243 | fi |
| 244 | if [ "$R" == "TRUE" ]; then |
| 245 | log "erase nand rootfs partition..." |
| 246 | usbboot -c "nerase 16 1024 0 0" >> "${LOG_FILE}" 2>&1 |
| 247 | log "flashing rootfs..." |
| 248 | progress_prepare |
| 249 | while read ILINE |
| 250 | do progress_draw "$ILINE" |
| 251 | done< <(usbboot -c "nprog 2048 ${WORKING_DIR}/${ROOTFS} 0 0 -n" 2>"${LOG_FILE}.err" | tee -a "${LOG_FILE}") |
| 252 | progress_finish |
| 253 | test "${tmp}" && abort "error while flashing rootfs:\n${tmp}" |
| 254 | fi |
| 255 | |
| 256 | if [ "$ALL" == "TRUE" ]; then |
| 257 | log "reboot device..." |
| 258 | usbboot -c "reset" >> "${LOG_FILE}" 2>&1 |
| 259 | fi |
| 260 | |
| 261 | log "done" |
| 262 |
