mercredi 7 novembre 2012

Handling nand flash to save/recover data using ArchLinuxArm

When booting from SDCard under linux, it is possible to access the NAND partitions.
I use ArchLinux ARM, following this tutorial: Mele A100, the only bootable image that gets correctly the NAND partitions (as under Android ICS). I changed the MAC entry in script.bin in order to have a well-known MAC address for ssh.

Under Android ICS, partitions are defined like this:

-dev-  -name-        -start-       -size-       -mountpoint-

nanda  bootloader  : 1000000       01000000      u-boot
nandb  env         : 2000000       01000000      N/A (u-boot environment)
nandc  boot        : 3000000       02000000      initrd in RAM as / + kernel
nandd  system      : 5000000       20000000      /system
nande  data        : 25000000      60000000      /data
nandf  misc        : 85000000      01000000      "boot-recovery" or 0xff*
nandg  recovery    : 86000000      02000000      N/A (recovery image)
nandh  cache       : 88000000      08000000      /cache
nandi  private     : 90000000      01000000      /mnt/private
nandj  sysrecovery : 91000000      20000000      /mnt/sysrecovery
nandk  UDISK       : b1000000      3b000000      /sdcard

Under Linux, partitions are detected correctly (the following line shows something comparable to the above output):

echo "-dev-  -size-";cat /proc/partitions|while read x y size dev; do echo "$dev  `printf %08x $(( $size * 1024 ))`";done
-dev-  -size-
nanda  01000000
nandb  01000000
nandc  02000000
nandd  20000000
nande  60000000
nandf  01000000
nandg  02000000
nandh  08000000
nandi  01000000
nandj  20000000
nandk  3c800000

As a consequence, you can read/edit/save data from NAND using a linux distribution.
Important note: don't write on Android ICS mounted partitions, you can corrupt data!
Use cases:
1/ list installed application in /data:
mount -o noatime,nosuid,nodev,barrier=0,journal_checksum,noauto_da_alloc /dev/nande /mnt #this is how Android mounts ext4 partitions, look at init.sun4i.rc for special nand mount options.
ls -l /mnt/app/
-rw-r--r-- 1 1000 1000  4707663 Nov  5  2012 com.adobe.flashplayer-1.apk       

2/ backup a NAND partition locally:
dd if=/dev/nande bs=4096 |bzip2 -c >/root/nande.bz2

3/ backup a NAND partition via ssh (assuming my ssh server is at @
dd if=/dev/nande bs=4096 |bzip2 -c | ssh user@ dd of=/home/user/nande.bz2

4/ restore a NAND partition locally:
bzip2 -cd /root/nande.bz2 | dd of=/dev/nande bs=4096

5/ restore a NAN partition via ssh:
ssh user@ bzip2 -cd /home/user/nande.bz2 | dd of=/dev/nande bs=4096

6/ make a tar.bz2 archive of a partition contents (for huge partitions, instead of saving raw data):

mount -o noatime,nosuid,nodev,barrier=0,journal_checksum,noauto_da_alloc /dev/nande /mnt
cd /mnt
tar jcf - .|ssh user@ dd of=/home/user/nande.tar.bz2
umount /mnt

Using these commands, you can save/restore completely some essential partitions before a crash or a new firmware flashing procedure (/data essentially, /sdcard contains user data - movies, ... - that you should save in another place by other means).

3 commentaires:

  1. I know this is off-topic. I have opened my Mele A2000 and taken note of the memory chips. According to the specs for those chips the board have 4 Gb of flash memory and 2 DDR3 memory chips of 2 Gb each. The description for the Mele clearly says that it has 512 Mb of memory. As I'm new to Android, I would like to know:
    How are the DDR3 modules been used?
    Why I can only see ~310 Mb of memory in Android setting from the 512 it has?
    Where are physically the 512 Mb of memory?
    Could if be possible to create a memory paging partition with a hard drive so that Android does not struggle so much with some of the applications that use a lot of memory like Xbmc?
    I would appreciate any explanation or link to a resource explaining this issues.

      could be a good start.
      I think the 2 DDR3 memory chips are 2Gbits, means 256 MBytes.
      So this means 512MBytes total.
      310MB is the allocation left for userspace by the kernel.
      Adding swap should be possible, the Mele kernel has swap capability (cat /proc/swaps is possible).