1 # SPDX-License-Identifier: GPL-2.0-only
4 platform_do_upgrade_netgear_orbi_upgrade
() {
5 command -v losetup
>/dev
/null ||
{
6 logger
-s "Upgrade failed: 'losetup' not installed."
14 [ -z "$kernel" ] && kernel
=$
(find_mmc_part
"kernel")
15 [ -z "$rootfs" ] && rootfs
=$
(find_mmc_part
"rootfs")
17 [ -z "$kernel" ] && echo "Upgrade failed: kernel partition not found! Rebooting..." && reboot
-f
18 [ -z "$rootfs" ] && echo "Upgrade failed: rootfs partition not found! Rebooting..." && reboot
-f
20 netgear_orbi_do_flash
$tar_file $kernel $rootfs
22 echo "sysupgrade successful"
27 netgear_orbi_do_flash
() {
32 # keep sure its unbound
33 losetup
--detach-all ||
{
34 echo "Failed to detach all loop devices. Skip this try."
38 # use the first found directory in the tar archive
39 local board_dir
=$
(tar tf
$tar_file |
grep -m 1 '^sysupgrade-.*/$')
40 board_dir
=${board_dir%/}
42 echo "flashing kernel to $kernel"
43 tar xf
$tar_file ${board_dir}/kernel
-O >$kernel
45 echo "flashing rootfs to ${rootfs}"
46 tar xf
$tar_file ${board_dir}/root
-O >"${rootfs}"
48 # a padded rootfs is needed for overlay fs creation
49 local offset
=$
(tar xf
$tar_file ${board_dir}/root
-O |
wc -c)
50 [ $offset -lt 65536 ] && {
51 echo "Wrong size for rootfs: $offset"
56 # Mount loop for rootfs_data
57 local loopdev
="$(losetup -f)"
58 losetup
-o $offset $loopdev $rootfs ||
{
59 echo "Failed to mount looped rootfs_data."
64 echo "Format new rootfs_data at position ${offset}."
65 mkfs.ext4
-F -L rootfs_data
$loopdev
67 mount
-t ext4
$loopdev /tmp
/new_root
&& {
68 echo "Saving config to rootfs_data at position ${offset}."
69 cp -v "$UPGRADE_BACKUP" "/tmp/new_root/$BACKUP_FILE"
74 losetup
-d $loopdev >/dev
/null
2>&1