Root/data/qi_lb60/scripts/reflash_ben.sh

1#!/bin/bash
2VERSION="latest"
3
4# use 'http' to download and flash images, use 'file' to flash images present in the <WORKING_DIR>
5PROTOCOL="http"
6
7# working directory
8#WORKING_DIR="/tmp/NanoNote/${VERSION}"
9WORKING_DIR="${HOME}/.qi/nanonote/ben/${VERSION}"
10
11# where the verbose output goes to
12LOG_FILE="${WORKING_DIR}/log.txt"
13
14# URL to images ($URL/$VERSION/$[images])
15#BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/Ben_NanoNote_2GB_NAND"
16BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/NanoNote/Ben"
17
18# names of images
19LOADER="openwrt-xburst-qi_lb60-u-boot.bin"
20#KERNEL="openwrt-xburst-uImage.bin"
21KERNEL="openwrt-xburst-qi_lb60-uImage.bin"
22#ROOTFS="openwrt-xburst-rootfs.ubi"
23ROOTFS="openwrt-xburst-qi_lb60-root.ubi"
24
25###############
26
27# version of script
28__VERSION__="2.1.1"
29
30
31# options for reflash bootloader, kernel or rootfs
32B="TRUE"
33K="TRUE"
34R="TRUE"
35
36while getopts d:l:bkr OPTIONS
37do
38    case $OPTIONS in
39    d)
40        VERSION=$OPTARG # override version by first argument if passed
41        B="TRUE"
42        K="TRUE"
43        R="TRUE"
44        ;;
45    l)
46        WORKING_DIR=$OPTARG
47        VERSION=
48        PROTOCOL="file"
49        B="TRUE"
50        K="TRUE"
51        R="TRUE"
52        ;;
53    *)
54        echo "\
55Usage: $0 [-d <version>] [-l <path to local images>] [-b] [-k] [-r] [-h] [-v]
56
57without any arguments, I will download and flash the latest official images
58(includes bootloader, kernel and rootfs)
59
60     -d <> I will download and flash a specific version of official images
61            (includes bootloader, kernel and rootfs)
62
63     -l <> I will flash images present in <arg>
64            (includes bootloader, kernel and rootfs -
65             missing files will be skipped)
66
67     -h you already found out
68
69 
70reflash script for qi-hardware Ben NanoNote
71
72written by: Mirko Vogt (mirko.vogt@sharism.cc)
73            Xiangfu Liu (xiangfu@sharism.cc)
74
75version: ${__VERSION__}
76
77Please report bugs to developer@lists.qi-hardware.com"
78        exit 1
79        ;;
80    esac
81done
82
83# if no arguments were given
84if [ "$#" == "0" ]; then
85    B="TRUE"
86    K="TRUE"
87    R="TRUE"
88fi
89
90# create working directory
91mkdir -p ${WORKING_DIR}
92date > "${LOG_FILE}" # purge logfile if exists
93
94function log() {
95    echo -e "$1"
96    echo -e "$1" >> "${LOG_FILE}"
97}
98
99function abort() {
100    log "==="
101    log "fatal error occured - ABORTED"
102    log "==="
103    log "$1"
104    log "==="
105    log "Before reporting this as a bug"
106    log "please ensure you're using the latest available version of"
107    log " this reflash script"
108    log " the xburst-tools"
109    exit 1
110}
111
112[ "$(whoami)" == "root" ] || abort "this script must be run as root"
113
114log "working dir: ${WORKING_DIR}"
115log "chosen method: ${PROTOCOL}"
116test ${VERSION} && log "chosen version: ${VERSION}"
117log "==="
118
119if [ "$PROTOCOL" == "http" ]; then
120
121    MD5SUMS_SERVER=$(wget -O - ${BASE_URL_HTTP}/${VERSION}/md5sums 2> /dev/null | grep -E "(${LOADER}|${KERNEL}|${ROOTFS})" | sort)
122    [ "${MD5SUMS_SERVER}" ] || abort "can't fetch files from server"
123    
124    MD5SUMS_LOCAL=$( (cd "${WORKING_DIR}" ; md5sum --binary "${LOADER}" "${KERNEL}" "${ROOTFS}" 2> /dev/null) | sort )
125
126    if [ "${MD5SUMS_SERVER}" == "${MD5SUMS_LOCAL}" ]; then
127        log "present files are identical to the ones on the server - do not download them again"
128    else
129        rm -f "${WORKING_DIR}/${LOADER}" "${WORKING_DIR}/${KERNEL}" "${WORKING_DIR}/${ROOTFS}"
130    if [ "$B" == "TRUE" ]; then
131        log "fetching bootloader..."
132        wget \
133            -a "${LOG_FILE}" \
134            -P "${WORKING_DIR}" \
135            "${BASE_URL_HTTP}/${VERSION}/${LOADER}"
136    fi
137    if [ "$K" == "TRUE" ]; then
138        log "fetching kernel..."
139        wget \
140            -a "${LOG_FILE}" \
141            -P "${WORKING_DIR}" \
142            "${BASE_URL_HTTP}/${VERSION}/${KERNEL}"
143    fi
144    if [ "$R" == "TRUE" ]; then
145        log "fetching rootfs..."
146        wget \
147            -a "${LOG_FILE}" \
148            -P "${WORKING_DIR}" \
149            "${BASE_URL_HTTP}/${VERSION}/${ROOTFS}"
150    fi
151    fi
152fi
153
154log "booting device..."
155usbboot -c "boot" >> "${LOG_FILE}" || abort "can't boot device - xburst-tools setup correctly? device in boot-mode? device connected?"
156
157if [ "$B" == "TRUE" ]; then
158    log "flashing bootloader..."
159    tmp=$(usbboot -c "nprog 0 ${WORKING_DIR}/${LOADER} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
160    test "${tmp}" && abort "error while flashing bootloader:\n${tmp}"
161fi
162if [ "$K" == "TRUE" ]; then
163    log "flashing kernel..."
164    tmp=$(usbboot -c "nprog 1024 ${WORKING_DIR}/${KERNEL} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
165    test "${tmp}" && abort "error while flashing kernel:\n${tmp}"
166fi
167if [ "$R" == "TRUE" ]; then
168    log "erase nand rootfs partition..."
169    usbboot -c "boot;nerase 16 1024 0 0" >> "${LOG_FILE}" 2>&1
170    log "flashing rootfs..."
171    tmp=$(usbboot -c "nprog 2048 ${WORKING_DIR}/${ROOTFS} 0 0 -n" 3>> "${LOG_FILE}" 2>&1 >&3)
172    test "${tmp}" && abort "error while flashing rootfs:\n${tmp}"
173fi
174log "done"
175

Archive Download this file



interactive