/
rpi-update
executable file
·134 lines (114 loc) · 3.19 KB
/
rpi-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
set -o nounset
set -o errexit
UPDATE=${2:-1}
UPDATE_URI="https://raw.github.com/Hexxeh/rpi-update/master/rpi-update"
FW_REPO="git://github.com/Hexxeh/rpi-firmware.git"
FW_PATH="/boot"
FW_RAM=${1:-224}
FW_GPU=$((256-FW_RAM))
function update_self() {
echo "Performing self-update"
_tempFileName="$0.tmp"
_payloadName="$0.payload"
if ! wget --quiet --output-document="$_payloadName" $UPDATE_URI ; then
echo "Failed: Error while trying to wget new version!"
echo "File requested: $UPDATE_URI"
exit 1
fi
_interpreter=$(head --lines=1 "$0")
echo $_interpreter > "$_tempFileName"
tail --lines=+2 "$_payloadName" >> "$_tempFileName"
rm "$_payloadName"
OCTAL_MODE=$(stat -c '%a' $0)
if ! chmod $OCTAL_MODE "$_tempFileName" ; then
echo "Failed: Error while trying to set mode on $_tempFileName."
exit 1
fi
cat > updateScript.sh << EOF
#!/bin/bash
if mv "$_tempFileName" "$0"; then
rm -- \$0
exec /bin/bash $0 ${FW_RAM} 0
else
echo "Failed!"
fi
EOF
exec /bin/bash updateScript.sh "$@"
}
function update_modules {
cp -R ${FW_PATH}/modules/* /lib/modules/
for D in `find ${FW_PATH}/modules -mindepth 1 -maxdepth 1 -type d`; do
depmod -a `basename $D`
done
}
function update_sdk {
ELFOUTPUT=`readelf -a /bin/bash`
if [ "$ELFOUTPUT" != "${ELFOUTPUT/VFP_args/}" ]; then
echo "Using HardFP libraries"
cp -R ${FW_PATH}/vc/hardfp/* /
else
echo "Using SoftFP libraries"
cp -R ${FW_PATH}/vc/softfp/* /
fi
cp -R ${FW_PATH}/vc/sdk/* /
}
function restore_configs {
cp ${FW_PATH}.bak/*.txt ${FW_PATH}/ &> /dev/null
}
function set_split {
cp ${FW_PATH}/arm${FW_RAM}_start.elf ${FW_PATH}/start.elf
}
if [[ $EUID -ne 0 ]]; then
echo "This tool must be run as root"
exit 1
fi
if [[ $UPDATE -ne 0 ]]; then
echo "Raspberry Pi firmware updater by Hexxeh"
update_self
fi
echo "Come back later, rpi-update needs patching up"
exit 0
command -v git >/dev/null 2>&1 || {
echo "This tool requires you have Git installed, please install it first"
echo "In Debian, try: sudo apt-get install git-core"
echo "In Arch, try: pacman -Sy git"
exit 1
}
command -v readelf >/dev/null 2>&1 || {
echo "This tool requires you have readelf installed, please install it first"
echo "In Debian, try: sudo apt-get install readelf"
echo "In Arch, try: pacman -Sy readelf"
exit 1
}
echo "Using memory split of ${FW_RAM}MB/${FW_GPU}MB"
GITCMD="git --git-dir=${FW_PATH}/.git --work-tree=${FW_PATH}"
if $($GITCMD rev-parse &> /dev/null); then
echo "Updating firmware (this will take a few minutes)"
rm -f ${FW_PATH}/start.elf
$GITCMD fetch --quiet
$GITCMD merge origin/master -m "automerge" --quiet
update_modules
update_sdk
set_split
sync
echo "If no errors appeared, your firmware was successfully updated"
else
echo "We're running for the first time"
echo "Setting up firmware (this will take a few minutes)"
cp -R ${FW_PATH} ${FW_PATH}.bak
rm -rf /boot &> /dev/null
git clone ${FW_REPO} ${FW_PATH} --depth=1 --quiet
RETVAL=$?
if [[ $RETVAL != 0 ]]; then
echo "We failed! Attmepting to restore your original firmware"
cp -R ${FW_PATH}.bak/* ${FW_PATH}/
else
update_modules
update_sdk
restore_configs
set_split
sync
echo "If no errors appeared, your firmware was successfully setup"
fi
fi