Root/
Source at commit 85ea640 created 13 years 10 months ago. By Mirko Vogt, kernel image name changed since the profile is now part of the image name(s) | |
---|---|
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 | KERNEL="openwrt-xburst-qi_lb60-uImage.bin" |
21 | #ROOTFS="openwrt-xburst-rootfs.ubi" |
22 | ROOTFS="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 |
31 | B="TRUE" |
32 | K="TRUE" |
33 | R="TRUE" |
34 | |
35 | while getopts d:l:bkr OPTIONS |
36 | do |
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 "\ |
54 | Usage: $0 [-d <version>] [-l <path to local images>] [-b] [-k] [-r] [-h] [-v] |
55 | |
56 | without 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 | |
69 | reflash script for qi-hardware Ben NanoNote |
70 | |
71 | written by: Mirko Vogt (mirko.vogt@sharism.cc) |
72 | Xiangfu Liu (xiangfu@sharism.cc) |
73 | |
74 | version: ${__VERSION__} |
75 | |
76 | Please report bugs to developer@lists.qi-hardware.com" |
77 | exit 1 |
78 | ;; |
79 | esac |
80 | done |
81 | |
82 | # if no arguments were given |
83 | if [ "$#" == "0" ]; then |
84 | B="TRUE" |
85 | K="TRUE" |
86 | R="TRUE" |
87 | fi |
88 | |
89 | # create working directory |
90 | mkdir -p ${WORKING_DIR} |
91 | date > "${LOG_FILE}" # purge logfile if exists |
92 | |
93 | function log() { |
94 | echo -e "$1" |
95 | echo -e "$1" >> "${LOG_FILE}" |
96 | } |
97 | |
98 | function 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 | |
113 | log "working dir: ${WORKING_DIR}" |
114 | log "chosen method: ${PROTOCOL}" |
115 | test ${VERSION} && log "chosen version: ${VERSION}" |
116 | log "===" |
117 | |
118 | if [ "$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 |
151 | fi |
152 | |
153 | log "booting device..." |
154 | usbboot -c "boot" >> "${LOG_FILE}" || abort "can't boot device - xburst-tools setup correctly? device in boot-mode? device connected?" |
155 | |
156 | if [ "$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}" |
160 | fi |
161 | if [ "$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}" |
165 | fi |
166 | if [ "$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}" |
172 | fi |
173 | log "done" |
174 |