xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | WORKDIR=$PWD |
| 4 | export PATH=$WORKDIR/bin:$PATH |
| 5 | |
| 6 | UBI_ARGS="-m 0x1000 -p 0x40000 -s 0x1000 -Q 1024" |
| 7 | MKSQUASHFS_ARGS="-nopad -noappend -root-owned -comp xz -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2 -b 256k -processors 1" |
| 8 | PRIVATE_KEY="$WORKDIR/SignTool/key/RSA_2048/private.k" |
| 9 | if [ $# -lt 5 ]; then |
| 10 | echo "[error] $0 parameter to less" |
| 11 | echo "$0 out_name dir_name vol_name selinux_file dm_verity" |
| 12 | echo "selinux_file: selinux context file" |
| 13 | echo "dm_verity: 0 for disable dm-verity, 1 for enable dm-verity" |
| 14 | exit -1 |
| 15 | fi |
| 16 | OUT_NAME=$1 |
| 17 | DIR_NAME=$2 |
| 18 | VOL_NAME=$3 |
| 19 | selinux_file=$4 |
| 20 | dm_verity=$5 |
| 21 | |
| 22 | echo "out_name: $OUT_NAME" |
| 23 | echo "dir_name: $DIR_NAME" |
| 24 | echo "vol_name: $VOL_NAME" |
| 25 | echo "ubi_args: $UBI_ARGS" |
| 26 | |
| 27 | rm -rf $OUT_NAME verity ${VOL_NAME}.out |
| 28 | mkdir -p $DIR_NAME |
| 29 | |
| 30 | if [ -f $selinux_file ]; then |
| 31 | setfiles -m -r $DIR_NAME $selinux_file $DIR_NAME |
| 32 | if [ $? -eq 0 ]; then |
| 33 | echo "selinux set success" |
| 34 | else |
| 35 | echo "selinux set fail" |
| 36 | exit -1 |
| 37 | fi |
| 38 | else |
| 39 | echo "selinux_file NOT exist and disable selinux" |
| 40 | fi |
| 41 | |
| 42 | $WORKDIR/bin/mksquashfs4 $DIR_NAME ${VOL_NAME}.out ${MKSQUASHFS_ARGS} -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1' |
| 43 | if [ $? -ne 0 ]; then |
| 44 | echo "mksquashfs error" |
| 45 | exit -1 |
| 46 | fi |
| 47 | |
| 48 | if [ "$dm_verity" == "1" ]; then |
| 49 | ./squashfs_dm-verity.sh ${VOL_NAME}.out ./ ${VOL_NAME}.dm $PRIVATE_KEY $WORKDIR/SignTool/SignImage |
| 50 | if [ $? -eq 0 ]; then |
| 51 | echo "dm-verity sucess" |
| 52 | else |
| 53 | echo "dm-verity fail" |
| 54 | exit -1 |
| 55 | fi |
| 56 | mv ${VOL_NAME}.dm ${VOL_NAME}.out |
| 57 | else |
| 58 | echo "disable dm-verity" |
| 59 | fi |
| 60 | |
| 61 | ./ubinize-static.sh $VOL_NAME $OUT_NAME ${VOL_NAME}.out "$UBI_ARGS" |