blob: fa3993ead521cf538e354b780dc770d2afbd9fb8 [file] [log] [blame]
#!/bin/sh
file_emmc_device="/dev/mmcblk0"
file_emmc_partition="/dev/mmcblk0p1"
# file_check_result="/var/log/emmc_check.txt"
# file_log="/var/log/emmc_init.log"
# file_mount_point="/media/mmc1"
file_check_result="/tmp/emmc_check.txt"
critical_msg="/oemdata/emmc_critical_msg.log"
file_log="/tmp/emmc_init.log"
file_mount_point="/media"
t108_check_mount_point="/rom/media"
emmc_result_no_emmc="emmc_no_device"
emmc_result_success="emmc_success"
emmc_result_no_partition="emmc_no_partition"
emmc_result_mount_fail="emmc_mount_fail"
find_format=0
find_mount_point=0
cplog_to_oemdata(){
cp $file_log /oemdata/
cp $file_check_result /oemdata/
}
mountCheck() {
i=1
find_format=0
find_mount_point=0
echo "$1 read $file_emmc_partition property start" >> $file_log
ext4=`df -T $file_emmc_partition`
for element in $ext4
do
echo "line$i:$element" >> $file_log
if [ $element == "ext4" ] ; then
echo "find format: ext4" >> $file_log
find_format=1
elif [ $element == "${check_mount_point}" ] ; then
echo "find mount point: ${check_mount_point}" >> $file_log
find_mount_point=1
fi
i=`expr $i + 1`
done
echo "$1 read $file_emmc_partition property end" >> $file_log
}
time=$(date "+%Y-%m-%d %H:%M:%S")
echo "emmc power on checkstart($time)" > $file_log
#¼ì²éÊÇ·ñÓÐemmcÉ豸£¬Èç¹ûûÓÐ
if [ ! -e $file_emmc_device ] ; then
echo "no emmc device detected" >> $file_log
echo "$emmc_result_no_emmc" > $file_check_result
else #Èç¹ûÓÐ
echo "found $file_emmc_device" >> $file_log
#¼ì²éÓÐûÓзÖÇøÉ豸£¬Èç¹ûûÓÐÔò½øÐзÖÇø
if [ ! -e $file_emmc_partition ] ; then
echo "make emmc partition start" >> $file_log
echo -e "n\np\n1\n\n\nw\n" | fdisk /dev/mmcblk0
echo "make emmc partition end" >> $file_log
sleep 1s
fi
#Ôٴγ¢ÊÔ£¬Èç¹û»¹ÊÇÕÒ²»µ½·ÖÇøÉ豸£¬ÔòÈÏΪemmcÓÐÎÊÌâ
if [ ! -e $file_emmc_partition ] ; then
echo "can not make partition:$file_emmc_device" >> $file_log
echo "$emmc_result_no_partition" > $file_check_result
else
echo "found $file_emmc_partition" >> $file_log
#¼ì²éÊÇ·ñÒѾ­mount£¬ÒòΪ¿ÉÄܱ»ÏµÍ³×Ô¶¯µ÷ÓÃfstab¶ømountÉÏ
mountCheck kkk
echo "kkk find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
#Èç¹ûÒѾ­mountÉÏ,²¢ÇÒ¸ñʽΪext4,Ôò³É¹¦£¬·ñÔòÈÏΪÓÐÎÊÌâ
if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
echo "$file_emmc_partition has alreay mount" >> $file_log
echo "$emmc_result_success" > $file_check_result
else
#ÏÈÐ¶ÔØ¹ÒÔØµã
echo "umount $file_mount_point" >> $file_log
umount $file_mount_point
#Ïȳ¢ÊÔÊÇ·ñ¿ÉÒÔmountÉÏ, Èç¹ûÒѾ­¸ñʽ»¯£¬Ö»ÒªÖ´ÐйÒÔØ¾Í¿ÉÒÔ£¬¾¡Á¿²»¸ñʽ»¯emmc
echo "find $file_emmc_partition, and mount to $file_mount_point" >> $file_log
mkdir $file_mount_point
mount -t ext4 $file_emmc_partition $file_mount_point
#¼ì²éÊÇ·ñ¿ÉÒÔ¹ÒÔØÉÏ
mountCheck bbb
echo "bbb find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
#Èç¹û¹ÒÔØÉÏ£¬²¢ÇÒÊÇext4¸ñʽ£¬Ôò³É¹¦
if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
echo "$file_emmc_partition mount success" >> $file_log
echo "$emmc_result_success" > $file_check_result
#Èç¹û¹ÒÔØÉÏ£¬È´²»ÊÇext4¸ñʽ£¬Ôò¸ñʽ»¯Îªext4
elif [ $find_mount_point -eq 1 -a $find_format -eq 0 ] ; then
#ÏÈÐ¶ÔØ
echo "$file_emmc_partition mounted, but it's not ext4 format" >> $file_log
echo "umount $file_mount_point" >> $file_log
umount $file_mount_point
#¸ñʽ»¯emmcΪext4¸ñʽ
echo "fomat $file_emmc_partition to ext4" >> $file_log
echo "mkfs.ext4 $file_mount_point" >> $file_log
cplog_to_oemdata
dmesg > $critical_msg
mkfs.ext4 $file_emmc_partition >> $file_log 2>&1
#Èç¹û¹ÒÔØ²»ÉÏ£¬Ò²¸ñʽ»¯Îªext4
else
#¸ñʽ»¯emmcΪext4¸ñʽ
echo "$file_emmc_partition can not mount" >> $file_log
echo "fomat $file_emmc_partition to ext4" >> $file_log
echo "mkfs.ext4 $file_mount_point" >> $file_log
cplog_to_oemdata
dmesg > $critical_msg
mkfs.ext4 $file_emmc_partition >> $file_log 2>&1
fi
#ÖØÐ¹ÒÔØ
if [ $find_mount_point -eq 0 -o $find_format -eq 0 ] ; then
echo "try mount $file_emmc_partition after proper process" >> $file_log
mkdir $file_mount_point
mount -t auto $file_emmc_partition $file_mount_point
sleep 1s
#¼ì²éÊÇ·ñ¿ÉÒÔ¹ÒÔØÉÏ
mountCheck zzz
echo "zzz find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
echo "$file_emmc_partition mount success" >> $file_log
echo "$emmc_result_success" > $file_check_result
else
echo "$file_emmc_partition mount failed" >> $file_log
echo "$emmc_result_mount_fail" > $file_check_result
cplog_to_oemdata
fi
fi
fi
fi
fi
#exit 0