summaryrefslogtreecommitdiffstats
path: root/target/linux/mvebu/base-files/lib/preinit/81_linksys_syscfg
blob: 3edd82ebcdd124d7db9fd2867a36accabbb70a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# Copyright (C) 2014-2016 OpenWrt.org
# Copyright (C) 2016 LEDE-Project.org
#

preinit_mount_syscfg() {

	. /lib/functions.sh
	. /lib/mvebu.sh

	case $(mvebu_board_name) in
	armada-385-linksys-caiman|armada-385-linksys-cobra|armada-385-linksys-rango|armada-385-linksys-shelby|armada-xp-linksys-mamba)
		needs_recovery=0
		syscfg_part=$(grep syscfg /proc/mtd |cut -c4)
		ubiattach -m $syscfg_part || needs_recovery=1
		if [ $needs_recovery -eq 1 ]
		then
			echo "ubifs syscfg partition is damaged, reformatting"
			ubidetach -m $syscfg_part
			ubiformat -y -O 2048 -q /dev/mtd$syscfg_part
			ubiattach -m $syscfg_part
			ubimkvol /dev/ubi1 -n 0 -N syscfg -t dynamic --maxavsize
		fi
		mkdir /tmp/syscfg
		mount -t ubifs ubi1:syscfg /tmp/syscfg
		[ -f /tmp/syscfg/sysupgrade.tgz ] && {
		echo "- config restore -"
		cd /
		mv /tmp/syscfg/sysupgrade.tgz /tmp
		tar xzf /tmp/sysupgrade.tgz
		rm -f /tmp/sysupgrade.tgz
		sync
		}
		;;
	esac
}

boot_hook_add preinit_main preinit_mount_syscfg