Comtrend STB-7007 backup memoria flash (V)

Llegados a este punto, con información sobre el hardware y el software. Seria importante realizar un backup de la memoria flash por lo que pueda pasar, sobretodo si vamos a tocar cosas y encontrar el problema que luego no arranca el sistema.

Para realizar la copia, utilizaremos el comando dd y conectaremos un pendrive en el USB.

Con el comando cat /proc/mtd nos informa que el sistema tiene un total de 18 particiones.

[root@stb:/] # cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00080000 00010000 "CFE"
mtd1: 00020000 00010000 "CFE config"
mtd2: 00320000 00010000 "reserved"
mtd3: 00020000 00010000 "secure storage"
mtd4: 0001f800 00010000 "MAC address"
mtd5: 00000800 00010000 "hdcp"
mtd6: 00800000 00020000 "Kernel"
mtd7: 00c00000 00020000 "/usr"
mtd8: 01000000 00020000 "/usr/local"
mtd9: 02000000 00020000 "/usr/lib/MediaBrowser"
mtd10: 02000000 00020000 "/usr/lib/MediaServer"
mtd11: 00800000 00020000 "Kernel (alt)"
mtd12: 00c00000 00020000 "/usr (alt)"
mtd13: 01000000 00020000 "/usr/local (alt)"
mtd14: 02000000 00020000 "/usr/lib/MediaBrowser (alt)"
mtd15: 02000000 00020000 "/usr/lib/MediaServer (alt)"
mtd16: 00400000 00020000 "Splash"
mtd17: 32e00000 00020000 "/rw/yaffs"
[root@stb:/] #

Durante el proceso de arranque se crean 6 particiones (mtd0 a mtd5) que corresponden con la memoria NOR Flash Spansion S29GL032A.

Creating 6 MTD partitions on "Broadcom 9xxxx mapped flash":
0x0000000000000000-0x0000000000080000 : "CFE"
0x0000000000080000-0x00000000000a0000 : "CFE config"
0x00000000000a0000-0x00000000003c0000 : "reserved"
0x00000000003c0000-0x00000000003e0000 : "secure storage"
0x00000000003e0000-0x00000000003ff800 : "MAC address"
mtd: partition "MAC address" doesn't end on an erase block -- force read-only
0x00000000003ff800-0x0000000000400000 : "hdcp

Mapa de particiones NOR Flash

 * +----------------------------------+
 * |       Mapa de particiones        |
 * |                                  |
 * +-0x00000000-----------------------+
 * |            bootloader   CFE      | 512 kb
 * +-0x00080000-----------------------+
 * |            CFE config            | 128 kb
 * +-0x000a0000-----------------------+
 * |            reserve               | 3.2 Mb
 * +-0x003c0000-----------------------+
 * |            secure storage        | 128 kb
 * +-0x003e0000-----------------------+
 * |            MAC address           | 126 kb
 * +-0x003ff800-----------------------+
 * |            hdcp                  | 2 kb
 * +-0x00400000-----------------------+

Las otras 12 particiones (mtd6 a mtd17) corresponden a la memoria NAND Flash Samsung K9K8G08U0A.

Creating 12 MTD partitions on "bcm7xxx-nand.0":
0x0000000006400000-0x0000000006c00000 : "Kernel"
0x0000000006c00000-0x0000000007800000 : "/usr"
0x0000000007800000-0x0000000008800000 : "/usr/local"
0x0000000008800000-0x000000000a800000 : "/usr/lib/MediaBrowser"
0x000000000a800000-0x000000000c800000 : "/usr/lib/MediaServer"
0x0000000000000000-0x0000000000800000 : "Kernel (alt)"
0x0000000000800000-0x0000000001400000 : "/usr (alt)"
0x0000000001400000-0x0000000002400000 : "/usr/local (alt)"
0x0000000002400000-0x0000000004400000 : "/usr/lib/MediaBrowser (alt)"
0x0000000004400000-0x0000000006400000 : "/usr/lib/MediaServer (alt)"
0x000000000c800000-0x000000000cc00000 : "Splash"
0x000000000cc00000-0x000000003fa00000 : "/rw/yaffs"

Mapa de particiones NAND Flash

 * +----------------------------------------+
 * |       Mapa de particiones              |
 * |                                        |
 * +-0x00000000-----------------------------+
 * |            Kernel (alt)                | 8 Mb
 * +-0x00800000-----------------------------+
 * |            /usr (alt)                  | 12 Mb
 * +-0x01400000-----------------------------+
 * |            /usr/local (alt)            | 16 Mb
 * +-0x02400000-----------------------------+
 * |            /usr/lib/MediaBrowser (alt) | 32 Mb
 * +-0x04400000-----------------------------+
 * |            /usr/lib/MediaServer (alt)  | 32 Mb
 * +-0x06400000-----------------------------+
 * |            Kernel                      | 8 Mb
 * +-0x06c00000-----------------------------+
 * |            /usr                        | 12 Mb
 * +-0x07800000-----------------------------+
 * |            /usr/local                  | 16 Mb
 * +-0x08800000-----------------------------+
 * |            /usr/lib/MediaBrowser       | 32 Mb
 * +-0x0a800000-----------------------------+
 * |            /usr/lib/MediaServer        | 32 Mb
 * +-0x0c800000-----------------------------+
 * |            Splash                      | 4 Mb
 * +-0x0cc00000-----------------------------+
 * |            /rw/yaffs                   | 833 Mb
 * +-0x3fa00000-----------------------------+

