forked from raspberrypi/rpi-eeprom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-recovery-images
executable file
·75 lines (66 loc) · 1.68 KB
/
make-recovery-images
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
#!/bin/sh
set -e
die() {
echo "$@" >&2
exit 1
}
cleanup() {
if [ -d "${TMP_DIR}" ]; then
rm -rf "${TMP_DIR}"
fi
}
trap cleanup EXIT
[ "$(id -u)" = "0" ] || die "$(basename $0) must be run as root"
[ -n "${SUDO_UID}" ] || die "SUDO_UID not defined"
[ -n "${SUDO_GID}" ] || die "SUDO_GID not defined"
build_images()
{
chip="$1"
for src in release-${chip}/*.zip; do
src=$(basename "${src}")
img=$(echo "${src}" | sed 's/\.zip/.img/')
TMP_DIR=$(mktemp -d)
(
cp "release-${chip}/${src}" "${TMP_DIR}"
mkdir "${TMP_DIR}/files"
cd "${TMP_DIR}/files"
unzip "../${src}"
cd "${TMP_DIR}"
dd if=/dev/zero bs=1M count=258 of=temp.img
/sbin/sfdisk temp.img <<EOF
label: dos
label-id: 0x0a7b5ac5
device: temp.img
unit: sectors
./test.img1 : start= 2048, size= 524288, type=c
EOF
file temp.img
kpartx -lv temp.img | head -n1 | awk '{print $1}'
LOOP="/dev/mapper/$(kpartx -lv temp.img | head -n1 | awk '{print $1}')"
kpartx -av temp.img
/sbin/mkfs.fat -F 32 -s 1 "${LOOP}"
mkdir fs
mount "${LOOP}" fs
cp -v files/* fs
sync
sleep 5
umount fs
# Delay before calling kpartx otherwise it's sometimes possible to get orphaned loopback devices
sleep 5
kpartx -dv temp.img
)
image_dir="images-${chip}"
mkdir -p "${image_dir}"
chown "${SUDO_UID}:${SUDO_GID}" "${image_dir}"
mv "${TMP_DIR}/temp.img" "${image_dir}/${img}"
file "${image_dir}/${img}"
cd "${image_dir}"
zip "${src}" "${img}"
cd ..
rm "${image_dir}/${img}"
chown "${SUDO_UID}:${SUDO_GID}" "${image_dir}/${src}"
done
echo "Wrote images for rpi-imager to $(pwd)/${image_dir}/${src}"
}
build_images 2711
build_images 2712