mpc85xx: fix Enterasys WS-AP3710i eth mac-address
[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=""
7 RAMFS_COPY_DATA=""
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
36 platform_do_upgrade_traverse_slotubi() {
37 part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
38 echo "Active boot slot: ${part}"
39 new_active_sys="b"
40
41 if [ ! -z "${part}" ]; then
42 if [ "${part}" = "ubia" ]; then
43 CI_UBIPART="ubib"
44 else
45 CI_UBIPART="ubia"
46 new_active_sys="a"
47 fi
48 fi
49 echo "Updating UBI part ${CI_UBIPART}"
50 fw_setenv "openwrt_active_sys" "${new_active_sys}"
51 nand_do_upgrade "$1"
52 return $?
53 }
54
55 platform_copy_config_sdboot() {
56 local diskdev partdev parttype=ext4
57
58 export_bootdevice && export_partdevice diskdev 0 || {
59 echo "Unable to determine upgrade device"
60 return 1
61 }
62
63 if export_partdevice partdev 1; then
64 mount -t $parttype -o rw,noatime "/dev/$partdev" /mnt 2>&1
65 echo "Saving config backup..."
66 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
67 umount /mnt
68 fi
69 }
70 platform_copy_config() {
71 local board=$(board_name)
72
73 case "$board" in
74 fsl,ls1012a-frwy-sdboot | \
75 fsl,ls1021a-iot-sdboot | \
76 fsl,ls1021a-twr-sdboot | \
77 fsl,ls1028a-rdb-sdboot | \
78 fsl,ls1043a-rdb-sdboot | \
79 fsl,ls1046a-frwy-sdboot | \
80 fsl,ls1046a-rdb-sdboot | \
81 fsl,ls1088a-rdb-sdboot | \
82 fsl,lx2160a-rdb-sdboot)
83 platform_copy_config_sdboot
84 ;;
85 esac
86 }
87 platform_check_image() {
88 local board=$(board_name)
89
90 case "$board" in
91 traverse,ten64)
92 nand_do_platform_check "ten64-mtd" $1
93 return $?
94 ;;
95 fsl,ls1012a-frdm | \
96 fsl,ls1012a-frwy-sdboot | \
97 fsl,ls1012a-rdb | \
98 fsl,ls1021a-iot-sdboot | \
99 fsl,ls1021a-twr | \
100 fsl,ls1021a-twr-sdboot | \
101 fsl,ls1028a-rdb | \
102 fsl,ls1028a-rdb-sdboot | \
103 fsl,ls1043a-rdb | \
104 fsl,ls1043a-rdb-sdboot | \
105 fsl,ls1046a-frwy | \
106 fsl,ls1046a-frwy-sdboot | \
107 fsl,ls1046a-rdb | \
108 fsl,ls1046a-rdb-sdboot | \
109 fsl,ls1088a-rdb | \
110 fsl,ls1088a-rdb-sdboot | \
111 fsl,ls2088a-rdb | \
112 fsl,lx2160a-rdb | \
113 fsl,lx2160a-rdb-sdboot)
114 return 0
115 ;;
116 *)
117 echo "Sysupgrade is not currently supported on $board"
118 ;;
119 esac
120
121 return 1
122 }
123 platform_do_upgrade() {
124 local board=$(board_name)
125
126 # Force the creation of fw_printenv.lock
127 mkdir -p /var/lock
128 touch /var/lock/fw_printenv.lock
129
130 case "$board" in
131 traverse,ten64)
132 platform_do_upgrade_traverse_slotubi "${1}"
133 ;;
134 fsl,ls1012a-frdm | \
135 fsl,ls1012a-rdb | \
136 fsl,ls1021a-twr | \
137 fsl,ls1028a-rdb | \
138 fsl,ls1043a-rdb | \
139 fsl,ls1046a-frwy | \
140 fsl,ls1046a-rdb | \
141 fsl,ls1088a-rdb | \
142 fsl,ls2088a-rdb | \
143 fsl,lx2160a-rdb)
144 PART_NAME=firmware
145 default_do_upgrade "$1"
146 ;;
147 fsl,ls1012a-frwy-sdboot | \
148 fsl,ls1021a-iot-sdboot | \
149 fsl,ls1021a-twr-sdboot | \
150 fsl,ls1028a-rdb-sdboot | \
151 fsl,ls1043a-rdb-sdboot | \
152 fsl,ls1046a-frwy-sdboot | \
153 fsl,ls1046a-rdb-sdboot | \
154 fsl,ls1088a-rdb-sdboot | \
155 fsl,lx2160a-rdb-sdboot)
156 platform_do_upgrade_sdboot "$1"
157 return 0
158 ;;
159 *)
160 echo "Sysupgrade is not currently supported on $board"
161 ;;
162 esac
163 }