a2dd20a8810902661f54623fb6a55d7b4e6e07ff
[openwrt/svn-archive/archive.git] / target / linux / x86 / base-files / lib / upgrade / platform.sh
1 x86_get_rootfs() {
2 local rootfsdev
3 local rootfstype
4
5 rootfstype="$(awk 'BEGIN { RS=" "; FS="="; } ($1 == "rootfstype") { print $2 }' < /proc/cmdline)"
6 case "$rootfstype" in
7 squashfs|jffs2)
8 rootfsdev="$(awk 'BEGIN { RS=" "; FS="="; } ($1 == "block2mtd.block2mtd") { print substr($2,1,index($2, ",")-1) }' < /proc/cmdline)";;
9 ext4)
10 rootfsdev="$(awk 'BEGIN { RS=" "; FS="="; } ($1 == "root") { print $2 }' < /proc/cmdline)";;
11 esac
12
13 echo "$rootfstype:$rootfsdev"
14 }
15
16 platform_check_image() {
17 [ "$#" -gt 1 ] && return 1
18
19 case "$(get_magic_word "$1")" in
20 eb48|eb63) return 0;;
21 *)
22 echo "Invalid image type"
23 return 1
24 ;;
25 esac
26 }
27
28 platform_copy_config() {
29 local rootfs="$(x86_get_rootfs)"
30 local rootfsdev="${rootfs##*:}"
31
32 mount -t ext4 -o rw,noatime "${rootfsdev%[0-9]}1" /mnt
33 cp -af "$CONF_TAR" /mnt/
34 umount /mnt
35 }
36
37 platform_do_upgrade() {
38 local rootfs="$(x86_get_rootfs)"
39 local rootfsdev="${rootfs##*:}"
40
41 sync
42 [ -b ${rootfsdev%[0-9]} ] && get_image "$@" | dd of=${rootfsdev%[0-9]} bs=4096 conv=fsync
43 sleep 1
44 }