blob: ad5baef4a19fd95a747f5739abdf93c6d4bd1681 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#
2# Copyright (C) 2014 OpenWrt.org
3#
4
5platform_get_rootfs() {
6 local rootfsdev
7
8 if read cmdline < /proc/cmdline; then
9 case "$cmdline" in
10 *root=*)
11 rootfsdev="${cmdline##*root=}"
12 rootfsdev="${rootfsdev%% *}"
13 ;;
14 esac
15
16 echo "${rootfsdev}"
17 fi
18}
19
20platform_copy_config() {
21 case "$(board_name)" in
22 erlite)
23 mount -t vfat /dev/sda1 /mnt
24 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
25 umount /mnt
26 ;;
27 itus,shield-router)
28 mount -t vfat /dev/mmcblk1p1 /mnt
29 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
30 umount /mnt
31 ;;
32 ubnt,edgerouter-4)
33 mount -t vfat /dev/mmcblk0p1 /mnt
34 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
35 umount /mnt
36 ;;
37 esac
38}
39
40platform_do_flash() {
41 local tar_file=$1
42 local board=$2
43 local kernel=$3
44 local rootfs=$4
45
46 local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
47 board_dir=${board_dir%/}
48 [ -n "$board_dir" ] || return 1
49
50 mkdir -p /boot
51
52 if [ $board = "itus,shield-router" ]; then
53 # mmcblk1p1 (fat) contains all ELF-bin images for the Shield
54 mount /dev/mmcblk1p1 /boot
55
56 echo "flashing Itus Kernel to /boot/$kernel (/dev/mmblk1p1)"
57 tar -Oxf $tar_file "$board_dir/kernel" > /boot/$kernel
58 else
59 mount -t vfat /dev/$kernel /boot
60
61 [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
62 mv /boot/vmlinux.64 /boot/vmlinux.64.previous
63 mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
64 }
65
66 echo "flashing kernel to /dev/$kernel"
67 tar xf $tar_file $board_dir/kernel -O > /boot/vmlinux.64
68 md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
69 fi
70
71 echo "flashing rootfs to ${rootfs}"
72 tar xf $tar_file $board_dir/root -O | dd of="${rootfs}" bs=4096
73
74 sync
75 umount /boot
76}
77
78platform_do_upgrade() {
79 local tar_file="$1"
80 local board=$(board_name)
81 local rootfs="$(platform_get_rootfs)"
82 local kernel=
83
84 [ -b "${rootfs}" ] || return 1
85 case "$board" in
86 er | \
87 ubnt,edgerouter-4)
88 kernel=mmcblk0p1
89 ;;
90 erlite)
91 kernel=sda1
92 ;;
93 itus,shield-router)
94 kernel=ItusrouterImage
95 ;;
96 *)
97 return 1
98 esac
99
100 platform_do_flash $tar_file $board $kernel $rootfs
101
102 return 0
103}
104
105platform_check_image() {
106 local board=$(board_name)
107 local tar_file="$1"
108
109 local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
110 board_dir=${board_dir%/}
111 [ -n "$board_dir" ] || return 1
112
113 case "$board" in
114 er | \
115 erlite | \
116 itus,shield-router | \
117 ubnt,edgerouter-4)
118 local kernel_length=$(tar xf $tar_file $board_dir/kernel -O | wc -c 2> /dev/null)
119 local rootfs_length=$(tar xf $tar_file $board_dir/root -O | wc -c 2> /dev/null)
120 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
121 echo "The upgrade image is corrupt."
122 return 1
123 }
124 return 0
125 ;;
126 esac
127
128 echo "Sysupgrade is not yet supported on $board."
129 return 1
130}