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