找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2985|回复: 5

大容量Nand Flash 光猫固件备份方法

[复制链接]
发表于 2024-1-4 00:51:51 | 显示全部楼层 |阅读模式
本帖最后由 jiuweiljp 于 2024-1-4 01:05 编辑

使用条件:
     1、有usb接口并且能驱动U pan的无视这个方法;
     2、光猫不能telnet,并没有tftp或者wget、chmod命令也可以不用看;

正文如下
手上有一个闲置的中兴光猫F657GV9,焊接TTL线后启动信息如下(可无视):
  1. U-Boot 2013.04 (Sep 11 2021 - 00:00:57)

  2. CPU  : ZX279127S@A9,1000MHZ
  3. Board: ZXIC zx279127sevb
  4. 127s product_vid = 158
  5. DRAM:  256 MiB
  6. 127s product_vid = 158
  7. ,10000000,50000000
  8. cpuid=27912710
  9. 127s pinmux: 3f7ffffa  3ffffeff  19ff0555  6be1b
  10. 127s product_vid = 158
  11. bootsel=3
  12. NAND:  
  13. Manu ID: 0x2c, Chip ID: 0x24 (Micron SPI NAND MT29F2G01ABAGDWB  256MiB 3,3V)
  14. 256 MiB
  15. <nand_read_skip_bad_,447>!mtdpart=0x1,offset=0x0,mtdpartoffset=0x180000,mtdPartsize=0x80000,length=0x20000
  16. In:    serial
  17. Out:   serial
  18. Err:   serial
  19. clk_pll env is not setted, core clk won't change
  20. Net:   enter ref_clk_set.. mode = 0 .
  21. enter pll_cfg_fractional
  22. ref_clk_set success!
  23. gpon serdes init
  24. addr 0x9400002c before value is 11000013
  25. addr 0x9400004c after value is 11003ff3
  26. eth0
  27. sec mode!

  28. Hit 1 to upgrade software version
  29. Hit any key to stop autoboot:  0
  30. addr=1200000
  31. addr=4200000
  32. select=0x0
  33. search=0x2
  34. <nand_read_skip_bad_,447>!mtdpart=0x6,offset=0x0,mtdpartoffset=0x200000,mtdPartsize=0x200000,length=0x1000
  35. tmp=0x00000000, value=0
  36. select=0x0
  37. search=0x2
  38. search->result[0].entry=1200240
  39. <nand_read_skip_bad_,447>!mtdpart=0x2,offset=0x0,mtdpartoffset=0x1200000,mtdPartsize=0x3000000,length=0x23e0000
  40. RSA Verify OK

  41. ---mtdparts_init--current_mtd_partnum=0-
  42. dev id: type = 2, num = 0, size = 0xffffffff, mtd_id = single part
  43. part  : name = rootfs0, size = 0x023c0000, offset = 0x01220000
  44. part  : name = rootfs1, size = 0x023c0000, offset = 0x04220000

  45. --- jffs2_part_info: partition number 0 for device nand0 (single part)
  46. jffs2_part_info:rootfs0,1220000
  47. ### JFFS2 loading '0uImage' to 0x44000000
  48. Scanning JFFS2 FS: ..................... done.
  49. ### JFFS2 load complete: 4344391 bytes loaded to 0x44000000
  50. 127s product_vid = 158
  51. <nand_read_skip_bad_,447>!mtdpart=0x0,offset=0x0,mtdpartoffset=0x0,mtdPartsize=0x180000,length=0x100000
  52. lseek=0x42080800
  53. cmdline=U-Boot V1.0.0P1N1 20210911001937
  54. output gpio:58, value=1, 0
  55. output gpio:59, value=1, 0
  56. ## Booting kernel from Legacy Image at 44000000 ...
  57.    Image Name:   Linux Kernel Image
  58.    Image Type:   ARM Linux Kernel Image (uncompressed)
  59.    Data Size:    4344327 Bytes = 4.1 MiB
  60.    Load Address: 40008000
  61.    Entry Point:  40008000
  62.    Verifying Checksum ... OK
  63.    Loading Kernel Image ... OK
  64. OK
  65. ----------------------
  66. |-->setup versioninfo tag...

  67. Starting kernel ...
