layerscape: add FRWY-LS1046A board support
[openwrt/openwrt.git] / target / linux / layerscape / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright 2015-2019 Traverse Technologies
3 # Copyright 2020 NXP
4 #
5
6 RAMFS_COPY_BIN="/usr/sbin/fw_printenv /usr/sbin/fw_setenv /usr/sbin/ubinfo /bin/echo"
7 RAMFS_COPY_DATA="/etc/fw_env.config /var/lock/fw_printenv.lock"
8
9 REQUIRE_IMAGE_METADATA=1
10
11 platform_do_upgrade_sdboot() {
12 local diskdev partdev parttype=ext4
13 local tar_file="$1"
14 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
15 board_dir=${board_dir%/}
16
17 export_bootdevice && export_partdevice diskdev 0 || {
18 echo "Unable to determine upgrade device"
19 return 1
20 }
21
22 if export_partdevice partdev 1; then
23 mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
24 echo "Writing kernel..."
25 tar xf $tar_file ${board_dir}/kernel -O > /mnt/fitImage
26 umount /mnt
27 fi
28
29 echo "Erasing rootfs..."
30 dd if=/dev/zero of=/dev/mmcblk0p2 bs=1M > /dev/null 2>&1
31 echo "Writing rootfs..."
32 tar xf $tar_file ${board_dir}/root -O | dd of=/dev/mmcblk0p2 bs=512k > /dev/null 2>&1
33
34 }
35 platform_do_upgrade_traverse_nandubi() {
36 bootsys=$(fw_printenv bootsys | awk -F= '{{print $2}}')
37 newbootsys=2
38 if [ "$bootsys" -eq "2" ]; then
39 newbootsys=1
40 fi
41
42 # If nand_do_upgrade succeeds, we don't have an opportunity to add any actions of
43 # our own, so do it here and set back on failure
44 echo "Setting bootsys to #${newbootsys}"
45 fw_setenv bootsys $newbootsys
46 CI_UBIPART="nandubi"
47 CI_KERNPART="kernel${newbootsys}"
48 CI_ROOTPART="rootfs${newbootsys}"
49 nand_do_upgrade "$1" || (echo "Upgrade failed, setting bootsys ${bootsys}" && fw_setenv bootsys $bootsys)
50
51 }
52 platform_copy_config_sdboot() {
53 local diskdev partdev parttype=ext4
54
55 export_bootdevice && export_partdevice diskdev 0 || {
56 echo "Unable to determine upgrade device"
57 return 1
58 }
59
60 if export_partdevice partdev 1; then
61 mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
62 echo "Saving config backup..."
63 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
64 umount /mnt
65 fi
66 }
67 platform_copy_config() {
68 local board=$(board_name)
69
70 case "$board" in
71 fsl,ls1012a-frwy-sdboot | \
72 fsl,ls1021a-iot-sdboot | \
73 fsl,ls1021a-twr-sdboot | \
74 fsl,ls1043a-rdb-sdboot | \
75 fsl,ls1046a-frwy-sdboot | \
76 fsl,ls1046a-rdb-sdboot | \
77 fsl,ls1088a-rdb-sdboot)
78 platform_copy_config_sdboot
79 ;;
80 esac
81 }
82 platform_check_image() {
83 local board=$(board_name)
84
85 case "$board" in
86 traverse,ls1043v | \
87 traverse,ls1043s)
88 nand_do_platform_check "traverse-ls1043" $1
89 return $?
90 ;;
91 fsl,ls1012a-frdm | \
92 fsl,ls1012a-frwy-sdboot | \
93 fsl,ls1012a-rdb | \
94 fsl,ls1021a-iot-sdboot | \
95 fsl,ls1021a-twr | \
96 fsl,ls1021a-twr-sdboot | \
97 fsl,ls1043a-rdb | \
98 fsl,ls1043a-rdb-sdboot | \
99 fsl,ls1046a-frwy | \
100 fsl,ls1046a-frwy-sdboot | \
101 fsl,ls1046a-rdb | \
102 fsl,ls1046a-rdb-sdboot | \
103 fsl,ls1088a-rdb | \
104 fsl,ls1088a-rdb-sdboot | \
105 fsl,ls2088a-rdb)
106 return 0
107 ;;
108 *)
109 echo "Sysupgrade is not currently supported on $board"
110 ;;
111 esac
112
113 return 1
114 }
115 platform_do_upgrade() {
116 local board=$(board_name)
117
118 # Force the creation of fw_printenv.lock
119 mkdir -p /var/lock
120 touch /var/lock/fw_printenv.lock
121
122 case "$board" in
123 traverse,ls1043v | \
124 traverse,ls1043s)
125 platform_do_upgrade_traverse_nandubi "$1"
126 ;;
127 fsl,ls1012a-frdm | \
128 fsl,ls1012a-rdb | \
129 fsl,ls1021a-twr | \
130 fsl,ls1043a-rdb | \
131 fsl,ls1046a-frwy | \
132 fsl,ls1046a-rdb | \
133 fsl,ls1088a-rdb | \
134 fsl,ls2088a-rdb)
135 PART_NAME=firmware
136 default_do_upgrade "$1"
137 ;;
138 fsl,ls1012a-frwy-sdboot | \
139 fsl,ls1021a-iot-sdboot | \
140 fsl,ls1021a-twr-sdboot | \
141 fsl,ls1043a-rdb-sdboot | \
142 fsl,ls1046a-frwy-sdboot | \
143 fsl,ls1046a-rdb-sdboot | \
144 fsl,ls1088a-rdb-sdboot)
145 platform_do_upgrade_sdboot "$1"
146 return 0
147 ;;
148 *)
149 echo "Sysupgrade is not currently supported on $board"
150 ;;
151 esac
152 }