2 # Copyright (C) 2016 lede-project.org
8 if read cmdline
< /proc
/cmdline
; then
11 rootfsdev
="${cmdline##*root=}"
12 rootfsdev
="${rootfsdev%% *}"
26 # keep sure its unbound
27 losetup
--detach-all ||
{
28 echo Failed to detach all loop devices. Skip this try.
32 # use the first found directory in the tar archive
33 local board_dir
=$
(tar tf
$tar_file |
grep -m 1 '^sysupgrade-.*/$')
34 board_dir
=${board_dir%/}
36 echo "flashing kernel to $kernel"
37 tar xf
$tar_file ${board_dir}/kernel
-O >$kernel
39 echo "flashing rootfs to ${rootfs}"
40 tar xf
$tar_file ${board_dir}/root
-O >"${rootfs}"
42 # a padded rootfs is needed for overlay fs creation
43 local offset
=$
(tar xf
$tar_file ${board_dir}/root
-O |
wc -c)
44 [ $offset -lt 65536 ] && {
45 echo Wrong size
for rootfs
: $offset
50 # Mount loop for rootfs_data
51 local loopdev
="$(losetup -f)"
52 losetup
-o $offset $loopdev $rootfs ||
{
53 echo "Failed to mount looped rootfs_data."
58 echo "Format new rootfs_data at position ${offset}."
59 mkfs.ext4
-F -L rootfs_data
$loopdev
61 mount
-t ext4
$loopdev /tmp
/new_root
&& {
62 echo "Saving config to rootfs_data at position ${offset}."
63 cp -v /tmp
/sysupgrade.tgz
/tmp
/new_root
/
67 # flashing successful, toggle the dualflag
70 printf "\xff" >$dualflagmtd
73 printf "\x01" >$dualflagmtd
78 losetup
-d $loopdev >/dev
/null
2>&1
86 local board
=$
(board_name
)
87 local rootfs
="$(zyxel_get_rootfs)"
90 [ -b "${rootfs}" ] ||
return 1
93 local dualflagmtd
="$(find_mtd_part 0:DUAL_FLAG)"
94 [ -b $dualflagmtd ] ||
return 1
98 # booted from the primary partition set
99 # write to the alternative set
100 kernel
="/dev/mmcblk0p7"
101 rootfs
="/dev/mmcblk0p8"
104 # booted from the alternative partition set
105 # write to the primary set
106 kernel
="/dev/mmcblk0p4"
107 rootfs
="/dev/mmcblk0p5"
119 zyxel_do_flash
$tar_file $kernel $rootfs $dualflagmtd