ipq806x: add support for Arris TR4400 v2 / RAC2V1A
[openwrt/openwrt.git] / target / linux / ipq806x / base-files / lib / upgrade / asrock.sh
1 . "$IPKG_INSTROOT/lib/functions.sh"
2
3 asrock_bootconfig_mangle() {
4 local mtdnum="$(find_mtd_index 0:bootconfig)"
5
6 if [ -z "$mtdnum" ]; then
7 echo "cannot find bootconfig mtd partition"
8 return 1
9 fi
10 dd if=/dev/mtd$mtdnum of=/tmp/mtd$mtdnum bs=1k
11
12 local partition_byte="$(dd if=/tmp/mtd$mtdnum bs=1 skip=52 count=1)"
13 local upgrade_byte="$(dd if=/tmp/mtd$mtdnum bs=1 skip=4 count=1)"
14
15 if [ $1 = "bootcheck" ]; then
16 if [ ! -s $upgrade_byte ]; then
17 dd if=/dev/mtd$mtdnum of=/tmp/mtd$mtdnum bs=1k
18 printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=4
19 printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=56
20 else
21 return 1
22 fi
23 elif [ $1 = "sysupgrade" ]; then
24 printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=4
25 printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=56
26 fi
27
28 if [ -s $partition_byte ]; then
29 printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=52
30 else
31 printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=52
32 fi
33
34 mtd write /tmp/mtd$mtdnum /dev/mtd$mtdnum
35 return 0
36 }
37
38 asrock_upgrade_prepare() {
39 local ubidev="$( nand_find_ubi ubi )"
40
41 #Set upgrade flag. If something goes wrong, router will boot with
42 #factory firmware.
43 asrock_bootconfig_mangle 'sysupgrade'
44
45 if [ $? -ne 0 ]; then
46 echo "cannot find bootconfig mtd partition"
47 exit 1
48 fi
49
50 # Just delete these partitions if present and use
51 # OpenWrt's standard names for those.
52 ubirmvol /dev/$ubidev -N ubi_rootfs &> /dev/null || true
53 ubirmvol /dev/$ubidev -N ubi_rootfs_data &> /dev/null || true
54 }