Files
2026-09-22 09:38:26 +08:00

154 lines
3.4 KiB
Bash
Executable File

#/bin/bash
#File package used by OTA
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not use the BSP as root. Exiting..."
exit 1
fi
DATE="$(date +%Y%m%d:%H%M%S)"
SOURCEROOT=${1}
MACHINE=${2}
DISTRO=${3}
UNISOC_PRODUCT=${4}
OUTPUT_PATH=$SOURCEROOT/out/target/product/$MACHINENAME
TMPPATHNAME=$(ls ${SOURCEROOT}/build-${DISTRONAME} | grep tmp)
TMPPATH="$SOURCEROOT/build-$DISTRONAME/$TMPPATHNAME"
IMAGEPATH="$TMPPATH/deploy/images/$MACHINENAME"
TARGET_FILES_DIR="ota_files"
UNISOC_ARCHIVE_DIR_ROOT=${OUTPUT_PATH}/archive_ota
UNISOC_ARCHIVE_DIR=${UNISOC_ARCHIVE_DIR_ROOT}/${TARGET_FILES_DIR}
echo SOURCEROOT=${SOURCEROOT} MACHINE=${MACHINE} DISTRO=${DISTRO} UNISOC_PRODUCT=${UNISOC_PRODUCT}
cd ${SOURCEROOT}
make_temp_dir()
{
if [ ! -d ${UNISOC_ARCHIVE_DIR_ROOT} ]; then
mkdir -p ${UNISOC_ARCHIVE_DIR_ROOT}
fi
if [ ! -d ${UNISOC_ARCHIVE_DIR} ]; then
rm -rf $UNISOC_ARCHIVE_DIR
fi
mkdir -p ${UNISOC_ARCHIVE_DIR}
}
# traverse ko for ubuntu
doindent()
{
# Do a small indent depending on how deep into the tree we are
# Depending on your enviroment, you may need to use
# echo " \c" instead of
# echo -en " "
j=0;
while [ "$j" -lt "$1" ]; do
echo -en " "
j=`expr $j + 1`
done
}
traverse()
{
# Traverse a directory
cd "$1"
ls | while read i
do
doindent $2
if [ -d "$i" ]; then
echo "Directory: $i"
# Calling this as a subshell means that when the called
# function changes directory, it will not affect our
# current working directory
(traverse "$i" `expr $2 + 1`)
else
echo "File: $i archive dir $UNISOC_ARCHIVE_DIR"
cp -rf "$i" $UNISOC_ARCHIVE_DIR/$i
abs_path="$(readlink -f $i)"
echo "path: $abs_path" >> $UNISOC_ARCHIVE_DIR/pathfile
fi
done
}
copy_files()
{
tmpPATH=$IMAGEPATH/update.sh
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/swupdateext
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/ota_engine_ext
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/libbspatch.so
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/libotaarith.so
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/nvheadertool
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=$IMAGEPATH/add_nv_header.py
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
tmpPATH=${SOURCEROOT}/build-${DISTRONAME}/gzip
if [ -e $tmpPATH ]; then
cp -rf $tmpPATH $UNISOC_ARCHIVE_DIR/
fi
#For Ubuntu product
if [[ ${DISTRO} =~ "ubuntu" ]]; then
echo "build ubuntu ko script!"
if [[ ${IMAGENAME} =~ "prerootfs" ]]; then
UBUNTUROOTFSPATH="$SOURCEROOT/prebuilts/os/ubuntu_rootfs/prerootfs/rootfs-bak"
elif [[ ${IMAGENAME} =~ "ubuntu18" ]]; then
UBUNTUROOTFSPATH="$SOURCEROOT/prebuilts/os/ubuntu_rootfs/18.04/rootfs-bak"
elif [[ ${IMAGENAME} =~ "ubuntu20" ]]; then
UBUNTUROOTFSPATH="$SOURCEROOT/prebuilts/os/ubuntu_rootfs/20.04/rootfs-bak"
fi
KOPATH="$UBUNTUROOTFSPATH/lib/modules"
#traverser ko path to add kos to TARGET_FILES_DIR
if [ -d $KOPATH ]; then
traverse $KOPATH 0
fi
fi
}
tar_target_files()
{
cd $UNISOC_ARCHIVE_DIR_ROOT/
tar -h -cvzf ota_files.tgz ${TARGET_FILES_DIR}
mv ota_files.tgz ${OUTPUT_PATH}/ota_files.img
cd -
}
remove_temp_dir()
{
rm -rf $UNISOC_ARCHIVE_DIR
}
make_temp_dir
copy_files
tar_target_files
remove_temp_dir