#!/bin/sh # Copyright (c) 2014, The Linux Foundation. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of The Linux Foundation nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # find_partitions init.d script to dynamically find partitions # #==================================================================================== # EDIT HISTORY FOR MODULE #This section contains comments describing changes made to the module. #Notice that changes are listed in reverse chronological order. #when who what, where, why #-------- --- --------------------------------------------------------- # #==================================================================================== FindAndMount () { partition=$1 dir=$2 ubinub=$3 QuecUsrdataFormatTimes=0 Var1=0 Var2=1 ubiattach_time=0 device=/dev/ubi${ubinub}_0 mtd_block_number=`cat $mtd_file | grep -wi $partition | sed 's/^mtd//' | awk -F ':' '{print $1}'` echo "MTD : Detected block device : $dir for $partition" mkdir -p $dir ubiattach -m $mtd_block_number -d $ubinub -b 1 /dev/ubi_ctrl while [ 1 ] do if [ -e $device ]; then break else sleep 0.01 ubiattach_time=$((ubiattach_time+1)) #echo "ubiattach wait times= $ubiattach_time" if [ "$ubiattach_time" -gt "50" ]; then echo " wait times = $ubiattach_time, > 50 !!!" break fi fi done if [ -e $device ] ;then echo "$partition : ubi attach success" else echo "$partition : ubi attach failure, start to format.." sync sleep 1 ubidetach -p /dev/mtd$mtd_block_number sleep 1 ubiformat /dev/mtd$mtd_block_number -y sleep 1 ubiattach -m $mtd_block_number -d $ubinub -b 1 /dev/ubi_ctrl if [ -e $device ];then echo "$partition : ubi attach success" else echo "$partition : ubi attach failure" fi sleep 1 ubimkvol /dev/ubi${ubinub} -m -N ${dir#*/} sleep 1 if [ -e $device ];then echo "$partition : ubimkvol success" else echo "$partition : ubimkvol failure" fi sync fi mounttimes=0 waitdevicetimes=0 while [ 1 ] do if [ -e $device ]; then mounttimes=$((mounttimes+1)) echo " $device mount times =$mounttimes" if [ "$mounttimes" -gt "10" ]; then echo " mount times =$mounttimes, > 10. mount failed, need format $partition" echo "$partition : mount times =$mounttimes, > 10. mount failed, need format" sleep 0.1 ubidetach -p /dev/mtd$mtd_block_number sleep 1 ubiformat /dev/mtd$mtd_block_number -y sleep 1 echo "not reboot sys mount $partition fail" fi mount -t ubifs /dev/ubi${ubinub}_0 $dir sleep 0.1 mountResult1=`mount | grep $dir` if [ "" = "$mountResult1" ]; then echo "$partition : mount failure" else echo "$partition : mount success" break fi else sleep 0.01 waitdevicetimes=$((waitdevicetimes+1)) #echo " $device wait times =$waitdevicetimes" if [ "$waitdevicetimes" -gt "50" ]; then echo " wait times =$waitdevicetimes, > 50. wait device failed, need format $partition" sync sleep 1 fi if [ "$waitdevicetimes" -gt "55" ]; then echo "exit mount $partition" sync break fi fi done } MoveEtcToUsrData() { mkdir -p /usr_data/etc if [ ! -f /usr_data/etc/etc_conf_flag ];then cp -a /etc/* /usr_data/etc sync touch /usr_data/etc/etc_conf_flag sync fi if [ -e /etc/syslog.conf ] && [ ! -e /usr_data/etc/syslog.conf ];then cp /etc/syslog.conf /usr_data/etc sync fi mount --bind /usr_data/etc /etc echo "mount bind /etc ok" } MoveAppsetConfToUsrData() { mkdir -p /usr_data/appset/conf if [ ! -f /usr_data/appset/conf/bind_conf_flag ];then cp -a /appset/conf/* /usr_data/appset/conf sync touch /usr_data/appset/conf/bind_conf_flag sync fi mount --bind /usr_data/appset/conf /appset/conf echo "mount bind /appset/conf ok" } MoveAppsetMvconfigDataToBackup() { mkdir -p /backup/appset/mvconfig/data if [ ! -f /backup/appset/mvconfig/data/bind_data_flag ];then cp -a /appset/mvconfig/data/* /backup/appset/mvconfig/data sync touch /backup/appset/mvconfig/data/bind_data_flag sync fi mount --bind /backup/appset/mvconfig/data /appset/mvconfig/data echo "mount bind /appset/mvconfig/data ok" } MoveMntToUsrData() { # should clear /mnt rm /usr_data/mnt -rf mkdir -p /usr_data/mnt if [ ! -f /usr_data/mnt/bind_mnt_flag ];then cp -rf /mnt/* /usr_data/mnt sync touch /usr_data/mnt/bind_mnt_flag sync fi mount --bind /usr_data/mnt /mnt echo "mount bind /mnt ok" } mtd_file=/proc/mtd eval FindAndMount usr_data /usr_data 2 eval FindAndMount backup /backup 3 MoveEtcToUsrData MoveAppsetConfToUsrData MoveAppsetMvconfigDataToBackup MoveMntToUsrData wait exit 0