post-image.sh

#!/usr/bin/env bash

set -e 

VERSION=$1

TOP_PATH=$(pwd)/..
CHIP_GROUP=${CHIP_NAME:0:5}X
PROJECT_PATH=$TOP_PATH/build/projects/$PROJECT

XML_FILE=$TOP_PATH/build/projects/$PROJECT/axp.xml

IMG_PATH=$TOP_PATH/build/out/$PROJECT/
TOOL_PATH=$TOP_PATH/tools/mkaxp/make_axp.py
VERSION_EXT=${VERSION}_$(date "+%Y%m%d%H%M%S")
AXP_FILE=$TOP_PATH/build/out/${PROJECT}_${VERSION_EXT}.axp

CMM_POOL_PARAM=anonymous,0,0x50000000,240M

FS_TYPE=ubifs

rm -rf $IMG_PATH/rootfs_opt
rm -rf $IMG_PATH/rootfs_soc
rm -rf $IMG_PATH/rootfs_without_soc_opt
rm -rf $IMG_PATH/rootfs_with_soc_opt
rm -rf $IMG_PATH/rootfs
	
	# rootfs_without_soc_opt
mkdir -p $IMG_PATH/rootfs_without_soc_opt
cp -rfp $TOP_PATH/rootfs/rootfs/* $IMG_PATH/rootfs_without_soc_opt/
rm -rf $IMG_PATH/rootfs_without_soc_opt/lib/modules
rm -rf $IMG_PATH/rootfs_without_soc_opt/soc
rm -rf $IMG_PATH/rootfs_without_soc_opt/opt

	# rootfs_soc
mkdir -p $IMG_PATH/rootfs_soc
mkdir -p $IMG_PATH/rootfs_soc/bin
mkdir -p $IMG_PATH/rootfs_soc/lib
cp -rf $TOP_PATH/kernel/osdrv/out/ko $IMG_PATH/rootfs_soc
cp -rf $TOP_PATH/msp/out/lib/*.so* $IMG_PATH/rootfs_soc/lib
cp -rf $TOP_PATH/rootfs/rootfs/opt/scripts $IMG_PATH/rootfs_soc/
rm -rf $IMG_PATH/rootfs_soc/lib/libmcvsdk_*.so
rm -rf $IMG_PATH/rootfs_soc/lib/libmegsearch.so
rm -rf $IMG_PATH/rootfs_soc/lib/libsns*.so*
rm -rf $IMG_PATH/rootfs_soc/lib/libact_dummy.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_eis.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_audio_3a.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_audio.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_channel.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_cipher.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_detect.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_eis.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_event_mediarecord.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_ives.so
rm -rf $IMG_PATH/rootfs_soc/lib/libax_vdec.so
rm -rf $IMG_PATH/rootfs_soc/lib/liblens_dciris.so

#cp -rf $TOP_PATH/msp/out/lib/libsns_ov2775.so $IMG_PATH/rootfs_soc/lib
cp -rf $TOP_PATH/msp/out/lib/libsns_ox02d10.so $IMG_PATH/rootfs_soc/lib

	# rootfs_opt
rm -rf $IMG_PATH/rootfs_opt
mkdir -p $IMG_PATH/rootfs_opt
cp -rfp $TOP_PATH/rootfs/rootfs/opt/* $IMG_PATH/rootfs_opt/

mkdir -p $IMG_PATH/rootfs_opt/ko
cp -rfp $TOP_PATH/rootfs/rootfs/lib/modules/4.19.125/kernel/* $IMG_PATH/rootfs_opt/ko
# remove unused kernel ko
DIRS=(`ls $IMG_PATH/rootfs_opt/ko`)
for((i=0; i<${#DIRS[@]}; i++))
do
    if [ "${DIRS[i]}" != "drivers"  ]; then
        rm -rf $IMG_PATH/rootfs_opt/ko/${DIRS[i]}
    fi
    SUBDIRS=(`ls $IMG_PATH/rootfs_opt/ko/drivers`)
    for((j=0; j<${#SUBDIRS[@]}; j++))
    do
        if [ "${SUBDIRS[j]}" != "usb" ] && [ "${SUBDIRS[j]}" != "uio"  ]; then
            rm -rf $IMG_PATH/rootfs_opt/ko/drivers/${SUBDIRS[j]}
        fi
    done
done

rm -rf $IMG_PATH/rootfs_opt/etc/*
rm -rf $IMG_PATH/rootfs_opt/lib/*
rm -rf $IMG_PATH/rootfs_opt/scripts/*
rm -rf $IMG_PATH/rootfs_opt/data/*
rm -rf $IMG_PATH/rootfs_opt/bin/*

cp -rf $TOP_PATH/app/IPCDemo/bin/ $IMG_PATH/rootfs_opt/bin/IPCDemo/
cp -rf $TOP_PATH/msp/out/bin/sample_uvc $IMG_PATH/rootfs_opt/bin/
#cp -rf $TOP_PATH/msp/out/etc/ov2775*.pro $IMG_PATH/rootfs_opt/etc/
#cp -rf $TOP_PATH/msp/out/etc/ov2775*.ini $IMG_PATH/rootfs_opt/etc/
cp -rf $TOP_PATH/msp/out/etc/ox02d10*.pro $IMG_PATH/rootfs_opt/etc/
cp -rf $TOP_PATH/msp/out/etc/ox02d10*.ini $IMG_PATH/rootfs_opt/etc/
cp -rf $TOP_PATH/msp/out/bin/tuning-server $IMG_PATH/rootfs_opt/bin/
cp -rf $TOP_PATH/msp/out/bin/dump_tools $IMG_PATH/rootfs_opt/bin/

mv $IMG_PATH/rootfs_without_soc_opt $IMG_PATH/rootfs_with_soc_opt
mv $IMG_PATH/rootfs_opt $IMG_PATH/rootfs_with_soc_opt/opt
mv $IMG_PATH/rootfs_soc $IMG_PATH/rootfs_with_soc_opt/soc
mkdir -p $IMG_PATH/rootfs_with_soc_opt/opt/data/AXSyslog/kernel
rm -rf $IMG_PATH/rootfs_with_soc_opt/opt/ko/*.ko

if [[ -d $PROJECT_PATH/rootfs_overlay ]]; then
	cp -rpf $PROJECT_PATH/rootfs_overlay/* $IMG_PATH/rootfs_with_soc_opt/
fi
	
sed -i "s/cmmpool*=.*/cmmpool=${CMM_POOL_PARAM}/g" $IMG_PATH/rootfs_with_soc_opt/soc/scripts/auto_load_pre_drv.sh

