-
Notifications
You must be signed in to change notification settings - Fork 1
/
fw
80 lines (68 loc) · 1.93 KB
/
fw
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
device=/dev/mmcblk0
rootdev=`readlink /dev/root`
if [ "Xmmcblk0p3" == "X$rootdev" ]; then
update_kernel_part_index=4
current_kernel_part_index=2
elif [ "Xmmcblk0p5" == "X$rootdev" ]; then
update_kernel_part_index=2
current_kernel_part_index=4
else
echo error
exit 1
fi
confirm() {
cgpt add -i $current_kernel_part_index -S 1 /dev/mmcblk0
cgpt prioritize -i $current_kernel_part_index /dev/mmcblk0
}
update() {
[ -f "$1" ] || usage
kernel_sig=`hexdump -n 8 -e '"%_p"' $1`
rootfs_sig=`hexdump -n 4 -e '"%_p"' $1`
if [ "XCHROMEOS" == "X$kernel_sig" ]; then
update_part=/dev/mmcblk0p$update_kernel_part_index
elif [ "Xhsqs" == "X$rootfs_sig" ]; then
update_part=/dev/mmcblk0p$(($update_kernel_part_index + 1))
else
echo "Unknown file type"
usage
fi
current_success=`cgpt show -i $current_kernel_part_index -S $device`
if [ "$current_success" -ne 1 ]; then
echo Cannot update from an unsuccessful partition
exit 1
fi
dd if=$1 of=$update_part
cgpt add -i $update_kernel_part_index -S 0 -T 1 /dev/mmcblk0
cgpt prioritize -i $update_kernel_part_index /dev/mmcblk0
}
usage() {
echo "Usage:"
echo "$0 update file"
echo " Update the kernel or rootfs partition and make it bootable"
echo "$0 confirm"
echo " Set the success flag on current kernel partition"
echo "$0 boot"
echo " Boot the system"
exit 1
}
boot() {
cmdline="root=LABEL=root resume=LABEL=swap rootflags=subvol=root"
mount -r -t ext4 LABEL=boot /boot
kexec -l /boot/vmlinuz --initrd=/boot/initramfs.img --command-line="$cmdline"
kexec -e
}
case "$1" in
boot)
boot
;;
confirm)
confirm
;;
update)
update $2
;;
*)
usage
;;
esac