a451de3779ee0c1fadec48a19982c30adff298ec
[openwrt/openwrt.git] / target / linux / imx / base-files / lib / imx.sh
1 #
2 # Copyright (C) 2010-2013 OpenWrt.org
3 #
4
5 rootpartuuid() {
6 local cmdline=$(cat /proc/cmdline)
7 local bootpart=${cmdline##*root=}
8 bootpart=${bootpart%% *}
9 local uuid=${bootpart#PARTUUID=}
10 echo ${uuid%-02}
11 }
12
13 bootdev_from_uuid() {
14 blkid | grep "PTUUID=\"$(rootpartuuid)\"" | cut -d : -f1
15 }
16
17 bootpart_from_uuid() {
18 blkid | grep $(rootpartuuid)-01 | cut -d : -f1
19 }
20
21 rootpart_from_uuid() {
22 blkid | grep $(rootpartuuid)-02 | cut -d : -f1
23 }
24
25 imx_sdcard_mount_boot() {
26 mkdir -p /boot
27 [ -f /boot/uImage ] || {
28 mount -o rw,noatime $(bootpart_from_uuid) /boot > /dev/null
29 }
30 }
31
32 imx_sdcard_copy_config() {
33 imx_sdcard_mount_boot
34 cp -af "$UPGRADE_BACKUP" "/boot/$BACKUP_FILE"
35 sync
36 umount /boot
37 }
38
39 imx_sdcard_do_upgrade() {
40 local board_dir="$(tar tf "${1}" | grep -m 1 '^sysupgrade-.*/$')"
41 board_dir="${board_dir%/}"
42
43 imx_sdcard_mount_boot
44 get_image "$1" | tar Oxf - ${board_dir}/kernel > /boot/uImage
45 get_image "$1" | tar Oxf - ${board_dir}/root > $(rootpart_from_uuid)
46 sync
47 umount /boot
48 }
49
50 imx_sdcard_pre_upgrade() {
51 [ -z "$UPGRADE_BACKUP" ] && {
52 jffs2reset -y
53 umount /overlay
54 }
55 }
56
57 imx_sdcard_move_config() {
58 if [ -b $(bootpart_from_uuid) ]; then
59 imx_sdcard_mount_boot
60 [ -f "/boot/$BACKUP_FILE" ] && mv -f "/boot/$BACKUP_FILE" /
61 umount /boot
62 fi
63 }