#!/bin/bash#
#   ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking
# 说明:
#     本文主要对TI的sdk中的create-sdcard.sh脚本进行解读,该文件只解读
# 前面一部分,后面一部分未解读,主要是因为后面的代码并不能获取到正确
# 的设备节点,于是不打算深入解读。其中学会到了tar中显示解压进度的写法,
# 以及拷贝文件夹的显示当前拷贝数据的进度的方法。
#
#                                      2016-4-16 深圳 南山平山村 曾剑锋# Authors:
#    LT Thomas <ltjr@ti.com>
#    Chase Maupin
#    Franklin Cooper Jr.
#
# create-sdcard.sh v0.3# This distribution contains contributions or derivatives under copyright
# as follows:
#
# Copyright (c) 2010, Texas Instruments Incorporated
# 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 Texas Instruments 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.# Force locale language to be set to English. This avoids issues when doing
# text and string processing.
export LANG=C# Determine the absolute path to the executable
# EXE will have the PWD removed so we can concatenate with the PWD safely
PWD=`pwd`
EXE=`echo $0 | sed s=$PWD==`
EXEPATH="$PWD"/"$EXE"
clear
cat << EOM################################################################################This script will create a bootable SD card from custom or pre-built binaries.The script must be run with root permissions and from the bin directory of
the SDKExample:$ sudo ./create-sdcard.shFormatting can be skipped if the SD card is already formatted and
partitioned properly.################################################################################EOM# 检查脚本运行用户,也就是检查权限
AMIROOT=`whoami | awk {'print $1'}`
if [ "$AMIROOT" != "root" ] ; thenecho "    **** Error *** must run script with sudo"echo ""exit
fiTHEPWD=$EXEPATH
PARSEPATH=`echo $THEPWD | grep -o '.*ti-processor-sdk-linux-am335x-evm-01.00.00.00/'`if [ "$PARSEPATH" != "" ] ; then
PATHVALID=1
else
PATHVALID=0
fi#Precentage function
# 解压文件,以百分比来显示
untar_progress ()
{TARBALL=$1;DIRECTPATH=$2;# 1. 获取解压后总共是多大:gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p")# 2. 51200 = 512*100# 3. 一共有多少个512:$(gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 512# 4. 算百分比的时候,一个百分比站多少个块:$(gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200# 5. 有些数据不够512整除,所以多加1,保证最后是100%:$(gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1BLOCKING_FACTOR=$(($(gzip --list ${TARBALL} | sed -n -e "s/.*[[:space:]]\+[0-9]\+[[:space:]]\+\([0-9]\+\)[[:space:]].*$/\1/p") / 51200 + 1));# --block-number                每个信息都显示归档内的块数# --checkpoint                  每隔 NUMBER 个记录显示进度信息(默认为 10 个)# --checkpoint-action=ACTION    在每个检查点上执行 ACTION tar --blocking-factor=${BLOCKING_FACTOR} --checkpoint=1 --checkpoint-action='ttyout=Written %u%  \r' -zxf ${TARBALL} -C ${DIRECTPATH}
}#copy/paste programs
# 拷贝文件,以当前是多少字节,一共有多少字节来显示。
cp_progress ()
{CURRENTSIZE=0while [ $CURRENTSIZE -lt $TOTALSIZE ]doTOTALSIZE=$1;TOHERE=$2;CURRENTSIZE=`sudo du -c $TOHERE | grep total | awk {'print $1'}`echo -e -n "$CURRENTSIZE /  $TOTALSIZE copied \r"sleep 1done
}# 如下面所述,这一部分是不一定能够获取到SD卡的设备节点的。
check_for_sdcards()
{# find the avaible SD cards# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ mount# /dev/sda1 on / type ext4 (rw,errors=remount-ro)# proc on /proc type proc (rw,noexec,nosuid,nodev)# sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)# none on /sys/fs/fuse/connections type fusectl (rw)# none on /sys/kernel/debug type debugfs (rw)# none on /sys/kernel/security type securityfs (rw)# udev on /dev type devtmpfs (rw,mode=0755)# devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)# tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)# none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)# none on /run/shm type tmpfs (rw,nosuid,nodev)# rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)# nfsd on /proc/fs/nfsd type nfsd (rw)# vmware-vmblock on /run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)# gvfs-fuse-daemon on /home/Qt/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=Qt)# /dev/sdb1 on /media/boot type vfat (rw,nosuid,nodev,uid=1001,gid=1001,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8
sda# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ # 从上面的程序来看,其实下面这行代码是错的,获取到的是sda,硬盘的文件设备节点ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ cat /proc/partitions | grep -v sda | grep -e '\<sd.\>\|\<mmcblk.\>' | grep -e -n ''# grep: : No such file or directory# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`if [ "$PARTITION_TEST" = "" ]; thenecho -e "Please insert a SD card to continue\n"while [ "$PARTITION_TEST" = "" ]; doread -p "Type 'y' to re-detect the SD card or 'n' to exit the script: " REPLYif [ "$REPLY" = 'n' ]; thenexit 1fiROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-8`PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`donefi
}populate_3_partitions() {ENTERCORRECTLY="0"while [ $ENTERCORRECTLY -ne 1 ]doread -e -p 'Enter path where SD card tarballs were downloaded : '  TARBALLPATHecho ""ENTERCORRECTLY=1if [ -d $TARBALLPATH ]thenecho "Directory exists"echo ""echo "This directory contains:"ls $TARBALLPATHecho ""read -p 'Is this correct? [y/n] : ' ISRIGHTPATHcase $ISRIGHTPATH in"y" | "Y") ;;"n" | "N" ) ENTERCORRECTLY=0;continue;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;continue;;esacelseecho "Invalid path make sure to include complete path"ENTERCORRECTLY=0continuefi# Check that tarballs were foundif [ ! -e "$TARBALLPATH""/boot_partition.tar.gz" ]thenecho "Could not find boot_partition.tar.gz as expected.  Please"echo "point to the directory containing the boot_partition.tar.gz"ENTERCORRECTLY=0continuefiif [ ! -e "$TARBALLPATH""/rootfs_partition.tar.gz" ]thenecho "Could not find rootfs_partition.tar.gz as expected.  Please"echo "point to the directory containing the rootfs_partition.tar.gz"ENTERCORRECTLY=0continuefiif [ ! -e "$TARBALLPATH""/start_here_partition.tar.gz" ]thenecho "Could not find start_here_partition.tar.gz as expected.  Please"echo "point to the directory containing the start_here_partition.tar.gz"ENTERCORRECTLY=0continuefidone# Make temporary directories and untar mount the partitionsmkdir $PWD/bootmkdir $PWD/rootfsmkdir $PWD/start_heremkdir $PWD/tmpmount -t vfat ${DRIVE}${P}1 bootmount -t ext3 ${DRIVE}${P}2 rootfsmount -t ext3 ${DRIVE}${P}3 start_here# Remove any existing content in case the partitions were not# recreatedsudo rm -rf boot/*sudo rm -rf rootfs/*sudo rm -rf start_here/*# Extract the tarball contents.
cat << EOM################################################################################Extracting boot partition tarball################################################################################
EOMuntar_progress $TARBALLPATH/boot_partition.tar.gz tmp/if [ -e "./tmp/MLO" ]thencp ./tmp/MLO boot/          # 这不多此一举。ficp -rf ./tmp/* boot/cat << EOM################################################################################Extracting rootfs partition tarball################################################################################
EOMuntar_progress $TARBALLPATH/rootfs_partition.tar.gz rootfs/cat << EOM################################################################################Extracting start_here partition to temp directory################################################################################
EOMrm -rf tmp/*untar_progress $TARBALLPATH/start_here_partition.tar.gz tmp/cat << EOM################################################################################Extracting CCS tarball################################################################################
EOMmv tmp/CCS-5*.tar.gz .untar_progress CCS-5*.tar.gz tmp/rm CCS-5*.tar.gzcat << EOM################################################################################Copying Contents to START_HERE################################################################################
EOMTOTALSIZE=`sudo du -c tmp/* | grep total | awk {'print $1'}`cp -rf tmp/* start_here/ &cp_progress $TOTALSIZE start_here/      # 这里没有使用百分比来显示。sync;sync# Fix up the START_HERE partitoin permissionschown nobody -R start_herechgrp nogroup -R start_herechmod -R g+r+x,o+r+x start_here/CCSumount boot rootfs start_here           # 卸载各个设备节点sync;sync# Clean up the temp directoriesrm -rf boot rootfs start_here tmp       # 删除各个文件夹,做完了也就没必要了
}# find the avaible SD cards
# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$ mount | grep 'on / ' | awk {'print $1'} |  cut -c6-9
# sda1
# Qt@aplex:~/ti-processor-sdk-linux-am335x-evm-01.00.00.00$
# 这里的ROOTDRIVE会得到sda1,所以这一部分代码应该都不会符合预期
ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} |  cut -c6-9`
if [ "$ROOTDRIVE" = "root" ]; thenROOTDRIVE=`readlink /dev/root | cut -c1-3`
elseROOTDRIVE=`echo $ROOTDRIVE | cut -c1-3`
fiPARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`# Check for available mounts
check_for_sdcardsecho -e "\nAvailible Drives to write images to: \n"
echo "#  major   minor    size   name "
cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
echo " "DEVICEDRIVENUMBER=
while true;
doread -p 'Enter Device Number or 'n' to exit: ' DEVICEDRIVENUMBERecho " "if [ "$DEVICEDRIVENUMBER" = 'n' ]; thenexit 1fiif [ "$DEVICEDRIVENUMBER" = "" ]; then# Check to see if there are any changescheck_for_sdcardsecho -e "These are the Drives available to write images to:"echo "#  major   minor    size   name "cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''echo " "continuefiDEVICEDRIVENAME=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $5}'`if [ -n "$DEVICEDRIVENAME" ]thenDRIVE=/dev/$DEVICEDRIVENAMEDEVICESIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $4}'`breakelseecho -e "Invalid selection!"# Check to see if there are any changescheck_for_sdcardsecho -e "These are the only Drives available to write images to: \n"echo "#  major   minor    size   name "cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''echo " "fi
doneecho "$DEVICEDRIVENAME was selected"
#Check the size of disk to make sure its under 16GB
if [ $DEVICESIZE -gt 17000000 ] ; then
cat << EOM################################################################################**********WARNING**********Selected Device is greater then 16GBContinuing past this point will erase data from deviceDouble check that this is the correct SD Card################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -p 'Would you like to continue [y/n] : ' SIZECHECKecho ""echo " "ENTERCORRECTLY=1case $SIZECHECK in"y")  ;;"n")  exit;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacecho ""donefi
echo ""DRIVE=/dev/$DEVICEDRIVENAME
NUM_OF_DRIVES=`df | grep -c $DEVICEDRIVENAME`# This if statement will determine if we have a mounted sdX or mmcblkX device.
# If it is mmcblkX, then we need to set an extra char in the partition names, 'p',
# to account for /dev/mmcblkXpY labled partitions.
if [[ ${DEVICEDRIVENAME} =~ ^sd. ]]; thenecho "$DRIVE is an sdx device"P=''
elseecho "$DRIVE is an mmcblkx device"P='p'
fiif [ "$NUM_OF_DRIVES" != "0" ]; thenecho "Unmounting the $DEVICEDRIVENAME drives"for ((c=1; c<="$NUM_OF_DRIVES"; c++ ))dounmounted=`df | grep '\<'$DEVICEDRIVENAME$P$c'\>' | awk '{print $1}'`if [ -n "$unmounted" ]thenecho " unmounted ${DRIVE}$P$c"sudo umount -f ${DRIVE}$P$cfidone
fi# Refresh this variable as the device may not be mounted at script instantiation time
# This will always return one more then needed
NUM_OF_PARTS=`cat /proc/partitions | grep -v $ROOTDRIVE | grep -c $DEVICEDRIVENAME`
for ((c=1; c<"$NUM_OF_PARTS"; c++ ))
doSIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME$P$c'\>'  | awk '{print $3}'`echo "Current size of $DEVICEDRIVENAME$P$c $SIZE bytes"
done# check to see if the device is already partitioned
for ((  c=1; c<5; c++ ))
doeval "SIZE$c=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME$P$c'\>'  | awk '{print $3}'`"
donePARTITION="0"
if [ -n "$SIZE1" -a -n "$SIZE2" ] ; thenif  [ "$SIZE1" -gt "72000" -a "$SIZE2" -gt "700000" ]thenPARTITION=1if [ -z "$SIZE3" -a -z "$SIZE4" ]then#Detected 2 partitionsPARTS=2elif [ "$SIZE3" -gt "1000" -a -z "$SIZE4" ]then#Detected 3 partitionsPARTS=3elseecho "SD Card is not correctly partitioned"PARTITION=0fifi
elseecho "SD Card is not correctly partitioned"PARTITION=0PARTS=0
fi#Partition is found
if [ "$PARTITION" -eq "1" ]
then
cat << EOM################################################################################Detected device has $PARTS partitions alreadyRe-partitioning will allow the choice of 2 or 3 partitions################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -p 'Would you like to re-partition the drive anyways [y/n] : ' CASEPARTITIONecho ""echo " "ENTERCORRECTLY=1case $CASEPARTITION in"y")  echo "Now partitioning $DEVICEDRIVENAME ...";PARTITION=0;;"n")  echo "Skipping partitioning";;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacecho ""donefi#Partition is not found, choose to partition 2 or 3 segments
if [ "$PARTITION" -eq "0" ]
then
cat << EOM################################################################################Select 2 partitions if only need boot and rootfs (most users)Select 3 partitions if need SDK & CCS on SD card.  This is usually usedby device manufacturers with access to partition tarballs.****WARNING**** continuing will erase all data on $DEVICEDRIVENAME################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -p 'Number of partitions needed [2/3] : ' CASEPARTITIONNUMBERecho ""echo " "ENTERCORRECTLY=1case $CASEPARTITIONNUMBER in"2")  echo "Now partitioning $DEVICEDRIVENAME with 2 partitions...";PARTITION=2;;"3")  echo "Now partitioning $DEVICEDRIVENAME with 3 partitions...";PARTITION=3;;"n")  exit;;*)  echo "Please enter 2 or 3";ENTERCORRECTLY=0;;esacecho " "done
fi#Section for partitioning the drive#create 3 partitions
if [ "$PARTITION" -eq "3" ]
then# set the PARTS value as well
PARTS=3cat << EOM################################################################################Now making 3 partitions################################################################################EOMdd if=/dev/zero of=$DRIVE bs=1024 count=1024SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`echo DISK SIZE - $SIZE bytesCYLINDERS=`echo $SIZE/255/63/512 | bc`sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
,9,0x0C,*
10,90,,-
100,,,-
EOFcat << EOM################################################################################Partitioning Boot################################################################################
EOMmkfs.vfat -F 32 -n "boot" ${DRIVE}${P}1
cat << EOM################################################################################Partitioning Rootfs################################################################################
EOMmkfs.ext3 -L "rootfs" ${DRIVE}${P}2
cat << EOM################################################################################Partitioning START_HERE################################################################################
EOMmkfs.ext3 -L "START_HERE" ${DRIVE}${P}3syncsync#create only 2 partitions
elif [ "$PARTITION" -eq "2" ]
then# Set the PARTS value as well
PARTS=2
cat << EOM################################################################################Now making 2 partitions################################################################################EOM
dd if=/dev/zero of=$DRIVE bs=1024 count=1024SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`echo DISK SIZE - $SIZE bytesCYLINDERS=`echo $SIZE/255/63/512 | bc`sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
,9,0x0C,*
10,,,-
EOFcat << EOM################################################################################Partitioning Boot################################################################################
EOMmkfs.vfat -F 32 -n "boot" ${DRIVE}${P}1
cat << EOM################################################################################Partitioning rootfs################################################################################
EOMmkfs.ext3 -L "rootfs" ${DRIVE}${P}2syncsyncINSTALLSTARTHERE=n
fi#Break between partitioning and installing file system
cat << EOM################################################################################Partitioning is now doneContinue to install filesystem or select 'n' to safe exit**Warning** Continuing will erase files any files in the partitions################################################################################EOM
ENTERCORRECTLY=0
while [ $ENTERCORRECTLY -ne 1 ]
doread -p 'Would you like to continue? [y/n] : ' EXITQecho ""echo " "ENTERCORRECTLY=1case $EXITQ in"y") ;;"n") exit;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esac
done# If this is a three partition card then we will jump to a function to
# populate the three partitions and then exit the script.  If not we
# go on to prompt the user for input on the two partitions
if [ "$PARTS" -eq "3" ]
thenpopulate_3_partitionsexit 0
fi#Add directories for images
export START_DIR=$PWD
mkdir $START_DIR/tmp
export PATH_TO_SDBOOT=boot
export PATH_TO_SDROOTFS=rootfs
export PATH_TO_TMP_DIR=$START_DIR/tmpecho " "
echo "Mount the partitions "
mkdir $PATH_TO_SDBOOT
mkdir $PATH_TO_SDROOTFSsudo mount -t vfat ${DRIVE}${P}1 boot/
sudo mount -t ext3 ${DRIVE}${P}2 rootfs/echo " "
echo "Emptying partitions "
echo " "
sudo rm -rf  $PATH_TO_SDBOOT/*
sudo rm -rf  $PATH_TO_SDROOTFS/*echo ""
echo "Syncing...."
echo ""
sync
sync
synccat << EOM
################################################################################Choose file path to install from1 ) Install pre-built images from SDK2 ) Enter in custom boot and rootfs file paths################################################################################EOM
ENTERCORRECTLY=0
while [ $ENTERCORRECTLY -ne 1 ]
doread -p 'Choose now [1/2] : ' FILEPATHOPTIONecho ""echo " "ENTERCORRECTLY=1case $FILEPATHOPTION in"1") echo "Will now install from SDK pre-built images";;"2") echo "";;*)  echo "Please enter 1 or 2";ENTERCORRECTLY=0;;esac
done# SDK DEFAULTS
if [ $FILEPATHOPTION -eq 1 ] ; then#check that in the right directoryTHEEVMSDK=`echo $PARSEPATH | grep -o 'ti-processor-sdk-linux-am335x-evm-01.00.00.00'`if [ $PATHVALID -eq 1 ]; thenecho "now installing:  $THEEVMSDK"elseecho "no SDK PATH found"ENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -e -p 'Enter path to SDK : '  SDKFILEPATHecho ""ENTERCORRECTLY=1if [ -d $SDKFILEPATH ]thenecho "Directory exists"echo ""PARSEPATH=`echo $SDKFILEPATH | grep -o '.*ti-processor-sdk-linux-am335x-evm-01.00.00.00/'`#echo $PARSEPATHif [ "$PARSEPATH" != "" ] ; thenPATHVALID=1elsePATHVALID=0fi#echo $PATHVALIDif [ $PATHVALID -eq 1 ] ; thenTHEEVMSDK=`echo $SDKFILEPATH | grep -o 'ti-processor-sdk-linux-am335x-evm-01.00.00.00'`echo "Is this the correct SDK: $THEEVMSDK"echo ""read -p 'Is this correct? [y/n] : ' ISRIGHTPATHcase $ISRIGHTPATH in"y") ;;"n") ENTERCORRECTLY=0;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacelseecho "Invalid SDK path make sure to include ti-sdk-xxxx"ENTERCORRECTLY=0fielseecho "Invalid path make sure to include complete path"ENTERCORRECTLY=0fidonefi#check that files are in SDKBOOTFILEPATH="$PARSEPATH/board-support/prebuilt-images"MLO=`ls $BOOTFILEPATH | grep MLO | awk {'print $1'}`KERNELIMAGE=`ls $BOOTFILEPATH | grep [uz]Image | awk {'print $1'}`BOOTIMG=`ls $BOOTFILEPATH | grep u-boot | grep .img | awk {'print $1'}`BOOTBIN=`ls $BOOTFILEPATH | grep u-boot | grep .bin | awk {'print $1'}`BOOTUENV=`ls $BOOTFILEPATH | grep uEnv.txt | awk {'print $1'}`#rootfsROOTFILEPARTH="$PARSEPATH/filesystem"#ROOTFSTAR=`ls  $ROOTFILEPARTH | grep tisdk-rootfs | awk {'print $1'}`#Make sure there is only 1 tarCHECKNUMOFTAR=`ls $ROOTFILEPARTH | grep "tisdk-rootfs" | grep 'tar.gz' | grep -n '' | grep '2:' | awk {'print $1'}`if [ -n "$CHECKNUMOFTAR" ]then
cat << EOM################################################################################Multiple rootfs Tarballs found################################################################################EOMls $ROOTFILEPARTH | grep "tisdk-rootfs" | grep 'tar.gz' | grep -n '' | awk {'print "    " , $1'}echo ""read -p "Enter Number of rootfs Tarball: " TARNUMBERecho " "FOUNDTARFILENAME=`ls $ROOTFILEPARTH | grep "rootfs" | grep 'tar.gz' | grep -n '' | grep "${TARNUMBER}:" | cut -c3- | awk {'print$1'}`ROOTFSTAR=$FOUNDTARFILENAMEelseROOTFSTAR=`ls  $ROOTFILEPARTH | grep "tisdk-rootfs" | grep 'tar.gz' | awk {'print $1'}`fiROOTFSUSERFILEPATH=$ROOTFILEPARTH/$ROOTFSTARBOOTPATHOPTION=1ROOTFSPATHOPTION=2elif [ $FILEPATHOPTION -eq 2  ] ; then
cat << EOM
################################################################################For U-boot and MLOIf files are located in Tarball write complete path including the file name.e.x. $:  /home/user/MyCustomTars/boot.tar.gzIf files are located in a directory write the directory pathe.x. $: /ti-sdk/board-support/prebuilt-images/NOTE: Not all platforms will have an MLO file and this file canbe ignored for platforms that do not support an MLO.Update: The proper location for the kernel image and device treefiles have moved from the boot partition to the root filesystem.################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -e -p 'Enter path for Boot Partition : '  BOOTUSERFILEPATHecho ""ENTERCORRECTLY=1if [ -f $BOOTUSERFILEPATH ]thenecho "File exists"echo ""elif [ -d $BOOTUSERFILEPATH ]thenecho "Directory exists"echo ""echo "This directory contains:"ls $BOOTUSERFILEPATHecho ""read -p 'Is this correct? [y/n] : ' ISRIGHTPATHcase $ISRIGHTPATH in"y") ;;"n") ENTERCORRECTLY=0;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacelseecho "Invalid path make sure to include complete path"ENTERCORRECTLY=0fidonecat << EOM################################################################################For Kernel Image and Device Trees filesWhat would you like to do?1) Reuse kernel image and device tree files found in the selected rootfs.2) Provide a directory that contains the kernel image and device tree filesto be used.################################################################################EOMENTERCORRECTLY=0
while [ $ENTERCORRECTLY -ne 1 ]
doread -p 'Choose option 1 or 2 : ' CASEOPTIONecho ""echo " "ENTERCORRECTLY=1case $CASEOPTION in"1")  echo "Reusing kernel and dt files from the rootfs's boot directory";KERNELFILESOPTION=1;;"2")  echo "Choosing a directory that contains the kernel files to be used";KERNELFILESOPTION=2;;"n")  exit;;*)  echo "Please enter 1 or 2";ENTERCORRECTLY=0;;esacecho " "
doneif [ $KERNELFILESOPTION == 2 ]
thencat << EOM
################################################################################For Kernel Image and Device Trees filesThe kernel image name should contain the image type uImage or zImage dependingon which format is used.The device tree files must end with .dtbe.g    am335x-evm.dtb am43x-gp-evm.dtb################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -e -p 'Enter path for kernel image and device tree files : '  KERNELUSERFILEPATHecho ""ENTERCORRECTLY=1if [ -d $KERNELUSERFILEPATH ]thenecho "Directory exists"echo ""echo "This directory contains:"ls $KERNELUSERFILEPATHecho ""read -p 'Is this correct? [y/n] : ' ISRIGHTPATHcase $ISRIGHTPATH in"y") ;;"n") ENTERCORRECTLY=0;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacelseecho "Invalid path make sure to include complete path"ENTERCORRECTLY=0fidone
ficat << EOM################################################################################For Rootfs partitionIf files are located in Tarball write complete path including the file name.e.x. $:  /home/user/MyCustomTars/rootfs.tar.gzIf files are located in a directory write the directory pathe.x. $: /ti-sdk/targetNFS/################################################################################EOMENTERCORRECTLY=0while [ $ENTERCORRECTLY -ne 1 ]doread -e -p 'Enter path for Rootfs Partition : ' ROOTFSUSERFILEPATHecho ""ENTERCORRECTLY=1if [ -f $ROOTFSUSERFILEPATH ]thenecho "File exists"echo ""elif [ -d $ROOTFSUSERFILEPATH ]thenecho "This directory contains:"ls $ROOTFSUSERFILEPATHecho ""read -p 'Is this correct? [y/n] : ' ISRIGHTPATHcase $ISRIGHTPATH in"y") ;;"n") ENTERCORRECTLY=0;;*)  echo "Please enter y or n";ENTERCORRECTLY=0;;esacelseecho "Invalid path make sure to include complete path"ENTERCORRECTLY=0fidoneecho ""# Check if user entered a tar or not for BootISBOOTTAR=`ls $BOOTUSERFILEPATH | grep .tar.gz | awk {'print $1'}`if [ -n "$ISBOOTTAR" ]thenBOOTPATHOPTION=2elseBOOTPATHOPTION=1BOOTFILEPATH=$BOOTUSERFILEPATHMLO=`ls $BOOTFILEPATH | grep MLO | awk {'print $1'}`BOOTIMG=`ls $BOOTFILEPATH | grep u-boot | grep .img | awk {'print $1'}`BOOTBIN=`ls $BOOTFILEPATH | grep u-boot | grep .bin | awk {'print $1'}`BOOTUENV=`ls $BOOTFILEPATH | grep uEnv.txt | awk {'print $1'}`fiif [ "$KERNELFILESOPTION" == "2" ]thenKERNELIMAGE=`ls $KERNELUSERFILEPATH | grep [uz]Image | awk {'print $1'}`DTFILES=`ls $KERNELUSERFILEPATH | grep .dtb$ | awk {'print $1'}`fi#Check if user entered a tar or not for RootfsISROOTFSTAR=`ls $ROOTFSUSERFILEPATH | grep .tar.gz | awk {'print $1'}`if [ -n "$ISROOTFSTAR" ]thenROOTFSPATHOPTION=2elseROOTFSPATHOPTION=1ROOTFSFILEPATH=$ROOTFSUSERFILEPATHfi
ficat << EOM
################################################################################Copying files now... will take minutes################################################################################Copying boot partition
EOMif [ $BOOTPATHOPTION -eq 1 ] ; thenecho ""#copy boot files out of board supportif [ "$MLO" != "" ] ; thencp $BOOTFILEPATH/$MLO $PATH_TO_SDBOOT/MLOecho "MLO copied"elseecho "MLO file not found"fiecho ""echo ""if [ "$BOOTIMG" != "" ] ; thencp $BOOTFILEPATH/$BOOTIMG $PATH_TO_SDBOOT/u-boot.imgecho "u-boot.img copied"elif [ "$BOOTBIN" != "" ] ; thencp $BOOTFILEPATH/$BOOTBIN $PATH_TO_SDBOOT/u-boot.binecho "u-boot.bin copied"elseecho "No U-Boot file found"fiecho ""if [ "$BOOTUENV" != "" ] ; thencp $BOOTFILEPATH/$BOOTUENV $PATH_TO_SDBOOT/uEnv.txtecho "uEnv.txt copied"fielif [ $BOOTPATHOPTION -eq 2  ] ; thenuntar_progress $BOOTUSERFILEPATH $PATH_TO_TMP_DIRcp -rf $PATH_TO_TMP_DIR/* $PATH_TO_SDBOOTecho ""fiecho ""
syncecho "Copying rootfs System partition"
if [ $ROOTFSPATHOPTION -eq 1 ] ; thenTOTALSIZE=`sudo du -c $ROOTFSUSERFILEPATH/* | grep total | awk {'print $1'}`sudo cp -r $ROOTFSUSERFILEPATH/* $PATH_TO_SDROOTFS & cp_progress $TOTALSIZE $PATH_TO_SDROOTFSelif [ $ROOTFSPATHOPTION -eq 2  ] ; thenuntar_progress $ROOTFSUSERFILEPATH $PATH_TO_SDROOTFS
fiecho ""
echo ""
echo "Syncing..."
sync
sync
sync
sync
sync
sync
sync
syncif [ "$KERNELFILESOPTION" == "2" ]
thenmkdir -p $PATH_TO_SDROOTFS/bootif [ "$KERNELIMAGE" != "" ] ; thenCLEANKERNELNAME=`ls "$BOOTFILEPATH/$KERNELIMAGE" | grep -o [uz]Image`cp -f $KERNELUSERFILEPATH/$KERNELIMAGE $PATH_TO_SDROOTFS/boot/$CLEANKERNELNAMEecho "Kernel image copied"elseecho "$KERNELIMAGE file not found"fiCOPYINGDTB="false"for dtb in $DTFILESdoif [ -f "$KERNELUSERFILEPATH/$dtb" ] ; thencp -f $KERNELUSERFILEPATH/$dtb $PATH_TO_SDROOTFS/bootecho "$dtb copied"COPYINGDTB="true"fidoneif [ "$COPYINGDTB" == "false" ]thenecho "No device tree files found"fifiecho " "
echo "Un-mount the partitions "
sudo umount -f $PATH_TO_SDBOOT
sudo umount -f $PATH_TO_SDROOTFSecho " "
echo "Remove created temp directories "
sudo rm -rf $PATH_TO_TMP_DIR
sudo rm -rf $PATH_TO_SDROOTFS
sudo rm -rf $PATH_TO_SDBOOTecho " "
echo "Operation Finished"
echo " "

ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking相关推荐

  1. ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking

    #!/bin/sh# # ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking # 说明: # 本文主要对TI的sdk中的 ...

  2. ti processor sdk linux am335x evm /bin/setup-minicom.sh hacking

    #!/bin/sh# # ti processor sdk linux am335x evm /bin/setup-minicom.sh hacking # 说明: # 本文主要对TI的sdk中的se ...

  3. 【华为Hilink SDK Linux系统开发】第三章:华为hilink SDK Linux系统网关适配

    mark:https://blog.csdn.net/qq_24550925/article/details/107282773 关注嘉友创科技公众号 声明:文章只做技术交流,没有其他任何用途,侵权泄 ...

  4. 【BLE】TI CC2640R2F SDK结构以及一些概念解析

    一.概述 CC2640R2F作为BLE单SOC解决方案, TI的SDK将工程分为应用程序(APP)和协议栈(Stack)两部分 二.协议栈 协议栈包括:主机(Host)和控制器(Controller) ...

  5. Linux下的/bin、/sbin、/usr/bin、/usr/sbin目录

    Linux下的/bin./sbin./usr/bin./usr/sbin目录 在linux下我们经常用到的四个应用程序的目录是/bin./sbin./usr/bin./usr/sbin .而四者存放的 ...

  6. linux中的 bin sh,Linux-#!/bin/sh理解

    #!是一个特殊符号,/bin/sh是用来解释该脚本的的shell路径 #!/bin/sh指该脚本使用/bin/sh来执行 sh只是其中一种解释方式,通过如下命令可以查到支持的shell解释方式: xx ...

  7. Linux脚本开头#!/bin/bash和#!/bin/sh是什么意思以及区别

    Linux脚本开头#!/bin/bash和#!/bin/sh是什么意思以及区别 一.意思 #!/bin/sh是指此脚本使用/bin/sh来解释执行,#!是特殊的表示符,其后面根的是此解释此脚本的she ...

  8. linux下安装bin格式的程序

    linux下安装*.bin程序的方式: 1.先切换到文件所在目录 2.执行命令 sudo chmod +x *.bin  (为文件添加可执行属性) 3.执行命令sudo ./*.bin (运行程序) ...

  9. 【华为Hilink SDK Linux系统开发】目录 开源一小步

    声明:文章只做技术交流,没有其他任何用途,侵权泄密立删!! 关注嘉友创科技公众号 [华为Hilink开发]目录 [华为Hilink SDK Linux系统开发]第一章:华为Hilink平台简介及开发流 ...

最新文章

  1. 《庆余年》值得一看吗?Python告诉你谁在关注 | CSDN原力计划
  2. 架构设计的本质:系统与子系统、模块与组件、框架与架构
  3. Webpack vs Rollup
  4. 熵值法计算权重有异常值_指标权重确定方法 1-熵值法
  5. 同类分析比较工具 google trend
  6. RTC 融合通信服务架构与场景应用 | 2021稀土开发者大会音视频专场
  7. linux dd iflag oflag,centos – dd oflag =直接5倍速
  8. NSRange的用法【转】
  9. c# 关于WebBrowser的模拟提交InvokeMember方法是什么意思!
  10. 如何优雅地根治null值引起的Bug?!
  11. Spring boot 2.x+oauth2实现单点登录:基础准备之Spring Security
  12. etherboot无盘启动
  13. 交换机解决电脑IP地址冲突
  14. 两分钟读懂什么是TPS和QPS
  15. 布尔运算(Boolean Operators)
  16. Rust: Descending Order
  17. 如何将PDF文档转成Excel?
  18. 插入法排序c语言程序,C语言之插入排序算法
  19. 后端进度报告(2018.5.17)
  20. solidworks 资料分享

热门文章

  1. aardio - 使用customPlus库制作弹出列表
  2. 51单片机DS12C887时钟芯片和1602液晶显示完善前人例程版本
  3. Shell脚本:2、后台处理nohup命令
  4. 批量插入或更新数据(MyBatis-plus框架)
  5. 小木虫emuch遭封禁,新域名muchong.com尚可用
  6. java中组件与容器_java组件和容器
  7. 自己开店怎么记账才能更清楚
  8. 利用solidworks钣金的通风口命令设计风扇罩,solidworks风扇罩如何设计
  9. Linux文件压缩和解压命令【gzip、gunzip、zip、unzip、tar】【详细总结】
  10. 快速排序 C/C++