Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =======================================================
- How to restore NAND in Linux (any distro)
- =======================================================
- Warning: Don't do this if you have any bad block in these MTD partitions, especially mtd0 (check your dmesg). And also do this at your own risk, it's highly recommended that you have serial console attached to recover from any bad flash.
- The original mtd0 was saved using the following nanddump command:
- /tmp # ./nanddump -nf usb/mtd0 /dev/mtd0
- Block size 131072, page size 2048, OOB size 64
- Dumping data starting at 0x00000000 and ending at 0x00200000...
- So in order to restore mtd0 back, you can use flash_erase and nandwrite. Below are actual flashing and output. Your output should look exactly like these. If not, don't reboot, and post the question here.
- 1. make sure the mtparts are correct
- # fw_printenv mtdparts
- mtdparts=mtdparts=orion_nand:2M(u-boot),3M(uImage),3M(uImage2),8M(failsafe),112M(root)
- 2. Erase mtd0:
- #flash_erase /dev/mtd0 0 16
- Erase Total 16 Units
- Performing Flash Erase of length 131072 at offset 0x1e0000 done
- 3. Write mtd0 backup file back to NAND:
- # nandwrite -on /dev/mtd0 mtd0
- 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
- Writing data to block 5 at offset 0xa0000
- Writing data to block 6 at offset 0xc0000
- Writing data to block 7 at offset 0xe0000
- Writing data to block 8 at offset 0x100000
- Writing data to block 9 at offset 0x120000
- Writing data to block 10 at offset 0x140000
- Writing data to block 11 at offset 0x160000
- Writing data to block 12 at offset 0x180000
- Writing data to block 13 at offset 0x1a0000
- Writing data to block 14 at offset 0x1c0000
- Writing data to block 15 at offset 0x1e0000
- If you need to restore mtd1 to mtd4, then calculate the number of blocks for each mtd (i.e. a block is 128K, 1M is 8 blocks).
- NOTE:
- The nanddump command above is to back up your own box and later restore it to the same box. To backup mtd0 (or other mtds), make it a little more robust so that it can be used in different boxes without problem (thanks restamp for suggestion), use the following format:
- nanddump --noecc --omitoob -l 0x80000 -f mtd0 /dev/mtd0
- =======================================================
- How to restore NAND in Serial Console
- =======================================================
- Here is what to do if you've decided that you need to restore NAND mtd0 in serial console to go back to stock OS. Assuming only mtd0 was messed up (that's how it usually happens). If the entire NAND was messed up, then use this procedure to restore mtd0 and then calculate the offset and size of the rest of the other mtds. If you're not sure, pls post questions in this thread.
- Caveats: This is something I would not recommend doing, unless you can no loger boot into Debian or Arch. Because If you can use kwboot to boot the box, then you can boot Debian or Arch quite easily, without doing this procedure. See the Debian kernel/rootfs thread for how to create the Debian 4.4 rootfs to use with this box.
- The procedure below has a lot more risk of errors occurred than flashing NAND mtd0 from Linux command line (section A).
- Prerequisites
- r1. This procedure requires a working serial console connected to the Pogo V4. And knowledge how to use kwboot to boot the latest version of u-boot.
- r2. Download the latest u-boot, and kwboot binary as described in the u-boot thread to the serial console server (where you run kwboot). Create a single partition, type Ext3, USB thumbdrive. Copy your backup mtd0 to this USB drive root folder. Plug this USB drive into the Pogo V4 top USB port.
- Restore NAND mtd0
- 1. Connect serial console and use kwboot to boot the Pogo V4. See davygravy instruction for more details. I'm assume that you already know how to use kwboot.
- Run kwboot and interrupt serial console when you see the countdown:
- ./kwboot -t -B 115200 /dev/ttyUSB0 -b uboot.2016.05-tld-1.pogo_v4.mtd0.kwb -p
- Expected output
- Sending boot message. Please reboot the target...-
- Sending boot image...
- 0 % [......................................................................]
- <snip>
- 95 % [......................................................................]
- 97 % [......................................................................]
- 99 % [....................................]
- [Type Ctrl-\ + c to quit]
- U-Boot 2016.05-tld-1 (Jun 12 2016 - 13:41:47 -0700)
- Pogoplug V4
- SoC: Kirkwood 88F6192_A1
- DRAM: 128 MiB
- WARNING: Caches not enabled
- NAND: 128 MiB
- MMC: kwsdio: 0
- *** Warning - bad CRC, using default environment
- In: serial
- Out: serial
- Err: serial
- Net: egiga0
- Hit any key to stop autoboot: 0
- 2. Verify the mtdparts is correct for Pogo V4
- mtdparts
- Expected output
- device nand0 <orion_nand>, # parts = 5
- #: name size offset mask_flags
- 0: u-boot 0x00200000 0x00000000 0
- 1: uImage 0x00300000 0x00200000 0
- 2: uImage2 0x00300000 0x00500000 0
- 3: failsafe 0x00800000 0x00800000 0
- 4: root 0x07000000 0x01000000 0
- active partition: nand0,2 - (uImage2) 0x00300000 @ 0x00500000
- defaults:
- mtdids : none
- mtdparts: none
- 3. Start the USB drive
- usb start
- Expected output
- starting USB...
- USB0: USB EHCI 1.00
- scanning bus 0 for devices... 2 USB Device(s) found
- scanning usb for storage devices... 1 Storage Device(s) found
- 4. Load the backup mtd0. Here the stock mtd0 backup file name was mtd0.pogo_v4
- ext2load usb 0:1 0x800000 /mtd0.pogo_v4
- Expected output
- 2097152 bytes read in 1318 ms (1.5 MiB/s)
- 5. Erase mtd0
- nand erase 0x0 0x200000
- Expected output
- NAND erase: device 0 offset 0x0, size 0x200000
- Erasing at 0x1e0000 -- 100% complete.
- OK
- 6. Flash mtd0.pogo_v4 to NAND mtd0
- nand write 0x800000 0x0 0x200000
- Expected output
- NAND write: device 0 offset 0x0, size 0x200000
- 2097152 bytes written: OK
- 7. Reset the box to boot with stock u-boot
- reset
- Expected output:
- The stock u-boot banner and other info. And then it will proceeed to boot stock OS.
- DONE.
- =======================================================
- Automation script not yet tested
- =======================================================
- I have provided a script that automates this process below also
- Warning: Automating firmware restoration and interactions with bootloaders carries significant risk. Incorrect use could permanently damage your device. This script is provided for educational purposes and should be thoroughly reviewed and tested on a case-by-case basis.
- Prerequisites:
- expect is installed on your system.
- kwboot, and your serial communication tool (minicom, screen, or similar) are installed and configured.
- You have a known-good NAND backup.
- You are familiar with the commands and responses of your device's bootloader.
- Script Overview:
- Use expect to handle kwboot and wait for it to finish.
- Open a serial communication session with expect and execute commands to restore NAND.
- This script assumes familiarity with the specific bootloader commands and responses.
- #!/usr/bin/expect -f
- set timeout -1
- set SERIAL_DEVICE "/dev/ttyUSB0"
- set BAUD_RATE "115200"
- set UBOOT_IMAGE "path/to/uboot.2016.05-tld-1.pogo_v4.mtd0.kwb"
- set MTD0_BACKUP_PATH "path/to/mtd0.pogo_v4"
- # Start kwboot and wait for it to boot the device
- spawn kwboot -t -B $BAUD_RATE $SERIAL_DEVICE -b $UBOOT_IMAGE -p
- expect "Sending boot image..."
- expect "99 %"
- send -- "\r"
- expect eof
- # Now interact with the serial console
- spawn minicom -D $SERIAL_DEVICE -b $BAUD_RATE
- # Example of interacting with U-Boot or bootloader
- # Stop autoboot
- expect "Hit any key to stop autoboot:"
- send -- "\r"
- # Check for the prompt, adjust based on your bootloader
- expect "Pogoplug>"
- # Start the USB and load the backup to RAM, adjust commands to your environment
- send -- "usb start\r"
- expect "USB Device(s) found"
- send -- "ext2load usb 0:1 0x800000 /mtd0.pogo_v4\r"
- expect "bytes read"
- # Erase and write NAND, adjust as necessary
- send -- "nand erase 0x0 0x200000\r"
- expect "OK"
- send -- "nand write 0x800000 0x0 0x200000\r"
- expect "OK"
- # Finish and reboot, adjust if needed
- send -- "reset\r"
- expect eof
- # Close the session
- send -- "\035\014"
- expect eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement