Advertisement
danielhilst

nand-recovery.sh

Apr 16th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. MEDIA=/opt/recovery
  4.  
  5. OS=Yocto
  6.  
  7. UBOOT_IMAGE=u-boot.bin
  8. KERNEL_IMAGE=uImage
  9. ROOTFS_IMAGE=rootfs.ubi.img
  10. ANDROID_BOOT=boot.img
  11. ANDROID_RECOVERY=recovery.img
  12. ANDROID_SYSTEM=android_root.img
  13. UBI_SUB_PAGE_SIZE=2048
  14. UBI_VID_HDR_OFFSET=2048
  15.  
  16. install_bootloader()
  17. {
  18.     if [ ! -f $MEDIA/$OS/$UBOOT_IMAGE ]
  19.     then
  20.         echo "\"$MEDIA/$OS/$UBOOT_IMAGE\"" does not exist! exit.
  21.         exit 1
  22.     fi 
  23.  
  24.     echo "Installing U-Boot ..."
  25.     flash_eraseall /dev/mtd0 2>/dev/null
  26.     kobs-ng init $MEDIA/$OS/$UBOOT_IMAGE --search_exponent=1 -v > /dev/null
  27. }
  28.  
  29. install_kernel()
  30. {
  31.     if [ ! -f $MEDIA/$OS/$KERNEL_IMAGE ]
  32.     then
  33.         echo "\"$MEDIA/$OS/$KERNEL_IMAGE\"" does not exist! exit.
  34.         exit 1
  35.     fi 
  36.     echo "Installing Kernel ..."
  37.     flash_eraseall /dev/mtd1 2>/dev/null
  38.     nandwrite -p /dev/mtd1 $MEDIA/$OS/$KERNEL_IMAGE > /dev/null
  39. }
  40.  
  41. install_rootfs()
  42. {
  43.     if [ ! -f $MEDIA/$OS/$ROOTFS_IMAGE ]
  44.     then
  45.         echo "\"$MEDIA/$OS/$ROOTFS_IMAGE\"" does not exist! exit.
  46.         exit 1
  47.     fi 
  48.     echo "Installing UBI rootfs ..."
  49.     flash_eraseall /dev/mtd2 2>/dev/null
  50.     ubiformat /dev/mtd2 -f $MEDIA/$OS/$ROOTFS_IMAGE -s $UBI_SUB_PAGE_SIZE -O $UBI_VID_HDR_OFFSET
  51. }
  52.  
  53. install_android_system()
  54. {
  55.         if [ ! -f $MEDIA/$OS/$ANDROID_SYSTEM ]
  56.     then
  57.         echo "\"$MEDIA/$OS/$ANDROID_SYSTEM\"" does not exist! exit.
  58.         exit 1
  59.     fi
  60.     echo "Installing system.img ..."
  61.     flash_eraseall /dev/mtd5 2>/dev/null
  62.     ubiformat /dev/mtd5 -f $MEDIA/$OS/$ANDROID_SYSTEM -s $UBI_SUB_PAGE_SIZE -O $UBI_VID_HDR_OFFSET
  63. }
  64.  
  65. install_android_boot()
  66. {
  67.     if [ ! -f $MEDIA/$OS/$ANDROID_BOOT ]
  68.     then
  69.         echo "\"$MEDIA/$OS/$ANDROID_BOOT\"" does not exist! exit.
  70.         exit 1
  71.     fi
  72.     echo "Installing boot.img ..."
  73.     flash_eraseall /dev/mtd3 2>/dev/null
  74.     nandwrite -p /dev/mtd3 $MEDIA/$OS/$ANDROID_BOOT > /dev/null
  75. }
  76.  
  77. install_android_recovery()
  78. {
  79.     if [ ! -f $MEDIA/$OS/$ANDROID_RECOVERY ]
  80.     then
  81.         echo "\"$MEDIA/$OS/$ANDROID_RECOVERY\"" does not exist! exit.
  82.         exit 1
  83.     fi
  84.     echo "Installing recovery.img ..."
  85.     flash_eraseall /dev/mtd4 2>/dev/null
  86.     nandwrite -p /dev/mtd4 $MEDIA/$OS/$ANDROID_RECOVERY > /dev/null
  87. }  
  88.                                                                                
  89. usage()
  90. {
  91.     cat << EOF
  92.         usage: $0 options
  93.  
  94.         This script install Linux/Android binaries in VAR-SOM-MX6 NAND.
  95.  
  96.         OPTIONS:
  97.         -h                          Show this message
  98.         -o <Linux|Android|Ubuntu|Yocto>   OS type (defualt: Linux).
  99. EOF
  100. }
  101.  
  102. while getopts .ho:c. OPTION
  103. do
  104.     case $OPTION in
  105.     h)
  106.         usage
  107.         exit 1
  108.         ;;
  109.     o)
  110.         OS=$OPTARG
  111.         ;;
  112.     ?)
  113.         usage
  114.         exit 1
  115.     ;;
  116.     esac
  117. done
  118.  
  119. if [[ "$OS" != "Linux" ]] && [[ "$OS" != "Android" ]] && [[ "$OS" != "Ubuntu" ]] && [[ "$OS" != "Yocto" ]]
  120. then
  121.     usage
  122.     exit 1
  123. fi
  124.  
  125. echo "*** VAR-SOM-MX6 NAND RECOVERY ***"
  126. echo "Installing $OS on NAND ..."
  127.  
  128. #if [ `cat /proc/cpuinfo |grep processor | wc -l` = 1 ] ; then
  129. #   UBOOT_IMAGE=u-boot.solo.bin
  130. #   ANDROID_BOOT=boot.solo.img
  131. #fi
  132.  
  133. if [ `dmesg |grep MT29F8G08ABABAWP | wc -l` = 1 ] ; then
  134.     # this is 1GB NAND (MT29F8G08ABABAWP)
  135.     ROOTFS_IMAGE=rootfs_1G_NAND.ubi.img
  136.     ANDROID_SYSTEM=android_root_1G_NAND.img
  137.     UBI_SUB_PAGE_SIZE=4096
  138.     UBI_VID_HDR_OFFSET=4096
  139. fi
  140.  
  141. install_bootloader
  142.  
  143. if [ "$OS" != "Android" ] ; then
  144.     install_kernel
  145.     install_rootfs
  146. else
  147.     install_android_boot
  148.     install_android_recovery
  149.     install_android_system
  150. fi
  151.  
  152. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement