Terminal

備份 Nand Flash 儲存區

  • November 27, 2017

板載 Linux 版本 2.6.26.5 嵌入式系統。設備使用完整圖像的核心。儲存在 NAND 快閃記憶體上的文件系統,Hynix NAND 32MiB 3,3V 8 位。

# printenv
baudrate=115200
ethaddr=FF:FF:FF:FF:FF:FF
netmask=255.255.255.0
ipaddr=192.168.1.1
serverip=192.168.1.100
bootfile=firetux.kernel
bootcmd1=setenv bootargs ${bootargs} && nboot 0x20200000 0 ${image_addr} && bootm 0x20200000
bootcmd2=setenv bootargs ${bootargs} && tftpboot 20200000 firetux.kernel && bootm 20200000
phymode=auto
mtdids=nand0=gen_nand
unlock=yes
verify=y
update.uboot=echo Update u-boot && tftpboot 0x20000000 nandboot.flash && nand erase 0x0 0x03ffff && nand write.jffs2 0x20000000 0x0 ${filesize}
update.kernel=echo Update kernel && tftpboot 0x20000000 uImage && nand erase 0x80000 0x180000 && nand write.jffs2 20000000 0x80000 0x180000
update.romimg=echo Update RomImage && tftpboot 0x20000000 romimage.img && nand erase 0x80000 0x13e0000&& nand write.jffs2 20000000 0x80000 ${filesize}
update.halfimg=echo Update HalfImage && tftpboot 0x20000000 recovery.img && nand erase 0x1460000 0x700000&& nand write.jffs2 20000000 0x1460000 ${filesize}
eraseenv=echo Erase Environment && nand erase 0x60000 0x20000
HwModel=Hw_Model=NXPi02
bootcmd=run bootcmd1
halfImage=half_image=0
cy_boot_code_ver=1.0.1 (Oct  6 2011 - 20:04:00)
RouterMode=Router_Mode=0
stdin=serial
stdout=serial
stderr=serial
bootcmd=run bootcmd1
image_addr=0x80000
bootargs=console=ttyS1,115200n8 rootfstype=squashfs noalign half_image=0 verify=y Hw_Model=NXPi02 Router_Mode=0
ethact=ETN1
bootdelay=3

需要從 U-boot 備份 NAND 記憶體 (NVRAM) 的某些區域,通過串列介面 (UART) 連接到板,網路連接不可用。U-boot 有一些管理 nand 記憶體的選項:

# help nand
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read - addr off|partition size
nand write - addr off|partition size
   read/write 'size' bytes starting at offset 'off'
   to/from memory address 'addr', skipping bad blocks.
nand erase [clean] [off size] - erase 'size' bytes from
   offset 'off' (entire device if not specified)
nand bad - show bad blocks
nand dump[.oob] off - dump page
nand scrub - really clean NAND erasing bad blocks (UNSAFE)
nand markbad off - mark bad block at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)

尤其,nand dump[.oob] off - dump page

什麼是 nand偏移地址?沒有指定要轉儲的分區大小。我需要轉儲整個 NVRAM。

設備載入核心映像後,會創建 11 個 MTD 分區:

Creating 11 MTD partitions on "gen_nand":
0x00000000-0x00060000 : "u-boot"
0x00060000-0x00080000 : "u-bootenv"
0x00080000-0x01460000 : "ROMIMAGE"
0x01460000-0x01b60000 : "HALFIMAGE"
0x00200000-0x01460000 : "LINUX_ROOTFS"
0x01b60000-0x01d60000 : "HS_FW"
0x01d60000-0x01e60000 : "FPAR"
0x01e60000-0x01ee0000 : "SNOM"
0x01ee0000-0x01f00000 : "EEPROM"
0x01f00000-0x01f80000 : "NVRAM"
0x01f80000-0x02000000 : "CA_DATA"

0x01f00000nvram 偏移地址嗎?什麼是 nvram 大小?是0x80000嗎?U-boot也有命令md - memory display

=> help md
md - memory display
Usage:
md [.b, .w, .l] address [# of objects]
=>

我嘗試md.b 0x01f00000 0x80000在終端上顯示 nvram 的命令,但它不輸出任何內容,終端掛斷。


編輯:

$$ an addition $$

# nand info

Device 0: NAND 32MiB 3,3V 8-bit, sector size 16 KiB
# nand device nand0
Device 0: NAND 32MiB 3,3V 8-bit... is now current device
# nand read 0x20000000 NVRAM

NAND read: mtdparts variable not set, see 'help mtdparts'
incorrect device type in NVRAM
'NVRAM' is not a number
# nand read 0x20000000 0x01f00000 0x00080000

NAND read: device 0 offset 0x1f00000, size 0x80000
524288 bytes read: OK

BusyBox v1.10.2 (2015-09-06 10:58:05 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/bin/sh: can't access tty; job control turned off
# help

Built-in commands:
-------------------
   . : [ [[ alias bg break cd chdir continue echo eval exec exit
   export false fg hash help jobs let local pwd read readonly return
   set shift source test times trap true type ulimit umask unalias
   unset wait

# ext4write LINUX_ROOTFS /NVRAM.img 0x20000000 0x00080000
/bin/sh: ext4write: not found

您將需要更加小心地使用命令。md 命令顯示該位置的記憶體。當您使用 md.b 時,它以字節為單位輸出,這無疑會使您的 tty 感到困惑。您的命令基本上是說將記憶體中從 0x01f00000 到 0x01f00000 + 0x80000 的所有字節發送給我。此外,nanddumb 不會像您認為的那樣做。

獲取設備

nand info

設置您的設備

nand device nand0

只需使用分區的名稱

nand read 0x20000000 NVRAM 0x00080000

要清楚這是做什麼的:從分區 nvram 讀取 524288(十六進制的 0x00080000)字節到記憶體位置 0x20000000。如果您想要整個分區,也可以省略大小。

nand read 0x20000000 NVRAM

現在有了記憶體中的 NVRAM,您需要將其寫入某處。讓我們說一個 ext4 文件系統。

ext4write LINUX_ROOTFS /NVRAM.img 0x20000000 0x00080000

引用自:https://unix.stackexchange.com/questions/407119