Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1) Keep all the below files in same location:

...

       i) Broadband image to be flashed

...

      ii) Video image to be flashed

...

    iii) extract.sh

Code Block
languagebash
titleextract.sh
collapsetrue
#--------------------------------------------------------------------------------------------------
# Extract meta information of Downloaded image
#--------------------------------------------------------------------------------------------------

mkdir -p extblock

fdisk -u -l $1 > extblock/sector.txt

linux_sector=`tail -2 extblock/sector.txt | tr -s ' ' | cut -d'*' -f2 | cut -d' ' -f2 | head -n1`
linux_offset=$((linux_sector*512))

rootfs_sector=`tail -2 extblock/sector.txt | tr -s ' ' | cut -d'*' -f2 | cut -d' ' -f2 | tail -1`
rootfs_offset=$((rootfs_sector*512))

mkdir -p extblock/linux_data
mkdir -p extblock/rootfs_data

mkdir -p extblock/vlinux_backup_data
mkdir -p extblock/vrootfs_backup_data

#sudo mount /dev/mmcblk0p1 extblock/bank0_linux

#--------------------------------------------------------------------------------------------------
# Loop mount + Extract kernel and bootload data of Downloaded image to storage area
#--------------------------------------------------------------------------------------------------

sudo mount -o loop,offset=$linux_offset $1 extblock/linux_data
cp -R extblock/linux_data/* extblock/vlinux_backup_data/
sudo umount extblock/linux_data
rm -rf extblock/linux_data


#--------------------------------------------------------------------------------------------------
# Loop mount + Extract rootfs data of Downloaded image to storage area
#--------------------------------------------------------------------------------------------------

sudo mount -o loop,offset=$rootfs_offset $1 extblock/rootfs_data

cp -R extblock/rootfs_data/* extblock/vrootfs_backup_data
sudo umount extblock/rootfs_data
rm -rf extblock/rootfs_data

...


 iv) multiSDcard_partition.sh

Code Block
languagebash
titlemultiSDcard_partition
collapsetrue
# This code is for partitioning and image flashing into multiple SD cards

echo Please enter the input arguments in this order : bash partition.sh bb_image video_image SDcardDetail_filename
echo Please keep the script extract.sh in the same folder

# Get user input for Broadband and Video image and SD card partition names and their respective sizes
echo Broadband image : $1
echo Video image : $2
echo SDcard details filename : $3

echo Deleting few folders if they are pre-existing...
sudo rm -rf videomnt/
sudo rm -rf extblock/

echo Video image is going to be extracted...
sudo sh extract.sh $2
sudo mkdir videomnt

loopcnt=1
while IFS=' ' read -r part_name sdcard_size
do
  sudo mkdir videomnt/videomnt'_'$loopcnt
  dir_name='videomnt/videomnt''_'$loopcnt
  echo $dir_name
  echo Calling the thread script which will paralleley execute for multiple SD cards...
  sudo bash threadSD.sh $1 $part_name $sdcard_size $dir_name &
  loopcnt=`expr $loopcnt + 1`
done < $3

# Check file inside videomnt is empty or not
cd videomnt

while true
do
  for file in *; do
     echo Check for file present in the directory...
  done

  if [ "$file" == "*" ]
  then
       echo All SD card partitioning and image flashing are completed !!
       # Deleting temporary folders.
       cd ..
       sudo rm -rf videomnt
       sudo rm -rf extblock/
       exit 1
   fi

  sleep 60
  sleep_cnt=`expr $sleep_cnt + 1`

  if [ "$sleep_cnt" == "10" ]
  then
     echo Multisd card flashing failed due to slow processing or error. Increase sleep count thresold sleep_cnt.
     exit 1
  fi

done


v) threadSD.sh

Code Block
titlethreadSD.sh
collapsetrue
# This program implements thread functionality for better performance for multiple SD card partitioning and image flashing
# Input arguments
bb_image=$1
part_name=$2
sdcard_size=$3
dir_name=$4
echo Going to flash the Broadband image in SD card which loaded in $part_name ...
`sudo dd if=$bb_image of=$part_name bs=4M`
echo Broadband Image flashed in SD card !!
echo SD card partitioning is going to start !!
sudo parted $part_name --script print
sudo parted $part_name --script resizepart 2 2048
sudo parted $part_name --script print free
sudo parted $part_name --script mkpart primary ext4 2049 4096
sudo parted $part_name --script print free
sd_size=$sdcard_size'GB'
sudo parted $part_name --script mkpart primary ext4 4097 $sd_size
sudo parted $part_name --script print
sudo parted $part_name --script quit
part3=$part_name'3'
part4=$part_name'4'
sudo mkfs.ext4 $part3
sudo mkfs.ext4 $part4
echo Video image is going to be copied in the extended partition ...
sudo mount $part4 $dir_name
sudo cp -r extblock/v* $dir_name/
sudo cp -r extblock/vrootfs_backup_data/* $dir_name/
echo Video image is stored in extended partition !!
sleep 10 
sudo umount $dir_name
sleep 10
echo SD card unmounted.
echo Partitioning and Image flashing in the SD card mounted in $part_name is Completed !!!
sudo rm -rf $dir_name

vi) Create a file (For ex. sudo vi sd_part_size) where all the SD card partition names and their respective sizes are mentioned

2) Connect all the SD cards with host PC and execute the command : sudo fdisk -l  . It will list all the SD card partitions with their respective sizes

...

           SD card size mentioned in input text file should always be in GB but with format as provided in the steps mentioned

           Minimum 8GB SD card is required to test this feature