Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 240 lines (210 sloc) 6.159 kB
9805f8f @Hexxeh Added initial version of update tool
authored
1 #!/bin/bash
2
80c9961 @Hexxeh Added self-updater
authored
3 set -o nounset
4 set -o errexit
5
dc9a0da @Hexxeh Really fix the repo URL...
authored
6 REPO_URI="http://github.com/Hexxeh/rpi-firmware"
16c2061 @Hexxeh Added support for installing a specific firmware revision
authored
7
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
8 UPDATE=${UPDATE:-1}
9 UPDATE_URI="https://github.com/Hexxeh/rpi-update/raw/master/rpi-update"
10
11 ROOT_PATH=${ROOT_PATH:-"/"}
12 BOOT_PATH=${BOOT_PATH:-"/boot"}
13 SKIP_KERNEL=${SKIP_KERNEL:-0}
5e8344a @Hexxeh Fix incorrect repo path
authored
14 FW_REPO="${REPO_URI}.git"
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
15 FW_REPOLOCAL="${ROOT_PATH}/root/.rpi-firmware"
16 FW_PATH="${BOOT_PATH}"
17 FW_MODPATH="${ROOT_PATH}/lib/modules"
18 FW_RAM=${1:-0}
16c2061 @Hexxeh Added support for installing a specific firmware revision
authored
19 FW_REV=${2:-""}
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
20 GITCMD="git --git-dir=\"${FW_REPOLOCAL}/.git\" --work-tree=\"${FW_REPOLOCAL}\""
21
22 function detect_split() {
23 if [[ -f "$FW_PATH/start.elf" && ${FW_RAM} -eq 0 ]]; then
e1c7f9e @Hexxeh Fix problem where memory split specified on cmdline was ignored
authored
24 echo "Autodetecting memory split"
872fc67 Add 240MB memory split option
Liam McLoughlin authored
25 FW_RAM=240
26 for R in 128 192 224 240
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
27 do
28 if [[ -f "$FW_PATH/arm${R}_start.elf" ]]
29 then
30 if diff "$FW_PATH/arm${R}_start.elf" "$FW_PATH/start.elf" >/dev/null
31 then
32 FW_RAM=$R
33 break
34 fi
35 fi
36 done
37 fi
38 FW_GPU=$((256-FW_RAM))
39 }
9805f8f @Hexxeh Added initial version of update tool
authored
40
80c9961 @Hexxeh Added self-updater
authored
41 function update_self() {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
42 echo "Performing self-update"
80c9961 @Hexxeh Added self-updater
authored
43 _tempFileName="$0.tmp"
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
44
45 if ! wget --quiet --output-document="${_tempFileName}" "${UPDATE_URI}"; then
bd0e2dd @Hexxeh Fixed readelf package names, added ldconfig call
authored
46 echo "Failed to download update for rpi-update!"
47 echo "Make sure you have ca-certificates installed and that the time is set correctly"
80c9961 @Hexxeh Added self-updater
authored
48 exit 1
49 fi
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
50
51 OCTAL_MODE=$(stat -c '%a' "$0")
52 if ! chmod ${OCTAL_MODE} "${_tempFileName}" ; then
53 echo "Failed: Error while trying to set mode on ${_tempFileName}"
80c9961 @Hexxeh Added self-updater
authored
54 exit 1
55 fi
56
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
57 cat > /tmp/updateScript.sh << EOF
80c9961 @Hexxeh Added self-updater
authored
58 #!/bin/bash
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
59 if mv "${_tempFileName}" "$0"; then
60 rm -- "\$0"
5c910a1 @DeadWalkingDeath Update rpi-update
DeadWalkingDeath authored
61 exec env UPDATE=0 /bin/bash "$0" "$FW_RAM" "$FW_REV"
80c9961 @Hexxeh Added self-updater
authored
62 else
63 echo "Failed!"
64 fi
65 EOF
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
66
67 exec /bin/bash /tmp/updateScript.sh
80c9961 @Hexxeh Added self-updater
authored
68 }
69
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
70 function update_modules {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
71 if [[ ${SKIP_KERNEL} -eq 0 ]]; then
72 cp -R "${FW_REPOLOCAL}/modules/"* "${FW_MODPATH}/"
73 find "${FW_REPOLOCAL}/modules" -mindepth 1 -maxdepth 1 -type d | while read DIR; do
74 depmod -b "${ROOT_PATH}" -a $(basename "${DIR}")
75 done
76 fi
80c9961 @Hexxeh Added self-updater
authored
77 }
48b6de4 @Hexxeh Add check for root
authored
78
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
79 function update_sdk {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
80 if [[ -f /etc/init.d/vcfiled ]]; then
81 /etc/init.d/vcfiled stop
82 fi
83
84 ELFOUTPUT=$(readelf -a "${ROOT_PATH}/bin/bash")
85 if [ "${ELFOUTPUT}" != "${ELFOUTPUT/VFP_args/}" ]; then
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
86 echo "Using HardFP libraries"
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
87 cp -R "${FW_REPOLOCAL}/vc/hardfp/"* "${ROOT_PATH}/"
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
88 else
89 echo "Using SoftFP libraries"
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
90 cp -R "${FW_REPOLOCAL}/vc/softfp/"* "${ROOT_PATH}/"
91 fi
92 cp -R "${FW_REPOLOCAL}/vc/sdk/"* "${ROOT_PATH}/"
93
94 if [[ -f /etc/init.d/vcfiled ]]; then
95 /etc/init.d/vcfiled start
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
96 fi
97 }
98
ecf2897 @Hexxeh Updated to store repo on root partition
authored
99 function set_split {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
100 cp "${FW_PATH}/arm${FW_RAM}_start.elf" "${FW_PATH}/start.elf"
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
101 }
102
ecf2897 @Hexxeh Updated to store repo on root partition
authored
103 function update_firmware {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
104 cp "${FW_REPOLOCAL}/"*.elf "${FW_PATH}/"
105 cp "${FW_REPOLOCAL}/"*.bin "${FW_PATH}/"
106 if [[ ${SKIP_KERNEL} -eq 0 ]]; then
107 cp "${FW_REPOLOCAL}/"*.img "${FW_PATH}/"
108 else
109 echo "Skipping kernel/modules updated as requested"
110 fi
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
111 }
112
bd0e2dd @Hexxeh Fixed readelf package names, added ldconfig call
authored
113 function finalise {
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
114 ldconfig -r "${ROOT_PATH}"
115 eval ${GITCMD} rev-parse master > "${FW_PATH}/.firmware_revision"
bd0e2dd @Hexxeh Fixed readelf package names, added ldconfig call
authored
116 sync
117 }
118
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
119 function download_repo {
120 echo "Setting up firmware (this will take a few minutes)"
121 mkdir -p "${FW_REPOLOCAL}"
122 git clone "${FW_REPO}" "${FW_REPOLOCAL}" --depth=1 --quiet
123 RETVAL=$?
124 if [[ ${RETVAL} -ne 0 ]]; then
125 echo "Failed to download new firmware files"
126 exit 1
127 fi
128 }
129
130 function update_repo {
131 echo "Updating firmware (this will take a few minutes)"
132 eval ${GITCMD} fetch --quiet
133 RETVAL=$?
134 if [[ ${RETVAL} -ne 0 ]]; then
135 echo "Failed to download updated firmware files"
136 exit 1
137 fi
16c2061 @Hexxeh Added support for installing a specific firmware revision
authored
138 eval ${GITCMD} reset --hard --quiet
139 eval ${GITCMD} clean -f -d --quiet
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
140 eval ${GITCMD} merge origin/master -m "automerge" --quiet
141 RETVAL=$?
142 if [[ ${RETVAL} -ne 0 ]]; then
143 echo "Failed to download updated firmware files"
144 exit 1
145 fi
146 }
147
148 function do_backup {
149 cp -a "${FW_PATH}" "${FW_PATH}.bak"
150 cp -a "${FW_MODPATH}" "${FW_MODPATH}.bak"
151 }
152
153 function do_update {
154 update_firmware
155 update_modules
156 update_sdk
157 set_split
158 finalise
159 echo "If no errors appeared, your firmware was successfully $1"
160 if [[ "${ROOT_PATH}" == "/" ]]; then
161 echo "A reboot is needed to activate the new firmware"
162 fi
163 }
164
16c2061 @Hexxeh Added support for installing a specific firmware revision
authored
165 function download_rev {
166 echo "Downloading specific firmware revision (this will take a few minutes)"
167 mkdir -p "${FW_REPOLOCAL}"
168 wget -q "${REPO_URI}/tarball/${FW_REV}" -O "${FW_REPOLOCAL}/${FW_REV}.tar.gz"
169 tar xzf "${FW_REPOLOCAL}/${FW_REV}.tar.gz" -C "${FW_REPOLOCAL}" --strip-components=1
170 rm "${FW_REPOLOCAL}/${FW_REV}.tar.gz"
171 }
172
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
173 if [[ ${EUID} -ne 0 ]]; then
7d3154e @Hexxeh Add check to make sure Git is installed before we attempt update/setup
authored
174 echo "This tool must be run as root"
48b6de4 @Hexxeh Add check for root
authored
175 exit 1
176 fi
177
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
178 if [[ ${UPDATE} -ne 0 ]]; then
179 echo "Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS"
80c9961 @Hexxeh Added self-updater
authored
180 update_self
181 fi
182
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
183 if [[ ( "${ROOT_PATH}" == "/" && "${BOOT_PATH}" != "/boot" ) ]] ||
184 [[ ( "${BOOT_PATH}" == "/boot" && "${ROOT_PATH}" != "/" ) ]]; then
185 echo "You need to specify both ROOT_PATH and BOOT_PATH, or neither"
186 exit 1
187 fi
188
189 if [[ ! -d "${FW_PATH}" ]]; then
190 echo "${FW_PATH} doesn't exist"
191 exit 1
192 fi
193 if [[ ! -f "${FW_PATH}/start.elf" ]]; then
194 echo "${FW_PATH}/start.elf doesn't exist."
195 exit 1
196 fi
197 if [[ ! -d "${FW_MODPATH}" ]]; then
198 echo "${FW_MODPATH} doesn't exist"
199 exit 1
200 fi
201
7d3154e @Hexxeh Add check to make sure Git is installed before we attempt update/setup
authored
202 command -v git >/dev/null 2>&1 || {
203 echo "This tool requires you have Git installed, please install it first"
204 echo "In Debian, try: sudo apt-get install git-core"
5f6ab29 @Hexxeh Update all ELFs and fix Arch install commands
authored
205 echo "In Arch, try: pacman -S git"
7d3154e @Hexxeh Add check to make sure Git is installed before we attempt update/setup
authored
206 exit 1
207 }
208
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
209 command -v readelf >/dev/null 2>&1 || {
210 echo "This tool requires you have readelf installed, please install it first"
bd0e2dd @Hexxeh Fixed readelf package names, added ldconfig call
authored
211 echo "In Debian, try: sudo apt-get install binutils"
5f6ab29 @Hexxeh Update all ELFs and fix Arch install commands
authored
212 echo "In Arch, try: pacman -S binutils"
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
213 exit 1
214 }
215
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
216 detect_split
872fc67 Add 240MB memory split option
Liam McLoughlin authored
217 if [[ ${FW_RAM} -ne 240 ]] &&[[ ${FW_RAM} -ne 224 ]] && [[ ${FW_RAM} -ne 192 ]] && [[ ${FW_RAM} -ne 128 ]]; then
218 echo "RAM value must be one of: 240, 224, 192, 128"
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
219 exit 1
220 fi
221 echo "Using ARM/GPU memory split of ${FW_RAM}MB/${FW_GPU}MB"
5c910a1 @DeadWalkingDeath Update rpi-update
DeadWalkingDeath authored
222 if [[ ${FW_REV} != "" ]]; then
16c2061 @Hexxeh Added support for installing a specific firmware revision
authored
223 download_rev
224 do_update "updated to revision ${FW_REV}"
225 elif [[ -f "${FW_REPOLOCAL}/.git/config" ]]; then
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
226 update_repo
227 if [[ -f "${FW_PATH}/.firmware_revision" ]] && [[ $(cat "${FW_PATH}/.firmware_revision") == $(eval ${GITCMD} rev-parse master) ]]; then
228 echo "Your firmware is already up to date"
76d8634 @Hexxeh Added VC libs update support and tidied the script up a little
authored
229 set_split
bd0e2dd @Hexxeh Fixed readelf package names, added ldconfig call
authored
230 finalise
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
231 else
232 do_update "updated"
9805f8f @Hexxeh Added initial version of update tool
authored
233 fi
e9c85cd @Hexxeh Added RAM split detection, added offline mode, added option to skip k…
authored
234 else
235 echo "We're running for the first time"
236 download_repo
237 do_backup
238 do_update "setup"
9805f8f @Hexxeh Added initial version of update tool
authored
239 fi
Something went wrong with that request. Please try again.