Root/
Source at commit cae16156304573584813d7b1c464001152f8726d created 13 years 4 months ago. By Xiangfu Liu, move NanoNote special files(build, reflash_ben.sh) to data/ folder | |
---|---|
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 | BASE_URL_HTTP="http://downloads.qi-hardware.com/software/images/NanoNote/Ben" |
17 | |
18 | # names of images |
19 | LOADER="openwrt-xburst-qi_lb60-u-boot.bin" |
20 | #KERNEL="openwrt-xburst-uImage.bin" |
21 | KERNEL="openwrt-xburst-qi_lb60-uImage.bin" |
22 | #ROOTFS="openwrt-xburst-rootfs.ubi" |
23 | ROOTFS="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 |
32 | B="TRUE" |
33 | K="TRUE" |
34 | R="TRUE" |
35 | |
36 | while getopts d:l:bkr OPTIONS |
37 | do |
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 "\ |
55 | Usage: $0 [-d <version>] [-l <path to local images>] [-b] [-k] [-r] [-h] [-v] |
56 | |
57 | without 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 | |
70 | reflash script for qi-hardware Ben NanoNote |
71 | |
72 | written by: Mirko Vogt (mirko.vogt@sharism.cc) |
73 | Xiangfu Liu (xiangfu@sharism.cc) |
74 | |
75 | version: ${__VERSION__} |
76 | |
77 | Please report bugs to developer@lists.qi-hardware.com" |
78 | exit 1 |
79 | ;; |
80 | esac |
81 | done |
82 | |
83 | # if no arguments were given |
84 | if [ "$#" == "0" ]; then |
85 | B="TRUE" |
86 | K="TRUE" |
87 | R="TRUE" |
88 | fi |
89 | |
90 | # create working directory |
91 | mkdir -p ${WORKING_DIR} |
92 | date > "${LOG_FILE}" # purge logfile if exists |
93 | |
94 | function log() { |
95 | echo -e "$1" |
96 | echo -e "$1" >> "${LOG_FILE}" |
97 | } |
98 | |
99 | function 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 | |
114 | log "working dir: ${WORKING_DIR}" |
115 | log "chosen method: ${PROTOCOL}" |
116 | test ${VERSION} && log "chosen version: ${VERSION}" |
117 | log "===" |
118 | |
119 | if [ "$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 |
152 | fi |
153 | |
154 | log "booting device..." |
155 | usbboot -c "boot" >> "${LOG_FILE}" || abort "can't boot device - xburst-tools setup correctly? device in boot-mode? device connected?" |
156 | |
157 | if [ "$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}" |
161 | fi |
162 | if [ "$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}" |
166 | fi |
167 | if [ "$R" == "TRUE" ]; then |
168 | log "erase nand rootfs partition..." |
169 | usbboot -c "boot;nerase 16 512 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}" |
173 | fi |
174 | log "done" |
175 |