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