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