{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The nandg recovery image is much the same as the boot image but will boot into recovery which is a minimal boot envoirnoment.  You can connnect with adb but no shell access or shell commands."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32772\ttablet/nandg.recovery.img\r\n"
     ]
    }
   ],
   "source": [
    "# The partition size of the image in bytes\n",
    "\n",
    "!du tablet/nandg.recovery.img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tablet/nandg.recovery.img: Android bootimg, kernel (0x40008000), ramdisk (0x41000000), page size: 2048, cmdline (console=ttyS0,115200 rw init=/init loglevel=4)\r\n"
     ]
    }
   ],
   "source": [
    "# We can use file to find out what kind of image we have.\n",
    "\n",
    "!file tablet/nandg.recovery.img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BOARD_KERNEL_CMDLINE console=ttyS0,115200 rw init=/init loglevel=4\r\n",
      "BOARD_KERNEL_BASE 40000000\r\n",
      "BOARD_PAGE_SIZE 2048\r\n"
     ]
    }
   ],
   "source": [
    "# We can unpack this type of image file using one of the tools from the android sdk\n",
    "\n",
    "!tools/unpackbootimg -i tablet/nandg.recovery.img -o tablet/recovery"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 12958\r\n",
      "drwxrwxrwx 1    4096 Mar 17 09:36 img-ramdisk\r\n",
      "-rwxrwxrwx 1       9 Mar 17 09:37 nandg.recovery.img-base\r\n",
      "-rwxrwxrwx 1      46 Mar 17 09:37 nandg.recovery.img-cmdline\r\n",
      "-rwxrwxrwx 1       5 Mar 17 09:37 nandg.recovery.img-pagesize\r\n",
      "-rwxrwxrwx 1 5623172 Mar 17 09:37 nandg.recovery.img-ramdisk.gz\r\n",
      "-rwxrwxrwx 1 7637412 Mar 17 09:37 nandg.recovery.img-zImage\r\n",
      "-rwxrwxrwx 1      66 Mar 16 13:57 README.md\r\n"
     ]
    }
   ],
   "source": [
    "# And this is what we get from unpacking this image file\n",
    "\n",
    "!ls -lgG tablet/recovery/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "27247 blocks\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "# Lets unpack the ramdisk file\n",
    "\n",
    "cd tablet/recovery/img-ramdisk/\n",
    "gunzip -c ../nandg.recovery.img-ramdisk.gz | cpio -i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 12837\r\n",
      "-rwxrwxrwx 1  425152 Mar 17 09:37 aw5306_ts.ko\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 data\r\n",
      "-rwxrwxrwx 1    2779 Mar 17 09:37 default.prop\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 dev\r\n",
      "-rwxrwxrwx 1 5513161 Mar 17 09:37 disp.ko\r\n",
      "drwxrwxrwx 1       0 Mar 17 09:37 etc\r\n",
      "-rwxrwxrwx 1     851 Mar 17 09:37 fstab.sun8i\r\n",
      "-rwxrwxrwx 1  360865 Mar 17 09:37 ft5x_ts.ko\r\n",
      "-rwxrwxrwx 1  515908 Mar 17 09:37 gslX680.ko\r\n",
      "-rwxrwxrwx 1  258952 Mar 17 09:37 gslX680new.ko\r\n",
      "-rwxrwxrwx 1  338644 Mar 17 09:37 gt818_ts.ko\r\n",
      "-rwxrwxrwx 1  137966 Mar 17 09:37 gt82x.ko\r\n",
      "-rwxrwxrwx 1  439901 Mar 17 09:37 gt9xxf_ts.ko\r\n",
      "-rwxrwxrwx 1  400708 Mar 17 09:37 gt9xx_ts.ko\r\n",
      "-rwxrwxrwx 1  113536 Mar 17 09:37 init\r\n",
      "-rwxrwxrwx 1 2457600 Mar 17 09:37 initlogo.rle\r\n",
      "-rwxrwxrwx 1    1514 Mar 17 09:37 init.rc\r\n",
      "-rwxrwxrwx 1  451089 Mar 17 09:37 lcd.ko\r\n",
      "-rwxrwxrwx 1 1453290 Mar 17 09:37 nand.ko\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 proc\r\n",
      "-rwxrwxrwx 1      58 Mar 16 13:58 README.md\r\n",
      "drwxrwxrwx 1     240 Mar 17 09:37 res\r\n",
      "drwxrwxrwx 1     448 Mar 17 09:37 sbin\r\n",
      "-rwxrwxrwx 1   87947 Mar 17 09:37 sunxi-keyboard.ko\r\n",
      "-rwxrwxrwx 1  143408 Mar 17 09:37 sw-device.ko\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 sys\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 system\r\n",
      "drwxrwxrwx 1       0 Mar 16 12:46 tmp\r\n",
      "-rwxrwxrwx 1     272 Mar 17 09:37 ueventd.goldfish.rc\r\n",
      "-rwxrwxrwx 1    4024 Mar 17 09:37 ueventd.rc\r\n",
      "-rwxrwxrwx 1     995 Mar 17 09:37 ueventd.sun8i.rc\r\n"
     ]
    }
   ],
   "source": [
    "# And what we have here\n",
    "\n",
    "!ls -lgG tablet/recovery/img-ramdisk/"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}