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

537 lines
18 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#
# SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
#
# Copyright 2016-2023 Unisoc (Shanghai) Technologies Co., Ltd
#
# Licensed under the Unisoc General Software License, version 1.0 (the License);
# you may not use this file except in compliance with the License. You may obtain a copy of the License at
#
# https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
#
# Software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OF ANY KIND, either express or implied.
# See the Unisoc General Software License, version 1.0 for more details.
#
build_time=$(date "+%Y%m%d%H%M%S")
timename=$1+$2+${build_time}+timemsg.log
timedir=${PWD}/prebuilts/scripts
echo "" >> ${timedir}/${timename}
echo "---------------- hardware info ----------------" >> ${timedir}/${timename}
cat /proc/meminfo | grep MemFree >> ${timedir}/${timename}
cat /proc/meminfo | grep MemAvailable >> ${timedir}/${timename}
physical_id=`cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l`
processor=`cat /proc/cpuinfo |grep "processor"|wc -l`
echo "physical CPU: ${physical_id}" >> ${timedir}/${timename}
echo "processor CPU: ${processor}" >> ${timedir}/${timename}
cat /proc/cpuinfo |grep "cores"|uniq >> ${timedir}/${timename}
echo "" >> ${timedir}/${timename}
echo "---------------- service info ----------------" >> ${timedir}/${timename}
echo "USERNAME: ${USER}" >> ${timedir}/${timename}
echo "HOSTNAME: ${HOSTNAME}" >> ${timedir}/${timename}
echo "ip info" >> ${timedir}/${timename}
ifconfig >> ${timedir}/${timename}
echo "" >> ${timedir}/${timename}
echo "---------------- build info ------------------" >> ${timedir}/${timename}
echo "pac name: $1 $2" >> ${timedir}/${timename}
echo "" >> ${timedir}/${timename}
echo "----------------- time info ------------------" >> ${timedir}/${timename}
echo "BUILD BEGIN: $(date "+%Y-%m-%d %H:%M:%S")" >> ${timedir}/${timename}
BEGIN_TIME=`date +%s`
btime=`date +%s`
long_help_message="
build.sh help message as below:
-h, --help, ? report help message
-m, MACHINE print MACHINENAME list
-d, DISTRO print DISTRONAME list
-i, IMAGE print IMAGENAME list
-u, USER print USERNAME list, [userdebug as default]
##--------------------------------------------------------------------##
## build.sh arguments include: ##
## MACHINENAME, DISTRONAME, IMAGENAME, USERNAME ##
## ##
## build modle: ##
## ./build.sh MACHINENAME+DISTRONAME+IMAGENAME USERNAME ##
## ##
## build sample: ##
## ./build.sh sl8563-cpe-2h10+initgc+console userdebug ##
##------------------------------------------------------------------- ##
"
machinelist=(s9863a-1h10 ums9620-2h10 ums9620-2h10-k515)
distrolist=(wayland initgc)
imagelist=(console docker minimal tiny prerootfs wayland)
userlist=(userdebug user)
func_build_list ()
{
names=$1
echo "$2 list:"
for ((i=0; i<${#names[*]}; i++))
{
echo ${names[$i]}
}
exit 0;
}
func_long_help_messge ()
{
echo "$long_help_message"
exit 0
}
func_help()
{
for loop in $@
do
case $loop in
?|-h|*help)
func_long_help_messge
break
;;
-m|MACHINE)
func_build_list "${machinelist[*]}" "MACHINENAME"
break
;;
-d|DISTRO)
func_build_list "${distrolist[*]}" "DISTRONAME"
break
;;
-i|IMAGE)
func_build_list "${imagelist[*]}" "IMAGENAME"
break
;;
-u|USER)
func_build_list "${userlist[*]}" "USERNAME"
break
;;
*)
break
;;
esac
done
}
fun_change_image_rootfs_dir(){
if [ ! -e "${ROOTFS_EXT4_GZ}" ];then
echo "${ROOTFS_EXT4_GZ} is not exsit"
return 1
fi
echo "begin mount ext4 for IMAGE_ROOTFS make has less difference"
if [ ! -d "${EXT4_MOUNT_POINT}" ];then
mkdir -p ${EXT4_MOUNT_POINT}
rm -rf ${ROOTFS_EXT4_DIR}
mkdir -p ${ROOTFS_EXT4_DIR}
else
echo "${EXT4_MOUNT_POINT} is exsit ,so umout and rm it first!"
ext4fsdir="${SOURCEROOT}/${EXT4_MOUNT_POINT}"
dirmountinfo=`df -h | grep ${ext4fsdir}`
if [ -n "${dirmountinfo}" ];then
echo "sudo umount ${EXT4_MOUNT_POINT}"
sudo umount ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
return 1
fi
fi
echo "rm -rf ${EXT4_MOUNT_POINT}"
rm -rf ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
return 1
fi
mkdir -p ${EXT4_MOUNT_POINT}
rm -rf ${ROOTFS_EXT4_DIR}
mkdir -p ${ROOTFS_EXT4_DIR}
fi
FILE_USER=`ls -l | grep "${EXT4_MOUNT_POINT}" | awk '{print $3}'`
echo "FILE_USER is ${FILE_USER}"
FILE_USER_GROUP=`ls -l | grep "${EXT4_MOUNT_POINT}" | awk '{print $4}'`
echo "FILE_USER_GROUP is ${FILE_USER_GROUP}"
cp ${ROOTFS_EXT4_GZ} ${ROOTFS_EXT4}.gz
gzip -d ${ROOTFS_EXT4}.gz
chmod 777 ${ROOTFS_EXT4}
echo "sudo mount -o loop ${ROOTFS_EXT4} ${EXT4_MOUNT_POINT}"
sudo mount -o loop ${ROOTFS_EXT4} ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
sudo umount ${EXT4_MOUNT_POINT}
return 1
fi
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
sudo umount ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "failed to umount ${EXT4_MOUNT_POINT},please umount it in manual: $LINENO"
return 1
fi
return 1
fi
echo "sudo chown "${FILE_USER}" ${EXT4_MOUNT_POINT}"
sudo chown "${FILE_USER}" ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
sudo umount ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "failed to umount ${EXT4_MOUNT_POINT},please umount it in manual: $LINENO"
return 1
fi
return 1
fi
echo `ls -l | grep "${EXT4_MOUNT_POINT}"`
return 0
}
fun_change_image_rootfs_in_localconf(){
echo "sed -i ${EXT4_MOUNT_POINT} to $SOURCEROOT/prebuilts/scripts/conf/local.conf"
sed -i "/${EXT4_MOUNT_POINT}/d" $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo "IMAGE_ROOTFS=\"${NEW_IMAGE_ROOTFS_DIR}\"" >> conf/local.conf
return 0
}
fun_post_change_image_rootfs_dir(){
sed -i "/${EXT4_MOUNT_POINT}/d" $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo `pwd`
cd ${SOURCEROOT}
echo "sudo umount ${EXT4_MOUNT_POINT}"
sudo umount ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
fi
echo "rm -rf ${EXT4_MOUNT_POINT}"
rm -rf ${EXT4_MOUNT_POINT}
if [ $? != 0 ]; then
echo "The procedure of fun_make_image_rootfs_point is failed, shell error line: $LINENO"
fi
rm -rf ${ROOTFS_EXT4_DIR}
cd -
}
fun_sign2(){
cd ${SOURCEROOT}
ext4fsdir="${SOURCEROOT}/${EXT4_MOUNT_POINT}"
dirmountinfo=`df -h | grep ${ext4fsdir}`
if [ -n "${dirmountinfo}" ];then
echo "sudo umount ${EXT4_MOUNT_POINT} before crtl c "
sudo umount ${EXT4_MOUNT_POINT}
fi
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
# when build pac. touch ctrl c or else, reset /prebuilts/scripts/conf/local.conf
sed -i '/USERDEBUG=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
sed -i '/ENG_IT=/d' $SOURCEROOT/prebuilts/scripts/conf/bblayers.conf
sed -i '/SECBOOT_ENABLE=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
sed -i '/DATE_BUILD=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
exit 0
}
func_help $1 $2
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not use the BSP as root. Exiting..."
exit 1
fi
DISTROSUFFIX=`echo $1 | awk -F+ '{print $2}'`
DISTRONAME=unisoc-`echo $1 | awk -F+ '{print $2}'`
IMAGESUFFIX=`echo $1 | awk -F+ '{print $3}'`
IMAGENAME=unisoc-`echo $1 | awk -F+ '{print $3}'`-image
TMP1=`echo $1 | awk -F+ '{print $1}'`
MACHINENAME=`echo $TMP1 | sed 's/_/-/g'`
MACHINESUFFIX=`echo ${MACHINENAME} | awk -F- '{print $1}'`
if [ "$IMAGENAME" == "" ]; then
IMAGENAME=unisoc-console-image
fi
TMP4=`echo $1 | awk -F+ '{print $4}'`
if [[ $2 == "" ]] || [[ $2 == "userdebug" ]] || [[ $2 == "default" ]]; then
USERDEBUG="userdebug"
elif [ $2 == "user" ]; then
USERDEBUG="user"
elif [ $2 == "eng" ]; then
USERDEBUG="eng"
else
IMAGENAME=unisoc-`echo $1 | awk -F+ '{print $3}'`-$2
fi
export USERDEBUG=${USERDEBUG}
# PRODUCT type
UNISOC_PRODUCT=`echo $1 | awk -F+ '{print $5}'`
if [[ $UNISOC_PRODUCT == "" ]]; then
UNISOC_PRODUCT="default"
# ubuntu distro, use ubuntu product type
if [[ ${DISTRONAME} == "unisoc-ubuntu" ]]; then
UNISOC_PRODUCT="ubuntu"
fi
fi
UNISOC_PRODUCT=`echo $UNISOC_PRODUCT | sed 's/_/-/g'`
BB_NO_NETWORK_FLAG="0"
# control if build sdk esdk and ota
BUILD_SDK_FLAG="0"
BUILD_ESDK_FLAG="0"
BUILD_OTA_FLAG="0"
param_count=$#
for ((i=1;i<=${param_count};i++));
do
eval j=\$$i
if [[ $j == "offline" ]]; then
BB_NO_NETWORK_FLAG="1"
fi
if [[ $j == "sdk" ]]; then
BUILD_SDK_FLAG="1"
fi
if [[ $j == "esdk" ]]; then
BUILD_ESDK_FLAG="1"
fi
if [[ $j == "ota" ]]; then
BUILD_OTA_FLAG="1"
fi
done
# ubuntu pac,dont build sdk/esdk and not build idh
if [[ ${IMAGENAME} == "unisoc-prerootfs-image" ]] || [[ ${DISTRONAME} == "unisoc-ubuntu" ]]; then
BUILD_SDK_FLAG="0"
BUILD_ESDK_FLAG="0"
fi
echo "FLAG is : BUILD_SDK_FLAG=${BUILD_SDK_FLAG} BUILD_ESDK_FLAG=${BUILD_ESDK_FLAG} BUILD_OTA_FLAG=${BUILD_OTA_FLAG}"
if [[ ${TMP4} == "" ]] || [[ ${TMP4} == "sec" ]] || [[ ${TMP4} == "default" ]]; then
SECBOOT_ENABLE="sec"
elif [ ${TMP4} == "nosec" ]; then
SECBOOT_ENABLE="nosec"
else
echo "Error: sec or nosec ?"
exit 1
fi
export SECBOOT_ENABLE=${SECBOOT_ENABLE}
SOURCEROOT=$(pwd)
cd ${SOURCEROOT}
echo "Check ubuntu toolchain..."
./prebuilts/scripts/ubuntu_scripts/setup_toolchain_for_ubuntu.sh ./prebuilts/toolchains/ubuntu20.04
./prebuilts/scripts/ubuntu_scripts/setup_toolchain_for_ubuntu.sh ./prebuilts/toolchains/ubuntu18.04
echo "Cleaning old built folder..."
rm -rf sstate-cache build-* out/target/product/${MACHINENAME} out/*timemsg.log
EXT4_MOUNT_IMAGE_ROOTFS_NAME=${MACHINENAME}-${SECBOOT_ENABLE}-${USERDEBUG}.ext4
EXT4_MOUNT_POINT="ext4mountpoint"
ROOTFS_EXT4_GZ_DIR="./prebuilts/pac-binary/${MACHINESUFFIX}"
ROOTFS_EXT4_GZ="${ROOTFS_EXT4_GZ_DIR}/${EXT4_MOUNT_IMAGE_ROOTFS_NAME}.gz"
ROOTFS_EXT4_DIR="ext4fs"
ROOTFS_EXT4="${ROOTFS_EXT4_DIR}/rootfs.ext4"
NEW_IMAGE_ROOTFS_DIR="${SOURCEROOT}/${EXT4_MOUNT_POINT}/rootfs"
trap "fun_sign2" 1 2
fun_change_image_rootfs_dir
flag_change_image_rootfs_dir=$?
echo "MACHINENAME=${MACHINENAME} ,DISTRO=${DISTRONAME}, USERDEBUG=${USERDEBUG}, SECBOOT_ENABLE=${SECBOOT_ENABLE} UNISOC_PRODUCT=${UNISOC_PRODUCT}"
export MACHINE=${MACHINENAME} && export DISTRO=${DISTRONAME} && export IMAGESUFFIX=${IMAGESUFFIX} && export USERDEBUG=${USERDEBUG} && export UNISOC_PRODUCT=${UNISOC_PRODUCT} && source setup-environment build-${DISTRONAME}
sed -i '/USERDEBUG=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
sed -i '/DATE_BUILD=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
sed -i '/SECBOOT_ENABLE=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
if [ "${flag_change_image_rootfs_dir}" = 0 ];then
echo "do fun_change_image_rootfs_in_localconf"
fun_change_image_rootfs_in_localconf
else
echo "no do fun_change_image_rootfs_in_localconf"
fi
if [ "$USERDEBUG" == "userdebug" ]; then
echo 'USERDEBUG="userdebug"' >> conf/local.conf
echo 'ENG_IT="userdebug"' >> conf/bblayers.conf
elif [ "$USERDEBUG" == "user" ]; then
echo 'USERDEBUG="user"' >> conf/local.conf
echo 'ENG_IT="user"' >> conf/bblayers.conf
elif [ "$USERDEBUG" == "eng" ]; then
echo 'USERDEBUG="userdebug"' >> conf/local.conf
echo 'ENG_IT="eng"' >> conf/bblayers.conf
fi
if [ "$SECBOOT_ENABLE" == "sec" ]; then
echo 'SECBOOT_ENABLE="sec"' >> conf/local.conf
elif [ "$SECBOOT_ENABLE" == "nosec" ]; then
echo 'SECBOOT_ENABLE="nosec"' >> conf/local.conf
fi
if [ "$BB_NO_NETWORK_FLAG" == "1" ]; then
echo 'BB_NO_NETWORK="1"' >> conf/local.conf
$SOURCEROOT/prebuilts/scripts/offline-monitor.sh $$ $SOURCEROOT/prebuilts/scripts/conf/local.conf &
elif [ "$BB_NO_NETWORK_FLAG" == "0" ]; then
echo 'BB_NO_NETWORK="0"' >> conf/local.conf
fi
YEAR=`date +%g`
WEEK=`date +%V`
DAY=`date +%u`
HOUR=`date +%H`
MINUTE=`date +%M`
SECOND=`date +%S`
WEEK=$((10#$WEEK))
WEEK=$(printf "%02d" $WEEK)
DATE="W${YEAR}.${WEEK}.${DAY}:${HOUR}.${MINUTE}.${SECOND}"
echo $DATE
TMP2="DATE_BUILD="\"$DATE"\""
echo $TMP2 >> conf/local.conf
sed -i '/^DATE_BUILD=/s/:/-/' conf/local.conf
bitbake_assert()
{
if [ $? != 0 ]; then
echo "The procedure of bitbake is failed, shell error line: $1"
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
exit 1
fi
}
bitbake_assert_change_image_rootfs_dir()
{
if [ $? != 0 ]; then
echo "The procedure of bitbake is failed, shell error line: $1"
if [ "${flag_change_image_rootfs_dir}" = 0 ];then
echo "do fun_post_change_image_rootfs_dir"
fun_post_change_image_rootfs_dir
else
echo "no no fun_post_change_image_rootfs_dir"
fi
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
exit 1
fi
}
check_offline_building()
{
if [ "$BB_NO_NETWORK_FLAG" == "1" ]; then
bitbake $2 --runall=fetch
if [ $? != 0 ]; then
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo -e "\e[1;31m The offline building failed, please upload tarballs to source/tarballs. shell error line: $1\e[0m"
exit 1
fi
fi
}
building_image()
{
check_offline_building $1 $2
bitbake $2
bitbake_assert $1
}
echo "Build preparation: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
echo "Start building process...${IMAGENAME}..."
building_image $LINENO ${IMAGENAME}
echo "Build ${IMAGENAME}: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
if [ "${flag_change_image_rootfs_dir}" = 0 ];then
echo "do fun_post_change_image_rootfs_dir"
fun_post_change_image_rootfs_dir
else
echo "no no fun_post_change_image_rootfs_dir"
fi
if [[ ${BUILD_SDK_FLAG} == "1" ]]; then
echo "Build sdk!"
# DATE_BUILD need modify for build SDK (from DATE_BUILD="W22.17.1:14.14.16" to DATE_BUILD="W22.17.1-14.14.16")
echo "modify DATE_BUILD for build sdk"
if [ $? != 0 ]; then
echo "modify DATE_BUILD ERROR!!!"
exit 1
fi
check_offline_building $LINENO ${IMAGENAME}
bitbake ${IMAGENAME} -c populate_sdk
bitbake_assert $LINENO
sed -i '/^DATE_BUILD=/s/-/:/' $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo "Build populate_sdk: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
fi
if [[ ${BUILD_ESDK_FLAG} == "1" ]]; then
echo "Build esdk!"
# DATE_BUILD need modify for build eSDK (from DATE_BUILD="W22.17.1:14.14.16" to DATE_BUILD="W22.17.1-14.14.16")
echo "modify DATE_BUILD for build esdk"
if [ $? != 0 ]; then
echo "modify DATE_BUILD ERROR!!!"
exit 1
fi
check_offline_building $LINENO ${IMAGENAME}
bitbake ${IMAGENAME} -c populate_sdk_ext
bitbake_assert $LINENO
echo "Build populate_esdk: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
fi
# 1. build prodnv
building_image $LINENO prodnv
echo "Build prodnv: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
# 2. build userdata
building_image $LINENO userdata
echo "Build userdata: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
# 3. build recovery-image
building_image $LINENO recovery-image
echo "Build recovery-image: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
# 4. build recovery-img
building_image $LINENO recovery-img
echo "Build recovery-img: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
cd ${SOURCEROOT}/prebuilts/scripts
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
source pac.sh $1 $USERDEBUG
echo "Exac pac: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
# build ota pac
if [[ ${BUILD_OTA_FLAG} == "1" ]]; then
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo OTA START
cd ${SOURCEROOT}/prebuilts/scripts
source ota.sh "fullota" "auto"
echo "ota.sh: $(expr $(date +%s) - $btime)" >> ${timedir}/${timename} && btime=`date +%s`
fi
sed -i '/BB_NO_NETWORK=/d' $SOURCEROOT/prebuilts/scripts/conf/local.conf
echo "Build END: $(date "+%Y-%m-%d %H:%M:%S")" >> ${timedir}/${timename}
END_TIME=`date +%s`
TOTAL_TIME_SEC=`expr $END_TIME - $BEGIN_TIME`
echo "TOTAL_TIME: $TOTAL_TIME_SEC" >> ${timedir}/${timename}
cd ${SOURCEROOT}/out/target/product/${MACHINENAME}
pac_size=`find . -name *.pac | xargs ls -sh`
echo "pac size: ${pac_size}" >> ${timedir}/${timename}
mv -f ${timedir}/${timename} ${SOURCEROOT}/out/
rm -rf ${timedir}/*timemsg.log
cat ${SOURCEROOT}/out/${timename}