mvebu: reformat the damaged syscfg partition on the mamba
[openwrt-github/.git] / target / linux / mvebu / base-files / lib / preinit / 81_linksys_syscfg
1 #
2 # Copyright (C) 2014 OpenWrt.org
3 #
4
5 preinit_mount_syscfg() {
6
7         . /lib/functions.sh
8         . /lib/mvebu.sh
9
10         case $(mvebu_board_name) in
11         armada-xp-mamba)
12                 needs_recovery=0
13                 ubiattach -m 8 || needs_recovery=1
14                 if [ $needs_recovery -eq 1 ]
15                 then
16                         echo "ubifs syscfg partition is damaged, reformatting"
17                         ubidetach -m 8
18                         ubiformat -y -O 2048 -q /dev/mtd8
19                         ubiattach -m 8
20                         ubimkvol /dev/ubi1 -n 0 -N syscfg -t dynamic --maxavsize
21                 fi
22                 mkdir /tmp/syscfg
23                 mount -t ubifs ubi1:syscfg /tmp/syscfg
24                 [ -f /tmp/syscfg/sysupgrade.tgz ] && {
25                 echo "- config restore -"
26                 cd /
27                 mv /tmp/syscfg/sysupgrade.tgz /tmp
28                 tar xzf /tmp/sysupgrade.tgz
29                 rm -f /tmp/sysupgrade.tgz
30                 sync
31                 }
32                 ;;
33         esac
34 }
35
36 boot_hook_add preinit_main preinit_mount_syscfg