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