OpenWrt – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
4 | office | 1 | . /lib/functions.sh |
2 | |||
3 | # copied from x86's platform.sh |
||
4 | |||
5 | mbl_do_platform_check() { |
||
6 | local diskdev partdev diff |
||
7 | |||
8 | [ "$#" -gt 1 ] && return 1 |
||
9 | |||
10 | export_bootdevice && export_partdevice diskdev -2 || { |
||
11 | echo "Unable to determine upgrade device" |
||
12 | return 1 |
||
13 | } |
||
14 | |||
15 | get_partitions "/dev/$diskdev" bootdisk |
||
16 | |||
17 | #extract the boot sector from the image |
||
18 | get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null |
||
19 | |||
20 | get_partitions /tmp/image.bs image |
||
21 | |||
22 | #compare tables |
||
23 | diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" |
||
24 | |||
25 | rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image |
||
26 | |||
27 | if [ -n "$diff" ]; then |
||
28 | echo "Partition layout has changed. Full image will be written." |
||
29 | ask_bool 0 "Abort" && exit 1 |
||
30 | return 0 |
||
31 | fi |
||
32 | |||
33 | return 0; |
||
34 | } |
||
35 | |||
36 | mbl_do_upgrade() { |
||
37 | local diskdev partdev diff |
||
38 | |||
39 | export_bootdevice && export_partdevice diskdev -2 || { |
||
40 | echo "Unable to determine upgrade device" |
||
41 | return 1 |
||
42 | } |
||
43 | |||
44 | sync |
||
45 | |||
46 | if [ "$SAVE_PARTITIONS" = "1" ]; then |
||
47 | get_partitions "/dev/$diskdev" bootdisk |
||
48 | |||
49 | #extract the boot sector from the image |
||
50 | get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b |
||
51 | |||
52 | get_partitions /tmp/image.bs image |
||
53 | |||
54 | #compare tables |
||
55 | diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" |
||
56 | else |
||
57 | diff=1 |
||
58 | fi |
||
59 | |||
60 | if [ -n "$diff" ]; then |
||
61 | get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync |
||
62 | |||
63 | # Separate removal and addtion is necessary; otherwise, partition 1 |
||
64 | # will be missing if it overlaps with the old partition 2 |
||
65 | partx -d - "/dev/$diskdev" |
||
66 | partx -a - "/dev/$diskdev" |
||
67 | |||
68 | return 0 |
||
69 | fi |
||
70 | |||
71 | #iterate over each partition from the image and write it to the boot disk |
||
72 | while read part start size; do |
||
73 | # root is /dev/sd[a|b]2 and not /dev/sd[a|b] this causes some problem |
||
74 | # one of which is this offset, I'm not sure what's the best fix, so |
||
75 | # here's a WA. |
||
76 | let part=$((part - 2)) |
||
77 | if export_partdevice partdev $part; then |
||
78 | echo "Writing image to /dev/$partdev..." |
||
79 | get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync |
||
80 | else |
||
81 | echo "Unable to find partition $part device, skipped." |
||
82 | fi |
||
83 | done < /tmp/partmap.image |
||
84 | |||
85 | #copy partition uuid |
||
86 | echo "Writing new UUID to /dev/$diskdev..." |
||
87 | get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync |
||
88 | } |
||
89 | |||
90 | mbl_copy_config() { |
||
91 | local partdev |
||
92 | |||
93 | # Same as above /dev/sd[a|b]2 is root, so /boot is -1 |
||
94 | if export_partdevice partdev -1; then |
||
95 | mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt |
||
96 | cp -af "$CONF_TAR" /mnt/ |
||
97 | umount /mnt |
||
98 | fi |
||
99 | } |