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