Create a shell script for the android SD Boot Card

Source: Internet
Author: User

Create a shell script for the android SD Boot Card

#! /Bin/bashexport lc_all = CIF [$ #-ne 1]; then Echo "Usage: $0 <drive>" Exit 1; fidrive = $1 skipmedia = 0out_ready = 0 root_dir = $ (PWD) product = 's5pc110 '# offset offset_authkey = 1offset_bl1 = watermark = 57offset_kernel = kernel = 9273 # size size_authkey = 8size_uboot = kernel = 6142 backup_dir = "backup" If [-e "$ root_dir/out/target/product/$ product "]; thenout_dir = "$ root_dir/out/target/product /$ Product "Elif [-e" $ product "]; thenout_dir =" $ product "elseecho" at least one out dir needed. "out_dir =" "Exit 1fi # format the SD card to three partitions. # The first partition is in vfat format. # The second and third partitions are in ext4 format. Function format_drive () {echo "formatting boot drive" If [-B $ {drive} 2]; thenumount $ {drive} 2 umount $ {drive} 3 mkfs. ext4-L "sys" $ {drive} 2 mkfs. ext4-L "data" $ {drive} 3 else if [-B $ {drive} P2]; thenumount $ {drive} p2umount $ {drive} P3 mk FS. ext4-L "sys" $ {drive} P2 mkfs. ext4-L "data" $ {drive} P3 else echo "can't find boot partition in/dev" Fifi} function format_vfat () {echo "formatting vfat Data Partition" If [-B $ {drive} 1]; thenumount $ {drive} 1 mkfs. vfat-F 32-n "fat" $ {drive} 1 else if [-B $ {drive} P1]; thenumount $ {drive} P1 mkfs. vfat-F 32-n "fat" $ {drive} P1 else echo "can't find boot partition in/dev" Fifi} # Check whether the corresponding image file F is prepared Unction check_files () {echo "checking files in $ out_dir." If [! -E "$ out_dir"/u-boot.bin]; thenout_dir = "" Echo "No u-boot.bin, checking if file existed." Exit 1 Elif [! -E "$ out_dir"/zimage]; thenout_dir = "" Echo "No zimage, checking if file existed." Exit 1 Elif [! -E "$ out_dir"/ramdisk-uboot.img]; thenout_dir = "" Echo "No ramdisk-uboot.img, check if file existed." Exit 1 Elif [! -E "$ out_dir"/system/build. prop]; thenout_dir = "" Echo "No system files, check if file existed. "Exit 1fi} # back up the data function backup_disk () {echo" backup disck "If [-e $ {backup_dir}] in SD; thenmv $ {backup_dir} "$ {backup_dir}-'date'" mkdir $ {backup_dir} elsemkdir $ {backup_dir} fiif [-B $ {drive}]; thendd if =$ {drive} of =$ {backup_dir}/secure. bin skip = $ offset_authkey COUNT = $ size_authkey BS = 512dd if =$ {drive} of = $ {Backup_dir}/u-boot.bin skip = $ offset_bl1 COUNT = $ size_uboot BS = 512dd if =$ {drive} of =$ {backup_dir}/zimage skip = $ offset_kernel COUNT = $ size_kernel BS = 512dd if =$ {drive} of =$ {backup_dir}/ramdisk-uboot.img skip = $ offset_rootfs COUNT = $ size_rootfs BS = 512 elseecho "can't find boot partition in/dev" fimkdir $ {backup_dir}/tmpif [-B $ {drive} 2]; thenumount $ {drive} 2 Mount-T ext4 $ {drive} 2 $ {backup_dir}/tmpelse If [-B $ {drive} P2]; thenumount $ {drive} P2 Mount-T ext4 $ {drive} P2 $ {backup_dir}/tmp else echo "can't find system partition in/dev" policiif ["$? "! = 0]; thenecho "warning, no system partition found. "ficp-RP $ {backup_dir}/tmp $ {backup_dir}/systemumount $ {backup_dir}/tmprmdir $ {backup_dir}/tmpecho" backup finished. "Return 0} # Run sdfunction write_disk () {echo" Writing Android images into disck "check_filesif [-B $ {drive}]; thendd of =$ {drive} If =$ {out_dir}/secure. bin seek = $ offset_authkey COUNT = $ size_authkey BS = 512dd of =$ {drive} If =$ {out_dir}/U- Boot. bin seek = $ offset_bl1 COUNT = $ size_uboot BS = 512 # dd OF =$ {drive} If =$ {out_dir}/u-boot.bin seek = $ offset_bl2 BS = 512dd of =$ {drive} If =$ {out_dir}/zimage seek = $ offset_kernel COUNT = $ size_kernel BS = 512dd of =$ {drive} If =$ {out_dir}/ramdisk-uboot.img seek = $ offset_rootfs COUNT = $ size_rootfs BS = 512 elseecho "can't write boot sectors into $ {drive}" fimkdir $ {out_dir}/tmpif [-B $ {drive} 2]; thenumount $ {drive} 2 m Ount-T ext4 $ {drive} 2 $ {out_dir}/tmpelse if [-B $ {drive} P2]; thenumount $ {drive} P2 Mount-T ext4 $ {drive} P2 $ {out_dir}/tmp else echo "can't find system partition in $ {drive}" policiif ["$? "-EQ 0]; thenecho" No system partition found, quit. "ficp-RP $ {out_dir}/system/* $ {out_dir}/tmpumount $ {out_dir}/tmprmdir $ {out_dir}/tmpecho" writing system files finished. "return $ ?} # Create partition function create_drives () {if [-B $ {drive} 1]; then umount $ {drive} 1 umount $ {drive} 2 umount $ {drive} 3 else if [-B $ {drive} P1]; then umount $ {drive} p1umount $ {drive} p2umount $ {drive} P3 else echo "can't find boot partition in/dev" primary IDD if =/dev/Zero of = $ drive BS = 1024 COUNT = 1024 size = 'fdisk-L $ drive | grep disk | grep bytes | awk' {print $5} ''echo disk size-$ size bytescylinders =' echo $ size/255/63/512 | BC 'echo cylinders-$ cylinders {echo 212 ,, 0x0c,-echo 77,135, 0x83,-Echo, 0x83, -} | sfdisk-D-H 255-s 63-C $ cylinders $ drivesleep 1} # Main fucntionecho "to backup a functional disk, enter 'B '. "Echo" to create a new drive, and fill it with Android image enter 'C '. "Echo" to write boot Android image only, enter 'W '. "echo-n" Enter B, C or W: "read answercase" $ answer "INB) backup_disk; exit; c) check_files; create_drives; format_drive; format_vfat; write_disk; exit; W) check_files; format_drive; backup_disk; write_disk; exit; *) echo "not a valid option. exiting "; exit; esaceject $ {drive}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.