forked from AsahiLinux/asahi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-vendor-firmware
executable file
·79 lines (63 loc) · 1.92 KB
/
update-vendor-firmware
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
#!/bin/sh
# SPDX-License-Identifier: MIT
# NOTE: This script runs in the initramfs, so it must be ash/busybox compatible!
set -e
[ -e /etc/default/update-vendor-firmware ] && . /etc/default/update-vendor-firmware
if [ -e "$(dirname "$0")"/functions.sh ]; then
. "$(dirname "$0")"/functions.sh
else
. /usr/share/asahi-scripts/functions.sh
fi
: ${VENDORFW:=}
: ${TARGET_ROOT:=/}
: ${TARGET:=/lib/firmware/}
: ${TARGET_MANIFEST:=".vendorfw.manifest"}
umount=false
if [ -z "$VENDORFW" ]; then
mount_sys_esp /run/.system-efi
VENDORFW="/run/.system-efi/vendorfw/"
umount=true
fi
if [ ! -e "$VENDORFW" ]; then
echo "No vendor firmware available"
$umount && umount /run/.system-efi
exit 0
fi
if [ ! -e "$VENDORFW/manifest.txt" ]; then
echo "$VENDORFW/manifest.txt not found"
$umount && umount /run/.system-efi
exit 1
fi
if [ ! -e "$VENDORFW/firmware.tar" ]; then
echo "$VENDORFW/firmware.tar not found"
$umount && umount /run/.system-efi
exit 1
fi
cd "$TARGET_ROOT/$TARGET"
if [ -e "$TARGET_MANIFEST" ]; then
h_cur=$(sha1sum "$TARGET_MANIFEST" | cut -d" " -f1)
h_new=$(sha1sum "$VENDORFW/manifest.txt" | cut -d" " -f1)
if [ "$h_cur" == "$h_new" ]; then
echo "Vendor firmware is up to date, nothing to do."
$umount && umount /run/.system-efi
exit 0
fi
fi
echo "Extracting updated vendor firmware..."
tar xf "$VENDORFW/firmware.tar"
if [ -e "$TARGET_MANIFEST" ]; then
echo "Cleaning up obsolete firmware..."
sort "$TARGET_MANIFEST" > /run/vendorfw.manifest.tmp
sort "$VENDORFW/manifest.txt" | comm - \
/run/vendorfw.manifest.tmp -13 | \
while read -r type name rest; do
rm -v "$name" || true
dir="$(dirname "$name")"
rmdir "$dir" 2>/dev/null || true
done
rm /run/vendorfw.manifest.tmp
fi
cp "$VENDORFW/manifest.txt" "$TARGET_MANIFEST"
echo "Done"
$umount && umount /run/.system-efi
true