ipq807x: add Redmi AX6
[openwrt/staging/jow.git] / target / linux / ipq807x / base-files / lib / upgrade / platform.sh
1 PART_NAME=firmware
2 REQUIRE_IMAGE_METADATA=1
3
4 RAMFS_COPY_BIN='fw_printenv fw_setenv'
5 RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
6
7 xiaomi_initramfs_prepare() {
8 # Wipe UBI if running initramfs
9 [ "$(rootfs_type)" = "tmpfs" ] || return 0
10
11 local rootfs_mtdnum="$( find_mtd_index rootfs )"
12 if [ ! "$rootfs_mtdnum" ]; then
13 echo "unable to find mtd partition rootfs"
14 return 1
15 fi
16
17 local kern_mtdnum="$( find_mtd_index ubi_kernel )"
18 if [ ! "$kern_mtdnum" ]; then
19 echo "unable to find mtd partition ubi_kernel"
20 return 1
21 fi
22
23 ubidetach -m "$rootfs_mtdnum"
24 ubiformat /dev/mtd$rootfs_mtdnum -y
25
26 ubidetach -m "$kern_mtdnum"
27 ubiformat /dev/mtd$kern_mtdnum -y
28 }
29
30 platform_check_image() {
31 return 0;
32 }
33
34 platform_pre_upgrade() {
35 case "$(board_name)" in
36 redmi,ax6|\
37 xiaomi,ax3600)
38 xiaomi_initramfs_prepare
39 ;;
40 esac
41 }
42
43 platform_do_upgrade() {
44 case "$(board_name)" in
45 redmi,ax6|\
46 xiaomi,ax3600)
47 # Make sure that UART is enabled
48 fw_setenv boot_wait on
49 fw_setenv uart_en 1
50
51 # Enforce single partition.
52 fw_setenv flag_boot_rootfs 0
53 fw_setenv flag_last_success 0
54 fw_setenv flag_boot_success 1
55 fw_setenv flag_try_sys1_failed 8
56 fw_setenv flag_try_sys2_failed 8
57
58 # Kernel and rootfs are placed in 2 different UBI
59 CI_KERN_UBIPART="ubi_kernel"
60 CI_ROOT_UBIPART="rootfs"
61 nand_do_upgrade "$1"
62 ;;
63 *)
64 default_do_upgrade "$1"
65 ;;
66 esac
67 }