2 # Copyright (C) 2014 OpenWrt.org
5 platform_get_rootfs
() {
8 if read cmdline
< /proc
/cmdline
; then
11 rootfsdev
="${cmdline##*block2mtd=}"
12 rootfsdev
="${rootfsdev%%,*}"
15 rootfsdev
="${cmdline##*root=}"
16 rootfsdev
="${rootfsdev%% *}"
24 platform_copy_config
() {
25 case "$(board_name)" in
27 mount
-t vfat
/dev
/sda1
/mnt
28 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
32 mount
-t vfat
/dev
/mmcblk1p1
/mnt
33 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
45 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
46 board_dir
=${board_dir%/}
47 [ -n "$board_dir" ] ||
return 1
51 if [ $board = "itus,shield-router" ]; then
52 # mmcblk1p1 (fat) contains all ELF-bin images for the Shield
53 mount
/dev
/mmcblk1p1
/boot
55 echo "flashing Itus Kernel to /boot/$kernel (/dev/mmblk1p1)"
56 tar -Oxf $tar_file "$board_dir/kernel" > /boot
/$kernel
58 mount
-t vfat
/dev
/$kernel /boot
60 [ -f /boot
/vmlinux
.64 -a ! -L /boot
/vmlinux
.64 ] && {
61 mv /boot
/vmlinux
.64 /boot
/vmlinux
.64.previous
62 mv /boot
/vmlinux
.64.md5
/boot
/vmlinux
.64.md5.previous
65 echo "flashing kernel to /dev/$kernel"
66 tar xf
$tar_file $board_dir/kernel
-O > /boot
/vmlinux
.64
67 md5sum /boot
/vmlinux
.64 | cut
-f1 -d " " > /boot
/vmlinux
.64.md5
70 echo "flashing rootfs to ${rootfs}"
71 tar xf
$tar_file $board_dir/root
-O |
dd of
="${rootfs}" bs
=4096
77 platform_do_upgrade
() {
79 local board
=$
(board_name
)
80 local rootfs
="$(platform_get_rootfs)"
83 [ -b "${rootfs}" ] ||
return 1
92 kernel
=ItusrouterImage
98 platform_do_flash
$tar_file $board $kernel $rootfs
103 platform_check_image
() {
104 local board
=$
(board_name
)
107 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
108 board_dir
=${board_dir%/}
109 [ -n "$board_dir" ] ||
return 1
115 local kernel_length
=$
(tar xf
$tar_file $board_dir/kernel
-O |
wc -c 2> /dev
/null
)
116 local rootfs_length
=$
(tar xf
$tar_file $board_dir/root
-O |
wc -c 2> /dev
/null
)
117 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
118 echo "The upgrade image is corrupt."
125 echo "Sysupgrade is not yet supported on $board."