-
Notifications
You must be signed in to change notification settings - Fork 4
/
install-rpi-boot.sh
executable file
·134 lines (114 loc) · 3.02 KB
/
install-rpi-boot.sh
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/sh
# immediately exit on any unhandled error
set -e
# current working directory
cwd=${0%/*}
. $cwd/lib/sh/utils.sh
. $cwd/config.sh
#
# Print the help message
#
cmd_help() {
cat <<EOF
Usage: $0 [--help] <sdcard-block-device>
Download and install into the block device the Raspberry Pi's firmware
& bootloader, and Farjump's Alpha. The block device must
contain a FAT file-system.
Note that the block device is mounted and finally unmounted during the
execution of this scripts, which requires root privileges.
EXAMPLE
\$ mkfs.vfat -F 32 -n RPI /dev/sdX # /!\ erases everything in sdX
\$ $0 /dev/sdX
EOF
}
#
# Mount the SD card block device `$1` into `$cfg_sdcard_mountpoint`.
#
cmd_mount() {
dev="$1"
log_info "Temporarily mounting \`$dev\` into \`$cfg_sdcard_mountpoint\`"
mkdir -p $cfg_sdcard_mountpoint
sudo mount -t vfat -o rw,umask=0000 "$dev" $cfg_sdcard_mountpoint
}
#
# Unmount `$cfg_sdcard_mountpoint`
#
cmd_unmount() {
log_info "Un-mounting \`$cfg_sdcard_mountpoint\`"
sync $cfg_sdcard_mountpoint/*
sudo umount $cfg_sdcard_mountpoint
}
#
# Download official firmwares from the RPi repo
#
cmd_download_files() {
dst="$1"
if ! cmd_check_fw_sha256 $dst --quiet 1>&- 2>&-; then
log_info "Downloading the Raspberry Pi's firmware version $cfg_rpi_fw_version"
(
cd $dst
curl -fSL --remote-name-all --progress-bar $cfg_rpi_fw_baseurl/start.elf $cfg_rpi_fw_baseurl/bootcode.bin
)
fi
}
#
# Copy downloaded files into the mounted SD card and check the file integrity.
#
cmd_copy_files() {
src=$1
log_info "Installing the RPi firmware and the Alpha debugger"
cp -fv $src/bootcode.bin $src/start.elf $src/Alpha.bin $src/config.txt $cfg_sdcard_mountpoint
log_info "Checking the integrity"
cmd_check_fw_sha256 $cfg_sdcard_mountpoint
echo "$cfg_alpha_sha256 $cfg_sdcard_mountpoint/Alpha.bin" | sha256sum -c -
}
#
# Check the sha256sum of the firmware stored in $1.
# Optionally pass an extra sha256sum argument as $2.
#
cmd_check_fw_sha256() {
( echo "$cfg_bootcode_download_sha256 $1/bootcode.bin" | sha256sum -c $2 - ) || return 1
echo "$cfg_start_download_sha256 $1/start.elf" | sha256sum -c $2 -
}
#
# script entry function
#
cmd() {
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
cmd_help
return 1 # note: doing this makes only one --help message possible
;;
-*)
log_error "$0: illegal option −− $1"
return 1
;;
--)
shift
;;
*)
[ -n "$dev" ] && log_info "warning: ignoring \`$dev\`"
dev="$1"
shift
;;
esac
done
if [ -z "$dev" ]; then
log_error " missing block device argument"
return 1
fi
src='boot'
cmd_download_files $src
cmd_mount "$dev"
trap 'cmd_unmount "$dev"' INT QUIT KILL ABRT
if ! cmd_copy_files $src; then
cmd_unmount "$dev"
return 1
fi
cmd_unmount "$dev"
log_info 'Your SD card is ready!'
log_info "You can now insert it into the RPi and use Alpha through the RPI's Mini-UART"
return 0
}
cmd $@