Closed yfhyou closed 3 months ago
hi @yfhyou,
Is there a 'simple' way for this device?
no.
I tried searching forums and OpenWRT wiki
to my knowledge, how to restore stock on this device was never discussed. in this repo i provided a way for people to backup before wiping their device, so that at least there would be the possibility of restoring stock if needed, but i never outlined a procedure for restoring.
the easiest way to restore stock on any device is:
openwrt initramfs builds run entirely from ram (the OS is contained in a ramdrive that is bundled with the kernel) and are a perfect fit for this purpose when available. they are for this device, so this point is covered.
but the restore part can be trickier.
WARNING: if the restore is started but not correctly finished (eg, powerloss or incorrect procedure), the device may not boot at all and recovery methods may be needed (eg, bootloader access).
if the device is eMMC, restoring the partitions is trivial. on NAND devices such as this one, it is a bit more complicated. NANDs can contain bad blocks and new bad blocks can develop at any moment. and these bad blocks are user visible and not hidden by a translation layer as in SSDs. (bad blocks typically develop during erase or write, but not read, and this is what the software expects. however, NANDs also can and will "forget" the data written to them given enough time, without the associated blocks being bad in any way. this effect is generally not compensated for in openwrt, other than by having two copies of the firmware in some devices.)
so you technically cannot in the general case "restore" a NAND to a previous state, as the NAND may have developed bad blocks since that previous time. what you can do is restore the NAND to a state that will look indistinguishable from the original state to the applicable software that will be reading the NAND. this concept is key: how to restore a NAND partition depends on how it will be used by the software. there is no general method as there is for block devices such as SSDs and eMMCs.
openwrt can use a NAND partition in 2 ways (that i can think of):
mtdblock
: it involves reading the partition sequentially and keeping a list of bad blocks in ram.) openwrt uses partitions in this way to store kernels and read-only squashfs rootfs filesystems. in openwrt you write these partitions using the mtd
command.ubiformat --flash-image=<file>
command.(openwrt also supports NOR flash, which is not expected to develop defects during its lifetime and thus is much easier to use. NOR partitions can be used directly for filesystems such as jffs2
. but i will not cover NOR flash here.)
regarding your device, in official openwrt this device uses a big UBI partition storing kernel, rootfs, and rootfs_data volumes. (this is known as a kernel-in-UBI configuration.) see the output of ubinfo -a
for more info.
(@hauke @mans0n @dangowrt, please read from this point on, if you have the time.)
so it would seem that return to stock is simple: just boot an initramfs build, scp the restore images to /tmp, ssh and write the images to flash using the right command from above, and finally reboot.
note that before reboot you would also need to restore the u-boot environment (see fw_printenv
), which can be done by restoring the partition in which it is stored (if you had the backup), or manually using fw_setenv
commands.
but that's it. it's simple, right? right?
err... unfortunately, nope.
this device as stock has partitions for two copies of its firmware. the people who ported this device repartitioned it: they deleted several stock partitions and created new, fewer, and larger partitions to store a single copy of openwrt and its non-volatile state.
and the problem is: when you run the initramfs official openwrt image, the partitions you want to restore simply don't exist! the "easiest" way to restore, IMHO, would be to setup an openwrt build environment and build your own modified initramfs kernel with the original partition table in it.
this is hardly easy or simple, even for experienced users. i have been advocating for a solution to this problem for some time now. take a look, this is a similar device i have ported (NAND, dual firmware stock, single firmware official openwrt):
for that device i have:
stock_
to their names.if this is done and enforced in all new ports, restoring say stock partition mtd26 is a simple affair of writing to /dev/mtd26 in official openwrt. this makes backup and restore scripts work unmodified both in stock rom and official openwrt.
as said, i have been advocating for this convention for a while, but for reasons that were not explained to me the project does not seem to favor this idea. or maybe they were too busy? idk.
back to your particular device... this convention was not followed, so restoring stock on this device is hard. not impossible though. but i would not recommend trying unless you have working access to the bootloader/serial port.
Thank you for the very thorough response. I learned a lot! I wish there was an 'easy' answer. I have an rtt4230w that seems to have a hardware issue. Whenever I start the wireless I get a error like:
I saw this during boot and thought just starting over might help OF: Bad cell count for /soc/nand-controller@1ac00000/nand@0/partitions
I guess they are probably unrelated though. I do have bootloader & serial access on this device.
@yfhyou
[ 1.662002] OF: Bad cell count for /soc/nand-controller@1ac00000/nand@0/partitions
[ 1.668851] OF: Bad cell count for /soc/nand-controller@1ac00000/nand@0/partitions
[ 1.794938] mtd: partition "ubi" extends beyond the end of device "qcom_nand.0" -- size truncated to 0xdc00000
i imagine that is just your device having a 256 MB NAND (rev 10) while the firmware image was made for a 512 MB NAND (rev 6), no cause for concern.
regarding the ath10k issue, grab all that info and create a thread in the openwrt forum; you may get some expert response.
why do you want to return to stock? is your device rented and you want a replacement?
if you want to return to stock, you can... if you have the backups.
root@router:~# mtd
Usage: mtd [<options> ...] <command> [<arguments> ...] <device>[:<device>...]
The device is in the format of mtdX (eg: mtd4) or its label.
mtd recognizes these commands:
unlock unlock the device
refresh refresh mtd partition
erase erase all data on device
verify <imagefile>|- verify <imagefile> (use - for stdin) to device
write <imagefile>|- write <imagefile> (use - for stdin) to device
jffs2write <file> append <file> to the jffs2 partition on the device
resetbc <device> reset the uboot boot counter
Following options are available:
-q quiet mode (once: no [w] on writing,
twice: no status messages)
-n write without first erasing the blocks
-r reboot after successful command
-f force write without trx checks
-e <device> erase <device> before executing the command
-d <name> directory for jffs2write, defaults to "tmp"
-j <name> integrate <file> into jffs2 data when writing an image
-s <number> skip the first n bytes when appending data to the jffs2 partiton, defaults to "0"
-p <number> write beginning at partition offset
-l <length> the length of data that we want to dump
Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards
mtd -r write linux.trx linux
as you can see, you can use the -p
option to write at an offset within an MTD partition. you can use this to write to where a partition would lay in the stock partition layout. the original partition layout can be seen in the stock bootlog in the wiki's device page.
notes:
mtd -p <offset>
command.ubiformat
. you cannot use ubiformat
with anything but a complete MTD partition, so you cannot apply the tricks above. but you could restore a UBI partition using MTD wrtite, only if the NAND has not developed new bad blocks in the UBI area, which has a reasonable probability. once again, reading back the MTD area should result in the same length of the backup if no new bad blocks developed.
How would one go about restoring the mtd / ubi backups?
I tried searching forums and OpenWRT wiki, but I am quickly overwhelmed with all the options with NAND, NOR, dd, mtdwrite, etc etc.
Is there a 'simple' way for this device?