Every time before flash a new firmware, I always do a full backup for my current running firmware.
[details=Summary] root@Lede:~# cat backup_full_bin.sh
#!/bin/sh
cat /dev/mtd0 > /tmp/full_flash.bin
cat /dev/mtd1 >> /tmp/full_flash.bin
cat /dev/mtd2 >> /tmp/full_flash.bin
cat /dev/mtd3 >> /tmp/full_flash.bin
echo "Full flash backup store at /tmp/full_flash.bin."
sysupgrade -b /tmp/full_config.tar.gz
echo "Full config backup store at /tmp/full_config.tar.gz."[/details]
If I need restore this backup and my router is bricks, I will using CH341A USB programmer flash the 'full_flash.bin' back to the 16MB SPI NOR flash IC.
But if my router is alive, and I can still ssh access. Is there anyway to flash the full_flash.bin to the router's 16MB SPI flash by linux command insead of the IC flash programmer?
It seems that sysupgrade using 'mtd write' can only write a partition not the whole IC.
I do not like using sysupgrade to restore the whole firmware because it did not restore all the things back, eg. installed package on overlayfs.
Finally, I find the solution myself: file split.
And I make a quick and dirty script to restore my router to snapshot state from the full backup image.
I think this is the fast way let my device go back to work by using the full backup file.
cat restore_full_bin.sh
#!/bin/sh
if [ ! -f /tmp/full_flash.bin ]; then
echo "Backup file not found!"
echo "Please upload backup file you need to restore as /tmp/full_flash.bin and try again."
exit
fi
dd if=/tmp/full_flash.bin of=/tmp/factory.bin bs=1K skip=256 count=64
dd if=/tmp/full_flash.bin of=/tmp/firmware.bin bs=1K skip=320
rm -f /tmp/full_flash.bin
mtd write /tmp/factory.bin factory
mtd -r write /tmp/firmware.bin firmware
and post the output text, in order to find out your partition layout, for generate full_flash.bin.
if you feel demsg output too long, you can cut only message like this.
[ 3.371920] 4 fixed-partitions partitions found on MTD device spi0.0
[ 3.384582] Creating 4 MTD partitions on "spi0.0":
[ 3.394142] 0x000000000000-0x000000030000 : "u-boot"
[ 3.405031] 0x000000030000-0x000000040000 : "u-boot-env"
[ 3.416510] 0x000000040000-0x000000050000 : "factory"
[ 3.427464] 0x000000050000-0x000002000000 : "firmware"
[ 3.438769] 2 uimage-fw partitions found on MTD device firmware
[ 3.450570] Creating 2 MTD partitions on "firmware":
[ 3.460472] 0x000000000000-0x0000001d944a : "kernel"
[ 3.471503] 0x0000001d944a-0x000001fb0000 : "rootfs"
[ 3.482407] mtd: device 5 (rootfs) set to be root filesystem
[ 3.493827] 1 squashfs-split partitions found on MTD device rootfs
[ 3.506166] 0x000000fc0000-0x000001fb0000 : "rootfs_data"
Your firmware have no bootloader partition, mtd device address 0x00000000, size 0x00030000.
I think there is no simple way to make full flash (for SPI programmer) backup.
If you know what bootloader your router using, you may using bootloder's backup feature to make full flash backup.
thank you for reply.
please tell me from x000000030000 to x00000040000 for this firmware.
from 0 to 30000 I has from another backup.
from 30000 to 40000 I do not know is?
from 40000 to 50000 maybe is factory or u-boot-env not sure?
from 50000 to end is firmware.
please tell me 30000 to 40000 and 40000 to 50000?
thank you.
I think 0x30000 u-boot-env is uboot data partition, to save some uboot settings.
0x40000 is storing factory data partition which can reset your router to default factory settings.
If you already have a full flash backup, you can simply take out bootloader bin file from it. And you will get full_flash.bin.
thank your help.
I have 2 full backup files with 32768KB and 1 file from my current router for x30000-x40000
file from current the same as factory file. but 2 other files do not like factory file.
these files following .
I am using raspberrypi2 as 32MB SPI programmer, every time after my router upgrade, I always make full flash backup and scp to raspberrypi2, make two backup into two IC.
root@ras RaspberryPi2 ~ #
cat burn_full_flash.sh
#!/bin/bash
echo "==== SPI flash IC 0 ===="
time flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=25000 -w /root/full_flash.bin
echo "==== SPI flash IC 1 ===="
time flashrom -p linux_spi:dev=/dev/spidev0.1,spispeed=25000 -w /root/full_flash_old.bin
and raspberrypi2 also as my router's serial port monitor, in order to catch some kernel crash of my router. alias scap='screen /dev/ttyAMA0 57600'
I tell you know about this router:
At first Pandora boot on, i can only telnet to it, using Winscp not work.
at this time i use this command to save MTD.
cat /dev/mtd2 > /tmp/firware.bin
-cat /dev/mtd7 > /tmp/nvram.bin
using HxD edit I found that 2 files factory.bin and u-boo-env.bin the same content.
The second i do with this router is
go to Chome brower insert this line: http://192.168.99.1/newifi/ifiwen_hss.html
and letter "succes" on screen after that:
I can telnet by putty and ssh by Wincp to this router, I use some command as upper, i found that u-boot-env.bin had nothing on this file(content).
As you say x30000-x40000 is u-boot-env.bin, please tell me x30000-x40000 should I put nothing or the same Factory.bin.
Thanks your help.
I suggest you do not modify or overwrite u-boot-env partition if you do not known what bootloader your router using.
Pandora box is a modified Openwrt maintained by Chinese community so I suppose you known Chinese.
Newfi D2 using pb-boot as factory bootloader, but many user flash breed bootloader before change to the 3rd part firmware like Pandora box or padavan.
If your router's bootloader is breed, there is a very simple way to get the full flash bin.
Power off Newfi D2
Hold reset button Power on Newfi D2 and keep holding reset button 5 sec.
assign your PC an static IP address 192.168.1.11 and wire connect to Newfi D2. Visit http://192.168.1.1 the Breed Web UI.