aboutsummaryrefslogtreecommitdiff
path: root/target/linux/mvebu/cortexa53/base-files/lib/preinit/82_uDPU
blob: 8d5a482b8290d8487a8d973356b3ca48d97c96e9 (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
39
40
41
42
43
44
45
46
47
48
49
#
# Copyright (C) 2014-2019 OpenWrt.org
# Copyright (C) 2016 LEDE-Project.org
#

preinit_mount_udpu() {
	. /lib/functions.sh
	. /lib/upgrade/common.sh

	case $(board_name) in
	methode,udpu|\
	methode,edpu)
		# Check which device is detected
		[ -b "/dev/mmcblk0" ] && mmcdev="/dev/mmcblk0" || mmcdev="/dev/mmcblk1"

		if [ -b "${mmcdev}p4" ]; then
			mkdir /misc
			mount -t f2fs ${mmcdev}p4 /misc
			[ -f "/misc/$BACKUP_FILE" ] && {
				echo "- Restoring configuration files -"
				tar xzf "/misc/$BACKUP_FILE" -C /
				rm -f "/misc/$BACKUP_FILE"
				sync
			}
			[ -f "/misc/firmware/recovery.itb" ] && {
					echo "- Updating /recovery partition -"
					mkfs.ext4 -q ${mmcdev}p2 | echo y &> /dev/null
					mkdir -p /tmp/recovery
					mount ${mmcdev}p2 /tmp/recovery
					cp /misc/firmware/recovery.itb /tmp/recovery
					[ -f "/misc/firmware/boot.scr" ] && \
						cp /misc/firmware/boot.scr /tmp/recovery
					sync
					umount /tmp/recovery
					rm -rf /tmp/recovery

					# Replace previous backup with the new one
					[ -d "/misc/firmware_old" ] && rm -rf /misc/firmware_old
					[ -d "/misc/firmware" ] && mv /misc/firmware /misc/firmware_old
				}
		fi

		# Legacy support - if rootfs was booted, instruct u-boot to keep the current root dev
		[ "$(df | grep /dev/root)" ] && fw_setenv root_ok '2'
	;;
	esac
}

boot_hook_add preinit_main preinit_mount_udpu