Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 28th, 2012  |  syntax: Bash  |  size: 10.17 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. #
  3. # This is a main init script for Z
  4. #
  5. # (C) 2005 Samsung Electronics
  6. #
  7. # $Log: rc,v $
  8. # Revision 1.12  2006/05/30 07:59:41  hcyun
  9. # add dosfsck to correct filesystem corruption due to power off during metadata update
  10. #
  11. # Revision 1.11  2006/04/19 07:26:43  hcyun
  12. # - set hidden on System/System.ver
  13. #
  14. # Revision 1.10  2006/03/23 14:05:54  hcyun
  15. # - support seperate MLC/SLC kernel image.
  16. # - support upgrade from phase1 + SLC
  17. # - add fixup script execution for future upgrade handling
  18. # - handle 7.5MB /ufdrawc limit due to 4GB with pre 2.0 partition table bug
  19. #   now Oasis image must be named as "Oasis-big.cramfs"
  20. # - firmware version update without modifying country code of /mnt/app/System.ver
  21. #
  22. # Revision 1.9  2006/03/06 10:43:44  biglow
  23. # - add detecting s/w version
  24. #
  25. # Revision 1.8  2006/02/22 12:43:45  hcyun
  26. # reset db after the reformatting due to FAT corruption.
  27. #
  28. # Revision 1.7  2006/02/13 10:02:54  hcyun
  29. # handle mount error
  30. #
  31. # - hcyun
  32. #
  33. # Revision 1.6  2006/01/16 13:22:48  hcyun
  34. # retry to write cramfs
  35. #
  36. # Revision 1.5  2006/01/15 08:20:54  hcyun
  37. # handle install fail case
  38. #
  39. # Revision 1.4  2005/12/29 11:43:28  hcyun
  40. # leave System.ver untouched in /mnt/usb
  41. #
  42. # Revision 1.3  2005/12/26 06:41:34  hcyun
  43. # safe System.ver update.
  44. #
  45. # Revision 1.2  2005/12/22 12:37:09  hcyun
  46. # add hostname
  47. #
  48. # Revision 1.1  2005/12/22 05:50:18  hcyun
  49. # Moved from images directory.
  50. #
  51.  
  52. err_msg()
  53. {
  54.     echo "ERROR $*"
  55.     exit 1
  56. }
  57.  
  58. err_install()
  59. {
  60.     echo "ERROR $*"
  61.  
  62.     killall -9 install-scr.sh
  63.  
  64.     rm -f z5-fw.dat fw.tar.gz
  65.     rm -f Oasis.cramfs Oasis.tar.gz Media.tar.gz System.ver
  66.     rm -f zImage Image rootfs.cramfs nandboot.sb
  67.     sync
  68.  
  69.     # TODO. display firmware upgrade failure.
  70.  
  71.     /z-proj/bin/recovery  /share/install-fail.fb
  72.  
  73.     echo ">> Reset the system"
  74.     reboot
  75.     echo "main 0" > /proc/powerctl
  76. }
  77.  
  78. handle_noformat_ufda()
  79. {
  80.     echo "mount failed"
  81.     echo "Unmounting previous mounts"
  82.     umount /mnt/app
  83.  
  84.     echo "Now re-format the /dev/ufda"
  85.     ffdisk /dev/ufda -a
  86.  
  87.     fformat -f12 -c 16 /dev/ufda1 || \
  88.         fformat -f12 -c 32 /dev/ufda1 || \
  89.             fformat -f16 -c 8 /dev/ufda1 || err_msg "Can't format /dev/ufda1"
  90.  
  91.     mount /mnt/app
  92.  
  93.     if mount -t cramfs /dev/ufdrawc /Oasis; then
  94.         if [ -f "/Oasis/OasisData.tar.gz" ]; then
  95.             echo "copy OasisData"
  96.             cat /Oasis/OasisData.tar.gz | ( cd /mnt/app ; tar zxvf - )
  97.         fi
  98.         umount /Oasis
  99.     fi
  100. }
  101.  
  102. handle_noformat_ufdb()
  103. {
  104.     echo "mount failed"
  105.     echo "Unmounting previous mounts"
  106.     umount /mnt/usb
  107.  
  108.     echo "Now re-format the /dev/ufdb"
  109.     ffdisk /dev/ufdb -a
  110.  
  111.     fformat -f32 -c 32 /dev/ufdb1 || \
  112.         fformat -f16 -c 32 /dev/ufdb1 || err_msg "Can't format /dev/ufdb1"
  113.  
  114.     mount /mnt/usb
  115.  
  116.     if mount -t cramfs /dev/ufdrawc /Oasis; then
  117.         echo "Copy wallpapers"
  118.         (cd /Oasis/usr/Oasis/DataTemplate; tar cf - . ) | ( cd /mnt/usb; tar xvf - )
  119.         (cd /Oasis/usr/Oasis; bin/resetdb.sh )
  120.         umount /Oasis
  121.     fi
  122. }
  123.  
  124. # procedure start downloading
  125. handle_nofw()
  126. {
  127.     echo "[handle_nofw]: Unable to find a firmware"
  128.  
  129.     umount /mnt/app
  130.     umount /mnt/usb
  131.  
  132.     # /dev/ufda2 must be formatted.
  133.     # TODO : error handling if /dev/ufda1 is not formatted"
  134.  
  135.     echo ">> Now ready to connect UMS"
  136.     echo "usbcontrol 1" > /proc/gadget_udc
  137.     insmod g_file_storage file=/dev/ufdb
  138.  
  139.     echo ">> download firmware to the UMS"
  140.     echo "after downlod is finished.. !!reboot the target!!"
  141.     echo "it will install new firmware automatically"
  142.  
  143.     echo
  144.     echo ">> Start recovery"
  145.     /z-proj/bin/recovery  /share/recovery.fb
  146.  
  147.     echo ">> Unloading UMS driver"
  148.     rmmod g_file_storage
  149.     sync
  150.  
  151.     echo ">> Reset the system"
  152.     echo "main 0" > /proc/powerctl
  153. }
  154.  
  155. handle_cramfs()
  156. {
  157.     image=$1
  158.     dev=$2
  159.  
  160.     echo "Error on installing cramfs $image on $dev. Try again"
  161.     dd if=$image of=$dev bs=2048  || err_msg "Fail again -_-"
  162.     sync
  163. }
  164.  
  165.  
  166. # this is fix for 4GB SLC, phase 1.
  167. fixup_oasis()
  168. {
  169.     echo "[fixup_oasis]: Found an uninstalled Oasis cramfs image"
  170.  
  171.     cd /mnt/usb
  172.  
  173.     echo "Install UI application (bigger than 7.5MB)"
  174.     dd if=Oasis-big.cramfs of=/dev/ufdrawc bs=2048 || handle_cramfs Oasis-big.cramfs /dev/ufdrawc
  175.     rm -f Oasis-big.cramfs
  176.     sync
  177. }
  178.  
  179. # temporary procedure to install correct kernel in case of installed
  180. # rc script do not distinguish MLC/SLC installation.
  181. # when this is kicked in, we can assume new rc script is running.
  182. # !! IMPORTANT !! require reboot
  183. fixup_kernel()
  184. {
  185.     echo "[fixup_kernel]: Found an uninstalled kernel image"
  186.  
  187.     cd /mnt/usb
  188.  
  189.     # TODO : display temporary kernel update notice
  190.     echo "refresh 0" > /proc/lfbctrl
  191.     cat /share/install.fb > /dev/fb0
  192.  
  193.     if [ ! -f "/proc/z5-hw" ]; then
  194.         # this must be a phase1 firmware with SLC attached.
  195.         echo "phase1 firmware with SLC"
  196.         dd if=Image-SLC of=/dev/ufdrawa bs=2048 || handle_cramfs Image-SLC /dev/ufdrawa
  197.     else
  198.         echo "[ERROR] Not a phase1 with SLC?"
  199.         cat /share/install-fail.fb > /dev/fb0
  200.     fi
  201.  
  202.     echo "Removing fixup kernel images"
  203.     rm -f Image-SLC Image-MLC
  204.  
  205.     sync
  206.  
  207.     echo "Reboot the system"
  208.     reboot
  209. }
  210.  
  211. # temporary procedure for initial product without fw version update capability
  212. update_fwver()
  213. {
  214.     echo "[update_fwver]: Found firmware update"
  215.  
  216.     # TODO :
  217.     update_version `cat /mnt/usb/z5-fw.ver` /mnt/app/System.ver
  218.     [ ! -d "/mnt/usb/System" ] && mkdir -p /mnt/usb/System
  219.     cp /mnt/app/System.ver /mnt/usb/System/System.ver
  220.     chmod 1555 /mnt/usb/System
  221.     chmod 1555 /mnt/usb/System/System.ver
  222.     rm -f /mnt/usb/z5-fw.ver
  223.     rm -f /mnt/usb/System.ver
  224.     sync
  225. }
  226.  
  227.  
  228. # procedure to install new firmware image..
  229. install_newfw()
  230. {
  231.     echo "[install_newfw]: Found a new firmware "
  232.  
  233.     cd /mnt/usb
  234.  
  235.     echo "refresh 0" > /proc/lfbctrl
  236.     /z-proj/bin/install-scr.sh &  # spinning update screen.
  237.  
  238.     echo ">> Start firmware installation"
  239.  
  240.     echo "Decrypting firmware"
  241.     if ! z5decrypt z5-fw.dat fw.tar.gz z5-fw.ver; then
  242.         err_install "Decryption failed"
  243.     fi
  244.  
  245.     echo "Decompressing firmware"
  246.     if ! tar zxvf fw.tar.gz ; then
  247.         err_install "Corrupted firmware"
  248.     fi
  249.  
  250.     echo "Removing decrypted firmware Image"
  251.     rm -f fw.tar.gz
  252.  
  253.  
  254.     if [ -f "z5_fixup.sh" ]; then
  255.         echo "Found a fixup script... run it first"
  256.         sh z5-fixup.sh
  257.         rm -f z5-fixup.sh
  258.         sync
  259.     fi
  260.  
  261.     if [ ! -f "/mnt/app/System.ver" ]; then
  262.         echo "Initial System.ver installation to /mnt/app"
  263.         mv System.ver /mnt/app
  264.         sync
  265.     fi
  266.  
  267.     if [ -f "Media.tar.gz" ]; then
  268.         echo "Installing Media Files"
  269.         cat Media.tar.gz | (cd /mnt/usb; tar zxvf - )
  270.         rm -f Media.tar.gz
  271.         sync
  272.     fi
  273.  
  274.     if [ -f "Oasis.cramfs" ]; then
  275.         echo "Install UI application"
  276.         dd if=Oasis.cramfs of=/dev/ufdrawc bs=2048 || handle_cramfs Oasis.cramfs /dev/ufdrawc
  277.         rm -f Oasis.cramfs
  278.         sync
  279.     fi
  280.  
  281.     if [ -f "Oasis-big.cramfs" ]; then
  282.         echo "Install UI application (bigger than 7.5MB)"
  283.         dd if=Oasis-big.cramfs of=/dev/ufdrawc bs=2048 || handle_cramfs Oasis-big.cramfs /dev/ufdrawc
  284.         rm -f Oasis-big.cramfs
  285.         sync
  286.     fi
  287.  
  288.     if [ -f "Oasis.tar.gz" ]; then
  289.         echo "Installing OasisData (or Devel version of Oasis)"
  290.         if [ -d "/mnt/app/usr/Oasis" ]; then
  291.             echo "Removing previously installed Oasis"
  292.             rm -rf /mnt/app/usr/Oasis
  293.             rm -f /mnt/app/start.sh
  294.         fi
  295.         cat Oasis.tar.gz | (cd /mnt/app; tar zxvf - )
  296.         rm -f Oasis.tar.gz
  297.         sync
  298.     fi
  299.  
  300.     if [ -f "zImage" ]; then
  301.         echo "Installing zImage"
  302.         dd if=zImage of=/dev/ufdrawa bs=2048 || handle_cramfs zImage /dev/ufdrawa
  303.         rm -f zImage
  304.         sync
  305.     fi
  306.  
  307.     if [ -f "Image" ]; then
  308.         echo "Installing Image"
  309.         dd if=Image of=/dev/ufdrawa bs=2048 || handle_cramfs Image /dev/ufdrawa
  310.         rm -f Image
  311.         sync
  312.     fi
  313.  
  314.     if [ -f "Image-SLC" -o -f "Image-MLC" ]; then
  315.         if grep "SLC" /proc/z5-hw ; then
  316.             echo "SLC flash is connected"
  317.             dd if=Image-SLC of=/dev/ufdrawa bs=2048 || handle_cramfs Image-SLC /dev/ufdrawa
  318.         elif grep "MLC" /proc/z5-hw ; then
  319.             echo "MLC flash is connected"
  320.             dd if=Image-MLC of=/dev/ufdrawa bs=2048 || handle_cramfs Image-MLC /dev/ufdrawa
  321.         else
  322.             echo "[ERROR] Incorrect z5-hw info.."
  323.         fi
  324.         echo "Removing fixup kernel images"
  325.         rm -f Image-SLC Image-MLC
  326.         sync
  327.     fi
  328.  
  329.     if [ -f "nandboot.sb" ]; then
  330.         echo "Installing bootloader"
  331.         nsect=`ls -l nandboot.sb | awk '{ print $5 }'`
  332.         echo "bootloader num sectors : $nsect"
  333.         dd if=nandboot.sb of=/dev/misc/sram
  334.         echo "$nsect" > /proc/lld/nandsb
  335.         rm -f nandboot.sb
  336.         sync
  337.     fi
  338.  
  339.     if [ -f "rootfs.cramfs" ]; then
  340.         echo "Install cramfs"
  341.         dd if=rootfs.cramfs of=/dev/ufdrawb bs=2048 || handle_cramfs rootfs.cramfs /dev/ufdrawb
  342.         rm -f rootfs.cramfs
  343.     fi
  344.  
  345.     echo "Removing encrypted firmware Image"
  346.     rm -f z5-fw.dat
  347.     sync
  348.  
  349.     echo ">>> Firmware Installation was successful"
  350.    
  351.     echo ">>> Reset the system"
  352.     /sbin/reboot
  353.     echo "reboot is not working.. force power off"
  354.     echo "main 0" > /proc/powerctl # should not reach here
  355. }
  356.  
  357. export PATH=$PATH:/z-proj/bin
  358.  
  359. mount -t proc none /proc
  360. mount -t tmpfs none /mnt/tmp
  361.  
  362. /z-proj/bin/dosfsck -a /dev/ufda1
  363.  
  364. mount /mnt/app \
  365.     || handle_noformat_ufda \
  366.     && echo "mount /dev/ufda1 is successful"
  367. mount /mnt/usb \
  368.     || handle_noformat_ufdb \
  369.     && echo "mount /dev/ufdb1 is successful"
  370.  
  371. [ -f "/mnt/usb/z5-fw.dat" ] && install_newfw
  372.  
  373. # Ugly fix for initial product (SLC with pre 2.0 firmware ) - require reboot
  374. [ -f "/mnt/usb/Image-SLC" ] && fixup_kernel
  375.  
  376. # Ugly for for initial product (4GB SLC with pre 2.0 firmware)
  377. [ -f "/mnt/usb/Oasis-big.cramfs" ] && fixup_oasis
  378.  
  379. [ -f "/mnt/usb/z5-fw.ver" ] && update_fwver
  380.  
  381. # read S/W version information
  382. cat /mnt/app/System.ver > /proc/z5-ver
  383.  
  384. # RFS Oasis (only for development)
  385. if [ -f "/mnt/app/start.sh" ]; then
  386.     echo "[DEVEL] RFS /dev/ufda1 contain oasis distribution"
  387.     echo "[DEVEL] Starting main UI"
  388.     /mnt/app/start.sh
  389.     exit
  390. fi
  391.  
  392. # CRAMFS Oasis (for production)
  393. mount -t cramfs /dev/ufdrawc /Oasis \
  394.     || handle_nofw
  395. [ -f "/Oasis/start.sh" ] \
  396.     || handle_nofw
  397.  
  398. echo "Start main UI"
  399. /Oasis/start.sh
  400.  
  401. hostname "Z5"
clone this paste RAW Paste Data