Root/scripts/reflash_ben.sh

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

Archive Download this file



interactive