Una vez analizada la estructura de la memoria flash, procederemos a realizar el backup.
EL primer paso sera encender el equipo y dejar que finalice el proceso de arranque completo, después conectaremos el pendrive al usb.

Ahora desde la consola, se crea la carpeta donde se montará el usb y se comprueba que este montado correctamente. En mi caso la carpeta la he creado en /tmp/usb.

[root@stb:/] # mkdir /tmp/usb
[root@stb:/] # mount /dev/sda1 /tmp/usb
[root@stb:/] # df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/romblock7            3.3M      3.3M         0 100% /usr
/dev/romblock8           12.3M     12.3M         0 100% /usr/local
/dev/romblock9           11.3M     11.3M         0 100% /usr/lib/MediaBrowser
/dev/romblock10           1.0M      1.0M         0 100% /usr/lib/MediaServer
/dev/mtdblock17         814.0M      2.3M    811.7M   0% /rw
tmpfs                    32.0M     20.0k     32.0M   0% /tmp
/dev/sda1                 7.4G      3.6G      3.9G  48% /tmp/usb
[root@stb:/] # 

Copia de seguridad de la memoria NOR Flash.

[root@stb:/] # dd if=/dev/mtd0 of=/tmp/usb/cfe.bin
1024+0 records in
1024+0 records out
[root@stb:/] # dd if=/dev/mtd1 of=/tmp/usb/cfe_config.bin
256+0 records in
256+0 records out
[root@stb:/] # dd if=/dev/mtd2 of=/tmp/usb/reserve       
6400+0 records in
6400+0 records out
[root@stb:/] # dd if=/dev/mtd3 of=/tmp/usb/secure_storage
256+0 records in
256+0 records out
[root@stb:/] # dd if=/dev/mtd4 of=/tmp/usb/MAC_address   
252+0 records in
252+0 records out
[root@stb:/] # dd if=/dev/mtd5 of=/tmp/usb/hdcp       
4+0 records in
4+0 records out
[root@stb:/] #

Copia de seguridad de la memoria NAND Flash.

[root@stb:/] # dd if=/dev/mtd6 of=/tmp/usb/kernel
16384+0 records in
16384+0 records out
[root@stb:/] # dd if=/dev/mtd7 of=/tmp/usb/usr
24576+0 records in
24576+0 records out
[root@stb:/] # dd if=/dev/mtd8 of=/tmp/usb/usr_local
32768+0 records in
32768+0 records out
[root@stb:/] # dd if=/dev/mtd9 of=/tmp/usb/u_l_mb
65536+0 records in
65536+0 records out
[root@stb:/] # dd if=/dev/mtd10 of=/tmp/usb/u_l_ms
65536+0 records in
65536+0 records out
[root@stb:/] # dd if=/dev/mtd11 of=/tmp/usb/kernelalt
16384+0 records in
16384+0 records out
[root@stb:/] # dd if=/dev/mtd12 of=/tmp/usb/usr_alt
24576+0 records in
24576+0 records out
[root@stb:/] # dd if=/dev/mtd13 of=/tmp/usb/usr_lo_al
32768+0 records in
32768+0 records out
[root@stb:/] # dd if=/dev/mtd14 of=/tmp/usb/u_l_mb_alt
65536+0 records in
65536+0 records out
[root@stb:/] # dd if=/dev/mtd15 of=/tmp/usb/u_l_ms_alt
65536+0 records in
65536+0 records out
[root@stb:/] # dd if=/dev/mtd16 of=/tmp/usb/splash
8192+0 records in
8192+0 records out
[root@stb:/] # dd if=/dev/mtd17 of=/tmp/usb/yaffs
1667072+0 records in
1667072+0 records out

Ahora ya tenemos nuestra copia completada, recomiendo tener dos copias del backup, una sin tocar "original" y la otra para análisis, modificaciones, etc. Un buen lugar puede ser el disco duro o la nube personal.

Estos son los enlaces a mi copia.

mtd0: ["CFE"] 512KB
mtd1: ["CFE config"] 128KB
mtd2: ["reserved"] 3.1MB
mtd3: ["secure storage"] 128KB
mtd4: ["MAC address"] 126KB
mtd5: ["hdcp"] 2KB
mtd6: ["Kernel"] 8MB
mtd7: ["/usr"] 12MB
mtd8: ["/usr/local"] 16MB
mtd9: ["/usr/lib/MediaBrowser"] 32MB
mtd10 ["/usr/lib/MediaServer"] 32MB
mtd11 ["Kernel (alt)"] 8MB
mtd12 ["/usr (alt)"] 12MB
mtd13 ["/usr/local (alt)"] 16MB
mtd14 ["/usr/lib/MediaBrowser (alt)"] 32MB
mtd15 ["/usr/lib/MediaServer (alt)"] 32MB
mtd16 ["Splash"] 4MB
mtd17 ["/rw/yaffs"] 833MB