复制代码
根据启动信息可以得知
cpu(ZX279127S@A9,1000MHZ)后面再吐槽它,内存(DRAM: 256 MiB),闪存用的美光(Micron SPI NAND MT29F2G01ABAGDWB 256MiB 3,3V其实这个光猫也有USB接口,我测量过没有5V输出,如果想USB好用需要补元件。

使用工具软件打开光猫telnet并登录后查看mtd信息
  1. / # cat /proc/mtd
  2. dev:    size   erasesize  name
  3. mtd0: 10000000 00020000 "whole flash"
  4. mtd1: 00200000 00020000 "u-boot"
  5. mtd2: 00200000 00020000 "others"
  6. mtd3: 00200000 00020000 "parameter tags"
  7. mtd4: 00200000 00020000 "wlan"
  8. mtd5: 00800000 00020000 "usercfg"
  9. mtd6: 00200000 00020000 "middleware"
  10. mtd7: 03000000 00020000 "kernel1"
  11. mtd8: 03000000 00020000 "kernel2"
  12. mtd9: 01000000 00020000 "framework1"
  13. mtd10: 01000000 00020000 "framework2"
  14. mtd11: 01800000 00020000 "preplugin_data"
  15. mtd12: 05600000 00020000 "plugin_data"
  16. mtd13: 02fe0000 00020000 "rootfs"
复制代码
可以看见有一个MTD0它就是一个完整的nand flash影像把它拷贝出来就是一个完整且连续的flash备份,有人会说下面不是有MTD1-13,分别拷贝不方便点吗?
1、mtd1-13 加起来是超过256MB的;
2、你不知道它mtd1-13在flash存储地址是不是按1-13这个编号连续分布的;

我查过启动信息如下:(我没看出来有MTD地址分布信息
  1. /opt/cu/apps # ./busybox1 dmesg
  2. NET: Registered protocol family 24
  3. p p t p driver version 0.8.5
  4. 127s doesn't have USB3.0,just return -ENODEV
  5. **********TOP_CRM_BASE+0x2c=0x11393ff3******
  6. **********TOP_CRM_BASE+0x2c=0x113f3ff3******
  7. dwc2 9000000.usb: 1792 invalid for host_rx_fifo_size. Check HW configuration.
  8. dwc2 9000000.usb: 1024 invalid for host_nperio_tx_fifo_size. Check HW configuration.
  9. dwc2 9000000.usb: 1024 invalid for max_packet_count. Check HW configuration.
  10. dwc2 9000000.usb: DWC OTG Controller
  11. dwc2 9000000.usb: new USB bus registered, assigned bus number 1
  12. dwc2 9000000.usb: irq 60, io mem 0x00000000
  13. usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
  14. usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
  15. usb usb1: Product: DWC OTG Controller
  16. usb usb1: Manufacturer: Linux 4.1.25 dwc2_hsotg
  17. usb usb1: SerialNumber: 9000000.usb
  18. hub 1-0:1.0: USB hub found
  19. hub 1-0:1.0: 1 port detected
  20. usbcore: registered new interface driver cdc_acm
  21. cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
  22. usbcore: registered new interface driver usbserial
  23. usbcore: registered new interface driver usbserial_generic
  24. usbserial: USB Serial support registered for generic
  25. usbcore: registered new interface driver ch341
  26. usbserial: USB Serial support registered for ch341-uart
  27. usbcore: registered new interface driver cp210x
  28. usbserial: USB Serial support registered for cp210x
  29. usbcore: registered new interface driver pl2303
  30. usbserial: USB Serial support registered for pl2303
  31. mousedev: PS/2 mouse device common for all mice
  32. I2C probe start!
  33. zx_i2c_probe i2c-1 i2c-1->clk is ccdce7c0 ,clk rate is 100000000
  34. I2C probe successed!
  35. usbcore: registered new interface driver usbhid
  36. usbhid: USB HID core driver
  37. zx tempsensor: zx_bsp_tempsensor.regs = 0xf0500034,&(zx_bsp_tempsensor.regs->cfg)= 0xf0500034
  38. bsp_temp_start,val = 0x2ef
  39. (458):creat proc files for temper sensor!!!
  40. (463):temper sensor is running...
  41. zx tempsensor: work clock 0
  42. zx tempsensor: selector0's int num 27 allocated.
  43. zx tempsensor: selector1's int num 28 allocated.
  44. zx tempsensor: selector2's int num 29 allocated.
  45. Netfilter messages via NETLINK v0.30.
  46. nf_conntrack version 0.5.0 (3372 buckets, 60000 max)
  47. ip_set: protocol 6
  48. gre: GRE over IPv4 demultiplexor driver
  49. ip_tables: (C) 2000-2006 Netfilter Core Team
  50. NET: Registered protocol family 10
  51. ip6_tables: (C) 2000-2006 Netfilter Core Team
  52. sit: IPv6 over IPv4 tunneling driver
  53. NET: Registered protocol family 17
  54. bridge: automatic filtering via arp/ip/ip6tables has been deprecated. Update your scripts to load br_netfilter if you need this.
  55. Bridge firewalling registered
  56. Ebtables v2.0 registered
  57. l2tp_core: L2TP core driver, V2.0
  58. l2tp_ppp: PPPoL2TP kernel driver, V2.0
  59. 8021q: 802.1Q VLAN Support v1.8
  60. systools version:v0.7.5
  61. zte--oss cpu usage module init
  62. DPI interface Loaded
  63. e8_init OK!
  64. Registering SWP/SWPB emulation handler
  65. FLowRL module init
  66. DevBw module init
  67. jffs2: notice: (1) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  68. VFS: Mounted root (jffs2 filesystem) readonly on device 31:13.
  69. Freeing unused kernel memory: 212K (c07d3000 - c0808000)
  70. This architecture does not have kernel memory protection.
  71. jffs2: notice: (532) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  72. jffs2: notice: (577) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  73. jffs2: notice: (585) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  74. jffs2: notice: (587) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  75. 11930:23:02 [Klogfile][Error] [(1348)CheckLogConfFile] CheckLogConfFile%CheckRestartCntConfFile

  76. jffs2: notice: (578) check_node_data: wrong data CRC in data node at 0x006d5d7c: read 0x19d3a03, calculated 0x1e78a0ef.
  77. ubi0: attaching mtd12
  78. ubi0: scanning is finished
  79. ubi0: attached mtd12 (name "plugin_data", size 86 MiB)
  80. ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
  81. ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
  82. ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
  83. ubi0: good PEBs: 688, bad PEBs: 0, corrupted PEBs: 0
  84. ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
  85. ubi0: max/mean erase counter: 14/9, WL threshold: 4096, image sequence number: 2012089330
  86. ubi0: available PEBs: 0, total reserved PEBs: 688, PEBs reserved for bad PEB handling: 16
  87. ubi0: background thread "ubi_bgt0d" started, PID 601
  88. UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 607
  89. UBIFS (ubi0:0): recovery needed
  90. UBIFS (ubi0:0): recovery completed
  91. UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "plugin_ubifs"
  92. UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
  93. UBIFS (ubi0:0): FS size: 83423232 bytes (79 MiB, 657 LEBs), journal size 4190208 bytes (3 MiB, 33 LEBs)
  94. UBIFS (ubi0:0): reserved for root: 3940284 bytes (3847 KiB)
  95. UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 156BD46D-0725-43B0-AA2C-8A8DCD1D83F4, small LPT model
  96. jffs2: notice: (618) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
  97. lo up
  98. mux[0]=3f7ffffa
  99. mux[1]=3ffffeff
  100. mux[2]=19ff0555
  101. mux[3]=6be1b
  102. storage_wakeup_proc_create success!
  103. verinfo=U-Boot V1.0.0P1N1 20210911001937 0x1200000 0x0 0x8f 0x83
  104. can find /usr/java/osgi_verosgi_version_info_get error!
  105. data_in=0x0
  106. data_in=0x0
  107. >>TagaramodInit the typeindex:  5
  108. >>TagaramodInit the board_name:  F657GV9 ,wan=0x40
  109. pon init
  110. ZX_PA_BUF_BASE0=4dea0000
  111. ZX_VA_BUF_BASE0=cdea0000
  112. ZX_BP_BUFFER_BASE=4dec0000
  113. ZX_DESC_BASE=4ee80000
  114. ZX_TX_UP_DESC_BASE=4ef40000
  115. ZX_TX_DN_DESC_BASE=4ef50000
  116. ZX_BPPE_SW_BASE=4dea0000
  117. ZX_BP_BUFFER_SW_BASE=4dec0000
  118. ZX_DESC_SW_BASE=4ea00000
  119. ZX_TX_UP_DESC_SW_BASE=4eac0000
  120. ZX_BPPE_BASE_127S=4eae0000
  121. ZX_BP_BUFFER_BASE_127S=4eb02000
  122. BP_BUFFER_SIZE_127S=b40000
  123. ZX_VA_TX_DN_DESC_BASE=cef50000
  124. BPPE_POOL_SIZE=1c00
  125. NORMAL_BP_BUFFER_SIZE=fc0000
  126. JUMBO_BP_SIZE=2800
  127. JUMBO_BPPE_POOL_SIZE=0
  128. BP_BUFFER_SIZE=fc0000
  129. lan_up=0, lan_up_port=0
  130. the pon mode is 40
  131. lan_up=0, lan_up_port=0
  132. g_pon_irq=36,d1000000,f0400000,f0500000,f0600000,d0e00000
  133. get npp irq succeed,g_npp_irq:38
  134. get tm irq succeed,g_tm_irq:41 tm_base:0xf4340000
  135. get pp irq succeed,g_pp_irq:37
  136. get idm irq succeed,g_idm_irq:39
  137. enter ref_clk_set.. mode = 0 .
  138. enter pll_cfg_fractional
  139. ref_clk_set success!
  140. serdes band cpu_temper:32 coarse:0x29
  141. band calc fin
  142. pon tm init
  143. enter pon_tm_bppe_pool_init
  144. bppe_va_addr = 0xceae0000
  145. jumbo_bppe_va_addr = 0xceaf0000
  146. BMU_JUMBO_BPPE_SW_PTR  =0x0    (JUMBO_BPPE_SW_POOL_SIZE)<<16=0x0
  147. netif_napi_add() called with weight 512 on device pon
  148. DMA_UP_DESC_CNT = 0x0
  149. pon_tm net init ok,272/176
  150. pon_pp init
  151. pon_npp init
  152. idm_status_proc success!
  153. idm_desc_init d0c35000/4c980000
  154. request idm irq succeed
  155. idm net init ok
  156. switch_phy_int_check 0
  157. mac 0 link down
  158. switch_phy_int_check 1
  159. mac 1 link down
  160. switch_phy_int_check 2
  161. mac 2 link down
  162. switch_phy_int_check 3
  163. mac 3 link down
  164. register fpga driver success, major=222
  165. register peripheral success, major = 106
  166. = TM Module SYS FS Init ended successfully =
  167. tm_initModule begin...
  168. enter tm_sdk_init  
  169. api lock init!!
  170. tm_initModule end...
  171. hw_power_optx_get_fordg:txdisable=0
  172. Kmodule ZX279511.ko insmod successfully !
  173. bob is not GN25L95: 40
  174. pon up
  175. ethdriver_init....
  176. g_mii_dev_name[0]  sw
  177. g_mii_dev_name[1]  pon
  178. sw up
  179. zteGpmac_devReg begin...
  180. zteGpmac_devReg end...
  181. enter zteGponCpuTypeAddrSet
  182. *
  183. asicGlbDb[97], 0x46,0x31007,0x0
  184. zteGpmac_initModule begin...
  185. === GponMac Supported MaxTcont: 16 MaxPLI: 800B ===
  186. htb debug 1 =====> inCnt =0,outCnt=0
  187. ##huoqf zteGponAsicStarttimeChkResultInit write cfg=10
  188. ##huoqf zteGponAsicStarttimeChkResultInit read cfg=10
  189. = PON Module Operate ended successfully =
  190. DEbug: GPON PIN_MUX_REG2:(0x19ff0555)
  191. DEbug: GPON GPIO_PDD_REG:(0xfac)
  192. DEbug: GPON GPIO_POSEDGE_REG:(0x4)
  193. DEbug: GPON PIN_MUX_REG3:(0x2be1b)
  194. create zteGpon_rei_task ok!
  195. = GMAC Module SYS FS Init ended successfully =
  196. zteGpmac_initModule end...
  197. gpon_Init ok
  198. gpondrv g_OnuType is 2
  199. 11930:23:06 [KMONITOR][Warn] [monitor.c(607)MontorSendMsg] netlink_unicast failedmsgid = 0xa5c2, ptr = bf26dd20, len = 4
  200. omci up
  201. Init switch module
  202. unicnt 4, wancnt 1, wifi cnt 0, all ports 5, portmask 0x0000002f
  203.   Onu type is 1,Wan type is 4
  204. switch config GPON HGU mode!
  205. protocol fail, error deal 66
  206. [TM][dpa_set_protocol_type_i_act] failed
  207. protocol fail, error deal 65
  208. [TM][dpa_set_protocol_type_i_act] failed
  209. -------chip_tm_init end-----
  210. [SW][sw_init_switch] l2_fast init
  211. [SW]set cpu queue rate limit to 8000pps
  212. tm_port_egress_traffic_sharp_set p_port:5 p_ena:1 p_band_width:2048

  213. Capacity=256000tm_port_egress_traffic_sharp_set p_port:6 p_ena:1 p_band_width:2048

  214. Capacity=256000[SW][sw_init_switch] reg hff
  215. [SW][sw_init_switch] reg get statistics
  216. Init switch module Success
  217. bsp_i2c_probe 0x50 success!
  218. vendor name = ZTE_PX20+_G
  219. optical PN(0x60) =
  220. optical PN(0x28) = ZX279511
  221. tdm: exports duplicate symbol tdm_ch_close (owned by kernel)
  222. udpwatchd inited!
  223. kudp  inited!
  224. Init codec v2.3(2019-05-17)!
  225. idm0 up
  226. idm1 up
  227. redirusb_init,no usb dev!
  228. random: dbus-uuidgen urandom read with 47 bits of entropy available
  229. gpondrvCfgXGRegInfoAdapter not support now!
  230. === GponMac Supported MaxTcont: 8 MaxPLI: 1536B ===
  231. htb debug 1 =====> inCnt =0,outCnt=0
  232. IPv6: ADDRCONF(NETDEV_UP): br0: link is not ready
  233. br0 up
  234. ethdrv_dev_ioctl  ,brdev_set.port_id 0 ,brdev_set.name eth0 ,brdev_set.flag 0
  235. eth0 up
  236. ethdrv_dev_ioctl  ,brdev_set.port_id 1 ,brdev_set.name eth1 ,brdev_set.flag 0
  237. eth1 up
  238. ethdrv_dev_ioctl  ,brdev_set.port_id 2 ,brdev_set.name eth2 ,brdev_set.flag 0
  239. eth2 up
  240. ethdrv_dev_ioctl  ,brdev_set.port_id 3 ,brdev_set.name eth3 ,brdev_set.flag 0
  241. eth3 up
  242. tm_port_egress_traffic_sharp_set p_port:3 p_ena:0 p_band_width:0

  243. Capacity=200000tm_port_egress_traffic_sharp_set p_port:2 p_ena:0 p_band_width:0

  244. Capacity=200000tm_port_egress_traffic_sharp_set p_port:1 p_ena:0 p_band_width:0

  245. Capacity=200000tm_port_egress_traffic_sharp_set p_port:0 p_ena:0 p_band_width:0

  246. Capacity=200000
  247. switch_phy_int_check 1
  248. pon0 up
  249. set_netdev_type dev (pon0) type (300) vendor name = ZTE_PX20+_G
  250. optical PN(0x60) =
  251. optical PN(0x28) = ZX279511
  252. device eth0 entered promiscuous mode
  253. set_netdev_type dev (eth0) type (800)
  254. device eth1 entered promiscuous mode
  255. set_netdev_type dev (eth1) type (800)
  256. device eth2 entered promiscuous mode
  257. br0: port 3(eth2) entered forwarding state
  258. br0: port 3(eth2) entered forwarding state
  259. IPv6: ADDRCONF(NETDEV_CHANGE): br0: link becomes ready
  260. set_netdev_type dev (eth2) type (800)
  261. device eth3 entered promiscuous mode
  262. set_netdev_type dev (eth3) type (800) set_netdev_type dev (pon0) type (300) set_netdev_type dev (pon0) type (300) set_netdev_type dev (pon0) type (300)
  263. ch:0 pcm mode:G711A_U
  264. Siliconlab chip id error! 0x0
  265. cmd [ck 1389 1] not found
  266. ====EVENT_O7_STATE_SAVE OFF====
  267. cmd [ck 1392 1] not found
  268. cmd [ck 1387 1] not found
  269. random: nonblocking pool is initialized
  270. device br0 entered promiscuous mode
  271. tm_port_egress_traffic_sharp_set p_port:5 p_ena:0 p_band_width:0

  272. Capacity=200000tm_port_egress_traffic_sharp_set p_port:6 p_ena:0 p_band_width:0

  273. Capacity=200000
  274. overlayfs: missing 'workdir'
复制代码

但是将这个mtd0自接考出来是不容易的,因为它的内存也就256MB,临时分区也容不下这个falsh影像
  1. /opt/cu/apps # df
  2. Filesystem           1024-blocks    Used Available Use% Mounted on
  3. /dev/root                49024     37824     11200  77% /
  4. /dev/mtdblock3            2048       404      1644  20% /tagparam
  5. cgroup_root             108016         0    108016   0% /sys/fs/cgroup
  6. none                     21604         0     21604   0% /run
  7. none                      5120         0      5120   0% /run/lock
  8. none                    108016         0    108016   0% /run/shm
  9. tmpfs                    20480       448     20032   2% /var
  10. tmpfs                    81920      2800     79120   3% /upgtempfile
  11. tmpfs                     2048         0      2048   0% /mnt
  12. tmpfs                    15360         4     15356   0% /tmp
  13. /dev/mtdblock5            8192       640      7552   8% /userconfig
  14. /dev/mtdblock6            2048       384      1664  19% /usr/local/ct
  15. /dev/mtdblock11          24576      6232     18344  25% /usr/tmp
  16. /dev/loop0                5376      5376         0 100% /usr/pre_plugin
  17. ubi0_0                   74660      2864     67948   4% /opt/cu/apps
  18. /dev/mtdblock4            2048       436      1612  21% /wlan
  19. overlay                  74660      2864     67948   4% /CuInform
  20. tmpfs                     5240        24      5216   0% /CuInform/tmp
  21. overlay                  74660      2864     67948   4% /usr/sbin
  22. /dev/mtdblock9            4352      4352         0 100% /opt/cu/framework
复制代码
可以看见也就/upgtempfile 文件夹可用,大小为80MB,远远不能满足需求。

以上都是分析,下面是操作步骤:
方法一:采用压缩方法在拷贝flash的时候边拷贝边压缩,然后将压缩后的文件传给电脑:
  1. dd if=/dev/mtd0 | gzip > /upgtempfile/mtd0.gz
复制代码
我使用上述方法临时目录还是无法容纳,只有用更强的压缩方式,linux中有一个.xz文件它使用LZMA的压缩方式,LZMA压缩比相比较zip高不少,但在busybox中的命令xz只能解压这种文件,无法压缩。只能从网上下载完整代码自己编译一个。
  1. /opt/cu/apps # ./xz-v5 -H
  2. Usage: ./xz-v5 [OPTION]... [FILE]...
  3. Compress or decompress FILEs in the .xz format.

  4. Mandatory arguments to long options are mandatory for short options too.

  5. Operation mode:
  6.   -z, --compress      force compression
  7.   -d, --decompress    force decompression
  8.   -t, --test          test compressed file integrity
  9.   -l, --list          list information about .xz files

  10. Operation modifiers:
  11.   -k, --keep          keep (don't delete) input files
  12.   -f, --force         force overwrite of output file and (de)compress links
  13.   -c, --stdout        write to standard output and don't delete input files
  14.       --single-stream decompress only the first stream, and silently
  15.                       ignore possible remaining input data
  16.       --no-sparse     do not create sparse files when decompressing
  17.   -S, --suffix=.SUF   use the suffix `.SUF' on compressed files
  18.       --files[=FILE]  read filenames to process from FILE; if FILE is
  19.                       omitted, filenames are read from the standard input;
  20.                       filenames must be terminated with the newline character
  21.       --files0[=FILE] like --files but use the null character as terminator

  22. Basic file format and compression options:
  23.   -F, --format=FMT    file format to encode or decode; possible values are
  24.                       `auto' (default), `xz', `lzma', and `raw'
  25.   -C, --check=CHECK   integrity check type: `none' (use with caution),
  26.                       `crc32', `crc64' (default), or `sha256'
  27.       --ignore-check  don't verify the integrity check when decompressing
  28.   -0 ... -9           compression preset; default is 6; take compressor *and*
  29.                       decompressor memory usage into account before using 7-9!
  30.   -e, --extreme       try to improve compression ratio by using more CPU time;
  31.                       does not affect decompressor memory requirements
  32.   -T, --threads=NUM   use at most NUM threads; the default is 1; set to 0
  33.                       to use as many threads as there are processor cores
  34.       --block-size=SIZE
  35.                       start a new .xz block after every SIZE bytes of input;
  36.                       use this to set the block size for threaded compression
  37.       --block-list=SIZES
  38.                       start a new .xz block after the given comma-separated
  39.                       intervals of uncompressed data
  40.       --flush-timeout=TIMEOUT
  41.                       when compressing, if more than TIMEOUT milliseconds has
  42.                       passed since the previous flush and reading more input
  43.                       would block, all pending data is flushed out
  44.       --memlimit-compress=LIMIT
  45.       --memlimit-decompress=LIMIT
  46.   -M, --memlimit=LIMIT
  47.                       set memory usage limit for compression, decompression,
  48.                       or both; LIMIT is in bytes, % of RAM, or 0 for defaults
  49.       --no-adjust     if compression settings exceed the memory usage limit,
  50.                       give an error instead of adjusting the settings downwards

  51. Custom filter chain for compression (alternative for using presets):
  52.   --lzma1[=OPTS]      LZMA1 or LZMA2; OPTS is a comma-separated list of zero or
  53.   --lzma2[=OPTS]      more of the following options (valid values; default):
  54.                         preset=PRE reset options to a preset (0-9[e])
  55.                         dict=NUM   dictionary size (4KiB - 1536MiB; 8MiB)
  56.                         lc=NUM     number of literal context bits (0-4; 3)
  57.                         lp=NUM     number of literal position bits (0-4; 0)
  58.                         pb=NUM     number of position bits (0-4; 2)
  59.                         mode=MODE  compression mode (fast, normal; normal)
  60.                         nice=NUM   nice length of a match (2-273; 64)
  61.                         mf=NAME    match finder (hc3, hc4, bt2, bt3, bt4; bt4)
  62.                         depth=NUM  maximum search depth; 0=automatic (default)

  63.   --x86[=OPTS]        x86 BCJ filter (32-bit and 64-bit)
  64.   --powerpc[=OPTS]    PowerPC BCJ filter (big endian only)
  65.   --ia64[=OPTS]       IA-64 (Itanium) BCJ filter
  66.   --arm[=OPTS]        ARM BCJ filter (little endian only)
  67.   --armthumb[=OPTS]   ARM-Thumb BCJ filter (little endian only)
  68.   --sparc[=OPTS]      SPARC BCJ filter
  69.                       Valid OPTS for all BCJ filters:
  70.                         start=NUM  start offset for conversions (default=0)

  71.   --delta[=OPTS]      Delta filter; valid OPTS (valid values; default):
  72.                         dist=NUM   distance between bytes being subtracted
  73.                                    from each other (1-256; 1)

  74. Other options:

  75.   -q, --quiet         suppress warnings; specify twice to suppress errors too
  76.   -v, --verbose       be verbose; specify twice for even more verbose
  77.   -Q, --no-warn       make warnings not affect the exit status
  78.       --robot         use machine-parsable messages (useful for scripts)

  79.       --info-memory   display the total amount of RAM and the currently active
  80.                       memory usage limits, and exit
  81.   -h, --help          display the short help (lists only the basic options)
  82.   -H, --long-help     display this long help and exit
  83.   -V, --version       display the version number and exit

  84. With no FILE, or when FILE is -, read standard input.

  85. Report bugs to <lasse.collin@tukaani.org> (in English or Finnish).
  86. XZ Utils home page: <https://tukaani.org/xz/>
复制代码
    到这个地方我走了一段弯路,这里要吐槽这个中兴的这个 ARM cpu (ZX279127S@A9,1000MHZ)TNN的看名字用的是A9并且查看cpu信息用的是ARMv7 指令集,编译好的文件在板子上就是不能跑,查了不短的时间才发现这个cpu要用ARMv5 指令方式编译才能跑起来,典型的挂羊头卖狗肉。
  1. /opt/cu/apps # cat /proc/cpuinfo
  2. processor       : 0
  3. model name      : ARMv7 Processor rev 1 (v7l)
  4. BogoMIPS        : 1987.37
  5. Features        : half fastmult edsp tls
  6. CPU implementer : 0x41
  7. CPU architecture: 7
  8. CPU variant     : 0x4
  9. CPU part        : 0xc09
  10. CPU revision    : 1

  11. Hardware        : ZTE ZX27912X (Device Tree)
  12. Revision        : 0000
  13. Serial          : 0000000000000000
复制代码

后面就简单了, 压缩后的文件为76.1 MB (79,894,956 字节)
  1. /opt/cu/apps/busybox1 dd if=/dev/mtd0 |/opt/cu/apps/xz-v5 -M32MB>/upgtempfile/mtd0.xz    (边拷贝边压缩,用-M32MB参数是因为LZMA压缩特别占用内存,如果不限制使用内存,光猫在拷贝过程后期可能因为内存溢出而重启,我这款就重启了2次,后来加了参数就ok了)
复制代码
这个busybox1 文件也是我传到光猫的,光猫内置busybox文件很简化(有tftp及chmod ),但没有包含dd命令

方法二:
在以上过程中我还参考网上信息Linux 下的dd命令使用详解以及dd if=/dev/zero of=的含义发现有另外一种方式使用netcat(简称nc)传数据,这是个非常有名的工具在busybox中集成了它的简化版,busybox windows版本也可以在 https://frippery.org/files/busybox/ 下载到

1、先在windows中执行命令:(接收数据端)
  1. busybox nc -l -p 12345 >mtd0
复制代码
2、在光猫中执行命令:(传输数据端)
  1. /opt/cu/apps/busybox1 dd if=/dev/mtd0 | /opt/cu/apps/busybox1 nc 192.168.1.2 12345
复制代码
我这里每秒能传300-400KB的数据,整个传输过程大约需要13分钟。


最后留下文件:
busybox for windows



busybox for Arm 使用静态编译,文件较大,但无需另外的库支撑,直接使用



xz for Arm 使用静态编译,文件较大,但无需另外的库支撑,直接使用


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2024-3-3 17:09:09 | 显示全部楼层
感谢!为技术网添砖加瓦!
发表于 2024-3-4 17:41:53 | 显示全部楼层
我去 有必要这么麻烦么,光猫都带tftp小型文件传输服务,在dev目录下 执行tftp -pl mtd0 你电脑的IP   在电脑上打开tftp服务端  想备份哪个都可以啊
 楼主| 发表于 2024-3-10 15:52:19 | 显示全部楼层
qq519948746 发表于 2024-3-4 17:41
我去 有必要这么麻烦么,光猫都带tftp小型文件传输服务,在dev目录下 执行tftp -pl mtd0 你电脑的IP   在电 ...

受教了。这个办法好,测试了下每秒约800+KB/S,256MB需要约6分钟。
发表于 2024-3-11 02:48:49 | 显示全部楼层
谢谢楼主分享
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|小黑屋|宽带技术网 |网站地图 粤公网安备44152102000001号

GMT+8, 2025-9-18 20:23 , Processed in 0.026871 second(s), 4 queries , Redis On.

Powered by Discuz! X3.5 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表