Process to flash without disassembly. Refer to https://github.com/APCCV/openwrt-dns320/releases/tag/v24.10.5-r1 for required files.
Full disclosure: I have tested this process much as I can. A lot of thought and checks have gone into it, but I no longer have Alt-F running on my NAS and I don't want to flash the u-boot back to stock to be able to fully test this. That said, I am extremely confident in this process or I would not have posted it.
DNS320-Ax ONLY.
There is a risk of bricking the device by following this process. Unbricking will require disassembly and use of a serial adapter to recover it. You've been warned. (Good news is that it is impossible to permanently brick this device.)
Prerequisites:
- DNS320-A1 device running stock firmware or Alt-F.
- ssh access to Alt-F.
- required
u-boot.kwb, env.bin and ubi.bin files copied over to the NAS and stored locally
Process (summary):
- Install patched version of Alt-F included in v24.10.5-r1 release that removes read-only restriction on u-boot partition and creates the env & ubi partitions.
- Stop services on Alt-F and disable the Alt-F folder.
- Flash
u-boot.kwb, env.bin and ubi.bin files to their respective partitions, cross fingers and reboot by unplugging the device. Do not reboot until all flashing is complete.
- Once in OpenWrt,
sysupgrade to the full sysupgrade image in release to ensure a flawless firmware image is installed (just in case Alt-F messed a block while trying to access old JFFS partitions).
The new u-boot can flash an image from USB as a recovery mechanism. Process above is interactive and allows for some level of recovery. Flashing from USB is not interactive but is a failsafe reccovery option for faulty OpenWrt images. Details for this on next post.
Step by step installation instructions:
If the NAS is running stock firmware, install the Alt-F-1.0-DNS-320-rev-Ax.bin firmware in the v24.10.5-r1 release through the stock firmware upgrade UI. If the NAS is already running Alt-F, upgrade the firmware with that file. Refer to the Alt-F site for more information in either case. Boot into this firmware.
Transfer the u-boot.kwb, env.bin and ubi.bin files to the NAS. Any location works, any mechanism works. Files need to be accessible to a shell. A USB drive works, a folder on any hard disk will do too.
Stop and disable as many services as possible (file sharing, torrent server or client, media server, anything...) with the exception of secure shell (ssh) access. Next, the Alt-F folder that contains all installed packages should be disabled to remove the possibility of it damaging the new UBI partition during flash. For that, go to Packages->Alt-F, check the "Boot Disable" checkbox, hit Submit, then reboot. After reboot you will see a Warning message in the Status page saying that an Alt-F folder was detected but not used, as a file named NOAUFS was found on it.
Connect to the NAS as root via ssh. The web password is also the password for ssh, unless it was changed from ssh. If unknown, reset the web password and that will also reset the root password.
Confirm the required partitions were created:
[root@DNS-320-0174DB]# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
mtd1: 00500000 00020000 "uImage"
mtd2: 00500000 00020000 "ramdisk"
mtd3: 06600000 00020000 "image"
mtd4: 00a00000 00020000 "mini firmware"
mtd5: 00500000 00020000 "config"
mtd6: 07f00000 00020000 "ubi"
mtd7: 00020000 00020000 "env"
Check kernel log with dmesg | less and validate the kernel sees the partitions with appropriate sizes:
8 ofpart partitions found on MTD device orion_nand
Creating 8 MTD partitions on "orion_nand":
0x000000000000-0x000000100000 : "u-boot"
0x000000100000-0x000000600000 : "uImage"
0x000000600000-0x000000b00000 : "ramdisk"
0x000000b00000-0x000007100000 : "image"
0x000007100000-0x000007b00000 : "mini firmware"
0x000007b00000-0x000008000000 : "config"
0x000000100000-0x000008000000 : "ubi"
0x0000000e0000-0x000000100000 : "env"
cd to where the flash files are located.
Last opportunity for recovery - make a backup of the flash. Takes a minute can might avoid a brick if things start going the wrong way. To do so:
dd if=/dev/mtd0 of=uboot_mtd.bak
dd if=/dev/mtd1 of=kernel_mtd.bak
dd if=/dev/mtd2 of=initramfs_mtd.bak
dd if=/dev/mtd3 of=sqimage_mtd.bak
Point of no return. Once flashing of any partition starts, process must complete or device will be bricked. Any errors will require disassembly and a serial adapter. Do not reboot if something goes wrong. The backup files can be flashed back as a last ditch effort to avoid the brick.
First flash u-boot and environment:
root@DNS-320-0174DB]# flash_erase /dev/mtd0 0 0
Erasing 128 Kibyte @ e0000 -- 100 % complete
[root@DNS-320-0174DB]# nandwrite -p /dev/mtd0 u-boot.kwb
Writing data to block 0 at offset 0x0
Writing data to block 1 at offset 0x20000
Writing data to block 2 at offset 0x40000
Writing data to block 3 at offset 0x60000
Writing data to block 4 at offset 0x80000
[root@DNS-320-0174DB]# nandwrite -p /dev/mtd7 env.bin
Writing data to block 0 at offset 0x0
[root@DNS-320-0174DB]#
If this fails...
Recovery
A "read only" (or permission denied) on flash_erase means the NAS is not using the firmware provided in this release. No changes have been done, process can be started from the beginning by rebooting and flashing the appropriate firmware in this release.
If flash_erase or nandwrite for u-boot fail before reaching 100% (extremely rare), the device is probably bricked due to a defect in flash storage in a critical area. Attempt the command(s) again, just once more. If it works, continue, with writes.
If it doesn't, as a last hope for recovery, erase again and flash back the backup of the u-boot (nandwrite -p /dev/mtd0 u-uboot_mtd.bak) as far as it will go and reboot. The device might come back to Alt-F.
The device might be recovered through disassembly and using the kwboot tool. Links on 1st post contain some information about it.
If write for the environment fails but u-boot writes OK... continue with process. u-boot will boot with the default environment which should be OK. This will be fixed from OpenWrt.
Now flash the main UBI filesystem:
flash_erase /dev/mtd6 0 0
nandwrite -p /dev/mtd6 ubi.bin
This will take a minute or two to execute.
If that fails... revert everything and with luck NAS will be back to Alt-F.
Recovery
Try erase and flash one more time, just once.
Recovering to Alt-F might be possible by flash_erase and nandwrite all four backups (including u-boot). Device can then reboot, hopefully into Alt-F. If device is bricked it can be most probably salvaged by disassembling and flashing OpenWrt via a serial adapter.
After the UBI file has been successfully flashed, unplug the device (do not reboot or do anything that could cause the running Alt-F OS to write to the filesystem). Plug in again, press power button. OpenWrt should boot. The NAS will reboot with the default OpenWrt IP address of 192.168.1.1/24. Congrats! NAS is on OpenWrt.
Final house keeping.
Update the MAC address in boot process.
- Connect to the NAS via ssh.
- The u-boot environment is read-only in the latest u-boot image, so it needs to be unlocked first. For that, unzip the packages.zip somewhere (not necessarily on the device) and transfer the
kmod-mtd-rw*.ipk to the NAS.
- Install it with
opkg install <file>. (Attempts to make this part of the image have failed so far).
- Once installed, insert it with
insmod mtd-rw i_want_a_brick=1
- Update the MAC address:
fw_setenv ethaddr fc:75:16:01:04:bd (this is an example, adjust MAC to match sticker on bottom of NAS.
Transfer the openwrt-24.10.5-kirkwood-generic-dlink_dns320-squashfs-sysupgrade.bin to the NAS and install it via the sysupgrade command to re-flash the UBI contents as a single partition (just in case), or use the GUI for firmware updates for it.