How to flash LEDE firmware, how to return back to stock firmware.

Attention!!!

Firmware files starting from build 1283 are named openwrt-r.... Firware files before build 1283 were named lede-rt.... There is a special procedure described later to downgrade firware from openwrt to lede due to board detection change in the OpenWrt project.

Preface

Nand flash has different partitions (ubi volumes) for stock and lede firmwares. This makes flashing more sophisticated for Asus RT-AC58U compared with other routers.

LEDE flashing instructions

More information and more details can be found on  4pda forum (Russian).

Method 1 (manual, 3 steps)

(1) Download two firmware files from http://lede-ac58u.zyxmon.org/firmware/: openwrt-r...-factory.trx (step 1 firmware) and openwrt-r...-sysupgrade.tar (step 2 firmware). Flash openwrt-r...factory.trx via web browser in a standard way. Now the firmware will appear to work and will work, however any settings will be lost on reboot. To fix it you need to flash second step firmware.
(2) Login to router using SSH (ip 192.168.1.1, user root, no password) and delete ubi volume named jffs2. First check if jffs2 is not mounted, because it will prevent volume deletion. Run mount command, if the output has  /dev/ubi0_5 on /mnt/ubi0_5... substring unmount partition with umount /mnt/ubi0_5. If the volume is not mounted it still might exist. Delete volume jffs2 with ubirmvol /dev/ubi0 -N jffs2. Verify that volume was deleted by running ubinfo -a. You should not see jffs2 in the output.
(3) Use your web browser to flash second step firmware. Router ip is 192.168.1.1, user root, no password. Update firmware - install openwrt-r...-sysupgrade.tar as a new firmware. After router reboots you will have the latest lede firmware on it. If you get an error The uploaded image file does not contain a supported format. Make sure that you choose the generic image format for your platform might be that you have not deleted jffs2 volume correctly. Try deleting again.
Check firmware URL and upgrade firmware on a regular basis.

Method 2 (automatic)

Download stock2lede.trx (first "automatic" firmware was build by dullish  4pda.ru forum). This firmware has sysupgrade.tar file inside it and runs operations from Method 1 automatically. Please note that stock2lede does not install the latest lede firmware. Total time to flash sock2lede is about 6-10 minutes. Use your web browser to flash the latest firmware after flashing stock2lede.

Method 3 (with USB-UART cable)

This method requires router disassembly and some skills. You will need (usb-uart) for it and *.itb firware. More details (Russian) are here - 4pda.

Downgrading from openwrt-r... firmware to lede-rt... firmware.

Firmware downgrade from build 1283 and later to build previous to 1283 (To downgrade openwrt... to lede...) can be done only in ssh session. 1. Rename the firmware file lede.....sysupgrade.tar to lede.tar (make filename shorter). 2. Upload it to /tmp router folder. 3. Run sysupgrade -F /tmp/lede.tar. Flag -F (force) overrides the image format check that was changed in the OpenWrt project. Here is an example (firmware downoad + rename + upgrade:

      
root@LEDE:~# wget http://lede-ac58u.zyxmon.org/archive/lede-rt-ac58u-r1057-ed83357-ipq806x-RT-AC58U-squashfs-sysupgrade.tar -O /tmp/lede.tar
Connecting to lede-ac58u.zyxmon.org (87.239.250.123:80)
lede.tar             100% |*****************************************************************|  6680k  0:00:00 ETA
root@LEDE:~# syspgrade -F /tmp/lede.tar
      
    

Closing remarks.

(1) The latest firmware has additional repository (installed automatically) with kernel kmod packages. If you need kmod packages use the latest firmware from this site.
(2) usb-uart method allows to restore router from nearly all firmware flashing errors.


Restoring stock (factory) firmware


To go back to factory firmware you need to remove ubi volumes that are different in lede and stock. After router reboots U-Boot bootloader will automatically restore stock partitions and enter recovery mode. To delete ubi volumes we will use sysupgrade script with -F (force) flag and junk firmware. In this case sysupgrade will remove three volumes linux, rootfs and rootfs_data. Since we use junk file as a firmware sysupgrade will not be able to calculet new volumes sizes and will reboot router. To avoid bootloop we will remove linux2 volume wich is a copy of linux volume. Login to you router using SSH and run (1) ubirmvol /dev/ubi0 -N linux2 (we delete linux2 volume) and  (2) sysupgrade -F /bin/busybox (we use busybox as a junk firmware). After the router reboots use Asus Recue utility (Windows) or tftp client binary to send RT-AC58U.trx stock firmware.