layerscape: Change to combined rootfs on sd images
[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-rdb-sdboot | \
76 fsl,ls1088a-rdb-sdboot)
77 platform_copy_config_sdboot
78 ;;
79 esac
80 }
81 platform_check_image() {
82 local board=$(board_name)
83
84 case "$board" in
85 traverse,ls1043v | \
86 traverse,ls1043s)
87 nand_do_platform_check "traverse-ls1043" $1
88 return $?
89 ;;
90 fsl,ls1012a-frdm | \
91 fsl,ls1012a-frwy-sdboot | \
92 fsl,ls1012a-rdb | \
93 fsl,ls1021a-iot-sdboot | \
94 fsl,ls1021a-twr | \
95 fsl,ls1021a-twr-sdboot | \
96 fsl,ls1043a-rdb | \
97 fsl,ls1043a-rdb-sdboot | \
98 fsl,ls1046a-rdb | \
99 fsl,ls1046a-rdb-sdboot | \
100 fsl,ls1088a-rdb | \
101 fsl,ls1088a-rdb-sdboot | \
102 fsl,ls2088a-rdb)
103 return 0
104 ;;
105 *)
106 echo "Sysupgrade is not currently supported on $board"
107 ;;
108 esac
109
110 return 1
111 }
112 platform_do_upgrade() {
113 local board=$(board_name)
114
115 # Force the creation of fw_printenv.lock
116 mkdir -p /var/lock
117 touch /var/lock/fw_printenv.lock
118
119 case "$board" in
120 traverse,ls1043v | \
121 traverse,ls1043s)
122 platform_do_upgrade_traverse_nandubi "$1"
123 ;;
124 fsl,ls1012a-frdm | \
125 fsl,ls1012a-rdb | \
126 fsl,ls1021a-twr | \
127 fsl,ls1043a-rdb | \
128 fsl,ls1046a-rdb | \
129 fsl,ls1088a-rdb | \
130 fsl,ls2088a-rdb)
131 PART_NAME=firmware
132 default_do_upgrade "$1"
133 ;;
134 fsl,ls1012a-frwy-sdboot | \
135 fsl,ls1021a-iot-sdboot | \
136 fsl,ls1021a-twr-sdboot | \
137 fsl,ls1043a-rdb-sdboot | \
138 fsl,ls1046a-rdb-sdboot | \
139 fsl,ls1088a-rdb-sdboot)
140 platform_do_upgrade_sdboot "$1"
141 return 0
142 ;;
143 *)
144 echo "Sysupgrade is not currently supported on $board"
145 ;;
146 esac
147 }