blob: fa3993ead521cf538e354b780dc770d2afbd9fb8 [file] [log] [blame]
cz.liadb48d12025-06-07 17:20:20 +08001#!/bin/sh
2file_emmc_device="/dev/mmcblk0"
3file_emmc_partition="/dev/mmcblk0p1"
4# file_check_result="/var/log/emmc_check.txt"
5# file_log="/var/log/emmc_init.log"
6# file_mount_point="/media/mmc1"
7file_check_result="/tmp/emmc_check.txt"
8critical_msg="/oemdata/emmc_critical_msg.log"
9file_log="/tmp/emmc_init.log"
10file_mount_point="/media"
11t108_check_mount_point="/rom/media"
12emmc_result_no_emmc="emmc_no_device"
13emmc_result_success="emmc_success"
14emmc_result_no_partition="emmc_no_partition"
15emmc_result_mount_fail="emmc_mount_fail"
16find_format=0
17find_mount_point=0
18cplog_to_oemdata(){
19 cp $file_log /oemdata/
20 cp $file_check_result /oemdata/
21}
22mountCheck() {
23 i=1
24 find_format=0
25 find_mount_point=0
26 echo "$1 read $file_emmc_partition property start" >> $file_log
27 ext4=`df -T $file_emmc_partition`
28 for element in $ext4
29 do
30 echo "line$i:$element" >> $file_log
31 if [ $element == "ext4" ] ; then
32 echo "find format: ext4" >> $file_log
33 find_format=1
34 elif [ $element == "${check_mount_point}" ] ; then
35 echo "find mount point: ${check_mount_point}" >> $file_log
36 find_mount_point=1
37 fi
38 i=`expr $i + 1`
39 done
40 echo "$1 read $file_emmc_partition property end" >> $file_log
41}
42time=$(date "+%Y-%m-%d %H:%M:%S")
43echo "emmc power on checkstart($time)" > $file_log
44#¼ì²éÊÇ·ñÓÐemmcÉ豸£¬Èç¹ûûÓÐ
45if [ ! -e $file_emmc_device ] ; then
46 echo "no emmc device detected" >> $file_log
47 echo "$emmc_result_no_emmc" > $file_check_result
48else #Èç¹ûÓÐ
49 echo "found $file_emmc_device" >> $file_log
50#¼ì²éÓÐûÓзÖÇøÉ豸£¬Èç¹ûûÓÐÔò½øÐзÖÇø
51 if [ ! -e $file_emmc_partition ] ; then
52 echo "make emmc partition start" >> $file_log
53 echo -e "n\np\n1\n\n\nw\n" | fdisk /dev/mmcblk0
54 echo "make emmc partition end" >> $file_log
55 sleep 1s
56 fi
57#Ôٴγ¢ÊÔ£¬Èç¹û»¹ÊÇÕÒ²»µ½·ÖÇøÉ豸£¬ÔòÈÏΪemmcÓÐÎÊÌâ
58 if [ ! -e $file_emmc_partition ] ; then
59 echo "can not make partition:$file_emmc_device" >> $file_log
60 echo "$emmc_result_no_partition" > $file_check_result
61 else
62 echo "found $file_emmc_partition" >> $file_log
63 #¼ì²éÊÇ·ñÒѾ­mount£¬ÒòΪ¿ÉÄܱ»ÏµÍ³×Ô¶¯µ÷ÓÃfstab¶ømountÉÏ
64 mountCheck kkk
65 echo "kkk find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
66
67 #Èç¹ûÒѾ­mountÉÏ,²¢ÇÒ¸ñʽΪext4,Ôò³É¹¦£¬·ñÔòÈÏΪÓÐÎÊÌâ
68 if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
69 echo "$file_emmc_partition has alreay mount" >> $file_log
70 echo "$emmc_result_success" > $file_check_result
71 else
72 #ÏÈÐ¶ÔØ¹ÒÔØµã
73 echo "umount $file_mount_point" >> $file_log
74 umount $file_mount_point
75 #Ïȳ¢ÊÔÊÇ·ñ¿ÉÒÔmountÉÏ, Èç¹ûÒѾ­¸ñʽ»¯£¬Ö»ÒªÖ´ÐйÒÔØ¾Í¿ÉÒÔ£¬¾¡Á¿²»¸ñʽ»¯emmc
76 echo "find $file_emmc_partition, and mount to $file_mount_point" >> $file_log
77 mkdir $file_mount_point
78 mount -t ext4 $file_emmc_partition $file_mount_point
79 #¼ì²éÊÇ·ñ¿ÉÒÔ¹ÒÔØÉÏ
80 mountCheck bbb
81 echo "bbb find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
82 #Èç¹û¹ÒÔØÉÏ£¬²¢ÇÒÊÇext4¸ñʽ£¬Ôò³É¹¦
83 if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
84 echo "$file_emmc_partition mount success" >> $file_log
85 echo "$emmc_result_success" > $file_check_result
86 #Èç¹û¹ÒÔØÉÏ£¬È´²»ÊÇext4¸ñʽ£¬Ôò¸ñʽ»¯Îªext4
87 elif [ $find_mount_point -eq 1 -a $find_format -eq 0 ] ; then
88 #ÏÈÐ¶ÔØ
89 echo "$file_emmc_partition mounted, but it's not ext4 format" >> $file_log
90 echo "umount $file_mount_point" >> $file_log
91 umount $file_mount_point
92 #¸ñʽ»¯emmcΪext4¸ñʽ
93 echo "fomat $file_emmc_partition to ext4" >> $file_log
94 echo "mkfs.ext4 $file_mount_point" >> $file_log
95 cplog_to_oemdata
96 dmesg > $critical_msg
97 mkfs.ext4 $file_emmc_partition >> $file_log 2>&1
98 #Èç¹û¹ÒÔØ²»ÉÏ£¬Ò²¸ñʽ»¯Îªext4
99 else
100 #¸ñʽ»¯emmcΪext4¸ñʽ
101 echo "$file_emmc_partition can not mount" >> $file_log
102 echo "fomat $file_emmc_partition to ext4" >> $file_log
103 echo "mkfs.ext4 $file_mount_point" >> $file_log
104 cplog_to_oemdata
105 dmesg > $critical_msg
106 mkfs.ext4 $file_emmc_partition >> $file_log 2>&1
107 fi
108 #ÖØÐ¹ÒÔØ
109 if [ $find_mount_point -eq 0 -o $find_format -eq 0 ] ; then
110 echo "try mount $file_emmc_partition after proper process" >> $file_log
111 mkdir $file_mount_point
112 mount -t auto $file_emmc_partition $file_mount_point
113 sleep 1s
114 #¼ì²éÊÇ·ñ¿ÉÒÔ¹ÒÔØÉÏ
115 mountCheck zzz
116 echo "zzz find mount_point:$find_mount_point, find_format:$find_format" >> $file_log
117 if [ $find_mount_point -eq 1 -a $find_format -eq 1 ] ; then
118 echo "$file_emmc_partition mount success" >> $file_log
119 echo "$emmc_result_success" > $file_check_result
120 else
121 echo "$file_emmc_partition mount failed" >> $file_log
122 echo "$emmc_result_mount_fail" > $file_check_result
123 cplog_to_oemdata
124 fi
125 fi
126
127 fi
128 fi
129fi
130#exit 0