treewide: use new procd sysupgrade $UPGRADE_BACKUP variable
[librecmc/librecmc.git] / target / linux / ath79 / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2011 OpenWrt.org
3 #
4
5 PART_NAME=firmware
6 REQUIRE_IMAGE_METADATA=1
7
8 redboot_fis_do_upgrade() {
9         local append
10         local sysup_file="$1"
11         local kern_part="$2"
12         local magic=$(get_magic_word "$sysup_file")
13
14         if [ "$magic" = "4349" ]; then
15                 local kern_length=0x$(dd if="$sysup_file" bs=2 skip=1 count=4 2>/dev/null)
16
17                 [ -f "$UPGRADE_BACKUP" -a "$UPGRADE_OPT_UPGRADE_OPT_SAVE_CONFIG" -eq 1 ] && append="-j $UPGRADE_BACKUP"
18                 dd if="$sysup_file" bs=64k skip=1 2>/dev/null | \
19                         mtd -r $append -F$kern_part:$kern_length:0x80060000,rootfs write - $kern_part:rootfs
20
21         elif [ "$magic" = "7379" ]; then
22                 local board_dir=$(tar tf $sysup_file | grep -m 1 '^sysupgrade-.*/$')
23                 local kern_length=$(tar xf $sysup_file ${board_dir}kernel -O | wc -c)
24
25                 [ -f "$UPGRADE_BACKUP" -a "$UPGRADE_OPT_UPGRADE_OPT_SAVE_CONFIG" -eq 1 ] && append="-j $UPGRADE_BACKUP"
26                 tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \
27                         mtd -r $append -F$kern_part:$kern_length:0x80060000,rootfs write - $kern_part:rootfs
28
29         else
30                 echo "Unknown image, aborting!"
31                 return 1
32         fi
33 }
34
35 platform_check_image() {
36         return 0
37 }
38
39 platform_do_upgrade() {
40         local board=$(board_name)
41
42         case "$board" in
43         jjplus,ja76pf2)
44                 redboot_fis_do_upgrade "$1" linux
45                 ;;
46         ubnt,routerstation|\
47         ubnt,routerstation-pro)
48                 redboot_fis_do_upgrade "$1" kernel
49                 ;;
50         *)
51                 default_do_upgrade "$1"
52                 ;;
53         esac
54 }