bcm63xx: use the generic nand upgrade on Sercomm devices
[openwrt/staging/noltari.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 huawei,hg253s-v2|\
11 netgear,dgnd3700-v2|\
12 sercomm,ad1018|\
13 sercomm,h500-s-lowi|\
14 sercomm,h500-s-vfes)
15 # NAND sysupgrade
16 return 0
17 ;;
18 esac
19
20 case "$(get_magic_word "$1")" in
21 3600|3700|3800)
22 # CFE tag versions
23 return 0
24 ;;
25 *)
26 echo "Invalid image type. Please use only .bin files"
27 return 1
28 ;;
29 esac
30 }
31
32 cfe_jffs2_upgrade_tar() {
33 local tar_file="$1"
34 local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
35
36 if [ -z "$kernel_mtd" ]; then
37 echo "$CI_KERNPART partition not found"
38 return 1
39 fi
40
41 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
42 board_dir=${board_dir%/}
43
44 local kernel_length=$(tar xf $tar_file ${board_dir}/kernel -O | wc -c 2> /dev/null)
45 local rootfs_length=$(tar xf $tar_file ${board_dir}/root -O | wc -c 2> /dev/null)
46
47 if [ "$kernel_length" = 0 ]; then
48 echo "kernel cannot be empty"
49 return 1
50 fi
51
52 flash_erase -j /dev/mtd${kernel_mtd} 0 0
53 tar xf $tar_file ${board_dir}/kernel -O | nandwrite /dev/mtd${kernel_mtd} -
54
55 local rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
56
57 nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "0" "0"
58
59 local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
60
61 local root_ubivol="$(nand_find_volume $ubidev $CI_ROOTPART)"
62 tar xf $tar_file ${board_dir}/root -O | \
63 ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
64
65 nand_do_upgrade_success
66 }
67
68 platform_do_upgrade() {
69 case "$(board_name)" in
70 comtrend,vg-8050|\
71 comtrend,vr-3032u|\
72 huawei,hg253s-v2|\
73 netgear,dgnd3700-v2)
74 REQUIRE_IMAGE_METADATA=1
75 cfe_jffs2_upgrade_tar "$1"
76 ;;
77 sercomm,ad1018|\
78 sercomm,h500-s-lowi|\
79 sercomm,h500-s-vfes)
80 REQUIRE_IMAGE_METADATA=1
81 nand_do_upgrade "$1"
82 ;;
83 *)
84 default_do_upgrade "$1"
85 ;;
86 esac
87 }