#!/bin/sh
# add a new primary partition
# Param:PartNum(1~3) First cylinder Last cylinder
add_partition(){
echo "creat primary partition $1 $2 $3"
echo "n
p
$1
$2
$3
w" | fdisk /dev/mmcblk0
sync
sleep 1
}
# delete a partition
# Param:PartNum
del_partition(){
echo "delete partition $1"
echo "d
$1
w" | fdisk /dev/mmcblk0
sync
sleep 1
}
check_partition(){
local par_start=`fdisk /dev/mmcblk0 -l | grep "/dev/mmcblk0p$1" | awk '{printf $2}'`
local par_end=`fdisk /dev/mmcblk0 -l | grep "/dev/mmcblk0p$1" | awk '{printf $3}'`
echo "check partition,index=$1,start=$par_start,end=$par_end,param=$2 $3"
if [[ $par_start -ne $2 ]]||[[ $par_end -ne $3 ]]; then
echo "not match."
return 0
else
echo "match."
return 1
fi
}
# main
if [ -b "/dev/mmcblk0" ]; then #[-b file] 如果file存在且是一个块特殊文件则为真
if [ $1 == "check" ]; then #//判断传入的第一个参数是不是-add
echo "Check to see if the EMMC has been successfully identified"
ls /dev/mmc* -l
elif [ $1 == "cat" ]; then
echo "check the BlockSize of eMMC"
cat /proc/partitions
elif [ $1 == "add" ]; then
add_partition $2 $3 $4
elif [ $1 == "del" ]; then
del_partition $2
elif [ $1 == "size" ]; then
echo "p" | fdisk /dev/mmcblk0
else
echo "### invalid parameter"
fi
else
echo "### no exist emmc"
fi
emmc分区创建脚本
最新推荐文章于 2024-05-28 10:08:55 发布