forked from mendersoftware/meta-mender-community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredundant-boot-install-script-uboot
62 lines (57 loc) · 1.89 KB
/
redundant-boot-install-script-uboot
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
#!/bin/sh
mnt=
cleanup() {
[ -n "$mnt" ] || return
for d in sys proc dev; do
if mountpoint -q "${mnt}/${d}"; then
umount "${mnt}/${d}" >/dev/null 2>&1 || true
fi
done
if mountpoint -q "$mnt"; then
umount "$mnt" >/dev/null 2>&1 || true
fi
rmdir "$mnt" >/dev/null 2>&1 || true
}
echo "Installing NVIDIA bootloader update payload"
num_slots=`nvbootctrl get-number-slots`
if [ $num_slots != 2 ]; then
echo "Enabling A/B update mode using nv_update_engine"
nv_update_engine --enable-ab
fi
current_slot=`nvbootctrl get-current-slot`
echo "Current boot slot: $current_slot"
new_boot_part=`fw_printenv -n mender_boot_part`
mnt=`mktemp -d -t nvbup.XXXXXX`
if [ -z "$mnt" -o ! -d "$mnt" ]; then
echo "ERR: could not create directory for mounting install partition" >&2
exit 1
fi
mount /dev/mmcblk0p${new_boot_part} "$mnt"
if [ ! -d "${mnt}/opt/ota_package" ]; then
echo "ERR: Missing /opt/ota_package directory in installed rootfs" >&2
cleanup
exit 1
fi
# nv_update_engine needs access to these filesystems,
# so bind-mount them into the new rootfs for the chroot
mount --bind /sys "${mnt}/sys"
mount --bind /proc "${mnt}/proc"
mount --bind /dev "${mnt}/dev"
# Run the update engine in the context of the just-installed rootfs
# to ensure that the TNSPEC in the config file it uses matches the
# TNSPEC in the update payload. But first we have to set up the
# configuration file with the TNSPEC.
if [ -L "${mnt}/etc/nv_boot_control.conf" -a -x "${mnt}/usr/bin/setup-nv-boot-control" ]; then
rm "${mnt}/etc/nv_boot_control.conf"
if ! chroot "${mnt}" /usr/bin/setup-nv-boot-control; then
echo "ERR: could not initialize nv_boot_control.conf in new rootfs" >&2
fi
fi
if ! chroot "${mnt}" /usr/sbin/nv_update_engine --install no-reboot; then
echo "ERR: bootloader update failed" >&2
cleanup
exit 1
fi
echo "Successful bootloader update"
cleanup
exit 0