bc19149d5c4de5a32984f34b27d1e9ce15c9593d
[openwrt/openwrt.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 routerstation_do_upgrade() {
9 local append
10 local sysup_file="$1"
11 local magic=$(get_magic_word "$sysup_file")
12
13 if [ "$magic" = "4349" ]; then
14 local kern_length=0x$(dd if="$sysup_file" bs=2 skip=1 count=4 2>/dev/null)
15
16 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
17 dd if="$sysup_file" bs=64k skip=1 2>/dev/null | \
18 mtd -r $append -Fkernel:$kern_length:0x80060000,rootfs write - kernel:rootfs
19
20 elif [ "$magic" = "7379" ]; then
21 local board_dir=$(tar tf $sysup_file | grep -m 1 '^sysupgrade-.*/$')
22 local kern_length=$(tar xf $sysup_file ${board_dir}kernel -O | wc -c)
23
24 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
25 tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \
26 mtd -r $append -Fkernel:$kern_length:0x80060000,rootfs write - kernel:rootfs
27
28 else
29 echo "Unknown image, aborting!"
30 return 1
31 fi
32 }
33
34 platform_check_image() {
35 return 0
36 }
37
38 platform_do_upgrade() {
39 local board=$(board_name)
40
41 case "$board" in
42 ubnt,routerstation|\
43 ubnt,routerstation-pro)
44 routerstation_do_upgrade "$ARGV"
45 ;;
46 *)
47 default_do_upgrade "$ARGV"
48 ;;
49 esac
50 }