#!/bin/bash

# 参考文章:
# . Shell特殊变量:Shell $, $#, $*, $@, $?, $$和命令行参数
# http://c.biancheng.net/cpp/view/2739.html # <CMD state="Updater" type="push" body="send" file="mksdcard-android.sh.tar">Sending partition shell</CMD>
# <CMD state="Updater" type="push" body="$ tar xf $FILE "> Partitioning...</CMD>
# <CMD state="Updater" type="push" body="$ sh mksdcard-android.sh /dev/mmcblk0"> Partitioning...</CMD>
# <CMD state="Updater" type="push" body="$ ls -l /dev/mmc* ">Formatting sd partition</CMD> # partition size in MB
BOOTLOAD_RESERVE= # bootload 8MB
BOOT_ROM_SIZE= # 启动rom 8MB
SYSTEM_ROM_SIZE= # 系统rom 512MB
CACHE_SIZE= # 缓存 512MB
RECOVERY_ROM_SIZE= # 恢复rom 8MB
VENDER_SIZE= # 供货商 8MB
MISC_SIZE= # 杂项 8MB help() { # basename String [ Suffix ]
# basename 命令读取 String 参数,删除以 /(斜杠) 结尾的前缀以及任何指定的 Suffix 参数,
# 并将剩余的基本文件名称写至标准输出。
bn=`basename $`
cat << EOF
usage $bn <option> device_node options:
-h displays this help message
-s only get partition size
-np not partition.
-f flash android image.
EOF } # check the if root?
# 检查当前是否拥有root权限
userid=`id -u`
if [ $userid -ne "" ]; then
echo "you're not root?"
exit
fi # parse command line
# 解析命令行参数
moreoptions=
node="na"
cal_only=
flash_images=
not_partition=
not_format_fs=
# $#: 传递给脚本或函数的参数个数。
#
# $ sh mksdcard-android.sh /dev/mmcblk0
# $: /dev/mmcblk0
#
# moreoptions:
# node: /dev/mmcblk0
while [ "$moreoptions" = -a $# -gt ]; do
case $ in
-h) help; exit ;;
-s) cal_only= ;;
-f) flash_images= ;;
-np) not_partition= ;;
-nf) not_format_fs= ;;
*) moreoptions=; node=$ ;;
esac
[ "$moreoptions" = ] && [ $# -gt ] && help && exit
[ "$moreoptions" = ] && shift
done # 如果node设备节点不存在,那么就退出程序
if [ ! -e ${node} ]; then
help
exit
fi # call sfdisk to create partition table
# 调用sfdisk来创建分区表
# get total card size
# extend_size 增加了这个分量,同时data_size减小了这个分量,所以磁盘总量不变
seprate=
# -s [or --show-size]: 显示一个分区的大小,单位是KB。
total_size=`sfdisk -s ${node}`
total_size=`expr ${total_size} / ` # 重新计算,将单位换算成MB
boot_rom_sizeb=`expr ${BOOT_ROM_SIZE} + ${BOOTLOAD_RESERVE}`
extend_size=`expr ${SYSTEM_ROM_SIZE} + ${CACHE_SIZE} + ${VENDER_SIZE} + ${MISC_SIZE} + ${seprate}`
data_size=`expr ${total_size} - ${boot_rom_sizeb} - ${RECOVERY_ROM_SIZE} - ${extend_size} + ${seprate}` # create partitions
if [ "${cal_only}" -eq "" ]; then
cat << EOF
BOOT : ${boot_rom_sizeb}MB
RECOVERY: ${RECOVERY_ROM_SIZE}MB
SYSTEM : ${SYSTEM_ROM_SIZE}MB
CACHE : ${CACHE_SIZE}MB
DATA : ${data_size}MB
MISC : ${MISC_SIZE}MB
EOF
exit
fi # destroy the partition table
# 删除以前的分区表,从这里可以看出,分区表的大小貌似是1024字节
dd if=/dev/zero of=${node} bs= count= sfdisk --force -uM ${node} << EOF
,${boot_rom_sizeb},
,${RECOVERY_ROM_SIZE},
,${extend_size},
,${data_size},
,${SYSTEM_ROM_SIZE},
,${CACHE_SIZE},
,${VENDER_SIZE},
,${MISC_SIZE},
EOF # adjust the partition reserve for bootloader.
# if you don't put the uboot on same device, you can remove the BOOTLOADER_ERSERVE
# to have 8M space.
# the minimal sylinder for some card is 4M, maybe some was 8M
# just 8M for some big eMMC 's sylinder
# -N# : 只改变分区的编号 #
sfdisk --force -uM ${node} -N1 << EOF
${BOOTLOAD_RESERVE},${BOOT_ROM_SIZE},
EOF # For MFGTool Notes:
# MFGTool use mksdcard-android.tar store this script
# if you want change it.
# do following:
# tar xf mksdcard-android.sh.tar
# vi mksdcard-android.sh
# [ edit want you want to change ]
# rm mksdcard-android.sh.tar; tar cf mksdcard-android.sh.tar mksdcard-android.sh

最新文章

  1. JAVA 自定义状态码
  2. net 连mysql奇怪问题
  3. Android笔记——Android中数据的存储方式(一)
  4. jquery的end(),addBack()方法example
  5. mpich2 下运行时出现“由于目标计算机积极拒绝,无法连接”的错误
  6. Ubuntu下利用Apache转发模块实现反向代理
  7. openlayers4 入门开发系列之小区信号扇形图篇
  8. EF连接Sqlserver2014,使用DBGeography时提示无法加载sqlserverspatial.dll
  9. bootstrap改变上传文件按钮样式,并显示已上传文件名
  10. 协助CIO成功实施ITIL
  11. Svn在eclipse中使用
  12. Python练习-内置函数的应用
  13. c++ word类型
  14. C语言 字符串处理函数 转自 http://blog.chinaunix.net/uid-25885064-id-3175049.html
  15. bzoj 1115: [POI2009]石子游戏Kam -- 博弈论
  16. qemu网络虚拟化之数据流向分析二
  17. UEditor文本编辑器
  18. [GO]数组的比较和赋值
  19. 【SSO单点系列】(7):CAS4.0 SERVER通过数据库方式认证用户
  20. 363 Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

热门文章

  1. eclipse+maven+tomcat构建web工程
  2. hive表与外部表的区别
  3. Linux系统——Ansible批量管理工具
  4. linux系统下单网卡绑定多个IP地址方法
  5. Codeforces Round #524 (Div. 2) Solution
  6. Vue学习笔记之Vue的使用
  7. Sybase数据库常用sql语言
  8. .net Core 发布并布署到Iis
  9. linux及安全第五周总结——20135227黄晓妍
  10. Linux内核分析06