bmips: add new target
[openwrt/openwrt.git] / target / linux / bmips / base-files / lib / upgrade / platform.sh
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 PART_NAME=firmware
4 REQUIRE_IMAGE_METADATA=1
5
6 platform_check_image() {
7 return 0
8 }
9
10 cfe_jffs2_nand_upgrade() {
11 local tar_file="$1"
12 local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
13
14 if [ -z "$kernel_mtd" ]; then
15 echo "$CI_KERNPART partition not found"
16 return 1
17 fi
18
19 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
20 board_dir=${board_dir%/}
21
22 local kernel_length=$(tar xf $tar_file ${board_dir}/kernel -O | wc -c 2> /dev/null)
23 local rootfs_length=$(tar xf $tar_file ${board_dir}/root -O | wc -c 2> /dev/null)
24
25 if [ "$kernel_length" = 0 ]; then
26 echo "kernel cannot be empty"
27 return 1
28 fi
29
30 flash_erase -j /dev/mtd${kernel_mtd} 0 0
31 tar xf $tar_file ${board_dir}/kernel -O | nandwrite /dev/mtd${kernel_mtd} -
32
33 local rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
34
35 nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "0" "0"
36
37 local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
38
39 local root_ubivol="$(nand_find_volume $ubidev $CI_ROOTPART)"
40 tar xf $tar_file ${board_dir}/root -O | \
41 ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
42
43 nand_do_upgrade_success
44 }
45
46 platform_do_upgrade() {
47 case "$(board_name)" in
48 comtrend,ar-5315u|\
49 comtrend,ar-5387un|\
50 comtrend,vr-3025u|\
51 huawei,hg556a-b)
52 default_do_upgrade "$1"
53 ;;
54 comtrend,vr-3032u|\
55 netgear,dgnd3700-v2)
56 cfe_jffs2_nand_upgrade "$1"
57 ;;
58 esac
59 }