2 # Copyright (C) 2016 lede-project.org
5 # this can be used as a generic mmc upgrade script
6 # just add a device entry in platform.sh,
7 # define "kernelname" and "rootfsname" and call mmc_do_upgrade
8 # after the kernel and rootfs flash a loopdev (as overlay) is
9 # setup on top of the rootfs partition
10 # for the proper function a padded rootfs image is needed, basically
11 # append "pad-to 64k" to the image definition
12 # this is based on the ipq806x zyxel.sh mmc upgrade
21 [ -z "$kernel" ] && kernel
=$
(find_mmc_part
${kernelname})
22 [ -z "$rootfs" ] && rootfs
=$
(find_mmc_part
${rootfsname})
24 [ -z "$kernel" ] && echo "Upgrade failed: kernel partition not found! Rebooting..." && reboot
-f
25 [ -z "$rootfs" ] && echo "Upgrade failed: rootfs partition not found! Rebooting..." && reboot
-f
27 mmc_do_flash
$tar_file $kernel $rootfs
37 # keep sure its unbound
38 losetup
--detach-all ||
{
39 echo Failed to detach all loop devices. Skip this try.
43 # use the first found directory in the tar archive
44 local board_dir
=$
(tar tf
$tar_file |
grep -m 1 '^sysupgrade-.*/$')
45 board_dir
=${board_dir%/}
47 echo "flashing kernel to $kernel"
48 tar xf
$tar_file ${board_dir}/kernel
-O >$kernel
50 echo "flashing rootfs to ${rootfs}"
51 tar xf
$tar_file ${board_dir}/root
-O >"${rootfs}"
53 # a padded rootfs is needed for overlay fs creation
54 local offset
=$
(tar xf
$tar_file ${board_dir}/root
-O |
wc -c)
55 [ $offset -lt 65536 ] && {
56 echo Wrong size
for rootfs
: $offset
61 # Mount loop for rootfs_data
62 local loopdev
="$(losetup -f)"
63 losetup
-o $offset $loopdev $rootfs ||
{
64 echo "Failed to mount looped rootfs_data."
69 echo "Format new rootfs_data at position ${offset}."
70 mkfs.ext4
-F -L rootfs_data
$loopdev
72 mount
-t ext4
$loopdev /tmp
/new_root
&& {
73 echo "Saving config to rootfs_data at position ${offset}."
74 cp -v "$UPGRADE_BACKUP" "/tmp/new_root/$BACKUP_FILE"
79 losetup
-d $loopdev >/dev
/null
2>&1