2 # Copyright (C) 2021 OpenWrt.org
5 platform_get_rootfs
() {
8 if read cmdline
< /proc
/cmdline
; then
11 rootfsdev
="${cmdline##*root=}"
12 rootfsdev
="${rootfsdev%% *}"
20 platform_copy_config_helper
() {
23 mount
-t vfat
"$device" /mnt
24 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
28 platform_copy_config
() {
29 case "$(board_name)" in
31 platform_copy_config_helper
/dev
/sda1
34 platform_copy_config_helper
/dev
/mmcblk1p1
38 platform_copy_config_helper
/dev
/mmcblk0p1
49 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
50 board_dir
=${board_dir%/}
51 [ -n "$board_dir" ] ||
return 1
55 if [ $board = "itus,shield-router" ]; then
56 # mmcblk1p1 (fat) contains all ELF-bin images for the Shield
57 mount
/dev
/mmcblk1p1
/boot
59 echo "flashing Itus Kernel to /boot/$kernel (/dev/mmblk1p1)"
60 tar -Oxf $tar_file "$board_dir/kernel" > /boot
/$kernel
62 mount
-t vfat
/dev
/$kernel /boot
64 [ -f /boot
/vmlinux
.64 -a ! -L /boot
/vmlinux
.64 ] && {
65 mv /boot
/vmlinux
.64 /boot
/vmlinux
.64.previous
66 mv /boot
/vmlinux
.64.md5
/boot
/vmlinux
.64.md5.previous
69 echo "flashing kernel to /dev/$kernel"
70 tar xf
$tar_file $board_dir/kernel
-O > /boot
/vmlinux
.64
71 md5sum /boot
/vmlinux
.64 | cut
-f1 -d " " > /boot
/vmlinux
.64.md5
74 echo "flashing rootfs to ${rootfs}"
75 tar xf
$tar_file $board_dir/root
-O |
dd of
="${rootfs}" bs
=4096
81 platform_do_upgrade
() {
83 local board
=$
(board_name
)
84 local rootfs
="$(platform_get_rootfs)"
87 [ -b "${rootfs}" ] ||
return 1
98 kernel
=ItusrouterImage
104 platform_do_flash
$tar_file $board $kernel $rootfs
109 platform_check_image
() {
110 local board
=$
(board_name
)
113 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
114 board_dir
=${board_dir%/}
115 [ -n "$board_dir" ] ||
return 1
120 itus
,shield-router | \
121 ubnt
,edgerouter-4 | \
123 local kernel_length
=$
(tar xf
$tar_file $board_dir/kernel
-O |
wc -c 2> /dev
/null
)
124 local rootfs_length
=$
(tar xf
$tar_file $board_dir/root
-O |
wc -c 2> /dev
/null
)
125 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
126 echo "The upgrade image is corrupt."
133 echo "Sysupgrade is not yet supported on $board."