Skip to content

Commit 35b8b27

Browse files
committed
Added xqflash utility for easy upgrades.
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.
1 parent 24ef304 commit 35b8b27

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,27 @@ Usage
5252
5. Flash this file directly into the router using SSH.
5353
You cannot use the web UI because this is a raw image, and more importantly has no signature.
5454

55-
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:
55+
If you are using a recently xqrepack'ed firmware, you can use the `xqflash` utility on the router to flash an update image:
5656

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

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

61-
nvram set flag_ota_reboot=1
62-
nvram commit
63-
reboot
61+
If the `xqflash` utility is not available, you can manually flash the update image described in the following section.
62+
63+
64+
Manual Flashing
65+
================
66+
67+
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:
68+
69+
ubiformat /dev/mtd12 -f /tmp/r3600-raw-img.bin -s 2048 -O 2048
70+
71+
Set the nvram variable to re-initialize `/etc` (and I think to switch partitions also):
72+
73+
nvram set flag_ota_reboot=1
74+
nvram commit
75+
reboot
6476

6577

6678
A/B Partitions
@@ -89,7 +101,7 @@ License
89101

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

92-
Copyright (C) 2020 Darell Tan
104+
Copyright (C) 2020-2021 Darell Tan
93105

94106
Redistribution and use in source and binary forms, with or without
95107
modification, are permitted provided that the following conditions

repack-squashfs.sh

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ cat <<JS >> "$FSDIR/www/js/miwifi-monitor.js"
6969
(function(){ if (typeof window.MIWIFI_MONITOR !== "undefined") window.MIWIFI_MONITOR.log = function(a,b) {}; })();
7070
JS
7171

72+
# add xqflash tool into firmware for easy upgrades
73+
cp xqflash "$FSDIR/sbin"
74+
chmod 0755 "$FSDIR/sbin/xqflash"
75+
chown root:root "$FSDIR/sbin/xqflash"
76+
7277
# dont start crap services
7378
for SVC in stat_points statisticsservice \
7479
datacenter \

xqflash

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
#
3+
# flash a raw image into the upgrade slot
4+
# installed by the xqrepack tool for easy upgrading
5+
#
6+
7+
. /lib/functions.sh
8+
9+
include /lib/upgrade
10+
11+
IMAGE="$1"
12+
13+
[ -z "$IMAGE" ] && { echo "usage: $0 <ubi-image>"; exit 1; }
14+
15+
[ -f "$IMAGE" ] || { echo "image file not found"; exit 2; }
16+
17+
img_type=$(identify $IMAGE)
18+
[ "$img_type" = "ubi" ] || { echo "image file needs to be of type UBI, not \"$img_type\""; exit 2; }
19+
20+
# determine partition
21+
r0_mtd=$(grep '"rootfs"' /proc/mtd | awk -F: '{print substr($1,4)}')
22+
r1_mtd=$(grep '"rootfs_1"' /proc/mtd | awk -F: '{print substr($1,4)}')
23+
os_idx=$(nvram get flag_boot_rootfs)
24+
mtd_cur=$(($r0_mtd+${os_idx:-0}))
25+
mtd_nxt=$(($r0_mtd+$r1_mtd-$mtd_cur))
26+
27+
MTD_DEV=/dev/mtd$mtd_nxt
28+
[ -c "$MTD_DEV" ] || { echo "unable to determine MTD partition to flash to: $MTD_DEV"; exit 2; }
29+
30+
# abort if any command fails
31+
set -e
32+
33+
echo "flashing $IMAGE onto $MTD_DEV..."
34+
ubiformat $MTD_DEV -f $IMAGE -s 2048 -O 2048
35+
36+
echo "setting nvram variables..."
37+
nvram set flag_ota_reboot=1
38+
nvram commit
39+
40+
echo "Done. You may reboot now."
41+

0 commit comments

Comments
 (0)