bcm63xx: add unmodded SERCOMM AD1018 support
[openwrt/openwrt.git] / target / linux / bcm63xx / base-files / lib / upgrade / platform.sh
1 PART_NAME=linux
2 REQUIRE_IMAGE_METADATA=0
3
4 platform_check_image() {
5 [ "$#" -gt 1 ] && return 1
6
7 case "$(board_name)" in
8 comtrend,vg-8050|\
9 comtrend,vr-3032u|\
10 netgear,dgnd3700-v2|\
11 sercomm,ad1018)
12 # NAND sysupgrade
13 return 0
14 ;;
15 esac
16
17 case "$(get_magic_word "$1")" in
18 3600|3700|3800)
19 # CFE tag versions
20 return 0
21 ;;
22 *)
23 echo "Invalid image type. Please use only .bin files"
24 return 1
25 ;;
26 esac
27 }
28
29 cfe_jffs2_upgrade_tar() {
30 local tar_file="$1"
31 local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
32
33 if [ -z "$kernel_mtd" ]; then
34 echo "$CI_KERNPART partition not found"
35 return 1
36 fi
37
38 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
39 board_dir=${board_dir%/}
40
41 local kernel_length=$(tar xf $tar_file ${board_dir}/kernel -O | wc -c 2> /dev/null)
42 local rootfs_length=$(tar xf $tar_file ${board_dir}/root -O | wc -c 2> /dev/null)
43
44 if [ "$kernel_length" = 0 ]; then
45 echo "kernel cannot be empty"
46 return 1
47 fi
48
49 flash_erase -j /dev/mtd${kernel_mtd} 0 0
50 tar xf $tar_file ${board_dir}/kernel -O | nandwrite /dev/mtd${kernel_mtd} -
51
52 local rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
53
54 nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "0" "0"
55
56 local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
57
58 local root_ubivol="$(nand_find_volume $ubidev $CI_ROOTPART)"
59 tar xf $tar_file ${board_dir}/root -O | \
60 ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
61
62 nand_do_upgrade_success
63 }
64
65 platform_do_upgrade() {
66 case "$(board_name)" in
67 comtrend,vg-8050|\
68 comtrend,vr-3032u|\
69 netgear,dgnd3700-v2|\
70 sercomm,ad1018)
71 REQUIRE_IMAGE_METADATA=1
72 cfe_jffs2_upgrade_tar "$1"
73 ;;
74 *)
75 default_do_upgrade "$1"
76 ;;
77 esac
78 }