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