if [[ "$FS_TYPE" == "ubifs" ]]; then
	cp -f $PROJECT_PATH/ubinize.cfg $IMG_PATH/

	cp -f $PROJECT_PATH/fstab_ubifs $IMG_PATH/rootfs_with_soc_opt/etc/fstab

	mv $IMG_PATH/rootfs_with_soc_opt/soc $IMG_PATH/rootfs_soc
	mv $IMG_PATH/rootfs_with_soc_opt/opt $IMG_PATH/rootfs_opt
	mv $IMG_PATH/rootfs_with_soc_opt $IMG_PATH/rootfs_without_soc_opt
	mkdir -p $IMG_PATH/rootfs_without_soc_opt/opt
	mkdir -p $IMG_PATH/rootfs_without_soc_opt/soc

	$TOP_PATH/tools/mkubifs/mkfs.ubifs -F -q -r $IMG_PATH/rootfs_soc -m 2048 -e 126976 -c 2047 -o $IMG_PATH/rootfs_soc.img
	$TOP_PATH/tools/mkubifs/mkfs.ubifs -F -q -r $IMG_PATH/rootfs_opt -m 2048 -e 126976 -c 2047 -o $IMG_PATH/rootfs_opt.img
	$TOP_PATH/tools/mkubifs/mkfs.ubifs -F -q -r $IMG_PATH/rootfs_without_soc_opt -m 2048 -e 126976 -c 2047 -o $IMG_PATH/rootfs_without_soc_opt.img

	cd $IMG_PATH
	$TOP_PATH/tools/mkubifs/ubinize -o $IMG_PATH/rootfs_with_soc_opt.img -m 2048 -p 128KiB ubinize.cfg
	cd -

	ROOTFS_PATH=$IMG_PATH/rootfs_with_soc_opt.img

elif [[ "$FS_TYPE" == "squashfs" ]]; then
	# squashfs

	rm -rf $IMG_PATH/rootfs.img
	rm -rf $IMG_PATH/rootfs
	mv $IMG_PATH/rootfs_with_soc_opt $IMG_PATH/rootfs
	cp -f $PROJECT_PATH/fstab_squashfs $IMG_PATH/rootfs/etc/fstab

	#rm -rf $IMG_PATH/rootfs/etc/inittab
	#rm -rf $IMG_PATH/rootfs/etc/fstab
	#rm -rf $IMG_PATH/rootfs/etc/init.d/*
	#rm -rf $IMG_PATH/rootfs/lib/modules
	#rm -rf $IMG_PATH/rootfs/usr/lib
	#rm -rf $IMG_PATH/rootfs/usr/lib32
	#rm -rf $IMG_PATH/rootfs/usr/local
	#rm -rf $IMG_PATH/rootfs/usr/sbin
	#rm -rf $IMG_PATH/rootfs/usr/share

	#cp -rfp $TOP_PATH/rootfs/rootfs/usr/sbin/lrz $IMG_PATH/rootfs/bin/
	#cp -rfp $TOP_PATH/rootfs/rootfs/usr/sbin/lsz $IMG_PATH/rootfs/bin/
	#rm -rf $IMG_PATH/rootfs/opt/*

	mksquashfs $IMG_PATH/rootfs/ $IMG_PATH/rootfs.img
	ROOTFS_PATH=$IMG_PATH/rootfs.img
else
	echo "Not Support $FS_TYPE filesystem NOW!"
fi

DTB_PATH=$IMG_PATH/${PROJECT}.dtb
EIP_PATH=$IMG_PATH/eip.bin
FDL1_PATH=$IMG_PATH/fdl_${PROJECT}_signed.bin
FDL2_PATH=$IMG_PATH/fdl2_signed.bin
UBOOT_PATH=$IMG_PATH/u-boot_signed.bin
KERNEL_PATH=$IMG_PATH/uImage
SPL_PATH=$IMG_PATH/spl_${PROJECT}_signed.bin


python3 $TOOL_PATH -p $CHIP_GROUP -v $VERSION_EXT -x $XML_FILE -o $AXP_FILE $EIP_PATH $FDL1_PATH $FDL2_PATH $UBOOT_PATH $DTB_PATH $KERNEL_PATH $ROOTFS_PATH $SPL_PATH

你可能感兴趣的:(Linux,linux,shell)