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