Due to project requirements, a differential upgrade function needs to be developed. Adopt OTA difference algorithm, use hdiff and hpatch tools to realize packet difference and merge respectively. Choose the appropriate combination parameters to achieve the shortest upgrade time. The following code reflects that different parameters correspond to different times.
#! /bin/bash
sdkdir=.
diffPath=./diffpath1
oldPath=./oldpath1
diff_args=("-s-8" "-s-16" "-s-32")
patch_args=("-s-8" "-s-16" "-s-32" "-s-64")
echo "${diff_args[@]}"
echo "${patch_args[@]}"
echo -n 0 >>date.text ; echo -n ',' >>date.text
for k in ${patch_args[@]}
do
echo -n $k >>date.text ; echo -n ',' >>date.text
done
echo `cat date.text` >> date.csv
echo >date.text
patch ()
{
for i in ${diff_args[@]}
do
echo -n $i >>date.text ; echo -n ',' >>date.text
for j in ${patch_args[@]}
do
echo -n `$sdkdir/hpatchz $j $oldPath/rootfs.tar $diffPath/rootfs.tar $sdkdir/rootfs.tar | grep patchz | awk '{print $3}'` >>date.text ; echo -n ',' >>date.text
sleep 1
if [ -f $sdkdir/rootfs.tar ]; then
rm $sdkdir/rootfs.tar
else
echo "ERROR: cann't find old rootfs.tar"
exit 1
fi
done
echo `cat date.text` >> date.csv
echo >date.text
if [[ $i == "-s-32" ]] && [[ $j == "-s-64" ]]; then
break
else
echo $i
fi
done
}
patch1 ()
{
for i in ${diff_args[@]}
do
echo -n $i >>date.text ; echo -n ',' >>date.text
for j in ${patch_args[@]}
do
echo -n `$sdkdir/hpatchz $j $oldPath/rootfs.tar $diffPath/rootfs.tar $sdkdir/rootfs.tar | grep patchz | awk '{print $3}'` >>date.text ; echo -n ',' >>date.text
sleep 1
if [ -f $sdkdir/rootfs.tar ]; then
rm $sdkdir/rootfs.tar
else
echo "ERROR: cann't find old rootfs.tar"
exit 1
fi
done
echo `cat date.text` >> date.csv
echo >date.text
break
done
}
arg='-s-0'
if [ $1 == $arg ]; then
patch ${diff_args[@]}
else
patch1 $1
fi