Skip to content

Commit

Permalink
Added xqflash utility for easy upgrades.
Browse files Browse the repository at this point in the history
Previously, you needed to locate the correct A/B partition to write the
upgrade image into. Now, the xqflash utility will now be injected into
the repacked firmware, allowing you to just type `xqflash <image>` to
flash an upgrade image.
  • Loading branch information
geekman committed Apr 13, 2021
1 parent 24ef304 commit 35b8b27
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@ Usage
5. Flash this file directly into the router using SSH.
You cannot use the web UI because this is a raw image, and more importantly has no signature.

The R3600 firmware uses an A/B partition system, called `rootfs` and `rootfs_1`. This corresponds to `mtd12` and `mtd13`. Find the partition that is not the one in use and use `ubiformat` to write the raw image onto the partition:
If you are using a recently xqrepack'ed firmware, you can use the `xqflash` utility on the router to flash an update image:

ubiformat /dev/mtd12 -f /tmp/r3600-raw-img.bin -s 2048 -O 2048
xqflash /tmp/r3600-raw-img.bin

6. Set the nvram variable to re-initialize `/etc` (and I think to switch partitions also):
After it completes successfully, you should be able to `reboot`.

nvram set flag_ota_reboot=1
nvram commit
reboot
If the `xqflash` utility is not available, you can manually flash the update image described in the following section.


Manual Flashing
================

The R3600 firmware uses an A/B partition system, called `rootfs` and `rootfs_1`. This corresponds to `mtd12` and `mtd13`. Find the partition that is not the one in use and use `ubiformat` to write the raw image onto the partition:

ubiformat /dev/mtd12 -f /tmp/r3600-raw-img.bin -s 2048 -O 2048

Set the nvram variable to re-initialize `/etc` (and I think to switch partitions also):

nvram set flag_ota_reboot=1
nvram commit
reboot


A/B Partitions
Expand Down Expand Up @@ -89,7 +101,7 @@ License

**xqrepack** is licensed under **the 3-clause ("modified") BSD License**.

Copyright (C) 2020 Darell Tan
Copyright (C) 2020-2021 Darell Tan

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down
5 changes: 5 additions & 0 deletions repack-squashfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ cat <<JS >> "$FSDIR/www/js/miwifi-monitor.js"
(function(){ if (typeof window.MIWIFI_MONITOR !== "undefined") window.MIWIFI_MONITOR.log = function(a,b) {}; })();
JS

# add xqflash tool into firmware for easy upgrades
cp xqflash "$FSDIR/sbin"
chmod 0755 "$FSDIR/sbin/xqflash"
chown root:root "$FSDIR/sbin/xqflash"

# dont start crap services
for SVC in stat_points statisticsservice \
datacenter \
Expand Down
41 changes: 41 additions & 0 deletions xqflash
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
#
# flash a raw image into the upgrade slot
# installed by the xqrepack tool for easy upgrading
#

. /lib/functions.sh

include /lib/upgrade

IMAGE="$1"

[ -z "$IMAGE" ] && { echo "usage: $0 <ubi-image>"; exit 1; }

[ -f "$IMAGE" ] || { echo "image file not found"; exit 2; }

img_type=$(identify $IMAGE)
[ "$img_type" = "ubi" ] || { echo "image file needs to be of type UBI, not \"$img_type\""; exit 2; }

# determine partition
r0_mtd=$(grep '"rootfs"' /proc/mtd | awk -F: '{print substr($1,4)}')
r1_mtd=$(grep '"rootfs_1"' /proc/mtd | awk -F: '{print substr($1,4)}')
os_idx=$(nvram get flag_boot_rootfs)
mtd_cur=$(($r0_mtd+${os_idx:-0}))
mtd_nxt=$(($r0_mtd+$r1_mtd-$mtd_cur))

MTD_DEV=/dev/mtd$mtd_nxt
[ -c "$MTD_DEV" ] || { echo "unable to determine MTD partition to flash to: $MTD_DEV"; exit 2; }

# abort if any command fails
set -e

echo "flashing $IMAGE onto $MTD_DEV..."
ubiformat $MTD_DEV -f $IMAGE -s 2048 -O 2048

echo "setting nvram variables..."
nvram set flag_ota_reboot=1
nvram commit

echo "Done. You may reboot now."

0 comments on commit 35b8b27

Please sign in to comment.