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
32 platform_copy_config_helper
/dev
/sda1
35 platform_copy_config_helper
/dev
/mmcblk1p1
39 platform_copy_config_helper
/dev
/mmcblk0p1
50 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
51 board_dir
=${board_dir%/}
52 [ -n "$board_dir" ] ||
return 1
56 if [ $board = "itus,shield-router" ]; then
57 # mmcblk1p1 (fat) contains all ELF-bin images for the Shield
58 mount
/dev
/mmcblk1p1
/boot
60 echo "flashing Itus Kernel to /boot/$kernel (/dev/mmblk1p1)"
61 tar -Oxf $tar_file "$board_dir/kernel" > /boot
/$kernel
63 mount
-t vfat
/dev
/$kernel /boot
65 [ -f /boot
/vmlinux
.64 -a ! -L /boot
/vmlinux
.64 ] && {
66 mv /boot
/vmlinux
.64 /boot
/vmlinux
.64.previous
67 mv /boot
/vmlinux
.64.md5
/boot
/vmlinux
.64.md5.previous
70 echo "flashing kernel to /dev/$kernel"
71 tar xf
$tar_file $board_dir/kernel
-O > /boot
/vmlinux
.64
72 md5sum /boot
/vmlinux
.64 | cut
-f1 -d " " > /boot
/vmlinux
.64.md5
75 echo "flashing rootfs to ${rootfs}"
76 tar xf
$tar_file $board_dir/root
-O |
dd of
="${rootfs}" bs
=4096
82 platform_do_upgrade
() {
84 local board
=$
(board_name
)
85 local rootfs
="$(platform_get_rootfs)"
88 [ -b "${rootfs}" ] ||
return 1
100 kernel
=ItusrouterImage
106 platform_do_flash
$tar_file $board $kernel $rootfs
111 platform_check_image
() {
112 local board
=$
(board_name
)
115 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
116 board_dir
=${board_dir%/}
117 [ -n "$board_dir" ] ||
return 1
122 itus
,shield-router | \
123 ubnt
,edgerouter-4 | \
124 ubnt
,edgerouter-6p | \
126 local kernel_length
=$
(tar xf
$tar_file $board_dir/kernel
-O |
wc -c 2> /dev
/null
)
127 local rootfs_length
=$
(tar xf
$tar_file $board_dir/root
-O |
wc -c 2> /dev
/null
)
128 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
129 echo "The upgrade image is corrupt."
136 echo "Sysupgrade is not yet supported on $board."